Annotation of loncom/interface/domainprefs.pm, revision 1.359
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.359 ! raeburn 4: # $Id: domainprefs.pm,v 1.358 2019/05/06 01:30:14 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
1.286 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
1.297 raeburn 30: ###############################################################
1.1 raeburn 31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.210 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.197 raeburn 98: used by course owners to request creation of a course, and to display/store
1.223 bisitz 99: default quota sizes for Authoring Spaces.
1.101 raeburn 100:
101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
1.325 raeburn 107: (official, unofficial, community, textbook, placement, and lti).
1.271 raeburn 108: In each case the radio buttons allow the selection of one of four values:
1.101 raeburn 109:
1.104 raeburn 110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
1.104 raeburn 121: approval
1.101 raeburn 122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
1.143 raeburn 145: - course requests will be processed automatically up to a limit of
1.101 raeburn 146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
1.1 raeburn 158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
1.43 raeburn 166: use Apache::lonmsg();
1.91 raeburn 167: use Apache::lonconfigsettings;
1.232 raeburn 168: use Apache::lonuserutils();
1.235 raeburn 169: use Apache::loncoursequeueadmin();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.275 raeburn 173: use LONCAPA::SSL;
1.9 raeburn 174: use File::Copy;
1.43 raeburn 175: use Locale::Language;
1.62 raeburn 176: use DateTime::TimeZone;
1.68 raeburn 177: use DateTime::Locale;
1.267 raeburn 178: use Time::HiRes qw( sleep );
1.1 raeburn 179:
1.155 raeburn 180: my $registered_cleanup;
181: my $modified_urls;
182:
1.1 raeburn 183: sub handler {
184: my $r=shift;
185: if ($r->header_only) {
186: &Apache::loncommon::content_type($r,'text/html');
187: $r->send_http_header;
188: return OK;
189: }
190:
1.91 raeburn 191: my $context = 'domain';
1.1 raeburn 192: my $dom = $env{'request.role.domain'};
1.5 albertel 193: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 194: if (&Apache::lonnet::allowed('mau',$dom)) {
195: &Apache::loncommon::content_type($r,'text/html');
196: $r->send_http_header;
197: } else {
198: $env{'user.error.msg'}=
199: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
200: return HTTP_NOT_ACCEPTABLE;
201: }
1.155 raeburn 202:
203: $registered_cleanup=0;
204: @{$modified_urls}=();
205:
1.1 raeburn 206: &Apache::lonhtmlcommon::clear_breadcrumbs();
207: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 208: ['phase','actions']);
1.30 raeburn 209: my $phase = 'pickactions';
1.3 raeburn 210: if ( exists($env{'form.phase'}) ) {
211: $phase = $env{'form.phase'};
212: }
1.150 raeburn 213: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 214: my %domconfig =
1.6 raeburn 215: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 216: 'quotas','autoenroll','autoupdate','autocreate',
217: 'directorysrch','usercreation','usermodification',
218: 'contacts','defaults','scantron','coursecategories',
219: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 220: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 221: 'requestauthor','selfenrollment','inststatus',
1.357 raeburn 222: 'ltitools','ssl','trust','lti','privacy','passwords'],$dom);
1.320 raeburn 223: my %encconfig =
224: &Apache::lonnet::get_dom('encconfig',['ltitools','lti'],$dom);
1.297 raeburn 225: if (ref($domconfig{'ltitools'}) eq 'HASH') {
226: if (ref($encconfig{'ltitools'}) eq 'HASH') {
227: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
1.320 raeburn 228: if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
229: (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
1.297 raeburn 230: foreach my $item ('key','secret') {
231: $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
232: }
233: }
234: }
235: }
236: }
1.320 raeburn 237: if (ref($domconfig{'lti'}) eq 'HASH') {
238: if (ref($encconfig{'lti'}) eq 'HASH') {
239: foreach my $id (keys(%{$domconfig{'lti'}})) {
240: if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
241: (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
242: foreach my $item ('key','secret') {
243: $domconfig{'lti'}{$id}{$item} = $encconfig{'lti'}{$id}{$item};
244: }
245: }
246: }
247: }
248: }
1.354 raeburn 249: my @prefs_order = ('rolecolors','login','defaults','passwords','quotas','autoenroll',
1.357 raeburn 250: 'autoupdate','autocreate','directorysrch','contacts','privacy',
1.224 raeburn 251: 'usercreation','selfcreation','usermodification','scantron',
1.163 raeburn 252: 'requestcourses','requestauthor','coursecategories',
1.267 raeburn 253: 'serverstatuses','helpsettings','coursedefaults',
1.320 raeburn 254: 'ltitools','selfenrollment','usersessions','ssl','trust','lti');
1.171 raeburn 255: my %existing;
256: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
257: %existing = %{$domconfig{'loadbalancing'}};
258: }
259: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 260: push(@prefs_order,'loadbalancing');
261: }
1.30 raeburn 262: my %prefs = (
263: 'rolecolors' =>
264: { text => 'Default color schemes',
1.67 raeburn 265: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 266: header => [{col1 => 'Student Settings',
267: col2 => '',},
268: {col1 => 'Coordinator Settings',
269: col2 => '',},
270: {col1 => 'Author Settings',
271: col2 => '',},
272: {col1 => 'Administrator Settings',
273: col2 => '',}],
1.230 raeburn 274: print => \&print_rolecolors,
275: modify => \&modify_rolecolors,
1.30 raeburn 276: },
1.110 raeburn 277: 'login' =>
1.30 raeburn 278: { text => 'Log-in page options',
1.67 raeburn 279: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 280: header => [{col1 => 'Log-in Page Items',
281: col2 => '',},
282: {col1 => 'Log-in Help',
1.256 raeburn 283: col2 => 'Value'},
284: {col1 => 'Custom HTML in document head',
1.168 raeburn 285: col2 => 'Value'}],
1.230 raeburn 286: print => \&print_login,
287: modify => \&modify_login,
1.30 raeburn 288: },
1.43 raeburn 289: 'defaults' =>
1.236 raeburn 290: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 291: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 292: header => [{col1 => 'Setting',
1.236 raeburn 293: col2 => 'Value'},
294: {col1 => 'Institutional user types',
1.305 raeburn 295: col2 => 'Name displayed'}],
1.230 raeburn 296: print => \&print_defaults,
297: modify => \&modify_defaults,
1.43 raeburn 298: },
1.354 raeburn 299: 'passwords' =>
300: { text => 'Passwords (Internal authentication)',
301: help => 'Domain_Configuration_Passwords',
302: header => [{col1 => 'Resetting Forgotten Password',
303: col2 => 'Settings'},
304: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
305: col2 => 'Settings'},
306: {col1 => 'Rules for LON-CAPA Passwords',
307: col2 => 'Settings'},
308: {col1 => 'Course Owner Changing Student Passwords',
309: col2 => 'Settings'}],
310: print => \&print_passwords,
311: modify => \&modify_passwords,
312: },
1.30 raeburn 313: 'quotas' =>
1.197 raeburn 314: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 315: help => 'Domain_Configuration_Quotas',
1.77 raeburn 316: header => [{col1 => 'User affiliation',
1.72 raeburn 317: col2 => 'Available tools',
1.213 raeburn 318: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 319: print => \&print_quotas,
320: modify => \&modify_quotas,
1.30 raeburn 321: },
322: 'autoenroll' =>
323: { text => 'Auto-enrollment settings',
1.67 raeburn 324: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 325: header => [{col1 => 'Configuration setting',
326: col2 => 'Value(s)'}],
1.230 raeburn 327: print => \&print_autoenroll,
328: modify => \&modify_autoenroll,
1.30 raeburn 329: },
330: 'autoupdate' =>
331: { text => 'Auto-update settings',
1.67 raeburn 332: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 333: header => [{col1 => 'Setting',
334: col2 => 'Value',},
1.131 raeburn 335: {col1 => 'Setting',
336: col2 => 'Affiliation'},
1.43 raeburn 337: {col1 => 'User population',
1.227 bisitz 338: col2 => 'Updatable user data'}],
1.230 raeburn 339: print => \&print_autoupdate,
340: modify => \&modify_autoupdate,
1.30 raeburn 341: },
1.125 raeburn 342: 'autocreate' =>
343: { text => 'Auto-course creation settings',
344: help => 'Domain_Configuration_Auto_Creation',
345: header => [{col1 => 'Configuration Setting',
346: col2 => 'Value',}],
1.230 raeburn 347: print => \&print_autocreate,
348: modify => \&modify_autocreate,
1.125 raeburn 349: },
1.30 raeburn 350: 'directorysrch' =>
1.277 raeburn 351: { text => 'Directory searches',
1.67 raeburn 352: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 353: header => [{col1 => 'Institutional Directory Setting',
354: col2 => 'Value',},
355: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 356: col2 => 'Value',}],
1.230 raeburn 357: print => \&print_directorysrch,
358: modify => \&modify_directorysrch,
1.30 raeburn 359: },
360: 'contacts' =>
1.286 raeburn 361: { text => 'E-mail addresses and helpform',
1.67 raeburn 362: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 363: header => [{col1 => 'Default e-mail addresses',
364: col2 => 'Value',},
365: {col1 => 'Recipient(s) for notifications',
366: col2 => 'Value',},
1.340 raeburn 367: {col1 => 'Nightly status check e-mail',
368: col2 => 'Settings',},
1.286 raeburn 369: {col1 => 'Ask helpdesk form settings',
370: col2 => 'Value',},],
1.230 raeburn 371: print => \&print_contacts,
372: modify => \&modify_contacts,
1.30 raeburn 373: },
374: 'usercreation' =>
375: { text => 'User creation',
1.67 raeburn 376: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 377: header => [{col1 => 'Format rule type',
378: col2 => 'Format rules in force'},
1.34 raeburn 379: {col1 => 'User account creation',
380: col2 => 'Usernames which may be created',},
1.30 raeburn 381: {col1 => 'Context',
1.43 raeburn 382: col2 => 'Assignable authentication types'}],
1.230 raeburn 383: print => \&print_usercreation,
384: modify => \&modify_usercreation,
1.30 raeburn 385: },
1.224 raeburn 386: 'selfcreation' =>
387: { text => 'Users self-creating accounts',
388: help => 'Domain_Configuration_Self_Creation',
389: header => [{col1 => 'Self-creation with institutional username',
390: col2 => 'Enabled?'},
391: {col1 => 'Institutional user type (login/SSO self-creation)',
392: col2 => 'Information user can enter'},
1.303 raeburn 393: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 394: col2 => 'Settings'}],
1.230 raeburn 395: print => \&print_selfcreation,
396: modify => \&modify_selfcreation,
1.224 raeburn 397: },
1.69 raeburn 398: 'usermodification' =>
1.33 raeburn 399: { text => 'User modification',
1.67 raeburn 400: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 401: header => [{col1 => 'Target user has role',
1.227 bisitz 402: col2 => 'User information updatable in author context'},
1.33 raeburn 403: {col1 => 'Target user has role',
1.227 bisitz 404: col2 => 'User information updatable in course context'}],
1.230 raeburn 405: print => \&print_usermodification,
406: modify => \&modify_usermodification,
1.33 raeburn 407: },
1.69 raeburn 408: 'scantron' =>
1.346 raeburn 409: { text => 'Bubblesheet format',
1.67 raeburn 410: help => 'Domain_Configuration_Scantron_Format',
1.346 raeburn 411: header => [ {col1 => 'Bubblesheet format file',
412: col2 => ''},
413: {col1 => 'Bubblesheet data upload formats',
414: col2 => 'Settings'}],
1.230 raeburn 415: print => \&print_scantron,
416: modify => \&modify_scantron,
1.46 raeburn 417: },
1.86 raeburn 418: 'requestcourses' =>
419: {text => 'Request creation of courses',
420: help => 'Domain_Configuration_Request_Courses',
421: header => [{col1 => 'User affiliation',
1.102 raeburn 422: col2 => 'Availability/Processing of requests',},
423: {col1 => 'Setting',
1.216 raeburn 424: col2 => 'Value'},
425: {col1 => 'Available textbooks',
1.235 raeburn 426: col2 => ''},
1.242 raeburn 427: {col1 => 'Available templates',
428: col2 => ''},
1.235 raeburn 429: {col1 => 'Validation (not official courses)',
430: col2 => 'Value'},],
1.230 raeburn 431: print => \&print_quotas,
432: modify => \&modify_quotas,
1.86 raeburn 433: },
1.163 raeburn 434: 'requestauthor' =>
1.223 bisitz 435: {text => 'Request Authoring Space',
1.163 raeburn 436: help => 'Domain_Configuration_Request_Author',
437: header => [{col1 => 'User affiliation',
438: col2 => 'Availability/Processing of requests',},
439: {col1 => 'Setting',
440: col2 => 'Value'}],
1.230 raeburn 441: print => \&print_quotas,
442: modify => \&modify_quotas,
1.163 raeburn 443: },
1.69 raeburn 444: 'coursecategories' =>
1.120 raeburn 445: { text => 'Cataloging of courses/communities',
1.67 raeburn 446: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 447: header => [{col1 => 'Catalog type/availability',
448: col2 => '',},
449: {col1 => 'Category settings for standard catalog',
1.57 raeburn 450: col2 => '',},
451: {col1 => 'Categories',
452: col2 => '',
453: }],
1.230 raeburn 454: print => \&print_coursecategories,
455: modify => \&modify_coursecategories,
1.69 raeburn 456: },
457: 'serverstatuses' =>
1.77 raeburn 458: {text => 'Access to server status pages',
1.69 raeburn 459: help => 'Domain_Configuration_Server_Status',
460: header => [{col1 => 'Status Page',
461: col2 => 'Other named users',
462: col3 => 'Specific IPs',
463: }],
1.230 raeburn 464: print => \&print_serverstatuses,
465: modify => \&modify_serverstatuses,
1.69 raeburn 466: },
1.118 jms 467: 'helpsettings' =>
1.282 raeburn 468: {text => 'Support settings',
1.118 jms 469: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 470: header => [{col1 => 'Help Page Settings (logged-in users)',
471: col2 => 'Value'},
472: {col1 => 'Helpdesk Roles',
473: col2 => 'Settings'},],
1.230 raeburn 474: print => \&print_helpsettings,
475: modify => \&modify_helpsettings,
1.118 jms 476: },
1.121 raeburn 477: 'coursedefaults' =>
478: {text => 'Course/Community defaults',
479: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 480: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
481: col2 => 'Value',},
482: {col1 => 'Defaults which can be overridden for each course by a DC',
483: col2 => 'Value',},],
1.230 raeburn 484: print => \&print_coursedefaults,
485: modify => \&modify_coursedefaults,
1.121 raeburn 486: },
1.231 raeburn 487: 'selfenrollment' =>
488: {text => 'Self-enrollment in Course/Community',
489: help => 'Domain_Configuration_Selfenrollment',
490: header => [{col1 => 'Configuration Rights',
491: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
492: {col1 => 'Defaults',
493: col2 => 'Value'},
494: {col1 => 'Self-enrollment validation (optional)',
495: col2 => 'Value'},],
496: print => \&print_selfenrollment,
497: modify => \&modify_selfenrollment,
498: },
1.120 raeburn 499: 'privacy' =>
1.357 raeburn 500: {text => 'Availability of User Information',
1.120 raeburn 501: help => 'Domain_Configuration_User_Privacy',
1.357 raeburn 502: header => [{col1 => 'Role assigned in different domain',
503: col2 => 'Approval options'},
504: {col1 => 'Role assigned in different domain to user of type',
505: col2 => 'User information available in that domain'},
506: {col1 => "Role assigned in user's domain",
507: col2 => 'Information viewable by privileged user'},
508: {col1 => "Role assigned in user's domain",
509: col2 => 'Information viewable by unprivileged user'}],
1.230 raeburn 510: print => \&print_privacy,
511: modify => \&modify_privacy,
1.120 raeburn 512: },
1.141 raeburn 513: 'usersessions' =>
1.145 raeburn 514: {text => 'User session hosting/offloading',
1.137 raeburn 515: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 516: header => [{col1 => 'Domain server',
517: col2 => 'Servers to offload sessions to when busy'},
518: {col1 => 'Hosting of users from other domains',
1.137 raeburn 519: col2 => 'Rules'},
520: {col1 => "Hosting domain's own users elsewhere",
521: col2 => 'Rules'}],
1.230 raeburn 522: print => \&print_usersessions,
523: modify => \&modify_usersessions,
1.137 raeburn 524: },
1.279 raeburn 525: 'loadbalancing' =>
1.185 raeburn 526: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 527: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 528: header => [{col1 => 'Balancers',
1.150 raeburn 529: col2 => 'Default destinations',
1.183 bisitz 530: col3 => 'User affiliation',
1.150 raeburn 531: col4 => 'Overrides'},
532: ],
1.230 raeburn 533: print => \&print_loadbalancing,
534: modify => \&modify_loadbalancing,
1.150 raeburn 535: },
1.279 raeburn 536: 'ltitools' =>
1.267 raeburn 537: {text => 'External Tools (LTI)',
1.296 raeburn 538: help => 'Domain_Configuration_LTI_Tools',
1.267 raeburn 539: header => [{col1 => 'Setting',
540: col2 => 'Value',}],
541: print => \&print_ltitools,
542: modify => \&modify_ltitools,
543: },
1.279 raeburn 544: 'ssl' =>
1.275 raeburn 545: {text => 'LON-CAPA Network (SSL)',
546: help => 'Domain_Configuration_Network_SSL',
547: header => [{col1 => 'Server',
548: col2 => 'Certificate Status'},
549: {col1 => 'Connections to other servers',
550: col2 => 'Rules'},
1.293 raeburn 551: {col1 => 'Connections from other servers',
552: col2 => 'Rules'},
1.275 raeburn 553: {col1 => "Replicating domain's published content",
554: col2 => 'Rules'}],
555: print => \&print_ssl,
556: modify => \&modify_ssl,
557: },
1.279 raeburn 558: 'trust' =>
559: {text => 'Trust Settings',
560: help => 'Domain_Configuration_Trust',
561: header => [{col1 => "Access to this domain's content by others",
562: col2 => 'Rules'},
563: {col1 => "Access to other domain's content by this domain",
564: col2 => 'Rules'},
565: {col1 => "Enrollment in this domain's courses by others",
566: col2 => 'Rules',},
567: {col1 => "Co-author roles in this domain for others",
568: col2 => 'Rules',},
569: {col1 => "Co-author roles for this domain's users elsewhere",
570: col2 => 'Rules',},
571: {col1 => "Domain roles in this domain assignable to others",
572: col2 => 'Rules'},
573: {col1 => "Course catalog for this domain displayed elsewhere",
574: col2 => 'Rules'},
575: {col1 => "Requests for creation of courses in this domain by others",
576: col2 => 'Rules'},
577: {col1 => "Users in other domains can send messages to this domain",
578: col2 => 'Rules'},],
579: print => \&print_trust,
580: modify => \&modify_trust,
581: },
1.320 raeburn 582: 'lti' =>
583: {text => 'LTI Provider',
584: help => 'Domain_Configuration_LTI_Provider',
585: header => [{col1 => 'Setting',
586: col2 => 'Value',}],
587: print => \&print_lti,
588: modify => \&modify_lti,
589: },
1.3 raeburn 590: );
1.110 raeburn 591: if (keys(%servers) > 1) {
592: $prefs{'login'} = { text => 'Log-in page options',
593: help => 'Domain_Configuration_Login_Page',
594: header => [{col1 => 'Log-in Service',
595: col2 => 'Server Setting',},
596: {col1 => 'Log-in Page Items',
1.168 raeburn 597: col2 => ''},
598: {col1 => 'Log-in Help',
1.256 raeburn 599: col2 => 'Value'},
600: {col1 => 'Custom HTML in document head',
1.168 raeburn 601: col2 => 'Value'}],
1.230 raeburn 602: print => \&print_login,
603: modify => \&modify_login,
1.110 raeburn 604: };
605: }
1.174 foxr 606:
1.6 raeburn 607: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 608: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 609: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 610: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 611: text=>"Settings to display/modify"});
1.9 raeburn 612: my $confname = $dom.'-domainconfig';
1.174 foxr 613:
1.3 raeburn 614: if ($phase eq 'process') {
1.212 raeburn 615: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
616: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 617: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 618: $r->rflush();
1.212 raeburn 619: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 620: }
1.30 raeburn 621: } elsif ($phase eq 'display') {
1.192 raeburn 622: my $js = &recaptcha_js().
1.236 raeburn 623: &toggle_display_js();
1.171 raeburn 624: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 625: my ($othertitle,$usertypes,$types) =
626: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 627: $js .= &lonbalance_targets_js($dom,$types,\%servers,
628: $domconfig{'loadbalancing'}).
1.170 raeburn 629: &new_spares_js().
630: &common_domprefs_js().
631: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 632: }
1.216 raeburn 633: if (grep(/^requestcourses$/,@actions)) {
634: my $javascript_validations;
635: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
636: $js .= <<END;
637: <script type="text/javascript">
638: $javascript_validations
639: </script>
640: $coursebrowserjs
641: END
642: }
1.305 raeburn 643: if (grep(/^selfcreation$/,@actions)) {
644: $js .= &selfcreate_javascript();
645: }
1.286 raeburn 646: if (grep(/^contacts$/,@actions)) {
647: $js .= &contacts_javascript();
648: }
1.346 raeburn 649: if (grep(/^scantron$/,@actions)) {
650: $js .= &scantron_javascript();
651: }
1.150 raeburn 652: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 653: } else {
1.180 raeburn 654: # check if domconfig user exists for the domain.
655: my $servadm = $r->dir_config('lonAdmEMail');
656: my ($configuserok,$author_ok,$switchserver) =
657: &config_check($dom,$confname,$servadm);
658: unless ($configuserok eq 'ok') {
1.181 raeburn 659: &Apache::lonconfigsettings::print_header($r,$phase,$context);
660: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 661: $confname).
1.181 raeburn 662: '<br />'
663: );
1.180 raeburn 664: if ($switchserver) {
1.181 raeburn 665: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
666: '<br />'.
667: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
668: '<br />'.
669: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
670: '<br />'.
671: &mt('To do that now, use the following link: [_1]',$switchserver)
672: );
673: } else {
674: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
675: '<br />'.
676: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
677: );
1.180 raeburn 678: }
679: $r->print(&Apache::loncommon::end_page());
680: return OK;
681: }
1.21 raeburn 682: if (keys(%domconfig) == 0) {
683: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 684: my @ids=&Apache::lonnet::current_machine_ids();
685: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 686: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 687: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 688: my $custom_img_count = 0;
689: foreach my $img (@loginimages) {
690: if ($designhash{$dom.'.login.'.$img} ne '') {
691: $custom_img_count ++;
692: }
693: }
694: foreach my $role (@roles) {
695: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
696: $custom_img_count ++;
697: }
698: }
699: if ($custom_img_count > 0) {
1.94 raeburn 700: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 701: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 702: $r->print(
703: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
704: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
705: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
706: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
707: if ($switch_server) {
1.30 raeburn 708: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 709: }
1.91 raeburn 710: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 711: return OK;
712: }
713: }
714: }
1.91 raeburn 715: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 716: }
717: return OK;
718: }
719:
720: sub process_changes {
1.205 raeburn 721: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 722: my %domconfig;
723: if (ref($values) eq 'HASH') {
724: %domconfig = %{$values};
725: }
1.3 raeburn 726: my $output;
727: if ($action eq 'login') {
1.205 raeburn 728: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 729: } elsif ($action eq 'rolecolors') {
1.9 raeburn 730: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 731: $lastactref,%domconfig);
1.3 raeburn 732: } elsif ($action eq 'quotas') {
1.216 raeburn 733: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 734: } elsif ($action eq 'autoenroll') {
1.205 raeburn 735: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 736: } elsif ($action eq 'autoupdate') {
737: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 738: } elsif ($action eq 'autocreate') {
739: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 740: } elsif ($action eq 'directorysrch') {
1.295 raeburn 741: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 742: } elsif ($action eq 'usercreation') {
1.28 raeburn 743: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 744: } elsif ($action eq 'selfcreation') {
1.305 raeburn 745: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 746: } elsif ($action eq 'usermodification') {
747: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 748: } elsif ($action eq 'contacts') {
1.205 raeburn 749: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 750: } elsif ($action eq 'defaults') {
1.212 raeburn 751: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 752: } elsif ($action eq 'scantron') {
1.205 raeburn 753: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 754: } elsif ($action eq 'coursecategories') {
1.239 raeburn 755: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 756: } elsif ($action eq 'serverstatuses') {
757: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 758: } elsif ($action eq 'requestcourses') {
1.216 raeburn 759: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 760: } elsif ($action eq 'requestauthor') {
1.216 raeburn 761: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 762: } elsif ($action eq 'helpsettings') {
1.285 raeburn 763: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 764: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 765: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 766: } elsif ($action eq 'selfenrollment') {
767: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 768: } elsif ($action eq 'usersessions') {
1.212 raeburn 769: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 770: } elsif ($action eq 'loadbalancing') {
771: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 772: } elsif ($action eq 'ltitools') {
773: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 774: } elsif ($action eq 'ssl') {
775: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 776: } elsif ($action eq 'trust') {
777: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 778: } elsif ($action eq 'lti') {
779: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.357 raeburn 780: } elsif ($action eq 'privacy') {
781: $output = &modify_privacy($dom,%domconfig);
1.354 raeburn 782: } elsif ($action eq 'passwords') {
783: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.3 raeburn 784: }
785: return $output;
786: }
787:
788: sub print_config_box {
1.9 raeburn 789: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 790: my $rowtotal = 0;
1.49 raeburn 791: my $output;
792: if ($action eq 'coursecategories') {
793: $output = &coursecategories_javascript($settings);
1.236 raeburn 794: } elsif ($action eq 'defaults') {
795: $output = &defaults_javascript($settings);
1.354 raeburn 796: } elsif ($action eq 'passwords') {
797: $output = &passwords_javascript();
1.282 raeburn 798: } elsif ($action eq 'helpsettings') {
799: my (%privs,%levelscurrent);
800: my %full=();
801: my %levels=(
802: course => {},
803: domain => {},
804: system => {},
805: );
806: my $context = 'domain';
807: my $crstype = 'Course';
808: my $formname = 'display';
809: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
810: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
811: $output =
812: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
813: \@templateroles);
1.334 raeburn 814: } elsif ($action eq 'ltitools') {
815: $output .= <itools_javascript($settings);
816: } elsif ($action eq 'lti') {
817: $output .= <i_javascript($settings);
1.91 raeburn 818: }
1.236 raeburn 819: $output .=
1.30 raeburn 820: '<table class="LC_nested_outer">
1.3 raeburn 821: <tr>
1.306 raeburn 822: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 823: &mt($item->{text}).' '.
824: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
825: '</tr>';
1.30 raeburn 826: $rowtotal ++;
1.110 raeburn 827: my $numheaders = 1;
828: if (ref($item->{'header'}) eq 'ARRAY') {
829: $numheaders = scalar(@{$item->{'header'}});
830: }
831: if ($numheaders > 1) {
1.64 raeburn 832: my $colspan = '';
1.145 raeburn 833: my $rightcolspan = '';
1.238 raeburn 834: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 835: ($action eq 'directorysrch') ||
1.256 raeburn 836: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 837: $colspan = ' colspan="2"';
838: }
1.145 raeburn 839: if ($action eq 'usersessions') {
840: $rightcolspan = ' colspan="3"';
841: }
1.30 raeburn 842: $output .= '
1.3 raeburn 843: <tr>
844: <td>
845: <table class="LC_nested">
846: <tr class="LC_info_row">
1.59 bisitz 847: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 848: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 849: </tr>';
1.69 raeburn 850: $rowtotal ++;
1.230 raeburn 851: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 852: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 853: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 854: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.357 raeburn 855: ($action eq 'contacts') || ($action eq 'privacy')) {
1.230 raeburn 856: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354 raeburn 857: } elsif ($action eq 'passwords') {
858: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 859: } elsif ($action eq 'coursecategories') {
1.230 raeburn 860: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346 raeburn 861: } elsif ($action eq 'scantron') {
862: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 863: } elsif ($action eq 'login') {
1.256 raeburn 864: if ($numheaders == 4) {
1.168 raeburn 865: $colspan = ' colspan="2"';
866: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
867: } else {
868: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
869: }
1.230 raeburn 870: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 871: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 872: } elsif ($action eq 'rolecolors') {
1.30 raeburn 873: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 874: }
1.30 raeburn 875: $output .= '
1.6 raeburn 876: </table>
877: </td>
878: </tr>
879: <tr>
880: <td>
881: <table class="LC_nested">
882: <tr class="LC_info_row">
1.230 raeburn 883: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 884: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 885: </tr>';
886: $rowtotal ++;
1.230 raeburn 887: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
888: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 889: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.357 raeburn 890: ($action eq 'trust') || ($action eq 'contacts') ||
891: ($action eq 'privacy') || ($action eq 'passwords')) {
1.238 raeburn 892: if ($action eq 'coursecategories') {
893: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
894: $colspan = ' colspan="2"';
1.279 raeburn 895: } elsif ($action eq 'trust') {
896: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354 raeburn 897: } elsif ($action eq 'passwords') {
898: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.238 raeburn 899: } else {
900: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
901: }
1.279 raeburn 902: if ($action eq 'trust') {
903: $output .= '
904: </table>
905: </td>
906: </tr>';
907: my @trusthdrs = qw(2 3 4 5 6 7);
908: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
909: for (my $i=0; $i<@trusthdrs; $i++) {
910: $output .= '
911: <tr>
912: <td>
913: <table class="LC_nested">
914: <tr class="LC_info_row">
915: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
916: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
917: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
918: </table>
919: </td>
920: </tr>';
921: }
922: $output .= '
923: <tr>
924: <td>
925: <table class="LC_nested">
926: <tr class="LC_info_row">
927: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
928: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
929: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
930: } else {
931: $output .= '
1.63 raeburn 932: </table>
933: </td>
934: </tr>
935: <tr>
936: <td>
937: <table class="LC_nested">
938: <tr class="LC_info_row">
939: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 940: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 941: </tr>'."\n";
1.279 raeburn 942: if ($action eq 'coursecategories') {
943: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.357 raeburn 944: } elsif (($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'passwords')) {
1.354 raeburn 945: if ($action eq 'passwords') {
946: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
947: } else {
948: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
949: }
950: $output .= '
1.340 raeburn 951: </tr>
952: </table>
953: </td>
954: </tr>
955: <tr>
956: <td>
957: <table class="LC_nested">
958: <tr class="LC_info_row">
959: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.354 raeburn 960: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
961: if ($action eq 'passwords') {
962: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
963: } else {
964: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
965: }
966: $output .= '
1.340 raeburn 967: </table>
968: </td>
969: </tr>
970: <tr>';
1.279 raeburn 971: } else {
972: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
973: }
1.238 raeburn 974: }
1.63 raeburn 975: $rowtotal ++;
1.236 raeburn 976: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282 raeburn 977: ($action eq 'defaults') || ($action eq 'directorysrch') ||
978: ($action eq 'helpsettings')) {
1.230 raeburn 979: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346 raeburn 980: } elsif ($action eq 'scantron') {
981: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293 raeburn 982: } elsif ($action eq 'ssl') {
983: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
984: </table>
985: </td>
986: </tr>
987: <tr>
988: <td>
989: <table class="LC_nested">
990: <tr class="LC_info_row">
991: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
992: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
993: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
994: </table>
995: </td>
996: </tr>
997: <tr>
998: <td>
999: <table class="LC_nested">
1000: <tr class="LC_info_row">
1001: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1002: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
1003: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 1004: } elsif ($action eq 'login') {
1.256 raeburn 1005: if ($numheaders == 4) {
1.168 raeburn 1006: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
1007: </table>
1008: </td>
1009: </tr>
1010: <tr>
1011: <td>
1012: <table class="LC_nested">
1013: <tr class="LC_info_row">
1014: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 1015: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 1016: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1017: $rowtotal ++;
1018: } else {
1019: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1020: }
1.256 raeburn 1021: $output .= '
1022: </table>
1023: </td>
1024: </tr>
1025: <tr>
1026: <td>
1027: <table class="LC_nested">
1028: <tr class="LC_info_row">';
1029: if ($numheaders == 4) {
1030: $output .= '
1031: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1032: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1033: </tr>';
1034: } else {
1035: $output .= '
1036: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1037: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1038: </tr>';
1039: }
1040: $rowtotal ++;
1041: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1042: } elsif ($action eq 'requestcourses') {
1.247 raeburn 1043: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1044: $rowtotal ++;
1045: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 1046: </table>
1047: </td>
1048: </tr>
1049: <tr>
1050: <td>
1051: <table class="LC_nested">
1052: <tr class="LC_info_row">
1053: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1054: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 1055: &textbookcourses_javascript($settings).
1056: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1057: </table>
1058: </td>
1059: </tr>
1060: <tr>
1061: <td>
1062: <table class="LC_nested">
1063: <tr class="LC_info_row">
1064: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1065: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1066: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 1067: </table>
1068: </td>
1069: </tr>
1070: <tr>
1071: <td>
1072: <table class="LC_nested">
1073: <tr class="LC_info_row">
1.306 raeburn 1074: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1075: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1076: </tr>'.
1077: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1078: } elsif ($action eq 'requestauthor') {
1079: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1080: $rowtotal ++;
1.122 jms 1081: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1082: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1083: </table>
1084: </td>
1085: </tr>
1086: <tr>
1087: <td>
1088: <table class="LC_nested">
1089: <tr class="LC_info_row">
1.306 raeburn 1090: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1091: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1092: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1093: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1094: </tr>'.
1.30 raeburn 1095: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1096: </table>
1097: </td>
1098: </tr>
1099: <tr>
1100: <td>
1101: <table class="LC_nested">
1102: <tr class="LC_info_row">
1.59 bisitz 1103: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1104: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1105: </tr>'.
1.30 raeburn 1106: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1107: $rowtotal += 2;
1.6 raeburn 1108: }
1.3 raeburn 1109: } else {
1.30 raeburn 1110: $output .= '
1.3 raeburn 1111: <tr>
1112: <td>
1113: <table class="LC_nested">
1.30 raeburn 1114: <tr class="LC_info_row">';
1.277 raeburn 1115: if ($action eq 'login') {
1.30 raeburn 1116: $output .= '
1.59 bisitz 1117: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1118: } elsif ($action eq 'serverstatuses') {
1119: $output .= '
1.306 raeburn 1120: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1121: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1122:
1.6 raeburn 1123: } else {
1.30 raeburn 1124: $output .= '
1.306 raeburn 1125: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1126: }
1.72 raeburn 1127: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1128: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1129: &mt($item->{'header'}->[0]->{'col2'});
1130: if ($action eq 'serverstatuses') {
1131: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1132: }
1.69 raeburn 1133: } else {
1.306 raeburn 1134: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1135: &mt($item->{'header'}->[0]->{'col2'});
1136: }
1137: $output .= '</td>';
1138: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1139: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1140: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1141: &mt($item->{'header'}->[0]->{'col3'});
1142: } else {
1.306 raeburn 1143: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1144: &mt($item->{'header'}->[0]->{'col3'});
1145: }
1.69 raeburn 1146: if ($action eq 'serverstatuses') {
1147: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1148: }
1149: $output .= '</td>';
1.6 raeburn 1150: }
1.150 raeburn 1151: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1152: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1153: &mt($item->{'header'}->[0]->{'col4'});
1154: }
1.69 raeburn 1155: $output .= '</tr>';
1.48 raeburn 1156: $rowtotal ++;
1.168 raeburn 1157: if ($action eq 'quotas') {
1.86 raeburn 1158: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1159: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1160: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.320 raeburn 1161: ($action eq 'ltitools') || ($action eq 'lti')) {
1.230 raeburn 1162: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1163: }
1.3 raeburn 1164: }
1.30 raeburn 1165: $output .= '
1.3 raeburn 1166: </table>
1167: </td>
1168: </tr>
1.30 raeburn 1169: </table><br />';
1170: return ($output,$rowtotal);
1.1 raeburn 1171: }
1172:
1.3 raeburn 1173: sub print_login {
1.168 raeburn 1174: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 1175: my ($css_class,$datatable);
1.6 raeburn 1176: my %choices = &login_choices();
1.110 raeburn 1177:
1.168 raeburn 1178: if ($caller eq 'service') {
1.149 raeburn 1179: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1180: my $choice = $choices{'disallowlogin'};
1181: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1182: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1183: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1184: '<th>'.$choices{'server'}.'</th>'.
1185: '<th>'.$choices{'serverpath'}.'</th>'.
1186: '<th>'.$choices{'custompath'}.'</th>'.
1187: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1188: my %disallowed;
1189: if (ref($settings) eq 'HASH') {
1190: if (ref($settings->{'loginvia'}) eq 'HASH') {
1191: %disallowed = %{$settings->{'loginvia'}};
1192: }
1193: }
1194: foreach my $lonhost (sort(keys(%servers))) {
1195: my $direct = 'selected="selected"';
1.128 raeburn 1196: if (ref($disallowed{$lonhost}) eq 'HASH') {
1197: if ($disallowed{$lonhost}{'server'} ne '') {
1198: $direct = '';
1199: }
1.110 raeburn 1200: }
1.115 raeburn 1201: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1202: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1203: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1204: '</option>';
1.184 raeburn 1205: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1206: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1207: my $selected = '';
1.128 raeburn 1208: if (ref($disallowed{$lonhost}) eq 'HASH') {
1209: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1210: $selected = 'selected="selected"';
1211: }
1.110 raeburn 1212: }
1213: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1214: $servers{$hostid}.'</option>';
1215: }
1.128 raeburn 1216: $datatable .= '</select></td>'.
1217: '<td><select name="'.$lonhost.'_serverpath">';
1218: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1219: my $pathname = $path;
1220: if ($path eq 'custom') {
1221: $pathname = &mt('Custom Path').' ->';
1222: }
1223: my $selected = '';
1224: if (ref($disallowed{$lonhost}) eq 'HASH') {
1225: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1226: $selected = 'selected="selected"';
1227: }
1228: } elsif ($path eq '') {
1229: $selected = 'selected="selected"';
1230: }
1231: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1232: }
1233: $datatable .= '</select></td>';
1234: my ($custom,$exempt);
1235: if (ref($disallowed{$lonhost}) eq 'HASH') {
1236: $custom = $disallowed{$lonhost}{'custompath'};
1237: $exempt = $disallowed{$lonhost}{'exempt'};
1238: }
1239: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1240: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1241: '</tr>';
1.110 raeburn 1242: }
1243: $datatable .= '</table></td></tr>';
1244: return $datatable;
1.168 raeburn 1245: } elsif ($caller eq 'page') {
1246: my %defaultchecked = (
1247: 'coursecatalog' => 'on',
1.188 raeburn 1248: 'helpdesk' => 'on',
1.168 raeburn 1249: 'adminmail' => 'off',
1250: 'newuser' => 'off',
1251: );
1.188 raeburn 1252: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1253: my (%checkedon,%checkedoff);
1.42 raeburn 1254: foreach my $item (@toggles) {
1.168 raeburn 1255: if ($defaultchecked{$item} eq 'on') {
1256: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1257: $checkedoff{$item} = ' ';
1.168 raeburn 1258: } elsif ($defaultchecked{$item} eq 'off') {
1259: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1260: $checkedon{$item} = ' ';
1261: }
1.1 raeburn 1262: }
1.168 raeburn 1263: my @images = ('img','logo','domlogo','login');
1264: my @logintext = ('textcol','bgcol');
1265: my @bgs = ('pgbg','mainbg','sidebg');
1266: my @links = ('link','alink','vlink');
1267: my %designhash = &Apache::loncommon::get_domainconf($dom);
1268: my %defaultdesign = %Apache::loncommon::defaultdesign;
1269: my (%is_custom,%designs);
1270: my %defaults = (
1271: font => $defaultdesign{'login.font'},
1272: );
1.6 raeburn 1273: foreach my $item (@images) {
1.168 raeburn 1274: $defaults{$item} = $defaultdesign{'login.'.$item};
1275: $defaults{'showlogo'}{$item} = 1;
1276: }
1277: foreach my $item (@bgs) {
1278: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1279: }
1.41 raeburn 1280: foreach my $item (@logintext) {
1.168 raeburn 1281: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1282: }
1.168 raeburn 1283: foreach my $item (@links) {
1284: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1285: }
1.168 raeburn 1286: if (ref($settings) eq 'HASH') {
1287: foreach my $item (@toggles) {
1288: if ($settings->{$item} eq '1') {
1289: $checkedon{$item} = ' checked="checked" ';
1290: $checkedoff{$item} = ' ';
1291: } elsif ($settings->{$item} eq '0') {
1292: $checkedoff{$item} = ' checked="checked" ';
1293: $checkedon{$item} = ' ';
1294: }
1295: }
1296: foreach my $item (@images) {
1297: if (defined($settings->{$item})) {
1298: $designs{$item} = $settings->{$item};
1299: $is_custom{$item} = 1;
1300: }
1301: if (defined($settings->{'showlogo'}{$item})) {
1302: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1303: }
1304: }
1305: foreach my $item (@logintext) {
1306: if ($settings->{$item} ne '') {
1307: $designs{'logintext'}{$item} = $settings->{$item};
1308: $is_custom{$item} = 1;
1309: }
1310: }
1311: if ($settings->{'font'} ne '') {
1312: $designs{'font'} = $settings->{'font'};
1313: $is_custom{'font'} = 1;
1314: }
1315: foreach my $item (@bgs) {
1316: if ($settings->{$item} ne '') {
1317: $designs{'bgs'}{$item} = $settings->{$item};
1318: $is_custom{$item} = 1;
1319: }
1320: }
1321: foreach my $item (@links) {
1322: if ($settings->{$item} ne '') {
1323: $designs{'links'}{$item} = $settings->{$item};
1324: $is_custom{$item} = 1;
1325: }
1326: }
1327: } else {
1328: if ($designhash{$dom.'.login.font'} ne '') {
1329: $designs{'font'} = $designhash{$dom.'.login.font'};
1330: $is_custom{'font'} = 1;
1331: }
1332: foreach my $item (@images) {
1333: if ($designhash{$dom.'.login.'.$item} ne '') {
1334: $designs{$item} = $designhash{$dom.'.login.'.$item};
1335: $is_custom{$item} = 1;
1336: }
1337: }
1338: foreach my $item (@bgs) {
1339: if ($designhash{$dom.'.login.'.$item} ne '') {
1340: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1341: $is_custom{$item} = 1;
1342: }
1.6 raeburn 1343: }
1.168 raeburn 1344: foreach my $item (@links) {
1345: if ($designhash{$dom.'.login.'.$item} ne '') {
1346: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1347: $is_custom{$item} = 1;
1348: }
1.6 raeburn 1349: }
1350: }
1.168 raeburn 1351: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1352: logo => 'Institution Logo',
1353: domlogo => 'Domain Logo',
1354: login => 'Login box');
1355: my $itemcount = 1;
1356: foreach my $item (@toggles) {
1357: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1358: $datatable .=
1359: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1360: '</td><td>'.
1361: '<span class="LC_nobreak"><label><input type="radio" name="'.
1362: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1363: '</label> <label><input type="radio" name="'.$item.'"'.
1364: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1365: '</tr>';
1366: $itemcount ++;
1.6 raeburn 1367: }
1.168 raeburn 1368: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1369: $datatable .= '</tr></table></td></tr>';
1370: } elsif ($caller eq 'help') {
1371: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1372: my $switchserver = &check_switchserver($dom,$confname);
1373: my $itemcount = 1;
1374: $defaulturl = '/adm/loginproblems.html';
1375: $defaulttype = 'default';
1376: %lt = &Apache::lonlocal::texthash (
1377: del => 'Delete?',
1378: rep => 'Replace:',
1379: upl => 'Upload:',
1380: default => 'Default',
1381: custom => 'Custom',
1382: );
1383: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1384: my @currlangs;
1385: if (ref($settings) eq 'HASH') {
1386: if (ref($settings->{'helpurl'}) eq 'HASH') {
1387: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1388: next if ($settings->{'helpurl'}{$key} eq '');
1389: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1390: $type{$key} = 'custom';
1391: unless ($key eq 'nolang') {
1392: push(@currlangs,$key);
1393: }
1394: }
1395: } elsif ($settings->{'helpurl'} ne '') {
1396: $type{'nolang'} = 'custom';
1397: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1398: }
1399: }
1.168 raeburn 1400: foreach my $lang ('nolang',sort(@currlangs)) {
1401: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1402: $datatable .= '<tr'.$css_class.'>';
1403: if ($url{$lang} eq '') {
1404: $url{$lang} = $defaulturl;
1405: }
1406: if ($type{$lang} eq '') {
1407: $type{$lang} = $defaulttype;
1408: }
1409: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1410: if ($lang eq 'nolang') {
1411: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1412: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1413: } else {
1414: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1415: $langchoices{$lang},
1416: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1417: }
1418: $datatable .= '</span></td>'."\n".
1419: '<td class="LC_left_item">';
1420: if ($type{$lang} eq 'custom') {
1421: $datatable .= '<span class="LC_nobreak"><label>'.
1422: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1423: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1424: } else {
1425: $datatable .= $lt{'upl'};
1426: }
1427: $datatable .='<br />';
1428: if ($switchserver) {
1429: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1430: } else {
1431: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1432: }
1.168 raeburn 1433: $datatable .= '</td></tr>';
1434: $itemcount ++;
1.6 raeburn 1435: }
1.168 raeburn 1436: my @addlangs;
1437: foreach my $lang (sort(keys(%langchoices))) {
1438: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1439: push(@addlangs,$lang);
1440: }
1441: if (@addlangs > 0) {
1442: my %toadd;
1443: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1444: $toadd{''} = &mt('Select');
1445: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1446: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1447: &mt('Add log-in help page for a specific language:').' '.
1448: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1449: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1450: if ($switchserver) {
1451: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1452: } else {
1453: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1454: }
1.168 raeburn 1455: $datatable .= '</td></tr>';
1.169 raeburn 1456: $itemcount ++;
1.6 raeburn 1457: }
1.169 raeburn 1458: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1459: } elsif ($caller eq 'headtag') {
1460: my %domservers = &Apache::lonnet::get_servers($dom);
1461: my $choice = $choices{'headtag'};
1462: $css_class = ' class="LC_odd_row"';
1463: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1464: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1465: '<th>'.$choices{'current'}.'</th>'.
1466: '<th>'.$choices{'action'}.'</th>'.
1467: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1468: my (%currurls,%currexempt);
1469: if (ref($settings) eq 'HASH') {
1470: if (ref($settings->{'headtag'}) eq 'HASH') {
1471: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1472: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1473: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1474: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1475: }
1476: }
1477: }
1478: }
1479: my %lt = &Apache::lonlocal::texthash(
1480: del => 'Delete?',
1481: rep => 'Replace:',
1482: upl => 'Upload:',
1483: curr => 'View contents',
1484: none => 'None',
1485: );
1486: my $switchserver = &check_switchserver($dom,$confname);
1487: foreach my $lonhost (sort(keys(%domservers))) {
1488: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1489: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1490: if ($currurls{$lonhost}) {
1491: $datatable .= '<td class="LC_right_item"><a href="'.
1492: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1493: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1494: '">'.$lt{'curr'}.'</a></td>'.
1495: '<td><span class="LC_nobreak"><label>'.
1496: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1497: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1498: } else {
1499: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1500: }
1501: $datatable .='<br />';
1502: if ($switchserver) {
1503: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1504: } else {
1505: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1506: }
1.330 raeburn 1507: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1508: }
1509: $datatable .= '</table></td></tr>';
1.1 raeburn 1510: }
1.6 raeburn 1511: return $datatable;
1512: }
1513:
1514: sub login_choices {
1515: my %choices =
1516: &Apache::lonlocal::texthash (
1.116 bisitz 1517: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1518: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1519: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1520: disallowlogin => "Login page requests redirected",
1521: hostid => "Server",
1.128 raeburn 1522: server => "Redirect to:",
1523: serverpath => "Path",
1524: custompath => "Custom",
1525: exempt => "Exempt IP(s)",
1.110 raeburn 1526: directlogin => "No redirect",
1527: newuser => "Link to create a user account",
1528: img => "Header",
1529: logo => "Main Logo",
1530: domlogo => "Domain Logo",
1531: login => "Log-in Header",
1532: textcol => "Text color",
1533: bgcol => "Box color",
1534: bgs => "Background colors",
1535: links => "Link colors",
1536: font => "Font color",
1537: pgbg => "Header",
1538: mainbg => "Page",
1539: sidebg => "Login box",
1540: link => "Link",
1541: alink => "Active link",
1542: vlink => "Visited link",
1.256 raeburn 1543: headtag => "Custom markup",
1544: action => "Action",
1545: current => "Current",
1.6 raeburn 1546: );
1547: return %choices;
1548: }
1549:
1550: sub print_rolecolors {
1.30 raeburn 1551: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1552: my %choices = &color_font_choices();
1553: my @bgs = ('pgbg','tabbg','sidebg');
1554: my @links = ('link','alink','vlink');
1555: my @images = ('img');
1556: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1557: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1558: my %defaultdesign = %Apache::loncommon::defaultdesign;
1559: my (%is_custom,%designs);
1.200 raeburn 1560: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1561: if (ref($settings) eq 'HASH') {
1562: if (ref($settings->{$role}) eq 'HASH') {
1563: if ($settings->{$role}->{'img'} ne '') {
1564: $designs{'img'} = $settings->{$role}->{'img'};
1565: $is_custom{'img'} = 1;
1566: }
1567: if ($settings->{$role}->{'font'} ne '') {
1568: $designs{'font'} = $settings->{$role}->{'font'};
1569: $is_custom{'font'} = 1;
1570: }
1.97 tempelho 1571: if ($settings->{$role}->{'fontmenu'} ne '') {
1572: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1573: $is_custom{'fontmenu'} = 1;
1574: }
1.6 raeburn 1575: foreach my $item (@bgs) {
1576: if ($settings->{$role}->{$item} ne '') {
1577: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1578: $is_custom{$item} = 1;
1579: }
1580: }
1581: foreach my $item (@links) {
1582: if ($settings->{$role}->{$item} ne '') {
1583: $designs{'links'}{$item} = $settings->{$role}->{$item};
1584: $is_custom{$item} = 1;
1585: }
1586: }
1587: }
1588: } else {
1589: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1590: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1591: $is_custom{'img'} = 1;
1592: }
1.97 tempelho 1593: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1594: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1595: $is_custom{'fontmenu'} = 1;
1596: }
1.6 raeburn 1597: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1598: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1599: $is_custom{'font'} = 1;
1600: }
1601: foreach my $item (@bgs) {
1602: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1603: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1604: $is_custom{$item} = 1;
1605:
1606: }
1607: }
1608: foreach my $item (@links) {
1609: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1610: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1611: $is_custom{$item} = 1;
1612: }
1613: }
1614: }
1615: my $itemcount = 1;
1.30 raeburn 1616: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1617: $datatable .= '</tr></table></td></tr>';
1618: return $datatable;
1619: }
1620:
1.200 raeburn 1621: sub role_defaults {
1622: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1623: my %defaults;
1624: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1625: return %defaults;
1626: }
1627: my %defaultdesign = %Apache::loncommon::defaultdesign;
1628: if ($role eq 'login') {
1629: %defaults = (
1630: font => $defaultdesign{$role.'.font'},
1631: );
1632: if (ref($logintext) eq 'ARRAY') {
1633: foreach my $item (@{$logintext}) {
1634: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1635: }
1636: }
1637: foreach my $item (@{$images}) {
1638: $defaults{'showlogo'}{$item} = 1;
1639: }
1640: } else {
1641: %defaults = (
1642: img => $defaultdesign{$role.'.img'},
1643: font => $defaultdesign{$role.'.font'},
1644: fontmenu => $defaultdesign{$role.'.fontmenu'},
1645: );
1646: }
1647: foreach my $item (@{$bgs}) {
1648: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1649: }
1650: foreach my $item (@{$links}) {
1651: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1652: }
1653: foreach my $item (@{$images}) {
1654: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1655: }
1656: return %defaults;
1657: }
1658:
1.6 raeburn 1659: sub display_color_options {
1.9 raeburn 1660: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1661: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1662: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1663: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1664: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1665: '<td>'.$choices->{'font'}.'</td>';
1666: if (!$is_custom->{'font'}) {
1.329 raeburn 1667: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1668: } else {
1669: $datatable .= '<td> </td>';
1670: }
1.174 foxr 1671: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1672:
1.8 raeburn 1673: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1674: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1675: ' value="'.$current_color.'" /> '.
1.329 raeburn 1676: ' </span></td></tr>';
1.107 raeburn 1677: unless ($role eq 'login') {
1678: $datatable .= '<tr'.$css_class.'>'.
1679: '<td>'.$choices->{'fontmenu'}.'</td>';
1680: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 1681: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1682: } else {
1683: $datatable .= '<td> </td>';
1684: }
1.202 raeburn 1685: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1686: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1687: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1688: '<input class="colorchooser" type="text" size="10" name="'
1689: .$role.'_fontmenu"'.
1690: ' value="'.$current_color.'" /> '.
1.329 raeburn 1691: ' </span></td></tr>';
1.97 tempelho 1692: }
1.9 raeburn 1693: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1694: foreach my $img (@{$images}) {
1.18 albertel 1695: $itemcount ++;
1.6 raeburn 1696: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1697: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1698: '<td>'.$choices->{$img};
1.41 raeburn 1699: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1700: if ($role eq 'login') {
1701: if ($img eq 'login') {
1702: $login_hdr_pick =
1.135 bisitz 1703: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1704: $logincolors =
1705: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1706: $designs,$defaults);
1.70 raeburn 1707: } elsif ($img ne 'domlogo') {
1708: $datatable.= &logo_display_options($img,$defaults,$designs);
1709: }
1710: }
1711: $datatable .= '</td>';
1.6 raeburn 1712: if ($designs->{$img} ne '') {
1713: $imgfile = $designs->{$img};
1.18 albertel 1714: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1715: } else {
1716: $imgfile = $defaults->{$img};
1717: }
1718: if ($imgfile) {
1.9 raeburn 1719: my ($showfile,$fullsize);
1720: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1721: my $urldir = $1;
1722: my $filename = $2;
1723: my @info = &Apache::lonnet::stat_file($designs->{$img});
1724: if (@info) {
1725: my $thumbfile = 'tn-'.$filename;
1726: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1727: if (@thumb) {
1728: $showfile = $urldir.'/'.$thumbfile;
1729: } else {
1730: $showfile = $imgfile;
1731: }
1732: } else {
1733: $showfile = '';
1734: }
1735: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1736: $showfile = $imgfile;
1.6 raeburn 1737: my $imgdir = $1;
1738: my $filename = $2;
1.159 raeburn 1739: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1740: $showfile = "/$imgdir/tn-".$filename;
1741: } else {
1.159 raeburn 1742: my $input = $londocroot.$imgfile;
1743: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1744: if (!-e $output) {
1.9 raeburn 1745: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1746: my ($fullwidth,$fullheight) = &check_dimensions($input);
1747: if ($fullwidth ne '' && $fullheight ne '') {
1748: if ($fullwidth > $width && $fullheight > $height) {
1749: my $size = $width.'x'.$height;
1.316 raeburn 1750: my @args = ('convert','-sample',$size,$input,$output);
1751: system({$args[0]} @args);
1.159 raeburn 1752: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1753: }
1754: }
1.6 raeburn 1755: }
1756: }
1.16 raeburn 1757: }
1.6 raeburn 1758: if ($showfile) {
1.40 raeburn 1759: if ($showfile =~ m{^/(adm|res)/}) {
1760: if ($showfile =~ m{^/res/}) {
1761: my $local_showfile =
1762: &Apache::lonnet::filelocation('',$showfile);
1763: &Apache::lonnet::repcopy($local_showfile);
1764: }
1765: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1766: }
1767: if ($imgfile) {
1768: if ($imgfile =~ m{^/(adm|res)/}) {
1769: if ($imgfile =~ m{^/res/}) {
1770: my $local_imgfile =
1771: &Apache::lonnet::filelocation('',$imgfile);
1772: &Apache::lonnet::repcopy($local_imgfile);
1773: }
1774: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1775: } else {
1776: $fullsize = $imgfile;
1777: }
1778: }
1.41 raeburn 1779: $datatable .= '<td>';
1780: if ($img eq 'login') {
1.135 bisitz 1781: $datatable .= $login_hdr_pick;
1782: }
1.41 raeburn 1783: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1784: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1785: } else {
1.201 raeburn 1786: $datatable .= '<td> </td><td class="LC_left_item">'.
1787: &mt('Upload:').'<br />';
1.6 raeburn 1788: }
1789: } else {
1.201 raeburn 1790: $datatable .= '<td> </td><td class="LC_left_item">'.
1791: &mt('Upload:').'<br />';
1.6 raeburn 1792: }
1.9 raeburn 1793: if ($switchserver) {
1794: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1795: } else {
1.135 bisitz 1796: if ($img ne 'login') { # suppress file selection for Log-in header
1797: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1798: }
1.9 raeburn 1799: }
1800: $datatable .= '</td></tr>';
1.6 raeburn 1801: }
1802: $itemcount ++;
1803: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1804: $datatable .= '<tr'.$css_class.'>'.
1805: '<td>'.$choices->{'bgs'}.'</td>';
1806: my $bgs_def;
1807: foreach my $item (@{$bgs}) {
1808: if (!$is_custom->{$item}) {
1.329 raeburn 1809: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span class="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 1810: }
1811: }
1812: if ($bgs_def) {
1.8 raeburn 1813: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1814: } else {
1815: $datatable .= '<td> </td>';
1816: }
1817: $datatable .= '<td class="LC_right_item">'.
1818: '<table border="0"><tr>';
1.174 foxr 1819:
1.6 raeburn 1820: foreach my $item (@{$bgs}) {
1.306 raeburn 1821: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 1822: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1823: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1824: $datatable .= ' ';
1.6 raeburn 1825: }
1.174 foxr 1826: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1827: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1828: }
1829: $datatable .= '</tr></table></td></tr>';
1830: $itemcount ++;
1831: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1832: $datatable .= '<tr'.$css_class.'>'.
1833: '<td>'.$choices->{'links'}.'</td>';
1834: my $links_def;
1835: foreach my $item (@{$links}) {
1836: if (!$is_custom->{$item}) {
1.329 raeburn 1837: $links_def .= '<td>'.$choices->{$item}.'<br /><span class="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1838: }
1839: }
1840: if ($links_def) {
1.8 raeburn 1841: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1842: } else {
1843: $datatable .= '<td> </td>';
1844: }
1845: $datatable .= '<td class="LC_right_item">'.
1846: '<table border="0"><tr>';
1847: foreach my $item (@{$links}) {
1.234 raeburn 1848: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 1849: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 1850: if ($designs->{'links'}{$item}) {
1.174 foxr 1851: $datatable.=' ';
1.6 raeburn 1852: }
1.174 foxr 1853: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1854: '" /></td>';
1855: }
1.30 raeburn 1856: $$rowtotal += $itemcount;
1.3 raeburn 1857: return $datatable;
1858: }
1859:
1.70 raeburn 1860: sub logo_display_options {
1861: my ($img,$defaults,$designs) = @_;
1862: my $checkedon;
1863: if (ref($defaults) eq 'HASH') {
1864: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1865: if ($defaults->{'showlogo'}{$img}) {
1866: $checkedon = 'checked="checked" ';
1867: }
1868: }
1869: }
1870: if (ref($designs) eq 'HASH') {
1871: if (ref($designs->{'showlogo'}) eq 'HASH') {
1872: if (defined($designs->{'showlogo'}{$img})) {
1873: if ($designs->{'showlogo'}{$img} == 0) {
1874: $checkedon = '';
1875: } elsif ($designs->{'showlogo'}{$img} == 1) {
1876: $checkedon = 'checked="checked" ';
1877: }
1878: }
1879: }
1880: }
1881: return '<br /><label> <input type="checkbox" name="'.
1882: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1883: &mt('show').'</label>'."\n";
1884: }
1885:
1.41 raeburn 1886: sub login_header_options {
1.135 bisitz 1887: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1888: my $output = '';
1.41 raeburn 1889: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1890: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1891: if (!$is_custom->{'textcol'}) {
1892: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1893: ' ';
1894: }
1895: if (!$is_custom->{'bgcol'}) {
1896: $output .= $choices->{'bgcol'}.': '.
1897: '<span id="css_'.$role.'_font" style="background-color: '.
1898: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1899: }
1900: $output .= '<br />';
1901: }
1902: $output .='<br />';
1903: return $output;
1904: }
1905:
1906: sub login_text_colors {
1.201 raeburn 1907: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1908: my $color_menu = '<table border="0"><tr>';
1909: foreach my $item (@{$logintext}) {
1.306 raeburn 1910: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 1911: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1912: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1913: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1914: }
1915: $color_menu .= '</tr></table><br />';
1916: return $color_menu;
1917: }
1918:
1919: sub image_changes {
1920: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1921: my $output;
1.135 bisitz 1922: if ($img eq 'login') {
1.331 raeburn 1923: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 1924: } elsif (!$is_custom) {
1.70 raeburn 1925: if ($img ne 'domlogo') {
1.331 raeburn 1926: $output = &mt('Default image:').'<br />';
1.41 raeburn 1927: } else {
1.331 raeburn 1928: $output = &mt('Default in use:').'<br />';
1.41 raeburn 1929: }
1930: }
1.331 raeburn 1931: if ($img ne 'login') {
1.135 bisitz 1932: if ($img_import) {
1933: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1934: }
1935: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1936: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1937: if ($is_custom) {
1938: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1939: '<input type="checkbox" name="'.
1940: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1941: '</label> '.&mt('Replace:').'</span><br />';
1942: } else {
1.306 raeburn 1943: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1944: }
1.41 raeburn 1945: }
1946: return $output;
1947: }
1948:
1.3 raeburn 1949: sub print_quotas {
1.86 raeburn 1950: my ($dom,$settings,$rowtotal,$action) = @_;
1951: my $context;
1952: if ($action eq 'quotas') {
1953: $context = 'tools';
1954: } else {
1955: $context = $action;
1956: }
1.197 raeburn 1957: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1958: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1959: my $typecount = 0;
1.101 raeburn 1960: my ($css_class,%titles);
1.86 raeburn 1961: if ($context eq 'requestcourses') {
1.325 raeburn 1962: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 1963: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1964: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1965: %titles = &courserequest_titles();
1.163 raeburn 1966: } elsif ($context eq 'requestauthor') {
1967: @usertools = ('author');
1968: @options = ('norequest','approval','automatic');
1.210 raeburn 1969: %titles = &authorrequest_titles();
1.86 raeburn 1970: } else {
1.162 raeburn 1971: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1972: %titles = &tool_titles();
1.86 raeburn 1973: }
1.26 raeburn 1974: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1975: foreach my $type (@{$types}) {
1.197 raeburn 1976: my ($currdefquota,$currauthorquota);
1.163 raeburn 1977: unless (($context eq 'requestcourses') ||
1978: ($context eq 'requestauthor')) {
1.86 raeburn 1979: if (ref($settings) eq 'HASH') {
1980: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1981: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1982: } else {
1983: $currdefquota = $settings->{$type};
1984: }
1.197 raeburn 1985: if (ref($settings->{authorquota}) eq 'HASH') {
1986: $currauthorquota = $settings->{authorquota}->{$type};
1987: }
1.78 raeburn 1988: }
1.72 raeburn 1989: }
1.3 raeburn 1990: if (defined($usertypes->{$type})) {
1991: $typecount ++;
1992: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1993: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1994: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1995: '<td class="LC_left_item">';
1.101 raeburn 1996: if ($context eq 'requestcourses') {
1997: $datatable .= '<table><tr>';
1998: }
1999: my %cell;
1.72 raeburn 2000: foreach my $item (@usertools) {
1.101 raeburn 2001: if ($context eq 'requestcourses') {
2002: my ($curroption,$currlimit);
2003: if (ref($settings) eq 'HASH') {
2004: if (ref($settings->{$item}) eq 'HASH') {
2005: $curroption = $settings->{$item}->{$type};
2006: if ($curroption =~ /^autolimit=(\d*)$/) {
2007: $currlimit = $1;
2008: }
2009: }
2010: }
2011: if (!$curroption) {
2012: $curroption = 'norequest';
2013: }
2014: $datatable .= '<th>'.$titles{$item}.'</th>';
2015: foreach my $option (@options) {
2016: my $val = $option;
2017: if ($option eq 'norequest') {
2018: $val = 0;
2019: }
2020: if ($option eq 'validate') {
2021: my $canvalidate = 0;
2022: if (ref($validations{$item}) eq 'HASH') {
2023: if ($validations{$item}{$type}) {
2024: $canvalidate = 1;
2025: }
2026: }
2027: next if (!$canvalidate);
2028: }
2029: my $checked = '';
2030: if ($option eq $curroption) {
2031: $checked = ' checked="checked"';
2032: } elsif ($option eq 'autolimit') {
2033: if ($curroption =~ /^autolimit/) {
2034: $checked = ' checked="checked"';
2035: }
2036: }
2037: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2038: '<input type="radio" name="crsreq_'.$item.
2039: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2040: $titles{$option}.'</label>';
1.101 raeburn 2041: if ($option eq 'autolimit') {
1.127 raeburn 2042: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2043: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2044: 'value="'.$currlimit.'" />';
1.101 raeburn 2045: }
1.127 raeburn 2046: $cell{$item} .= '</span> ';
1.103 raeburn 2047: if ($option eq 'autolimit') {
1.127 raeburn 2048: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2049: }
1.101 raeburn 2050: }
1.163 raeburn 2051: } elsif ($context eq 'requestauthor') {
2052: my $curroption;
2053: if (ref($settings) eq 'HASH') {
2054: $curroption = $settings->{$type};
2055: }
2056: if (!$curroption) {
2057: $curroption = 'norequest';
2058: }
2059: foreach my $option (@options) {
2060: my $val = $option;
2061: if ($option eq 'norequest') {
2062: $val = 0;
2063: }
2064: my $checked = '';
2065: if ($option eq $curroption) {
2066: $checked = ' checked="checked"';
2067: }
2068: $datatable .= '<span class="LC_nobreak"><label>'.
2069: '<input type="radio" name="authorreq_'.$type.
2070: '" value="'.$val.'"'.$checked.' />'.
2071: $titles{$option}.'</label></span> ';
2072: }
1.101 raeburn 2073: } else {
2074: my $checked = 'checked="checked" ';
2075: if (ref($settings) eq 'HASH') {
2076: if (ref($settings->{$item}) eq 'HASH') {
2077: if ($settings->{$item}->{$type} == 0) {
2078: $checked = '';
2079: } elsif ($settings->{$item}->{$type} == 1) {
2080: $checked = 'checked="checked" ';
2081: }
1.78 raeburn 2082: }
1.72 raeburn 2083: }
1.101 raeburn 2084: $datatable .= '<span class="LC_nobreak"><label>'.
2085: '<input type="checkbox" name="'.$context.'_'.$item.
2086: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2087: '</label></span> ';
1.72 raeburn 2088: }
1.101 raeburn 2089: }
2090: if ($context eq 'requestcourses') {
2091: $datatable .= '</tr><tr>';
2092: foreach my $item (@usertools) {
1.106 raeburn 2093: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2094: }
2095: $datatable .= '</tr></table>';
1.72 raeburn 2096: }
1.86 raeburn 2097: $datatable .= '</td>';
1.163 raeburn 2098: unless (($context eq 'requestcourses') ||
2099: ($context eq 'requestauthor')) {
1.86 raeburn 2100: $datatable .=
1.197 raeburn 2101: '<td class="LC_right_item">'.
2102: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2103: '<input type="text" name="quota_'.$type.
1.72 raeburn 2104: '" value="'.$currdefquota.
1.197 raeburn 2105: '" size="5" /></span>'.(' ' x 2).
2106: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2107: '<input type="text" name="authorquota_'.$type.
2108: '" value="'.$currauthorquota.
2109: '" size="5" /></span></td>';
1.86 raeburn 2110: }
2111: $datatable .= '</tr>';
1.3 raeburn 2112: }
2113: }
2114: }
1.163 raeburn 2115: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2116: $defaultquota = '20';
1.197 raeburn 2117: $authorquota = '500';
1.86 raeburn 2118: if (ref($settings) eq 'HASH') {
2119: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2120: $defaultquota = $settings->{'defaultquota'}->{'default'};
2121: } elsif (defined($settings->{'default'})) {
2122: $defaultquota = $settings->{'default'};
2123: }
1.197 raeburn 2124: if (ref($settings->{'authorquota'}) eq 'HASH') {
2125: $authorquota = $settings->{'authorquota'}->{'default'};
2126: }
1.3 raeburn 2127: }
2128: }
2129: $typecount ++;
2130: $css_class = $typecount%2?' class="LC_odd_row"':'';
2131: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2132: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2133: '<td class="LC_left_item">';
1.101 raeburn 2134: if ($context eq 'requestcourses') {
2135: $datatable .= '<table><tr>';
2136: }
2137: my %defcell;
1.72 raeburn 2138: foreach my $item (@usertools) {
1.101 raeburn 2139: if ($context eq 'requestcourses') {
2140: my ($curroption,$currlimit);
2141: if (ref($settings) eq 'HASH') {
2142: if (ref($settings->{$item}) eq 'HASH') {
2143: $curroption = $settings->{$item}->{'default'};
2144: if ($curroption =~ /^autolimit=(\d*)$/) {
2145: $currlimit = $1;
2146: }
2147: }
2148: }
2149: if (!$curroption) {
2150: $curroption = 'norequest';
2151: }
2152: $datatable .= '<th>'.$titles{$item}.'</th>';
2153: foreach my $option (@options) {
2154: my $val = $option;
2155: if ($option eq 'norequest') {
2156: $val = 0;
2157: }
2158: if ($option eq 'validate') {
2159: my $canvalidate = 0;
2160: if (ref($validations{$item}) eq 'HASH') {
2161: if ($validations{$item}{'default'}) {
2162: $canvalidate = 1;
2163: }
2164: }
2165: next if (!$canvalidate);
2166: }
2167: my $checked = '';
2168: if ($option eq $curroption) {
2169: $checked = ' checked="checked"';
2170: } elsif ($option eq 'autolimit') {
2171: if ($curroption =~ /^autolimit/) {
2172: $checked = ' checked="checked"';
2173: }
2174: }
2175: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2176: '<input type="radio" name="crsreq_'.$item.
2177: '_default" value="'.$val.'"'.$checked.' />'.
2178: $titles{$option}.'</label>';
2179: if ($option eq 'autolimit') {
1.127 raeburn 2180: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2181: $item.'_limit_default" size="1" '.
2182: 'value="'.$currlimit.'" />';
2183: }
1.127 raeburn 2184: $defcell{$item} .= '</span> ';
1.104 raeburn 2185: if ($option eq 'autolimit') {
1.127 raeburn 2186: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2187: }
1.101 raeburn 2188: }
1.163 raeburn 2189: } elsif ($context eq 'requestauthor') {
2190: my $curroption;
2191: if (ref($settings) eq 'HASH') {
1.172 raeburn 2192: $curroption = $settings->{'default'};
1.163 raeburn 2193: }
2194: if (!$curroption) {
2195: $curroption = 'norequest';
2196: }
2197: foreach my $option (@options) {
2198: my $val = $option;
2199: if ($option eq 'norequest') {
2200: $val = 0;
2201: }
2202: my $checked = '';
2203: if ($option eq $curroption) {
2204: $checked = ' checked="checked"';
2205: }
2206: $datatable .= '<span class="LC_nobreak"><label>'.
2207: '<input type="radio" name="authorreq_default"'.
2208: ' value="'.$val.'"'.$checked.' />'.
2209: $titles{$option}.'</label></span> ';
2210: }
1.101 raeburn 2211: } else {
2212: my $checked = 'checked="checked" ';
2213: if (ref($settings) eq 'HASH') {
2214: if (ref($settings->{$item}) eq 'HASH') {
2215: if ($settings->{$item}->{'default'} == 0) {
2216: $checked = '';
2217: } elsif ($settings->{$item}->{'default'} == 1) {
2218: $checked = 'checked="checked" ';
2219: }
1.78 raeburn 2220: }
1.72 raeburn 2221: }
1.101 raeburn 2222: $datatable .= '<span class="LC_nobreak"><label>'.
2223: '<input type="checkbox" name="'.$context.'_'.$item.
2224: '" value="default" '.$checked.'/>'.$titles{$item}.
2225: '</label></span> ';
2226: }
2227: }
2228: if ($context eq 'requestcourses') {
2229: $datatable .= '</tr><tr>';
2230: foreach my $item (@usertools) {
1.106 raeburn 2231: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2232: }
1.101 raeburn 2233: $datatable .= '</tr></table>';
1.72 raeburn 2234: }
1.86 raeburn 2235: $datatable .= '</td>';
1.163 raeburn 2236: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2237: $datatable .= '<td class="LC_right_item">'.
2238: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2239: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2240: $defaultquota.'" size="5" /></span>'.(' ' x2).
2241: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2242: '<input type="text" name="authorquota" value="'.
2243: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2244: }
2245: $datatable .= '</tr>';
1.72 raeburn 2246: $typecount ++;
2247: $css_class = $typecount%2?' class="LC_odd_row"':'';
2248: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2249: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2250: if ($context eq 'requestcourses') {
1.109 raeburn 2251: $datatable .= &mt('(overrides affiliation, if set)').
2252: '</td>'.
2253: '<td class="LC_left_item">'.
2254: '<table><tr>';
1.101 raeburn 2255: } else {
1.109 raeburn 2256: $datatable .= &mt('(overrides affiliation, if checked)').
2257: '</td>'.
2258: '<td class="LC_left_item" colspan="2">'.
2259: '<br />';
1.101 raeburn 2260: }
2261: my %advcell;
1.72 raeburn 2262: foreach my $item (@usertools) {
1.101 raeburn 2263: if ($context eq 'requestcourses') {
2264: my ($curroption,$currlimit);
2265: if (ref($settings) eq 'HASH') {
2266: if (ref($settings->{$item}) eq 'HASH') {
2267: $curroption = $settings->{$item}->{'_LC_adv'};
2268: if ($curroption =~ /^autolimit=(\d*)$/) {
2269: $currlimit = $1;
2270: }
2271: }
2272: }
2273: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2274: my $checked = '';
2275: if ($curroption eq '') {
2276: $checked = ' checked="checked"';
2277: }
2278: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2279: '<input type="radio" name="crsreq_'.$item.
2280: '__LC_adv" value=""'.$checked.' />'.
2281: &mt('No override set').'</label></span> ';
1.101 raeburn 2282: foreach my $option (@options) {
2283: my $val = $option;
2284: if ($option eq 'norequest') {
2285: $val = 0;
2286: }
2287: if ($option eq 'validate') {
2288: my $canvalidate = 0;
2289: if (ref($validations{$item}) eq 'HASH') {
2290: if ($validations{$item}{'_LC_adv'}) {
2291: $canvalidate = 1;
2292: }
2293: }
2294: next if (!$canvalidate);
2295: }
2296: my $checked = '';
1.104 raeburn 2297: if ($val eq $curroption) {
1.101 raeburn 2298: $checked = ' checked="checked"';
2299: } elsif ($option eq 'autolimit') {
2300: if ($curroption =~ /^autolimit/) {
2301: $checked = ' checked="checked"';
2302: }
2303: }
2304: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2305: '<input type="radio" name="crsreq_'.$item.
2306: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2307: $titles{$option}.'</label>';
2308: if ($option eq 'autolimit') {
1.127 raeburn 2309: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2310: $item.'_limit__LC_adv" size="1" '.
2311: 'value="'.$currlimit.'" />';
2312: }
1.127 raeburn 2313: $advcell{$item} .= '</span> ';
1.104 raeburn 2314: if ($option eq 'autolimit') {
1.127 raeburn 2315: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2316: }
1.101 raeburn 2317: }
1.163 raeburn 2318: } elsif ($context eq 'requestauthor') {
2319: my $curroption;
2320: if (ref($settings) eq 'HASH') {
2321: $curroption = $settings->{'_LC_adv'};
2322: }
2323: my $checked = '';
2324: if ($curroption eq '') {
2325: $checked = ' checked="checked"';
2326: }
2327: $datatable .= '<span class="LC_nobreak"><label>'.
2328: '<input type="radio" name="authorreq__LC_adv"'.
2329: ' value=""'.$checked.' />'.
2330: &mt('No override set').'</label></span> ';
2331: foreach my $option (@options) {
2332: my $val = $option;
2333: if ($option eq 'norequest') {
2334: $val = 0;
2335: }
2336: my $checked = '';
2337: if ($val eq $curroption) {
2338: $checked = ' checked="checked"';
2339: }
2340: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2341: '<input type="radio" name="authorreq__LC_adv"'.
2342: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2343: $titles{$option}.'</label></span> ';
2344: }
1.101 raeburn 2345: } else {
2346: my $checked = 'checked="checked" ';
2347: if (ref($settings) eq 'HASH') {
2348: if (ref($settings->{$item}) eq 'HASH') {
2349: if ($settings->{$item}->{'_LC_adv'} == 0) {
2350: $checked = '';
2351: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2352: $checked = 'checked="checked" ';
2353: }
1.79 raeburn 2354: }
1.72 raeburn 2355: }
1.101 raeburn 2356: $datatable .= '<span class="LC_nobreak"><label>'.
2357: '<input type="checkbox" name="'.$context.'_'.$item.
2358: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2359: '</label></span> ';
2360: }
2361: }
2362: if ($context eq 'requestcourses') {
2363: $datatable .= '</tr><tr>';
2364: foreach my $item (@usertools) {
1.106 raeburn 2365: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2366: }
1.101 raeburn 2367: $datatable .= '</tr></table>';
1.72 raeburn 2368: }
1.98 raeburn 2369: $datatable .= '</td></tr>';
1.30 raeburn 2370: $$rowtotal += $typecount;
1.3 raeburn 2371: return $datatable;
2372: }
2373:
1.163 raeburn 2374: sub print_requestmail {
1.305 raeburn 2375: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2376: my ($now,$datatable,%currapp);
1.102 raeburn 2377: $now = time;
2378: if (ref($settings) eq 'HASH') {
2379: if (ref($settings->{'notify'}) eq 'HASH') {
2380: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2381: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2382: }
2383: }
2384: }
1.191 raeburn 2385: my $numinrow = 2;
1.224 raeburn 2386: my $css_class;
1.305 raeburn 2387: if ($$rowtotal%2) {
2388: $css_class = 'LC_odd_row';
2389: }
2390: if ($customcss) {
2391: $css_class .= " $customcss";
2392: }
2393: $css_class =~ s/^\s+//;
2394: if ($css_class) {
2395: $css_class = ' class="'.$css_class.'"';
2396: }
2397: if ($rowstyle) {
2398: $css_class .= ' style="'.$rowstyle.'"';
2399: }
1.163 raeburn 2400: my $text;
2401: if ($action eq 'requestcourses') {
2402: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2403: } elsif ($action eq 'requestauthor') {
2404: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2405: } else {
1.224 raeburn 2406: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2407: }
1.224 raeburn 2408: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2409: ' <td>'.$text.'</td>'.
1.102 raeburn 2410: ' <td class="LC_left_item">';
1.191 raeburn 2411: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2412: $action.'notifyapproval',%currapp);
1.191 raeburn 2413: if ($numdc > 0) {
2414: $datatable .= $table;
1.102 raeburn 2415: } else {
2416: $datatable .= &mt('There are no active Domain Coordinators');
2417: }
2418: $datatable .='</td></tr>';
2419: return $datatable;
2420: }
2421:
1.216 raeburn 2422: sub print_studentcode {
2423: my ($settings,$rowtotal) = @_;
2424: my $rownum = 0;
1.218 raeburn 2425: my ($output,%current);
1.325 raeburn 2426: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2427: if (ref($settings) eq 'HASH') {
2428: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2429: foreach my $type (@crstypes) {
2430: $current{$type} = $settings->{'uniquecode'}{$type};
2431: }
1.218 raeburn 2432: }
2433: }
2434: $output .= '<tr>'.
2435: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2436: '<td class="LC_left_item">';
2437: foreach my $type (@crstypes) {
2438: my $check = ' ';
2439: if ($current{$type}) {
2440: $check = ' checked="checked" ';
2441: }
2442: $output .= '<span class="LC_nobreak"><label>'.
2443: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2444: &mt($type).'</label></span>'.(' 'x2).' ';
2445: }
2446: $output .= '</td></tr>';
2447: $$rowtotal ++;
2448: return $output;
1.216 raeburn 2449: }
2450:
2451: sub print_textbookcourses {
1.242 raeburn 2452: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2453: my $rownum = 0;
2454: my $css_class;
2455: my $itemcount = 1;
2456: my $maxnum = 0;
2457: my $bookshash;
2458: if (ref($settings) eq 'HASH') {
1.242 raeburn 2459: $bookshash = $settings->{$type};
1.216 raeburn 2460: }
2461: my %ordered;
2462: if (ref($bookshash) eq 'HASH') {
2463: foreach my $item (keys(%{$bookshash})) {
2464: if (ref($bookshash->{$item}) eq 'HASH') {
2465: my $num = $bookshash->{$item}{'order'};
2466: $ordered{$num} = $item;
2467: }
2468: }
2469: }
2470: my $confname = $dom.'-domainconfig';
2471: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2472: my $maxnum = scalar(keys(%ordered));
2473: my $datatable;
1.216 raeburn 2474: if (keys(%ordered)) {
2475: my @items = sort { $a <=> $b } keys(%ordered);
2476: for (my $i=0; $i<@items; $i++) {
2477: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2478: my $key = $ordered{$items[$i]};
2479: my %coursehash=&Apache::lonnet::coursedescription($key);
2480: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2481: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2482: if (ref($bookshash->{$key}) eq 'HASH') {
2483: $subject = $bookshash->{$key}->{'subject'};
2484: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2485: if ($type eq 'textbooks') {
1.243 raeburn 2486: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2487: $author = $bookshash->{$key}->{'author'};
2488: $image = $bookshash->{$key}->{'image'};
2489: if ($image ne '') {
2490: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2491: my $imagethumb = "$path/tn-".$imagefile;
2492: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2493: }
1.216 raeburn 2494: }
2495: }
1.242 raeburn 2496: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2497: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2498: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2499: for (my $k=0; $k<=$maxnum; $k++) {
2500: my $vpos = $k+1;
2501: my $selstr;
2502: if ($k == $i) {
2503: $selstr = ' selected="selected" ';
2504: }
2505: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2506: }
2507: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2508: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2509: &mt('Delete?').'</label></span></td>'.
2510: '<td colspan="2">'.
1.242 raeburn 2511: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2512: (' 'x2).
1.242 raeburn 2513: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2514: if ($type eq 'textbooks') {
2515: $datatable .= (' 'x2).
1.243 raeburn 2516: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2517: (' 'x2).
1.242 raeburn 2518: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2519: (' 'x2).
2520: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2521: if ($image) {
1.267 raeburn 2522: $datatable .= $imgsrc.
1.242 raeburn 2523: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2524: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2525: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2526: }
2527: if ($switchserver) {
2528: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2529: } else {
2530: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2531: }
1.216 raeburn 2532: }
1.242 raeburn 2533: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2534: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2535: $coursetitle.'</span></td></tr>'."\n";
2536: $itemcount ++;
2537: }
2538: }
2539: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2540: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2541: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2542: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2543: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2544: for (my $k=0; $k<$maxnum+1; $k++) {
2545: my $vpos = $k+1;
2546: my $selstr;
2547: if ($k == $maxnum) {
2548: $selstr = ' selected="selected" ';
2549: }
2550: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2551: }
2552: $datatable .= '</select> '."\n".
1.334 raeburn 2553: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 2554: '<td colspan="2">'.
1.242 raeburn 2555: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2556: (' 'x2).
1.242 raeburn 2557: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2558: (' 'x2);
2559: if ($type eq 'textbooks') {
1.243 raeburn 2560: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2561: (' 'x2).
2562: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2563: (' 'x2).
2564: '<span class="LC_nobreak">'.&mt('Image:').' ';
2565: if ($switchserver) {
2566: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2567: } else {
2568: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2569: }
1.334 raeburn 2570: $datatable .= '</span>'."\n";
1.216 raeburn 2571: }
1.334 raeburn 2572: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2573: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2574: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2575: &Apache::loncommon::selectcourse_link
1.334 raeburn 2576: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 2577: '</span></td>'."\n".
2578: '</tr>'."\n";
2579: $itemcount ++;
2580: return $datatable;
2581: }
2582:
1.217 raeburn 2583: sub textbookcourses_javascript {
1.242 raeburn 2584: my ($settings) = @_;
2585: return unless(ref($settings) eq 'HASH');
2586: my (%ordered,%total,%jstext);
2587: foreach my $type ('textbooks','templates') {
2588: $total{$type} = 0;
2589: if (ref($settings->{$type}) eq 'HASH') {
2590: foreach my $item (keys(%{$settings->{$type}})) {
2591: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2592: my $num = $settings->{$type}->{$item}{'order'};
2593: $ordered{$type}{$num} = $item;
2594: }
2595: }
2596: $total{$type} = scalar(keys(%{$settings->{$type}}));
2597: }
2598: my @jsarray = ();
2599: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2600: push(@jsarray,$ordered{$type}{$item});
2601: }
2602: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2603: }
2604: return <<"ENDSCRIPT";
2605: <script type="text/javascript">
2606: // <![CDATA[
1.242 raeburn 2607: function reorderBooks(form,item,caller) {
1.217 raeburn 2608: var changedVal;
1.242 raeburn 2609: $jstext{'textbooks'};
2610: $jstext{'templates'};
2611: var newpos;
2612: var maxh;
2613: if (caller == 'textbooks') {
2614: newpos = 'textbooks_addbook_pos';
2615: maxh = 1 + $total{'textbooks'};
2616: } else {
2617: newpos = 'templates_addbook_pos';
2618: maxh = 1 + $total{'templates'};
2619: }
1.217 raeburn 2620: var current = new Array;
2621: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2622: if (item == newpos) {
2623: changedVal = newitemVal;
2624: } else {
2625: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2626: current[newitemVal] = newpos;
2627: }
1.242 raeburn 2628: if (caller == 'textbooks') {
2629: for (var i=0; i<textbooks.length; i++) {
2630: var elementName = 'textbooks_'+textbooks[i];
2631: if (elementName != item) {
2632: if (form.elements[elementName]) {
2633: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2634: current[currVal] = elementName;
2635: }
2636: }
2637: }
2638: }
2639: if (caller == 'templates') {
2640: for (var i=0; i<templates.length; i++) {
2641: var elementName = 'templates_'+templates[i];
2642: if (elementName != item) {
2643: if (form.elements[elementName]) {
2644: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2645: current[currVal] = elementName;
2646: }
1.217 raeburn 2647: }
2648: }
2649: }
2650: var oldVal;
2651: for (var j=0; j<maxh; j++) {
2652: if (current[j] == undefined) {
2653: oldVal = j;
2654: }
2655: }
2656: if (oldVal < changedVal) {
2657: for (var k=oldVal+1; k<=changedVal ; k++) {
2658: var elementName = current[k];
2659: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2660: }
2661: } else {
2662: for (var k=changedVal; k<oldVal; k++) {
2663: var elementName = current[k];
2664: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2665: }
2666: }
2667: return;
2668: }
2669:
2670: // ]]>
2671: </script>
2672:
2673: ENDSCRIPT
2674: }
2675:
1.267 raeburn 2676: sub ltitools_javascript {
2677: my ($settings) = @_;
1.319 raeburn 2678: my $togglejs = <itools_toggle_js();
2679: unless (ref($settings) eq 'HASH') {
2680: return $togglejs;
2681: }
1.267 raeburn 2682: my (%ordered,$total,%jstext);
2683: $total = 0;
2684: foreach my $item (keys(%{$settings})) {
2685: if (ref($settings->{$item}) eq 'HASH') {
2686: my $num = $settings->{$item}{'order'};
2687: $ordered{$num} = $item;
2688: }
2689: }
2690: $total = scalar(keys(%{$settings}));
2691: my @jsarray = ();
2692: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2693: push(@jsarray,$ordered{$item});
2694: }
2695: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2696: return <<"ENDSCRIPT";
2697: <script type="text/javascript">
2698: // <![CDATA[
1.319 raeburn 2699: function reorderLTITools(form,item) {
1.267 raeburn 2700: var changedVal;
2701: $jstext
2702: var newpos = 'ltitools_add_pos';
2703: var maxh = 1 + $total;
2704: var current = new Array;
2705: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2706: if (item == newpos) {
2707: changedVal = newitemVal;
2708: } else {
2709: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2710: current[newitemVal] = newpos;
2711: }
2712: for (var i=0; i<ltitools.length; i++) {
2713: var elementName = 'ltitools_'+ltitools[i];
2714: if (elementName != item) {
2715: if (form.elements[elementName]) {
2716: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2717: current[currVal] = elementName;
2718: }
2719: }
2720: }
2721: var oldVal;
2722: for (var j=0; j<maxh; j++) {
2723: if (current[j] == undefined) {
2724: oldVal = j;
2725: }
2726: }
2727: if (oldVal < changedVal) {
2728: for (var k=oldVal+1; k<=changedVal ; k++) {
2729: var elementName = current[k];
2730: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2731: }
2732: } else {
2733: for (var k=changedVal; k<oldVal; k++) {
2734: var elementName = current[k];
2735: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2736: }
2737: }
2738: return;
2739: }
2740:
2741: // ]]>
2742: </script>
2743:
1.319 raeburn 2744: $togglejs
2745:
2746: ENDSCRIPT
2747: }
2748:
2749: sub ltitools_toggle_js {
2750: return <<"ENDSCRIPT";
2751: <script type="text/javascript">
2752: // <![CDATA[
2753:
2754: function toggleLTITools(form,setting,item) {
2755: var radioname = '';
2756: var divid = '';
2757: if ((setting == 'passback') || (setting == 'roster')) {
2758: radioname = 'ltitools_'+setting+'_'+item;
2759: divid = 'ltitools_'+setting+'time_'+item;
2760: var num = form.elements[radioname].length;
2761: if (num) {
2762: var setvis = '';
2763: for (var i=0; i<num; i++) {
2764: if (form.elements[radioname][i].checked) {
2765: if (form.elements[radioname][i].value == '1') {
2766: if (document.getElementById(divid)) {
2767: document.getElementById(divid).style.display = 'inline-block';
2768: }
2769: setvis = 1;
2770: }
2771: break;
2772: }
2773: }
2774: }
2775: if (!setvis) {
2776: if (document.getElementById(divid)) {
2777: document.getElementById(divid).style.display = 'none';
2778: }
2779: }
2780: }
1.324 raeburn 2781: if (setting == 'user') {
2782: divid = 'ltitools_'+setting+'_div_'+item;
2783: var checkid = 'ltitools_'+setting+'_field_'+item;
2784: if (document.getElementById(divid)) {
2785: if (document.getElementById(checkid)) {
2786: if (document.getElementById(checkid).checked) {
2787: document.getElementById(divid).style.display = 'inline-block';
2788: } else {
2789: document.getElementById(divid).style.display = 'none';
2790: }
2791: }
2792: }
2793: }
1.319 raeburn 2794: return;
2795: }
2796: // ]]>
2797: </script>
2798:
1.267 raeburn 2799: ENDSCRIPT
2800: }
2801:
1.320 raeburn 2802: sub lti_javascript {
2803: my ($settings) = @_;
2804: my $togglejs = <i_toggle_js();
2805: unless (ref($settings) eq 'HASH') {
2806: return $togglejs;
2807: }
2808: my (%ordered,$total,%jstext);
2809: $total = 0;
2810: foreach my $item (keys(%{$settings})) {
2811: if (ref($settings->{$item}) eq 'HASH') {
2812: my $num = $settings->{$item}{'order'};
2813: $ordered{$num} = $item;
2814: }
2815: }
2816: $total = scalar(keys(%{$settings}));
2817: my @jsarray = ();
2818: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2819: push(@jsarray,$ordered{$item});
2820: }
2821: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
2822: return <<"ENDSCRIPT";
2823: <script type="text/javascript">
2824: // <![CDATA[
2825: function reorderLTI(form,item) {
2826: var changedVal;
2827: $jstext
2828: var newpos = 'lti_pos_add';
2829: var maxh = 1 + $total;
2830: var current = new Array;
2831: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2832: if (item == newpos) {
2833: changedVal = newitemVal;
2834: } else {
2835: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2836: current[newitemVal] = newpos;
2837: }
2838: for (var i=0; i<lti.length; i++) {
2839: var elementName = 'lti_pos_'+lti[i];
2840: if (elementName != item) {
2841: if (form.elements[elementName]) {
2842: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2843: current[currVal] = elementName;
2844: }
2845: }
2846: }
2847: var oldVal;
2848: for (var j=0; j<maxh; j++) {
2849: if (current[j] == undefined) {
2850: oldVal = j;
2851: }
2852: }
2853: if (oldVal < changedVal) {
2854: for (var k=oldVal+1; k<=changedVal ; k++) {
2855: var elementName = current[k];
2856: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2857: }
2858: } else {
2859: for (var k=changedVal; k<oldVal; k++) {
2860: var elementName = current[k];
2861: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2862: }
2863: }
2864: return;
2865: }
2866: // ]]>
2867: </script>
2868:
2869: $togglejs
2870:
2871: ENDSCRIPT
2872: }
2873:
2874: sub lti_toggle_js {
1.325 raeburn 2875: my %lcauthparmtext = &Apache::lonlocal::texthash (
2876: localauth => 'Local auth argument',
2877: krb => 'Kerberos domain',
2878: );
1.320 raeburn 2879: return <<"ENDSCRIPT";
2880: <script type="text/javascript">
2881: // <![CDATA[
2882:
2883: function toggleLTI(form,setting,item) {
1.345 raeburn 2884: if (setting == 'requser') {
2885: var fieldsets = document.getElementsByClassName('ltioption_'+item);
2886: if (fieldsets.length) {
2887: var radioname = 'lti_'+setting+'_'+item;
2888: var num = form.elements[radioname].length;
2889: if (num) {
2890: var setvis = '';
2891: for (var i=0; i<num; i++) {
2892: if (form.elements[radioname][i].checked) {
2893: if (form.elements[radioname][i].value == '1') {
2894: setvis = 1;
2895: break;
2896: }
2897: }
2898: }
1.352 raeburn 2899: for (var j=0; j<fieldsets.length; j++) {
1.345 raeburn 2900: if (setvis) {
2901: fieldsets[j].style.display = 'block';
2902: } else {
2903: fieldsets[j].style.display = 'none';
2904: }
2905: }
2906: }
2907: }
2908: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback')) {
1.320 raeburn 2909: var radioname = '';
2910: var divid = '';
2911: if (setting == 'user') {
2912: radioname = 'lti_mapuser_'+item;
2913: divid = 'lti_userfield_'+item;
1.343 raeburn 2914: } else if (setting == 'crs') {
1.320 raeburn 2915: radioname = 'lti_mapcrs_'+item;
2916: divid = 'lti_crsfield_'+item;
1.337 raeburn 2917: } else {
1.351 raeburn 2918: radioname = 'lti_passback_'+item;
1.337 raeburn 2919: divid = 'lti_passback_'+item;
1.320 raeburn 2920: }
2921: var num = form.elements[radioname].length;
2922: if (num) {
2923: var setvis = '';
2924: for (var i=0; i<num; i++) {
2925: if (form.elements[radioname][i].checked) {
1.337 raeburn 2926: if (setting == 'passback') {
2927: if (form.elements[radioname][i].value == '1') {
2928: if (document.getElementById(divid)) {
2929: document.getElementById(divid).style.display = 'inline-block';
2930: }
2931: setvis = 1;
2932: break;
2933: }
2934: } else {
2935: if (form.elements[radioname][i].value == 'other') {
2936: if (document.getElementById(divid)) {
2937: document.getElementById(divid).style.display = 'inline-block';
2938: }
2939: setvis = 1;
2940: break;
1.320 raeburn 2941: }
2942: }
2943: }
2944: }
2945: if (!setvis) {
2946: if (document.getElementById(divid)) {
2947: document.getElementById(divid).style.display = 'none';
2948: }
2949: }
2950: }
2951: } else if ((setting == 'sec') || (setting == 'secsrc')) {
2952: var numsec = form.elements['lti_crssec_'+item].length;
2953: if (numsec) {
2954: var setvis = '';
2955: for (var i=0; i<numsec; i++) {
2956: if (form.elements['lti_crssec_'+item][i].checked) {
2957: if (form.elements['lti_crssec_'+item][i].value == '1') {
2958: if (document.getElementById('lti_crssecfield_'+item)) {
2959: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
2960: setvis = 1;
2961: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
2962: if (numsrcsec) {
2963: var setsrcvis = '';
2964: for (var j=0; j<numsrcsec; j++) {
2965: if (form.elements['lti_crssecsrc_'+item][j].checked) {
2966: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
2967: if (document.getElementById('lti_secsrcfield_'+item)) {
2968: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
2969: setsrcvis = 1;
2970: }
2971: }
2972: }
2973: }
2974: if (!setsrcvis) {
2975: if (document.getElementById('lti_secsrcfield_'+item)) {
2976: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
2977: }
2978: }
2979: }
2980: }
2981: }
2982: }
2983: }
2984: if (!setvis) {
2985: if (document.getElementById('lti_crssecfield_'+item)) {
2986: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
2987: }
2988: if (document.getElementById('lti_secsrcfield_'+item)) {
2989: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
2990: }
2991: }
2992: }
1.325 raeburn 2993: } else if (setting == 'lcauth') {
2994: var numauth = form.elements['lti_lcauth_'+item].length;
2995: if (numauth) {
2996: for (var i=0; i<numauth; i++) {
2997: if (form.elements['lti_lcauth_'+item][i].checked) {
2998: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
2999: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3000: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3001: } else {
3002: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3003: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3004: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3005: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3006: } else {
3007: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3008: }
3009: }
3010: }
3011: }
3012: }
3013: }
3014: }
1.326 raeburn 3015: } else if (setting == 'lcmenu') {
3016: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3017: var divid = 'lti_menufield_'+item;
3018: var setvis = '';
3019: for (var i=0; i<menus.length; i++) {
3020: var radioname = menus[i];
3021: var num = form.elements[radioname].length;
3022: if (num) {
3023: for (var j=0; j<num; j++) {
3024: if (form.elements[radioname][j].checked) {
3025: if (form.elements[radioname][j].value == '1') {
3026: if (document.getElementById(divid)) {
3027: document.getElementById(divid).style.display = 'inline-block';
3028: }
3029: setvis = 1;
3030: break;
3031: }
3032: }
3033: }
3034: }
3035: if (setvis == 1) {
3036: break;
3037: }
3038: }
3039: if (!setvis) {
3040: if (document.getElementById(divid)) {
3041: document.getElementById(divid).style.display = 'none';
3042: }
3043: }
1.320 raeburn 3044: }
3045: return;
3046: }
3047: // ]]>
3048: </script>
3049:
3050: ENDSCRIPT
3051: }
3052:
1.3 raeburn 3053: sub print_autoenroll {
1.30 raeburn 3054: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3055: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 3056: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 3057: if (ref($settings) eq 'HASH') {
3058: if (exists($settings->{'run'})) {
3059: if ($settings->{'run'} eq '0') {
3060: $runoff = ' checked="checked" ';
3061: $runon = ' ';
3062: } else {
3063: $runon = ' checked="checked" ';
3064: $runoff = ' ';
3065: }
3066: } else {
3067: if ($autorun) {
3068: $runon = ' checked="checked" ';
3069: $runoff = ' ';
3070: } else {
3071: $runoff = ' checked="checked" ';
3072: $runon = ' ';
3073: }
3074: }
1.129 raeburn 3075: if (exists($settings->{'co-owners'})) {
3076: if ($settings->{'co-owners'} eq '0') {
3077: $coownersoff = ' checked="checked" ';
3078: $coownerson = ' ';
3079: } else {
3080: $coownerson = ' checked="checked" ';
3081: $coownersoff = ' ';
3082: }
3083: } else {
3084: $coownersoff = ' checked="checked" ';
3085: $coownerson = ' ';
3086: }
1.3 raeburn 3087: if (exists($settings->{'sender_domain'})) {
3088: $defdom = $settings->{'sender_domain'};
3089: }
1.274 raeburn 3090: if (exists($settings->{'autofailsafe'})) {
3091: $failsafe = $settings->{'autofailsafe'};
3092: }
1.14 raeburn 3093: } else {
3094: if ($autorun) {
3095: $runon = ' checked="checked" ';
3096: $runoff = ' ';
3097: } else {
3098: $runoff = ' checked="checked" ';
3099: $runon = ' ';
3100: }
1.3 raeburn 3101: }
3102: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3103: my $notif_sender;
3104: if (ref($settings) eq 'HASH') {
3105: $notif_sender = $settings->{'sender_uname'};
3106: }
1.3 raeburn 3107: my $datatable='<tr class="LC_odd_row">'.
3108: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3109: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3110: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3111: $runon.' value="1" />'.&mt('Yes').'</label> '.
3112: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3113: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3114: '</tr><tr>'.
3115: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3116: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3117: &mt('username').': '.
3118: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3119: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3120: ': '.$domform.'</span></td></tr>'.
3121: '<tr class="LC_odd_row">'.
3122: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3123: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3124: '<input type="radio" name="autoassign_coowners"'.
3125: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3126: '<label><input type="radio" name="autoassign_coowners"'.
3127: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 3128: '</tr><tr>'.
3129: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
3130: '<td class="LC_right_item"><span class="LC_nobreak">'.
3131: '<input type="text" name="autoenroll_failsafe"'.
1.333 raeburn 3132: ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.274 raeburn 3133: $$rowtotal += 4;
1.3 raeburn 3134: return $datatable;
3135: }
3136:
3137: sub print_autoupdate {
1.30 raeburn 3138: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 3139: my $datatable;
3140: if ($position eq 'top') {
3141: my $updateon = ' ';
3142: my $updateoff = ' checked="checked" ';
3143: my $classlistson = ' ';
3144: my $classlistsoff = ' checked="checked" ';
3145: if (ref($settings) eq 'HASH') {
3146: if ($settings->{'run'} eq '1') {
3147: $updateon = $updateoff;
3148: $updateoff = ' ';
3149: }
3150: if ($settings->{'classlists'} eq '1') {
3151: $classlistson = $classlistsoff;
3152: $classlistsoff = ' ';
3153: }
3154: }
3155: my %title = (
3156: run => 'Auto-update active?',
3157: classlists => 'Update information in classlists?',
3158: );
3159: $datatable = '<tr class="LC_odd_row">'.
3160: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 3161: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3162: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 3163: $updateon.' value="1" />'.&mt('Yes').'</label> '.
3164: '<label><input type="radio" name="autoupdate_run"'.
3165: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3166: '</tr><tr>'.
3167: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 3168: '<td class="LC_right_item"><span class="LC_nobreak">'.
3169: '<label><input type="radio" name="classlists"'.
3170: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
3171: '<label><input type="radio" name="classlists"'.
3172: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3173: '</tr>';
1.30 raeburn 3174: $$rowtotal += 2;
1.131 raeburn 3175: } elsif ($position eq 'middle') {
3176: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3177: my $numinrow = 3;
3178: my $locknamesettings;
3179: $datatable .= &insttypes_row($settings,$types,$usertypes,
3180: $dom,$numinrow,$othertitle,
1.305 raeburn 3181: 'lockablenames',$rowtotal);
1.131 raeburn 3182: $$rowtotal ++;
1.3 raeburn 3183: } else {
1.44 raeburn 3184: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3185: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3186: 'permanentemail','id');
1.33 raeburn 3187: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3188: my $numrows = 0;
1.26 raeburn 3189: if (ref($types) eq 'ARRAY') {
3190: if (@{$types} > 0) {
3191: $datatable =
3192: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3193: \@fields,$types,\$numrows);
1.30 raeburn 3194: $$rowtotal += @{$types};
1.26 raeburn 3195: }
1.3 raeburn 3196: }
3197: $datatable .=
3198: &usertype_update_row($settings,{'default' => $othertitle},
3199: \%fieldtitles,\@fields,['default'],
3200: \$numrows);
1.30 raeburn 3201: $$rowtotal ++;
1.3 raeburn 3202: }
3203: return $datatable;
3204: }
3205:
1.125 raeburn 3206: sub print_autocreate {
3207: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 3208: my (%createon,%createoff,%currhash);
1.125 raeburn 3209: my @types = ('xml','req');
3210: if (ref($settings) eq 'HASH') {
3211: foreach my $item (@types) {
3212: $createoff{$item} = ' checked="checked" ';
3213: $createon{$item} = ' ';
3214: if (exists($settings->{$item})) {
3215: if ($settings->{$item}) {
3216: $createon{$item} = ' checked="checked" ';
3217: $createoff{$item} = ' ';
3218: }
3219: }
3220: }
1.210 raeburn 3221: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 3222: $currhash{$settings->{'xmldc'}} = 1;
3223: }
1.125 raeburn 3224: } else {
3225: foreach my $item (@types) {
3226: $createoff{$item} = ' checked="checked" ';
3227: $createon{$item} = ' ';
3228: }
3229: }
3230: $$rowtotal += 2;
1.191 raeburn 3231: my $numinrow = 2;
1.125 raeburn 3232: my $datatable='<tr class="LC_odd_row">'.
3233: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3234: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3235: '<input type="radio" name="autocreate_xml"'.
3236: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3237: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3238: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3239: '</td></tr><tr>'.
3240: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3241: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3242: '<input type="radio" name="autocreate_req"'.
3243: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3244: '<label><input type="radio" name="autocreate_req"'.
3245: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 3246: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3247: 'autocreate_xmldc',%currhash);
1.247 raeburn 3248: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3249: if ($numdc > 1) {
1.247 raeburn 3250: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3251: '</td><td class="LC_left_item">';
1.125 raeburn 3252: } else {
1.247 raeburn 3253: $datatable .= &mt('Course creation processed as:').
3254: '</td><td class="LC_right_item">';
1.125 raeburn 3255: }
1.247 raeburn 3256: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 3257: $$rowtotal += $rows;
1.125 raeburn 3258: return $datatable;
3259: }
3260:
1.23 raeburn 3261: sub print_directorysrch {
1.277 raeburn 3262: my ($position,$dom,$settings,$rowtotal) = @_;
3263: my $datatable;
3264: if ($position eq 'top') {
3265: my $instsrchon = ' ';
3266: my $instsrchoff = ' checked="checked" ';
3267: my ($exacton,$containson,$beginson);
3268: my $instlocalon = ' ';
3269: my $instlocaloff = ' checked="checked" ';
3270: if (ref($settings) eq 'HASH') {
3271: if ($settings->{'available'} eq '1') {
3272: $instsrchon = $instsrchoff;
3273: $instsrchoff = ' ';
3274: }
3275: if ($settings->{'localonly'} eq '1') {
3276: $instlocalon = $instlocaloff;
3277: $instlocaloff = ' ';
3278: }
3279: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3280: foreach my $type (@{$settings->{'searchtypes'}}) {
3281: if ($type eq 'exact') {
3282: $exacton = ' checked="checked" ';
3283: } elsif ($type eq 'contains') {
3284: $containson = ' checked="checked" ';
3285: } elsif ($type eq 'begins') {
3286: $beginson = ' checked="checked" ';
3287: }
3288: }
3289: } else {
3290: if ($settings->{'searchtypes'} eq 'exact') {
3291: $exacton = ' checked="checked" ';
3292: } elsif ($settings->{'searchtypes'} eq 'contains') {
3293: $containson = ' checked="checked" ';
3294: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 3295: $exacton = ' checked="checked" ';
3296: $containson = ' checked="checked" ';
3297: }
3298: }
1.277 raeburn 3299: }
3300: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3301: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3302:
3303: my $numinrow = 4;
3304: my $cansrchrow = 0;
3305: $datatable='<tr class="LC_odd_row">'.
3306: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3307: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3308: '<input type="radio" name="dirsrch_available"'.
3309: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3310: '<label><input type="radio" name="dirsrch_available"'.
3311: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3312: '</tr><tr>'.
3313: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3314: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3315: '<input type="radio" name="dirsrch_instlocalonly"'.
3316: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3317: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3318: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3319: '</tr>';
3320: $$rowtotal += 2;
3321: if (ref($usertypes) eq 'HASH') {
3322: if (keys(%{$usertypes}) > 0) {
3323: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 3324: $numinrow,$othertitle,'cansearch',
3325: $rowtotal);
1.277 raeburn 3326: $cansrchrow = 1;
1.25 raeburn 3327: }
1.23 raeburn 3328: }
1.277 raeburn 3329: if ($cansrchrow) {
3330: $$rowtotal ++;
3331: $datatable .= '<tr>';
3332: } else {
3333: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 3334: }
1.277 raeburn 3335: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3336: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3337: foreach my $title (@{$titleorder}) {
3338: if (defined($searchtitles->{$title})) {
3339: my $check = ' ';
3340: if (ref($settings) eq 'HASH') {
3341: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3342: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3343: $check = ' checked="checked" ';
3344: }
1.39 raeburn 3345: }
1.25 raeburn 3346: }
1.277 raeburn 3347: $datatable .= '<td class="LC_left_item">'.
3348: '<span class="LC_nobreak"><label>'.
3349: '<input type="checkbox" name="searchby" '.
3350: 'value="'.$title.'"'.$check.'/>'.
3351: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 3352: }
3353: }
1.277 raeburn 3354: $datatable .= '</tr></table></td></tr>';
3355: $$rowtotal ++;
3356: if ($cansrchrow) {
3357: $datatable .= '<tr class="LC_odd_row">';
3358: } else {
3359: $datatable .= '<tr>';
3360: }
3361: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3362: '<td class="LC_left_item" colspan="2">'.
3363: '<span class="LC_nobreak"><label>'.
3364: '<input type="checkbox" name="searchtypes" '.
3365: $exacton.' value="exact" />'.&mt('Exact match').
3366: '</label> '.
3367: '<label><input type="checkbox" name="searchtypes" '.
3368: $beginson.' value="begins" />'.&mt('Begins with').
3369: '</label> '.
3370: '<label><input type="checkbox" name="searchtypes" '.
3371: $containson.' value="contains" />'.&mt('Contains').
3372: '</label></span></td></tr>';
3373: $$rowtotal ++;
1.26 raeburn 3374: } else {
1.277 raeburn 3375: my $domsrchon = ' checked="checked" ';
3376: my $domsrchoff = ' ';
3377: my $domlocalon = ' ';
3378: my $domlocaloff = ' checked="checked" ';
3379: if (ref($settings) eq 'HASH') {
3380: if ($settings->{'lclocalonly'} eq '1') {
3381: $domlocalon = $domlocaloff;
3382: $domlocaloff = ' ';
3383: }
3384: if ($settings->{'lcavailable'} eq '0') {
3385: $domsrchoff = $domsrchon;
3386: $domsrchon = ' ';
3387: }
3388: }
3389: $datatable='<tr class="LC_odd_row">'.
3390: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3391: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3392: '<input type="radio" name="dirsrch_domavailable"'.
3393: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3394: '<label><input type="radio" name="dirsrch_domavailable"'.
3395: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3396: '</tr><tr>'.
3397: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3398: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3399: '<input type="radio" name="dirsrch_domlocalonly"'.
3400: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3401: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3402: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3403: '</tr>';
3404: $$rowtotal += 2;
1.26 raeburn 3405: }
1.25 raeburn 3406: return $datatable;
3407: }
3408:
1.28 raeburn 3409: sub print_contacts {
1.286 raeburn 3410: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3411: my $datatable;
3412: my @contacts = ('adminemail','supportemail');
1.286 raeburn 3413: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 3414: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 3415: if ($position eq 'top') {
3416: if (ref($settings) eq 'HASH') {
3417: foreach my $item (@contacts) {
3418: if (exists($settings->{$item})) {
3419: $to{$item} = $settings->{$item};
3420: }
3421: }
3422: }
3423: } elsif ($position eq 'middle') {
3424: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 3425: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 3426: foreach my $type (@mailings) {
3427: $otheremails{$type} = '';
3428: }
1.340 raeburn 3429: } elsif ($position eq 'lower') {
3430: if (ref($settings) eq 'HASH') {
3431: if (ref($settings->{'lonstatus'}) eq 'HASH') {
3432: %lonstatus = %{$settings->{'lonstatus'}};
3433: }
3434: }
1.286 raeburn 3435: } else {
3436: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 3437: foreach my $type (@mailings) {
3438: $otheremails{$type} = '';
3439: }
1.286 raeburn 3440: $bccemails{'helpdeskmail'} = '';
3441: $bccemails{'otherdomsmail'} = '';
3442: $includestr{'helpdeskmail'} = '';
3443: $includestr{'otherdomsmail'} = '';
3444: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3445: }
1.28 raeburn 3446: if (ref($settings) eq 'HASH') {
1.340 raeburn 3447: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 3448: foreach my $type (@mailings) {
3449: if (exists($settings->{$type})) {
3450: if (ref($settings->{$type}) eq 'HASH') {
3451: foreach my $item (@contacts) {
3452: if ($settings->{$type}{$item}) {
3453: $checked{$type}{$item} = ' checked="checked" ';
3454: }
3455: }
3456: $otheremails{$type} = $settings->{$type}{'others'};
3457: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3458: $bccemails{$type} = $settings->{$type}{'bcc'};
3459: if ($settings->{$type}{'include'} ne '') {
3460: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3461: $includestr{$type} = &unescape($includestr{$type});
3462: }
3463: }
3464: }
3465: } elsif ($type eq 'lonstatusmail') {
3466: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3467: }
1.28 raeburn 3468: }
3469: }
1.286 raeburn 3470: if ($position eq 'bottom') {
3471: foreach my $type (@mailings) {
3472: $bccemails{$type} = $settings->{$type}{'bcc'};
3473: if ($settings->{$type}{'include'} ne '') {
3474: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3475: $includestr{$type} = &unescape($includestr{$type});
3476: }
3477: }
3478: if (ref($settings->{'helpform'}) eq 'HASH') {
3479: if (ref($fields) eq 'ARRAY') {
3480: foreach my $field (@{$fields}) {
3481: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3482: }
1.286 raeburn 3483: }
3484: if (exists($settings->{'helpform'}{'maxsize'})) {
3485: $maxsize = $settings->{'helpform'}{'maxsize'};
3486: } else {
1.289 raeburn 3487: $maxsize = '1.0';
1.286 raeburn 3488: }
3489: } else {
3490: if (ref($fields) eq 'ARRAY') {
3491: foreach my $field (@{$fields}) {
3492: $currfield{$field} = 'yes';
1.134 raeburn 3493: }
1.28 raeburn 3494: }
1.286 raeburn 3495: $maxsize = '1.0';
1.28 raeburn 3496: }
3497: }
3498: } else {
1.286 raeburn 3499: if ($position eq 'top') {
3500: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3501: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3502: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3503: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 3504: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3505: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3506: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3507: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 3508: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3509: } elsif ($position eq 'bottom') {
3510: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3511: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3512: if (ref($fields) eq 'ARRAY') {
3513: foreach my $field (@{$fields}) {
3514: $currfield{$field} = 'yes';
3515: }
3516: }
3517: $maxsize = '1.0';
3518: }
1.28 raeburn 3519: }
3520: my ($titles,$short_titles) = &contact_titles();
3521: my $rownum = 0;
3522: my $css_class;
1.286 raeburn 3523: if ($position eq 'top') {
3524: foreach my $item (@contacts) {
3525: $css_class = $rownum%2?' class="LC_odd_row"':'';
3526: $datatable .= '<tr'.$css_class.'>'.
3527: '<td><span class="LC_nobreak">'.$titles->{$item}.
3528: '</span></td><td class="LC_right_item">'.
3529: '<input type="text" name="'.$item.'" value="'.
3530: $to{$item}.'" /></td></tr>';
3531: $rownum ++;
3532: }
1.315 raeburn 3533: } elsif ($position eq 'bottom') {
3534: $css_class = $rownum%2?' class="LC_odd_row"':'';
3535: $datatable .= '<tr'.$css_class.'>'.
3536: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3537: &mt('(e-mail, subject, and description always shown)').
3538: '</td><td class="LC_left_item">';
3539: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3540: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3541: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3542: foreach my $field (@{$fields}) {
3543: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3544: if (($field eq 'screenshot') || ($field eq 'cc')) {
3545: $datatable .= ' '.&mt('(logged-in users)');
3546: }
3547: $datatable .='</td><td>';
3548: my $clickaction;
3549: if ($field eq 'screenshot') {
3550: $clickaction = ' onclick="screenshotSize(this);"';
3551: }
3552: if (ref($possoptions->{$field}) eq 'ARRAY') {
3553: foreach my $option (@{$possoptions->{$field}}) {
3554: my $checked;
3555: if ($currfield{$field} eq $option) {
3556: $checked = ' checked="checked"';
3557: }
3558: $datatable .= '<span class="LC_nobreak"><label>'.
3559: '<input type="radio" name="helpform_'.$field.'" '.
3560: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3561: '</label></span>'.(' 'x2);
3562: }
3563: }
3564: if ($field eq 'screenshot') {
3565: my $display;
3566: if ($currfield{$field} eq 'no') {
3567: $display = ' style="display:none"';
3568: }
1.334 raeburn 3569: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 3570: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3571: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3572: }
3573: $datatable .= '</td></tr>';
3574: }
3575: $datatable .= '</table>';
3576: }
3577: $datatable .= '</td></tr>'."\n";
3578: $rownum ++;
3579: }
1.340 raeburn 3580: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 3581: foreach my $type (@mailings) {
3582: $css_class = $rownum%2?' class="LC_odd_row"':'';
3583: $datatable .= '<tr'.$css_class.'>'.
3584: '<td><span class="LC_nobreak">'.
3585: $titles->{$type}.': </span></td>'.
3586: '<td class="LC_left_item">';
3587: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3588: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3589: }
3590: $datatable .= '<span class="LC_nobreak">';
3591: foreach my $item (@contacts) {
3592: $datatable .= '<label>'.
3593: '<input type="checkbox" name="'.$type.'"'.
3594: $checked{$type}{$item}.
3595: ' value="'.$item.'" />'.$short_titles->{$item}.
3596: '</label> ';
3597: }
3598: $datatable .= '</span><br />'.&mt('Others').': '.
3599: '<input type="text" name="'.$type.'_others" '.
3600: 'value="'.$otheremails{$type}.'" />';
3601: my %locchecked;
3602: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3603: foreach my $loc ('s','b') {
3604: if ($includeloc{$type} eq $loc) {
3605: $locchecked{$loc} = ' checked="checked"';
3606: last;
3607: }
3608: }
3609: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3610: '<input type="text" name="'.$type.'_bcc" '.
3611: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3612: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3613: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 3614: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 3615: '<span class="LC_nobreak">'.&mt('Location:').' '.
3616: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3617: (' 'x2).
3618: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3619: '</span></fieldset>';
3620: }
3621: $datatable .= '</td></tr>'."\n";
3622: $rownum ++;
3623: }
1.28 raeburn 3624: }
1.286 raeburn 3625: if ($position eq 'middle') {
3626: my %choices;
1.340 raeburn 3627: my $corelink = &core_link_msu();
3628: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 3629: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 3630: $corelink);
3631: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
3632: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 3633: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 3634: 'reportupdates' => 'on',
3635: 'reportstatus' => 'on');
1.286 raeburn 3636: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3637: \%choices,$rownum);
3638: $datatable .= $reports;
1.340 raeburn 3639: } elsif ($position eq 'lower') {
3640: $css_class = $rownum%2?' class="LC_odd_row"':'';
3641: my ($threshold,$sysmail,%excluded,%weights);
3642: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
3643: if ($lonstatus{'threshold'} =~ /^\d+$/) {
3644: $threshold = $lonstatus{'threshold'};
3645: } else {
3646: $threshold = $defaults->{'threshold'};
3647: }
3648: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
3649: $sysmail = $lonstatus{'sysmail'};
3650: } else {
3651: $sysmail = $defaults->{'sysmail'};
3652: }
3653: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 3654: foreach my $type ('E','W','N','U') {
1.340 raeburn 3655: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
3656: $weights{$type} = $lonstatus{'weights'}{$type};
3657: } else {
3658: $weights{$type} = $defaults->{$type};
3659: }
3660: }
3661: } else {
1.341 raeburn 3662: foreach my $type ('E','W','N','U') {
1.340 raeburn 3663: $weights{$type} = $defaults->{$type};
3664: }
3665: }
3666: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
3667: if (@{$lonstatus{'excluded'}} > 0) {
3668: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
3669: }
3670: }
3671: $datatable .= '<tr'.$css_class.'>'.
3672: '<td class="LC_left_item"><span class="LC_nobreak">'.
3673: $titles->{'errorthreshold'}.
3674: '</span></td><td class="LC_left_item">'.
3675: '<input type="text" name="errorthreshold" value="'.
3676: $threshold.'" size="5" /></td></tr>';
3677: $rownum ++;
3678: $css_class = $rownum%2?' class="LC_odd_row"':'';
3679: $datatable .= '<tr'.$css_class.'>'.
3680: '<td class="LC_left_item">'.
3681: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
3682: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 3683: foreach my $type ('E','W','N','U') {
1.340 raeburn 3684: $datatable .= '<td>'.$names->{$type}.'<br />'.
3685: '<input type="text" name="errorweights_'.$type.'" value="'.
3686: $weights{$type}.'" size="5" /></td>';
3687: }
3688: $datatable .= '</tr></table></tr>';
3689: $rownum ++;
3690: $css_class = $rownum%2?' class="LC_odd_row"':'';
3691: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
3692: $titles->{'errorexcluded'}.'</td>'.
3693: '<td class="LC_left_item"><table>';
3694: my $numinrow = 4;
3695: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
3696: for (my $i=0; $i<@ids; $i++) {
3697: my $rem = $i%($numinrow);
3698: if ($rem == 0) {
3699: if ($i > 0) {
3700: $datatable .= '</tr>';
3701: }
3702: $datatable .= '<tr>';
3703: }
3704: my $check;
3705: if ($excluded{$ids[$i]}) {
3706: $check = ' checked="checked" ';
3707: }
3708: $datatable .= '<td class="LC_left_item">'.
3709: '<span class="LC_nobreak"><label>'.
3710: '<input type="checkbox" name="errorexcluded" '.
3711: 'value="'.$ids[$i].'"'.$check.' />'.
3712: $ids[$i].'</label></span></td>';
3713: }
3714: my $colsleft = $numinrow - @ids%($numinrow);
3715: if ($colsleft > 1 ) {
3716: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3717: ' </td>';
3718: } elsif ($colsleft == 1) {
3719: $datatable .= '<td class="LC_left_item"> </td>';
3720: }
3721: $datatable .= '</tr></table></td></tr>';
3722: $rownum ++;
3723: $css_class = $rownum%2?' class="LC_odd_row"':'';
3724: $datatable .= '<tr'.$css_class.'>'.
3725: '<td class="LC_left_item"><span class="LC_nobreak">'.
3726: $titles->{'errorsysmail'}.
3727: '</span></td><td class="LC_left_item">'.
3728: '<input type="text" name="errorsysmail" value="'.
3729: $sysmail.'" size="5" /></td></tr>';
3730: $rownum ++;
1.286 raeburn 3731: } elsif ($position eq 'bottom') {
1.315 raeburn 3732: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3733: my (@posstypes,%usertypeshash);
3734: if (ref($types) eq 'ARRAY') {
3735: @posstypes = @{$types};
3736: }
3737: if (@posstypes) {
3738: if (ref($usertypes) eq 'HASH') {
3739: %usertypeshash = %{$usertypes};
3740: }
3741: my @overridden;
3742: my $numinrow = 4;
3743: if (ref($settings) eq 'HASH') {
3744: if (ref($settings->{'overrides'}) eq 'HASH') {
3745: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3746: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3747: push(@overridden,$key);
3748: foreach my $item (@contacts) {
3749: if ($settings->{'overrides'}{$key}{$item}) {
3750: $checked{'override_'.$key}{$item} = ' checked="checked" ';
3751: }
3752: }
3753: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3754: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3755: $includeloc{'override_'.$key} = '';
3756: $includestr{'override_'.$key} = '';
3757: if ($settings->{'overrides'}{$key}{'include'} ne '') {
3758: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3759: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3760: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3761: }
1.286 raeburn 3762: }
3763: }
3764: }
1.315 raeburn 3765: }
3766: my $customclass = 'LC_helpdesk_override';
3767: my $optionsprefix = 'LC_options_helpdesk_';
3768:
3769: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3770:
3771: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3772: $numinrow,$othertitle,'overrides',
3773: \$rownum,$onclicktypes,$customclass);
3774: $rownum ++;
3775: $usertypeshash{'default'} = $othertitle;
3776: foreach my $status (@posstypes) {
3777: my $css_class;
3778: if ($rownum%2) {
3779: $css_class = 'LC_odd_row ';
3780: }
3781: $css_class .= $customclass;
3782: my $rowid = $optionsprefix.$status;
3783: my $hidden = 1;
3784: my $currstyle = 'display:none';
3785: if (grep(/^\Q$status\E$/,@overridden)) {
3786: $currstyle = 'display:table-row';
3787: $hidden = 0;
3788: }
3789: my $key = 'override_'.$status;
3790: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3791: $includeloc{$key},$includestr{$key},$status,$rowid,
3792: $usertypeshash{$status},$css_class,$currstyle,
3793: \@contacts,$short_titles);
3794: unless ($hidden) {
3795: $rownum ++;
1.286 raeburn 3796: }
3797: }
1.134 raeburn 3798: }
1.28 raeburn 3799: }
1.30 raeburn 3800: $$rowtotal += $rownum;
1.28 raeburn 3801: return $datatable;
3802: }
3803:
1.340 raeburn 3804: sub core_link_msu {
3805: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3806: &mt('LON-CAPA core group - MSU'),600,500);
3807: }
3808:
1.315 raeburn 3809: sub overridden_helpdesk {
3810: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3811: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3812: my $class = 'LC_left_item';
3813: if ($css_class) {
3814: $css_class = ' class="'.$css_class.'"';
3815: }
3816: if ($rowid) {
3817: $rowid = ' id="'.$rowid.'"';
3818: }
3819: if ($rowstyle) {
3820: $rowstyle = ' style="'.$rowstyle.'"';
3821: }
3822: my ($output,$description);
3823: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3824: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3825: "<td>$description</td>\n".
3826: '<td class="'.$class.'" colspan="2">'.
3827: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3828: '<span class="LC_nobreak">';
3829: if (ref($contacts) eq 'ARRAY') {
3830: foreach my $item (@{$contacts}) {
3831: my $check;
3832: if (ref($checked) eq 'HASH') {
3833: $check = $checked->{$item};
3834: }
3835: my $title;
3836: if (ref($short_titles) eq 'HASH') {
3837: $title = $short_titles->{$item};
3838: }
3839: $output .= '<label>'.
3840: '<input type="checkbox" name="override_'.$type.'"'.$check.
3841: ' value="'.$item.'" />'.$title.'</label> ';
3842: }
3843: }
3844: $output .= '</span><br />'.&mt('Others').': '.
3845: '<input type="text" name="override_'.$type.'_others" '.
3846: 'value="'.$otheremails.'" />';
3847: my %locchecked;
3848: foreach my $loc ('s','b') {
3849: if ($includeloc eq $loc) {
3850: $locchecked{$loc} = ' checked="checked"';
3851: last;
3852: }
3853: }
3854: $output .= '<br />'.&mt('Bcc:').(' 'x6).
3855: '<input type="text" name="override_'.$type.'_bcc" '.
3856: 'value="'.$bccemails.'" /></fieldset>'.
3857: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3858: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 3859: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 3860: '<span class="LC_nobreak">'.&mt('Location:').' '.
3861: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3862: (' 'x2).
3863: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3864: '</span></fieldset>'.
3865: '</td></tr>'."\n";
3866: return $output;
3867: }
3868:
1.286 raeburn 3869: sub contacts_javascript {
3870: return <<"ENDSCRIPT";
3871:
3872: <script type="text/javascript">
3873: // <![CDATA[
3874:
3875: function screenshotSize(field) {
3876: if (document.getElementById('help_screenshotsize')) {
3877: if (field.value == 'no') {
1.289 raeburn 3878: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 3879: } else {
3880: document.getElementById('help_screenshotsize').style.display="";
3881: }
3882: }
3883: return;
3884: }
3885:
1.315 raeburn 3886: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
3887: if (form.elements[checkbox].length != undefined) {
3888: var count = 0;
3889: if (docount) {
3890: for (var i=0; i<form.elements[checkbox].length; i++) {
3891: if (form.elements[checkbox][i].checked) {
3892: count ++;
3893: }
3894: }
3895: }
3896: for (var i=0; i<form.elements[checkbox].length; i++) {
3897: var type = form.elements[checkbox][i].value;
3898: if (document.getElementById(prefix+type)) {
3899: if (form.elements[checkbox][i].checked) {
3900: document.getElementById(prefix+type).style.display = 'table-row';
3901: if (count % 2 == 1) {
3902: document.getElementById(prefix+type).className = target+' LC_odd_row';
3903: } else {
3904: document.getElementById(prefix+type).className = target;
3905: }
3906: count ++;
3907: } else {
3908: document.getElementById(prefix+type).style.display = 'none';
3909: }
3910: }
3911: }
3912: }
3913: return;
3914: }
3915:
3916:
1.286 raeburn 3917: // ]]>
3918: </script>
3919:
3920: ENDSCRIPT
3921: }
3922:
1.118 jms 3923: sub print_helpsettings {
1.282 raeburn 3924: my ($position,$dom,$settings,$rowtotal) = @_;
3925: my $confname = $dom.'-domainconfig';
1.285 raeburn 3926: my $formname = 'display';
1.168 raeburn 3927: my ($datatable,$itemcount);
1.282 raeburn 3928: if ($position eq 'top') {
3929: $itemcount = 1;
3930: my (%choices,%defaultchecked,@toggles);
3931: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3932: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3933: &mt('LON-CAPA bug tracker'),600,500));
3934: %defaultchecked = ('submitbugs' => 'on');
3935: @toggles = ('submitbugs');
3936: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3937: \%choices,$itemcount);
3938: $$rowtotal ++;
3939: } else {
3940: my $css_class;
3941: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 3942: my (%customroles,%ordered,%current);
1.301 raeburn 3943: if (ref($settings) eq 'HASH') {
3944: if (ref($settings->{'adhoc'}) eq 'HASH') {
3945: %current = %{$settings->{'adhoc'}};
3946: }
1.285 raeburn 3947: }
3948: my $count = 0;
3949: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 3950: if ($key=~/^rolesdef\_(\w+)$/) {
3951: my $rolename = $1;
1.285 raeburn 3952: my (%privs,$order);
1.282 raeburn 3953: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3954: $customroles{$rolename} = \%privs;
1.285 raeburn 3955: if (ref($current{$rolename}) eq 'HASH') {
3956: $order = $current{$rolename}{'order'};
3957: }
3958: if ($order eq '') {
3959: $order = $count;
3960: }
3961: $ordered{$order} = $rolename;
3962: $count++;
3963: }
3964: }
3965: my $maxnum = scalar(keys(%ordered));
3966: my @roles_by_num = ();
3967: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3968: push(@roles_by_num,$item);
3969: }
3970: my $context = 'domprefs';
3971: my $crstype = 'Course';
3972: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 3973: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 3974: my ($numstatustypes,@jsarray);
3975: if (ref($types) eq 'ARRAY') {
3976: if (@{$types} > 0) {
3977: $numstatustypes = scalar(@{$types});
3978: push(@accesstypes,'status');
3979: @jsarray = ('bystatus');
1.282 raeburn 3980: }
3981: }
1.290 raeburn 3982: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 3983: if (keys(%domhelpdesk)) {
3984: push(@accesstypes,('inc','exc'));
3985: push(@jsarray,('notinc','notexc'));
3986: }
3987: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 3988: my $context = 'domprefs';
3989: my $crstype = 'Course';
1.285 raeburn 3990: my $prefix = 'helproles_';
3991: my $add_class = 'LC_hidden';
3992: foreach my $num (@roles_by_num) {
3993: my $role = $ordered{$num};
3994: my ($desc,$access,@statuses);
3995: if (ref($current{$role}) eq 'HASH') {
3996: $desc = $current{$role}{'desc'};
3997: $access = $current{$role}{'access'};
3998: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3999: @statuses = @{$current{$role}{'insttypes'}};
4000: }
4001: }
4002: if ($desc eq '') {
4003: $desc = $role;
4004: }
4005: my $identifier = 'custhelp'.$num;
1.282 raeburn 4006: my %full=();
4007: my %levels= (
4008: course => {},
4009: domain => {},
4010: system => {},
4011: );
4012: my %levelscurrent=(
4013: course => {},
4014: domain => {},
4015: system => {},
4016: );
4017: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4018: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4019: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 4020: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 4021: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 4022: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4023: for (my $k=0; $k<=$maxnum; $k++) {
4024: my $vpos = $k+1;
4025: my $selstr;
4026: if ($k == $num) {
4027: $selstr = ' selected="selected" ';
4028: }
4029: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4030: }
4031: $datatable .= '</select>'.(' 'x2).
4032: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4033: '</td>'.
4034: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4035: &mt('Name shown to users:').
4036: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4037: '</fieldset>'.
4038: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4039: $othertitle,$usertypes,$types,\%domhelpdesk).
4040: '<fieldset>'.
4041: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 4042: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 4043: \%levelscurrent,$identifier,
4044: 'LC_hidden',$prefix.$num.'_privs').
4045: '</fieldset></td>';
1.282 raeburn 4046: $itemcount ++;
4047: }
4048: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4049: my $newcust = 'custhelp'.$count;
4050: my (%privs,%levelscurrent);
4051: my %full=();
4052: my %levels= (
4053: course => {},
4054: domain => {},
4055: system => {},
4056: );
4057: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4058: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 4059: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 4060: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 4061: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4062: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4063: for (my $k=0; $k<$maxnum+1; $k++) {
4064: my $vpos = $k+1;
4065: my $selstr;
4066: if ($k == $maxnum) {
4067: $selstr = ' selected="selected" ';
4068: }
4069: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4070: }
4071: $datatable .= '</select> '."\n".
1.282 raeburn 4072: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4073: '</label></span></td>'.
1.285 raeburn 4074: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4075: '<span class="LC_nobreak">'.
4076: &mt('Internal name:').
4077: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4078: '</span>'.(' 'x4).
4079: '<span class="LC_nobreak">'.
4080: &mt('Name shown to users:').
4081: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4082: '</span></fieldset>'.
4083: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4084: $usertypes,$types,\%domhelpdesk).
4085: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 4086: &Apache::lonuserutils::custom_role_header($context,$crstype,
4087: \@templateroles,$newcust).
4088: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4089: \%levelscurrent,$newcust).
1.334 raeburn 4090: '</fieldset>'.
4091: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4092: '</td></tr>';
1.282 raeburn 4093: $count ++;
4094: $$rowtotal += $count;
4095: }
1.166 raeburn 4096: return $datatable;
1.121 raeburn 4097: }
4098:
1.285 raeburn 4099: sub adhocbutton {
4100: my ($prefix,$num,$field,$visibility) = @_;
4101: my %lt = &Apache::lonlocal::texthash(
4102: show => 'Show details',
4103: hide => 'Hide details',
4104: );
4105: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4106: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4107: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4108: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4109: }
4110:
4111: sub helpsettings_javascript {
4112: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4113: return unless(ref($roles_by_num) eq 'ARRAY');
4114: my %html_js_lt = &Apache::lonlocal::texthash(
4115: show => 'Show details',
4116: hide => 'Hide details',
4117: );
4118: &html_escape(\%html_js_lt);
4119: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4120: return <<"ENDSCRIPT";
4121: <script type="text/javascript">
4122: // <![CDATA[
4123:
4124: function reorderHelpRoles(form,item) {
4125: var changedVal;
4126: $jstext
4127: var newpos = 'helproles_${total}_pos';
4128: var maxh = 1 + $total;
4129: var current = new Array();
4130: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4131: if (item == newpos) {
4132: changedVal = newitemVal;
4133: } else {
4134: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4135: current[newitemVal] = newpos;
4136: }
4137: for (var i=0; i<helproles.length; i++) {
4138: var elementName = 'helproles_'+helproles[i]+'_pos';
4139: if (elementName != item) {
4140: if (form.elements[elementName]) {
4141: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4142: current[currVal] = elementName;
4143: }
4144: }
4145: }
4146: var oldVal;
4147: for (var j=0; j<maxh; j++) {
4148: if (current[j] == undefined) {
4149: oldVal = j;
4150: }
4151: }
4152: if (oldVal < changedVal) {
4153: for (var k=oldVal+1; k<=changedVal ; k++) {
4154: var elementName = current[k];
4155: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4156: }
4157: } else {
4158: for (var k=changedVal; k<oldVal; k++) {
4159: var elementName = current[k];
4160: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4161: }
4162: }
4163: return;
4164: }
4165:
4166: function helpdeskAccess(num) {
4167: var curraccess = null;
4168: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4169: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4170: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4171: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4172: }
4173: }
4174: }
4175: var shown = Array();
4176: var hidden = Array();
4177: if (curraccess == 'none') {
4178: hidden = Array('$hiddenstr');
4179: } else {
4180: if (curraccess == 'status') {
4181: shown = Array('bystatus');
4182: hidden = Array('notinc','notexc');
4183: } else {
4184: if (curraccess == 'exc') {
4185: shown = Array('notexc');
4186: hidden = Array('notinc','bystatus');
4187: }
4188: if (curraccess == 'inc') {
4189: shown = Array('notinc');
4190: hidden = Array('notexc','bystatus');
4191: }
1.293 raeburn 4192: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 4193: hidden = Array('notinc','notexc','bystatus');
4194: }
4195: }
4196: }
4197: if (hidden.length > 0) {
4198: for (var i=0; i<hidden.length; i++) {
4199: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4200: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4201: }
4202: }
4203: }
4204: if (shown.length > 0) {
4205: for (var i=0; i<shown.length; i++) {
4206: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4207: if (shown[i] == 'privs') {
4208: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4209: } else {
4210: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4211: }
4212: }
4213: }
4214: }
4215: return;
4216: }
4217:
4218: function toggleHelpdeskItem(num,field) {
4219: if (document.getElementById('helproles_'+num+'_'+field)) {
4220: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 4221: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 4222: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4223: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4224: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4225: }
4226: } else {
4227: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4228: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4229: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4230: }
4231: }
4232: }
4233: return;
4234: }
4235:
4236: // ]]>
4237: </script>
4238:
4239: ENDSCRIPT
4240: }
4241:
4242: sub helpdeskroles_access {
4243: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4244: $usertypes,$types,$domhelpdesk) = @_;
4245: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4246: my %lt = &Apache::lonlocal::texthash(
4247: 'rou' => 'Role usage',
4248: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 4249: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4250: 'dh' => 'All with domain helpdesk role',
4251: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 4252: 'none' => 'None',
4253: 'status' => 'Determined based on institutional status',
4254: 'inc' => 'Include all, but exclude specific personnel',
4255: 'exc' => 'Exclude all, but include specific personnel',
4256: );
4257: my %usecheck = (
4258: all => ' checked="checked"',
4259: );
4260: my %displaydiv = (
4261: status => 'none',
4262: inc => 'none',
4263: exc => 'none',
4264: priv => 'block',
4265: );
4266: my $output;
4267: if (ref($current) eq 'HASH') {
4268: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4269: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4270: $usecheck{$current->{access}} = $usecheck{'all'};
4271: delete($usecheck{'all'});
4272: if ($current->{access} =~ /^(status|inc|exc)$/) {
4273: my $access = $1;
4274: $displaydiv{$access} = 'inline';
4275: } elsif ($current->{access} eq 'none') {
4276: $displaydiv{'priv'} = 'none';
4277: }
4278: }
4279: }
4280: }
4281: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4282: '<p>'.$lt{'whi'}.'</p>';
4283: foreach my $access (@{$accesstypes}) {
4284: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4285: ' onclick="helpdeskAccess('."'$num'".');" />'.
4286: $lt{$access}.'</label>';
4287: if ($access eq 'status') {
4288: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4289: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4290: $othertitle,$usertypes,$types).
4291: '</div>';
4292: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4293: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4294: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4295: '</div>';
4296: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4297: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4298: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4299: '</div>';
4300: }
4301: $output .= '</p>';
4302: }
4303: $output .= '</fieldset>';
4304: return $output;
4305: }
4306:
1.121 raeburn 4307: sub radiobutton_prefs {
1.192 raeburn 4308: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 4309: $additional,$align) = @_;
1.121 raeburn 4310: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4311: (ref($choices) eq 'HASH'));
4312:
1.170 raeburn 4313: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 4314:
4315: foreach my $item (@{$toggles}) {
4316: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4317: $checkedon{$item} = ' checked="checked" ';
4318: $checkedoff{$item} = ' ';
1.121 raeburn 4319: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4320: $checkedoff{$item} = ' checked="checked" ';
4321: $checkedon{$item} = ' ';
4322: }
4323: }
4324: if (ref($settings) eq 'HASH') {
1.121 raeburn 4325: foreach my $item (@{$toggles}) {
1.118 jms 4326: if ($settings->{$item} eq '1') {
4327: $checkedon{$item} = ' checked="checked" ';
4328: $checkedoff{$item} = ' ';
4329: } elsif ($settings->{$item} eq '0') {
4330: $checkedoff{$item} = ' checked="checked" ';
4331: $checkedon{$item} = ' ';
4332: }
4333: }
1.121 raeburn 4334: }
1.192 raeburn 4335: if ($onclick) {
4336: $onclick = ' onclick="'.$onclick.'"';
4337: }
1.121 raeburn 4338: foreach my $item (@{$toggles}) {
1.118 jms 4339: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4340: $datatable .=
1.306 raeburn 4341: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 4342: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 4343: '</span></td>';
4344: if ($align eq 'left') {
4345: $datatable .= '<td class="LC_left_item">';
4346: } else {
4347: $datatable .= '<td class="LC_right_item">';
4348: }
1.289 raeburn 4349: $datatable .=
1.257 raeburn 4350: '<span class="LC_nobreak">'.
1.118 jms 4351: '<label><input type="radio" name="'.
1.192 raeburn 4352: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 4353: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 4354: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
4355: '</span>'.$additional.
4356: '</td>'.
1.118 jms 4357: '</tr>';
4358: $itemcount ++;
1.121 raeburn 4359: }
4360: return ($datatable,$itemcount);
4361: }
4362:
1.267 raeburn 4363: sub print_ltitools {
4364: my ($dom,$settings,$rowtotal) = @_;
4365: my $rownum = 0;
4366: my $css_class;
4367: my $itemcount = 1;
4368: my $maxnum = 0;
4369: my %ordered;
4370: if (ref($settings) eq 'HASH') {
4371: foreach my $item (keys(%{$settings})) {
4372: if (ref($settings->{$item}) eq 'HASH') {
4373: my $num = $settings->{$item}{'order'};
4374: $ordered{$num} = $item;
4375: }
4376: }
4377: }
4378: my $confname = $dom.'-domainconfig';
4379: my $switchserver = &check_switchserver($dom,$confname);
4380: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 4381: my $datatable;
1.267 raeburn 4382: my %lt = <itools_names();
4383: my @courseroles = ('cc','in','ta','ep','st');
4384: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.324 raeburn 4385: my @fields = ('fullname','firstname','lastname','email','roles','user');
1.267 raeburn 4386: if (keys(%ordered)) {
4387: my @items = sort { $a <=> $b } keys(%ordered);
4388: for (my $i=0; $i<@items; $i++) {
4389: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4390: my $item = $ordered{$items[$i]};
1.323 raeburn 4391: my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267 raeburn 4392: if (ref($settings->{$item}) eq 'HASH') {
4393: $title = $settings->{$item}->{'title'};
4394: $url = $settings->{$item}->{'url'};
4395: $key = $settings->{$item}->{'key'};
4396: $secret = $settings->{$item}->{'secret'};
1.322 raeburn 4397: $lifetime = $settings->{$item}->{'lifetime'};
1.267 raeburn 4398: my $image = $settings->{$item}->{'image'};
4399: if ($image ne '') {
4400: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
4401: }
1.323 raeburn 4402: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
4403: $sigsel{'HMAC-256'} = ' selected="selected"';
4404: } else {
4405: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
4406: }
1.267 raeburn 4407: }
1.319 raeburn 4408: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267 raeburn 4409: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4410: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
4411: for (my $k=0; $k<=$maxnum; $k++) {
4412: my $vpos = $k+1;
4413: my $selstr;
4414: if ($k == $i) {
4415: $selstr = ' selected="selected" ';
4416: }
4417: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4418: }
4419: $datatable .= '</select>'.(' 'x2).
4420: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4421: &mt('Delete?').'</label></span></td>'.
4422: '<td colspan="2">'.
4423: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4424: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267 raeburn 4425: (' 'x2).
4426: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4427: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4428: (' 'x2).
4429: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4430: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4431: (' 'x2).
4432: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
4433: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
4434: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267 raeburn 4435: '<br /><br />'.
1.323 raeburn 4436: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267 raeburn 4437: ' value="'.$url.'" /></span>'.
4438: (' 'x2).
1.319 raeburn 4439: '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267 raeburn 4440: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4441: (' 'x2).
1.322 raeburn 4442: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
4443: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
4444: (' 'x2).
1.267 raeburn 4445: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4446: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4447: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltitools_secret_'.$i.'.type='."'text'".' } else { this.form.ltitools_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
4448: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4449: '</fieldset>'.
4450: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4451: '<span class="LC_nobreak">'.&mt('Display target:');
4452: my %currdisp;
4453: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4454: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4455: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 4456: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4457: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 4458: } else {
4459: $currdisp{'iframe'} = ' checked="checked"';
4460: }
4461: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4462: $currdisp{'width'} = $1;
4463: }
4464: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4465: $currdisp{'height'} = $1;
4466: }
1.296 raeburn 4467: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4468: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 4469: } else {
4470: $currdisp{'iframe'} = ' checked="checked"';
4471: }
1.298 raeburn 4472: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4473: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4474: $lt{$disp}.'</label>'.(' 'x2);
4475: }
4476: $datatable .= (' 'x4);
4477: foreach my $dimen ('width','height') {
4478: $datatable .= '<label>'.$lt{$dimen}.' '.
4479: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4480: (' 'x2);
4481: }
1.334 raeburn 4482: $datatable .= '</span><br />'.
1.296 raeburn 4483: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 4484: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
1.296 raeburn 4485: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4486: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
4487: '</textarea></div><div style=""></div><br />';
1.319 raeburn 4488: my %units = (
4489: 'passback' => 'days',
4490: 'roster' => 'seconds',
4491: );
1.267 raeburn 4492: foreach my $extra ('passback','roster') {
1.319 raeburn 4493: my $validsty = 'none';
4494: my $currvalid;
1.267 raeburn 4495: my $checkedon = '';
4496: my $checkedoff = ' checked="checked"';
4497: if ($settings->{$item}->{$extra}) {
4498: $checkedon = $checkedoff;
4499: $checkedoff = '';
1.319 raeburn 4500: $validsty = 'inline-block';
4501: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
4502: $currvalid = $settings->{$item}->{$extra.'valid'};
4503: }
4504: }
4505: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
4506: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4507: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
4508: &mt('No').'</label>'.(' 'x2).
4509: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
4510: &mt('Yes').'</label></span></div>'.
4511: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
4512: '<span class="LC_nobreak">'.
4513: &mt("at least [_1] $units{$extra} after launch",
4514: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
4515: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4516: }
1.319 raeburn 4517: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
1.267 raeburn 4518: if ($imgsrc) {
4519: $datatable .= $imgsrc.
4520: '<label><input type="checkbox" name="ltitools_image_del"'.
4521: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
4522: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
4523: } else {
4524: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4525: }
4526: if ($switchserver) {
4527: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4528: } else {
4529: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
4530: }
4531: $datatable .= '</span></fieldset>';
1.324 raeburn 4532: my (%checkedfields,%rolemaps,$userincdom);
1.267 raeburn 4533: if (ref($settings->{$item}) eq 'HASH') {
4534: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
4535: %checkedfields = %{$settings->{$item}->{'fields'}};
4536: }
1.324 raeburn 4537: $userincdom = $settings->{$item}->{'incdom'};
1.267 raeburn 4538: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
4539: %rolemaps = %{$settings->{$item}->{'roles'}};
4540: $checkedfields{'roles'} = 1;
4541: }
4542: }
4543: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4544: '<span class="LC_nobreak">';
1.324 raeburn 4545: my $userfieldstyle = 'display:none;';
4546: my $seluserdom = '';
4547: my $unseluserdom = ' selected="selected"';
1.267 raeburn 4548: foreach my $field (@fields) {
1.324 raeburn 4549: my ($checked,$onclick,$id,$spacer);
1.267 raeburn 4550: if ($checkedfields{$field}) {
4551: $checked = ' checked="checked"';
4552: }
1.324 raeburn 4553: if ($field eq 'user') {
4554: $id = ' id="ltitools_user_field_'.$i.'"';
4555: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
4556: if ($checked) {
4557: $userfieldstyle = 'display:inline-block';
4558: if ($userincdom) {
4559: $seluserdom = $unseluserdom;
4560: $unseluserdom = '';
4561: }
4562: }
4563: } else {
4564: $spacer = (' ' x2);
4565: }
1.267 raeburn 4566: $datatable .= '<label>'.
1.324 raeburn 4567: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
4568: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4569: }
1.324 raeburn 4570: $datatable .= '</span>';
4571: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
4572: '<span class="LC_nobreak"> : '.
4573: '<select name="ltitools_userincdom_'.$i.'">'.
4574: '<option value="">'.&mt('Select').'</option>'.
4575: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
4576: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
4577: '</select></span></div>';
4578: $datatable .= '</fieldset>'.
1.267 raeburn 4579: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4580: foreach my $role (@courseroles) {
4581: my ($selected,$selectnone);
4582: if (!$rolemaps{$role}) {
4583: $selectnone = ' selected="selected"';
4584: }
1.306 raeburn 4585: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4586: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4587: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
4588: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4589: foreach my $ltirole (@ltiroles) {
4590: unless ($selectnone) {
4591: if ($rolemaps{$role} eq $ltirole) {
4592: $selected = ' selected="selected"';
4593: } else {
4594: $selected = '';
4595: }
4596: }
4597: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
4598: }
4599: $datatable .= '</select></td>';
4600: }
1.273 raeburn 4601: $datatable .= '</tr></table></fieldset>';
4602: my %courseconfig;
4603: if (ref($settings->{$item}) eq 'HASH') {
4604: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
4605: %courseconfig = %{$settings->{$item}->{'crsconf'}};
4606: }
4607: }
4608: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4609: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 4610: my $checked;
4611: if ($courseconfig{$item}) {
4612: $checked = ' checked="checked"';
4613: }
4614: $datatable .= '<label>'.
4615: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
4616: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
4617: }
4618: $datatable .= '</span></fieldset>'.
1.267 raeburn 4619: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4620: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
4621: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
4622: my %custom = %{$settings->{$item}->{'custom'}};
4623: if (keys(%custom) > 0) {
4624: foreach my $key (sort(keys(%custom))) {
4625: $datatable .= '<tr><td><span class="LC_nobreak">'.
4626: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
4627: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
4628: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
4629: ' value="'.$custom{$key}.'" /></td></tr>';
4630: }
4631: }
4632: }
4633: $datatable .= '<tr><td><span class="LC_nobreak">'.
4634: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
4635: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
4636: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
4637: $datatable .= '</table></fieldset></td></tr>'."\n";
4638: $itemcount ++;
4639: }
4640: }
4641: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319 raeburn 4642: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267 raeburn 4643: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4644: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
4645: '<select name="ltitools_add_pos"'.$chgstr.'>';
4646: for (my $k=0; $k<$maxnum+1; $k++) {
4647: my $vpos = $k+1;
4648: my $selstr;
4649: if ($k == $maxnum) {
4650: $selstr = ' selected="selected" ';
4651: }
4652: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4653: }
4654: $datatable .= '</select> '."\n".
1.334 raeburn 4655: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.267 raeburn 4656: '<td colspan="2">'.
4657: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4658: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267 raeburn 4659: (' 'x2).
4660: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
4661: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4662: (' 'x2).
4663: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
4664: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4665: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
4666: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
4667: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267 raeburn 4668: '<br />'.
1.323 raeburn 4669: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267 raeburn 4670: (' 'x2).
4671: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
4672: (' 'x2).
1.322 raeburn 4673: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
4674: (' 'x2).
1.267 raeburn 4675: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
4676: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltitools_add_secret.type='."'text'".' } else { this.form.ltitools_add_secret.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n".
4677: '</fieldset>'.
4678: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4679: '<span class="LC_nobreak">'.&mt('Display target:');
4680: my %defaultdisp;
4681: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 4682: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4683: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
4684: $lt{$disp}.'</label>'.(' 'x2);
4685: }
4686: $datatable .= (' 'x4);
4687: foreach my $dimen ('width','height') {
4688: $datatable .= '<label>'.$lt{$dimen}.' '.
4689: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
4690: (' 'x2);
4691: }
1.334 raeburn 4692: $datatable .= '</span><br />'.
1.296 raeburn 4693: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 4694: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
1.296 raeburn 4695: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
1.334 raeburn 4696: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
1.296 raeburn 4697: '</div><div style=""></div><br />';
1.319 raeburn 4698: my %units = (
4699: 'passback' => 'days',
4700: 'roster' => 'seconds',
4701: );
4702: my %defaulttimes = (
4703: 'passback' => '7',
1.322 raeburn 4704: 'roster' => '300',
1.319 raeburn 4705: );
1.267 raeburn 4706: foreach my $extra ('passback','roster') {
1.319 raeburn 4707: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
4708: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4709: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
4710: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
4711: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
4712: &mt('Yes').'</label></span></div>'.
4713: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
4714: '<span class="LC_nobreak">'.
4715: &mt("at least [_1] $units{$extra} after launch",
4716: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
4717: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4718: }
1.319 raeburn 4719: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
1.267 raeburn 4720: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4721: if ($switchserver) {
4722: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4723: } else {
4724: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
4725: }
4726: $datatable .= '</span></fieldset>'.
4727: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4728: '<span class="LC_nobreak">';
4729: foreach my $field (@fields) {
1.324 raeburn 4730: my ($id,$onclick,$spacer);
4731: if ($field eq 'user') {
4732: $id = ' id="ltitools_user_field_add"';
4733: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
4734: } else {
4735: $spacer = (' ' x2);
4736: }
1.267 raeburn 4737: $datatable .= '<label>'.
1.324 raeburn 4738: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
4739: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4740: }
1.324 raeburn 4741: $datatable .= '</span>'.
4742: '<div style="display:none;" id="ltitools_user_div_add">'.
4743: '<span class="LC_nobreak"> : '.
4744: '<select name="ltitools_userincdom_add">'.
4745: '<option value="" selected="selected">'.&mt('Select').'</option>'.
4746: '<option value="0">'.&mt('username').'</option>'.
4747: '<option value="1">'.&mt('username:domain').'</option>'.
4748: '</select></span></div></fieldset>';
4749: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1.267 raeburn 4750: foreach my $role (@courseroles) {
4751: my ($checked,$checkednone);
1.306 raeburn 4752: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4753: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4754: '<select name="ltitools_add_roles_'.$role.'">'.
4755: '<option value="" selected="selected">'.&mt('Select').'</option>';
4756: foreach my $ltirole (@ltiroles) {
4757: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
4758: }
4759: $datatable .= '</select></td>';
4760: }
4761: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 4762: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4763: foreach my $item ('label','title','target','linktext','explanation','append') {
1.296 raeburn 4764: $datatable .= '<label>'.
4765: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4766: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 4767: }
4768: $datatable .= '</span></fieldset>'.
1.267 raeburn 4769: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4770: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4771: '<tr><td><span class="LC_nobreak">'.
4772: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4773: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4774: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
1.334 raeburn 4775: '</table></fieldset>'."\n".
1.267 raeburn 4776: '</td>'."\n".
4777: '</tr>'."\n";
4778: $itemcount ++;
4779: return $datatable;
4780: }
4781:
4782: sub ltitools_names {
4783: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 4784: 'title' => 'Title',
4785: 'version' => 'Version',
4786: 'msgtype' => 'Message Type',
1.323 raeburn 4787: 'sigmethod' => 'Signature Method',
1.296 raeburn 4788: 'url' => 'URL',
4789: 'key' => 'Key',
1.322 raeburn 4790: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 4791: 'secret' => 'Secret',
4792: 'icon' => 'Icon',
1.324 raeburn 4793: 'user' => 'User',
1.296 raeburn 4794: 'fullname' => 'Full Name',
4795: 'firstname' => 'First Name',
4796: 'lastname' => 'Last Name',
4797: 'email' => 'E-mail',
4798: 'roles' => 'Role',
1.298 raeburn 4799: 'window' => 'Window',
4800: 'tab' => 'Tab',
1.296 raeburn 4801: 'iframe' => 'iFrame',
4802: 'height' => 'Height',
4803: 'width' => 'Width',
4804: 'linktext' => 'Default Link Text',
4805: 'explanation' => 'Default Explanation',
4806: 'passback' => 'Tool can return grades:',
4807: 'roster' => 'Tool can retrieve roster:',
4808: 'crstarget' => 'Display target',
4809: 'crslabel' => 'Course label',
4810: 'crstitle' => 'Course title',
4811: 'crslinktext' => 'Link Text',
4812: 'crsexplanation' => 'Explanation',
1.318 raeburn 4813: 'crsappend' => 'Provider URL',
1.267 raeburn 4814: );
4815: return %lt;
4816: }
4817:
1.320 raeburn 4818: sub print_lti {
4819: my ($dom,$settings,$rowtotal) = @_;
4820: my $itemcount = 1;
4821: my $maxnum = 0;
4822: my $css_class;
4823: my %ordered;
4824: if (ref($settings) eq 'HASH') {
4825: foreach my $item (keys(%{$settings})) {
4826: if (ref($settings->{$item}) eq 'HASH') {
4827: my $num = $settings->{$item}{'order'};
4828: $ordered{$num} = $item;
4829: }
4830: }
4831: }
4832: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 4833: my $datatable;
1.320 raeburn 4834: my %lt = <i_names();
4835: if (keys(%ordered)) {
4836: my @items = sort { $a <=> $b } keys(%ordered);
4837: for (my $i=0; $i<@items; $i++) {
4838: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4839: my $item = $ordered{$items[$i]};
1.345 raeburn 4840: my ($key,$secret,$lifetime,$consumer,$requser,$current);
1.320 raeburn 4841: if (ref($settings->{$item}) eq 'HASH') {
4842: $key = $settings->{$item}->{'key'};
4843: $secret = $settings->{$item}->{'secret'};
4844: $lifetime = $settings->{$item}->{'lifetime'};
4845: $consumer = $settings->{$item}->{'consumer'};
1.345 raeburn 4846: $requser = $settings->{$item}->{'requser'};
1.320 raeburn 4847: $current = $settings->{$item};
4848: }
1.345 raeburn 4849: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
4850: my %checkedrequser = (
4851: yes => ' checked="checked"',
4852: no => '',
4853: );
4854: if (!$requser) {
4855: $checkedrequser{'no'} = $checkedrequser{'yes'};
4856: $checkedrequser{'yes'} = '';
1.352 raeburn 4857: }
1.320 raeburn 4858: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
4859: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4860: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
4861: for (my $k=0; $k<=$maxnum; $k++) {
4862: my $vpos = $k+1;
4863: my $selstr;
4864: if ($k == $i) {
4865: $selstr = ' selected="selected" ';
4866: }
4867: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4868: }
4869: $datatable .= '</select>'.(' 'x2).
4870: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
4871: &mt('Delete?').'</label></span></td>'.
4872: '<td colspan="2">'.
4873: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4874: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 4875: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
1.320 raeburn 4876: (' 'x2).
4877: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
4878: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4879: (' 'x2).
4880: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.345 raeburn 4881: 'value="'.$lifetime.'" size="3" /></span>'.
4882: (' 'x2).
4883: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
4884: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
4885: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 4886: '<br /><br />'.
4887: '<span class="LC_nobreak">'.$lt{'key'}.
4888: ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
4889: (' 'x2).
4890: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4891: '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
4892: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.lti_secret_'.$i.'.type='."'text'".' } else { this.form.lti_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
4893: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
1.325 raeburn 4894: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
1.320 raeburn 4895: $itemcount ++;
4896: }
4897: }
4898: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4899: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
4900: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4901: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
4902: '<select name="lti_pos_add"'.$chgstr.'>';
4903: for (my $k=0; $k<$maxnum+1; $k++) {
4904: my $vpos = $k+1;
4905: my $selstr;
4906: if ($k == $maxnum) {
4907: $selstr = ' selected="selected" ';
4908: }
4909: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4910: }
4911: $datatable .= '</select> '."\n".
1.334 raeburn 4912: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.320 raeburn 4913: '<td colspan="2">'.
4914: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4915: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 4916: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
1.320 raeburn 4917: (' 'x2).
4918: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
4919: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4920: (' 'x2).
1.345 raeburn 4921: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span> '."\n".
4922: (' 'x2).
4923: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
4924: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
4925: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 4926: '<br /><br />'.
4927: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
4928: (' 'x2).
4929: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
4930: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.lti_secret_add.type='."'text'".' } else { this.form.lti_secret_add.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n".
1.325 raeburn 4931: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
1.320 raeburn 4932: '</td>'."\n".
4933: '</tr>'."\n";
4934: $$rowtotal ++;
4935: return $datatable;;
4936: }
4937:
4938: sub lti_names {
4939: my %lt = &Apache::lonlocal::texthash(
4940: 'version' => 'LTI Version',
4941: 'url' => 'URL',
4942: 'key' => 'Key',
1.322 raeburn 4943: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 4944: 'consumer' => 'Consumer',
1.320 raeburn 4945: 'secret' => 'Secret',
1.345 raeburn 4946: 'requser' => "User's identity sent",
1.320 raeburn 4947: 'email' => 'Email address',
4948: 'sourcedid' => 'User ID',
4949: 'other' => 'Other',
4950: 'passback' => 'Can return grades to Consumer:',
4951: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 4952: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 4953: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 4954: );
4955: return %lt;
4956: }
4957:
4958: sub lti_options {
1.325 raeburn 4959: my ($num,$current,$itemcount,%lt) = @_;
1.320 raeburn 4960: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield);
4961: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
4962: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
4963: $checked{'makecrs'}{'N'} = ' checked="checked"';
4964: $checked{'mapcrstype'} = {};
4965: $checked{'makeuser'} = {};
4966: $checked{'selfenroll'} = {};
4967: $checked{'crssec'} = {};
4968: $checked{'crssecsrc'} = {};
1.325 raeburn 4969: $checked{'lcauth'} = {};
1.326 raeburn 4970: $checked{'menuitem'} = {};
1.325 raeburn 4971: if ($num eq 'add') {
4972: $checked{'lcauth'}{'lti'} = ' checked="checked"';
4973: }
1.320 raeburn 4974: my $userfieldsty = 'none';
4975: my $crsfieldsty = 'none';
4976: my $crssecfieldsty = 'none';
4977: my $secsrcfieldsty = 'none';
1.337 raeburn 4978: my $passbacksty = 'none';
1.345 raeburn 4979: my $optionsty = 'block';
1.325 raeburn 4980: my $lcauthparm;
4981: my $lcauthparmstyle = 'display:none';
4982: my $lcauthparmtext;
1.326 raeburn 4983: my $menusty;
1.325 raeburn 4984: my $numinrow = 4;
1.326 raeburn 4985: my %menutitles = <imenu_titles();
1.320 raeburn 4986:
4987: if (ref($current) eq 'HASH') {
1.345 raeburn 4988: if (!$current->{'requser'}) {
4989: $optionsty = 'none';
4990: }
1.320 raeburn 4991: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
4992: $checked{'mapuser'}{'sourcedid'} = '';
4993: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
4994: $checked{'mapuser'}{'email'} = ' checked="checked"';
4995: } else {
4996: $checked{'mapuser'}{'other'} = ' checked="checked"';
4997: $userfield = $current->{'mapuser'};
4998: $userfieldsty = 'inline-block';
4999: }
5000: }
5001: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
5002: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
5003: if ($current->{'mapcrs'} eq 'context_id') {
5004: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
5005: } else {
5006: $checked{'mapcrs'}{'other'} = ' checked="checked"';
5007: $cidfield = $current->{'mapcrs'};
5008: $crsfieldsty = 'inline-block';
5009: }
5010: }
5011: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
5012: foreach my $type (@{$current->{'mapcrstype'}}) {
5013: $checked{'mapcrstype'}{$type} = ' checked="checked"';
5014: }
5015: }
1.345 raeburn 5016: if ($current->{'makecrs'}) {
1.320 raeburn 5017: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 5018: }
1.320 raeburn 5019: if (ref($current->{'makeuser'}) eq 'ARRAY') {
5020: foreach my $role (@{$current->{'makeuser'}}) {
5021: $checked{'makeuser'}{$role} = ' checked="checked"';
5022: }
5023: }
1.325 raeburn 5024: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
5025: $checked{'lcauth'}{$1} = ' checked="checked"';
5026: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
5027: $lcauthparm = $current->{'lcauthparm'};
5028: $lcauthparmstyle = 'display:table-row';
5029: if ($current->{'lcauth'} eq 'localauth') {
5030: $lcauthparmtext = &mt('Local auth argument');
5031: } else {
5032: $lcauthparmtext = &mt('Kerberos domain');
5033: }
5034: }
5035: }
1.320 raeburn 5036: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
5037: foreach my $role (@{$current->{'selfenroll'}}) {
5038: $checked{'selfenroll'}{$role} = ' checked="checked"';
5039: }
5040: }
5041: if (ref($current->{'maproles'}) eq 'HASH') {
5042: %rolemaps = %{$current->{'maproles'}};
5043: }
5044: if ($current->{'section'} ne '') {
5045: $checked{'crssec'}{'Y'} = ' checked="checked"';
5046: $crssecfieldsty = 'inline-block';
5047: if ($current->{'section'} eq 'course_section_sourcedid') {
5048: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
5049: } else {
5050: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
5051: $crssecsrc = $current->{'section'};
5052: $secsrcfieldsty = 'inline-block';
5053: }
5054: } else {
5055: $checked{'crssec'}{'N'} = ' checked="checked"';
5056: }
1.326 raeburn 5057: if ($current->{'topmenu'}) {
5058: $checked{'topmenu'}{'Y'} = ' checked="checked"';
5059: } else {
5060: $checked{'topmenu'}{'N'} = ' checked="checked"';
5061: }
5062: if ($current->{'inlinemenu'}) {
5063: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5064: } else {
5065: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
5066: }
5067: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
5068: $menusty = 'inline-block';
5069: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
5070: foreach my $item (@{$current->{'lcmenu'}}) {
5071: if (exists($menutitles{$item})) {
5072: $checked{'menuitem'}{$item} = ' checked="checked"';
5073: }
5074: }
5075: }
5076: } else {
5077: $menusty = 'none';
5078: }
1.320 raeburn 5079: } else {
5080: $checked{'makecrs'}{'N'} = ' checked="checked"';
5081: $checked{'crssec'}{'N'} = ' checked="checked"';
1.326 raeburn 5082: $checked{'topmenu'}{'N'} = ' checked="checked"';
5083: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5084: $checked{'menuitem'}{'grades'} = ' checked="checked"';
5085: $menusty = 'inline-block';
1.320 raeburn 5086: }
1.325 raeburn 5087: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 5088: my %coursetypetitles = &Apache::lonlocal::texthash (
5089: official => 'Official',
5090: unofficial => 'Unofficial',
5091: community => 'Community',
5092: textbook => 'Textbook',
5093: placement => 'Placement Test',
1.325 raeburn 5094: lti => 'LTI Provider',
1.320 raeburn 5095: );
1.325 raeburn 5096: my @authtypes = ('internal','krb4','krb5','localauth');
5097: my %shortauth = (
5098: internal => 'int',
5099: krb4 => 'krb4',
5100: krb5 => 'krb5',
5101: localauth => 'loc'
5102: );
5103: my %authnames = &authtype_names();
1.320 raeburn 5104: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
5105: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
5106: my @courseroles = ('cc','in','ta','ep','st');
5107: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
5108: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
5109: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
5110: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 5111: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 5112: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.345 raeburn 5113: my $output = '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 5114: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
5115: foreach my $option ('sourcedid','email','other') {
5116: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
5117: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
5118: ($option eq 'other' ? '' : (' 'x2) );
5119: }
5120: $output .= '</span></div>'.
5121: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
5122: '<input type="text" name="lti_customuser_'.$num.'" '.
5123: 'value="'.$userfield.'" /></div></fieldset>'.
1.345 raeburn 5124: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
1.320 raeburn 5125: foreach my $ltirole (@lticourseroles) {
5126: my ($selected,$selectnone);
5127: if ($rolemaps{$ltirole} eq '') {
5128: $selectnone = ' selected="selected"';
5129: }
5130: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
5131: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
5132: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5133: foreach my $role (@courseroles) {
5134: unless ($selectnone) {
5135: if ($rolemaps{$ltirole} eq $role) {
5136: $selected = ' selected="selected"';
5137: } else {
5138: $selected = '';
5139: }
5140: }
5141: $output .= '<option value="'.$role.'"'.$selected.'>'.
5142: &Apache::lonnet::plaintext($role,'Course').
5143: '</option>';
5144: }
5145: $output .= '</select></td>';
5146: }
5147: $output .= '</tr></table></fieldset>'.
1.345 raeburn 5148: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 5149: foreach my $ltirole (@ltiroles) {
5150: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
5151: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
5152: }
5153: $output .= '</fieldset>'.
1.345 raeburn 5154: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 5155: '<table>'.
5156: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
5157: '</table>'.
5158: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
5159: '<td class="LC_left_item">';
5160: foreach my $auth ('lti',@authtypes) {
5161: my $authtext;
5162: if ($auth eq 'lti') {
5163: $authtext = &mt('None');
5164: } else {
5165: $authtext = $authnames{$shortauth{$auth}};
5166: }
5167: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
5168: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
5169: $authtext.'</label></span> ';
5170: }
5171: $output .= '</td></tr>'.
5172: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
5173: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
5174: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
5175: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
5176: '</table></fieldset>'.
1.345 raeburn 5177: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 5178: '<div class="LC_floatleft"><span class="LC_nobreak">'.
5179: &mt('Unique course identifier').': ';
5180: foreach my $option ('course_offering_sourcedid','context_id','other') {
5181: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
5182: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
5183: ($option eq 'other' ? '' : (' 'x2) );
5184: }
1.334 raeburn 5185: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 5186: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
5187: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
5188: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
5189: foreach my $type (@coursetypes) {
5190: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
5191: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
5192: (' 'x2);
5193: }
5194: $output .= '</span></fieldset>'.
1.345 raeburn 5195: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 5196: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
5197: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
5198: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
5199: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
5200: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
5201: '</fieldset>'.
1.345 raeburn 5202: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 5203: foreach my $lticrsrole (@lticourseroles) {
5204: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
5205: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
5206: }
5207: $output .= '</fieldset>'.
1.345 raeburn 5208: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 5209: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
5210: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
5211: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
5212: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 5213: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 5214: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
5215: '<span class="LC_nobreak">'.&mt('From').':<label>'.
5216: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
5217: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
5218: &mt('Standard field').'</label>'.(' 'x2).
5219: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
5220: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 5221: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 5222: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 5223: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
5224: my ($pb1p1chk,$pb1p0chk,$onclickpb);
5225: foreach my $extra ('roster','passback') {
1.320 raeburn 5226: my $checkedon = '';
5227: my $checkedoff = ' checked="checked"';
1.337 raeburn 5228: if ($extra eq 'passback') {
5229: $pb1p1chk = ' checked="checked"';
5230: $pb1p0chk = '';
5231: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
5232: } else {
5233: $onclickpb = '';
5234: }
1.320 raeburn 5235: if (ref($current) eq 'HASH') {
5236: if (($current->{$extra})) {
5237: $checkedon = $checkedoff;
5238: $checkedoff = '';
1.337 raeburn 5239: if ($extra eq 'passback') {
5240: $passbacksty = 'inline-block';
5241: }
5242: if ($current->{'passbackformat'} eq '1.0') {
5243: $pb1p0chk = ' checked="checked"';
5244: $pb1p1chk = '';
5245: }
1.320 raeburn 5246: }
5247: }
5248: $output .= $lt{$extra}.' '.
1.337 raeburn 5249: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 5250: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 5251: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 5252: &mt('Yes').'</label><br />';
5253: }
1.337 raeburn 5254: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
5255: '<span class="LC_nobreak">'.&mt('Grade format').
5256: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
5257: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
5258: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
5259: &mt('Outcomes Extension (1.0)').'</label></span></div></fieldset>'.
1.345 raeburn 5260: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Course defaults (Course Coordinator can override)').'</legend>'.
1.326 raeburn 5261: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
5262: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
5263: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5264: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
1.334 raeburn 5265: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
1.326 raeburn 5266: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5267: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
5268: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
5269: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5270: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
1.334 raeburn 5271: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
1.326 raeburn 5272: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5273: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
5274: '<span class="LC_nobreak">'.&mt('Menu items').': ';
5275: foreach my $type ('fullname','coursetitle','role','logout','grades') {
5276: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
5277: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
5278: (' 'x2);
5279: }
1.334 raeburn 5280: $output .= '</span></div></fieldset>';
1.320 raeburn 5281: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
5282: #
5283: # $output .= '</fieldset>'.
5284: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
5285: return $output;
5286: }
5287:
1.326 raeburn 5288: sub ltimenu_titles {
5289: return &Apache::lonlocal::texthash(
5290: fullname => 'Full name',
5291: coursetitle => 'Course title',
5292: role => 'Role',
5293: logout => 'Logout',
5294: grades => 'Grades',
5295: );
5296: }
5297:
1.121 raeburn 5298: sub print_coursedefaults {
1.139 raeburn 5299: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 5300: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 5301: my $itemcount = 1;
1.192 raeburn 5302: my %choices = &Apache::lonlocal::texthash (
5303: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 5304: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 5305: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
5306: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 5307: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
5308: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.314 raeburn 5309: texengine => 'Default method to display mathematics',
1.257 raeburn 5310: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 5311: canclone => "People who may clone a course (besides course's owner and coordinators)",
5312: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 5313: );
1.198 raeburn 5314: my %staticdefaults = (
5315: anonsurvey_threshold => 10,
5316: uploadquota => 500,
1.257 raeburn 5317: postsubmit => 60,
1.276 raeburn 5318: mysqltables => 172800,
1.198 raeburn 5319: );
1.139 raeburn 5320: if ($position eq 'top') {
1.257 raeburn 5321: %defaultchecked = (
5322: 'canuse_pdfforms' => 'off',
5323: 'uselcmath' => 'on',
5324: 'usejsme' => 'on',
1.289 raeburn 5325: 'canclone' => 'none',
1.257 raeburn 5326: );
5327: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.349 raeburn 5328: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 5329: if (ref($settings) eq 'HASH') {
5330: if ($settings->{'texengine'}) {
5331: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
5332: $deftex = $settings->{'texengine'};
5333: }
5334: }
5335: }
5336: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5337: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
5338: '<span class="LC_nobreak">'.$choices{'texengine'}.
5339: '</span></td><td class="LC_right_item">'.
5340: '<select name="texengine">'."\n";
5341: my %texoptions = (
5342: MathJax => 'MathJax',
5343: mimetex => &mt('Convert to Images'),
5344: tth => &mt('TeX to HTML'),
5345: );
5346: foreach my $renderer ('MathJax','mimetex','tth') {
5347: my $selected = '';
5348: if ($renderer eq $deftex) {
5349: $selected = ' selected="selected"';
5350: }
5351: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
5352: }
5353: $mathdisp .= '</select></td></tr>'."\n";
5354: $itemcount ++;
1.139 raeburn 5355: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 5356: \%choices,$itemcount);
1.314 raeburn 5357: $datatable = $mathdisp.$datatable;
1.264 raeburn 5358: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5359: $datatable .=
1.306 raeburn 5360: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 5361: '<span class="LC_nobreak">'.$choices{'canclone'}.
5362: '</span></td><td class="LC_left_item">';
5363: my $currcanclone = 'none';
5364: my $onclick;
5365: my @cloneoptions = ('none','domain');
5366: my %clonetitles = (
5367: none => 'No additional course requesters',
5368: domain => "Any course requester in course's domain",
5369: instcode => 'Course requests for official courses ...',
5370: );
5371: my (%codedefaults,@code_order,@posscodes);
5372: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
5373: \@code_order) eq 'ok') {
5374: if (@code_order > 0) {
5375: push(@cloneoptions,'instcode');
5376: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
5377: }
5378: }
5379: if (ref($settings) eq 'HASH') {
5380: if ($settings->{'canclone'}) {
5381: if (ref($settings->{'canclone'}) eq 'HASH') {
5382: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
5383: if (@code_order > 0) {
5384: $currcanclone = 'instcode';
5385: @posscodes = @{$settings->{'canclone'}{'instcode'}};
5386: }
5387: }
5388: } elsif ($settings->{'canclone'} eq 'domain') {
5389: $currcanclone = $settings->{'canclone'};
5390: }
5391: }
1.289 raeburn 5392: }
1.264 raeburn 5393: foreach my $option (@cloneoptions) {
5394: my ($checked,$additional);
5395: if ($currcanclone eq $option) {
5396: $checked = ' checked="checked"';
5397: }
5398: if ($option eq 'instcode') {
5399: if (@code_order) {
5400: my $show = 'none';
5401: if ($checked) {
5402: $show = 'block';
5403: }
1.317 raeburn 5404: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 5405: &mt('Institutional codes for new and cloned course have identical:').
5406: '<br />';
5407: foreach my $item (@code_order) {
5408: my $codechk;
5409: if ($checked) {
5410: if (grep(/^\Q$item\E$/,@posscodes)) {
5411: $codechk = ' checked="checked"';
5412: }
5413: }
5414: $additional .= '<label>'.
5415: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
5416: $item.'</label>';
5417: }
5418: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
5419: }
5420: }
5421: $datatable .=
5422: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
5423: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
5424: '</label> '.$additional.'</span><br />';
5425: }
5426: $datatable .= '</td>'.
5427: '</tr>';
5428: $itemcount ++;
1.139 raeburn 5429: } else {
5430: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 5431: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 5432: my $currusecredits = 0;
1.257 raeburn 5433: my $postsubmitclient = 1;
1.271 raeburn 5434: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 5435: if (ref($settings) eq 'HASH') {
5436: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 5437: if (ref($settings->{'uploadquota'}) eq 'HASH') {
5438: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
5439: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
5440: }
5441: }
1.192 raeburn 5442: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 5443: foreach my $type (@types) {
5444: next if ($type eq 'community');
5445: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
5446: if ($defcredits{$type} ne '') {
5447: $currusecredits = 1;
5448: }
5449: }
5450: }
5451: if (ref($settings->{'postsubmit'}) eq 'HASH') {
5452: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
5453: $postsubmitclient = 0;
5454: foreach my $type (@types) {
5455: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5456: }
5457: } else {
5458: foreach my $type (@types) {
5459: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
5460: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 5461: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 5462: } else {
5463: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5464: }
5465: } else {
5466: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5467: }
5468: }
5469: }
5470: } else {
5471: foreach my $type (@types) {
5472: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 5473: }
5474: }
1.276 raeburn 5475: if (ref($settings->{'mysqltables'}) eq 'HASH') {
5476: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
5477: $currmysql{$type} = $settings->{'mysqltables'}{$type};
5478: }
5479: } else {
5480: foreach my $type (@types) {
5481: $currmysql{$type} = $staticdefaults{'mysqltables'};
5482: }
5483: }
1.258 raeburn 5484: } else {
5485: foreach my $type (@types) {
5486: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5487: }
1.139 raeburn 5488: }
5489: if (!$currdefresponder) {
1.198 raeburn 5490: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 5491: } elsif ($currdefresponder < 1) {
5492: $currdefresponder = 1;
5493: }
1.198 raeburn 5494: foreach my $type (@types) {
5495: if ($curruploadquota{$type} eq '') {
5496: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
5497: }
5498: }
1.139 raeburn 5499: $datatable .=
1.192 raeburn 5500: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5501: $choices{'anonsurvey_threshold'}.
1.139 raeburn 5502: '</span></td>'.
5503: '<td class="LC_right_item"><span class="LC_nobreak">'.
5504: '<input type="text" name="anonsurvey_threshold"'.
5505: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 5506: '</td></tr>'."\n";
5507: $itemcount ++;
5508: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5509: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5510: $choices{'uploadquota'}.
5511: '</span></td>'.
1.306 raeburn 5512: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 5513: '<table><tr>';
1.198 raeburn 5514: foreach my $type (@types) {
1.306 raeburn 5515: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 5516: '<input type="text" name="uploadquota_'.$type.'"'.
5517: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
5518: }
5519: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 5520: $itemcount ++;
1.236 raeburn 5521: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 5522: my $display = 'none';
1.192 raeburn 5523: if ($currusecredits) {
5524: $display = 'block';
5525: }
5526: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 5527: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
5528: foreach my $type (@types) {
5529: next if ($type eq 'community');
1.306 raeburn 5530: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5531: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 5532: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 5533: }
5534: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 5535: %defaultchecked = ('coursecredits' => 'off');
5536: @toggles = ('coursecredits');
5537: my $current = {
5538: 'coursecredits' => $currusecredits,
5539: };
5540: (my $table,$itemcount) =
5541: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 5542: \%choices,$itemcount,$onclick,$additional,'left');
5543: $datatable .= $table;
5544: $onclick = "toggleDisplay(this.form,'studentsubmission');";
5545: my $display = 'none';
5546: if ($postsubmitclient) {
5547: $display = 'block';
5548: }
5549: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 5550: &mt('Number of seconds submit is disabled').'<br />'.
5551: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
5552: '<table><tr>';
1.257 raeburn 5553: foreach my $type (@types) {
1.306 raeburn 5554: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5555: '<input type="text" name="'.$type.'_timeout" value="'.
5556: $deftimeout{$type}.'" size="5" /></td>';
5557: }
5558: $additional .= '</tr></table></div>'."\n";
5559: %defaultchecked = ('postsubmit' => 'on');
5560: @toggles = ('postsubmit');
1.280 raeburn 5561: $current = {
5562: 'postsubmit' => $postsubmitclient,
5563: };
1.257 raeburn 5564: ($table,$itemcount) =
5565: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
5566: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 5567: $datatable .= $table;
1.276 raeburn 5568: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5569: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5570: $choices{'mysqltables'}.
5571: '</span></td>'.
1.306 raeburn 5572: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 5573: '<table><tr>';
5574: foreach my $type (@types) {
1.306 raeburn 5575: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 5576: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 5577: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 5578: }
5579: $datatable .= '</tr></table></td></tr>'."\n";
5580: $itemcount ++;
5581:
1.139 raeburn 5582: }
1.192 raeburn 5583: $$rowtotal += $itemcount;
1.121 raeburn 5584: return $datatable;
1.118 jms 5585: }
5586:
1.231 raeburn 5587: sub print_selfenrollment {
5588: my ($position,$dom,$settings,$rowtotal) = @_;
5589: my ($css_class,$datatable);
5590: my $itemcount = 1;
1.271 raeburn 5591: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 5592: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 5593: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
5594: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 5595: my @rows;
5596: my $key;
5597: if ($position eq 'top') {
5598: $key = 'admin';
5599: if (ref($rowsref) eq 'ARRAY') {
5600: @rows = @{$rowsref};
5601: }
5602: } elsif ($position eq 'middle') {
5603: $key = 'default';
5604: @rows = ('types','registered','approval','limit');
5605: }
5606: foreach my $row (@rows) {
5607: if (defined($titlesref->{$row})) {
5608: $itemcount ++;
5609: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5610: $datatable .= '<tr'.$css_class.'>'.
5611: '<td>'.$titlesref->{$row}.'</td>'.
5612: '<td class="LC_left_item">'.
5613: '<table><tr>';
5614: my (%current,%currentcap);
5615: if (ref($settings) eq 'HASH') {
5616: if (ref($settings->{$key}) eq 'HASH') {
5617: foreach my $type (@types) {
5618: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5619: $current{$type} = $settings->{$key}->{$type}->{$row};
5620: }
5621: if (($row eq 'limit') && ($key eq 'default')) {
5622: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5623: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
5624: }
5625: }
5626: }
5627: }
5628: }
5629: my %roles = (
5630: '0' => &Apache::lonnet::plaintext('dc'),
5631: );
5632:
5633: foreach my $type (@types) {
5634: unless (($row eq 'registered') && ($key eq 'default')) {
5635: $datatable .= '<th>'.&mt($type).'</th>';
5636: }
5637: }
5638: unless (($row eq 'registered') && ($key eq 'default')) {
5639: $datatable .= '</tr><tr>';
5640: }
5641: foreach my $type (@types) {
5642: if ($type eq 'community') {
5643: $roles{'1'} = &mt('Community personnel');
5644: } else {
5645: $roles{'1'} = &mt('Course personnel');
5646: }
5647: $datatable .= '<td style="vertical-align: top">';
5648: if ($position eq 'top') {
5649: my %checked;
5650: if ($current{$type} eq '0') {
5651: $checked{'0'} = ' checked="checked"';
5652: } else {
5653: $checked{'1'} = ' checked="checked"';
5654: }
5655: foreach my $role ('1','0') {
5656: $datatable .= '<span class="LC_nobreak"><label>'.
5657: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
5658: 'value="'.$role.'"'.$checked{$role}.' />'.
5659: $roles{$role}.'</label></span> ';
5660: }
5661: } else {
5662: if ($row eq 'types') {
5663: my %checked;
5664: if ($current{$type} =~ /^(all|dom)$/) {
5665: $checked{$1} = ' checked="checked"';
5666: } else {
5667: $checked{''} = ' checked="checked"';
5668: }
5669: foreach my $val ('','dom','all') {
5670: $datatable .= '<span class="LC_nobreak"><label>'.
5671: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5672: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5673: }
5674: } elsif ($row eq 'registered') {
5675: my %checked;
5676: if ($current{$type} eq '1') {
5677: $checked{'1'} = ' checked="checked"';
5678: } else {
5679: $checked{'0'} = ' checked="checked"';
5680: }
5681: foreach my $val ('0','1') {
5682: $datatable .= '<span class="LC_nobreak"><label>'.
5683: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5684: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5685: }
5686: } elsif ($row eq 'approval') {
5687: my %checked;
5688: if ($current{$type} =~ /^([12])$/) {
5689: $checked{$1} = ' checked="checked"';
5690: } else {
5691: $checked{'0'} = ' checked="checked"';
5692: }
5693: for my $val (0..2) {
5694: $datatable .= '<span class="LC_nobreak"><label>'.
5695: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5696: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5697: }
5698: } elsif ($row eq 'limit') {
5699: my %checked;
5700: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
5701: $checked{$1} = ' checked="checked"';
5702: } else {
5703: $checked{'none'} = ' checked="checked"';
5704: }
5705: my $cap;
5706: if ($currentcap{$type} =~ /^\d+$/) {
5707: $cap = $currentcap{$type};
5708: }
5709: foreach my $val ('none','allstudents','selfenrolled') {
5710: $datatable .= '<span class="LC_nobreak"><label>'.
5711: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5712: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5713: }
5714: $datatable .= '<br />'.
5715: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
5716: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
5717: '</span>';
5718: }
5719: }
5720: $datatable .= '</td>';
5721: }
5722: $datatable .= '</tr>';
5723: }
5724: $datatable .= '</table></td></tr>';
5725: }
5726: } elsif ($position eq 'bottom') {
1.235 raeburn 5727: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
5728: }
5729: $$rowtotal += $itemcount;
5730: return $datatable;
5731: }
5732:
5733: sub print_validation_rows {
5734: my ($caller,$dom,$settings,$rowtotal) = @_;
5735: my ($itemsref,$namesref,$fieldsref);
5736: if ($caller eq 'selfenroll') {
5737: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
5738: } elsif ($caller eq 'requestcourses') {
5739: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
5740: }
5741: my %currvalidation;
5742: if (ref($settings) eq 'HASH') {
5743: if (ref($settings->{'validation'}) eq 'HASH') {
5744: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 5745: }
1.235 raeburn 5746: }
5747: my $datatable;
5748: my $itemcount = 0;
5749: foreach my $item (@{$itemsref}) {
5750: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5751: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5752: $namesref->{$item}.
5753: '</span></td>'.
5754: '<td class="LC_left_item">';
5755: if (($item eq 'url') || ($item eq 'button')) {
5756: $datatable .= '<span class="LC_nobreak">'.
5757: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
5758: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
5759: } elsif ($item eq 'fields') {
5760: my @currfields;
5761: if (ref($currvalidation{$item}) eq 'ARRAY') {
5762: @currfields = @{$currvalidation{$item}};
5763: }
5764: foreach my $field (@{$fieldsref}) {
5765: my $check = '';
5766: if (grep(/^\Q$field\E$/,@currfields)) {
5767: $check = ' checked="checked"';
5768: }
5769: $datatable .= '<span class="LC_nobreak"><label>'.
5770: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
5771: ' value="'.$field.'"'.$check.' />'.$field.
5772: '</label></span> ';
5773: }
5774: } elsif ($item eq 'markup') {
1.334 raeburn 5775: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 5776: $currvalidation{$item}.
1.231 raeburn 5777: '</textarea>';
1.235 raeburn 5778: }
5779: $datatable .= '</td></tr>'."\n";
5780: if (ref($rowtotal)) {
1.231 raeburn 5781: $itemcount ++;
5782: }
5783: }
1.235 raeburn 5784: if ($caller eq 'requestcourses') {
5785: my %currhash;
1.248 raeburn 5786: if (ref($settings) eq 'HASH') {
5787: if (ref($settings->{'validation'}) eq 'HASH') {
5788: if ($settings->{'validation'}{'dc'} ne '') {
5789: $currhash{$settings->{'validation'}{'dc'}} = 1;
5790: }
1.235 raeburn 5791: }
5792: }
5793: my $numinrow = 2;
5794: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
5795: 'validationdc',%currhash);
1.247 raeburn 5796: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 5797: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 5798: if ($numdc > 1) {
1.247 raeburn 5799: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 5800: } else {
1.247 raeburn 5801: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 5802: }
1.247 raeburn 5803: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 5804: $itemcount ++;
5805: }
5806: if (ref($rowtotal)) {
5807: $$rowtotal += $itemcount;
5808: }
1.231 raeburn 5809: return $datatable;
5810: }
5811:
1.357 raeburn 5812: sub print_privacy {
5813: my ($position,$dom,$settings,$rowtotal) = @_;
5814: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
5815: my $itemcount = 0;
5816: unless ($position eq 'top') {
5817: @items = ('domain','author','course','community');
5818: %names = &Apache::lonlocal::texthash (
5819: domain => 'Assigned domain role(s)',
5820: author => 'Assigned co-author role(s)',
5821: course => 'Assigned course role(s)',
5822: community => 'Assigned community role',
5823: );
5824: $numinrow = 4;
5825: ($othertitle,$usertypes,$types) =
5826: &Apache::loncommon::sorted_inst_types($dom);
5827: }
5828: if (($position eq 'top') || ($position eq 'middle')) {
5829: my (%by_ip,%by_location,@intdoms,@instdoms);
5830: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
5831: if ($position eq 'top') {
5832: my %curr;
5833: my @options = ('none','user','domain','auto');
5834: my %titles = &Apache::lonlocal::texthash (
5835: none => 'Not allowed',
5836: user => 'User authorizes',
5837: domain => 'DC authorizes',
5838: auto => 'Unrestricted',
5839: instdom => 'Other domain shares institution/provider',
5840: extdom => 'Other domain has different institution/provider',
5841: );
5842: my %names = &Apache::lonlocal::texthash (
5843: domain => 'Domain role',
5844: author => 'Co-author role',
5845: course => 'Course role',
5846: community => 'Community role',
5847: );
5848: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5849: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5850: foreach my $domtype ('instdom','extdom') {
5851: my (%checked,$skip);
5852: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5853: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
5854: '<td class="LC_left_item">';
5855: if ($domtype eq 'instdom') {
5856: unless (@instdoms > 1) {
5857: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
5858: $skip = 1;
5859: }
5860: } elsif ($domtype eq 'extdom') {
5861: if (keys(%by_location) == 0) {
5862: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
5863: $skip = 1;
5864: }
5865: }
5866: unless ($skip) {
5867: foreach my $roletype ('domain','author','course','community') {
5868: $checked{'auto'} = ' checked="checked"';
5869: if (ref($settings) eq 'HASH') {
5870: if (ref($settings->{approval}) eq 'HASH') {
5871: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
5872: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
5873: $checked{$1} = ' checked="checked"';
5874: $checked{'auto'} = '';
5875: }
5876: }
5877: }
5878: }
5879: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
5880: foreach my $option (@options) {
5881: $datatable .= '<span class="LC_nobreak"><label>'.
5882: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
5883: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
5884: '</label></span> ';
5885: }
5886: $datatable .= '</fieldset>';
5887: }
5888: }
5889: $datatable .= '</td></tr>';
5890: $itemcount ++;
5891: }
5892: } elsif ($position eq 'middle') {
5893: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
5894: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5895: foreach my $item (@{$types}) {
5896: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
5897: $numinrow,$itemcount,'','','','','',
5898: '',$usertypes->{$item});
5899: $itemcount ++;
5900: }
5901: }
5902: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
5903: $numinrow,$itemcount,'','','','','',
5904: '',$othertitle);
5905: $itemcount ++;
5906: } else {
5907: $datatable .= &mt('Nothing to set here, as there are no other domains');
5908: }
5909: }
5910: } else {
5911: my $prefix;
5912: if ($position eq 'lower') {
5913: $prefix = 'priv';
5914: } else {
5915: $prefix = 'unpriv';
5916: }
5917: foreach my $item (@items) {
5918: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
5919: $numinrow,$itemcount,'','','','','',
5920: '',$names{$item});
5921: $itemcount ++;
5922: }
5923: }
5924: if (ref($rowtotal)) {
5925: $$rowtotal += $itemcount;
5926: }
5927: return $datatable;
5928: }
5929:
1.354 raeburn 5930: sub print_passwords {
5931: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
5932: my ($datatable,$css_class);
5933: my $itemcount = 0;
5934: my %titles = &Apache::lonlocal::texthash (
5935: captcha => '"Forgot Password" CAPTCHA validation',
5936: link => 'Reset link expiration (hours)',
5937: case => 'Case-sensitive usernames/e-mail',
5938: prelink => 'Information required (form 1)',
5939: postlink => 'Information required (form 2)',
5940: emailsrc => 'LON-CAPA e-mail address type(s)',
5941: customtext => 'Domain specific text (HTML)',
5942: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
5943: intauth_check => 'Check bcrypt cost if authenticated',
5944: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
5945: permanent => 'Permanent e-mail address',
5946: critical => 'Critical notification address',
5947: notify => 'Notification address',
5948: min => 'Minimum password length',
5949: max => 'Maximum password length',
5950: chars => 'Required characters',
5951: expire => 'Password expiration (days)',
1.356 raeburn 5952: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 5953: );
5954: if ($position eq 'top') {
5955: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5956: my $shownlinklife = 2;
5957: my $prelink = 'both';
5958: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
5959: if (ref($settings) eq 'HASH') {
5960: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
5961: $shownlinklife = $settings->{resetlink};
5962: }
5963: if (ref($settings->{resetcase}) eq 'ARRAY') {
5964: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
5965: }
5966: if ($settings->{resetprelink} =~ /^(both|either)$/) {
5967: $prelink = $settings->{resetprelink};
5968: }
5969: if (ref($settings->{resetpostlink}) eq 'HASH') {
5970: %postlink = %{$settings->{resetpostlink}};
5971: }
5972: if (ref($settings->{resetemail}) eq 'ARRAY') {
5973: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
5974: }
5975: if ($settings->{resetremove}) {
5976: $nostdtext = 1;
5977: }
5978: if ($settings->{resetcustom}) {
5979: $customurl = $settings->{resetcustom};
5980: }
5981: } else {
5982: if (ref($types) eq 'ARRAY') {
5983: foreach my $item (@{$types}) {
5984: $casesens{$item} = 1;
5985: $postlink{$item} = ['username','email'];
5986: }
5987: }
5988: $casesens{'default'} = 1;
5989: $postlink{'default'} = ['username','email'];
5990: $prelink = 'both';
5991: %emailsrc = (
5992: permanent => 1,
5993: critical => 1,
5994: notify => 1,
5995: );
5996: }
5997: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
5998: $itemcount ++;
5999: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6000: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
6001: '<td class="LC_left_item">'.
6002: '<input type="textbox" value="'.$shownlinklife.'" '.
6003: 'name="passwords_link" size="3" /></td></tr>';
6004: $itemcount ++;
6005: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6006: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
6007: '<td class="LC_left_item">';
6008: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6009: foreach my $item (@{$types}) {
6010: my $checkedcase;
6011: if ($casesens{$item}) {
6012: $checkedcase = ' checked="checked"';
6013: }
6014: $datatable .= '<span class="LC_nobreak"><label>'.
6015: '<input type="checkbox" name="passwords_case_sensitive" value="'.
6016: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
6017: '<span> ';
6018: }
6019: }
6020: my $checkedcase;
6021: if ($casesens{'default'}) {
6022: $checkedcase = ' checked="checked"';
6023: }
6024: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
6025: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
6026: $othertitle.'</label></span></td>';
6027: $itemcount ++;
6028: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6029: my %checkedpre = (
6030: both => ' checked="checked"',
6031: either => '',
6032: );
6033: if ($prelink eq 'either') {
6034: $checkedpre{either} = ' checked="checked"';
6035: $checkedpre{both} = '';
6036: }
6037: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
6038: '<td class="LC_left_item"><span class="LC_nobreak">'.
6039: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
6040: &mt('Both username and e-mail address').'</label></span> '.
6041: '<span class="LC_nobreak"><label>'.
6042: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
6043: &mt('Either username or e-mail address').'</label></span></td></tr>';
6044: $itemcount ++;
6045: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6046: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
6047: '<td class="LC_left_item">';
6048: my %postlinked;
6049: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6050: foreach my $item (@{$types}) {
6051: undef(%postlinked);
6052: $datatable .= '<fieldset style="display: inline-block;">'.
6053: '<legend>'.$usertypes->{$item}.'</legend>';
6054: if (ref($postlink{$item}) eq 'ARRAY') {
6055: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
6056: }
6057: foreach my $field ('email','username') {
6058: my $checked;
6059: if ($postlinked{$field}) {
6060: $checked = ' checked="checked"';
6061: }
6062: $datatable .= '<span class="LC_nobreak"><label>'.
6063: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
6064: $field.'"'.$checked.' />'.$field.'</label>'.
6065: '<span> ';
6066: }
6067: $datatable .= '</fieldset>';
6068: }
6069: }
6070: if (ref($postlink{'default'}) eq 'ARRAY') {
6071: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
6072: }
6073: $datatable .= '<fieldset style="display: inline-block;">'.
6074: '<legend>'.$othertitle.'</legend>';
6075: foreach my $field ('email','username') {
6076: my $checked;
6077: if ($postlinked{$field}) {
6078: $checked = ' checked="checked"';
6079: }
6080: $datatable .= '<span class="LC_nobreak"><label>'.
6081: '<input type="checkbox" name="passwords_postlink_default" value="'.
6082: $field.'"'.$checked.' />'.$field.'</label>'.
6083: '<span> ';
6084: }
6085: $datatable .= '</fieldset></td></tr>';
6086: $itemcount ++;
6087: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6088: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
6089: '<td class="LC_left_item">';
6090: foreach my $type ('permanent','critical','notify') {
6091: my $checkedemail;
6092: if ($emailsrc{$type}) {
6093: $checkedemail = ' checked="checked"';
6094: }
6095: $datatable .= '<span class="LC_nobreak"><label>'.
6096: '<input type="checkbox" name="passwords_emailsrc" value="'.
6097: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
6098: '<span> ';
6099: }
6100: $datatable .= '</td></tr>';
6101: $itemcount ++;
6102: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6103: my $switchserver = &check_switchserver($dom,$confname);
6104: my ($showstd,$noshowstd);
6105: if ($nostdtext) {
6106: $noshowstd = ' checked="checked"';
6107: } else {
6108: $showstd = ' checked="checked"';
6109: }
6110: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
6111: '<td class="LC_left_item"><span class="LC_nobreak">'.
6112: &mt('Retain standard text:').
6113: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
6114: &mt('Yes').'</label>'.' '.
6115: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
6116: &mt('No').'</label></span><br />'.
6117: '<span class="LC_fontsize_small">'.
6118: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
6119: &mt('Include custom text:');
6120: if ($customurl) {
6121: my $link = &Apache::loncommon::modal_link($customurl,&mt('Custom text file'),600,500,
6122: undef,undef,undef,undef,'background-color:#ffffff');
6123: $datatable .= '<span class="LC_nobreak"> '.$link.
6124: '<label><input type="checkbox" name="passwords_custom_del"'.
6125: ' value="1" />'.&mt('Delete?').'</label></span>'.
6126: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
6127: }
6128: if ($switchserver) {
6129: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
6130: } else {
6131: $datatable .='<span class="LC_nobreak"> '.
6132: '<input type="file" name="passwords_customfile" /></span>';
6133: }
6134: $datatable .= '</td></tr>';
6135: } elsif ($position eq 'middle') {
6136: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
6137: my @items = ('intauth_cost','intauth_check','intauth_switch');
6138: my %defaults;
6139: if (ref($domconf{'defaults'}) eq 'HASH') {
6140: %defaults = %{$domconf{'defaults'}};
6141: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
6142: $defaults{'intauth_cost'} = 10;
6143: }
6144: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
6145: $defaults{'intauth_check'} = 0;
6146: }
6147: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
6148: $defaults{'intauth_switch'} = 0;
6149: }
6150: } else {
6151: %defaults = (
6152: 'intauth_cost' => 10,
6153: 'intauth_check' => 0,
6154: 'intauth_switch' => 0,
6155: );
6156: }
6157: foreach my $item (@items) {
6158: if ($itemcount%2) {
6159: $css_class = '';
6160: } else {
6161: $css_class = ' class="LC_odd_row" ';
6162: }
6163: $datatable .= '<tr'.$css_class.'>'.
6164: '<td><span class="LC_nobreak">'.$titles{$item}.
6165: '</span></td><td class="LC_left_item" colspan="3">';
6166: if ($item eq 'intauth_switch') {
6167: my @options = (0,1,2);
6168: my %optiondesc = &Apache::lonlocal::texthash (
6169: 0 => 'No',
6170: 1 => 'Yes',
6171: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
6172: );
6173: $datatable .= '<table width="100%">';
6174: foreach my $option (@options) {
6175: my $checked = ' ';
6176: if ($defaults{$item} eq $option) {
6177: $checked = ' checked="checked"';
6178: }
6179: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6180: '<label><input type="radio" name="'.$item.
6181: '" value="'.$option.'"'.$checked.' />'.
6182: $optiondesc{$option}.'</label></span></td></tr>';
6183: }
6184: $datatable .= '</table>';
6185: } elsif ($item eq 'intauth_check') {
6186: my @options = (0,1,2);
6187: my %optiondesc = &Apache::lonlocal::texthash (
6188: 0 => 'No',
6189: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
6190: 2 => 'Yes, disallow login if stored cost is less than domain default',
6191: );
6192: $datatable .= '<table width="100%">';
6193: foreach my $option (@options) {
6194: my $checked = ' ';
6195: my $onclick;
6196: if ($defaults{$item} eq $option) {
6197: $checked = ' checked="checked"';
6198: }
6199: if ($option == 2) {
6200: $onclick = ' onclick="javascript:warnIntAuth(this);"';
6201: }
6202: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6203: '<label><input type="radio" name="'.$item.
6204: '" value="'.$option.'"'.$checked.$onclick.' />'.
6205: $optiondesc{$option}.'</label></span></td></tr>';
6206: }
6207: $datatable .= '</table>';
6208: } else {
6209: $datatable .= '<input type="text" name="'.$item.'" value="'.
6210: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
6211: }
6212: $datatable .= '</td></tr>';
6213: $itemcount ++;
6214: }
6215: } elsif ($position eq 'lower') {
1.356 raeburn 6216: my ($min,$max,%chars,$expire,$numsaved);
1.354 raeburn 6217: if (ref($settings) eq 'HASH') {
6218: if ($settings->{min}) {
6219: $min = $settings->{min};
6220: }
6221: if ($settings->{max}) {
6222: $max = $settings->{max};
6223: }
6224: if (ref($settings->{chars}) eq 'ARRAY') {
6225: map { $chars{$_} = 1; } (@{$settings->{chars}});
6226: }
6227: if ($settings->{expire}) {
6228: $expire = $settings->{expire};
6229: }
1.358 raeburn 6230: if ($settings->{numsaved}) {
6231: $numsaved = $settings->{numsaved};
1.356 raeburn 6232: }
1.354 raeburn 6233: } else {
6234: $min = '7';
6235: }
6236: my %rulenames = &Apache::lonlocal::texthash(
6237: uc => 'At least one upper case letter',
6238: lc => 'At least one lower case letter',
6239: num => 'At least one number',
6240: spec => 'At least one non-alphanumeric',
6241: );
6242: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6243: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
6244: '<td class="LC_left_item"><span class="LC_nobreak">'.
6245: '<input type="text" name="passwords_min" value="'.$min.'" size="3" />'.
6246: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no minimum)').'</span>'.
6247: '</span></td></tr>';
6248: $itemcount ++;
6249: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6250: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
6251: '<td class="LC_left_item"><span class="LC_nobreak">'.
6252: '<input type="text" name="passwords_max" value="'.$max.'" size="3" />'.
6253: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
6254: '</span></td></tr>';
6255: $itemcount ++;
6256: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6257: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
6258: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
6259: '</span></td>';
6260: my $numinrow = 2;
6261: my @possrules = ('uc','lc','num','spec');
6262: $datatable .= '<td class="LC_left_item"><table>';
6263: for (my $i=0; $i<@possrules; $i++) {
6264: my ($rem,$checked);
6265: if ($chars{$possrules[$i]}) {
6266: $checked = ' checked="checked"';
6267: }
6268: $rem = $i%($numinrow);
6269: if ($rem == 0) {
6270: if ($i > 0) {
6271: $datatable .= '</tr>';
6272: }
6273: $datatable .= '<tr>';
6274: }
6275: $datatable .= '<td><span class="LC_nobreak"><label>'.
6276: '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
6277: $rulenames{$possrules[$i]}.'</label></span></td>';
6278: }
6279: my $rem = @possrules%($numinrow);
6280: my $colsleft = $numinrow - $rem;
6281: if ($colsleft > 1 ) {
6282: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6283: ' </td>';
6284: } elsif ($colsleft == 1) {
6285: $datatable .= '<td class="LC_left_item"> </td>';
6286: }
6287: $datatable .='</table></td></tr>';
6288: $itemcount ++;
6289: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6290: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
6291: '<td class="LC_left_item"><span class="LC_nobreak">'.
6292: '<input type="text" name="passwords_expire" value="'.$expire.'" size="4" />'.
6293: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
6294: '</span></td></tr>';
1.356 raeburn 6295: $itemcount ++;
6296: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6297: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
6298: '<td class="LC_left_item"><span class="LC_nobreak">'.
6299: '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" />'.
6300: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
6301: '</span></td></tr>';
1.354 raeburn 6302: } else {
1.359 ! raeburn 6303: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
! 6304: my %ownerchg = (
! 6305: by => {},
! 6306: for => {},
! 6307: );
! 6308: my %ownertitles = &Apache::lonlocal::texthash (
! 6309: by => 'Course owner status(es) allowed',
! 6310: for => 'Student status(es) allowed',
! 6311: );
1.354 raeburn 6312: if (ref($settings) eq 'HASH') {
1.359 ! raeburn 6313: if (ref($settings->{crsownerchg}) eq 'HASH') {
! 6314: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
! 6315: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
! 6316: }
! 6317: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
! 6318: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
! 6319: }
1.354 raeburn 6320: }
6321: }
6322: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6323: $datatable .= '<tr '.$css_class.'>'.
6324: '<td>'.
6325: &mt('Requirements').'<ul>'.
1.359 ! raeburn 6326: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 6327: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
6328: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 ! raeburn 6329: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 6330: '</ul>'.
6331: '</td>'.
1.359 ! raeburn 6332: '<td class="LC_left_item">';
! 6333: foreach my $item ('by','for') {
! 6334: $datatable .= '<fieldset style="display: inline-block;">'.
! 6335: '<legend>'.$ownertitles{$item}.'</legend>';
! 6336: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
! 6337: foreach my $type (@{$types}) {
! 6338: my $checked;
! 6339: if ($ownerchg{$item}{$type}) {
! 6340: $checked = ' checked="checked"';
! 6341: }
! 6342: $datatable .= '<span class="LC_nobreak"><label>'.
! 6343: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
! 6344: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
! 6345: '<span> ';
! 6346: }
! 6347: }
! 6348: my $checked;
! 6349: if ($ownerchg{$item}{'default'}) {
! 6350: $checked = ' checked="checked"';
! 6351: }
! 6352: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
! 6353: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
! 6354: $othertitle.'</label></span></fieldset>';
! 6355: }
! 6356: $datatable .= '</td></tr>';
1.354 raeburn 6357: }
6358: return $datatable;
6359: }
6360:
1.137 raeburn 6361: sub print_usersessions {
6362: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 6363: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 6364: my (%by_ip,%by_location,@intdoms,@instdoms);
6365: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 6366:
6367: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 6368: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 6369: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 6370: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 6371: if ($position eq 'top') {
1.152 raeburn 6372: if (keys(%serverhomes) > 1) {
1.145 raeburn 6373: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 6374: my $curroffloadnow;
6375: if (ref($settings) eq 'HASH') {
6376: if (ref($settings->{'offloadnow'}) eq 'HASH') {
6377: $curroffloadnow = $settings->{'offloadnow'};
6378: }
6379: }
6380: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 6381: } else {
1.140 raeburn 6382: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 6383: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
6384: '</td></tr>';
1.140 raeburn 6385: }
1.137 raeburn 6386: } else {
1.279 raeburn 6387: my %titles = &usersession_titles();
6388: my ($prefix,@types);
6389: if ($position eq 'bottom') {
6390: $prefix = 'remote';
6391: @types = ('version','excludedomain','includedomain');
1.145 raeburn 6392: } else {
1.279 raeburn 6393: $prefix = 'hosted';
6394: @types = ('excludedomain','includedomain');
6395: }
6396: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
6397: }
6398: $$rowtotal += $itemcount;
6399: return $datatable;
6400: }
6401:
6402: sub rules_by_location {
6403: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
6404: my ($datatable,$itemcount,$css_class);
6405: if (keys(%{$by_location}) == 0) {
6406: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6407: $datatable = '<tr'.$css_class.'><td colspan="2">'.
6408: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
6409: '</td></tr>';
6410: $itemcount = 1;
6411: } else {
6412: $itemcount = 0;
6413: my $numinrow = 5;
6414: my (%current,%checkedon,%checkedoff);
6415: my @locations = sort(keys(%{$by_location}));
6416: foreach my $type (@{$types}) {
6417: $checkedon{$type} = '';
6418: $checkedoff{$type} = ' checked="checked"';
6419: }
6420: if (ref($settings) eq 'HASH') {
6421: if (ref($settings->{$prefix}) eq 'HASH') {
6422: foreach my $key (keys(%{$settings->{$prefix}})) {
6423: $current{$key} = $settings->{$prefix}{$key};
6424: if ($key eq 'version') {
6425: if ($current{$key} ne '') {
1.145 raeburn 6426: $checkedon{$key} = ' checked="checked"';
6427: $checkedoff{$key} = '';
6428: }
1.279 raeburn 6429: } elsif (ref($current{$key}) eq 'ARRAY') {
6430: $checkedon{$key} = ' checked="checked"';
6431: $checkedoff{$key} = '';
1.137 raeburn 6432: }
6433: }
6434: }
1.279 raeburn 6435: }
6436: foreach my $type (@{$types}) {
6437: next if ($type ne 'version' && !@locations);
6438: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6439: $datatable .= '<tr'.$css_class.'>
6440: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
6441: <span class="LC_nobreak">
6442: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
6443: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
6444: if ($type eq 'version') {
6445: my @lcversions = &Apache::lonnet::all_loncaparevs();
6446: my $selector = '<select name="'.$prefix.'_version">';
6447: foreach my $version (@lcversions) {
6448: my $selected = '';
6449: if ($current{'version'} eq $version) {
6450: $selected = ' selected="selected"';
1.145 raeburn 6451: }
1.279 raeburn 6452: $selector .= ' <option value="'.$version.'"'.
6453: $selected.'>'.$version.'</option>';
6454: }
6455: $selector .= '</select> ';
6456: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
6457: } else {
6458: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
6459: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
6460: ' />'.(' 'x2).
6461: '<input type="button" value="'.&mt('uncheck all').'" '.
6462: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
6463: "\n".
6464: '</div><div><table>';
6465: my $rem;
6466: for (my $i=0; $i<@locations; $i++) {
6467: my ($showloc,$value,$checkedtype);
6468: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
6469: my $ip = $by_location->{$locations[$i]}->[0];
6470: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6471: $value = join(':',@{$by_ip->{$ip}});
6472: $showloc = join(', ',@{$by_ip->{$ip}});
6473: if (ref($current{$type}) eq 'ARRAY') {
6474: foreach my $loc (@{$by_ip->{$ip}}) {
6475: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
6476: $checkedtype = ' checked="checked"';
6477: last;
1.145 raeburn 6478: }
1.138 raeburn 6479: }
6480: }
6481: }
1.137 raeburn 6482: }
1.279 raeburn 6483: $rem = $i%($numinrow);
6484: if ($rem == 0) {
6485: if ($i > 0) {
6486: $datatable .= '</tr>';
6487: }
6488: $datatable .= '<tr>';
6489: }
6490: $datatable .= '<td class="LC_left_item">'.
6491: '<span class="LC_nobreak"><label>'.
6492: '<input type="checkbox" name="'.$prefix.'_'.$type.
6493: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
6494: '</label></span></td>';
6495: }
6496: $rem = @locations%($numinrow);
6497: my $colsleft = $numinrow - $rem;
6498: if ($colsleft > 1 ) {
6499: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6500: ' </td>';
6501: } elsif ($colsleft == 1) {
6502: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 6503: }
1.279 raeburn 6504: $datatable .= '</tr></table>';
1.137 raeburn 6505: }
1.279 raeburn 6506: $datatable .= '</td></tr>';
6507: $itemcount ++;
1.137 raeburn 6508: }
6509: }
1.279 raeburn 6510: return ($datatable,$itemcount);
1.137 raeburn 6511: }
6512:
1.275 raeburn 6513: sub print_ssl {
6514: my ($position,$dom,$settings,$rowtotal) = @_;
6515: my ($css_class,$datatable);
6516: my $itemcount = 1;
6517: if ($position eq 'top') {
1.281 raeburn 6518: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6519: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6520: my $same_institution;
6521: if ($intdom ne '') {
6522: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
6523: if (ref($internet_names) eq 'ARRAY') {
6524: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
6525: $same_institution = 1;
6526: }
6527: }
6528: }
1.275 raeburn 6529: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 6530: $datatable = '<tr'.$css_class.'><td colspan="2">';
6531: if ($same_institution) {
6532: my %domservers = &Apache::lonnet::get_servers($dom);
6533: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
6534: } else {
6535: $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.");
6536: }
6537: $datatable .= '</td></tr>';
1.275 raeburn 6538: $itemcount ++;
6539: } else {
6540: my %titles = &ssl_titles();
6541: my (%by_ip,%by_location,@intdoms,@instdoms);
6542: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
6543: my @alldoms = &Apache::lonnet::all_domains();
6544: my %serverhomes = %Apache::lonnet::serverhomeIDs;
6545: my @domservers = &Apache::lonnet::get_servers($dom);
6546: my %servers = &Apache::lonnet::internet_dom_servers($dom);
6547: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 6548: if (($position eq 'connto') || ($position eq 'connfrom')) {
6549: my $legacy;
6550: unless (ref($settings) eq 'HASH') {
6551: my $name;
6552: if ($position eq 'connto') {
6553: $name = 'loncAllowInsecure';
6554: } else {
6555: $name = 'londAllowInsecure';
6556: }
6557: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
6558: my @ids=&Apache::lonnet::current_machine_ids();
6559: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
6560: my %what = (
6561: $name => 1,
6562: );
6563: my ($result,$returnhash) =
6564: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
6565: if ($result eq 'ok') {
6566: if (ref($returnhash) eq 'HASH') {
6567: $legacy = $returnhash->{$name};
6568: }
6569: }
6570: } else {
6571: $legacy = $Apache::lonnet::perlvar{$name};
6572: }
6573: }
1.275 raeburn 6574: foreach my $type ('dom','intdom','other') {
6575: my %checked;
6576: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6577: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
6578: '<td class="LC_right_item">';
6579: my $skip;
6580: if ($type eq 'dom') {
6581: unless (keys(%servers) > 1) {
6582: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
6583: $skip = 1;
6584: }
6585: }
6586: if ($type eq 'intdom') {
6587: unless (@instdoms > 1) {
6588: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
6589: $skip = 1;
6590: }
6591: } elsif ($type eq 'other') {
6592: if (keys(%by_location) == 0) {
6593: $datatable .= &mt('Nothing to set here, as there are no other institutions');
6594: $skip = 1;
6595: }
6596: }
6597: unless ($skip) {
6598: $checked{'yes'} = ' checked="checked"';
6599: if (ref($settings) eq 'HASH') {
1.293 raeburn 6600: if (ref($settings->{$position}) eq 'HASH') {
6601: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 6602: $checked{$1} = $checked{'yes'};
6603: delete($checked{'yes'});
6604: }
6605: }
1.293 raeburn 6606: } else {
6607: if ($legacy == 0) {
6608: $checked{'req'} = $checked{'yes'};
6609: delete($checked{'yes'});
6610: }
1.275 raeburn 6611: }
6612: foreach my $option ('no','yes','req') {
6613: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 6614: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 6615: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
6616: '</label></span>'.(' 'x2);
6617: }
6618: }
6619: $datatable .= '</td></tr>';
6620: $itemcount ++;
6621: }
6622: } else {
6623: my $prefix = 'replication';
6624: my @types = ('certreq','nocertreq');
1.279 raeburn 6625: if (keys(%by_location) == 0) {
6626: $datatable .= '<tr'.$css_class.'><td>'.
6627: &mt('Nothing to set here, as there are no other institutions').
6628: '</td></tr>';
6629: $itemcount ++;
1.275 raeburn 6630: } else {
1.279 raeburn 6631: ($datatable,$itemcount) =
6632: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 6633: }
6634: }
6635: }
6636: $$rowtotal += $itemcount;
6637: return $datatable;
6638: }
6639:
6640: sub ssl_titles {
6641: return &Apache::lonlocal::texthash (
6642: dom => 'LON-CAPA servers/VMs from same domain',
6643: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
6644: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 6645: connto => 'Connections to other servers',
6646: connfrom => 'Connections from other servers',
1.275 raeburn 6647: replication => 'Replicating content to other institutions',
6648: certreq => 'Client certificate required, but specific domains exempt',
6649: nocertreq => 'No client certificate required, except for specific domains',
6650: no => 'SSL not used',
6651: yes => 'SSL Optional (used if available)',
6652: req => 'SSL Required',
6653: );
1.279 raeburn 6654: }
6655:
6656: sub print_trust {
6657: my ($prefix,$dom,$settings,$rowtotal) = @_;
6658: my ($css_class,$datatable,%checked,%choices);
6659: my (%by_ip,%by_location,@intdoms,@instdoms);
6660: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
6661: my $itemcount = 1;
6662: my %titles = &trust_titles();
6663: my @types = ('exc','inc');
6664: if ($prefix eq 'top') {
6665: $prefix = 'content';
6666: } elsif ($prefix eq 'bottom') {
6667: $prefix = 'msg';
6668: }
6669: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
6670: $$rowtotal += $itemcount;
6671: return $datatable;
6672: }
6673:
6674: sub trust_titles {
6675: return &Apache::lonlocal::texthash(
6676: content => "Access to this domain's content by others",
6677: shared => "Access to other domain's content by this domain",
6678: enroll => "Enrollment in this domain's courses by others",
6679: othcoau => "Co-author roles in this domain for others",
6680: coaurem => "Co-author roles for this domain's users elsewhere",
6681: domroles => "Domain roles in this domain assignable to others",
6682: catalog => "Course Catalog for this domain displayed elsewhere",
6683: reqcrs => "Requests for creation of courses in this domain by others",
6684: msg => "Users in other domains can send messages to this domain",
6685: exc => "Allow all, but exclude specific domains",
6686: inc => "Deny all, but include specific domains",
6687: );
1.275 raeburn 6688: }
6689:
1.138 raeburn 6690: sub build_location_hashes {
1.275 raeburn 6691: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 6692: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 6693: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 6694: my %iphost = &Apache::lonnet::get_iphost();
6695: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
6696: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
6697: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
6698: foreach my $id (@{$iphost{$primary_ip}}) {
6699: my $intdom = &Apache::lonnet::internet_dom($id);
6700: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
6701: push(@{$intdoms},$intdom);
6702: }
6703: }
6704: }
6705: foreach my $ip (keys(%iphost)) {
6706: if (ref($iphost{$ip}) eq 'ARRAY') {
6707: foreach my $id (@{$iphost{$ip}}) {
6708: my $location = &Apache::lonnet::internet_dom($id);
6709: if ($location) {
1.275 raeburn 6710: if (grep(/^\Q$location\E$/,@{$intdoms})) {
6711: my $dom = &Apache::lonnet::host_domain($id);
6712: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
6713: push(@{$instdoms},$dom);
6714: }
6715: next;
6716: }
1.138 raeburn 6717: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6718: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
6719: push(@{$by_ip->{$ip}},$location);
6720: }
6721: } else {
6722: $by_ip->{$ip} = [$location];
6723: }
6724: }
6725: }
6726: }
6727: }
6728: foreach my $ip (sort(keys(%{$by_ip}))) {
6729: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6730: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
6731: my $first = $by_ip->{$ip}->[0];
6732: if (ref($by_location->{$first}) eq 'ARRAY') {
6733: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
6734: push(@{$by_location->{$first}},$ip);
6735: }
6736: } else {
6737: $by_location->{$first} = [$ip];
6738: }
6739: }
6740: }
6741: return;
6742: }
6743:
1.145 raeburn 6744: sub current_offloads_to {
6745: my ($dom,$settings,$servers) = @_;
6746: my (%spareid,%otherdomconfigs);
1.152 raeburn 6747: if (ref($servers) eq 'HASH') {
1.145 raeburn 6748: foreach my $lonhost (sort(keys(%{$servers}))) {
6749: my $gotspares;
1.152 raeburn 6750: if (ref($settings) eq 'HASH') {
6751: if (ref($settings->{'spares'}) eq 'HASH') {
6752: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
6753: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
6754: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
6755: $gotspares = 1;
6756: }
1.145 raeburn 6757: }
6758: }
6759: unless ($gotspares) {
6760: my $gotspares;
6761: my $serverhomeID =
6762: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
6763: my $serverhomedom =
6764: &Apache::lonnet::host_domain($serverhomeID);
6765: if ($serverhomedom ne $dom) {
6766: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
6767: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
6768: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
6769: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
6770: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
6771: $gotspares = 1;
6772: }
6773: }
6774: } else {
6775: $otherdomconfigs{$serverhomedom} =
6776: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
6777: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
6778: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
6779: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
6780: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
6781: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
6782: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
6783: $gotspares = 1;
6784: }
6785: }
6786: }
6787: }
6788: }
6789: }
6790: }
6791: unless ($gotspares) {
6792: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
6793: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6794: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6795: } else {
6796: my $server_hostname = &Apache::lonnet::hostname($lonhost);
6797: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
6798: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
6799: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6800: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6801: } else {
1.150 raeburn 6802: my %what = (
6803: spareid => 1,
6804: );
6805: my ($result,$returnhash) =
6806: &Apache::lonnet::get_remote_globals($lonhost,\%what);
6807: if ($result eq 'ok') {
6808: if (ref($returnhash) eq 'HASH') {
6809: if (ref($returnhash->{'spareid'}) eq 'HASH') {
6810: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
6811: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
6812: }
6813: }
1.145 raeburn 6814: }
6815: }
6816: }
6817: }
6818: }
6819: }
6820: return %spareid;
6821: }
6822:
6823: sub spares_row {
1.261 raeburn 6824: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 6825: my $css_class;
6826: my $numinrow = 4;
6827: my $itemcount = 1;
6828: my $datatable;
1.152 raeburn 6829: my %typetitles = &sparestype_titles();
6830: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 6831: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 6832: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
6833: my ($othercontrol,$serverdom);
6834: if ($serverhome ne $server) {
6835: $serverdom = &Apache::lonnet::host_domain($serverhome);
6836: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6837: } else {
6838: $serverdom = &Apache::lonnet::host_domain($server);
6839: if ($serverdom ne $dom) {
6840: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6841: }
6842: }
6843: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 6844: my $checkednow;
6845: if (ref($curroffloadnow) eq 'HASH') {
6846: if ($curroffloadnow->{$server}) {
6847: $checkednow = ' checked="checked"';
6848: }
6849: }
1.145 raeburn 6850: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6851: $datatable .= '<tr'.$css_class.'>
6852: <td rowspan="2">
1.183 bisitz 6853: <span class="LC_nobreak">'.
6854: &mt('[_1] when busy, offloads to:'
1.261 raeburn 6855: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 6856: '<span class="LC_nobreak">'."\n".
1.261 raeburn 6857: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
6858: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 6859: "\n";
1.145 raeburn 6860: my (%current,%canselect);
1.152 raeburn 6861: my @choices =
6862: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
6863: foreach my $type ('primary','default') {
6864: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 6865: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
6866: my @spares = @{$spareid->{$server}{$type}};
6867: if (@spares > 0) {
1.152 raeburn 6868: if ($othercontrol) {
6869: $current{$type} = join(', ',@spares);
6870: } else {
6871: $current{$type} .= '<table>';
6872: my $numspares = scalar(@spares);
6873: for (my $i=0; $i<@spares; $i++) {
6874: my $rem = $i%($numinrow);
6875: if ($rem == 0) {
6876: if ($i > 0) {
6877: $current{$type} .= '</tr>';
6878: }
6879: $current{$type} .= '<tr>';
1.145 raeburn 6880: }
1.152 raeburn 6881: $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'".');" /> '.
6882: $spareid->{$server}{$type}[$i].
6883: '</label></td>'."\n";
6884: }
6885: my $rem = @spares%($numinrow);
6886: my $colsleft = $numinrow - $rem;
6887: if ($colsleft > 1 ) {
6888: $current{$type} .= '<td colspan="'.$colsleft.
6889: '" class="LC_left_item">'.
6890: ' </td>';
6891: } elsif ($colsleft == 1) {
6892: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 6893: }
1.152 raeburn 6894: $current{$type} .= '</tr></table>';
1.150 raeburn 6895: }
1.145 raeburn 6896: }
6897: }
6898: if ($current{$type} eq '') {
6899: $current{$type} = &mt('None specified');
6900: }
1.152 raeburn 6901: if ($othercontrol) {
6902: if ($type eq 'primary') {
6903: $canselect{$type} = $othercontrol;
6904: }
6905: } else {
6906: $canselect{$type} =
6907: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
6908: '<select name="newspare_'.$type.'_'.$server.'" '.
6909: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
6910: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
6911: if (@choices > 0) {
6912: foreach my $lonhost (@choices) {
6913: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
6914: }
6915: }
6916: $canselect{$type} .= '</select>'."\n";
6917: }
6918: } else {
6919: $current{$type} = &mt('Could not be determined');
6920: if ($type eq 'primary') {
6921: $canselect{$type} = $othercontrol;
6922: }
1.145 raeburn 6923: }
1.152 raeburn 6924: if ($type eq 'default') {
6925: $datatable .= '<tr'.$css_class.'>';
6926: }
6927: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
6928: '<td>'.$current{$type}.'</td>'."\n".
6929: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 6930: }
6931: $itemcount ++;
6932: }
6933: }
6934: $$rowtotal += $itemcount;
6935: return $datatable;
6936: }
6937:
1.152 raeburn 6938: sub possible_newspares {
6939: my ($server,$currspares,$serverhomes,$altids) = @_;
6940: my $serverhostname = &Apache::lonnet::hostname($server);
6941: my %excluded;
6942: if ($serverhostname ne '') {
6943: %excluded = (
6944: $serverhostname => 1,
6945: );
6946: }
6947: if (ref($currspares) eq 'HASH') {
6948: foreach my $type (keys(%{$currspares})) {
6949: if (ref($currspares->{$type}) eq 'ARRAY') {
6950: if (@{$currspares->{$type}} > 0) {
6951: foreach my $curr (@{$currspares->{$type}}) {
6952: my $hostname = &Apache::lonnet::hostname($curr);
6953: $excluded{$hostname} = 1;
6954: }
6955: }
6956: }
6957: }
6958: }
6959: my @choices;
6960: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
6961: if (keys(%{$serverhomes}) > 1) {
6962: foreach my $name (sort(keys(%{$serverhomes}))) {
6963: unless ($excluded{$name}) {
6964: if (exists($altids->{$serverhomes->{$name}})) {
6965: push(@choices,$altids->{$serverhomes->{$name}});
6966: } else {
6967: push(@choices,$serverhomes->{$name});
1.145 raeburn 6968: }
6969: }
6970: }
6971: }
6972: }
1.152 raeburn 6973: return sort(@choices);
1.145 raeburn 6974: }
6975:
1.150 raeburn 6976: sub print_loadbalancing {
6977: my ($dom,$settings,$rowtotal) = @_;
6978: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6979: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6980: my $numinrow = 1;
6981: my $datatable;
6982: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 6983: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 6984: if (ref($settings) eq 'HASH') {
6985: %existing = %{$settings};
6986: }
6987: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
6988: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 6989: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 6990: } else {
6991: return;
6992: }
6993: my ($othertitle,$usertypes,$types) =
6994: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 6995: my $rownum = 8;
1.150 raeburn 6996: if (ref($types) eq 'ARRAY') {
6997: $rownum += scalar(@{$types});
6998: }
1.171 raeburn 6999: my @css_class = ('LC_odd_row','LC_even_row');
7000: my $balnum = 0;
7001: my $islast;
7002: my (@toshow,$disabledtext);
7003: if (keys(%currbalancer) > 0) {
7004: @toshow = sort(keys(%currbalancer));
7005: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
7006: push(@toshow,'');
7007: }
7008: } else {
7009: @toshow = ('');
7010: $disabledtext = &mt('No existing load balancer');
7011: }
7012: foreach my $lonhost (@toshow) {
7013: if ($balnum == scalar(@toshow)-1) {
7014: $islast = 1;
7015: } else {
7016: $islast = 0;
7017: }
7018: my $cssidx = $balnum%2;
7019: my $targets_div_style = 'display: none';
7020: my $disabled_div_style = 'display: block';
7021: my $homedom_div_style = 'display: none';
7022: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 7023: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 7024: '<p>';
7025: if ($lonhost eq '') {
1.210 raeburn 7026: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 7027: if (keys(%currbalancer) > 0) {
7028: $datatable .= &mt('Add balancer:');
7029: } else {
7030: $datatable .= &mt('Enable balancer:');
7031: }
7032: $datatable .= ' '.
7033: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
7034: ' id="loadbalancing_lonhost_'.$balnum.'"'.
7035: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
7036: '<option value="" selected="selected">'.&mt('None').
7037: '</option>'."\n";
7038: foreach my $server (sort(keys(%servers))) {
7039: next if ($currbalancer{$server});
7040: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
7041: }
1.210 raeburn 7042: $datatable .=
1.171 raeburn 7043: '</select>'."\n".
7044: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
7045: } else {
7046: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
7047: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
7048: &mt('Stop balancing').'</label>'.
7049: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
7050: $targets_div_style = 'display: block';
7051: $disabled_div_style = 'display: none';
7052: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
7053: $homedom_div_style = 'display: block';
7054: }
7055: }
1.306 raeburn 7056: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 7057: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
7058: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
7059: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
7060: my ($numspares,@spares) = &count_servers($lonhost,%servers);
7061: my @sparestypes = ('primary','default');
7062: my %typetitles = &sparestype_titles();
1.284 raeburn 7063: my %hostherechecked = (
7064: no => ' checked="checked"',
7065: );
1.342 raeburn 7066: my %balcookiechecked = (
7067: no => ' checked="checked"',
7068: );
1.171 raeburn 7069: foreach my $sparetype (@sparestypes) {
7070: my $targettable;
7071: for (my $i=0; $i<$numspares; $i++) {
7072: my $checked;
7073: if (ref($currtargets{$lonhost}) eq 'HASH') {
7074: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
7075: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
7076: $checked = ' checked="checked"';
7077: }
7078: }
7079: }
7080: my ($chkboxval,$disabled);
7081: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
7082: $chkboxval = $spares[$i];
7083: }
7084: if (exists($currbalancer{$spares[$i]})) {
7085: $disabled = ' disabled="disabled"';
7086: }
1.210 raeburn 7087: $targettable .=
1.253 raeburn 7088: '<td><span class="LC_nobreak"><label>'.
7089: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 7090: $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 7091: '</span></label></span></td>';
1.171 raeburn 7092: my $rem = $i%($numinrow);
7093: if ($rem == 0) {
7094: if (($i > 0) && ($i < $numspares-1)) {
7095: $targettable .= '</tr>';
7096: }
7097: if ($i < $numspares-1) {
7098: $targettable .= '<tr>';
1.150 raeburn 7099: }
7100: }
7101: }
1.171 raeburn 7102: if ($targettable ne '') {
7103: my $rem = $numspares%($numinrow);
7104: my $colsleft = $numinrow - $rem;
7105: if ($colsleft > 1 ) {
7106: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7107: ' </td>';
7108: } elsif ($colsleft == 1) {
7109: $targettable .= '<td class="LC_left_item"> </td>';
7110: }
7111: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
7112: '<table><tr>'.$targettable.'</tr></table><br />';
7113: }
1.284 raeburn 7114: $hostherechecked{$sparetype} = '';
7115: if (ref($currtargets{$lonhost}) eq 'HASH') {
7116: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
7117: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
7118: $hostherechecked{$sparetype} = ' checked="checked"';
7119: $hostherechecked{'no'} = '';
7120: }
7121: }
7122: }
7123: }
1.342 raeburn 7124: if ($currcookies{$lonhost}) {
7125: %balcookiechecked = (
7126: yes => ' checked="checked"',
7127: );
7128: }
1.284 raeburn 7129: $datatable .= &mt('Hosting on balancer itself').'<br />'.
7130: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
7131: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
7132: foreach my $sparetype (@sparestypes) {
7133: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
7134: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
7135: '</i></label><br />';
1.171 raeburn 7136: }
1.342 raeburn 7137: $datatable .= &mt('Use balancer cookie').'<br />'.
7138: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
7139: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
7140: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
7141: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
7142: '</div></td></tr>'.
1.171 raeburn 7143: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
7144: $othertitle,$usertypes,$types,\%servers,
7145: \%currbalancer,$lonhost,
7146: $targets_div_style,$homedom_div_style,
7147: $css_class[$cssidx],$balnum,$islast);
7148: $$rowtotal += $rownum;
7149: $balnum ++;
7150: }
7151: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
7152: return $datatable;
7153: }
7154:
7155: sub get_loadbalancers_config {
1.342 raeburn 7156: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 7157: return unless ((ref($servers) eq 'HASH') &&
7158: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 7159: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
7160: (ref($currcookies) eq 'HASH'));
1.171 raeburn 7161: if (keys(%{$existing}) > 0) {
7162: my $oldlonhost;
7163: foreach my $key (sort(keys(%{$existing}))) {
7164: if ($key eq 'lonhost') {
7165: $oldlonhost = $existing->{'lonhost'};
7166: $currbalancer->{$oldlonhost} = 1;
7167: } elsif ($key eq 'targets') {
7168: if ($oldlonhost) {
7169: $currtargets->{$oldlonhost} = $existing->{'targets'};
7170: }
7171: } elsif ($key eq 'rules') {
7172: if ($oldlonhost) {
7173: $currrules->{$oldlonhost} = $existing->{'rules'};
7174: }
7175: } elsif (ref($existing->{$key}) eq 'HASH') {
7176: $currbalancer->{$key} = 1;
7177: $currtargets->{$key} = $existing->{$key}{'targets'};
7178: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 7179: if ($existing->{$key}{'cookie'}) {
7180: $currcookies->{$key} = 1;
7181: }
1.150 raeburn 7182: }
7183: }
1.171 raeburn 7184: } else {
7185: my ($balancerref,$targetsref) =
7186: &Apache::lonnet::get_lonbalancer_config($servers);
7187: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
7188: foreach my $server (sort(keys(%{$balancerref}))) {
7189: $currbalancer->{$server} = 1;
7190: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 7191: }
7192: }
7193: }
1.171 raeburn 7194: return;
1.150 raeburn 7195: }
7196:
7197: sub loadbalancing_rules {
7198: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 7199: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
7200: $css_class,$balnum,$islast) = @_;
1.150 raeburn 7201: my $output;
1.171 raeburn 7202: my $num = 0;
1.210 raeburn 7203: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 7204: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
7205: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
7206: foreach my $type (@{$alltypes}) {
1.171 raeburn 7207: $num ++;
1.150 raeburn 7208: my $current;
7209: if (ref($currrules) eq 'HASH') {
7210: $current = $currrules->{$type};
7211: }
1.253 raeburn 7212: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 7213: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 7214: $current = '';
7215: }
7216: }
7217: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 7218: $servers,$currbalancer,$lonhost,$dom,
7219: $targets_div_style,$homedom_div_style,
7220: $css_class,$balnum,$num,$islast);
1.150 raeburn 7221: }
7222: }
7223: return $output;
7224: }
7225:
7226: sub loadbalancing_titles {
7227: my ($dom,$intdom,$usertypes,$types) = @_;
7228: my %othertypes = (
7229: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
7230: '_LC_author' => &mt('Users from [_1] with author role',$dom),
7231: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
7232: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 7233: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
7234: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 7235: );
1.209 raeburn 7236: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 7237: my @available;
1.150 raeburn 7238: if (ref($types) eq 'ARRAY') {
1.302 raeburn 7239: @available = @{$types};
1.150 raeburn 7240: }
1.302 raeburn 7241: unless (grep(/^default$/,@available)) {
7242: push(@available,'default');
7243: }
7244: unshift(@alltypes,@available);
1.150 raeburn 7245: my %titles;
7246: foreach my $type (@alltypes) {
7247: if ($type =~ /^_LC_/) {
7248: $titles{$type} = $othertypes{$type};
7249: } elsif ($type eq 'default') {
7250: $titles{$type} = &mt('All users from [_1]',$dom);
7251: if (ref($types) eq 'ARRAY') {
7252: if (@{$types} > 0) {
7253: $titles{$type} = &mt('Other users from [_1]',$dom);
7254: }
7255: }
7256: } elsif (ref($usertypes) eq 'HASH') {
7257: $titles{$type} = $usertypes->{$type};
7258: }
7259: }
7260: return (\@alltypes,\%othertypes,\%titles);
7261: }
7262:
7263: sub loadbalance_rule_row {
1.171 raeburn 7264: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
7265: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 7266: my @rulenames;
1.150 raeburn 7267: my %ruletitles = &offloadtype_text();
1.209 raeburn 7268: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 7269: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 7270: } else {
1.209 raeburn 7271: @rulenames = ('default','homeserver');
7272: if ($type eq '_LC_external') {
7273: push(@rulenames,'externalbalancer');
7274: } else {
7275: push(@rulenames,'specific');
7276: }
7277: push(@rulenames,'none');
1.150 raeburn 7278: }
7279: my $style = $targets_div_style;
1.253 raeburn 7280: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 7281: $style = $homedom_div_style;
7282: }
1.171 raeburn 7283: my $space;
7284: if ($islast && $num == 1) {
1.317 raeburn 7285: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 7286: }
1.210 raeburn 7287: my $output =
1.306 raeburn 7288: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 7289: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
7290: '<td valaign="top">'.$space.
7291: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 7292: for (my $i=0; $i<@rulenames; $i++) {
7293: my $rule = $rulenames[$i];
7294: my ($checked,$extra);
7295: if ($rulenames[$i] eq 'default') {
7296: $rule = '';
7297: }
7298: if ($rulenames[$i] eq 'specific') {
7299: if (ref($servers) eq 'HASH') {
7300: my $default;
7301: if (($current ne '') && (exists($servers->{$current}))) {
7302: $checked = ' checked="checked"';
7303: }
7304: unless ($checked) {
7305: $default = ' selected="selected"';
7306: }
1.210 raeburn 7307: $extra =
1.171 raeburn 7308: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
7309: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
7310: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
7311: '<option value=""'.$default.'></option>'."\n";
7312: foreach my $server (sort(keys(%{$servers}))) {
7313: if (ref($currbalancer) eq 'HASH') {
7314: next if (exists($currbalancer->{$server}));
7315: }
1.150 raeburn 7316: my $selected;
1.171 raeburn 7317: if ($server eq $current) {
1.150 raeburn 7318: $selected = ' selected="selected"';
7319: }
1.171 raeburn 7320: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 7321: }
7322: $extra .= '</select>';
7323: }
7324: } elsif ($rule eq $current) {
7325: $checked = ' checked="checked"';
7326: }
7327: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 7328: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
7329: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
7330: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 7331: ')"'.$checked.' /> ';
7332: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
7333: $output .= $ruletitles{'particular'};
7334: } else {
7335: $output .= $ruletitles{$rulenames[$i]};
7336: }
7337: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 7338: }
7339: $output .= '</div></td></tr>'."\n";
7340: return $output;
7341: }
7342:
7343: sub offloadtype_text {
7344: my %ruletitles = &Apache::lonlocal::texthash (
7345: 'default' => 'Offloads to default destinations',
7346: 'homeserver' => "Offloads to user's home server",
7347: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
7348: 'specific' => 'Offloads to specific server',
1.161 raeburn 7349: 'none' => 'No offload',
1.209 raeburn 7350: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
7351: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 7352: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 7353: );
7354: return %ruletitles;
7355: }
7356:
7357: sub sparestype_titles {
7358: my %typestitles = &Apache::lonlocal::texthash (
7359: 'primary' => 'primary',
7360: 'default' => 'default',
7361: );
7362: return %typestitles;
7363: }
7364:
1.28 raeburn 7365: sub contact_titles {
7366: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 7367: 'supportemail' => 'Support E-mail address',
7368: 'adminemail' => 'Default Server Admin E-mail address',
7369: 'errormail' => 'Error reports to be e-mailed to',
7370: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 7371: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
7372: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 7373: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
7374: 'requestsmail' => 'E-mail from course requests requiring approval',
7375: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 7376: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 7377: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.340 raeburn 7378: 'errorthreshold' => 'Error/warning threshold for status e-mail',
7379: 'errorsysmail' => 'Error threshold for e-mail to core group',
7380: 'errorweights' => 'Weights used to compute error count',
7381: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 7382: );
7383: my %short_titles = &Apache::lonlocal::texthash (
7384: adminemail => 'Admin E-mail address',
7385: supportemail => 'Support E-mail',
7386: );
7387: return (\%titles,\%short_titles);
7388: }
7389:
1.286 raeburn 7390: sub helpform_fields {
7391: my %titles = &Apache::lonlocal::texthash (
7392: 'username' => 'Name',
7393: 'user' => 'Username/domain',
7394: 'phone' => 'Phone',
7395: 'cc' => 'Cc e-mail',
7396: 'course' => 'Course Details',
7397: 'section' => 'Sections',
1.289 raeburn 7398: 'screenshot' => 'File upload',
1.286 raeburn 7399: );
7400: my @fields = ('username','phone','user','course','section','cc','screenshot');
7401: my %possoptions = (
7402: username => ['yes','no','req'],
1.289 raeburn 7403: phone => ['yes','no','req'],
1.286 raeburn 7404: user => ['yes','no'],
1.289 raeburn 7405: cc => ['yes','no'],
1.286 raeburn 7406: course => ['yes','no'],
7407: section => ['yes','no'],
7408: screenshot => ['yes','no'],
7409: );
7410: my %fieldoptions = &Apache::lonlocal::texthash (
7411: 'yes' => 'Optional',
7412: 'req' => 'Required',
7413: 'no' => "Not shown",
7414: );
7415: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
7416: }
7417:
1.72 raeburn 7418: sub tool_titles {
7419: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 7420: aboutme => 'Personal web page',
1.86 raeburn 7421: blog => 'Blog',
1.162 raeburn 7422: webdav => 'WebDAV',
1.86 raeburn 7423: portfolio => 'Portfolio',
1.88 bisitz 7424: official => 'Official courses (with institutional codes)',
7425: unofficial => 'Unofficial courses',
1.98 raeburn 7426: community => 'Communities',
1.216 raeburn 7427: textbook => 'Textbook courses',
1.271 raeburn 7428: placement => 'Placement tests',
1.86 raeburn 7429: );
1.72 raeburn 7430: return %titles;
7431: }
7432:
1.101 raeburn 7433: sub courserequest_titles {
7434: my %titles = &Apache::lonlocal::texthash (
7435: official => 'Official',
7436: unofficial => 'Unofficial',
7437: community => 'Communities',
1.216 raeburn 7438: textbook => 'Textbook',
1.271 raeburn 7439: placement => 'Placement tests',
1.325 raeburn 7440: lti => 'LTI Provider',
1.101 raeburn 7441: norequest => 'Not allowed',
1.325 raeburn 7442: approval => 'Approval by DC',
1.101 raeburn 7443: validate => 'With validation',
7444: autolimit => 'Numerical limit',
1.103 raeburn 7445: unlimited => '(blank for unlimited)',
1.101 raeburn 7446: );
7447: return %titles;
7448: }
7449:
1.163 raeburn 7450: sub authorrequest_titles {
7451: my %titles = &Apache::lonlocal::texthash (
7452: norequest => 'Not allowed',
7453: approval => 'Approval by Dom. Coord.',
7454: automatic => 'Automatic approval',
7455: );
7456: return %titles;
1.210 raeburn 7457: }
1.163 raeburn 7458:
1.101 raeburn 7459: sub courserequest_conditions {
7460: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 7461: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 7462: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 7463: );
7464: return %conditions;
7465: }
7466:
7467:
1.27 raeburn 7468: sub print_usercreation {
1.30 raeburn 7469: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 7470: my $numinrow = 4;
1.28 raeburn 7471: my $datatable;
7472: if ($position eq 'top') {
1.30 raeburn 7473: $$rowtotal ++;
1.34 raeburn 7474: my $rowcount = 0;
1.32 raeburn 7475: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 7476: if (ref($rules) eq 'HASH') {
7477: if (keys(%{$rules}) > 0) {
1.32 raeburn 7478: $datatable .= &user_formats_row('username',$settings,$rules,
7479: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 7480: $$rowtotal ++;
1.32 raeburn 7481: $rowcount ++;
7482: }
7483: }
7484: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
7485: if (ref($idrules) eq 'HASH') {
7486: if (keys(%{$idrules}) > 0) {
7487: $datatable .= &user_formats_row('id',$settings,$idrules,
7488: $idruleorder,$numinrow,$rowcount);
7489: $$rowtotal ++;
7490: $rowcount ++;
1.28 raeburn 7491: }
7492: }
1.39 raeburn 7493: if ($rowcount == 0) {
7494: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
7495: $$rowtotal ++;
7496: $rowcount ++;
7497: }
1.34 raeburn 7498: } elsif ($position eq 'middle') {
1.224 raeburn 7499: my @creators = ('author','course','requestcrs');
1.37 raeburn 7500: my ($rules,$ruleorder) =
7501: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 7502: my %lt = &usercreation_types();
7503: my %checked;
7504: if (ref($settings) eq 'HASH') {
7505: if (ref($settings->{'cancreate'}) eq 'HASH') {
7506: foreach my $item (@creators) {
7507: $checked{$item} = $settings->{'cancreate'}{$item};
7508: }
7509: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
7510: foreach my $item (@creators) {
7511: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
7512: $checked{$item} = 'none';
7513: }
7514: }
7515: }
7516: }
7517: my $rownum = 0;
7518: foreach my $item (@creators) {
7519: $rownum ++;
1.224 raeburn 7520: if ($checked{$item} eq '') {
7521: $checked{$item} = 'any';
1.34 raeburn 7522: }
7523: my $css_class;
7524: if ($rownum%2) {
7525: $css_class = '';
7526: } else {
7527: $css_class = ' class="LC_odd_row" ';
7528: }
7529: $datatable .= '<tr'.$css_class.'>'.
7530: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 7531: '</span></td><td style="text-align: right">';
1.224 raeburn 7532: my @options = ('any');
7533: if (ref($rules) eq 'HASH') {
7534: if (keys(%{$rules}) > 0) {
7535: push(@options,('official','unofficial'));
1.37 raeburn 7536: }
7537: }
1.224 raeburn 7538: push(@options,'none');
1.37 raeburn 7539: foreach my $option (@options) {
1.50 raeburn 7540: my $type = 'radio';
1.34 raeburn 7541: my $check = ' ';
1.224 raeburn 7542: if ($checked{$item} eq $option) {
7543: $check = ' checked="checked" ';
1.34 raeburn 7544: }
7545: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 7546: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 7547: $item.'" value="'.$option.'"'.$check.'/> '.
7548: $lt{$option}.'</label> </span>';
7549: }
7550: $datatable .= '</td></tr>';
7551: }
1.28 raeburn 7552: } else {
7553: my @contexts = ('author','course','domain');
1.325 raeburn 7554: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 7555: my %checked;
7556: if (ref($settings) eq 'HASH') {
7557: if (ref($settings->{'authtypes'}) eq 'HASH') {
7558: foreach my $item (@contexts) {
7559: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
7560: foreach my $auth (@authtypes) {
7561: if ($settings->{'authtypes'}{$item}{$auth}) {
7562: $checked{$item}{$auth} = ' checked="checked" ';
7563: }
7564: }
7565: }
7566: }
1.27 raeburn 7567: }
1.35 raeburn 7568: } else {
7569: foreach my $item (@contexts) {
1.36 raeburn 7570: foreach my $auth (@authtypes) {
1.35 raeburn 7571: $checked{$item}{$auth} = ' checked="checked" ';
7572: }
7573: }
1.27 raeburn 7574: }
1.28 raeburn 7575: my %title = &context_names();
7576: my %authname = &authtype_names();
7577: my $rownum = 0;
7578: my $css_class;
7579: foreach my $item (@contexts) {
7580: if ($rownum%2) {
7581: $css_class = '';
7582: } else {
7583: $css_class = ' class="LC_odd_row" ';
7584: }
1.30 raeburn 7585: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 7586: '<td>'.$title{$item}.
7587: '</td><td class="LC_left_item">'.
7588: '<span class="LC_nobreak">';
7589: foreach my $auth (@authtypes) {
7590: $datatable .= '<label>'.
7591: '<input type="checkbox" name="'.$item.'_auth" '.
7592: $checked{$item}{$auth}.' value="'.$auth.'" />'.
7593: $authname{$auth}.'</label> ';
7594: }
7595: $datatable .= '</span></td></tr>';
7596: $rownum ++;
1.27 raeburn 7597: }
1.30 raeburn 7598: $$rowtotal += $rownum;
1.27 raeburn 7599: }
7600: return $datatable;
7601: }
7602:
1.224 raeburn 7603: sub print_selfcreation {
7604: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 7605: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
7606: $emaildomain,$datatable);
1.224 raeburn 7607: if (ref($settings) eq 'HASH') {
7608: if (ref($settings->{'cancreate'}) eq 'HASH') {
7609: $createsettings = $settings->{'cancreate'};
1.236 raeburn 7610: if (ref($createsettings) eq 'HASH') {
7611: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
7612: @selfcreate = @{$createsettings->{'selfcreate'}};
7613: } elsif ($createsettings->{'selfcreate'} ne '') {
7614: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
7615: @selfcreate = ('email','login','sso');
7616: } elsif ($createsettings->{'selfcreate'} ne 'none') {
7617: @selfcreate = ($createsettings->{'selfcreate'});
7618: }
7619: }
7620: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
7621: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 7622: }
1.305 raeburn 7623: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
7624: $emailoptions = $createsettings->{'emailoptions'};
7625: }
1.303 raeburn 7626: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
7627: $emailverified = $createsettings->{'emailverified'};
7628: }
7629: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
7630: $emaildomain = $createsettings->{'emaildomain'};
7631: }
1.224 raeburn 7632: }
7633: }
7634: }
7635: my %radiohash;
7636: my $numinrow = 4;
7637: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 7638: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 7639: if ($position eq 'top') {
7640: my %choices = &Apache::lonlocal::texthash (
7641: cancreate_login => 'Institutional Login',
7642: cancreate_sso => 'Institutional Single Sign On',
7643: );
7644: my @toggles = sort(keys(%choices));
7645: my %defaultchecked = (
7646: 'cancreate_login' => 'off',
7647: 'cancreate_sso' => 'off',
7648: );
1.228 raeburn 7649: my ($onclick,$itemcount);
1.224 raeburn 7650: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
7651: \%choices,$itemcount,$onclick);
1.228 raeburn 7652: $$rowtotal += $itemcount;
7653:
1.224 raeburn 7654: if (ref($usertypes) eq 'HASH') {
7655: if (keys(%{$usertypes}) > 0) {
7656: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
7657: $dom,$numinrow,$othertitle,
1.305 raeburn 7658: 'statustocreate',$rowtotal);
1.224 raeburn 7659: $$rowtotal ++;
7660: }
7661: }
1.240 raeburn 7662: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
7663: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7664: $fieldtitles{'inststatus'} = &mt('Institutional status');
7665: my $rem;
7666: my $numperrow = 2;
7667: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
7668: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 7669: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 7670: '<td class="LC_left_item">'."\n".
1.334 raeburn 7671: '<table>'."\n";
1.240 raeburn 7672: for (my $i=0; $i<@fields; $i++) {
7673: $rem = $i%($numperrow);
7674: if ($rem == 0) {
7675: if ($i > 0) {
7676: $datatable .= '</tr>';
7677: }
7678: $datatable .= '<tr>';
7679: }
7680: my $currval;
1.248 raeburn 7681: if (ref($createsettings) eq 'HASH') {
7682: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
7683: $currval = $createsettings->{'shibenv'}{$fields[$i]};
7684: }
1.240 raeburn 7685: }
7686: $datatable .= '<td class="LC_left_item">'.
7687: '<span class="LC_nobreak">'.
7688: '<input type="text" name="shibenv_'.$fields[$i].'" '.
7689: 'value="'.$currval.'" size="10" /> '.
7690: $fieldtitles{$fields[$i]}.'</span></td>';
7691: }
7692: my $colsleft = $numperrow - $rem;
7693: if ($colsleft > 1 ) {
7694: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7695: ' </td>';
7696: } elsif ($colsleft == 1) {
7697: $datatable .= '<td class="LC_left_item"> </td>';
7698: }
7699: $datatable .= '</tr></table></td></tr>';
7700: $$rowtotal ++;
1.224 raeburn 7701: } elsif ($position eq 'middle') {
7702: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 7703: my @posstypes;
1.224 raeburn 7704: if (ref($types) eq 'ARRAY') {
1.302 raeburn 7705: @posstypes = @{$types};
7706: }
7707: unless (grep(/^default$/,@posstypes)) {
7708: push(@posstypes,'default');
7709: }
7710: my %usertypeshash;
7711: if (ref($usertypes) eq 'HASH') {
7712: %usertypeshash = %{$usertypes};
7713: }
7714: $usertypeshash{'default'} = $othertitle;
7715: foreach my $status (@posstypes) {
7716: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
7717: $numinrow,$$rowtotal,\%usertypeshash);
7718: $$rowtotal ++;
1.224 raeburn 7719: }
7720: } else {
1.236 raeburn 7721: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 7722: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 7723: );
7724: my @toggles = sort(keys(%choices));
7725: my %defaultchecked = (
7726: 'cancreate_email' => 'off',
7727: );
1.305 raeburn 7728: my $customclass = 'LC_selfcreate_email';
7729: my $classprefix = 'LC_canmodify_emailusername_';
7730: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 7731: my $display = 'none';
1.305 raeburn 7732: my $rowstyle = 'display:none';
1.236 raeburn 7733: if (grep(/^\Qemail\E$/,@selfcreate)) {
7734: $display = 'block';
1.305 raeburn 7735: $rowstyle = 'display:table-row';
1.236 raeburn 7736: }
1.305 raeburn 7737: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
7738: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
7739: \%choices,$$rowtotal,$onclick);
7740: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
7741: $rowstyle);
7742: $$rowtotal ++;
7743: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
7744: $rowstyle);
7745: $$rowtotal ++;
7746: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 7747: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 7748: my ($emailrules,$emailruleorder) =
7749: &Apache::lonnet::inst_userrules($dom,'email');
7750: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7751: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7752: if (ref($types) eq 'ARRAY') {
7753: @posstypes = @{$types};
7754: }
7755: if (@posstypes) {
7756: unless (grep(/^default$/,@posstypes)) {
7757: push(@posstypes,'default');
1.302 raeburn 7758: }
7759: if (ref($usertypes) eq 'HASH') {
7760: %usertypeshash = %{$usertypes};
7761: }
1.305 raeburn 7762: my $currassign;
7763: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
7764: $currassign = {
7765: selfassign => $domdefaults{'inststatusguest'},
7766: };
7767: @ordered = @{$domdefaults{'inststatusguest'}};
7768: } else {
7769: $currassign = { selfassign => [] };
7770: }
7771: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
7772: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
7773: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
7774: $numinrow,$othertitle,'selfassign',
7775: $rowtotal,$onclicktypes,$customclass,
7776: $rowstyle);
7777: $$rowtotal ++;
1.302 raeburn 7778: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 7779: foreach my $status (@posstypes) {
7780: my $css_class;
7781: if ($$rowtotal%2) {
7782: $css_class = 'LC_odd_row ';
7783: }
7784: $css_class .= $customclass;
7785: my $rowid = $optionsprefix.$status;
7786: my $hidden = 1;
7787: my $currstyle = 'display:none';
7788: if (grep(/^\Q$status\E$/,@ordered)) {
7789: $currstyle = $rowstyle;
7790: $hidden = 0;
7791: }
7792: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7793: $emailrules,$emailruleorder,$settings,$status,$rowid,
7794: $usertypeshash{$status},$css_class,$currstyle,$intdom);
7795: unless ($hidden) {
7796: $$rowtotal ++;
7797: }
1.224 raeburn 7798: }
1.302 raeburn 7799: } else {
1.305 raeburn 7800: my $css_class;
7801: if ($$rowtotal%2) {
7802: $css_class = 'LC_odd_row ';
7803: }
7804: $css_class .= $customclass;
1.302 raeburn 7805: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 7806: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7807: $emailrules,$emailruleorder,$settings,'default','',
7808: $othertitle,$css_class,$rowstyle,$intdom);
7809: $$rowtotal ++;
1.224 raeburn 7810: }
7811: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 7812: $numinrow = 1;
1.305 raeburn 7813: if (@posstypes) {
7814: foreach my $status (@posstypes) {
7815: my $rowid = $classprefix.$status;
7816: my $datarowstyle = 'display:none';
7817: if (grep(/^\Q$status\E$/,@ordered)) {
7818: $datarowstyle = $rowstyle;
7819: }
7820: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
7821: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7822: $infotitles,$rowid,$customclass,$datarowstyle);
7823: unless ($datarowstyle eq 'display:none') {
7824: $$rowtotal ++;
7825: }
1.224 raeburn 7826: }
1.305 raeburn 7827: } else {
7828: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
7829: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7830: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 7831: }
7832: }
7833: return $datatable;
7834: }
7835:
1.305 raeburn 7836: sub selfcreate_javascript {
7837: return <<"ENDSCRIPT";
7838:
7839: <script type="text/javascript">
7840: // <![CDATA[
7841:
7842: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
7843: var x = document.getElementsByClassName(target);
7844: var insttypes = 0;
7845: var insttypeRegExp = new RegExp(prefix);
7846: if ((x.length != undefined) && (x.length > 0)) {
7847: if (form.elements[radio].length != undefined) {
7848: for (var i=0; i<form.elements[radio].length; i++) {
7849: if (form.elements[radio][i].checked) {
7850: if (form.elements[radio][i].value == 1) {
7851: for (var j=0; j<x.length; j++) {
7852: if (x[j].id == 'undefined') {
7853: x[j].style.display = 'table-row';
7854: } else if (insttypeRegExp.test(x[j].id)) {
7855: insttypes ++;
7856: } else {
7857: x[j].style.display = 'table-row';
7858: }
7859: }
7860: } else {
7861: for (var j=0; j<x.length; j++) {
7862: x[j].style.display = 'none';
7863: }
1.236 raeburn 7864: }
1.305 raeburn 7865: break;
7866: }
7867: }
7868: if (insttypes > 0) {
7869: toggleDataRow(form,checkbox,target,altprefix);
7870: toggleDataRow(form,checkbox,target,prefix,1);
7871: }
7872: }
7873: }
7874: return;
7875: }
7876:
7877: function toggleDataRow(form,checkbox,target,prefix,docount) {
7878: if (form.elements[checkbox].length != undefined) {
7879: var count = 0;
7880: if (docount) {
7881: for (var i=0; i<form.elements[checkbox].length; i++) {
7882: if (form.elements[checkbox][i].checked) {
7883: count ++;
1.236 raeburn 7884: }
1.305 raeburn 7885: }
7886: }
7887: for (var i=0; i<form.elements[checkbox].length; i++) {
7888: var type = form.elements[checkbox][i].value;
7889: if (document.getElementById(prefix+type)) {
7890: if (form.elements[checkbox][i].checked) {
7891: document.getElementById(prefix+type).style.display = 'table-row';
7892: if (count % 2 == 1) {
7893: document.getElementById(prefix+type).className = target+' LC_odd_row';
7894: } else {
7895: document.getElementById(prefix+type).className = target;
1.236 raeburn 7896: }
1.305 raeburn 7897: count ++;
1.236 raeburn 7898: } else {
1.305 raeburn 7899: document.getElementById(prefix+type).style.display = 'none';
7900: }
7901: }
7902: }
7903: }
7904: return;
7905: }
7906:
7907: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
7908: var caller = radio+'_'+status;
7909: if (form.elements[caller].length != undefined) {
7910: for (var i=0; i<form.elements[caller].length; i++) {
7911: if (form.elements[caller][i].checked) {
7912: if (document.getElementById(altprefix+'_inst_'+status)) {
7913: var curr = form.elements[caller][i].value;
7914: if (prefix) {
7915: document.getElementById(prefix+'_'+status).style.display = 'none';
7916: }
7917: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
7918: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
7919: if (curr == 'custom') {
7920: if (prefix) {
7921: document.getElementById(prefix+'_'+status).style.display = 'inline';
7922: }
7923: } else if (curr == 'inst') {
7924: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
7925: } else if (curr == 'noninst') {
7926: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 7927: }
1.305 raeburn 7928: break;
1.236 raeburn 7929: }
7930: }
7931: }
7932: }
7933: }
7934:
1.305 raeburn 7935: // ]]>
7936: </script>
7937:
7938: ENDSCRIPT
7939: }
7940:
7941: sub noninst_users {
7942: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
7943: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
7944: my $class = 'LC_left_item';
7945: if ($css_class) {
7946: $css_class = ' class="'.$css_class.'"';
7947: }
7948: if ($rowid) {
7949: $rowid = ' id="'.$rowid.'"';
7950: }
7951: if ($rowstyle) {
7952: $rowstyle = ' style="'.$rowstyle.'"';
7953: }
7954: my ($output,$description);
7955: if ($type eq 'default') {
7956: $description = &mt('Requests for: [_1]',$typetitle);
7957: } else {
7958: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
7959: }
7960: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
7961: "<td>$description</td>\n".
7962: '<td class="'.$class.'" colspan="2">'.
7963: '<table><tr>';
7964: my %headers = &Apache::lonlocal::texthash(
7965: approve => 'Processing',
7966: email => 'E-mail',
7967: username => 'Username',
7968: );
7969: foreach my $item ('approve','email','username') {
7970: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 7971: }
1.305 raeburn 7972: $output .= '</tr><tr>';
7973: foreach my $item ('approve','email','username') {
1.306 raeburn 7974: $output .= '<td style="vertical-align: top">';
1.305 raeburn 7975: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
7976: if ($item eq 'approve') {
7977: %choices = &Apache::lonlocal::texthash (
7978: automatic => 'Automatically approved',
7979: approval => 'Queued for approval',
7980: );
7981: @options = ('automatic','approval');
7982: $hashref = $processing;
7983: $defoption = 'automatic';
7984: $name = 'cancreate_emailprocess_'.$type;
7985: } elsif ($item eq 'email') {
7986: %choices = &Apache::lonlocal::texthash (
7987: any => 'Any e-mail',
7988: inst => 'Institutional only',
7989: noninst => 'Non-institutional only',
7990: custom => 'Custom restrictions',
7991: );
7992: @options = ('any','inst','noninst');
7993: my $showcustom;
7994: if (ref($emailrules) eq 'HASH') {
7995: if (keys(%{$emailrules}) > 0) {
7996: push(@options,'custom');
7997: $showcustom = 'cancreate_emailrule';
7998: if (ref($settings) eq 'HASH') {
7999: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
8000: foreach my $rule (@{$settings->{'email_rule'}}) {
8001: if (exists($emailrules->{$rule})) {
8002: $hascustom ++;
8003: }
8004: }
8005: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
8006: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
8007: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
8008: if (exists($emailrules->{$rule})) {
8009: $hascustom ++;
8010: }
8011: }
8012: }
8013: }
8014: }
8015: }
8016: }
8017: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
8018: "'cancreate_emaildomain','$type'".');"';
8019: $hashref = $emailoptions;
8020: $defoption = 'any';
8021: $name = 'cancreate_emailoptions_'.$type;
8022: } elsif ($item eq 'username') {
8023: %choices = &Apache::lonlocal::texthash (
8024: all => 'Same as e-mail',
8025: first => 'Omit @domain',
8026: free => 'Free to choose',
8027: );
8028: @options = ('all','first','free');
8029: $hashref = $emailverified;
8030: $defoption = 'all';
8031: $name = 'cancreate_usernameoptions_'.$type;
8032: }
8033: foreach my $option (@options) {
8034: my $checked;
8035: if (ref($hashref) eq 'HASH') {
8036: if ($type eq '') {
8037: if (!exists($hashref->{'default'})) {
8038: if ($option eq $defoption) {
8039: $checked = ' checked="checked"';
8040: }
8041: } else {
8042: if ($hashref->{'default'} eq $option) {
8043: $checked = ' checked="checked"';
8044: }
1.303 raeburn 8045: }
8046: } else {
1.305 raeburn 8047: if (!exists($hashref->{$type})) {
8048: if ($option eq $defoption) {
8049: $checked = ' checked="checked"';
8050: }
8051: } else {
8052: if ($hashref->{$type} eq $option) {
8053: $checked = ' checked="checked"';
8054: }
1.303 raeburn 8055: }
8056: }
1.305 raeburn 8057: } elsif (($item eq 'email') && ($hascustom)) {
8058: if ($option eq 'custom') {
8059: $checked = ' checked="checked"';
8060: }
8061: } elsif ($option eq $defoption) {
8062: $checked = ' checked="checked"';
8063: }
8064: $output .= '<span class="LC_nobreak"><label>'.
8065: '<input type="radio" name="'.$name.'"'.
8066: $checked.' value="'.$option.'"'.$onclick.' />'.
8067: $choices{$option}.'</label></span><br />';
8068: if ($item eq 'email') {
8069: if ($option eq 'custom') {
8070: my $id = 'cancreate_emailrule_'.$type;
8071: my $display = 'none';
8072: if ($checked) {
8073: $display = 'inline';
1.303 raeburn 8074: }
1.305 raeburn 8075: my $numinrow = 2;
8076: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
8077: '<legend>'.&mt('Disallow').'</legend><table>'.
8078: &user_formats_row('email',$settings,$emailrules,
8079: $emailruleorder,$numinrow,'',$type);
8080: '</table></fieldset>';
8081: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
8082: my %text = &Apache::lonlocal::texthash (
8083: inst => 'must end:',
8084: noninst => 'cannot end:',
8085: );
8086: my $value;
8087: if (ref($emaildomain) eq 'HASH') {
8088: if (ref($emaildomain->{$type}) eq 'HASH') {
8089: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 8090: }
8091: }
1.305 raeburn 8092: if ($value eq '') {
8093: $value = '@'.$intdom;
8094: }
8095: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
8096: my $display = 'none';
8097: if ($checked) {
8098: $display = 'inline';
8099: }
8100: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
8101: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
8102: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
8103: '</div>';
1.303 raeburn 8104: }
8105: }
8106: }
1.305 raeburn 8107: $output .= '</td>'."\n";
1.303 raeburn 8108: }
1.305 raeburn 8109: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 8110: return $output;
8111: }
8112:
1.165 raeburn 8113: sub captcha_choice {
1.305 raeburn 8114: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 8115: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
8116: $vertext,$currver);
1.165 raeburn 8117: my %lt = &captcha_phrases();
8118: $keyentry = 'hidden';
1.354 raeburn 8119: my $colspan=2;
1.165 raeburn 8120: if ($context eq 'cancreate') {
1.224 raeburn 8121: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 8122: } elsif ($context eq 'login') {
8123: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 8124: } elsif ($context eq 'passwords') {
8125: $rowname = &mt('"Forgot Password" CAPTCHA validation');
8126: $colspan=1;
1.165 raeburn 8127: }
8128: if (ref($settings) eq 'HASH') {
8129: if ($settings->{'captcha'}) {
8130: $checked{$settings->{'captcha'}} = ' checked="checked"';
8131: } else {
8132: $checked{'original'} = ' checked="checked"';
8133: }
8134: if ($settings->{'captcha'} eq 'recaptcha') {
8135: $pubtext = $lt{'pub'};
8136: $privtext = $lt{'priv'};
8137: $keyentry = 'text';
1.269 raeburn 8138: $vertext = $lt{'ver'};
8139: $currver = $settings->{'recaptchaversion'};
8140: if ($currver ne '2') {
8141: $currver = 1;
8142: }
1.165 raeburn 8143: }
8144: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
8145: $currpub = $settings->{'recaptchakeys'}{'public'};
8146: $currpriv = $settings->{'recaptchakeys'}{'private'};
8147: }
8148: } else {
8149: $checked{'original'} = ' checked="checked"';
8150: }
1.305 raeburn 8151: my $css_class;
8152: if ($itemcount%2) {
8153: $css_class = 'LC_odd_row';
8154: }
8155: if ($customcss) {
8156: $css_class .= " $customcss";
8157: }
8158: $css_class =~ s/^\s+//;
8159: if ($css_class) {
8160: $css_class = ' class="'.$css_class.'"';
8161: }
8162: if ($rowstyle) {
8163: $css_class .= ' style="'.$rowstyle.'"';
8164: }
1.169 raeburn 8165: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 8166: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 8167: '<table><tr><td>'."\n";
8168: foreach my $option ('original','recaptcha','notused') {
8169: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
8170: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
8171: $lt{$option}.'</label></span>';
8172: unless ($option eq 'notused') {
8173: $output .= (' 'x2)."\n";
8174: }
8175: }
8176: #
8177: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
8178: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 8179: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 8180: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 8181: #
1.165 raeburn 8182: $output .= '</td></tr>'."\n".
1.305 raeburn 8183: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 8184: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
8185: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
8186: $currpub.'" size="40" /></span><br />'."\n".
8187: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
8188: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 8189: $currpriv.'" size="40" /></span><br />'.
8190: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
8191: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
8192: $currver.'" size="3" /></span><br />'.
8193: '</td></tr></table>'."\n".
1.165 raeburn 8194: '</td></tr>';
8195: return $output;
8196: }
8197:
1.32 raeburn 8198: sub user_formats_row {
1.305 raeburn 8199: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 8200: my $output;
8201: my %text = (
8202: 'username' => 'new usernames',
8203: 'id' => 'IDs',
8204: );
1.305 raeburn 8205: unless ($type eq 'email') {
8206: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
8207: $output = '<tr '.$css_class.'>'.
8208: '<td><span class="LC_nobreak">'.
8209: &mt("Format rules to check for $text{$type}: ").
8210: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 8211: }
1.27 raeburn 8212: my $rem;
8213: if (ref($ruleorder) eq 'ARRAY') {
8214: for (my $i=0; $i<@{$ruleorder}; $i++) {
8215: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
8216: my $rem = $i%($numinrow);
8217: if ($rem == 0) {
8218: if ($i > 0) {
8219: $output .= '</tr>';
8220: }
8221: $output .= '<tr>';
8222: }
8223: my $check = ' ';
1.39 raeburn 8224: if (ref($settings) eq 'HASH') {
8225: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
8226: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
8227: $check = ' checked="checked" ';
8228: }
1.305 raeburn 8229: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
8230: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
8231: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
8232: $check = ' checked="checked" ';
8233: }
8234: }
1.27 raeburn 8235: }
8236: }
1.305 raeburn 8237: my $name = $type.'_rule';
8238: if ($type eq 'email') {
8239: $name .= '_'.$status;
8240: }
1.27 raeburn 8241: $output .= '<td class="LC_left_item">'.
8242: '<span class="LC_nobreak"><label>'.
1.311 raeburn 8243: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 8244: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
8245: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
8246: }
8247: }
8248: $rem = @{$ruleorder}%($numinrow);
8249: }
1.305 raeburn 8250: my $colsleft;
8251: if ($rem) {
8252: $colsleft = $numinrow - $rem;
8253: }
1.27 raeburn 8254: if ($colsleft > 1 ) {
8255: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8256: ' </td>';
8257: } elsif ($colsleft == 1) {
8258: $output .= '<td class="LC_left_item"> </td>';
8259: }
1.305 raeburn 8260: $output .= '</tr></table>';
8261: unless ($type eq 'email') {
8262: $output .= '</td></tr>';
8263: }
1.27 raeburn 8264: return $output;
8265: }
8266:
1.34 raeburn 8267: sub usercreation_types {
8268: my %lt = &Apache::lonlocal::texthash (
8269: author => 'When adding a co-author',
8270: course => 'When adding a user to a course',
1.100 raeburn 8271: requestcrs => 'When requesting a course',
1.34 raeburn 8272: any => 'Any',
8273: official => 'Institutional only ',
8274: unofficial => 'Non-institutional only',
8275: none => 'None',
8276: );
8277: return %lt;
1.48 raeburn 8278: }
1.34 raeburn 8279:
1.224 raeburn 8280: sub selfcreation_types {
8281: my %lt = &Apache::lonlocal::texthash (
8282: selfcreate => 'User creates own account',
8283: any => 'Any',
8284: official => 'Institutional only ',
8285: unofficial => 'Non-institutional only',
8286: email => 'E-mail address',
8287: login => 'Institutional Login',
8288: sso => 'SSO',
8289: );
8290: }
8291:
1.28 raeburn 8292: sub authtype_names {
8293: my %lt = &Apache::lonlocal::texthash(
8294: int => 'Internal',
8295: krb4 => 'Kerberos 4',
8296: krb5 => 'Kerberos 5',
8297: loc => 'Local',
1.325 raeburn 8298: lti => 'LTI',
1.28 raeburn 8299: );
8300: return %lt;
8301: }
8302:
8303: sub context_names {
8304: my %context_title = &Apache::lonlocal::texthash(
8305: author => 'Creating users when an Author',
8306: course => 'Creating users when in a course',
8307: domain => 'Creating users when a Domain Coordinator',
8308: );
8309: return %context_title;
8310: }
8311:
1.33 raeburn 8312: sub print_usermodification {
8313: my ($position,$dom,$settings,$rowtotal) = @_;
8314: my $numinrow = 4;
8315: my ($context,$datatable,$rowcount);
8316: if ($position eq 'top') {
8317: $rowcount = 0;
8318: $context = 'author';
8319: foreach my $role ('ca','aa') {
8320: $datatable .= &modifiable_userdata_row($context,$role,$settings,
8321: $numinrow,$rowcount);
8322: $$rowtotal ++;
8323: $rowcount ++;
8324: }
1.230 raeburn 8325: } elsif ($position eq 'bottom') {
1.33 raeburn 8326: $context = 'course';
8327: $rowcount = 0;
8328: foreach my $role ('st','ep','ta','in','cr') {
8329: $datatable .= &modifiable_userdata_row($context,$role,$settings,
8330: $numinrow,$rowcount);
8331: $$rowtotal ++;
8332: $rowcount ++;
8333: }
8334: }
8335: return $datatable;
8336: }
8337:
1.43 raeburn 8338: sub print_defaults {
1.236 raeburn 8339: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 8340: my $rownum = 0;
1.294 raeburn 8341: my ($datatable,$css_class,$titles);
8342: unless ($position eq 'bottom') {
8343: $titles = &defaults_titles($dom);
8344: }
1.236 raeburn 8345: if ($position eq 'top') {
8346: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
8347: 'datelocale_def','portal_def');
8348: my %defaults;
8349: if (ref($settings) eq 'HASH') {
8350: %defaults = %{$settings};
1.43 raeburn 8351: } else {
1.236 raeburn 8352: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8353: foreach my $item (@items) {
8354: $defaults{$item} = $domdefaults{$item};
8355: }
1.43 raeburn 8356: }
1.236 raeburn 8357: foreach my $item (@items) {
8358: if ($rownum%2) {
8359: $css_class = '';
8360: } else {
8361: $css_class = ' class="LC_odd_row" ';
8362: }
8363: $datatable .= '<tr'.$css_class.'>'.
8364: '<td><span class="LC_nobreak">'.$titles->{$item}.
8365: '</span></td><td class="LC_right_item" colspan="3">';
8366: if ($item eq 'auth_def') {
1.325 raeburn 8367: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 8368: my %shortauth = (
8369: internal => 'int',
8370: krb4 => 'krb4',
8371: krb5 => 'krb5',
1.325 raeburn 8372: localauth => 'loc',
8373: lti => 'lti',
1.236 raeburn 8374: );
8375: my %authnames = &authtype_names();
8376: foreach my $auth (@authtypes) {
8377: my $checked = ' ';
8378: if ($defaults{$item} eq $auth) {
8379: $checked = ' checked="checked" ';
8380: }
8381: $datatable .= '<label><input type="radio" name="'.$item.
8382: '" value="'.$auth.'"'.$checked.'/>'.
8383: $authnames{$shortauth{$auth}}.'</label> ';
8384: }
8385: } elsif ($item eq 'timezone_def') {
8386: my $includeempty = 1;
8387: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
8388: } elsif ($item eq 'datelocale_def') {
8389: my $includeempty = 1;
8390: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
8391: } elsif ($item eq 'lang_def') {
1.263 raeburn 8392: my $includeempty = 1;
8393: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 8394: } else {
8395: my $size;
8396: if ($item eq 'portal_def') {
8397: $size = ' size="25"';
8398: }
8399: $datatable .= '<input type="text" name="'.$item.'" value="'.
8400: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 8401: }
1.236 raeburn 8402: $datatable .= '</td></tr>';
8403: $rownum ++;
8404: }
1.354 raeburn 8405: } else {
1.294 raeburn 8406: my %defaults;
8407: if (ref($settings) eq 'HASH') {
1.354 raeburn 8408: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
8409: my $maxnum = @{$settings->{'inststatusorder'}};
8410: for (my $i=0; $i<$maxnum; $i++) {
8411: $css_class = $rownum%2?' class="LC_odd_row"':'';
8412: my $item = $settings->{'inststatusorder'}->[$i];
8413: my $title = $settings->{'inststatustypes'}->{$item};
8414: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
8415: $datatable .= '<tr'.$css_class.'>'.
8416: '<td><span class="LC_nobreak">'.
8417: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
8418: for (my $k=0; $k<=$maxnum; $k++) {
8419: my $vpos = $k+1;
8420: my $selstr;
8421: if ($k == $i) {
8422: $selstr = ' selected="selected" ';
8423: }
8424: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8425: }
8426: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
8427: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
8428: &mt('delete').'</span></td>'.
8429: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed:').
8430: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
8431: '</span></td></tr>';
8432: }
8433: $css_class = $rownum%2?' class="LC_odd_row"':'';
8434: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
8435: $datatable .= '<tr '.$css_class.'>'.
8436: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
8437: for (my $k=0; $k<=$maxnum; $k++) {
8438: my $vpos = $k+1;
8439: my $selstr;
8440: if ($k == $maxnum) {
8441: $selstr = ' selected="selected" ';
8442: }
8443: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8444: }
8445: $datatable .= '</select> '.&mt('Internal ID:').
8446: '<input type="text" size="10" name="addinststatus" value="" />'.
8447: ' '.&mt('(new)').
8448: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
8449: &mt('Name displayed:').
8450: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
8451: '</tr>'."\n";
8452: $rownum ++;
1.294 raeburn 8453: }
1.354 raeburn 8454: }
8455: }
8456: $$rowtotal += $rownum;
1.43 raeburn 8457: return $datatable;
8458: }
8459:
1.168 raeburn 8460: sub get_languages_hash {
8461: my %langchoices;
8462: foreach my $id (&Apache::loncommon::languageids()) {
8463: my $code = &Apache::loncommon::supportedlanguagecode($id);
8464: if ($code ne '') {
8465: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
8466: }
8467: }
8468: return %langchoices;
8469: }
8470:
1.43 raeburn 8471: sub defaults_titles {
1.141 raeburn 8472: my ($dom) = @_;
1.43 raeburn 8473: my %titles = &Apache::lonlocal::texthash (
8474: 'auth_def' => 'Default authentication type',
8475: 'auth_arg_def' => 'Default authentication argument',
8476: 'lang_def' => 'Default language',
1.54 raeburn 8477: 'timezone_def' => 'Default timezone',
1.68 raeburn 8478: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 8479: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 8480: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
8481: 'intauth_check' => 'Check bcrypt cost if authenticated',
8482: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 8483: );
1.141 raeburn 8484: if ($dom) {
8485: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
8486: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
8487: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
8488: $protocol = 'http' if ($protocol ne 'https');
8489: if ($uint_dom) {
8490: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
8491: $uint_dom);
8492: }
8493: }
1.43 raeburn 8494: return (\%titles);
8495: }
8496:
1.346 raeburn 8497: sub print_scantron {
8498: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
8499: if ($position eq 'top') {
8500: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
8501: } else {
8502: return &print_scantronconfig($dom,$settings,\$rowtotal);
8503: }
8504: }
8505:
8506: sub scantron_javascript {
8507: return <<"ENDSCRIPT";
8508:
8509: <script type="text/javascript">
8510: // <![CDATA[
8511:
8512: function toggleScantron(form) {
1.347 raeburn 8513: var csvfieldset = new Array();
1.346 raeburn 8514: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 8515: csvfieldset.push(document.getElementById('scantroncsv_cols'));
8516: }
8517: if (document.getElementById('scantroncsv_options')) {
8518: csvfieldset.push(document.getElementById('scantroncsv_options'));
8519: }
8520: if (csvfieldset.length) {
1.346 raeburn 8521: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 8522: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 8523: if (scantroncsv.checked) {
1.347 raeburn 8524: for (var i=0; i<csvfieldset.length; i++) {
8525: csvfieldset[i].style.display = 'block';
8526: }
1.346 raeburn 8527: } else {
1.347 raeburn 8528: for (var i=0; i<csvfieldset.length; i++) {
8529: csvfieldset[i].style.display = 'none';
8530: }
1.346 raeburn 8531: var csvselects = document.getElementsByClassName('scantronconfig_csv');
8532: if (csvselects.length) {
8533: for (var j=0; j<csvselects.length; j++) {
8534: csvselects[j].selectedIndex = 0;
8535: }
8536: }
8537: }
8538: }
8539: }
8540: return;
8541: }
8542: // ]]>
8543: </script>
8544:
8545: ENDSCRIPT
8546:
8547: }
8548:
1.46 raeburn 8549: sub print_scantronformat {
8550: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
8551: my $itemcount = 1;
1.60 raeburn 8552: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
8553: %confhash);
1.46 raeburn 8554: my $switchserver = &check_switchserver($dom,$confname);
8555: my %lt = &Apache::lonlocal::texthash (
1.95 www 8556: default => 'Default bubblesheet format file error',
8557: custom => 'Custom bubblesheet format file error',
1.46 raeburn 8558: );
8559: my %scantronfiles = (
8560: default => 'default.tab',
8561: custom => 'custom.tab',
8562: );
8563: foreach my $key (keys(%scantronfiles)) {
8564: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
8565: .$scantronfiles{$key};
8566: }
8567: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
8568: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
8569: if (!$switchserver) {
8570: my $servadm = $r->dir_config('lonAdmEMail');
8571: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
8572: if ($configuserok eq 'ok') {
8573: if ($author_ok eq 'ok') {
8574: my %legacyfile = (
1.346 raeburn 8575: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
8576: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 8577: );
8578: my %md5chk;
8579: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 8580: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
8581: chomp($md5chk{$type});
1.46 raeburn 8582: }
8583: if ($md5chk{'default'} ne $md5chk{'custom'}) {
8584: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 8585: ($scantronurls{$type},my $error) =
1.46 raeburn 8586: &legacy_scantronformat($r,$dom,$confname,
8587: $type,$legacyfile{$type},
8588: $scantronurls{$type},
8589: $scantronfiles{$type});
1.60 raeburn 8590: if ($error ne '') {
8591: $error{$type} = $error;
8592: }
8593: }
8594: if (keys(%error) == 0) {
8595: $is_custom = 1;
1.346 raeburn 8596: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 8597: $scantronurls{'custom'};
1.346 raeburn 8598: my $putresult =
1.60 raeburn 8599: &Apache::lonnet::put_dom('configuration',
8600: \%confhash,$dom);
8601: if ($putresult ne 'ok') {
1.346 raeburn 8602: $error{'custom'} =
1.60 raeburn 8603: '<span class="LC_error">'.
8604: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
8605: }
1.46 raeburn 8606: }
8607: } else {
1.60 raeburn 8608: ($scantronurls{'default'},my $error) =
1.46 raeburn 8609: &legacy_scantronformat($r,$dom,$confname,
8610: 'default',$legacyfile{'default'},
8611: $scantronurls{'default'},
8612: $scantronfiles{'default'});
1.60 raeburn 8613: if ($error eq '') {
8614: $confhash{'scantron'}{'scantronformat'} = '';
8615: my $putresult =
8616: &Apache::lonnet::put_dom('configuration',
8617: \%confhash,$dom);
8618: if ($putresult ne 'ok') {
8619: $error{'default'} =
8620: '<span class="LC_error">'.
8621: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
8622: }
8623: } else {
8624: $error{'default'} = $error;
8625: }
1.46 raeburn 8626: }
8627: }
8628: }
8629: } else {
1.95 www 8630: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 8631: }
8632: }
8633: if (ref($settings) eq 'HASH') {
8634: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
8635: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
8636: if ((!@info) || ($info[0] eq 'no_such_dir')) {
8637: $scantronurl = '';
8638: } else {
8639: $scantronurl = $settings->{'scantronformat'};
8640: }
8641: $is_custom = 1;
8642: } else {
8643: $scantronurl = $scantronurls{'default'};
8644: }
8645: } else {
1.60 raeburn 8646: if ($is_custom) {
8647: $scantronurl = $scantronurls{'custom'};
8648: } else {
8649: $scantronurl = $scantronurls{'default'};
8650: }
1.46 raeburn 8651: }
8652: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8653: $datatable .= '<tr'.$css_class.'>';
8654: if (!$is_custom) {
1.65 raeburn 8655: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
8656: '<span class="LC_nobreak">';
1.46 raeburn 8657: if ($scantronurl) {
1.199 raeburn 8658: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
8659: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 8660: } else {
8661: $datatable = &mt('File unavailable for display');
8662: }
1.65 raeburn 8663: $datatable .= '</span></td>';
1.60 raeburn 8664: if (keys(%error) == 0) {
1.306 raeburn 8665: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 8666: if (!$switchserver) {
8667: $datatable .= &mt('Upload:').'<br />';
8668: }
8669: } else {
8670: my $errorstr;
8671: foreach my $key (sort(keys(%error))) {
8672: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
8673: }
8674: $datatable .= '<td>'.$errorstr;
8675: }
1.46 raeburn 8676: } else {
8677: if (keys(%error) > 0) {
8678: my $errorstr;
8679: foreach my $key (sort(keys(%error))) {
8680: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
8681: }
1.60 raeburn 8682: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 8683: } elsif ($scantronurl) {
1.199 raeburn 8684: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
8685: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 8686: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 8687: $link.
8688: '<label><input type="checkbox" name="scantronformat_del"'.
8689: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 8690: '<td><span class="LC_nobreak"> '.
8691: &mt('Replace:').'</span><br />';
1.46 raeburn 8692: }
8693: }
8694: if (keys(%error) == 0) {
8695: if ($switchserver) {
8696: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
8697: } else {
1.65 raeburn 8698: $datatable .='<span class="LC_nobreak"> '.
8699: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 8700: }
8701: }
8702: $datatable .= '</td></tr>';
8703: $$rowtotal ++;
8704: return $datatable;
8705: }
8706:
8707: sub legacy_scantronformat {
8708: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
8709: my ($url,$error);
8710: my @statinfo = &Apache::lonnet::stat_file($newurl);
8711: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
8712: (my $result,$url) =
8713: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
8714: '','',$newfile);
8715: if ($result ne 'ok') {
1.130 raeburn 8716: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 8717: }
8718: }
8719: return ($url,$error);
8720: }
1.43 raeburn 8721:
1.346 raeburn 8722: sub print_scantronconfig {
8723: my ($dom,$settings,$rowtotal) = @_;
8724: my $itemcount = 2;
8725: my $is_checked = ' checked="checked"';
1.347 raeburn 8726: my %optionson = (
8727: hdr => ' checked="checked"',
8728: pad => ' checked="checked"',
8729: rem => ' checked="checked"',
8730: );
8731: my %optionsoff = (
8732: hdr => '',
8733: pad => '',
8734: rem => '',
8735: );
1.346 raeburn 8736: my $currcsvsty = 'none';
1.347 raeburn 8737: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 8738: my @fields = &scantroncsv_fields();
8739: my %titles = &scantronconfig_titles();
8740: if (ref($settings) eq 'HASH') {
8741: if (ref($settings->{config}) eq 'HASH') {
8742: if ($settings->{config}->{dat}) {
8743: $checked{'dat'} = $is_checked;
8744: }
8745: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 8746: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
8747: %csvfields = %{$settings->{config}->{csv}->{fields}};
8748: if (keys(%csvfields) > 0) {
8749: $checked{'csv'} = $is_checked;
8750: $currcsvsty = 'block';
8751: }
8752: }
8753: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
8754: %csvoptions = %{$settings->{config}->{csv}->{options}};
8755: foreach my $option (keys(%optionson)) {
8756: unless ($csvoptions{$option}) {
8757: $optionsoff{$option} = $optionson{$option};
8758: $optionson{$option} = '';
8759: }
8760: }
1.346 raeburn 8761: }
8762: }
8763: } else {
8764: $checked{'dat'} = $is_checked;
8765: }
8766: } else {
8767: $checked{'dat'} = $is_checked;
8768: }
8769: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
8770: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8771: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
8772: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
8773: foreach my $item ('dat','csv') {
8774: my $id;
8775: if ($item eq 'csv') {
8776: $id = 'id="scantronconfcsv" ';
1.347 raeburn 8777: }
1.346 raeburn 8778: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
8779: $titles{$item}.'</label>'.(' 'x3);
8780: if ($item eq 'csv') {
8781: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
8782: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
8783: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
8784: foreach my $col (@fields) {
8785: my $selnone;
8786: if ($csvfields{$col} eq '') {
8787: $selnone = ' selected="selected"';
8788: }
8789: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
8790: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
8791: '<option value=""'.$selnone.'></option>';
8792: for (my $i=0; $i<20; $i++) {
8793: my $shown = $i+1;
8794: my $sel;
8795: unless ($selnone) {
8796: if (exists($csvfields{$col})) {
8797: if ($csvfields{$col} == $i) {
8798: $sel = ' selected="selected"';
8799: }
8800: }
8801: }
8802: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
8803: }
8804: $datatable .= '</select></td></tr>';
8805: }
1.347 raeburn 8806: $datatable .= '</table></fieldset>'.
8807: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
8808: '<legend>'.&mt('CSV Options').'</legend>';
8809: foreach my $option ('hdr','pad','rem') {
8810: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
8811: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
8812: &mt('Yes').'</label>'.(' 'x2)."\n".
8813: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
8814: }
8815: $datatable .= '</fieldset>';
1.346 raeburn 8816: $itemcount ++;
8817: }
8818: }
8819: $datatable .= '</td></tr>';
8820: $$rowtotal ++;
8821: return $datatable;
8822: }
8823:
8824: sub scantronconfig_titles {
8825: return &Apache::lonlocal::texthash(
8826: dat => 'Standard format (.dat)',
8827: csv => 'Comma separated values (.csv)',
1.347 raeburn 8828: hdr => 'Remove first line in file (contains column titles)',
8829: pad => 'Prepend 0s to PaperID',
1.348 raeburn 8830: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 8831: CODE => 'CODE',
8832: ID => 'Student ID',
8833: PaperID => 'Paper ID',
8834: FirstName => 'First Name',
8835: LastName => 'Last Name',
8836: FirstQuestion => 'First Question Response',
8837: Section => 'Section',
8838: );
8839: }
8840:
8841: sub scantroncsv_fields {
8842: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
8843: }
8844:
1.49 raeburn 8845: sub print_coursecategories {
1.57 raeburn 8846: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
8847: my $datatable;
8848: if ($position eq 'top') {
1.238 raeburn 8849: my (%checked);
8850: my @catitems = ('unauth','auth');
8851: my @cattypes = ('std','domonly','codesrch','none');
8852: $checked{'unauth'} = 'std';
8853: $checked{'auth'} = 'std';
8854: if (ref($settings) eq 'HASH') {
8855: foreach my $type (@cattypes) {
8856: if ($type eq $settings->{'unauth'}) {
8857: $checked{'unauth'} = $type;
8858: }
8859: if ($type eq $settings->{'auth'}) {
8860: $checked{'auth'} = $type;
8861: }
8862: }
8863: }
8864: my %lt = &Apache::lonlocal::texthash (
8865: unauth => 'Catalog type for unauthenticated users',
8866: auth => 'Catalog type for authenticated users',
8867: none => 'No catalog',
8868: std => 'Standard catalog',
8869: domonly => 'Domain-only catalog',
8870: codesrch => "Code search form",
8871: );
8872: my $itemcount = 0;
8873: foreach my $item (@catitems) {
8874: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8875: $datatable .= '<tr '.$css_class.'>'.
8876: '<td>'.$lt{$item}.'</td>'.
8877: '<td class="LC_right_item"><span class="LC_nobreak">';
8878: foreach my $type (@cattypes) {
8879: my $ischecked;
8880: if ($checked{$item} eq $type) {
8881: $ischecked=' checked="checked"';
8882: }
8883: $datatable .= '<label>'.
8884: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
8885: ' />'.$lt{$type}.'</label> ';
8886: }
1.327 raeburn 8887: $datatable .= '</span></td></tr>';
1.238 raeburn 8888: $itemcount ++;
8889: }
8890: $$rowtotal += $itemcount;
8891: } elsif ($position eq 'middle') {
1.57 raeburn 8892: my $toggle_cats_crs = ' ';
8893: my $toggle_cats_dom = ' checked="checked" ';
8894: my $can_cat_crs = ' ';
8895: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 8896: my $toggle_catscomm_comm = ' ';
8897: my $toggle_catscomm_dom = ' checked="checked" ';
8898: my $can_catcomm_comm = ' ';
8899: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 8900: my $toggle_catsplace_place = ' ';
8901: my $toggle_catsplace_dom = ' checked="checked" ';
8902: my $can_catplace_place = ' ';
8903: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 8904:
1.57 raeburn 8905: if (ref($settings) eq 'HASH') {
8906: if ($settings->{'togglecats'} eq 'crs') {
8907: $toggle_cats_crs = $toggle_cats_dom;
8908: $toggle_cats_dom = ' ';
8909: }
8910: if ($settings->{'categorize'} eq 'crs') {
8911: $can_cat_crs = $can_cat_dom;
8912: $can_cat_dom = ' ';
8913: }
1.120 raeburn 8914: if ($settings->{'togglecatscomm'} eq 'comm') {
8915: $toggle_catscomm_comm = $toggle_catscomm_dom;
8916: $toggle_catscomm_dom = ' ';
8917: }
8918: if ($settings->{'categorizecomm'} eq 'comm') {
8919: $can_catcomm_comm = $can_catcomm_dom;
8920: $can_catcomm_dom = ' ';
8921: }
1.272 raeburn 8922: if ($settings->{'togglecatsplace'} eq 'place') {
8923: $toggle_catsplace_place = $toggle_catsplace_dom;
8924: $toggle_catsplace_dom = ' ';
8925: }
8926: if ($settings->{'categorizeplace'} eq 'place') {
8927: $can_catplace_place = $can_catplace_dom;
8928: $can_catplace_dom = ' ';
8929: }
1.57 raeburn 8930: }
8931: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 8932: togglecats => 'Show/Hide a course in catalog',
8933: togglecatscomm => 'Show/Hide a community in catalog',
8934: togglecatsplace => 'Show/Hide a placement test in catalog',
8935: categorize => 'Assign a category to a course',
8936: categorizecomm => 'Assign a category to a community',
8937: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 8938: );
8939: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 8940: dom => 'Set in Domain',
8941: crs => 'Set in Course',
8942: comm => 'Set in Community',
8943: place => 'Set in Placement Test',
1.57 raeburn 8944: );
8945: $datatable = '<tr class="LC_odd_row">'.
8946: '<td>'.$title{'togglecats'}.'</td>'.
8947: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8948: '<input type="radio" name="togglecats"'.
8949: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8950: '<label><input type="radio" name="togglecats"'.
8951: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
8952: '</tr><tr>'.
8953: '<td>'.$title{'categorize'}.'</td>'.
8954: '<td class="LC_right_item"><span class="LC_nobreak">'.
8955: '<label><input type="radio" name="categorize"'.
8956: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8957: '<label><input type="radio" name="categorize"'.
8958: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 8959: '</tr><tr class="LC_odd_row">'.
8960: '<td>'.$title{'togglecatscomm'}.'</td>'.
8961: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8962: '<input type="radio" name="togglecatscomm"'.
8963: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8964: '<label><input type="radio" name="togglecatscomm"'.
8965: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
8966: '</tr><tr>'.
8967: '<td>'.$title{'categorizecomm'}.'</td>'.
8968: '<td class="LC_right_item"><span class="LC_nobreak">'.
8969: '<label><input type="radio" name="categorizecomm"'.
8970: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8971: '<label><input type="radio" name="categorizecomm"'.
8972: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 8973: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 8974: '<td>'.$title{'togglecatsplace'}.'</td>'.
8975: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8976: '<input type="radio" name="togglecatsplace"'.
8977: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8978: '<label><input type="radio" name="togglecatscomm"'.
8979: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
8980: '</tr><tr>'.
8981: '<td>'.$title{'categorizeplace'}.'</td>'.
8982: '<td class="LC_right_item"><span class="LC_nobreak">'.
8983: '<label><input type="radio" name="categorizeplace"'.
8984: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8985: '<label><input type="radio" name="categorizeplace"'.
8986: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 8987: '</tr>';
1.272 raeburn 8988: $$rowtotal += 6;
1.57 raeburn 8989: } else {
8990: my $css_class;
8991: my $itemcount = 1;
8992: my $cathash;
8993: if (ref($settings) eq 'HASH') {
8994: $cathash = $settings->{'cats'};
8995: }
8996: if (ref($cathash) eq 'HASH') {
8997: my (@cats,@trails,%allitems,%idx,@jsarray);
8998: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
8999: \%allitems,\%idx,\@jsarray);
9000: my $maxdepth = scalar(@cats);
9001: my $colattrib = '';
9002: if ($maxdepth > 2) {
9003: $colattrib = ' colspan="2" ';
9004: }
9005: my @path;
9006: if (@cats > 0) {
9007: if (ref($cats[0]) eq 'ARRAY') {
9008: my $numtop = @{$cats[0]};
9009: my $maxnum = $numtop;
1.120 raeburn 9010: my %default_names = (
9011: instcode => &mt('Official courses'),
9012: communities => &mt('Communities'),
1.272 raeburn 9013: placement => &mt('Placement Tests'),
1.120 raeburn 9014: );
9015:
9016: if ((!grep(/^instcode$/,@{$cats[0]})) ||
9017: ($cathash->{'instcode::0'} eq '') ||
9018: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 9019: ($cathash->{'communities::0'} eq '') ||
9020: (!grep(/^placement$/,@{$cats[0]})) ||
9021: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 9022: $maxnum ++;
9023: }
9024: my $lastidx;
9025: for (my $i=0; $i<$numtop; $i++) {
9026: my $parent = $cats[0][$i];
9027: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9028: my $item = &escape($parent).'::0';
9029: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
9030: $lastidx = $idx{$item};
9031: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
9032: .'<select name="'.$item.'"'.$chgstr.'>';
9033: for (my $k=0; $k<=$maxnum; $k++) {
9034: my $vpos = $k+1;
9035: my $selstr;
9036: if ($k == $i) {
9037: $selstr = ' selected="selected" ';
9038: }
9039: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9040: }
1.214 raeburn 9041: $datatable .= '</select></span></td><td>';
1.272 raeburn 9042: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 9043: $datatable .= '<span class="LC_nobreak">'
9044: .$default_names{$parent}.'</span>';
9045: if ($parent eq 'instcode') {
9046: $datatable .= '<br /><span class="LC_nobreak">('
9047: .&mt('with institutional codes')
9048: .')</span></td><td'.$colattrib.'>';
9049: } else {
9050: $datatable .= '<table><tr><td>';
9051: }
9052: $datatable .= '<span class="LC_nobreak">'
9053: .'<label><input type="radio" name="'
9054: .$parent.'" value="1" checked="checked" />'
9055: .&mt('Display').'</label>';
9056: if ($parent eq 'instcode') {
9057: $datatable .= ' ';
9058: } else {
9059: $datatable .= '</span></td></tr><tr><td>'
9060: .'<span class="LC_nobreak">';
9061: }
9062: $datatable .= '<label><input type="radio" name="'
9063: .$parent.'" value="0" />'
9064: .&mt('Do not display').'</label></span>';
1.272 raeburn 9065: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 9066: $datatable .= '</td></tr></table>';
9067: }
9068: $datatable .= '</td>';
1.57 raeburn 9069: } else {
9070: $datatable .= $parent
1.214 raeburn 9071: .' <span class="LC_nobreak"><label>'
9072: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 9073: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
9074: }
9075: my $depth = 1;
9076: push(@path,$parent);
9077: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
9078: pop(@path);
9079: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9080: $itemcount ++;
9081: }
1.48 raeburn 9082: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 9083: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
9084: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 9085: for (my $k=0; $k<=$maxnum; $k++) {
9086: my $vpos = $k+1;
9087: my $selstr;
1.57 raeburn 9088: if ($k == $numtop) {
1.48 raeburn 9089: $selstr = ' selected="selected" ';
9090: }
9091: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9092: }
1.59 bisitz 9093: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 9094: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
9095: .'</tr>'."\n";
1.48 raeburn 9096: $itemcount ++;
1.272 raeburn 9097: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 9098: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
9099: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9100: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
9101: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
9102: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
9103: for (my $k=0; $k<=$maxnum; $k++) {
9104: my $vpos = $k+1;
9105: my $selstr;
9106: if ($k == $maxnum) {
9107: $selstr = ' selected="selected" ';
9108: }
9109: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 9110: }
1.120 raeburn 9111: $datatable .= '</select></span></td>'.
9112: '<td><span class="LC_nobreak">'.
9113: $default_names{$default}.'</span>';
9114: if ($default eq 'instcode') {
9115: $datatable .= '<br /><span class="LC_nobreak">('
9116: .&mt('with institutional codes').')</span>';
9117: }
9118: $datatable .= '</td>'
9119: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
9120: .&mt('Display').'</label> '
9121: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
9122: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 9123: }
9124: }
9125: }
1.57 raeburn 9126: } else {
9127: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 9128: }
9129: } else {
1.327 raeburn 9130: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 9131: .&initialize_categories($itemcount);
1.48 raeburn 9132: }
1.57 raeburn 9133: $$rowtotal += $itemcount;
1.48 raeburn 9134: }
9135: return $datatable;
9136: }
9137:
1.69 raeburn 9138: sub print_serverstatuses {
9139: my ($dom,$settings,$rowtotal) = @_;
9140: my $datatable;
9141: my @pages = &serverstatus_pages();
9142: my (%namedaccess,%machineaccess);
9143: foreach my $type (@pages) {
9144: $namedaccess{$type} = '';
9145: $machineaccess{$type}= '';
9146: }
9147: if (ref($settings) eq 'HASH') {
9148: foreach my $type (@pages) {
9149: if (exists($settings->{$type})) {
9150: if (ref($settings->{$type}) eq 'HASH') {
9151: foreach my $key (keys(%{$settings->{$type}})) {
9152: if ($key eq 'namedusers') {
9153: $namedaccess{$type} = $settings->{$type}->{$key};
9154: } elsif ($key eq 'machines') {
9155: $machineaccess{$type} = $settings->{$type}->{$key};
9156: }
9157: }
9158: }
9159: }
9160: }
9161: }
1.81 raeburn 9162: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 9163: my $rownum = 0;
9164: my $css_class;
9165: foreach my $type (@pages) {
9166: $rownum ++;
9167: $css_class = $rownum%2?' class="LC_odd_row"':'';
9168: $datatable .= '<tr'.$css_class.'>'.
9169: '<td><span class="LC_nobreak">'.
9170: $titles->{$type}.'</span></td>'.
9171: '<td class="LC_left_item">'.
9172: '<input type="text" name="'.$type.'_namedusers" '.
9173: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
9174: '<td class="LC_right_item">'.
9175: '<span class="LC_nobreak">'.
9176: '<input type="text" name="'.$type.'_machines" '.
9177: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 9178: '</span></td></tr>'."\n";
1.69 raeburn 9179: }
9180: $$rowtotal += $rownum;
9181: return $datatable;
9182: }
9183:
9184: sub serverstatus_pages {
9185: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 9186: 'checksums','clusterstatus','certstatus','metadata_keywords',
9187: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
9188: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 9189: }
9190:
1.236 raeburn 9191: sub defaults_javascript {
9192: my ($settings) = @_;
1.354 raeburn 9193: return unless (ref($settings) eq 'HASH');
1.236 raeburn 9194: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
9195: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
9196: if ($maxnum eq '') {
9197: $maxnum = 0;
9198: }
9199: $maxnum ++;
1.249 raeburn 9200: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 9201: return <<"ENDSCRIPT";
9202: <script type="text/javascript">
9203: // <![CDATA[
9204: function reorderTypes(form,caller) {
9205: var changedVal;
9206: $jstext
9207: var newpos = 'addinststatus_pos';
9208: var current = new Array;
9209: var maxh = $maxnum;
9210: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
9211: var oldVal;
9212: if (caller == newpos) {
9213: changedVal = newitemVal;
9214: } else {
9215: var curritem = 'inststatus_pos_'+caller;
9216: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
9217: current[newitemVal] = newpos;
9218: }
9219: for (var i=0; i<inststatuses.length; i++) {
9220: if (inststatuses[i] != caller) {
9221: var elementName = 'inststatus_pos_'+inststatuses[i];
9222: if (form.elements[elementName]) {
9223: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
9224: current[currVal] = elementName;
9225: }
9226: }
9227: }
9228: for (var j=0; j<maxh; j++) {
9229: if (current[j] == undefined) {
9230: oldVal = j;
9231: }
9232: }
9233: if (oldVal < changedVal) {
9234: for (var k=oldVal+1; k<=changedVal ; k++) {
9235: var elementName = current[k];
9236: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
9237: }
9238: } else {
9239: for (var k=changedVal; k<oldVal; k++) {
9240: var elementName = current[k];
9241: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
9242: }
9243: }
9244: return;
9245: }
9246:
9247: // ]]>
9248: </script>
9249:
9250: ENDSCRIPT
9251: }
1.354 raeburn 9252: return;
9253: }
9254:
9255: sub passwords_javascript {
9256: my $intauthcheck = &mt('Warning: disallowing login for an authenticated user if the stored cost is less than the default will require a password reset by/for the user.');
9257: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
9258: &js_escape(\$intauthcheck);
9259: &js_escape(\$intauthcost);
9260: my $intauthjs = <<"ENDSCRIPT";
9261:
9262: function warnIntAuth(field) {
9263: if (field.name == 'intauth_check') {
9264: if (field.value == '2') {
9265: alert('$intauthcheck');
9266: }
9267: }
9268: if (field.name == 'intauth_cost') {
9269: field.value.replace(/\s/g,'');
9270: if (field.value != '') {
9271: var regexdigit=/^\\d+\$/;
9272: if (!regexdigit.test(field.value)) {
9273: alert('$intauthcost');
9274: }
9275: }
9276: }
9277: return;
9278: }
9279:
9280: ENDSCRIPT
9281: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 9282: }
9283:
1.49 raeburn 9284: sub coursecategories_javascript {
9285: my ($settings) = @_;
1.57 raeburn 9286: my ($output,$jstext,$cathash);
1.49 raeburn 9287: if (ref($settings) eq 'HASH') {
1.57 raeburn 9288: $cathash = $settings->{'cats'};
9289: }
9290: if (ref($cathash) eq 'HASH') {
1.49 raeburn 9291: my (@cats,@jsarray,%idx);
1.57 raeburn 9292: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 9293: if (@jsarray > 0) {
9294: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
9295: for (my $i=0; $i<@jsarray; $i++) {
9296: if (ref($jsarray[$i]) eq 'ARRAY') {
9297: my $catstr = join('","',@{$jsarray[$i]});
9298: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
9299: }
9300: }
9301: }
9302: } else {
9303: $jstext = ' var categories = Array(1);'."\n".
9304: ' categories[0] = Array("instcode_pos");'."\n";
9305: }
1.237 bisitz 9306: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
9307: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 9308: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 9309: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
9310: &js_escape(\$instcode_reserved);
9311: &js_escape(\$communities_reserved);
1.272 raeburn 9312: &js_escape(\$placement_reserved);
1.265 damieng 9313: &js_escape(\$choose_again);
1.49 raeburn 9314: $output = <<"ENDSCRIPT";
9315: <script type="text/javascript">
1.109 raeburn 9316: // <![CDATA[
1.49 raeburn 9317: function reorderCats(form,parent,item,idx) {
9318: var changedVal;
9319: $jstext
9320: var newpos = 'addcategory_pos';
9321: if (parent == '') {
9322: var has_instcode = 0;
9323: var maxtop = categories[idx].length;
9324: for (var j=0; j<maxtop; j++) {
9325: if (categories[idx][j] == 'instcode::0') {
9326: has_instcode == 1;
9327: }
9328: }
9329: if (has_instcode == 0) {
9330: categories[idx][maxtop] = 'instcode_pos';
9331: }
9332: } else {
9333: newpos += '_'+parent;
9334: }
9335: var maxh = 1 + categories[idx].length;
9336: var current = new Array;
9337: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
9338: if (item == newpos) {
9339: changedVal = newitemVal;
9340: } else {
9341: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
9342: current[newitemVal] = newpos;
9343: }
9344: for (var i=0; i<categories[idx].length; i++) {
9345: var elementName = categories[idx][i];
9346: if (elementName != item) {
9347: if (form.elements[elementName]) {
9348: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
9349: current[currVal] = elementName;
9350: }
9351: }
9352: }
9353: var oldVal;
9354: for (var j=0; j<maxh; j++) {
9355: if (current[j] == undefined) {
9356: oldVal = j;
9357: }
9358: }
9359: if (oldVal < changedVal) {
9360: for (var k=oldVal+1; k<=changedVal ; k++) {
9361: var elementName = current[k];
9362: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
9363: }
9364: } else {
9365: for (var k=changedVal; k<oldVal; k++) {
9366: var elementName = current[k];
9367: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
9368: }
9369: }
9370: return;
9371: }
1.120 raeburn 9372:
9373: function categoryCheck(form) {
9374: if (form.elements['addcategory_name'].value == 'instcode') {
9375: alert('$instcode_reserved\\n$choose_again');
9376: return false;
9377: }
9378: if (form.elements['addcategory_name'].value == 'communities') {
9379: alert('$communities_reserved\\n$choose_again');
9380: return false;
9381: }
1.272 raeburn 9382: if (form.elements['addcategory_name'].value == 'placement') {
9383: alert('$placement_reserved\\n$choose_again');
9384: return false;
9385: }
1.120 raeburn 9386: return true;
9387: }
9388:
1.109 raeburn 9389: // ]]>
1.49 raeburn 9390: </script>
9391:
9392: ENDSCRIPT
9393: return $output;
9394: }
9395:
1.48 raeburn 9396: sub initialize_categories {
9397: my ($itemcount) = @_;
1.120 raeburn 9398: my ($datatable,$css_class,$chgstr);
9399: my %default_names = (
9400: instcode => 'Official courses (with institutional codes)',
9401: communities => 'Communities',
1.272 raeburn 9402: placement => 'Placement Tests',
1.120 raeburn 9403: );
1.328 raeburn 9404: my %selnum = (
9405: instcode => '0',
9406: communities => '1',
9407: placement => '2',
9408: );
9409: my %selected;
1.272 raeburn 9410: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 9411: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 9412: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 9413: map { $selected{$selnum{$_}} = '' } keys(%selnum);
9414: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 9415: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 9416: .'<select name="'.$default.'_pos"'.$chgstr.'>'
9417: .'<option value="0"'.$selected{'0'}.'>1</option>'
9418: .'<option value="1"'.$selected{'1'}.'>2</option>'
9419: .'<option value="2"'.$selected{'2'}.'>3</option>'
9420: .'<option value="3">4</option></select> '
1.120 raeburn 9421: .$default_names{$default}
9422: .'</span></td><td><span class="LC_nobreak">'
9423: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
9424: .&mt('Display').'</label> <label>'
9425: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 9426: .'</label></span></td></tr>';
1.120 raeburn 9427: $itemcount ++;
9428: }
1.48 raeburn 9429: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 9430: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 9431: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 9432: .'<select name="addcategory_pos"'.$chgstr.'>'
9433: .'<option value="0">1</option>'
9434: .'<option value="1">2</option>'
1.328 raeburn 9435: .'<option value="2">3</option>'
9436: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 9437: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
9438: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
9439: .'</td></tr>';
1.48 raeburn 9440: return $datatable;
9441: }
9442:
9443: sub build_category_rows {
1.49 raeburn 9444: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
9445: my ($text,$name,$item,$chgstr);
1.48 raeburn 9446: if (ref($cats) eq 'ARRAY') {
9447: my $maxdepth = scalar(@{$cats});
9448: if (ref($cats->[$depth]) eq 'HASH') {
9449: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9450: my $numchildren = @{$cats->[$depth]{$parent}};
9451: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 9452: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 9453: my ($idxnum,$parent_name,$parent_item);
9454: my $higher = $depth - 1;
9455: if ($higher == 0) {
9456: $parent_name = &escape($parent).'::'.$higher;
9457: } else {
9458: if (ref($path) eq 'ARRAY') {
9459: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
9460: }
9461: }
9462: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 9463: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 9464: if ($j < $numchildren) {
1.48 raeburn 9465: $name = $cats->[$depth]{$parent}[$j];
9466: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 9467: $idxnum = $idx->{$item};
9468: } else {
9469: $name = $parent_name;
9470: $item = $parent_item;
1.48 raeburn 9471: }
1.49 raeburn 9472: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
9473: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 9474: for (my $i=0; $i<=$numchildren; $i++) {
9475: my $vpos = $i+1;
9476: my $selstr;
9477: if ($j == $i) {
9478: $selstr = ' selected="selected" ';
9479: }
9480: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
9481: }
9482: $text .= '</select> ';
9483: if ($j < $numchildren) {
9484: my $deeper = $depth+1;
9485: $text .= $name.' '
9486: .'<label><input type="checkbox" name="deletecategory" value="'
9487: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
9488: if(ref($path) eq 'ARRAY') {
9489: push(@{$path},$name);
1.49 raeburn 9490: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 9491: pop(@{$path});
9492: }
9493: } else {
1.330 raeburn 9494: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 9495: if ($j == $numchildren) {
9496: $text .= $name;
9497: } else {
9498: $text .= $item;
9499: }
9500: $text .= '" value="" />';
9501: }
9502: $text .= '</td></tr>';
9503: }
9504: $text .= '</table></td>';
9505: } else {
9506: my $higher = $depth-1;
9507: if ($higher == 0) {
9508: $name = &escape($parent).'::'.$higher;
9509: } else {
9510: if (ref($path) eq 'ARRAY') {
9511: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
9512: }
9513: }
9514: my $colspan;
9515: if ($parent ne 'instcode') {
9516: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 9517: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 9518: }
9519: }
9520: }
9521: }
9522: return $text;
9523: }
9524:
1.33 raeburn 9525: sub modifiable_userdata_row {
1.305 raeburn 9526: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 9527: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 9528: my ($role,$rolename,$statustype);
9529: $role = $item;
1.224 raeburn 9530: if ($context eq 'cancreate') {
1.305 raeburn 9531: if ($item =~ /^(emailusername)_(.+)$/) {
9532: $role = $1;
9533: $statustype = $2;
1.228 raeburn 9534: if (ref($usertypes) eq 'HASH') {
9535: if ($usertypes->{$statustype}) {
9536: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
9537: } else {
9538: $rolename = &mt('Data provided by user');
9539: }
9540: }
1.224 raeburn 9541: }
9542: } elsif ($context eq 'selfcreate') {
1.63 raeburn 9543: if (ref($usertypes) eq 'HASH') {
9544: $rolename = $usertypes->{$role};
9545: } else {
9546: $rolename = $role;
9547: }
1.325 raeburn 9548: } elsif ($context eq 'lti') {
9549: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 9550: } elsif ($context eq 'privacy') {
9551: $rolename = $itemdesc;
1.33 raeburn 9552: } else {
1.63 raeburn 9553: if ($role eq 'cr') {
9554: $rolename = &mt('Custom role');
9555: } else {
9556: $rolename = &Apache::lonnet::plaintext($role);
9557: }
1.33 raeburn 9558: }
1.224 raeburn 9559: my (@fields,%fieldtitles);
9560: if (ref($fieldsref) eq 'ARRAY') {
9561: @fields = @{$fieldsref};
9562: } else {
9563: @fields = ('lastname','firstname','middlename','generation',
9564: 'permanentemail','id');
9565: }
9566: if ((ref($titlesref) eq 'HASH')) {
9567: %fieldtitles = %{$titlesref};
9568: } else {
9569: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9570: }
1.33 raeburn 9571: my $output;
1.305 raeburn 9572: my $css_class;
9573: if ($rowcount%2) {
9574: $css_class = 'LC_odd_row';
9575: }
9576: if ($customcss) {
9577: $css_class .= " $customcss";
9578: }
9579: $css_class =~ s/^\s+//;
9580: if ($css_class) {
9581: $css_class = ' class="'.$css_class.'"';
9582: }
9583: if ($rowstyle) {
9584: $css_class .= ' style="'.$rowstyle.'"';
9585: }
9586: if ($rowid) {
9587: $rowid = ' id="'.$rowid.'"';
9588: }
9589: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 9590: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
9591: '<td class="LC_left_item" colspan="2"><table>';
9592: my $rem;
9593: my %checks;
1.325 raeburn 9594: my %current;
1.33 raeburn 9595: if (ref($settings) eq 'HASH') {
1.325 raeburn 9596: my $hashref;
9597: if ($context eq 'lti') {
9598: if (ref($settings) eq 'HASH') {
9599: $hashref = $settings->{'instdata'};
9600: }
1.357 raeburn 9601: } elsif ($context eq 'privacy') {
9602: my ($key,$inner) = split(/_/,$role);
9603: if (ref($settings) eq 'HASH') {
9604: if (ref($settings->{$key}) eq 'HASH') {
9605: $hashref = $settings->{$key}->{$inner};
9606: }
9607: }
1.325 raeburn 9608: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 9609: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 9610: $hashref = $settings->{'lti_instdata'};
9611: }
9612: if ($role eq 'emailusername') {
9613: if ($statustype) {
9614: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
9615: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 9616: }
1.325 raeburn 9617: }
9618: }
9619: }
9620: if (ref($hashref) eq 'HASH') {
9621: foreach my $field (@fields) {
9622: if ($hashref->{$field}) {
9623: if ($role eq 'emailusername') {
9624: $checks{$field} = $hashref->{$field};
9625: } else {
9626: $checks{$field} = ' checked="checked" ';
1.33 raeburn 9627: }
9628: }
9629: }
9630: }
9631: }
1.305 raeburn 9632:
9633: my $total = scalar(@fields);
9634: for (my $i=0; $i<$total; $i++) {
9635: $rem = $i%($numinrow);
1.33 raeburn 9636: if ($rem == 0) {
9637: if ($i > 0) {
9638: $output .= '</tr>';
9639: }
9640: $output .= '<tr>';
9641: }
9642: my $check = ' ';
1.228 raeburn 9643: unless ($role eq 'emailusername') {
9644: if (exists($checks{$fields[$i]})) {
1.354 raeburn 9645: $check = $checks{$fields[$i]};
1.357 raeburn 9646: } elsif ($context eq 'privacy') {
9647: if ($role =~ /^priv_(domain|course)$/) {
9648: if (ref($settings) ne 'HASH') {
9649: $check = ' checked="checked" ';
9650: }
9651: } elsif ($role =~ /^priv_(author|community)$/) {
9652: if (ref($settings) ne 'HASH') {
9653: unless ($fields[$i] eq 'id') {
9654: $check = ' checked="checked" ';
9655: }
9656: }
9657: } elsif ($role =~ /^(unpriv|othdom)_/) {
9658: if (ref($settings) ne 'HASH') {
9659: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
9660: $check = ' checked="checked" ';
9661: }
9662: }
9663: }
1.325 raeburn 9664: } elsif ($context ne 'lti') {
1.228 raeburn 9665: if ($role eq 'st') {
9666: if (ref($settings) ne 'HASH') {
9667: $check = ' checked="checked" ';
9668: }
1.33 raeburn 9669: }
9670: }
9671: }
9672: $output .= '<td class="LC_left_item">'.
1.228 raeburn 9673: '<span class="LC_nobreak">';
1.325 raeburn 9674: my $prefix = 'canmodify';
1.228 raeburn 9675: if ($role eq 'emailusername') {
9676: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
9677: $checks{$fields[$i]} = 'omit';
9678: }
9679: foreach my $option ('required','optional','omit') {
9680: my $checked='';
9681: if ($checks{$fields[$i]} eq $option) {
9682: $checked='checked="checked" ';
9683: }
9684: $output .= '<label>'.
1.325 raeburn 9685: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 9686: &mt($option).'</label>'.(' ' x2);
9687: }
9688: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
9689: } else {
1.325 raeburn 9690: if ($context eq 'lti') {
9691: $prefix = 'lti';
1.357 raeburn 9692: } elsif ($context eq 'privacy') {
9693: $prefix = 'privacy';
1.325 raeburn 9694: }
1.228 raeburn 9695: $output .= '<label>'.
1.325 raeburn 9696: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 9697: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
9698: '</label>';
9699: }
9700: $output .= '</span></td>';
1.33 raeburn 9701: }
1.305 raeburn 9702: $rem = $total%$numinrow;
9703: my $colsleft;
9704: if ($rem) {
9705: $colsleft = $numinrow - $rem;
9706: }
9707: if ($colsleft > 1) {
1.33 raeburn 9708: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9709: ' </td>';
9710: } elsif ($colsleft == 1) {
9711: $output .= '<td class="LC_left_item"> </td>';
9712: }
9713: $output .= '</tr></table></td></tr>';
9714: return $output;
9715: }
1.28 raeburn 9716:
1.93 raeburn 9717: sub insttypes_row {
1.305 raeburn 9718: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
9719: $customcss,$rowstyle) = @_;
1.93 raeburn 9720: my %lt = &Apache::lonlocal::texthash (
9721: cansearch => 'Users allowed to search',
9722: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 9723: lockablenames => 'User preference to lock name',
1.305 raeburn 9724: selfassign => 'Self-reportable affiliations',
1.315 raeburn 9725: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 9726: );
9727: my $showdom;
9728: if ($context eq 'cansearch') {
9729: $showdom = ' ('.$dom.')';
9730: }
1.165 raeburn 9731: my $class = 'LC_left_item';
9732: if ($context eq 'statustocreate') {
9733: $class = 'LC_right_item';
9734: }
1.305 raeburn 9735: my $css_class;
9736: if ($$rowtotal%2) {
9737: $css_class = 'LC_odd_row';
9738: }
9739: if ($customcss) {
9740: $css_class .= ' '.$customcss;
9741: }
9742: $css_class =~ s/^\s+//;
9743: if ($css_class) {
9744: $css_class = ' class="'.$css_class.'"';
9745: }
9746: if ($rowstyle) {
9747: $css_class .= ' style="'.$rowstyle.'"';
9748: }
9749: if ($onclick) {
9750: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 9751: }
9752: my $output = '<tr'.$css_class.'>'.
9753: '<td>'.$lt{$context}.$showdom.
9754: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 9755: my $rem;
9756: if (ref($types) eq 'ARRAY') {
9757: for (my $i=0; $i<@{$types}; $i++) {
9758: if (defined($usertypes->{$types->[$i]})) {
9759: my $rem = $i%($numinrow);
9760: if ($rem == 0) {
9761: if ($i > 0) {
9762: $output .= '</tr>';
9763: }
9764: $output .= '<tr>';
1.23 raeburn 9765: }
1.26 raeburn 9766: my $check = ' ';
1.99 raeburn 9767: if (ref($settings) eq 'HASH') {
9768: if (ref($settings->{$context}) eq 'ARRAY') {
9769: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
9770: $check = ' checked="checked" ';
9771: }
1.315 raeburn 9772: } elsif (ref($settings->{$context}) eq 'HASH') {
9773: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
9774: $check = ' checked="checked" ';
9775: }
1.99 raeburn 9776: } elsif ($context eq 'statustocreate') {
1.26 raeburn 9777: $check = ' checked="checked" ';
9778: }
1.23 raeburn 9779: }
1.26 raeburn 9780: $output .= '<td class="LC_left_item">'.
9781: '<span class="LC_nobreak"><label>'.
1.93 raeburn 9782: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 9783: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 9784: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 9785: }
9786: }
1.26 raeburn 9787: $rem = @{$types}%($numinrow);
1.23 raeburn 9788: }
9789: my $colsleft = $numinrow - $rem;
1.315 raeburn 9790: if ($context eq 'overrides') {
9791: if ($colsleft > 1) {
9792: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9793: } else {
9794: $output .= '<td class="LC_left_item">';
9795: }
9796: $output .= ' ';
1.23 raeburn 9797: } else {
1.334 raeburn 9798: if ($rem == 0) {
1.315 raeburn 9799: $output .= '<tr>';
9800: }
9801: if ($colsleft > 1) {
9802: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9803: } else {
9804: $output .= '<td class="LC_left_item">';
9805: }
9806: my $defcheck = ' ';
9807: if (ref($settings) eq 'HASH') {
9808: if (ref($settings->{$context}) eq 'ARRAY') {
9809: if (grep(/^default$/,@{$settings->{$context}})) {
9810: $defcheck = ' checked="checked" ';
9811: }
9812: } elsif ($context eq 'statustocreate') {
1.99 raeburn 9813: $defcheck = ' checked="checked" ';
9814: }
1.26 raeburn 9815: }
1.315 raeburn 9816: $output .= '<span class="LC_nobreak"><label>'.
9817: '<input type="checkbox" name="'.$context.'" '.
9818: 'value="default"'.$defcheck.$onclick.' />'.
9819: $othertitle.'</label></span>';
1.23 raeburn 9820: }
1.315 raeburn 9821: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 9822: return $output;
1.23 raeburn 9823: }
9824:
9825: sub sorted_searchtitles {
9826: my %searchtitles = &Apache::lonlocal::texthash(
9827: 'uname' => 'username',
9828: 'lastname' => 'last name',
9829: 'lastfirst' => 'last name, first name',
9830: );
9831: my @titleorder = ('uname','lastname','lastfirst');
9832: return (\%searchtitles,\@titleorder);
9833: }
9834:
1.25 raeburn 9835: sub sorted_searchtypes {
9836: my %srchtypes_desc = (
9837: exact => 'is exact match',
9838: contains => 'contains ..',
9839: begins => 'begins with ..',
9840: );
9841: my @srchtypeorder = ('exact','begins','contains');
9842: return (\%srchtypes_desc,\@srchtypeorder);
9843: }
9844:
1.3 raeburn 9845: sub usertype_update_row {
9846: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
9847: my $datatable;
9848: my $numinrow = 4;
9849: foreach my $type (@{$types}) {
9850: if (defined($usertypes->{$type})) {
9851: $$rownums ++;
9852: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
9853: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
9854: '</td><td class="LC_left_item"><table>';
9855: for (my $i=0; $i<@{$fields}; $i++) {
9856: my $rem = $i%($numinrow);
9857: if ($rem == 0) {
9858: if ($i > 0) {
9859: $datatable .= '</tr>';
9860: }
9861: $datatable .= '<tr>';
9862: }
9863: my $check = ' ';
1.39 raeburn 9864: if (ref($settings) eq 'HASH') {
9865: if (ref($settings->{'fields'}) eq 'HASH') {
9866: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
9867: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
9868: $check = ' checked="checked" ';
9869: }
1.3 raeburn 9870: }
9871: }
9872: }
9873:
9874: if ($i == @{$fields}-1) {
9875: my $colsleft = $numinrow - $rem;
9876: if ($colsleft > 1) {
9877: $datatable .= '<td colspan="'.$colsleft.'">';
9878: } else {
9879: $datatable .= '<td>';
9880: }
9881: } else {
9882: $datatable .= '<td>';
9883: }
1.8 raeburn 9884: $datatable .= '<span class="LC_nobreak"><label>'.
9885: '<input type="checkbox" name="updateable_'.$type.
9886: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
9887: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 9888: }
9889: $datatable .= '</tr></table></td></tr>';
9890: }
9891: }
9892: return $datatable;
1.1 raeburn 9893: }
9894:
9895: sub modify_login {
1.205 raeburn 9896: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 9897: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
9898: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
9899: %title = ( coursecatalog => 'Display course catalog',
9900: adminmail => 'Display administrator E-mail address',
1.188 raeburn 9901: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 9902: newuser => 'Link for visitors to create a user account',
9903: loginheader => 'Log-in box header');
9904: @offon = ('off','on');
1.112 raeburn 9905: if (ref($domconfig{login}) eq 'HASH') {
9906: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
9907: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
9908: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
9909: }
9910: }
9911: }
1.9 raeburn 9912: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
9913: \%domconfig,\%loginhash);
1.188 raeburn 9914: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9915: foreach my $item (@toggles) {
9916: $loginhash{login}{$item} = $env{'form.'.$item};
9917: }
1.41 raeburn 9918: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 9919: if (ref($colchanges{'login'}) eq 'HASH') {
9920: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
9921: \%loginhash);
9922: }
1.110 raeburn 9923:
1.149 raeburn 9924: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 9925: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 9926: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 9927: if (keys(%servers) > 1) {
9928: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 9929: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
9930: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
9931: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
9932: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
9933: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
9934: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9935: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9936: $changes{'loginvia'}{$lonhost} = 1;
9937: } else {
9938: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
9939: $changes{'loginvia'}{$lonhost} = 1;
9940: }
9941: } else {
9942: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9943: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9944: $changes{'loginvia'}{$lonhost} = 1;
9945: }
9946: }
9947: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
9948: foreach my $item (@loginvia_attribs) {
9949: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
9950: }
9951: } else {
9952: foreach my $item (@loginvia_attribs) {
9953: my $new = $env{'form.'.$lonhost.'_'.$item};
9954: if (($item eq 'serverpath') && ($new eq 'custom')) {
9955: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
9956: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9957: $new = '/';
9958: }
9959: }
9960: if (($item eq 'custompath') &&
9961: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9962: $new = '';
9963: }
9964: if ($new ne $curr_loginvia{$lonhost}{$item}) {
9965: $changes{'loginvia'}{$lonhost} = 1;
9966: }
9967: if ($item eq 'exempt') {
1.256 raeburn 9968: $new = &check_exempt_addresses($new);
1.128 raeburn 9969: }
9970: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9971: }
9972: }
1.112 raeburn 9973: } else {
1.128 raeburn 9974: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9975: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 9976: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 9977: foreach my $item (@loginvia_attribs) {
9978: my $new = $env{'form.'.$lonhost.'_'.$item};
9979: if (($item eq 'serverpath') && ($new eq 'custom')) {
9980: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9981: $new = '/';
9982: }
9983: }
9984: if (($item eq 'custompath') &&
9985: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9986: $new = '';
9987: }
9988: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9989: }
1.110 raeburn 9990: }
9991: }
9992: }
9993: }
1.119 raeburn 9994:
1.168 raeburn 9995: my $servadm = $r->dir_config('lonAdmEMail');
9996: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
9997: if (ref($domconfig{'login'}) eq 'HASH') {
9998: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
9999: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
10000: if ($lang eq 'nolang') {
10001: push(@currlangs,$lang);
10002: } elsif (defined($langchoices{$lang})) {
10003: push(@currlangs,$lang);
10004: } else {
10005: next;
10006: }
10007: }
10008: }
10009: }
10010: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
10011: if (@currlangs > 0) {
10012: foreach my $lang (@currlangs) {
10013: if (grep(/^\Q$lang\E$/,@delurls)) {
10014: $changes{'helpurl'}{$lang} = 1;
10015: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
10016: $changes{'helpurl'}{$lang} = 1;
10017: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
10018: push(@newlangs,$lang);
10019: } else {
10020: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
10021: }
10022: }
10023: }
10024: unless (grep(/^nolang$/,@currlangs)) {
10025: if ($env{'form.loginhelpurl_nolang.filename'}) {
10026: $changes{'helpurl'}{'nolang'} = 1;
10027: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
10028: push(@newlangs,'nolang');
10029: }
10030: }
10031: if ($env{'form.loginhelpurl_add_lang'}) {
10032: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
10033: ($env{'form.loginhelpurl_add_file.filename'})) {
10034: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
10035: $addedfile = $env{'form.loginhelpurl_add_lang'};
10036: }
10037: }
10038: if ((@newlangs > 0) || ($addedfile)) {
10039: my $error;
10040: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10041: if ($configuserok eq 'ok') {
10042: if ($switchserver) {
10043: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
10044: } elsif ($author_ok eq 'ok') {
10045: my @allnew = @newlangs;
10046: if ($addedfile ne '') {
10047: push(@allnew,$addedfile);
10048: }
10049: foreach my $lang (@allnew) {
10050: my $formelem = 'loginhelpurl_'.$lang;
10051: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
10052: $formelem = 'loginhelpurl_add_file';
10053: }
10054: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
10055: "help/$lang",'','',$newfile{$lang});
10056: if ($result eq 'ok') {
10057: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
10058: $changes{'helpurl'}{$lang} = 1;
10059: } else {
10060: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
10061: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 10062: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 10063: (!grep(/^\Q$lang\E$/,@delurls))) {
10064: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
10065: }
10066: }
10067: }
10068: } else {
10069: $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);
10070: }
10071: } else {
10072: $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);
10073: }
10074: if ($error) {
10075: &Apache::lonnet::logthis($error);
10076: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10077: }
10078: }
1.256 raeburn 10079:
10080: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
10081: if (ref($domconfig{'login'}) eq 'HASH') {
10082: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
10083: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
10084: if ($domservers{$lonhost}) {
10085: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
10086: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 10087: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 10088: }
10089: }
10090: }
10091: }
10092: }
10093: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
10094: foreach my $lonhost (sort(keys(%domservers))) {
10095: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
10096: $changes{'headtag'}{$lonhost} = 1;
10097: } else {
10098: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
10099: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
10100: }
10101: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
10102: push(@newhosts,$lonhost);
10103: } elsif ($currheadtagurls{$lonhost}) {
10104: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
10105: if ($currexempt{$lonhost}) {
1.289 raeburn 10106: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 10107: $changes{'headtag'}{$lonhost} = 1;
10108: }
10109: } elsif ($possexempt{$lonhost}) {
10110: $changes{'headtag'}{$lonhost} = 1;
10111: }
10112: if ($possexempt{$lonhost}) {
10113: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
10114: }
10115: }
10116: }
10117: }
10118: if (@newhosts) {
10119: my $error;
10120: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10121: if ($configuserok eq 'ok') {
10122: if ($switchserver) {
10123: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
10124: } elsif ($author_ok eq 'ok') {
10125: foreach my $lonhost (@newhosts) {
10126: my $formelem = 'loginheadtag_'.$lonhost;
10127: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
10128: "login/headtag/$lonhost",'','',
10129: $env{'form.loginheadtag_'.$lonhost.'.filename'});
10130: if ($result eq 'ok') {
10131: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
10132: $changes{'headtag'}{$lonhost} = 1;
10133: if ($possexempt{$lonhost}) {
10134: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
10135: }
10136: } else {
10137: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
10138: $newheadtagurls{$lonhost},$result);
10139: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
10140: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
10141: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
10142: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
10143: }
10144: }
10145: }
10146: } else {
10147: $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);
10148: }
10149: } else {
10150: $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);
10151: }
10152: if ($error) {
10153: &Apache::lonnet::logthis($error);
10154: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10155: }
10156: }
1.169 raeburn 10157: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 10158:
10159: my $defaulthelpfile = '/adm/loginproblems.html';
10160: my $defaulttext = &mt('Default in use');
10161:
1.1 raeburn 10162: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
10163: $dom);
10164: if ($putresult eq 'ok') {
1.188 raeburn 10165: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 10166: my %defaultchecked = (
10167: 'coursecatalog' => 'on',
1.188 raeburn 10168: 'helpdesk' => 'on',
1.42 raeburn 10169: 'adminmail' => 'off',
1.43 raeburn 10170: 'newuser' => 'off',
1.42 raeburn 10171: );
1.55 raeburn 10172: if (ref($domconfig{'login'}) eq 'HASH') {
10173: foreach my $item (@toggles) {
10174: if ($defaultchecked{$item} eq 'on') {
10175: if (($domconfig{'login'}{$item} eq '0') &&
10176: ($env{'form.'.$item} eq '1')) {
10177: $changes{$item} = 1;
10178: } elsif (($domconfig{'login'}{$item} eq '' ||
10179: $domconfig{'login'}{$item} eq '1') &&
10180: ($env{'form.'.$item} eq '0')) {
10181: $changes{$item} = 1;
10182: }
10183: } elsif ($defaultchecked{$item} eq 'off') {
10184: if (($domconfig{'login'}{$item} eq '1') &&
10185: ($env{'form.'.$item} eq '0')) {
10186: $changes{$item} = 1;
10187: } elsif (($domconfig{'login'}{$item} eq '' ||
10188: $domconfig{'login'}{$item} eq '0') &&
10189: ($env{'form.'.$item} eq '1')) {
10190: $changes{$item} = 1;
10191: }
1.42 raeburn 10192: }
10193: }
1.41 raeburn 10194: }
1.6 raeburn 10195: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 10196: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10197: if (ref($lastactref) eq 'HASH') {
10198: $lastactref->{'domainconfig'} = 1;
10199: }
1.1 raeburn 10200: $resulttext = &mt('Changes made:').'<ul>';
10201: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 10202: if ($item eq 'loginvia') {
1.112 raeburn 10203: if (ref($changes{$item}) eq 'HASH') {
10204: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
10205: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 10206: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
10207: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
10208: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
10209: $protocol = 'http' if ($protocol ne 'https');
10210: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
10211:
10212: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
10213: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
10214: } else {
10215: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
10216: }
10217: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
10218: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
10219: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
10220: }
10221: $resulttext .= '</li>';
10222: } else {
10223: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
10224: }
1.112 raeburn 10225: } else {
1.128 raeburn 10226: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 10227: }
10228: }
1.128 raeburn 10229: $resulttext .= '</ul></li>';
1.112 raeburn 10230: }
1.168 raeburn 10231: } elsif ($item eq 'helpurl') {
10232: if (ref($changes{$item}) eq 'HASH') {
10233: foreach my $lang (sort(keys(%{$changes{$item}}))) {
10234: if (grep(/^\Q$lang\E$/,@delurls)) {
10235: my ($chg,$link);
10236: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
10237: if ($lang eq 'nolang') {
10238: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
10239: } else {
10240: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
10241: }
10242: $resulttext .= '<li>'.$chg.'</li>';
10243: } else {
10244: my $chg;
10245: if ($lang eq 'nolang') {
10246: $chg = &mt('custom log-in help file for no preferred language');
10247: } else {
10248: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
10249: }
10250: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
10251: $loginhash{'login'}{'helpurl'}{$lang}.
10252: '?inhibitmenu=yes',$chg,600,500).
10253: '</li>';
10254: }
10255: }
10256: }
1.256 raeburn 10257: } elsif ($item eq 'headtag') {
10258: if (ref($changes{$item}) eq 'HASH') {
10259: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
10260: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
10261: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
10262: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
10263: $resulttext .= '<li><a href="'.
10264: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
10265: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
10266: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
10267: if ($possexempt{$lonhost}) {
10268: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
10269: } else {
10270: $resulttext .= &mt('included for any client IP');
10271: }
10272: $resulttext .= '</li>';
10273: }
10274: }
10275: }
1.169 raeburn 10276: } elsif ($item eq 'captcha') {
10277: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 10278: my $chgtxt;
1.169 raeburn 10279: if ($loginhash{'login'}{$item} eq 'notused') {
10280: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
10281: } else {
10282: my %captchas = &captcha_phrases();
10283: if ($captchas{$loginhash{'login'}{$item}}) {
10284: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
10285: } else {
10286: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
10287: }
10288: }
10289: $resulttext .= '<li>'.$chgtxt.'</li>';
10290: }
10291: } elsif ($item eq 'recaptchakeys') {
10292: if (ref($loginhash{'login'}) eq 'HASH') {
10293: my ($privkey,$pubkey);
10294: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
10295: $pubkey = $loginhash{'login'}{$item}{'public'};
10296: $privkey = $loginhash{'login'}{$item}{'private'};
10297: }
10298: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
10299: if (!$pubkey) {
10300: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
10301: } else {
10302: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
10303: }
10304: if (!$privkey) {
10305: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
10306: } else {
1.251 raeburn 10307: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 10308: }
10309: $chgtxt .= '</ul>';
10310: $resulttext .= '<li>'.$chgtxt.'</li>';
10311: }
1.269 raeburn 10312: } elsif ($item eq 'recaptchaversion') {
10313: if (ref($loginhash{'login'}) eq 'HASH') {
10314: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 10315: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 10316: '</li>';
10317: }
10318: }
1.41 raeburn 10319: } else {
10320: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
10321: }
1.1 raeburn 10322: }
1.6 raeburn 10323: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 10324: } else {
10325: $resulttext = &mt('No changes made to log-in page settings');
10326: }
10327: } else {
1.11 albertel 10328: $resulttext = '<span class="LC_error">'.
10329: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10330: }
1.6 raeburn 10331: if ($errors) {
1.9 raeburn 10332: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 10333: $errors.'</ul>';
10334: }
10335: return $resulttext;
10336: }
10337:
1.256 raeburn 10338: sub check_exempt_addresses {
10339: my ($iplist) = @_;
10340: $iplist =~ s/^\s+//;
10341: $iplist =~ s/\s+$//;
10342: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
10343: my (@okips,$new);
10344: foreach my $ip (@poss_ips) {
10345: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
10346: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
10347: push(@okips,$ip);
10348: }
10349: }
10350: }
10351: if (@okips > 0) {
10352: $new = join(',',@okips);
10353: } else {
10354: $new = '';
10355: }
10356: return $new;
10357: }
10358:
1.6 raeburn 10359: sub color_font_choices {
10360: my %choices =
10361: &Apache::lonlocal::texthash (
10362: img => "Header",
10363: bgs => "Background colors",
10364: links => "Link colors",
1.55 raeburn 10365: images => "Images",
1.6 raeburn 10366: font => "Font color",
1.201 raeburn 10367: fontmenu => "Font menu",
1.76 raeburn 10368: pgbg => "Page",
1.6 raeburn 10369: tabbg => "Header",
10370: sidebg => "Border",
10371: link => "Link",
10372: alink => "Active link",
10373: vlink => "Visited link",
10374: );
10375: return %choices;
10376: }
10377:
10378: sub modify_rolecolors {
1.205 raeburn 10379: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 10380: my ($resulttext,%rolehash);
10381: $rolehash{'rolecolors'} = {};
1.55 raeburn 10382: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
10383: if ($domconfig{'rolecolors'} eq '') {
10384: $domconfig{'rolecolors'} = {};
10385: }
10386: }
1.9 raeburn 10387: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 10388: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
10389: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
10390: $dom);
10391: if ($putresult eq 'ok') {
10392: if (keys(%changes) > 0) {
1.41 raeburn 10393: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10394: if (ref($lastactref) eq 'HASH') {
10395: $lastactref->{'domainconfig'} = 1;
10396: }
1.6 raeburn 10397: $resulttext = &display_colorchgs($dom,\%changes,$roles,
10398: $rolehash{'rolecolors'});
10399: } else {
10400: $resulttext = &mt('No changes made to default color schemes');
10401: }
10402: } else {
1.11 albertel 10403: $resulttext = '<span class="LC_error">'.
10404: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 10405: }
10406: if ($errors) {
10407: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10408: $errors.'</ul>';
10409: }
10410: return $resulttext;
10411: }
10412:
10413: sub modify_colors {
1.9 raeburn 10414: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 10415: my (%changes,%choices);
1.51 raeburn 10416: my @bgs;
1.6 raeburn 10417: my @links = ('link','alink','vlink');
1.41 raeburn 10418: my @logintext;
1.6 raeburn 10419: my @images;
10420: my $servadm = $r->dir_config('lonAdmEMail');
10421: my $errors;
1.200 raeburn 10422: my %defaults;
1.6 raeburn 10423: foreach my $role (@{$roles}) {
10424: if ($role eq 'login') {
1.12 raeburn 10425: %choices = &login_choices();
1.41 raeburn 10426: @logintext = ('textcol','bgcol');
1.12 raeburn 10427: } else {
10428: %choices = &color_font_choices();
10429: }
10430: if ($role eq 'login') {
1.41 raeburn 10431: @images = ('img','logo','domlogo','login');
1.51 raeburn 10432: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 10433: } else {
10434: @images = ('img');
1.200 raeburn 10435: @bgs = ('pgbg','tabbg','sidebg');
10436: }
10437: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
10438: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
10439: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
10440: }
10441: if ($role eq 'login') {
10442: foreach my $item (@logintext) {
1.234 raeburn 10443: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10444: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10445: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10446: }
10447: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 10448: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10449: }
10450: }
10451: } else {
1.234 raeburn 10452: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
10453: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
10454: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
10455: }
10456: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 10457: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
10458: }
1.6 raeburn 10459: }
1.200 raeburn 10460: foreach my $item (@bgs) {
1.234 raeburn 10461: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10462: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10463: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10464: }
10465: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 10466: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10467: }
10468: }
10469: foreach my $item (@links) {
1.234 raeburn 10470: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10471: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10472: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10473: }
10474: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 10475: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10476: }
1.6 raeburn 10477: }
1.46 raeburn 10478: my ($configuserok,$author_ok,$switchserver) =
10479: &config_check($dom,$confname,$servadm);
1.9 raeburn 10480: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 10481: if (ref($domconfig->{$role}) ne 'HASH') {
10482: $domconfig->{$role} = {};
10483: }
1.8 raeburn 10484: foreach my $img (@images) {
1.70 raeburn 10485: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
10486: if (defined($env{'form.login_showlogo_'.$img})) {
10487: $confhash->{$role}{'showlogo'}{$img} = 1;
10488: } else {
10489: $confhash->{$role}{'showlogo'}{$img} = 0;
10490: }
10491: }
1.18 albertel 10492: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
10493: && !defined($domconfig->{$role}{$img})
10494: && !$env{'form.'.$role.'_del_'.$img}
10495: && $env{'form.'.$role.'_import_'.$img}) {
10496: # import the old configured image from the .tab setting
10497: # if they haven't provided a new one
10498: $domconfig->{$role}{$img} =
10499: $env{'form.'.$role.'_import_'.$img};
10500: }
1.6 raeburn 10501: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 10502: my $error;
1.6 raeburn 10503: if ($configuserok eq 'ok') {
1.9 raeburn 10504: if ($switchserver) {
1.12 raeburn 10505: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 10506: } else {
10507: if ($author_ok eq 'ok') {
10508: my ($result,$logourl) =
10509: &publishlogo($r,'upload',$role.'_'.$img,
10510: $dom,$confname,$img,$width,$height);
10511: if ($result eq 'ok') {
10512: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 10513: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 10514: } else {
1.12 raeburn 10515: $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 10516: }
10517: } else {
1.46 raeburn 10518: $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 10519: }
10520: }
10521: } else {
1.46 raeburn 10522: $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 10523: }
10524: if ($error) {
1.8 raeburn 10525: &Apache::lonnet::logthis($error);
1.11 albertel 10526: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 10527: }
10528: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 10529: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
10530: my $error;
10531: if ($configuserok eq 'ok') {
10532: # is confname an author?
10533: if ($switchserver eq '') {
10534: if ($author_ok eq 'ok') {
10535: my ($result,$logourl) =
10536: &publishlogo($r,'copy',$domconfig->{$role}{$img},
10537: $dom,$confname,$img,$width,$height);
10538: if ($result eq 'ok') {
10539: $confhash->{$role}{$img} = $logourl;
1.18 albertel 10540: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 10541: }
10542: }
10543: }
10544: }
1.6 raeburn 10545: }
10546: }
10547: }
10548: if (ref($domconfig) eq 'HASH') {
10549: if (ref($domconfig->{$role}) eq 'HASH') {
10550: foreach my $img (@images) {
10551: if ($domconfig->{$role}{$img} ne '') {
10552: if ($env{'form.'.$role.'_del_'.$img}) {
10553: $confhash->{$role}{$img} = '';
1.12 raeburn 10554: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 10555: } else {
1.9 raeburn 10556: if ($confhash->{$role}{$img} eq '') {
10557: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
10558: }
1.6 raeburn 10559: }
10560: } else {
10561: if ($env{'form.'.$role.'_del_'.$img}) {
10562: $confhash->{$role}{$img} = '';
1.12 raeburn 10563: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 10564: }
10565: }
1.70 raeburn 10566: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
10567: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
10568: if ($confhash->{$role}{'showlogo'}{$img} ne
10569: $domconfig->{$role}{'showlogo'}{$img}) {
10570: $changes{$role}{'showlogo'}{$img} = 1;
10571: }
10572: } else {
10573: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
10574: $changes{$role}{'showlogo'}{$img} = 1;
10575: }
10576: }
10577: }
10578: }
1.6 raeburn 10579: if ($domconfig->{$role}{'font'} ne '') {
10580: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
10581: $changes{$role}{'font'} = 1;
10582: }
10583: } else {
10584: if ($confhash->{$role}{'font'}) {
10585: $changes{$role}{'font'} = 1;
10586: }
10587: }
1.107 raeburn 10588: if ($role ne 'login') {
10589: if ($domconfig->{$role}{'fontmenu'} ne '') {
10590: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
10591: $changes{$role}{'fontmenu'} = 1;
10592: }
10593: } else {
10594: if ($confhash->{$role}{'fontmenu'}) {
10595: $changes{$role}{'fontmenu'} = 1;
10596: }
1.97 tempelho 10597: }
10598: }
1.6 raeburn 10599: foreach my $item (@bgs) {
10600: if ($domconfig->{$role}{$item} ne '') {
10601: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10602: $changes{$role}{'bgs'}{$item} = 1;
10603: }
10604: } else {
10605: if ($confhash->{$role}{$item}) {
10606: $changes{$role}{'bgs'}{$item} = 1;
10607: }
10608: }
10609: }
10610: foreach my $item (@links) {
10611: if ($domconfig->{$role}{$item} ne '') {
10612: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10613: $changes{$role}{'links'}{$item} = 1;
10614: }
10615: } else {
10616: if ($confhash->{$role}{$item}) {
10617: $changes{$role}{'links'}{$item} = 1;
10618: }
10619: }
10620: }
1.41 raeburn 10621: foreach my $item (@logintext) {
10622: if ($domconfig->{$role}{$item} ne '') {
10623: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10624: $changes{$role}{'logintext'}{$item} = 1;
10625: }
10626: } else {
10627: if ($confhash->{$role}{$item}) {
10628: $changes{$role}{'logintext'}{$item} = 1;
10629: }
10630: }
10631: }
1.6 raeburn 10632: } else {
10633: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 10634: \@logintext,$confhash,\%changes);
1.6 raeburn 10635: }
10636: } else {
10637: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 10638: \@logintext,$confhash,\%changes);
1.6 raeburn 10639: }
10640: }
10641: return ($errors,%changes);
10642: }
10643:
1.46 raeburn 10644: sub config_check {
10645: my ($dom,$confname,$servadm) = @_;
10646: my ($configuserok,$author_ok,$switchserver,%currroles);
10647: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
10648: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
10649: $confname,$servadm);
10650: if ($configuserok eq 'ok') {
10651: $switchserver = &check_switchserver($dom,$confname);
10652: if ($switchserver eq '') {
10653: $author_ok = &check_authorstatus($dom,$confname,%currroles);
10654: }
10655: }
10656: return ($configuserok,$author_ok,$switchserver);
10657: }
10658:
1.6 raeburn 10659: sub default_change_checker {
1.41 raeburn 10660: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 10661: foreach my $item (@{$links}) {
10662: if ($confhash->{$role}{$item}) {
10663: $changes->{$role}{'links'}{$item} = 1;
10664: }
10665: }
10666: foreach my $item (@{$bgs}) {
10667: if ($confhash->{$role}{$item}) {
10668: $changes->{$role}{'bgs'}{$item} = 1;
10669: }
10670: }
1.41 raeburn 10671: foreach my $item (@{$logintext}) {
10672: if ($confhash->{$role}{$item}) {
10673: $changes->{$role}{'logintext'}{$item} = 1;
10674: }
10675: }
1.6 raeburn 10676: foreach my $img (@{$images}) {
10677: if ($env{'form.'.$role.'_del_'.$img}) {
10678: $confhash->{$role}{$img} = '';
1.12 raeburn 10679: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 10680: }
1.70 raeburn 10681: if ($role eq 'login') {
10682: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
10683: $changes->{$role}{'showlogo'}{$img} = 1;
10684: }
10685: }
1.6 raeburn 10686: }
10687: if ($confhash->{$role}{'font'}) {
10688: $changes->{$role}{'font'} = 1;
10689: }
1.48 raeburn 10690: }
1.6 raeburn 10691:
10692: sub display_colorchgs {
10693: my ($dom,$changes,$roles,$confhash) = @_;
10694: my (%choices,$resulttext);
10695: if (!grep(/^login$/,@{$roles})) {
10696: $resulttext = &mt('Changes made:').'<br />';
10697: }
10698: foreach my $role (@{$roles}) {
10699: if ($role eq 'login') {
10700: %choices = &login_choices();
10701: } else {
10702: %choices = &color_font_choices();
10703: }
10704: if (ref($changes->{$role}) eq 'HASH') {
10705: if ($role ne 'login') {
10706: $resulttext .= '<h4>'.&mt($role).'</h4>';
10707: }
10708: foreach my $key (sort(keys(%{$changes->{$role}}))) {
10709: if ($role ne 'login') {
10710: $resulttext .= '<ul>';
10711: }
10712: if (ref($changes->{$role}{$key}) eq 'HASH') {
10713: if ($role ne 'login') {
10714: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
10715: }
10716: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 10717: if (($role eq 'login') && ($key eq 'showlogo')) {
10718: if ($confhash->{$role}{$key}{$item}) {
10719: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
10720: } else {
10721: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
10722: }
10723: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 10724: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
10725: } else {
1.12 raeburn 10726: my $newitem = $confhash->{$role}{$item};
10727: if ($key eq 'images') {
1.306 raeburn 10728: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 10729: }
10730: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 10731: }
10732: }
10733: if ($role ne 'login') {
10734: $resulttext .= '</ul></li>';
10735: }
10736: } else {
10737: if ($confhash->{$role}{$key} eq '') {
10738: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
10739: } else {
10740: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
10741: }
10742: }
10743: if ($role ne 'login') {
10744: $resulttext .= '</ul>';
10745: }
10746: }
10747: }
10748: }
1.3 raeburn 10749: return $resulttext;
1.1 raeburn 10750: }
10751:
1.9 raeburn 10752: sub thumb_dimensions {
10753: return ('200','50');
10754: }
10755:
1.16 raeburn 10756: sub check_dimensions {
10757: my ($inputfile) = @_;
10758: my ($fullwidth,$fullheight);
10759: if ($inputfile =~ m|^[/\w.\-]+$|) {
10760: if (open(PIPE,"identify $inputfile 2>&1 |")) {
10761: my $imageinfo = <PIPE>;
10762: if (!close(PIPE)) {
10763: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
10764: }
10765: chomp($imageinfo);
10766: my ($fullsize) =
1.21 raeburn 10767: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 10768: if ($fullsize) {
10769: ($fullwidth,$fullheight) = split(/x/,$fullsize);
10770: }
10771: }
10772: }
10773: return ($fullwidth,$fullheight);
10774: }
10775:
1.9 raeburn 10776: sub check_configuser {
10777: my ($uhome,$dom,$confname,$servadm) = @_;
10778: my ($configuserok,%currroles);
10779: if ($uhome eq 'no_host') {
10780: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
10781: my $configpass = &LONCAPA::Enrollment::create_password();
10782: $configuserok =
10783: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
10784: $configpass,'','','','','',undef,$servadm);
10785: } else {
10786: $configuserok = 'ok';
10787: %currroles =
10788: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
10789: }
10790: return ($configuserok,%currroles);
10791: }
10792:
10793: sub check_authorstatus {
10794: my ($dom,$confname,%currroles) = @_;
10795: my $author_ok;
1.40 raeburn 10796: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 10797: my $start = time;
10798: my $end = 0;
10799: $author_ok =
10800: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 10801: 'au',$end,$start,'','','domconfig');
1.9 raeburn 10802: } else {
10803: $author_ok = 'ok';
10804: }
10805: return $author_ok;
10806: }
10807:
10808: sub publishlogo {
1.46 raeburn 10809: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 10810: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 10811: if ($action eq 'upload') {
10812: $fname=$env{'form.'.$formname.'.filename'};
10813: chop($env{'form.'.$formname});
10814: } else {
10815: ($fname) = ($formname =~ /([^\/]+)$/);
10816: }
1.46 raeburn 10817: if ($savefileas ne '') {
10818: $fname = $savefileas;
10819: }
1.9 raeburn 10820: $fname=&Apache::lonnet::clean_filename($fname);
10821: # See if there is anything left
10822: unless ($fname) { return ('error: no uploaded file'); }
10823: $fname="$subdir/$fname";
1.210 raeburn 10824: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 10825: my $filepath="$docroot/priv";
10826: my $relpath = "$dom/$confname";
1.9 raeburn 10827: my ($fnamepath,$file,$fetchthumb);
10828: $file=$fname;
10829: if ($fname=~m|/|) {
10830: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
10831: }
1.164 raeburn 10832: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 10833: my $count;
1.164 raeburn 10834: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 10835: $filepath.="/$parts[$count]";
10836: if ((-e $filepath)!=1) {
10837: mkdir($filepath,02770);
10838: }
10839: }
10840: # Check for bad extension and disallow upload
10841: if ($file=~/\.(\w+)$/ &&
10842: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
10843: $output =
1.207 bisitz 10844: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 10845: } elsif ($file=~/\.(\w+)$/ &&
10846: !defined(&Apache::loncommon::fileembstyle($1))) {
10847: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
10848: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 10849: $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 10850: } elsif (-d "$filepath/$file") {
1.195 bisitz 10851: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 10852: } else {
10853: my $source = $filepath.'/'.$file;
10854: my $logfile;
1.316 raeburn 10855: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 10856: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 10857: }
10858: print $logfile
10859: "\n================= Publish ".localtime()." ================\n".
10860: $env{'user.name'}.':'.$env{'user.domain'}."\n";
10861: # Save the file
1.316 raeburn 10862: if (!open(FH,">",$source)) {
1.9 raeburn 10863: &Apache::lonnet::logthis('Failed to create '.$source);
10864: return (&mt('Failed to create file'));
10865: }
10866: if ($action eq 'upload') {
10867: if (!print FH ($env{'form.'.$formname})) {
10868: &Apache::lonnet::logthis('Failed to write to '.$source);
10869: return (&mt('Failed to write file'));
10870: }
10871: } else {
10872: my $original = &Apache::lonnet::filelocation('',$formname);
10873: if(!copy($original,$source)) {
10874: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
10875: return (&mt('Failed to write file'));
10876: }
10877: }
10878: close(FH);
10879: chmod(0660, $source); # Permissions to rw-rw---.
10880:
10881: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
10882: my $copyfile=$targetdir.'/'.$file;
10883:
10884: my @parts=split(/\//,$targetdir);
10885: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
10886: for (my $count=5;$count<=$#parts;$count++) {
10887: $path.="/$parts[$count]";
10888: if (!-e $path) {
10889: print $logfile "\nCreating directory ".$path;
10890: mkdir($path,02770);
10891: }
10892: }
10893: my $versionresult;
10894: if (-e $copyfile) {
10895: $versionresult = &logo_versioning($targetdir,$file,$logfile);
10896: } else {
10897: $versionresult = 'ok';
10898: }
10899: if ($versionresult eq 'ok') {
10900: if (copy($source,$copyfile)) {
10901: print $logfile "\nCopied original source to ".$copyfile."\n";
10902: $output = 'ok';
10903: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 10904: push(@{$modified_urls},[$copyfile,$source]);
10905: my $metaoutput =
10906: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
10907: unless ($registered_cleanup) {
10908: my $handlers = $r->get_handlers('PerlCleanupHandler');
10909: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
10910: $registered_cleanup=1;
10911: }
1.9 raeburn 10912: } else {
10913: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
10914: $output = &mt('Failed to copy file to RES space').", $!";
10915: }
10916: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
10917: my $inputfile = $filepath.'/'.$file;
10918: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 10919: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
10920: if ($fullwidth ne '' && $fullheight ne '') {
10921: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
10922: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 10923: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
10924: system({$args[0]} @args);
1.16 raeburn 10925: chmod(0660, $filepath.'/tn-'.$file);
10926: if (-e $outfile) {
10927: my $copyfile=$targetdir.'/tn-'.$file;
10928: if (copy($outfile,$copyfile)) {
10929: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 10930: my $thumb_metaoutput =
10931: &write_metadata($dom,$confname,$formname,
10932: $targetdir,'tn-'.$file,$logfile);
10933: push(@{$modified_urls},[$copyfile,$outfile]);
10934: unless ($registered_cleanup) {
10935: my $handlers = $r->get_handlers('PerlCleanupHandler');
10936: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
10937: $registered_cleanup=1;
10938: }
1.267 raeburn 10939: $madethumb = 1;
1.16 raeburn 10940: } else {
10941: print $logfile "\nUnable to write ".$copyfile.
10942: ':'.$!."\n";
10943: }
10944: }
1.9 raeburn 10945: }
10946: }
10947: }
10948: } else {
10949: $output = $versionresult;
10950: }
10951: }
1.267 raeburn 10952: return ($output,$logourl,$madethumb);
1.9 raeburn 10953: }
10954:
10955: sub logo_versioning {
10956: my ($targetdir,$file,$logfile) = @_;
10957: my $target = $targetdir.'/'.$file;
10958: my ($maxversion,$fn,$extn,$output);
10959: $maxversion = 0;
10960: if ($file =~ /^(.+)\.(\w+)$/) {
10961: $fn=$1;
10962: $extn=$2;
10963: }
10964: opendir(DIR,$targetdir);
10965: while (my $filename=readdir(DIR)) {
10966: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
10967: $maxversion=($1>$maxversion)?$1:$maxversion;
10968: }
10969: }
10970: $maxversion++;
10971: print $logfile "\nCreating old version ".$maxversion."\n";
10972: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
10973: if (copy($target,$copyfile)) {
10974: print $logfile "Copied old target to ".$copyfile."\n";
10975: $copyfile=$copyfile.'.meta';
10976: if (copy($target.'.meta',$copyfile)) {
10977: print $logfile "Copied old target metadata to ".$copyfile."\n";
10978: $output = 'ok';
10979: } else {
10980: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
10981: $output = &mt('Failed to copy old meta').", $!, ";
10982: }
10983: } else {
10984: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
10985: $output = &mt('Failed to copy old target').", $!, ";
10986: }
10987: return $output;
10988: }
10989:
10990: sub write_metadata {
10991: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
10992: my (%metadatafields,%metadatakeys,$output);
10993: $metadatafields{'title'}=$formname;
10994: $metadatafields{'creationdate'}=time;
10995: $metadatafields{'lastrevisiondate'}=time;
10996: $metadatafields{'copyright'}='public';
10997: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
10998: $env{'user.domain'};
10999: $metadatafields{'authorspace'}=$confname.':'.$dom;
11000: $metadatafields{'domain'}=$dom;
11001: {
11002: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
11003: my $mfh;
1.316 raeburn 11004: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 11005: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 11006: unless ($_=~/\./) {
11007: my $unikey=$_;
11008: $unikey=~/^([A-Za-z]+)/;
11009: my $tag=$1;
11010: $tag=~tr/A-Z/a-z/;
11011: print $mfh "\n\<$tag";
11012: foreach (split(/\,/,$metadatakeys{$unikey})) {
11013: my $value=$metadatafields{$unikey.'.'.$_};
11014: $value=~s/\"/\'\'/g;
11015: print $mfh ' '.$_.'="'.$value.'"';
11016: }
11017: print $mfh '>'.
11018: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
11019: .'</'.$tag.'>';
11020: }
11021: }
11022: $output = 'ok';
11023: print $logfile "\nWrote metadata";
11024: close($mfh);
11025: } else {
11026: print $logfile "\nFailed to open metadata file";
1.9 raeburn 11027: $output = &mt('Could not write metadata');
11028: }
11029: }
1.155 raeburn 11030: return $output;
11031: }
11032:
11033: sub notifysubscribed {
11034: foreach my $targetsource (@{$modified_urls}){
11035: next unless (ref($targetsource) eq 'ARRAY');
11036: my ($target,$source)=@{$targetsource};
11037: if ($source ne '') {
1.316 raeburn 11038: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 11039: print $logfh "\nCleanup phase: Notifications\n";
11040: my @subscribed=&subscribed_hosts($target);
11041: foreach my $subhost (@subscribed) {
11042: print $logfh "\nNotifying host ".$subhost.':';
11043: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
11044: print $logfh $reply;
11045: }
11046: my @subscribedmeta=&subscribed_hosts("$target.meta");
11047: foreach my $subhost (@subscribedmeta) {
11048: print $logfh "\nNotifying host for metadata only ".$subhost.':';
11049: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
11050: $subhost);
11051: print $logfh $reply;
11052: }
11053: print $logfh "\n============ Done ============\n";
1.160 raeburn 11054: close($logfh);
1.155 raeburn 11055: }
11056: }
11057: }
11058: return OK;
11059: }
11060:
11061: sub subscribed_hosts {
11062: my ($target) = @_;
11063: my @subscribed;
1.316 raeburn 11064: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 11065: while (my $subline=<$fh>) {
11066: if ($subline =~ /^($match_lonid):/) {
11067: my $host = $1;
11068: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
11069: unless (grep(/^\Q$host\E$/,@subscribed)) {
11070: push(@subscribed,$host);
11071: }
11072: }
11073: }
11074: }
11075: }
11076: return @subscribed;
1.9 raeburn 11077: }
11078:
11079: sub check_switchserver {
11080: my ($dom,$confname) = @_;
11081: my ($allowed,$switchserver);
11082: my $home = &Apache::lonnet::homeserver($confname,$dom);
11083: if ($home eq 'no_host') {
11084: $home = &Apache::lonnet::domain($dom,'primary');
11085: }
11086: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 11087: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
11088: if (!$allowed) {
1.180 raeburn 11089: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 11090: }
11091: return $switchserver;
11092: }
11093:
1.1 raeburn 11094: sub modify_quotas {
1.216 raeburn 11095: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 11096: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 11097: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 11098: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
11099: $validationfieldsref);
1.86 raeburn 11100: if ($action eq 'quotas') {
11101: $context = 'tools';
1.163 raeburn 11102: } else {
1.86 raeburn 11103: $context = $action;
11104: }
11105: if ($context eq 'requestcourses') {
1.325 raeburn 11106: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 11107: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 11108: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
11109: %titles = &courserequest_titles();
11110: $toolregexp = join('|',@usertools);
11111: %conditions = &courserequest_conditions();
1.216 raeburn 11112: $confname = $dom.'-domainconfig';
11113: my $servadm = $r->dir_config('lonAdmEMail');
11114: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 11115: ($validationitemsref,$validationnamesref,$validationfieldsref) =
11116: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 11117: } elsif ($context eq 'requestauthor') {
11118: @usertools = ('author');
11119: %titles = &authorrequest_titles();
1.86 raeburn 11120: } else {
1.162 raeburn 11121: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 11122: %titles = &tool_titles();
1.86 raeburn 11123: }
1.212 raeburn 11124: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 11125: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 11126: foreach my $key (keys(%env)) {
1.101 raeburn 11127: if ($context eq 'requestcourses') {
11128: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
11129: my $item = $1;
11130: my $type = $2;
11131: if ($type =~ /^limit_(.+)/) {
11132: $limithash{$item}{$1} = $env{$key};
11133: } else {
11134: $confhash{$item}{$type} = $env{$key};
11135: }
11136: }
1.163 raeburn 11137: } elsif ($context eq 'requestauthor') {
11138: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
11139: $confhash{$1} = $env{$key};
11140: }
1.101 raeburn 11141: } else {
1.86 raeburn 11142: if ($key =~ /^form\.quota_(.+)$/) {
11143: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 11144: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
11145: $confhash{'authorquota'}{$1} = $env{$key};
11146: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 11147: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
11148: }
1.72 raeburn 11149: }
11150: }
1.163 raeburn 11151: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 11152: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 11153: @approvalnotify = sort(@approvalnotify);
11154: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 11155: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 11156: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
11157: foreach my $type (@hasuniquecode) {
11158: if (grep(/^\Q$type\E$/,@crstypes)) {
11159: $confhash{'uniquecode'}{$type} = 1;
11160: }
1.216 raeburn 11161: }
1.242 raeburn 11162: my (%newbook,%allpos);
1.216 raeburn 11163: if ($context eq 'requestcourses') {
1.242 raeburn 11164: foreach my $type ('textbooks','templates') {
11165: @{$allpos{$type}} = ();
11166: my $invalid;
11167: if ($type eq 'textbooks') {
11168: $invalid = &mt('Invalid LON-CAPA course for textbook');
11169: } else {
11170: $invalid = &mt('Invalid LON-CAPA course for template');
11171: }
11172: if ($env{'form.'.$type.'_addbook'}) {
11173: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
11174: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
11175: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
11176: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
11177: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
11178: } else {
11179: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
11180: my $position = $env{'form.'.$type.'_addbook_pos'};
11181: $position =~ s/\D+//g;
11182: if ($position ne '') {
11183: $allpos{$type}[$position] = $newbook{$type};
11184: }
1.216 raeburn 11185: }
1.242 raeburn 11186: } else {
11187: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 11188: }
11189: }
1.242 raeburn 11190: }
1.216 raeburn 11191: }
1.102 raeburn 11192: if (ref($domconfig{$action}) eq 'HASH') {
11193: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
11194: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
11195: $changes{'notify'}{'approval'} = 1;
11196: }
11197: } else {
1.144 raeburn 11198: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 11199: $changes{'notify'}{'approval'} = 1;
11200: }
11201: }
1.218 raeburn 11202: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
11203: if (ref($confhash{'uniquecode'}) eq 'HASH') {
11204: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
11205: unless ($confhash{'uniquecode'}{$crstype}) {
11206: $changes{'uniquecode'} = 1;
11207: }
11208: }
11209: unless ($changes{'uniquecode'}) {
11210: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
11211: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
11212: $changes{'uniquecode'} = 1;
11213: }
11214: }
11215: }
11216: } else {
11217: $changes{'uniquecode'} = 1;
11218: }
11219: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
11220: $changes{'uniquecode'} = 1;
1.216 raeburn 11221: }
11222: if ($context eq 'requestcourses') {
1.242 raeburn 11223: foreach my $type ('textbooks','templates') {
11224: if (ref($domconfig{$action}{$type}) eq 'HASH') {
11225: my %deletions;
11226: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
11227: if (@todelete) {
11228: map { $deletions{$_} = 1; } @todelete;
11229: }
11230: my %imgdeletions;
11231: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
11232: if (@todeleteimages) {
11233: map { $imgdeletions{$_} = 1; } @todeleteimages;
11234: }
11235: my $maxnum = $env{'form.'.$type.'_maxnum'};
11236: for (my $i=0; $i<=$maxnum; $i++) {
11237: my $itemid = $env{'form.'.$type.'_id_'.$i};
11238: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
11239: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
11240: if ($deletions{$key}) {
11241: if ($domconfig{$action}{$type}{$key}{'image'}) {
11242: #FIXME need to obsolete item in RES space
11243: }
11244: next;
11245: } else {
11246: my $newpos = $env{'form.'.$itemid};
11247: $newpos =~ s/\D+//g;
1.243 raeburn 11248: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 11249: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 11250: ($type eq 'templates'));
1.242 raeburn 11251: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
11252: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
11253: $changes{$type}{$key} = 1;
11254: }
11255: }
11256: $allpos{$type}[$newpos] = $key;
11257: }
11258: if ($imgdeletions{$key}) {
11259: $changes{$type}{$key} = 1;
1.216 raeburn 11260: #FIXME need to obsolete item in RES space
1.242 raeburn 11261: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
11262: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 11263: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
11264: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
11265: } else {
11266: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
11267: $cdom,$cnum,$type,$configuserok,
11268: $switchserver,$author_ok);
11269: if ($imgurl) {
11270: $confhash{$type}{$key}{'image'} = $imgurl;
11271: $changes{$type}{$key} = 1;
11272: }
11273: if ($error) {
11274: &Apache::lonnet::logthis($error);
11275: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11276: }
11277: }
1.242 raeburn 11278: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
11279: $confhash{$type}{$key}{'image'} =
11280: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 11281: }
11282: }
11283: }
11284: }
11285: }
11286: }
1.102 raeburn 11287: } else {
1.144 raeburn 11288: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 11289: $changes{'notify'}{'approval'} = 1;
11290: }
1.218 raeburn 11291: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 11292: $changes{'uniquecode'} = 1;
11293: }
11294: }
11295: if ($context eq 'requestcourses') {
1.242 raeburn 11296: foreach my $type ('textbooks','templates') {
11297: if ($newbook{$type}) {
11298: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 11299: foreach my $item ('subject','title','publisher','author') {
11300: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11301: ($type eq 'template'));
1.242 raeburn 11302: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
11303: if ($env{'form.'.$type.'_addbook_'.$item}) {
11304: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
11305: }
11306: }
11307: if ($type eq 'textbooks') {
11308: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
11309: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 11310: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
11311: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
11312: } else {
11313: my ($imageurl,$error) =
11314: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
11315: $configuserok,$switchserver,$author_ok);
11316: if ($imageurl) {
11317: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
11318: }
11319: if ($error) {
11320: &Apache::lonnet::logthis($error);
11321: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11322: }
1.242 raeburn 11323: }
11324: }
1.216 raeburn 11325: }
11326: }
1.242 raeburn 11327: if (@{$allpos{$type}} > 0) {
11328: my $idx = 0;
11329: foreach my $item (@{$allpos{$type}}) {
11330: if ($item ne '') {
11331: $confhash{$type}{$item}{'order'} = $idx;
11332: if (ref($domconfig{$action}) eq 'HASH') {
11333: if (ref($domconfig{$action}{$type}) eq 'HASH') {
11334: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
11335: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
11336: $changes{$type}{$item} = 1;
11337: }
1.216 raeburn 11338: }
11339: }
11340: }
1.242 raeburn 11341: $idx ++;
1.216 raeburn 11342: }
11343: }
11344: }
11345: }
1.235 raeburn 11346: if (ref($validationitemsref) eq 'ARRAY') {
11347: foreach my $item (@{$validationitemsref}) {
11348: if ($item eq 'fields') {
11349: my @changed;
11350: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
11351: if (@{$confhash{'validation'}{$item}} > 0) {
11352: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
11353: }
1.266 raeburn 11354: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11355: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11356: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
11357: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
11358: $domconfig{'requestcourses'}{'validation'}{$item});
11359: } else {
11360: @changed = @{$confhash{'validation'}{$item}};
11361: }
1.235 raeburn 11362: } else {
11363: @changed = @{$confhash{'validation'}{$item}};
11364: }
11365: } else {
11366: @changed = @{$confhash{'validation'}{$item}};
11367: }
11368: if (@changed) {
11369: if ($confhash{'validation'}{$item}) {
11370: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
11371: } else {
11372: $changes{'validation'}{$item} = &mt('None');
11373: }
11374: }
11375: } else {
11376: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
11377: if ($item eq 'markup') {
11378: if ($env{'form.requestcourses_validation_'.$item}) {
11379: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
11380: }
11381: }
1.266 raeburn 11382: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11383: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11384: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
11385: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11386: }
11387: } else {
11388: if ($confhash{'validation'}{$item} ne '') {
11389: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11390: }
1.235 raeburn 11391: }
11392: } else {
11393: if ($confhash{'validation'}{$item} ne '') {
11394: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11395: }
11396: }
11397: }
11398: }
11399: }
11400: if ($env{'form.validationdc'}) {
11401: my $newval = $env{'form.validationdc'};
1.285 raeburn 11402: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 11403: if (exists($domcoords{$newval})) {
11404: $confhash{'validation'}{'dc'} = $newval;
11405: }
11406: }
11407: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 11408: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11409: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11410: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
11411: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
11412: if ($confhash{'validation'}{'dc'} eq '') {
11413: $changes{'validation'}{'dc'} = &mt('None');
11414: } else {
11415: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11416: }
1.235 raeburn 11417: }
1.266 raeburn 11418: } elsif ($confhash{'validation'}{'dc'} ne '') {
11419: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 11420: }
11421: } elsif ($confhash{'validation'}{'dc'} ne '') {
11422: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11423: }
11424: } elsif ($confhash{'validation'}{'dc'} ne '') {
11425: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 11426: }
1.266 raeburn 11427: } else {
11428: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11429: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11430: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
11431: $changes{'validation'}{'dc'} = &mt('None');
11432: }
11433: }
1.235 raeburn 11434: }
11435: }
1.102 raeburn 11436: }
11437: } else {
1.86 raeburn 11438: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 11439: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 11440: }
1.72 raeburn 11441: foreach my $item (@usertools) {
11442: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 11443: my $unset;
1.101 raeburn 11444: if ($context eq 'requestcourses') {
1.104 raeburn 11445: $unset = '0';
11446: if ($type eq '_LC_adv') {
11447: $unset = '';
11448: }
1.101 raeburn 11449: if ($confhash{$item}{$type} eq 'autolimit') {
11450: $confhash{$item}{$type} .= '=';
11451: unless ($limithash{$item}{$type} =~ /\D/) {
11452: $confhash{$item}{$type} .= $limithash{$item}{$type};
11453: }
11454: }
1.163 raeburn 11455: } elsif ($context eq 'requestauthor') {
11456: $unset = '0';
11457: if ($type eq '_LC_adv') {
11458: $unset = '';
11459: }
1.72 raeburn 11460: } else {
1.101 raeburn 11461: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
11462: $confhash{$item}{$type} = 1;
11463: } else {
11464: $confhash{$item}{$type} = 0;
11465: }
1.72 raeburn 11466: }
1.86 raeburn 11467: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 11468: if ($action eq 'requestauthor') {
11469: if ($domconfig{$action}{$type} ne $confhash{$type}) {
11470: $changes{$type} = 1;
11471: }
11472: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 11473: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
11474: $changes{$item}{$type} = 1;
11475: }
11476: } else {
11477: if ($context eq 'requestcourses') {
1.104 raeburn 11478: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 11479: $changes{$item}{$type} = 1;
11480: }
11481: } else {
11482: if (!$confhash{$item}{$type}) {
11483: $changes{$item}{$type} = 1;
11484: }
11485: }
11486: }
11487: } else {
11488: if ($context eq 'requestcourses') {
1.104 raeburn 11489: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 11490: $changes{$item}{$type} = 1;
11491: }
1.163 raeburn 11492: } elsif ($context eq 'requestauthor') {
11493: if ($confhash{$type} ne $unset) {
11494: $changes{$type} = 1;
11495: }
1.72 raeburn 11496: } else {
11497: if (!$confhash{$item}{$type}) {
11498: $changes{$item}{$type} = 1;
11499: }
11500: }
11501: }
1.1 raeburn 11502: }
11503: }
1.163 raeburn 11504: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 11505: if (ref($domconfig{'quotas'}) eq 'HASH') {
11506: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
11507: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
11508: if (exists($confhash{'defaultquota'}{$key})) {
11509: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
11510: $changes{'defaultquota'}{$key} = 1;
11511: }
11512: } else {
11513: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 11514: }
11515: }
1.86 raeburn 11516: } else {
11517: foreach my $key (keys(%{$domconfig{'quotas'}})) {
11518: if (exists($confhash{'defaultquota'}{$key})) {
11519: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
11520: $changes{'defaultquota'}{$key} = 1;
11521: }
11522: } else {
11523: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 11524: }
1.1 raeburn 11525: }
11526: }
1.197 raeburn 11527: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
11528: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
11529: if (exists($confhash{'authorquota'}{$key})) {
11530: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
11531: $changes{'authorquota'}{$key} = 1;
11532: }
11533: } else {
11534: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
11535: }
11536: }
11537: }
1.1 raeburn 11538: }
1.86 raeburn 11539: if (ref($confhash{'defaultquota'}) eq 'HASH') {
11540: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
11541: if (ref($domconfig{'quotas'}) eq 'HASH') {
11542: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
11543: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
11544: $changes{'defaultquota'}{$key} = 1;
11545: }
11546: } else {
11547: if (!exists($domconfig{'quotas'}{$key})) {
11548: $changes{'defaultquota'}{$key} = 1;
11549: }
1.72 raeburn 11550: }
11551: } else {
1.86 raeburn 11552: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 11553: }
1.1 raeburn 11554: }
11555: }
1.197 raeburn 11556: if (ref($confhash{'authorquota'}) eq 'HASH') {
11557: foreach my $key (keys(%{$confhash{'authorquota'}})) {
11558: if (ref($domconfig{'quotas'}) eq 'HASH') {
11559: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
11560: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
11561: $changes{'authorquota'}{$key} = 1;
11562: }
11563: } else {
11564: $changes{'authorquota'}{$key} = 1;
11565: }
11566: } else {
11567: $changes{'authorquota'}{$key} = 1;
11568: }
11569: }
11570: }
1.1 raeburn 11571: }
1.72 raeburn 11572:
1.163 raeburn 11573: if ($context eq 'requestauthor') {
11574: $domdefaults{'requestauthor'} = \%confhash;
11575: } else {
11576: foreach my $key (keys(%confhash)) {
1.242 raeburn 11577: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 11578: $domdefaults{$key} = $confhash{$key};
11579: }
1.163 raeburn 11580: }
1.72 raeburn 11581: }
1.163 raeburn 11582:
1.1 raeburn 11583: my %quotahash = (
1.86 raeburn 11584: $action => { %confhash }
1.1 raeburn 11585: );
11586: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
11587: $dom);
11588: if ($putresult eq 'ok') {
11589: if (keys(%changes) > 0) {
1.72 raeburn 11590: my $cachetime = 24*60*60;
11591: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 11592: if (ref($lastactref) eq 'HASH') {
11593: $lastactref->{'domdefaults'} = 1;
11594: }
1.1 raeburn 11595: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 11596: unless (($context eq 'requestcourses') ||
1.163 raeburn 11597: ($context eq 'requestauthor')) {
1.86 raeburn 11598: if (ref($changes{'defaultquota'}) eq 'HASH') {
11599: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
11600: foreach my $type (@{$types},'default') {
11601: if (defined($changes{'defaultquota'}{$type})) {
11602: my $typetitle = $usertypes->{$type};
11603: if ($type eq 'default') {
11604: $typetitle = $othertitle;
11605: }
1.213 raeburn 11606: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 11607: }
11608: }
1.86 raeburn 11609: $resulttext .= '</ul></li>';
1.72 raeburn 11610: }
1.197 raeburn 11611: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 11612: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 11613: foreach my $type (@{$types},'default') {
11614: if (defined($changes{'authorquota'}{$type})) {
11615: my $typetitle = $usertypes->{$type};
11616: if ($type eq 'default') {
11617: $typetitle = $othertitle;
11618: }
1.213 raeburn 11619: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 11620: }
11621: }
11622: $resulttext .= '</ul></li>';
11623: }
1.72 raeburn 11624: }
1.80 raeburn 11625: my %newenv;
1.72 raeburn 11626: foreach my $item (@usertools) {
1.163 raeburn 11627: my (%haschgs,%inconf);
11628: if ($context eq 'requestauthor') {
11629: %haschgs = %changes;
1.210 raeburn 11630: %inconf = %confhash;
1.163 raeburn 11631: } else {
11632: if (ref($changes{$item}) eq 'HASH') {
11633: %haschgs = %{$changes{$item}};
11634: }
11635: if (ref($confhash{$item}) eq 'HASH') {
11636: %inconf = %{$confhash{$item}};
11637: }
11638: }
11639: if (keys(%haschgs) > 0) {
1.80 raeburn 11640: my $newacc =
11641: &Apache::lonnet::usertools_access($env{'user.name'},
11642: $env{'user.domain'},
1.86 raeburn 11643: $item,'reload',$context);
1.210 raeburn 11644: if (($context eq 'requestcourses') ||
1.163 raeburn 11645: ($context eq 'requestauthor')) {
1.108 raeburn 11646: if ($env{'environment.canrequest.'.$item} ne $newacc) {
11647: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 11648: }
11649: } else {
11650: if ($env{'environment.availabletools.'.$item} ne $newacc) {
11651: $newenv{'environment.availabletools.'.$item} = $newacc;
11652: }
1.80 raeburn 11653: }
1.163 raeburn 11654: unless ($context eq 'requestauthor') {
11655: $resulttext .= '<li>'.$titles{$item}.'<ul>';
11656: }
1.72 raeburn 11657: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 11658: if ($haschgs{$type}) {
1.72 raeburn 11659: my $typetitle = $usertypes->{$type};
11660: if ($type eq 'default') {
11661: $typetitle = $othertitle;
11662: } elsif ($type eq '_LC_adv') {
11663: $typetitle = 'LON-CAPA Advanced Users';
11664: }
1.163 raeburn 11665: if ($inconf{$type}) {
1.101 raeburn 11666: if ($context eq 'requestcourses') {
11667: my $cond;
1.163 raeburn 11668: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 11669: if ($1 eq '') {
11670: $cond = &mt('(Automatic processing of any request).');
11671: } else {
11672: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
11673: }
11674: } else {
1.163 raeburn 11675: $cond = $conditions{$inconf{$type}};
1.101 raeburn 11676: }
11677: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 11678: } elsif ($context eq 'requestauthor') {
11679: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
11680: $titles{$inconf{$type}},$typetitle);
11681:
1.101 raeburn 11682: } else {
11683: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
11684: }
1.72 raeburn 11685: } else {
1.104 raeburn 11686: if ($type eq '_LC_adv') {
1.163 raeburn 11687: if ($inconf{$type} eq '0') {
1.104 raeburn 11688: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
11689: } else {
11690: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
11691: }
11692: } else {
11693: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
11694: }
1.72 raeburn 11695: }
11696: }
1.26 raeburn 11697: }
1.163 raeburn 11698: unless ($context eq 'requestauthor') {
11699: $resulttext .= '</ul></li>';
11700: }
1.26 raeburn 11701: }
1.1 raeburn 11702: }
1.163 raeburn 11703: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 11704: if (ref($changes{'notify'}) eq 'HASH') {
11705: if ($changes{'notify'}{'approval'}) {
11706: if (ref($confhash{'notify'}) eq 'HASH') {
11707: if ($confhash{'notify'}{'approval'}) {
11708: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
11709: } else {
1.163 raeburn 11710: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 11711: }
11712: }
11713: }
11714: }
11715: }
1.216 raeburn 11716: if ($action eq 'requestcourses') {
11717: my @offon = ('off','on');
11718: if ($changes{'uniquecode'}) {
1.218 raeburn 11719: if (ref($confhash{'uniquecode'}) eq 'HASH') {
11720: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
11721: $resulttext .= '<li>'.
11722: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
11723: '</li>';
11724: } else {
11725: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
11726: '</li>';
11727: }
1.216 raeburn 11728: }
1.242 raeburn 11729: foreach my $type ('textbooks','templates') {
11730: if (ref($changes{$type}) eq 'HASH') {
11731: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
11732: foreach my $key (sort(keys(%{$changes{$type}}))) {
11733: my %coursehash = &Apache::lonnet::coursedescription($key);
11734: my $coursetitle = $coursehash{'description'};
11735: my $position = $confhash{$type}{$key}{'order'} + 1;
11736: $resulttext .= '<li>';
1.243 raeburn 11737: foreach my $item ('subject','title','publisher','author') {
11738: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11739: ($type eq 'templates'));
1.242 raeburn 11740: my $name = $item.':';
11741: $name =~ s/^(\w)/\U$1/;
11742: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
11743: }
11744: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
11745: if ($type eq 'textbooks') {
11746: if ($confhash{$type}{$key}{'image'}) {
11747: $resulttext .= ' '.&mt('Image: [_1]',
11748: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
11749: ' alt="Textbook cover" />').'<br />';
11750: }
11751: }
11752: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 11753: }
1.242 raeburn 11754: $resulttext .= '</ul></li>';
1.216 raeburn 11755: }
11756: }
1.235 raeburn 11757: if (ref($changes{'validation'}) eq 'HASH') {
11758: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
11759: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
11760: foreach my $item (@{$validationitemsref}) {
11761: if (exists($changes{'validation'}{$item})) {
11762: if ($item eq 'markup') {
11763: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
11764: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
11765: } else {
11766: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
11767: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
11768: }
11769: }
11770: }
11771: if (exists($changes{'validation'}{'dc'})) {
11772: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
11773: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
11774: }
11775: }
11776: }
1.216 raeburn 11777: }
1.1 raeburn 11778: $resulttext .= '</ul>';
1.80 raeburn 11779: if (keys(%newenv)) {
11780: &Apache::lonnet::appenv(\%newenv);
11781: }
1.1 raeburn 11782: } else {
1.86 raeburn 11783: if ($context eq 'requestcourses') {
11784: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 11785: } elsif ($context eq 'requestauthor') {
11786: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 11787: } else {
1.90 weissno 11788: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 11789: }
1.1 raeburn 11790: }
11791: } else {
1.11 albertel 11792: $resulttext = '<span class="LC_error">'.
11793: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11794: }
1.216 raeburn 11795: if ($errors) {
11796: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
11797: '<ul>'.$errors.'</ul></p>';
11798: }
1.3 raeburn 11799: return $resulttext;
1.1 raeburn 11800: }
11801:
1.216 raeburn 11802: sub process_textbook_image {
1.242 raeburn 11803: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 11804: my $filename = $env{'form.'.$caller.'.filename'};
11805: my ($error,$url);
11806: my ($width,$height) = (50,50);
11807: if ($configuserok eq 'ok') {
11808: if ($switchserver) {
11809: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
11810: $switchserver);
11811: } elsif ($author_ok eq 'ok') {
11812: my ($result,$imageurl) =
11813: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 11814: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 11815: if ($result eq 'ok') {
11816: $url = $imageurl;
11817: } else {
11818: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
11819: }
11820: } else {
11821: $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);
11822: }
11823: } else {
11824: $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);
11825: }
11826: return ($url,$error);
11827: }
11828:
1.267 raeburn 11829: sub modify_ltitools {
11830: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
11831: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 11832: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 11833: my $confname = $dom.'-domainconfig';
11834: my $servadm = $r->dir_config('lonAdmEMail');
11835: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11836: my (%posslti,%possfield);
11837: my @courseroles = ('cc','in','ta','ep','st');
11838: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
11839: map { $posslti{$_} = 1; } @ltiroles;
11840: my @allfields = ('fullname','firstname','lastname','email','user','roles');
11841: map { $possfield{$_} = 1; } @allfields;
11842: my %lt = <itools_names();
11843: if ($env{'form.ltitools_add'}) {
11844: my $title = $env{'form.ltitools_add_title'};
11845: $title =~ s/(`)/'/g;
11846: ($newid,my $error) = &get_ltitools_id($dom,$title);
11847: if ($newid) {
11848: my $position = $env{'form.ltitools_add_pos'};
11849: $position =~ s/\D+//g;
11850: if ($position ne '') {
11851: $allpos[$position] = $newid;
11852: }
11853: $changes{$newid} = 1;
1.322 raeburn 11854: foreach my $item ('title','url','key','secret','lifetime') {
1.267 raeburn 11855: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322 raeburn 11856: if ($item eq 'lifetime') {
11857: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
11858: }
1.267 raeburn 11859: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 11860: if (($item eq 'key') || ($item eq 'secret')) {
11861: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
11862: } else {
11863: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
11864: }
1.267 raeburn 11865: }
11866: }
11867: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
11868: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
11869: }
11870: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
11871: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
11872: }
1.323 raeburn 11873: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
11874: $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
11875: } else {
11876: $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
11877: }
1.296 raeburn 11878: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 11879: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
11880: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 11881: if (($item eq 'width') || ($item eq 'height')) {
11882: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
11883: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
11884: }
11885: } else {
11886: if ($env{'form.ltitools_add_'.$item} ne '') {
11887: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
11888: }
1.267 raeburn 11889: }
11890: }
11891: if ($env{'form.ltitools_add_target'} eq 'window') {
11892: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 11893: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
11894: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 11895: } else {
11896: $confhash{$newid}{'display'}{'target'} = 'iframe';
11897: }
11898: foreach my $item ('passback','roster') {
1.319 raeburn 11899: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 11900: $confhash{$newid}{$item} = 1;
1.319 raeburn 11901: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
11902: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
11903: $lifetime =~ s/^\s+|\s+$//g;
11904: if ($lifetime =~ /^\d+\.?\d*$/) {
11905: $confhash{$newid}{$item.'valid'} = $lifetime;
11906: }
11907: }
1.267 raeburn 11908: }
11909: }
11910: if ($env{'form.ltitools_add_image.filename'} ne '') {
11911: my ($imageurl,$error) =
1.307 raeburn 11912: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 11913: $configuserok,$switchserver,$author_ok);
11914: if ($imageurl) {
11915: $confhash{$newid}{'image'} = $imageurl;
11916: }
11917: if ($error) {
11918: &Apache::lonnet::logthis($error);
11919: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11920: }
11921: }
11922: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
11923: foreach my $field (@fields) {
11924: if ($possfield{$field}) {
11925: if ($field eq 'roles') {
11926: foreach my $role (@courseroles) {
11927: my $choice = $env{'form.ltitools_add_roles_'.$role};
11928: if (($choice ne '') && ($posslti{$choice})) {
11929: $confhash{$newid}{'roles'}{$role} = $choice;
11930: if ($role eq 'cc') {
11931: $confhash{$newid}{'roles'}{'co'} = $choice;
11932: }
11933: }
11934: }
11935: } else {
11936: $confhash{$newid}{'fields'}{$field} = 1;
11937: }
11938: }
11939: }
1.324 raeburn 11940: if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
11941: if ($confhash{$newid}{'fields'}{'user'}) {
11942: if ($env{'form.ltitools_userincdom_add'}) {
11943: $confhash{$newid}{'incdom'} = 1;
11944: }
11945: }
11946: }
1.273 raeburn 11947: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
11948: foreach my $item (@courseconfig) {
11949: $confhash{$newid}{'crsconf'}{$item} = 1;
11950: }
1.267 raeburn 11951: if ($env{'form.ltitools_add_custom'}) {
11952: my $name = $env{'form.ltitools_add_custom_name'};
11953: my $value = $env{'form.ltitools_add_custom_value'};
11954: $value =~ s/(`)/'/g;
11955: $name =~ s/(`)/'/g;
11956: $confhash{$newid}{'custom'}{$name} = $value;
11957: }
11958: } else {
11959: my $error = &mt('Failed to acquire unique ID for new external tool');
11960: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11961: }
11962: }
11963: if (ref($domconfig{$action}) eq 'HASH') {
11964: my %deletions;
11965: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
11966: if (@todelete) {
11967: map { $deletions{$_} = 1; } @todelete;
11968: }
11969: my %customadds;
11970: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
11971: if (@newcustom) {
11972: map { $customadds{$_} = 1; } @newcustom;
11973: }
11974: my %imgdeletions;
11975: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
11976: if (@todeleteimages) {
11977: map { $imgdeletions{$_} = 1; } @todeleteimages;
11978: }
11979: my $maxnum = $env{'form.ltitools_maxnum'};
11980: for (my $i=0; $i<=$maxnum; $i++) {
11981: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 11982: $itemid =~ s/\D+//g;
1.267 raeburn 11983: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11984: if ($deletions{$itemid}) {
11985: if ($domconfig{$action}{$itemid}{'image'}) {
11986: #FIXME need to obsolete item in RES space
11987: }
11988: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
11989: next;
11990: } else {
11991: my $newpos = $env{'form.ltitools_'.$itemid};
11992: $newpos =~ s/\D+//g;
1.322 raeburn 11993: foreach my $item ('title','url','lifetime') {
1.267 raeburn 11994: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11995: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
11996: $changes{$itemid} = 1;
11997: }
11998: }
1.297 raeburn 11999: foreach my $item ('key','secret') {
12000: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
12001: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
12002: $changes{$itemid} = 1;
12003: }
12004: }
1.267 raeburn 12005: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
12006: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
12007: }
12008: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
12009: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
12010: }
1.323 raeburn 12011: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
12012: $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
12013: } else {
12014: $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
12015: }
12016: if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
12017: if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
12018: $changes{$itemid} = 1;
12019: }
12020: } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
12021: $changes{$itemid} = 1;
12022: }
1.267 raeburn 12023: foreach my $size ('width','height') {
12024: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
12025: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
12026: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
12027: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
12028: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12029: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
12030: $changes{$itemid} = 1;
12031: }
12032: } else {
12033: $changes{$itemid} = 1;
12034: }
1.296 raeburn 12035: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12036: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
12037: $changes{$itemid} = 1;
12038: }
12039: }
12040: }
12041: foreach my $item ('linktext','explanation') {
12042: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
12043: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
12044: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
12045: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
12046: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12047: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
12048: $changes{$itemid} = 1;
12049: }
12050: } else {
12051: $changes{$itemid} = 1;
12052: }
12053: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12054: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
12055: $changes{$itemid} = 1;
12056: }
1.267 raeburn 12057: }
12058: }
12059: if ($env{'form.ltitools_target_'.$i} eq 'window') {
12060: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 12061: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
12062: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 12063: } else {
12064: $confhash{$itemid}{'display'}{'target'} = 'iframe';
12065: }
12066: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12067: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
12068: $changes{$itemid} = 1;
12069: }
12070: } else {
12071: $changes{$itemid} = 1;
12072: }
12073: foreach my $extra ('passback','roster') {
12074: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
12075: $confhash{$itemid}{$extra} = 1;
1.319 raeburn 12076: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
1.338 raeburn 12077: my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
1.319 raeburn 12078: $lifetime =~ s/^\s+|\s+$//g;
12079: if ($lifetime =~ /^\d+\.?\d*$/) {
12080: $confhash{$itemid}{$extra.'valid'} = $lifetime;
12081: }
12082: }
1.267 raeburn 12083: }
12084: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
12085: $changes{$itemid} = 1;
12086: }
1.319 raeburn 12087: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
12088: $changes{$itemid} = 1;
12089: }
1.267 raeburn 12090: }
1.273 raeburn 12091: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 12092: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 12093: if (grep(/^\Q$item\E$/,@courseconfig)) {
12094: $confhash{$itemid}{'crsconf'}{$item} = 1;
12095: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
12096: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
12097: $changes{$itemid} = 1;
12098: }
12099: } else {
12100: $changes{$itemid} = 1;
12101: }
12102: }
12103: }
1.267 raeburn 12104: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
12105: foreach my $field (@fields) {
12106: if ($possfield{$field}) {
12107: if ($field eq 'roles') {
12108: foreach my $role (@courseroles) {
12109: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
12110: if (($choice ne '') && ($posslti{$choice})) {
12111: $confhash{$itemid}{'roles'}{$role} = $choice;
12112: if ($role eq 'cc') {
12113: $confhash{$itemid}{'roles'}{'co'} = $choice;
12114: }
12115: }
12116: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
12117: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
12118: $changes{$itemid} = 1;
12119: }
12120: } elsif ($confhash{$itemid}{'roles'}{$role}) {
12121: $changes{$itemid} = 1;
12122: }
12123: }
12124: } else {
12125: $confhash{$itemid}{'fields'}{$field} = 1;
12126: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
12127: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
12128: $changes{$itemid} = 1;
12129: }
12130: } else {
12131: $changes{$itemid} = 1;
12132: }
12133: }
12134: }
12135: }
1.324 raeburn 12136: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
12137: if ($confhash{$itemid}{'fields'}{'user'}) {
12138: if ($env{'form.ltitools_userincdom_'.$i}) {
12139: $confhash{$itemid}{'incdom'} = 1;
12140: }
12141: if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
12142: $changes{$itemid} = 1;
12143: }
12144: }
12145: }
1.267 raeburn 12146: $allpos[$newpos] = $itemid;
12147: }
12148: if ($imgdeletions{$itemid}) {
12149: $changes{$itemid} = 1;
12150: #FIXME need to obsolete item in RES space
12151: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
12152: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
12153: $itemid,$configuserok,$switchserver,
12154: $author_ok);
12155: if ($imgurl) {
12156: $confhash{$itemid}{'image'} = $imgurl;
12157: $changes{$itemid} = 1;
12158: }
12159: if ($error) {
12160: &Apache::lonnet::logthis($error);
12161: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12162: }
12163: } elsif ($domconfig{$action}{$itemid}{'image'}) {
12164: $confhash{$itemid}{'image'} =
12165: $domconfig{$action}{$itemid}{'image'};
12166: }
12167: if ($customadds{$i}) {
12168: my $name = $env{'form.ltitools_custom_name_'.$i};
12169: $name =~ s/(`)/'/g;
12170: $name =~ s/^\s+//;
12171: $name =~ s/\s+$//;
12172: my $value = $env{'form.ltitools_custom_value_'.$i};
12173: $value =~ s/(`)/'/g;
12174: $value =~ s/^\s+//;
12175: $value =~ s/\s+$//;
12176: if ($name ne '') {
12177: $confhash{$itemid}{'custom'}{$name} = $value;
12178: $changes{$itemid} = 1;
12179: }
12180: }
12181: my %customdels;
12182: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
12183: if (@customdeletions) {
12184: $changes{$itemid} = 1;
12185: }
12186: map { $customdels{$_} = 1; } @customdeletions;
12187: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
12188: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
12189: unless ($customdels{$key}) {
12190: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
12191: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
12192: }
12193: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
12194: $changes{$itemid} = 1;
12195: }
12196: }
12197: }
12198: }
12199: unless ($changes{$itemid}) {
12200: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
12201: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
12202: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
12203: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
12204: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
12205: $changes{$itemid} = 1;
12206: last;
12207: }
12208: }
12209: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
12210: $changes{$itemid} = 1;
12211: }
12212: }
12213: last if ($changes{$itemid});
12214: }
12215: }
12216: }
12217: }
12218: }
12219: if (@allpos > 0) {
12220: my $idx = 0;
12221: foreach my $itemid (@allpos) {
12222: if ($itemid ne '') {
12223: $confhash{$itemid}{'order'} = $idx;
12224: if (ref($domconfig{$action}) eq 'HASH') {
12225: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12226: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
12227: $changes{$itemid} = 1;
12228: }
12229: }
12230: }
12231: $idx ++;
12232: }
12233: }
12234: }
12235: my %ltitoolshash = (
12236: $action => { %confhash }
12237: );
12238: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
12239: $dom);
12240: if ($putresult eq 'ok') {
1.297 raeburn 12241: my %ltienchash = (
12242: $action => { %encconfig }
12243: );
12244: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267 raeburn 12245: if (keys(%changes) > 0) {
12246: my $cachetime = 24*60*60;
1.297 raeburn 12247: my %ltiall = %confhash;
12248: foreach my $id (keys(%ltiall)) {
12249: if (ref($encconfig{$id}) eq 'HASH') {
12250: foreach my $item ('key','secret') {
12251: $ltiall{$id}{$item} = $encconfig{$id}{$item};
12252: }
12253: }
12254: }
12255: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 12256: if (ref($lastactref) eq 'HASH') {
12257: $lastactref->{'ltitools'} = 1;
12258: }
12259: $resulttext = &mt('Changes made:').'<ul>';
12260: my %bynum;
12261: foreach my $itemid (sort(keys(%changes))) {
12262: my $position = $confhash{$itemid}{'order'};
12263: $bynum{$position} = $itemid;
12264: }
12265: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
12266: my $itemid = $bynum{$pos};
12267: if (ref($confhash{$itemid}) ne 'HASH') {
12268: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
12269: } else {
12270: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
12271: if ($confhash{$itemid}{'image'}) {
12272: $resulttext .= ' '.
12273: '<img src="'.$confhash{$itemid}{'image'}.'"'.
12274: ' alt="'.&mt('Tool Provider icon').'" />';
12275: }
12276: $resulttext .= '</li><ul>';
12277: my $position = $pos + 1;
12278: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323 raeburn 12279: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267 raeburn 12280: if ($confhash{$itemid}{$item} ne '') {
12281: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
12282: }
12283: }
1.297 raeburn 12284: if ($encconfig{$itemid}{'key'} ne '') {
12285: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
12286: }
12287: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 12288: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 12289: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 12290: $resulttext .= ('*'x$num).'</li>';
12291: }
1.273 raeburn 12292: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 12293: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 12294: my $numconfig = 0;
12295: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
12296: foreach my $item (@possconfig) {
12297: if ($confhash{$itemid}{'crsconf'}{$item}) {
12298: $numconfig ++;
1.296 raeburn 12299: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 12300: }
12301: }
12302: }
12303: if (!$numconfig) {
12304: $resulttext .= &mt('None');
12305: }
12306: $resulttext .= '</li>';
1.267 raeburn 12307: foreach my $item ('passback','roster') {
12308: $resulttext .= '<li>'.$lt{$item}.' ';
12309: if ($confhash{$itemid}{$item}) {
12310: $resulttext .= &mt('Yes');
1.319 raeburn 12311: if ($confhash{$itemid}{$item.'valid'}) {
12312: if ($item eq 'passback') {
12313: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
12314: $confhash{$itemid}{$item.'valid'});
12315: } else {
12316: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
12317: $confhash{$itemid}{$item.'valid'});
12318: }
12319: }
1.267 raeburn 12320: } else {
12321: $resulttext .= &mt('No');
12322: }
12323: $resulttext .= '</li>';
12324: }
12325: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
12326: my $displaylist;
12327: if ($confhash{$itemid}{'display'}{'target'}) {
12328: $displaylist = &mt('Display target').': '.
12329: $confhash{$itemid}{'display'}{'target'}.',';
12330: }
12331: foreach my $size ('width','height') {
12332: if ($confhash{$itemid}{'display'}{$size}) {
12333: $displaylist .= (' 'x2).$lt{$size}.': '.
12334: $confhash{$itemid}{'display'}{$size}.',';
12335: }
12336: }
12337: if ($displaylist) {
12338: $displaylist =~ s/,$//;
12339: $resulttext .= '<li>'.$displaylist.'</li>';
12340: }
1.296 raeburn 12341: foreach my $item ('linktext','explanation') {
12342: if ($confhash{$itemid}{'display'}{$item}) {
12343: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
12344: }
12345: }
12346: }
1.267 raeburn 12347: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
12348: my $fieldlist;
12349: foreach my $field (@allfields) {
12350: if ($confhash{$itemid}{'fields'}{$field}) {
12351: $fieldlist .= (' 'x2).$lt{$field}.',';
12352: }
12353: }
12354: if ($fieldlist) {
12355: $fieldlist =~ s/,$//;
1.324 raeburn 12356: if ($confhash{$itemid}{'fields'}{'user'}) {
12357: if ($confhash{$itemid}{'incdom'}) {
12358: $fieldlist .= ' ('.&mt('username:domain').')';
12359: } else {
12360: $fieldlist .= ' ('.&mt('username').')';
12361: }
12362: }
1.267 raeburn 12363: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
12364: }
12365: }
12366: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
12367: my $rolemaps;
12368: foreach my $role (@courseroles) {
12369: if ($confhash{$itemid}{'roles'}{$role}) {
12370: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
12371: $confhash{$itemid}{'roles'}{$role}.',';
12372: }
12373: }
12374: if ($rolemaps) {
12375: $rolemaps =~ s/,$//;
12376: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
12377: }
12378: }
12379: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
12380: my $customlist;
12381: if (keys(%{$confhash{$itemid}{'custom'}})) {
12382: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
12383: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
12384: }
12385: }
12386: if ($customlist) {
1.317 raeburn 12387: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 12388: }
12389: }
12390: $resulttext .= '</ul></li>';
12391: }
12392: }
12393: $resulttext .= '</ul>';
12394: } else {
12395: $resulttext = &mt('No changes made.');
12396: }
12397: } else {
12398: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
12399: }
12400: if ($errors) {
12401: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12402: $errors.'</ul>';
12403: }
12404: return $resulttext;
12405: }
12406:
12407: sub process_ltitools_image {
12408: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
12409: my $filename = $env{'form.'.$caller.'.filename'};
12410: my ($error,$url);
12411: my ($width,$height) = (21,21);
12412: if ($configuserok eq 'ok') {
12413: if ($switchserver) {
12414: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
12415: $switchserver);
12416: } elsif ($author_ok eq 'ok') {
12417: my ($result,$imageurl,$madethumb) =
12418: &publishlogo($r,'upload',$caller,$dom,$confname,
12419: "ltitools/$itemid/icon",$width,$height);
12420: if ($result eq 'ok') {
12421: if ($madethumb) {
12422: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
12423: my $imagethumb = "$path/tn-".$imagefile;
12424: $url = $imagethumb;
12425: } else {
12426: $url = $imageurl;
12427: }
12428: } else {
12429: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
12430: }
12431: } else {
12432: $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);
12433: }
12434: } else {
12435: $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);
12436: }
12437: return ($url,$error);
12438: }
12439:
12440: sub get_ltitools_id {
12441: my ($cdom,$title) = @_;
12442: # get lock on ltitools db
12443: my $lockhash = {
12444: lock => $env{'user.name'}.
12445: ':'.$env{'user.domain'},
12446: };
12447: my $tries = 0;
12448: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
12449: my ($id,$error);
12450:
12451: while (($gotlock ne 'ok') && ($tries<10)) {
12452: $tries ++;
12453: sleep (0.1);
12454: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
12455: }
12456: if ($gotlock eq 'ok') {
12457: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
12458: if ($currids{'lock'}) {
12459: delete($currids{'lock'});
12460: if (keys(%currids)) {
12461: my @curr = sort { $a <=> $b } keys(%currids);
12462: if ($curr[-1] =~ /^\d+$/) {
12463: $id = 1 + $curr[-1];
12464: }
12465: } else {
12466: $id = 1;
12467: }
12468: if ($id) {
12469: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
12470: $error = 'nostore';
12471: }
12472: } else {
12473: $error = 'nonumber';
12474: }
12475: }
12476: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
12477: } else {
12478: $error = 'nolock';
12479: }
12480: return ($id,$error);
12481: }
12482:
1.320 raeburn 12483: sub modify_lti {
12484: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
12485: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12486: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
12487: my (%posslti,%posslticrs,%posscrstype);
12488: my @courseroles = ('cc','in','ta','ep','st');
12489: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
12490: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
12491: my @coursetypes = ('official','unofficial','community','textbook','placement');
12492: my %coursetypetitles = &Apache::lonlocal::texthash (
12493: official => 'Official',
12494: unofficial => 'Unofficial',
12495: community => 'Community',
12496: textbook => 'Textbook',
12497: placement => 'Placement Test',
12498: );
1.325 raeburn 12499: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 12500: my %lt = <i_names();
12501: map { $posslti{$_} = 1; } @ltiroles;
12502: map { $posslticrs{$_} = 1; } @lticourseroles;
12503: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 12504:
1.326 raeburn 12505: my %menutitles = <imenu_titles();
12506:
1.320 raeburn 12507: my (@items,%deletions,%itemids);
12508: if ($env{'form.lti_add'}) {
12509: my $consumer = $env{'form.lti_consumer_add'};
12510: $consumer =~ s/(`)/'/g;
12511: ($newid,my $error) = &get_lti_id($dom,$consumer);
12512: if ($newid) {
12513: $itemids{'add'} = $newid;
12514: push(@items,'add');
12515: $changes{$newid} = 1;
12516: } else {
12517: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
12518: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12519: }
12520: }
12521: if (ref($domconfig{$action}) eq 'HASH') {
12522: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
12523: if (@todelete) {
12524: map { $deletions{$_} = 1; } @todelete;
12525: }
12526: my $maxnum = $env{'form.lti_maxnum'};
12527: for (my $i=0; $i<=$maxnum; $i++) {
12528: my $itemid = $env{'form.lti_id_'.$i};
12529: $itemid =~ s/\D+//g;
12530: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12531: if ($deletions{$itemid}) {
12532: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
12533: } else {
12534: push(@items,$i);
12535: $itemids{$i} = $itemid;
12536: }
12537: }
12538: }
12539: }
12540: foreach my $idx (@items) {
12541: my $itemid = $itemids{$idx};
12542: next unless ($itemid);
12543: my $position = $env{'form.lti_pos_'.$idx};
12544: $position =~ s/\D+//g;
12545: if ($position ne '') {
12546: $allpos[$position] = $itemid;
12547: }
1.345 raeburn 12548: foreach my $item ('consumer','key','secret','lifetime','requser') {
1.320 raeburn 12549: my $formitem = 'form.lti_'.$item.'_'.$idx;
12550: $env{$formitem} =~ s/(`)/'/g;
12551: if ($item eq 'lifetime') {
12552: $env{$formitem} =~ s/[^\d.]//g;
12553: }
12554: if ($env{$formitem} ne '') {
12555: if (($item eq 'key') || ($item eq 'secret')) {
12556: $encconfig{$itemid}{$item} = $env{$formitem};
12557: } else {
12558: $confhash{$itemid}{$item} = $env{$formitem};
12559: unless (($idx eq 'add') || ($changes{$itemid})) {
12560: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
12561: $changes{$itemid} = 1;
12562: }
12563: }
12564: }
12565: }
12566: }
12567: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
12568: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
12569: }
1.345 raeburn 12570: if ($confhash{$itemid}{'requser'}) {
12571: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
12572: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
12573: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
12574: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
12575: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
12576: my $mapuser = $env{'form.lti_customuser_'.$idx};
12577: $mapuser =~ s/(`)/'/g;
12578: $mapuser =~ s/^\s+|\s+$//g;
12579: $confhash{$itemid}{'mapuser'} = $mapuser;
12580: }
12581: foreach my $ltirole (@lticourseroles) {
12582: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
12583: if (grep(/^\Q$possrole\E$/,@courseroles)) {
12584: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
12585: }
12586: }
12587: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
12588: my @makeuser;
12589: foreach my $ltirole (sort(@possmakeuser)) {
12590: if ($posslti{$ltirole}) {
12591: push(@makeuser,$ltirole);
12592: }
12593: }
12594: $confhash{$itemid}{'makeuser'} = \@makeuser;
12595: if (@makeuser) {
12596: my $lcauth = $env{'form.lti_lcauth_'.$idx};
12597: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
12598: $confhash{$itemid}{'lcauth'} = $lcauth;
12599: if ($lcauth ne 'internal') {
12600: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
12601: $lcauthparm =~ s/^(\s+|\s+)$//g;
12602: $lcauthparm =~ s/`//g;
12603: if ($lcauthparm ne '') {
12604: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
12605: }
12606: }
12607: } else {
12608: $confhash{$itemid}{'lcauth'} = 'lti';
12609: }
1.320 raeburn 12610: }
1.345 raeburn 12611: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
12612: if (@possinstdata) {
12613: foreach my $field (@possinstdata) {
12614: if (exists($fieldtitles{$field})) {
12615: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 12616: }
12617: }
12618: }
1.345 raeburn 12619: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
12620: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
12621: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
12622: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
12623: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
12624: $mapcrs =~ s/(`)/'/g;
12625: $mapcrs =~ s/^\s+|\s+$//g;
12626: $confhash{$itemid}{'mapcrs'} = $mapcrs;
12627: }
12628: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
12629: my @crstypes;
12630: foreach my $type (sort(@posstypes)) {
12631: if ($posscrstype{$type}) {
12632: push(@crstypes,$type);
1.325 raeburn 12633: }
12634: }
1.345 raeburn 12635: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
12636: if ($env{'form.lti_makecrs_'.$idx}) {
12637: $confhash{$itemid}{'makecrs'} = 1;
1.320 raeburn 12638: }
1.345 raeburn 12639: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
12640: my @selfenroll;
12641: foreach my $type (sort(@possenroll)) {
12642: if ($posslticrs{$type}) {
12643: push(@selfenroll,$type);
12644: }
1.320 raeburn 12645: }
1.345 raeburn 12646: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
12647: if ($env{'form.lti_crssec_'.$idx}) {
12648: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
12649: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
12650: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
12651: my $section = $env{'form.lti_customsection_'.$idx};
12652: $section =~ s/(`)/'/g;
12653: $section =~ s/^\s+|\s+$//g;
12654: if ($section ne '') {
12655: $confhash{$itemid}{'section'} = $section;
12656: }
1.320 raeburn 12657: }
12658: }
1.345 raeburn 12659: foreach my $field ('passback','roster','topmenu','inlinemenu') {
12660: if ($env{'form.lti_'.$field.'_'.$idx}) {
12661: $confhash{$itemid}{$field} = 1;
12662: }
1.320 raeburn 12663: }
1.345 raeburn 12664: if ($env{'form.lti_passback_'.$idx}) {
12665: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
12666: $confhash{$itemid}{'passbackformat'} = '1.0';
12667: } else {
12668: $confhash{$itemid}{'passbackformat'} = '1.1';
12669: }
1.337 raeburn 12670: }
1.345 raeburn 12671: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
12672: $confhash{$itemid}{lcmenu} = [];
12673: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
12674: foreach my $field (@possmenu) {
12675: if (exists($menutitles{$field})) {
12676: if ($field eq 'grades') {
12677: next unless ($env{'form.lti_inlinemenu_'.$idx});
12678: }
12679: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 12680: }
12681: }
12682: }
1.345 raeburn 12683: unless (($idx eq 'add') || ($changes{$itemid})) {
12684: foreach my $field ('mapuser','mapcrs','makecrs','section','passback','roster','lcauth','lcauthparm','topmenu','inlinemenu') {
12685: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.337 raeburn 12686: $changes{$itemid} = 1;
12687: }
12688: }
1.320 raeburn 12689: unless ($changes{$itemid}) {
1.345 raeburn 12690: if ($domconfig{$action}{$itemid}{'passback'} eq $confhash{$itemid}{'passback'}) {
12691: if ($domconfig{$action}{$itemid}{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 12692: $changes{$itemid} = 1;
12693: }
1.345 raeburn 12694: }
1.320 raeburn 12695: }
1.345 raeburn 12696: foreach my $field ('makeuser','mapcrstype','selfenroll','instdata','lcmenu') {
12697: unless ($changes{$itemid}) {
12698: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
12699: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
12700: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
12701: $confhash{$itemid}{$field});
12702: if (@diffs) {
12703: $changes{$itemid} = 1;
12704: }
12705: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
12706: $changes{$itemid} = 1;
12707: }
12708: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
12709: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 12710: $changes{$itemid} = 1;
12711: }
12712: }
1.345 raeburn 12713: }
12714: }
12715: unless ($changes{$itemid}) {
12716: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
12717: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
12718: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
12719: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
12720: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.320 raeburn 12721: $changes{$itemid} = 1;
12722: last;
12723: }
12724: }
1.345 raeburn 12725: unless ($changes{$itemid}) {
12726: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
12727: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
12728: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
12729: $changes{$itemid} = 1;
12730: last;
12731: }
12732: }
12733: }
12734: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
12735: $changes{$itemid} = 1;
1.320 raeburn 12736: }
1.345 raeburn 12737: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
12738: unless ($changes{$itemid}) {
12739: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
12740: $changes{$itemid} = 1;
12741: }
1.320 raeburn 12742: }
12743: }
12744: }
12745: }
12746: }
12747: }
12748: if (@allpos > 0) {
12749: my $idx = 0;
12750: foreach my $itemid (@allpos) {
12751: if ($itemid ne '') {
12752: $confhash{$itemid}{'order'} = $idx;
12753: if (ref($domconfig{$action}) eq 'HASH') {
12754: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12755: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
12756: $changes{$itemid} = 1;
12757: }
12758: }
12759: }
12760: $idx ++;
12761: }
12762: }
12763: }
12764: my %ltihash = (
12765: $action => { %confhash }
12766: );
12767: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
12768: $dom);
12769: if ($putresult eq 'ok') {
12770: my %ltienchash = (
12771: $action => { %encconfig }
12772: );
12773: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
12774: if (keys(%changes) > 0) {
12775: my $cachetime = 24*60*60;
12776: my %ltiall = %confhash;
12777: foreach my $id (keys(%ltiall)) {
12778: if (ref($encconfig{$id}) eq 'HASH') {
12779: foreach my $item ('key','secret') {
12780: $ltiall{$id}{$item} = $encconfig{$id}{$item};
12781: }
12782: }
12783: }
12784: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
12785: if (ref($lastactref) eq 'HASH') {
12786: $lastactref->{'lti'} = 1;
12787: }
12788: $resulttext = &mt('Changes made:').'<ul>';
12789: my %bynum;
12790: foreach my $itemid (sort(keys(%changes))) {
12791: my $position = $confhash{$itemid}{'order'};
12792: $bynum{$position} = $itemid;
12793: }
12794: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
12795: my $itemid = $bynum{$pos};
12796: if (ref($confhash{$itemid}) ne 'HASH') {
12797: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
12798: } else {
12799: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b></li><ul>';
12800: my $position = $pos + 1;
12801: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
12802: foreach my $item ('version','lifetime') {
12803: if ($confhash{$itemid}{$item} ne '') {
12804: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
12805: }
12806: }
12807: if ($encconfig{$itemid}{'key'} ne '') {
12808: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
12809: }
12810: if ($encconfig{$itemid}{'secret'} ne '') {
12811: $resulttext .= '<li>'.$lt{'secret'}.': ';
12812: my $num = length($encconfig{$itemid}{'secret'});
12813: $resulttext .= ('*'x$num).'</li>';
12814: }
1.345 raeburn 12815: if ($confhash{$itemid}{'requser'}) {
12816: if ($confhash{$itemid}{'mapuser'}) {
12817: my $shownmapuser;
12818: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
12819: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
12820: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
12821: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
12822: } else {
12823: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 12824: }
1.345 raeburn 12825: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 12826: }
1.345 raeburn 12827: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
12828: my $rolemaps;
12829: foreach my $role (@ltiroles) {
12830: if ($confhash{$itemid}{'maproles'}{$role}) {
12831: $rolemaps .= (' 'x2).$role.'='.
12832: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
12833: 'Course').',';
12834: }
12835: }
12836: if ($rolemaps) {
12837: $rolemaps =~ s/,$//;
12838: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
12839: }
12840: }
12841: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
12842: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
12843: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
12844: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
12845: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
12846: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
12847: } else {
12848: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
12849: $confhash{$itemid}{'lcauth'});
12850: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
12851: $resulttext .= '; '.&mt('a randomly generated password will be created');
12852: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
12853: if ($confhash{$itemid}{'lcauthparm'} ne '') {
12854: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
12855: }
12856: } else {
12857: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
12858: }
12859: }
12860: $resulttext .= '</li>';
12861: } else {
12862: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
12863: }
1.320 raeburn 12864: }
1.345 raeburn 12865: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
12866: if (@{$confhash{$itemid}{'instdata'}} > 0) {
12867: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
12868: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 12869: } else {
1.345 raeburn 12870: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 12871: }
1.320 raeburn 12872: }
1.345 raeburn 12873: if ($confhash{$itemid}{'mapcrs'}) {
12874: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
12875: }
12876: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
12877: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
12878: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
12879: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
12880: '</li>';
12881: } else {
12882: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
12883: }
1.325 raeburn 12884: }
1.345 raeburn 12885: if ($confhash{$itemid}{'makecrs'}) {
12886: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
1.320 raeburn 12887: } else {
1.345 raeburn 12888: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
1.320 raeburn 12889: }
1.345 raeburn 12890: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
12891: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
12892: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
12893: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
12894: '</li>';
12895: } else {
12896: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
12897: }
1.320 raeburn 12898: }
1.345 raeburn 12899: if ($confhash{$itemid}{'section'}) {
12900: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
12901: $resulttext .= '<li>'.&mt('User section from standard field:').
12902: ' (course_section_sourcedid)'.'</li>';
12903: } else {
12904: $resulttext .= '<li>'.&mt('User section from:').' '.
12905: $confhash{$itemid}{'section'}.'</li>';
12906: }
1.320 raeburn 12907: } else {
1.345 raeburn 12908: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
1.320 raeburn 12909: }
1.345 raeburn 12910: foreach my $item ('passback','roster','topmenu','inlinemenu') {
12911: $resulttext .= '<li>'.$lt{$item}.': ';
12912: if ($confhash{$itemid}{$item}) {
12913: $resulttext .= &mt('Yes');
12914: if ($item eq 'passback') {
12915: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
12916: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
12917: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
12918: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
12919: }
1.337 raeburn 12920: }
1.345 raeburn 12921: } else {
12922: $resulttext .= &mt('No');
1.337 raeburn 12923: }
1.345 raeburn 12924: $resulttext .= '</li>';
1.320 raeburn 12925: }
1.345 raeburn 12926: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
12927: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
12928: $resulttext .= '<li>'.&mt('Menu items:').' '.
12929: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
12930: } else {
12931: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
12932: }
1.326 raeburn 12933: }
12934: }
1.320 raeburn 12935: $resulttext .= '</ul></li>';
12936: }
12937: }
12938: $resulttext .= '</ul>';
12939: } else {
12940: $resulttext = &mt('No changes made.');
12941: }
12942: } else {
12943: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
12944: }
12945: if ($errors) {
12946: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12947: $errors.'</ul>';
12948: }
12949: return $resulttext;
12950: }
12951:
12952: sub get_lti_id {
12953: my ($domain,$consumer) = @_;
12954: # get lock on lti db
12955: my $lockhash = {
12956: lock => $env{'user.name'}.
12957: ':'.$env{'user.domain'},
12958: };
12959: my $tries = 0;
12960: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
12961: my ($id,$error);
12962:
12963: while (($gotlock ne 'ok') && ($tries<10)) {
12964: $tries ++;
12965: sleep (0.1);
12966: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
12967: }
12968: if ($gotlock eq 'ok') {
12969: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
12970: if ($currids{'lock'}) {
12971: delete($currids{'lock'});
12972: if (keys(%currids)) {
12973: my @curr = sort { $a <=> $b } keys(%currids);
12974: if ($curr[-1] =~ /^\d+$/) {
12975: $id = 1 + $curr[-1];
12976: }
12977: } else {
12978: $id = 1;
12979: }
12980: if ($id) {
12981: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
12982: $error = 'nostore';
12983: }
12984: } else {
12985: $error = 'nonumber';
12986: }
12987: }
12988: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
12989: } else {
12990: $error = 'nolock';
12991: }
12992: return ($id,$error);
12993: }
12994:
1.3 raeburn 12995: sub modify_autoenroll {
1.205 raeburn 12996: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 12997: my ($resulttext,%changes);
12998: my %currautoenroll;
12999: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
13000: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
13001: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
13002: }
13003: }
13004: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
13005: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 13006: sender => 'Sender for notification messages',
1.274 raeburn 13007: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
13008: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 13009: my @offon = ('off','on');
1.17 raeburn 13010: my $sender_uname = $env{'form.sender_uname'};
13011: my $sender_domain = $env{'form.sender_domain'};
13012: if ($sender_domain eq '') {
13013: $sender_uname = '';
13014: } elsif ($sender_uname eq '') {
13015: $sender_domain = '';
13016: }
1.129 raeburn 13017: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 13018: my $failsafe = $env{'form.autoenroll_failsafe'};
13019: $failsafe =~ s{^\s+|\s+$}{}g;
13020: if ($failsafe =~ /\D/) {
13021: undef($failsafe);
13022: }
1.1 raeburn 13023: my %autoenrollhash = (
1.129 raeburn 13024: autoenroll => { 'run' => $env{'form.autoenroll_run'},
13025: 'sender_uname' => $sender_uname,
13026: 'sender_domain' => $sender_domain,
13027: 'co-owners' => $coowners,
1.274 raeburn 13028: 'autofailsafe' => $failsafe,
1.1 raeburn 13029: }
13030: );
1.4 raeburn 13031: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
13032: $dom);
1.1 raeburn 13033: if ($putresult eq 'ok') {
13034: if (exists($currautoenroll{'run'})) {
13035: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
13036: $changes{'run'} = 1;
13037: }
13038: } elsif ($autorun) {
13039: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 13040: $changes{'run'} = 1;
1.1 raeburn 13041: }
13042: }
1.17 raeburn 13043: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 13044: $changes{'sender'} = 1;
13045: }
1.17 raeburn 13046: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 13047: $changes{'sender'} = 1;
13048: }
1.129 raeburn 13049: if ($currautoenroll{'co-owners'} ne '') {
13050: if ($currautoenroll{'co-owners'} ne $coowners) {
13051: $changes{'coowners'} = 1;
13052: }
13053: } elsif ($coowners) {
13054: $changes{'coowners'} = 1;
1.274 raeburn 13055: }
13056: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
13057: $changes{'autofailsafe'} = 1;
13058: }
1.1 raeburn 13059: if (keys(%changes) > 0) {
13060: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 13061: if ($changes{'run'}) {
1.1 raeburn 13062: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
13063: }
13064: if ($changes{'sender'}) {
1.17 raeburn 13065: if ($sender_uname eq '' || $sender_domain eq '') {
13066: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
13067: } else {
13068: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
13069: }
1.1 raeburn 13070: }
1.129 raeburn 13071: if ($changes{'coowners'}) {
13072: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
13073: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13074: if (ref($lastactref) eq 'HASH') {
13075: $lastactref->{'domainconfig'} = 1;
13076: }
1.129 raeburn 13077: }
1.274 raeburn 13078: if ($changes{'autofailsafe'}) {
13079: if ($failsafe ne '') {
1.299 raeburn 13080: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 13081: } else {
1.299 raeburn 13082: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 13083: }
13084: &Apache::lonnet::get_domain_defaults($dom,1);
13085: if (ref($lastactref) eq 'HASH') {
13086: $lastactref->{'domdefaults'} = 1;
13087: }
13088: }
1.1 raeburn 13089: $resulttext .= '</ul>';
13090: } else {
13091: $resulttext = &mt('No changes made to auto-enrollment settings');
13092: }
13093: } else {
1.11 albertel 13094: $resulttext = '<span class="LC_error">'.
13095: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13096: }
1.3 raeburn 13097: return $resulttext;
1.1 raeburn 13098: }
13099:
13100: sub modify_autoupdate {
1.3 raeburn 13101: my ($dom,%domconfig) = @_;
1.1 raeburn 13102: my ($resulttext,%currautoupdate,%fields,%changes);
13103: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
13104: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
13105: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
13106: }
13107: }
13108: my @offon = ('off','on');
13109: my %title = &Apache::lonlocal::texthash (
13110: run => 'Auto-update:',
13111: classlists => 'Updates to user information in classlists?'
13112: );
1.44 raeburn 13113: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 13114: my %fieldtitles = &Apache::lonlocal::texthash (
13115: id => 'Student/Employee ID',
1.20 raeburn 13116: permanentemail => 'E-mail address',
1.1 raeburn 13117: lastname => 'Last Name',
13118: firstname => 'First Name',
13119: middlename => 'Middle Name',
1.132 raeburn 13120: generation => 'Generation',
1.1 raeburn 13121: );
1.142 raeburn 13122: $othertitle = &mt('All users');
1.1 raeburn 13123: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 13124: $othertitle = &mt('Other users');
1.1 raeburn 13125: }
13126: foreach my $key (keys(%env)) {
13127: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 13128: my ($usertype,$item) = ($1,$2);
13129: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
13130: if ($usertype eq 'default') {
13131: push(@{$fields{$1}},$2);
13132: } elsif (ref($types) eq 'ARRAY') {
13133: if (grep(/^\Q$usertype\E$/,@{$types})) {
13134: push(@{$fields{$1}},$2);
13135: }
13136: }
13137: }
1.1 raeburn 13138: }
13139: }
1.131 raeburn 13140: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
13141: @lockablenames = sort(@lockablenames);
13142: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
13143: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
13144: if (@changed) {
13145: $changes{'lockablenames'} = 1;
13146: }
13147: } else {
13148: if (@lockablenames) {
13149: $changes{'lockablenames'} = 1;
13150: }
13151: }
1.1 raeburn 13152: my %updatehash = (
13153: autoupdate => { run => $env{'form.autoupdate_run'},
13154: classlists => $env{'form.classlists'},
13155: fields => {%fields},
1.131 raeburn 13156: lockablenames => \@lockablenames,
1.1 raeburn 13157: }
13158: );
13159: foreach my $key (keys(%currautoupdate)) {
13160: if (($key eq 'run') || ($key eq 'classlists')) {
13161: if (exists($updatehash{autoupdate}{$key})) {
13162: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
13163: $changes{$key} = 1;
13164: }
13165: }
13166: } elsif ($key eq 'fields') {
13167: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 13168: foreach my $item (@{$types},'default') {
1.1 raeburn 13169: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
13170: my $change = 0;
13171: foreach my $type (@{$currautoupdate{$key}{$item}}) {
13172: if (!exists($fields{$item})) {
13173: $change = 1;
1.132 raeburn 13174: last;
1.1 raeburn 13175: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 13176: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 13177: $change = 1;
1.132 raeburn 13178: last;
1.1 raeburn 13179: }
13180: }
13181: }
13182: if ($change) {
13183: push(@{$changes{$key}},$item);
13184: }
1.26 raeburn 13185: }
1.1 raeburn 13186: }
13187: }
1.131 raeburn 13188: } elsif ($key eq 'lockablenames') {
13189: if (ref($currautoupdate{$key}) eq 'ARRAY') {
13190: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
13191: if (@changed) {
13192: $changes{'lockablenames'} = 1;
13193: }
13194: } else {
13195: if (@lockablenames) {
13196: $changes{'lockablenames'} = 1;
13197: }
13198: }
13199: }
13200: }
13201: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
13202: if (@lockablenames) {
13203: $changes{'lockablenames'} = 1;
1.1 raeburn 13204: }
13205: }
1.26 raeburn 13206: foreach my $item (@{$types},'default') {
13207: if (defined($fields{$item})) {
13208: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 13209: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
13210: my $change = 0;
13211: if (ref($fields{$item}) eq 'ARRAY') {
13212: foreach my $type (@{$fields{$item}}) {
13213: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
13214: $change = 1;
13215: last;
13216: }
13217: }
13218: }
13219: if ($change) {
13220: push(@{$changes{'fields'}},$item);
13221: }
13222: } else {
1.26 raeburn 13223: push(@{$changes{'fields'}},$item);
13224: }
13225: } else {
13226: push(@{$changes{'fields'}},$item);
1.1 raeburn 13227: }
13228: }
13229: }
13230: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
13231: $dom);
13232: if ($putresult eq 'ok') {
13233: if (keys(%changes) > 0) {
13234: $resulttext = &mt('Changes made:').'<ul>';
13235: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 13236: if ($key eq 'lockablenames') {
13237: $resulttext .= '<li>';
13238: if (@lockablenames) {
13239: $usertypes->{'default'} = $othertitle;
13240: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
13241: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
13242: } else {
13243: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
13244: }
13245: $resulttext .= '</li>';
13246: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 13247: foreach my $item (@{$changes{$key}}) {
13248: my @newvalues;
13249: foreach my $type (@{$fields{$item}}) {
13250: push(@newvalues,$fieldtitles{$type});
13251: }
1.3 raeburn 13252: my $newvaluestr;
13253: if (@newvalues > 0) {
13254: $newvaluestr = join(', ',@newvalues);
13255: } else {
13256: $newvaluestr = &mt('none');
1.6 raeburn 13257: }
1.1 raeburn 13258: if ($item eq 'default') {
1.26 raeburn 13259: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 13260: } else {
1.26 raeburn 13261: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 13262: }
13263: }
13264: } else {
13265: my $newvalue;
13266: if ($key eq 'run') {
13267: $newvalue = $offon[$env{'form.autoupdate_run'}];
13268: } else {
13269: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 13270: }
1.1 raeburn 13271: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
13272: }
13273: }
13274: $resulttext .= '</ul>';
13275: } else {
1.3 raeburn 13276: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 13277: }
13278: } else {
1.11 albertel 13279: $resulttext = '<span class="LC_error">'.
13280: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13281: }
1.3 raeburn 13282: return $resulttext;
1.1 raeburn 13283: }
13284:
1.125 raeburn 13285: sub modify_autocreate {
13286: my ($dom,%domconfig) = @_;
13287: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
13288: if (ref($domconfig{'autocreate'}) eq 'HASH') {
13289: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
13290: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
13291: }
13292: }
13293: my %title= ( xml => 'Auto-creation of courses in XML course description files',
13294: req => 'Auto-creation of validated requests for official courses',
13295: xmldc => 'Identity of course creator of courses from XML files',
13296: );
13297: my @types = ('xml','req');
13298: foreach my $item (@types) {
13299: $newvals{$item} = $env{'form.autocreate_'.$item};
13300: $newvals{$item} =~ s/\D//g;
13301: $newvals{$item} = 0 if ($newvals{$item} eq '');
13302: }
13303: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 13304: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 13305: unless (exists($domcoords{$newvals{'xmldc'}})) {
13306: $newvals{'xmldc'} = '';
13307: }
13308: %autocreatehash = (
13309: autocreate => { xml => $newvals{'xml'},
13310: req => $newvals{'req'},
13311: }
13312: );
13313: if ($newvals{'xmldc'} ne '') {
13314: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
13315: }
13316: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
13317: $dom);
13318: if ($putresult eq 'ok') {
13319: my @items = @types;
13320: if ($newvals{'xml'}) {
13321: push(@items,'xmldc');
13322: }
13323: foreach my $item (@items) {
13324: if (exists($currautocreate{$item})) {
13325: if ($currautocreate{$item} ne $newvals{$item}) {
13326: $changes{$item} = 1;
13327: }
13328: } elsif ($newvals{$item}) {
13329: $changes{$item} = 1;
13330: }
13331: }
13332: if (keys(%changes) > 0) {
13333: my @offon = ('off','on');
13334: $resulttext = &mt('Changes made:').'<ul>';
13335: foreach my $item (@types) {
13336: if ($changes{$item}) {
13337: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 13338: $resulttext .= '<li>'.
13339: &mt("$title{$item} set to [_1]$newtxt [_2]",
13340: '<b>','</b>').
13341: '</li>';
1.125 raeburn 13342: }
13343: }
13344: if ($changes{'xmldc'}) {
13345: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
13346: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 13347: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 13348: }
13349: $resulttext .= '</ul>';
13350: } else {
13351: $resulttext = &mt('No changes made to auto-creation settings');
13352: }
13353: } else {
13354: $resulttext = '<span class="LC_error">'.
13355: &mt('An error occurred: [_1]',$putresult).'</span>';
13356: }
13357: return $resulttext;
13358: }
13359:
1.23 raeburn 13360: sub modify_directorysrch {
1.295 raeburn 13361: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 13362: my ($resulttext,%changes);
13363: my %currdirsrch;
13364: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
13365: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
13366: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
13367: }
13368: }
1.277 raeburn 13369: my %title = ( available => 'Institutional directory search available',
13370: localonly => 'Other domains can search institution',
13371: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 13372: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 13373: searchby => 'Search types',
13374: searchtypes => 'Search latitude');
13375: my @offon = ('off','on');
1.24 raeburn 13376: my @otherdoms = ('Yes','No');
1.23 raeburn 13377:
1.25 raeburn 13378: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 13379: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
13380: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
13381:
1.44 raeburn 13382: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 13383: if (keys(%{$usertypes}) == 0) {
13384: @cansearch = ('default');
13385: } else {
13386: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
13387: foreach my $type (@{$currdirsrch{'cansearch'}}) {
13388: if (!grep(/^\Q$type\E$/,@cansearch)) {
13389: push(@{$changes{'cansearch'}},$type);
13390: }
1.23 raeburn 13391: }
1.26 raeburn 13392: foreach my $type (@cansearch) {
13393: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
13394: push(@{$changes{'cansearch'}},$type);
13395: }
1.23 raeburn 13396: }
1.26 raeburn 13397: } else {
13398: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 13399: }
13400: }
13401:
13402: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
13403: foreach my $by (@{$currdirsrch{'searchby'}}) {
13404: if (!grep(/^\Q$by\E$/,@searchby)) {
13405: push(@{$changes{'searchby'}},$by);
13406: }
13407: }
13408: foreach my $by (@searchby) {
13409: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
13410: push(@{$changes{'searchby'}},$by);
13411: }
13412: }
13413: } else {
13414: push(@{$changes{'searchby'}},@searchby);
13415: }
1.25 raeburn 13416:
13417: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
13418: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
13419: if (!grep(/^\Q$type\E$/,@searchtypes)) {
13420: push(@{$changes{'searchtypes'}},$type);
13421: }
13422: }
13423: foreach my $type (@searchtypes) {
13424: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
13425: push(@{$changes{'searchtypes'}},$type);
13426: }
13427: }
13428: } else {
13429: if (exists($currdirsrch{'searchtypes'})) {
13430: foreach my $type (@searchtypes) {
13431: if ($type ne $currdirsrch{'searchtypes'}) {
13432: push(@{$changes{'searchtypes'}},$type);
13433: }
13434: }
13435: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
13436: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
13437: }
13438: } else {
13439: push(@{$changes{'searchtypes'}},@searchtypes);
13440: }
13441: }
13442:
1.23 raeburn 13443: my %dirsrch_hash = (
13444: directorysrch => { available => $env{'form.dirsrch_available'},
13445: cansearch => \@cansearch,
1.277 raeburn 13446: localonly => $env{'form.dirsrch_instlocalonly'},
13447: lclocalonly => $env{'form.dirsrch_domlocalonly'},
13448: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 13449: searchby => \@searchby,
1.25 raeburn 13450: searchtypes => \@searchtypes,
1.23 raeburn 13451: }
13452: );
13453: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
13454: $dom);
13455: if ($putresult eq 'ok') {
13456: if (exists($currdirsrch{'available'})) {
13457: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
13458: $changes{'available'} = 1;
13459: }
13460: } else {
13461: if ($env{'form.dirsrch_available'} eq '1') {
13462: $changes{'available'} = 1;
13463: }
13464: }
1.277 raeburn 13465: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 13466: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
13467: $changes{'lcavailable'} = 1;
13468: }
1.277 raeburn 13469: } else {
13470: if ($env{'form.dirsrch_lcavailable'} eq '1') {
13471: $changes{'lcavailable'} = 1;
13472: }
13473: }
1.24 raeburn 13474: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 13475: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
13476: $changes{'localonly'} = 1;
13477: }
1.24 raeburn 13478: } else {
1.277 raeburn 13479: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 13480: $changes{'localonly'} = 1;
13481: }
13482: }
1.277 raeburn 13483: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 13484: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
13485: $changes{'lclocalonly'} = 1;
13486: }
1.277 raeburn 13487: } else {
13488: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
13489: $changes{'lclocalonly'} = 1;
13490: }
13491: }
1.23 raeburn 13492: if (keys(%changes) > 0) {
13493: $resulttext = &mt('Changes made:').'<ul>';
13494: if ($changes{'available'}) {
13495: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
13496: }
1.277 raeburn 13497: if ($changes{'lcavailable'}) {
13498: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
13499: }
1.24 raeburn 13500: if ($changes{'localonly'}) {
1.277 raeburn 13501: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 13502: }
1.277 raeburn 13503: if ($changes{'lclocalonly'}) {
13504: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 13505: }
1.23 raeburn 13506: if (ref($changes{'cansearch'}) eq 'ARRAY') {
13507: my $chgtext;
1.26 raeburn 13508: if (ref($usertypes) eq 'HASH') {
13509: if (keys(%{$usertypes}) > 0) {
13510: foreach my $type (@{$types}) {
13511: if (grep(/^\Q$type\E$/,@cansearch)) {
13512: $chgtext .= $usertypes->{$type}.'; ';
13513: }
13514: }
13515: if (grep(/^default$/,@cansearch)) {
13516: $chgtext .= $othertitle;
13517: } else {
13518: $chgtext =~ s/\; $//;
13519: }
1.210 raeburn 13520: $resulttext .=
1.178 raeburn 13521: '<li>'.
13522: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
13523: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
13524: '</li>';
1.23 raeburn 13525: }
13526: }
13527: }
13528: if (ref($changes{'searchby'}) eq 'ARRAY') {
13529: my ($searchtitles,$titleorder) = &sorted_searchtitles();
13530: my $chgtext;
13531: foreach my $type (@{$titleorder}) {
13532: if (grep(/^\Q$type\E$/,@searchby)) {
13533: if (defined($searchtitles->{$type})) {
13534: $chgtext .= $searchtitles->{$type}.'; ';
13535: }
13536: }
13537: }
13538: $chgtext =~ s/\; $//;
13539: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
13540: }
1.25 raeburn 13541: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
13542: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
13543: my $chgtext;
13544: foreach my $type (@{$srchtypeorder}) {
13545: if (grep(/^\Q$type\E$/,@searchtypes)) {
13546: if (defined($srchtypes_desc->{$type})) {
13547: $chgtext .= $srchtypes_desc->{$type}.'; ';
13548: }
13549: }
13550: }
13551: $chgtext =~ s/\; $//;
1.178 raeburn 13552: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 13553: }
13554: $resulttext .= '</ul>';
1.295 raeburn 13555: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
13556: if (ref($lastactref) eq 'HASH') {
13557: $lastactref->{'directorysrch'} = 1;
13558: }
1.23 raeburn 13559: } else {
1.277 raeburn 13560: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 13561: }
13562: } else {
13563: $resulttext = '<span class="LC_error">'.
1.27 raeburn 13564: &mt('An error occurred: [_1]',$putresult).'</span>';
13565: }
13566: return $resulttext;
13567: }
13568:
1.28 raeburn 13569: sub modify_contacts {
1.205 raeburn 13570: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 13571: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
13572: if (ref($domconfig{'contacts'}) eq 'HASH') {
13573: foreach my $key (keys(%{$domconfig{'contacts'}})) {
13574: $currsetting{$key} = $domconfig{'contacts'}{$key};
13575: }
13576: }
1.286 raeburn 13577: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 13578: my @contacts = ('supportemail','adminemail');
1.286 raeburn 13579: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 13580: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 13581: my @toggles = ('reporterrors','reportupdates','reportstatus');
13582: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 13583: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 13584: foreach my $type (@mailings) {
13585: @{$newsetting{$type}} =
13586: &Apache::loncommon::get_env_multiple('form.'.$type);
13587: foreach my $item (@contacts) {
13588: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
13589: $contacts_hash{contacts}{$type}{$item} = 1;
13590: } else {
13591: $contacts_hash{contacts}{$type}{$item} = 0;
13592: }
1.289 raeburn 13593: }
1.28 raeburn 13594: $others{$type} = $env{'form.'.$type.'_others'};
13595: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 13596: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13597: $bcc{$type} = $env{'form.'.$type.'_bcc'};
13598: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 13599: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
13600: $includestr{$type} = $env{'form.'.$type.'_includestr'};
13601: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
13602: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
13603: }
1.134 raeburn 13604: }
1.28 raeburn 13605: }
13606: foreach my $item (@contacts) {
13607: $to{$item} = $env{'form.'.$item};
13608: $contacts_hash{'contacts'}{$item} = $to{$item};
13609: }
1.203 raeburn 13610: foreach my $item (@toggles) {
13611: if ($env{'form.'.$item} =~ /^(0|1)$/) {
13612: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
13613: }
13614: }
1.340 raeburn 13615: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
13616: foreach my $item (@lonstatus) {
13617: if ($item eq 'excluded') {
13618: my (%serverhomes,@excluded);
13619: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
13620: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
13621: if (@possexcluded) {
13622: foreach my $id (sort(@possexcluded)) {
13623: if ($serverhomes{$id}) {
13624: push(@excluded,$id);
13625: }
13626: }
13627: }
13628: if (@excluded) {
13629: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
13630: }
13631: } elsif ($item eq 'weights') {
13632: foreach my $type ('E','W','N') {
13633: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
13634: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
13635: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
13636: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
13637: $env{'form.error'.$item.'_'.$type};
13638: }
13639: }
13640: }
13641: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
13642: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
13643: if ($env{'form.error'.$item} =~ /^\d+$/) {
13644: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
13645: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
13646: }
13647: }
13648: }
13649: }
1.286 raeburn 13650: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
13651: foreach my $field (@{$fields}) {
13652: if (ref($possoptions->{$field}) eq 'ARRAY') {
13653: my $value = $env{'form.helpform_'.$field};
13654: $value =~ s/^\s+|\s+$//g;
13655: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 13656: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 13657: if ($field eq 'screenshot') {
13658: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
13659: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 13660: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 13661: }
13662: }
13663: }
13664: }
13665: }
13666: }
1.315 raeburn 13667: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13668: my (@statuses,%usertypeshash,@overrides);
13669: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
13670: @statuses = @{$types};
13671: if (ref($usertypes) eq 'HASH') {
13672: %usertypeshash = %{$usertypes};
13673: }
13674: }
13675: if (@statuses) {
13676: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
13677: foreach my $type (@possoverrides) {
13678: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
13679: push(@overrides,$type);
13680: }
13681: }
13682: if (@overrides) {
13683: foreach my $type (@overrides) {
13684: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
13685: foreach my $item (@contacts) {
13686: if (grep(/^\Q$item\E$/,@standard)) {
13687: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
13688: $newsetting{'override_'.$type}{$item} = 1;
13689: } else {
13690: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
13691: $newsetting{'override_'.$type}{$item} = 0;
13692: }
13693: }
13694: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
13695: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
13696: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
13697: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
13698: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
13699: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
13700: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
13701: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
13702: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
13703: }
13704: }
13705: }
13706: }
1.28 raeburn 13707: if (keys(%currsetting) > 0) {
13708: foreach my $item (@contacts) {
13709: if ($to{$item} ne $currsetting{$item}) {
13710: $changes{$item} = 1;
13711: }
13712: }
13713: foreach my $type (@mailings) {
13714: foreach my $item (@contacts) {
13715: if (ref($currsetting{$type}) eq 'HASH') {
13716: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
13717: push(@{$changes{$type}},$item);
13718: }
13719: } else {
13720: push(@{$changes{$type}},@{$newsetting{$type}});
13721: }
13722: }
13723: if ($others{$type} ne $currsetting{$type}{'others'}) {
13724: push(@{$changes{$type}},'others');
13725: }
1.289 raeburn 13726: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13727: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
13728: push(@{$changes{$type}},'bcc');
13729: }
1.286 raeburn 13730: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
13731: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
13732: push(@{$changes{$type}},'include');
13733: }
13734: }
13735: }
13736: if (ref($fields) eq 'ARRAY') {
13737: if (ref($currsetting{'helpform'}) eq 'HASH') {
13738: foreach my $field (@{$fields}) {
13739: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
13740: push(@{$changes{'helpform'}},$field);
13741: }
13742: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
13743: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
13744: push(@{$changes{'helpform'}},'maxsize');
13745: }
13746: }
13747: }
13748: } else {
13749: foreach my $field (@{$fields}) {
13750: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
13751: push(@{$changes{'helpform'}},$field);
13752: }
13753: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
13754: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
13755: push(@{$changes{'helpform'}},'maxsize');
13756: }
13757: }
13758: }
1.134 raeburn 13759: }
1.28 raeburn 13760: }
1.315 raeburn 13761: if (@statuses) {
13762: if (ref($currsetting{'overrides'}) eq 'HASH') {
13763: foreach my $key (keys(%{$currsetting{'overrides'}})) {
13764: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
13765: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
13766: foreach my $item (@contacts,'bcc','others','include') {
13767: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
13768: push(@{$changes{'overrides'}},$key);
13769: last;
13770: }
13771: }
13772: } else {
13773: push(@{$changes{'overrides'}},$key);
13774: }
13775: }
13776: }
13777: foreach my $key (@overrides) {
13778: unless (exists($currsetting{'overrides'}{$key})) {
13779: push(@{$changes{'overrides'}},$key);
13780: }
13781: }
13782: } else {
13783: foreach my $key (@overrides) {
13784: push(@{$changes{'overrides'}},$key);
13785: }
13786: }
13787: }
1.340 raeburn 13788: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
13789: foreach my $key ('excluded','weights','threshold','sysmail') {
13790: if ($key eq 'excluded') {
13791: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
13792: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
13793: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
13794: (@{$currsetting{'lonstatus'}{$key}})) {
13795: my @diffs =
13796: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
13797: $currsetting{'lonstatus'}{$key});
13798: if (@diffs) {
13799: push(@{$changes{'lonstatus'}},$key);
13800: }
13801: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
13802: push(@{$changes{'lonstatus'}},$key);
13803: }
13804: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
13805: (@{$currsetting{'lonstatus'}{$key}})) {
13806: push(@{$changes{'lonstatus'}},$key);
13807: }
13808: } elsif ($key eq 'weights') {
13809: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
13810: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
13811: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 13812: foreach my $type ('E','W','N','U') {
1.340 raeburn 13813: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
13814: $currsetting{'lonstatus'}{$key}{$type}) {
13815: push(@{$changes{'lonstatus'}},$key);
13816: last;
13817: }
13818: }
13819: } else {
1.341 raeburn 13820: foreach my $type ('E','W','N','U') {
1.340 raeburn 13821: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
13822: push(@{$changes{'lonstatus'}},$key);
13823: last;
13824: }
13825: }
13826: }
13827: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 13828: foreach my $type ('E','W','N','U') {
1.340 raeburn 13829: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
13830: push(@{$changes{'lonstatus'}},$key);
13831: last;
13832: }
13833: }
13834: }
13835: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
13836: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
13837: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
13838: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
13839: push(@{$changes{'lonstatus'}},$key);
13840: }
13841: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
13842: push(@{$changes{'lonstatus'}},$key);
13843: }
13844: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
13845: push(@{$changes{'lonstatus'}},$key);
13846: }
13847: }
13848: }
13849: } else {
13850: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
13851: foreach my $key ('excluded','weights','threshold','sysmail') {
13852: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
13853: push(@{$changes{'lonstatus'}},$key);
13854: }
13855: }
13856: }
13857: }
1.28 raeburn 13858: } else {
13859: my %default;
13860: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
13861: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
13862: $default{'errormail'} = 'adminemail';
13863: $default{'packagesmail'} = 'adminemail';
13864: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 13865: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 13866: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 13867: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 13868: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 13869: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 13870: foreach my $item (@contacts) {
13871: if ($to{$item} ne $default{$item}) {
1.286 raeburn 13872: $changes{$item} = 1;
1.203 raeburn 13873: }
1.28 raeburn 13874: }
13875: foreach my $type (@mailings) {
13876: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
13877: push(@{$changes{$type}},@{$newsetting{$type}});
13878: }
13879: if ($others{$type} ne '') {
13880: push(@{$changes{$type}},'others');
1.134 raeburn 13881: }
1.286 raeburn 13882: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13883: if ($bcc{$type} ne '') {
13884: push(@{$changes{$type}},'bcc');
13885: }
1.286 raeburn 13886: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
13887: push(@{$changes{$type}},'include');
13888: }
1.134 raeburn 13889: }
1.28 raeburn 13890: }
1.286 raeburn 13891: if (ref($fields) eq 'ARRAY') {
13892: foreach my $field (@{$fields}) {
13893: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
13894: push(@{$changes{'helpform'}},$field);
13895: }
13896: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
13897: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
13898: push(@{$changes{'helpform'}},'maxsize');
13899: }
13900: }
13901: }
1.289 raeburn 13902: }
1.340 raeburn 13903: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
13904: foreach my $key ('excluded','weights','threshold','sysmail') {
13905: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
13906: push(@{$changes{'lonstatus'}},$key);
13907: }
13908: }
13909: }
1.28 raeburn 13910: }
1.203 raeburn 13911: foreach my $item (@toggles) {
13912: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
13913: $changes{$item} = 1;
13914: } elsif ((!$env{'form.'.$item}) &&
13915: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
13916: $changes{$item} = 1;
13917: }
13918: }
1.28 raeburn 13919: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
13920: $dom);
13921: if ($putresult eq 'ok') {
13922: if (keys(%changes) > 0) {
1.205 raeburn 13923: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13924: if (ref($lastactref) eq 'HASH') {
13925: $lastactref->{'domainconfig'} = 1;
13926: }
1.28 raeburn 13927: my ($titles,$short_titles) = &contact_titles();
13928: $resulttext = &mt('Changes made:').'<ul>';
13929: foreach my $item (@contacts) {
13930: if ($changes{$item}) {
13931: $resulttext .= '<li>'.$titles->{$item}.
13932: &mt(' set to: ').
13933: '<span class="LC_cusr_emph">'.
13934: $to{$item}.'</span></li>';
13935: }
13936: }
13937: foreach my $type (@mailings) {
13938: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 13939: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 13940: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 13941: } else {
13942: $resulttext .= '<li>'.$titles->{$type}.': ';
13943: }
1.28 raeburn 13944: my @text;
13945: foreach my $item (@{$newsetting{$type}}) {
13946: push(@text,$short_titles->{$item});
13947: }
13948: if ($others{$type} ne '') {
13949: push(@text,$others{$type});
13950: }
1.286 raeburn 13951: if (@text) {
13952: $resulttext .= '<span class="LC_cusr_emph">'.
13953: join(', ',@text).'</span>';
13954: }
13955: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13956: if ($bcc{$type} ne '') {
1.286 raeburn 13957: my $bcctext;
13958: if (@text) {
1.289 raeburn 13959: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 13960: } else {
13961: $bcctext = '(Bcc)';
13962: }
13963: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
13964: } elsif (!@text) {
13965: $resulttext .= &mt('No one');
13966: }
1.289 raeburn 13967: if ($includestr{$type} ne '') {
1.286 raeburn 13968: if ($includeloc{$type} eq 'b') {
13969: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
13970: } elsif ($includeloc{$type} eq 's') {
13971: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
13972: }
1.134 raeburn 13973: }
1.286 raeburn 13974: } elsif (!@text) {
13975: $resulttext .= &mt('No recipients');
1.134 raeburn 13976: }
13977: $resulttext .= '</li>';
1.28 raeburn 13978: }
13979: }
1.315 raeburn 13980: if (ref($changes{'overrides'}) eq 'ARRAY') {
13981: my @deletions;
13982: foreach my $type (@{$changes{'overrides'}}) {
13983: if ($usertypeshash{$type}) {
13984: if (grep(/^\Q$type\E/,@overrides)) {
13985: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
13986: $usertypeshash{$type}).'<ul><li>';
13987: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
13988: my @text;
13989: foreach my $item (@contacts) {
13990: if ($newsetting{'override_'.$type}{$item}) {
13991: push(@text,$short_titles->{$item});
13992: }
13993: }
13994: if ($newsetting{'override_'.$type}{'others'} ne '') {
13995: push(@text,$newsetting{'override_'.$type}{'others'});
13996: }
13997:
13998: if (@text) {
13999: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
14000: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
14001: }
14002: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
14003: my $bcctext;
14004: if (@text) {
14005: $bcctext = ' '.&mt('with Bcc to');
14006: } else {
14007: $bcctext = '(Bcc)';
14008: }
14009: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
14010: } elsif (!@text) {
14011: $resulttext .= &mt('Helpdesk e-mail sent to no one');
14012: }
14013: $resulttext .= '</li>';
14014: if ($newsetting{'override_'.$type}{'include'} ne '') {
14015: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
14016: if ($loc eq 'b') {
14017: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
14018: } elsif ($loc eq 's') {
14019: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
14020: }
14021: }
14022: }
14023: $resulttext .= '</li></ul></li>';
14024: } else {
14025: push(@deletions,$usertypeshash{$type});
14026: }
14027: }
14028: }
14029: if (@deletions) {
14030: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
14031: join(', ',@deletions)).'</li>';
14032: }
14033: }
1.203 raeburn 14034: my @offon = ('off','on');
1.340 raeburn 14035: my $corelink = &core_link_msu();
1.203 raeburn 14036: if ($changes{'reporterrors'}) {
14037: $resulttext .= '<li>'.
14038: &mt('E-mail error reports to [_1] set to "'.
14039: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 14040: $corelink).
1.203 raeburn 14041: '</li>';
14042: }
14043: if ($changes{'reportupdates'}) {
14044: $resulttext .= '<li>'.
14045: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
14046: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 14047: $corelink).
1.203 raeburn 14048: '</li>';
14049: }
1.340 raeburn 14050: if ($changes{'reportstatus'}) {
14051: $resulttext .= '<li>'.
14052: &mt('E-mail status if errors above threshold to [_1] set to "'.
14053: $offon[$env{'form.reportstatus'}].'".',
14054: $corelink).
14055: '</li>';
14056: }
14057: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
14058: $resulttext .= '<li>'.
14059: &mt('Nightly status check e-mail settings').':<ul>';
14060: my (%defval,%use_def,%shown);
14061: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
14062: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
14063: $defval{'weights'} =
1.341 raeburn 14064: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 14065: $defval{'excluded'} = &mt('None');
14066: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
14067: foreach my $item ('threshold','sysmail','weights','excluded') {
14068: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
14069: if (($item eq 'threshold') || ($item eq 'sysmail')) {
14070: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
14071: } elsif ($item eq 'weights') {
14072: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 14073: foreach my $type ('E','W','N','U') {
1.340 raeburn 14074: $shown{$item} .= $lonstatus_names->{$type}.'=';
14075: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
14076: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
14077: } else {
14078: $shown{$item} .= $lonstatus_defs->{$type};
14079: }
14080: $shown{$item} .= ', ';
14081: }
14082: $shown{$item} =~ s/, $//;
14083: } else {
14084: $shown{$item} = $defval{$item};
14085: }
14086: } elsif ($item eq 'excluded') {
14087: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
14088: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
14089: } else {
14090: $shown{$item} = $defval{$item};
14091: }
14092: }
14093: } else {
14094: $shown{$item} = $defval{$item};
14095: }
14096: }
14097: } else {
14098: foreach my $item ('threshold','weights','excluded','sysmail') {
14099: $shown{$item} = $defval{$item};
14100: }
14101: }
14102: foreach my $item ('threshold','weights','excluded','sysmail') {
14103: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
14104: $shown{$item}).'</li>';
14105: }
14106: $resulttext .= '</ul></li>';
14107: }
1.286 raeburn 14108: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
14109: my (@optional,@required,@unused,$maxsizechg);
14110: foreach my $field (@{$changes{'helpform'}}) {
14111: if ($field eq 'maxsize') {
14112: $maxsizechg = 1;
14113: next;
14114: }
14115: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 14116: push(@optional,$field);
1.286 raeburn 14117: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
14118: push(@unused,$field);
14119: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 14120: push(@required,$field);
1.286 raeburn 14121: }
14122: }
14123: if (@optional) {
14124: $resulttext .= '<li>'.
14125: &mt('Help form fields changed to "Optional": [_1].',
14126: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
14127: '</li>';
14128: }
14129: if (@required) {
14130: $resulttext .= '<li>'.
14131: &mt('Help form fields changed to "Required": [_1].',
14132: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
14133: '</li>';
14134: }
14135: if (@unused) {
14136: $resulttext .= '<li>'.
14137: &mt('Help form fields changed to "Not shown": [_1].',
14138: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
14139: '</li>';
14140: }
14141: if ($maxsizechg) {
14142: $resulttext .= '<li>'.
14143: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
14144: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
14145: '</li>';
14146: }
14147: }
1.28 raeburn 14148: $resulttext .= '</ul>';
14149: } else {
1.288 raeburn 14150: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 14151: }
14152: } else {
14153: $resulttext = '<span class="LC_error">'.
14154: &mt('An error occurred: [_1].',$putresult).'</span>';
14155: }
14156: return $resulttext;
14157: }
14158:
1.357 raeburn 14159: sub modify_privacy {
14160: my ($dom,%domconfig) = @_;
14161: my ($resulttext,%current,%changes);
14162: if (ref($domconfig{'privacy'}) eq 'HASH') {
14163: %current = %{$domconfig{'privacy'}};
14164: }
14165: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
14166: my @items = ('domain','author','course','community');
14167: my %names = &Apache::lonlocal::texthash (
14168: domain => 'Assigned domain role(s)',
14169: author => 'Assigned co-author role(s)',
14170: course => 'Assigned course role(s)',
14171: community => 'Assigned community role',
14172: );
14173: my %roles = &Apache::lonlocal::texthash (
14174: domain => 'Domain role',
14175: author => 'Co-author role',
14176: course => 'Course role',
14177: community => 'Community role',
14178: );
14179: my %titles = &Apache::lonlocal::texthash (
14180: approval => 'Approval for role in different domain',
14181: othdom => 'User information available in other domain',
14182: priv => 'Information viewable by privileged user in same domain',
14183: unpriv => 'Information viewable by unprivileged user in same domain',
14184: instdom => 'Other domain shares institution/provider',
14185: extdom => 'Other domain has different institution/provider',
14186: none => 'Not allowed',
14187: user => 'User authorizes',
14188: domain => 'Domain Coordinator authorizes',
14189: auto => 'Unrestricted',
14190: );
14191: my %fieldnames = &Apache::lonlocal::texthash (
14192: id => 'Student/Employee ID',
14193: permanentemail => 'E-mail address',
14194: lastname => 'Last Name',
14195: firstname => 'First Name',
14196: middlename => 'Middle Name',
14197: generation => 'Generation',
14198: );
14199: my ($othertitle,$usertypes,$types) =
14200: &Apache::loncommon::sorted_inst_types($dom);
14201: my (%by_ip,%by_location,@intdoms,@instdoms);
14202: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
14203:
14204: my %privacyhash = (
14205: 'approval' => {
14206: instdom => {},
14207: extdom => {},
14208: },
14209: 'othdom' => {},
14210: 'priv' => {},
14211: 'unpriv' => {},
14212: );
14213: foreach my $item (@items) {
14214: if (@instdoms > 1) {
14215: if ($env{'form.privacy_approval_instdom'.$item} =~ /^(none|user|domain|auto)$/) {
14216: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
14217: }
14218: if (ref($current{'approval'}) eq 'HASH') {
14219: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
14220: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
14221: $changes{'approval'} = 1;
14222: }
14223: }
14224: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
14225: $changes{'approval'} = 1;
14226: }
14227: }
14228: if (keys(%by_location) > 0) {
14229: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
14230: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
14231: }
14232: if (ref($current{'approval'}) eq 'HASH') {
14233: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
14234: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
14235: $changes{'approval'} = 1;
14236: }
14237: }
14238: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
14239: $changes{'approval'} = 1;
14240: }
14241: }
14242: foreach my $status ('priv','unpriv') {
14243: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
14244: my @newvalues;
14245: foreach my $field (@possibles) {
14246: if (grep(/^\Q$field\E$/,@fields)) {
14247: $privacyhash{$status}{$item}{$field} = 1;
14248: push(@newvalues,$field);
14249: }
14250: }
14251: @newvalues = sort(@newvalues);
14252: if (ref($current{$status}) eq 'HASH') {
14253: if (ref($current{$status}{$item}) eq 'HASH') {
14254: my @currvalues = sort(keys(%{$current{$status}{$item}}));
14255: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
14256: if (@diffs > 0) {
14257: $changes{$status} = 1;
14258: }
14259: }
14260: } else {
14261: my @stdfields;
14262: foreach my $field (@fields) {
14263: if ($field eq 'id') {
14264: next if ($status eq 'unpriv');
14265: next if (($status eq 'priv') && ($item eq 'community'));
14266: }
14267: push(@stdfields,$field);
14268: }
14269: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
14270: if (@diffs > 0) {
14271: $changes{$status} = 1;
14272: }
14273: }
14274: }
14275: }
14276: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
14277: my @statuses;
14278: if (ref($types) eq 'ARRAY') {
14279: @statuses = @{$types};
14280: }
14281: foreach my $type (@statuses,'default') {
14282: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
14283: my @newvalues;
14284: foreach my $field (sort(@possfields)) {
14285: if (grep(/^\Q$field\E$/,@fields)) {
14286: $privacyhash{'othdom'}{$type}{$field} = 1;
14287: push(@newvalues,$field);
14288: }
14289: }
14290: @newvalues = sort(@newvalues);
14291: if (ref($current{'othdom'}) eq 'HASH') {
14292: if (ref($current{'othdom'}{$type}) eq 'HASH') {
14293: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
14294: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
14295: if (@diffs > 0) {
14296: $changes{'othdom'} = 1;
14297: }
14298: }
14299: } else {
14300: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
14301: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
14302: if (@diffs > 0) {
14303: $changes{'othdom'} = 1;
14304: }
14305: }
14306: }
14307: }
14308: my %confighash = (
14309: privacy => \%privacyhash,
14310: );
14311: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
14312: if ($putresult eq 'ok') {
14313: if (keys(%changes) > 0) {
14314: $resulttext = &mt('Changes made: ').'<ul>';
14315: foreach my $key ('approval','othdom','priv','unpriv') {
14316: if ($changes{$key}) {
14317: $resulttext .= '<li>'.$titles{$key}.':<ul>';
14318: if ($key eq 'approval') {
14319: if (keys(%{$privacyhash{$key}{instdom}})) {
14320: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
14321: foreach my $item (@items) {
14322: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
14323: }
14324: $resulttext .= '</ul></li>';
14325: }
14326: if (keys(%{$privacyhash{$key}{extdom}})) {
14327: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
14328: foreach my $item (@items) {
14329: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
14330: }
14331: $resulttext .= '</ul></li>';
14332: }
14333: } elsif ($key eq 'othdom') {
14334: my @statuses;
14335: if (ref($types) eq 'ARRAY') {
14336: @statuses = @{$types};
14337: }
14338: if (ref($privacyhash{$key}) eq 'HASH') {
14339: foreach my $status (@statuses,'default') {
14340: if ($status eq 'default') {
14341: $resulttext .= '<li>'.$othertitle.': ';
14342: } elsif (ref($usertypes) eq 'HASH') {
14343: $resulttext .= '<li>'.$usertypes->{$status}.': ';
14344: } else {
14345: next;
14346: }
14347: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
14348: if (keys(%{$privacyhash{$key}{$status}})) {
14349: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
14350: } else {
14351: $resulttext .= &mt('none');
14352: }
14353: }
14354: $resulttext .= '</li>';
14355: }
14356: }
14357: } else {
14358: foreach my $item (@items) {
14359: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
14360: $resulttext .= '<li>'.$names{$item}.': ';
14361: if (keys(%{$privacyhash{$key}{$item}})) {
14362: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
14363: } else {
14364: $resulttext .= &mt('none');
14365: }
14366: $resulttext .= '</li>';
14367: }
14368: }
14369: }
14370: $resulttext .= '</ul></li>';
14371: }
14372: }
14373: } else {
14374: $resulttext = &mt('No changes made to user information settings');
14375: }
14376: } else {
14377: $resulttext = '<span class="LC_error">'.
14378: &mt('An error occurred: [_1]',$putresult).'</span>';
14379: }
14380: return $resulttext;
14381: }
14382:
1.354 raeburn 14383: sub modify_passwords {
14384: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 14385: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
14386: $updatedefaults,$updateconf);
1.354 raeburn 14387: my $customfn = 'resetpw.html';
14388: if (ref($domconfig{'passwords'}) eq 'HASH') {
14389: %current = %{$domconfig{'passwords'}};
14390: }
14391: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14392: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14393: if (ref($types) eq 'ARRAY') {
14394: @oktypes = @{$types};
14395: }
14396: push(@oktypes,'default');
14397:
14398: my %titles = &Apache::lonlocal::texthash (
14399: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
14400: intauth_check => 'Check bcrypt cost if authenticated',
14401: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
14402: permanent => 'Permanent e-mail address',
14403: critical => 'Critical notification address',
14404: notify => 'Notification address',
14405: min => 'Minimum password length',
14406: max => 'Maximum password length',
14407: chars => 'Required characters',
14408: expire => 'Password expiration (days)',
1.356 raeburn 14409: numsaved => 'Number of previous passwords to save',
1.354 raeburn 14410: reset => 'Resetting Forgotten Password',
14411: intauth => 'Encryption of Stored Passwords (Internal Auth)',
14412: rules => 'Rules for LON-CAPA Passwords',
14413: crsownerchg => 'Course Owner Changing Student Passwords',
14414: username => 'Username',
14415: email => 'E-mail address',
14416: );
14417:
14418: #
14419: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
14420: #
14421: my (%curr_defaults,%save_defaults);
14422: if (ref($domconfig{'defaults'}) eq 'HASH') {
14423: foreach my $key (keys(%{$domconfig{'defaults'}})) {
14424: if ($key =~ /^intauth_(cost|check|switch)$/) {
14425: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
14426: } else {
14427: $save_defaults{$key} = $domconfig{'defaults'}{$key};
14428: }
14429: }
14430: }
14431: my %staticdefaults = (
14432: 'resetlink' => 2,
14433: 'resetcase' => \@oktypes,
14434: 'resetprelink' => 'both',
14435: 'resetemail' => ['critical','notify','permanent'],
14436: 'intauth_cost' => 10,
14437: 'intauth_check' => 0,
14438: 'intauth_switch' => 0,
14439: 'min' => 7,
14440: );
14441: foreach my $type (@oktypes) {
14442: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
14443: }
14444: my $linklife = $env{'form.passwords_link'};
14445: $linklife =~ s/^\s+|\s+$//g;
14446: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
14447: $newvalues{'resetlink'} = $linklife;
14448: if ($current{'resetlink'}) {
14449: if ($current{'resetlink'} ne $linklife) {
14450: $changes{'reset'} = 1;
14451: }
14452: } elsif (!exists($domconfig{passwords})) {
14453: if ($staticdefaults{'resetlink'} ne $linklife) {
14454: $changes{'reset'} = 1;
14455: }
14456: }
14457: } elsif ($current{'resetlink'}) {
14458: $changes{'reset'} = 1;
14459: }
14460: my @casesens;
14461: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
14462: foreach my $case (sort(@posscase)) {
14463: if (grep(/^\Q$case\E$/,@oktypes)) {
14464: push(@casesens,$case);
14465: }
14466: }
14467: $newvalues{'resetcase'} = \@casesens;
14468: if (ref($current{'resetcase'}) eq 'ARRAY') {
14469: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
14470: if (@diffs > 0) {
14471: $changes{'reset'} = 1;
14472: }
14473: } elsif (!exists($domconfig{passwords})) {
14474: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
14475: if (@diffs > 0) {
14476: $changes{'reset'} = 1;
14477: }
14478: }
14479: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
14480: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
14481: if (exists($current{'resetprelink'})) {
14482: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
14483: $changes{'reset'} = 1;
14484: }
14485: } elsif (!exists($domconfig{passwords})) {
14486: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
14487: $changes{'reset'} = 1;
14488: }
14489: }
14490: } elsif ($current{'resetprelink'}) {
14491: $changes{'reset'} = 1;
14492: }
14493: foreach my $type (@oktypes) {
14494: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
14495: my @postlink;
14496: foreach my $item (sort(@possplink)) {
14497: if ($item =~ /^(email|username)$/) {
14498: push(@postlink,$item);
14499: }
14500: }
14501: $newvalues{'resetpostlink'}{$type} = \@postlink;
14502: unless ($changes{'reset'}) {
14503: if (ref($current{'resetpostlink'}) eq 'HASH') {
14504: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
14505: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
14506: if (@diffs > 0) {
14507: $changes{'reset'} = 1;
14508: }
14509: } else {
14510: $changes{'reset'} = 1;
14511: }
14512: } elsif (!exists($domconfig{passwords})) {
14513: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
14514: if (@diffs > 0) {
14515: $changes{'reset'} = 1;
14516: }
14517: }
14518: }
14519: }
14520: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
14521: my @resetemail;
14522: foreach my $item (sort(@possemailsrc)) {
14523: if ($item =~ /^(permanent|critical|notify)$/) {
14524: push(@resetemail,$item);
14525: }
14526: }
14527: $newvalues{'resetemail'} = \@resetemail;
14528: unless ($changes{'reset'}) {
14529: if (ref($current{'resetemail'}) eq 'ARRAY') {
14530: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
14531: if (@diffs > 0) {
14532: $changes{'reset'} = 1;
14533: }
14534: } elsif (!exists($domconfig{passwords})) {
14535: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
14536: if (@diffs > 0) {
14537: $changes{'reset'} = 1;
14538: }
14539: }
14540: }
14541: if ($env{'form.passwords_stdtext'} == 0) {
14542: $newvalues{'resetremove'} = 1;
14543: unless ($current{'resetremove'}) {
14544: $changes{'reset'} = 1;
14545: }
14546: } elsif ($current{'resetremove'}) {
14547: $changes{'reset'} = 1;
14548: }
14549: if ($env{'form.passwords_customfile.filename'} ne '') {
14550: my $servadm = $r->dir_config('lonAdmEMail');
14551: my ($configuserok,$author_ok,$switchserver) =
14552: &config_check($dom,$confname,$servadm);
14553: my $error;
14554: if ($configuserok eq 'ok') {
14555: if ($switchserver) {
14556: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
14557: } else {
14558: if ($author_ok eq 'ok') {
14559: my ($result,$customurl) =
14560: &publishlogo($r,'upload','passwords_customfile',$dom,
14561: $confname,'customtext/resetpw','','',$customfn);
14562: if ($result eq 'ok') {
14563: $newvalues{'resetcustom'} = $customurl;
14564: $changes{'reset'} = 1;
14565: } else {
14566: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
14567: }
14568: } else {
14569: $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);
14570: }
14571: }
14572: } else {
14573: $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);
14574: }
14575: if ($error) {
14576: &Apache::lonnet::logthis($error);
14577: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14578: }
14579: } elsif ($current{'resetcustom'}) {
14580: if ($env{'form.passwords_custom_del'}) {
14581: $changes{'reset'} = 1;
14582: } else {
14583: $newvalues{'resetcustom'} = $current{'resetcustom'};
14584: }
14585: }
14586: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
14587: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
14588: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
14589: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
14590: $changes{'intauth'} = 1;
14591: }
14592: } else {
14593: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
14594: }
14595: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
14596: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
14597: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
14598: $changes{'intauth'} = 1;
14599: }
14600: } else {
14601: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
14602: }
14603: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
14604: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
14605: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
14606: $changes{'intauth'} = 1;
14607: }
14608: } else {
14609: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
14610: }
14611: foreach my $item ('cost','check','switch') {
14612: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
14613: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
14614: $updatedefaults = 1;
14615: }
14616: }
1.356 raeburn 14617: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 14618: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.356 raeburn 14619: my $ruleok;
14620: if ($rule eq 'expire') {
14621: if ($env{'form.passwords_'.$rule} =~ /^\d+(|\.\d*)$/) {
1.359 ! raeburn 14622: $ruleok = 1;
1.356 raeburn 14623: }
14624: } elsif ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
14625: $ruleok = 1;
14626: }
14627: if ($ruleok) {
1.354 raeburn 14628: $newvalues{$rule} = $env{'form.passwords_'.$rule};
14629: if (exists($current{$rule})) {
14630: if ($newvalues{$rule} ne $current{$rule}) {
14631: $changes{'rules'} = 1;
14632: }
14633: } elsif ($rule eq 'min') {
14634: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
14635: $changes{'rules'} = 1;
14636: }
14637: }
14638: } elsif (exists($current{$rule})) {
14639: $changes{'rules'} = 1;
14640: }
14641: }
14642: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
14643: my @chars;
14644: foreach my $item (sort(@posschars)) {
14645: if ($item =~ /^(uc|lc|num|spec)$/) {
14646: push(@chars,$item);
14647: }
14648: }
14649: $newvalues{'chars'} = \@chars;
14650: unless ($changes{'rules'}) {
14651: if (ref($current{'chars'}) eq 'ARRAY') {
14652: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
14653: if (@diffs > 0) {
14654: $changes{'rules'} = 1;
14655: }
14656: } else {
14657: if (@chars > 0) {
14658: $changes{'rules'} = 1;
14659: }
14660: }
14661: }
1.359 ! raeburn 14662: my %crsownerchg = (
! 14663: by => [],
! 14664: for => [],
! 14665: );
! 14666: foreach my $item ('by','for') {
! 14667: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
! 14668: foreach my $type (sort(@posstypes)) {
! 14669: if (grep(/^\Q$type\E$/,@oktypes)) {
! 14670: push(@{$crsownerchg{$item}},$type);
! 14671: }
! 14672: }
! 14673: }
! 14674: $newvalues{'crsownerchg'} = \%crsownerchg;
! 14675: if (ref($current{'crsownerchg'}) eq 'HASH') {
! 14676: foreach my $item ('by','for') {
! 14677: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
! 14678: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
! 14679: if (@diffs > 0) {
! 14680: $changes{'crsownerchg'} = 1;
! 14681: last;
! 14682: }
! 14683: }
! 14684: }
! 14685: } elsif (!exists($domconfig{passwords})) {
! 14686: foreach my $item ('by','for') {
! 14687: if (@{$crsownerchg{$item}} > 0) {
! 14688: $changes{'crsownerchg'} = 1;
! 14689: last;
! 14690: }
1.354 raeburn 14691: }
14692: }
14693:
14694: my %confighash = (
14695: defaults => \%save_defaults,
14696: passwords => \%newvalues,
14697: );
14698: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
14699:
14700: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
14701: if ($putresult eq 'ok') {
14702: if (keys(%changes) > 0) {
14703: $resulttext = &mt('Changes made: ').'<ul>';
14704: foreach my $key ('reset','intauth','rules','crsownerchg') {
14705: if ($changes{$key}) {
1.355 raeburn 14706: unless ($key eq 'intauth') {
14707: $updateconf = 1;
14708: }
1.354 raeburn 14709: $resulttext .= '<li>'.$titles{$key}.':<ul>';
14710: if ($key eq 'reset') {
14711: if ($confighash{'passwords'}{'captcha'} eq 'original') {
14712: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
14713: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
14714: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
14715: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />'.
14716: &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchapub'}).'</br>'.
14717: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchapriv'}).'</li>';
14718: } else {
14719: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
14720: }
14721: if ($confighash{'passwords'}{'resetlink'}) {
14722: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
14723: } else {
14724: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
14725: &mt('Will default to 2 hours').'</li>';
14726: }
14727: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
14728: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
14729: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
14730: } else {
14731: my $casesens;
14732: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
14733: if ($type eq 'default') {
14734: $casesens .= $othertitle.', ';
14735: } elsif ($usertypes->{$type} ne '') {
14736: $casesens .= $usertypes->{$type}.', ';
14737: }
14738: }
14739: $casesens =~ s/\Q, \E$//;
14740: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
14741: }
14742: } else {
14743: $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>';
14744: }
14745: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
14746: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
14747: } else {
14748: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
14749: }
14750: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
14751: my $output;
14752: if (ref($types) eq 'ARRAY') {
14753: foreach my $type (@{$types}) {
14754: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
14755: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
14756: $output .= $usertypes->{$type}.' -- '.&mt('none');
14757: } else {
14758: $output .= $usertypes->{$type}.' -- '.
14759: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
14760: }
14761: }
14762: }
14763: }
14764: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
14765: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
14766: $output .= $othertitle.' -- '.&mt('none');
14767: } else {
14768: $output .= $othertitle.' -- '.
14769: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
14770: }
14771: }
14772: if ($output) {
14773: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
14774: } else {
14775: $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>';
14776: }
14777: } else {
14778: $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>';
14779: }
14780: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
14781: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
14782: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
14783: } else {
14784: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
14785: }
14786: } else {
14787: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA usedfor verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
14788: }
14789: if ($confighash{'passwords'}{'resetremove'}) {
14790: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
14791: } else {
14792: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
14793: }
14794: if ($confighash{'passwords'}{'resetcustom'}) {
14795: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
14796: $titles{custom},600,500);
14797: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes [_1]',$customlink).'</li>';
14798: } else {
14799: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
14800: }
14801: } elsif ($key eq 'intauth') {
14802: foreach my $item ('cost','switch','check') {
14803: my $value = $save_defaults{$key.'_'.$item};
14804: if ($item eq 'switch') {
14805: my %optiondesc = &Apache::lonlocal::texthash (
14806: 0 => 'No',
14807: 1 => 'Yes',
14808: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
14809: );
14810: if ($value =~ /^(0|1|2)$/) {
14811: $value = $optiondesc{$value};
14812: } else {
14813: $value = &mt('none -- defaults to No');
14814: }
14815: } elsif ($item eq 'check') {
14816: my %optiondesc = &Apache::lonlocal::texthash (
14817: 0 => 'No',
14818: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
14819: 2 => 'Yes, disallow login if stored cost is less than domain default',
14820: );
14821: if ($value =~ /^(0|1|2)$/) {
14822: $value = $optiondesc{$value};
14823: } else {
14824: $value = &mt('none -- defaults to No');
14825: }
14826: }
14827: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
14828: }
14829: } elsif ($key eq 'rules') {
1.356 raeburn 14830: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 14831: if ($confighash{'passwords'}{$rule} eq '') {
14832: if ($rule eq 'min') {
1.356 raeburn 14833: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
14834: ' '.&mt('Default of 7 will be used').'</li>';
14835: } else {
14836: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 14837: }
14838: } else {
14839: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
14840: }
14841: }
14842: } elsif ($key eq 'crsownerchg') {
1.359 ! raeburn 14843: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
! 14844: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
! 14845: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
! 14846: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
! 14847: } else {
! 14848: my %crsownerstr;
! 14849: foreach my $item ('by','for') {
! 14850: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
! 14851: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
! 14852: if ($type eq 'default') {
! 14853: $crsownerstr{$item} .= $othertitle.', ';
! 14854: } elsif ($usertypes->{$type} ne '') {
! 14855: $crsownerstr{$item} .= $usertypes->{$type}.', ';
! 14856: }
! 14857: }
! 14858: $crsownerstr{$item} =~ s/\Q, \E$//;
! 14859: }
! 14860: }
! 14861: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
! 14862: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
! 14863: }
1.354 raeburn 14864: } else {
1.359 ! raeburn 14865: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 14866: }
14867: }
14868: $resulttext .= '</ul></li>';
14869: }
14870: }
14871: $resulttext .= '</ul>';
14872: } else {
14873: $resulttext = &mt('No changes made to password settings');
14874: }
1.355 raeburn 14875: my $cachetime = 24*60*60;
1.354 raeburn 14876: if ($updatedefaults) {
14877: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14878: if (ref($lastactref) eq 'HASH') {
14879: $lastactref->{'domdefaults'} = 1;
14880: }
14881: }
1.355 raeburn 14882: if ($updateconf) {
14883: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
14884: if (ref($lastactref) eq 'HASH') {
14885: $lastactref->{'passwdconf'} = 1;
14886: }
14887: }
1.354 raeburn 14888: } else {
14889: $resulttext = '<span class="LC_error">'.
14890: &mt('An error occurred: [_1]',$putresult).'</span>';
14891: }
14892: if ($errors) {
14893: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
14894: $errors.'</ul></p>';
14895: }
14896: return $resulttext;
14897: }
14898:
1.28 raeburn 14899: sub modify_usercreation {
1.27 raeburn 14900: my ($dom,%domconfig) = @_;
1.224 raeburn 14901: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 14902: my $warningmsg;
1.27 raeburn 14903: if (ref($domconfig{'usercreation'}) eq 'HASH') {
14904: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 14905: if ($key eq 'cancreate') {
14906: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
14907: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 14908: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
14909: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
14910: } else {
1.224 raeburn 14911: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
14912: }
14913: }
14914: }
14915: } elsif ($key eq 'email_rule') {
14916: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
14917: } else {
14918: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
14919: }
1.27 raeburn 14920: }
14921: }
14922: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 14923: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 14924: my @contexts = ('author','course','requestcrs');
1.34 raeburn 14925: foreach my $item(@contexts) {
1.224 raeburn 14926: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 14927: }
1.34 raeburn 14928: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
14929: foreach my $item (@contexts) {
1.224 raeburn 14930: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
14931: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 14932: }
1.27 raeburn 14933: }
1.34 raeburn 14934: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
14935: foreach my $item (@contexts) {
1.43 raeburn 14936: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 14937: if ($cancreate{$item} ne 'any') {
14938: push(@{$changes{'cancreate'}},$item);
14939: }
14940: } else {
14941: if ($cancreate{$item} ne 'none') {
14942: push(@{$changes{'cancreate'}},$item);
14943: }
1.27 raeburn 14944: }
14945: }
14946: } else {
1.43 raeburn 14947: foreach my $item (@contexts) {
1.34 raeburn 14948: push(@{$changes{'cancreate'}},$item);
14949: }
1.27 raeburn 14950: }
1.34 raeburn 14951:
1.27 raeburn 14952: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
14953: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
14954: if (!grep(/^\Q$type\E$/,@username_rule)) {
14955: push(@{$changes{'username_rule'}},$type);
14956: }
14957: }
14958: foreach my $type (@username_rule) {
14959: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
14960: push(@{$changes{'username_rule'}},$type);
14961: }
14962: }
14963: } else {
14964: push(@{$changes{'username_rule'}},@username_rule);
14965: }
14966:
1.32 raeburn 14967: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
14968: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
14969: if (!grep(/^\Q$type\E$/,@id_rule)) {
14970: push(@{$changes{'id_rule'}},$type);
14971: }
14972: }
14973: foreach my $type (@id_rule) {
14974: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
14975: push(@{$changes{'id_rule'}},$type);
14976: }
14977: }
14978: } else {
14979: push(@{$changes{'id_rule'}},@id_rule);
14980: }
14981:
1.43 raeburn 14982: my @authen_contexts = ('author','course','domain');
1.325 raeburn 14983: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 14984: my %authhash;
1.43 raeburn 14985: foreach my $item (@authen_contexts) {
1.28 raeburn 14986: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
14987: foreach my $auth (@authtypes) {
14988: if (grep(/^\Q$auth\E$/,@authallowed)) {
14989: $authhash{$item}{$auth} = 1;
14990: } else {
14991: $authhash{$item}{$auth} = 0;
14992: }
14993: }
14994: }
14995: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 14996: foreach my $item (@authen_contexts) {
1.28 raeburn 14997: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
14998: foreach my $auth (@authtypes) {
14999: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
15000: push(@{$changes{'authtypes'}},$item);
15001: last;
15002: }
15003: }
15004: }
15005: }
15006: } else {
1.43 raeburn 15007: foreach my $item (@authen_contexts) {
1.28 raeburn 15008: push(@{$changes{'authtypes'}},$item);
15009: }
15010: }
15011:
1.224 raeburn 15012: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
15013: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
15014: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
15015: $save_usercreate{'id_rule'} = \@id_rule;
15016: $save_usercreate{'username_rule'} = \@username_rule,
15017: $save_usercreate{'authtypes'} = \%authhash;
15018:
1.27 raeburn 15019: my %usercreation_hash = (
1.224 raeburn 15020: usercreation => \%save_usercreate,
15021: );
1.27 raeburn 15022:
15023: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
15024: $dom);
1.50 raeburn 15025:
1.224 raeburn 15026: if ($putresult eq 'ok') {
15027: if (keys(%changes) > 0) {
15028: $resulttext = &mt('Changes made:').'<ul>';
15029: if (ref($changes{'cancreate'}) eq 'ARRAY') {
15030: my %lt = &usercreation_types();
15031: foreach my $type (@{$changes{'cancreate'}}) {
15032: my $chgtext = $lt{$type}.', ';
15033: if ($cancreate{$type} eq 'none') {
15034: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
15035: } elsif ($cancreate{$type} eq 'any') {
15036: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
15037: } elsif ($cancreate{$type} eq 'official') {
15038: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
15039: } elsif ($cancreate{$type} eq 'unofficial') {
15040: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
15041: }
15042: $resulttext .= '<li>'.$chgtext.'</li>';
15043: }
15044: }
15045: if (ref($changes{'username_rule'}) eq 'ARRAY') {
15046: my ($rules,$ruleorder) =
15047: &Apache::lonnet::inst_userrules($dom,'username');
15048: my $chgtext = '<ul>';
15049: foreach my $type (@username_rule) {
15050: if (ref($rules->{$type}) eq 'HASH') {
15051: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
15052: }
15053: }
15054: $chgtext .= '</ul>';
15055: if (@username_rule > 0) {
15056: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
15057: } else {
15058: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
15059: }
15060: }
15061: if (ref($changes{'id_rule'}) eq 'ARRAY') {
15062: my ($idrules,$idruleorder) =
15063: &Apache::lonnet::inst_userrules($dom,'id');
15064: my $chgtext = '<ul>';
15065: foreach my $type (@id_rule) {
15066: if (ref($idrules->{$type}) eq 'HASH') {
15067: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
15068: }
15069: }
15070: $chgtext .= '</ul>';
15071: if (@id_rule > 0) {
15072: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
15073: } else {
15074: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
15075: }
15076: }
15077: my %authname = &authtype_names();
15078: my %context_title = &context_names();
15079: if (ref($changes{'authtypes'}) eq 'ARRAY') {
15080: my $chgtext = '<ul>';
15081: foreach my $type (@{$changes{'authtypes'}}) {
15082: my @allowed;
15083: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
15084: foreach my $auth (@authtypes) {
15085: if ($authhash{$type}{$auth}) {
15086: push(@allowed,$authname{$auth});
15087: }
15088: }
15089: if (@allowed > 0) {
15090: $chgtext .= join(', ',@allowed).'</li>';
15091: } else {
15092: $chgtext .= &mt('none').'</li>';
15093: }
15094: }
15095: $chgtext .= '</ul>';
15096: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
15097: $resulttext .= '</li>';
15098: }
15099: $resulttext .= '</ul>';
15100: } else {
15101: $resulttext = &mt('No changes made to user creation settings');
15102: }
15103: } else {
15104: $resulttext = '<span class="LC_error">'.
15105: &mt('An error occurred: [_1]',$putresult).'</span>';
15106: }
15107: if ($warningmsg ne '') {
15108: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
15109: }
15110: return $resulttext;
15111: }
15112:
15113: sub modify_selfcreation {
1.305 raeburn 15114: my ($dom,$lastactref,%domconfig) = @_;
15115: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
15116: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
15117: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 15118: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
15119: if (ref($typesref) eq 'ARRAY') {
15120: @types = @{$typesref};
15121: }
15122: if (ref($usertypesref) eq 'HASH') {
15123: %usertypes = %{$usertypesref};
1.228 raeburn 15124: }
1.303 raeburn 15125: $usertypes{'default'} = $othertitle;
1.224 raeburn 15126: #
15127: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
15128: #
15129: if (ref($domconfig{'usercreation'}) eq 'HASH') {
15130: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
15131: if ($key eq 'cancreate') {
15132: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
15133: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
15134: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 15135: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
15136: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
15137: ($item eq 'emailusername') || ($item eq 'shibenv') ||
15138: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 15139: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 15140: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
15141: } else {
15142: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
15143: }
15144: }
15145: }
15146: } elsif ($key eq 'email_rule') {
15147: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
15148: } else {
15149: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
15150: }
15151: }
15152: }
15153: #
15154: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
15155: #
15156: if (ref($domconfig{'usermodification'}) eq 'HASH') {
15157: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
15158: if ($key eq 'selfcreate') {
15159: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
15160: } else {
15161: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
15162: }
15163: }
15164: }
1.305 raeburn 15165: #
15166: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
15167: #
15168: if (ref($domconfig{'inststatus'}) eq 'HASH') {
15169: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
15170: if ($key eq 'inststatusguest') {
15171: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
15172: } else {
15173: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
15174: }
15175: }
15176: }
1.224 raeburn 15177:
15178: my @contexts = ('selfcreate');
15179: @{$cancreate{'selfcreate'}} = ();
15180: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 15181: if (@types) {
15182: @{$cancreate{'statustocreate'}} = ();
15183: }
1.236 raeburn 15184: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 15185: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 15186: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 15187: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 15188: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 15189: my %selfcreatetypes = (
15190: sso => 'users authenticated by institutional single sign on',
15191: login => 'users authenticated by institutional log-in',
1.303 raeburn 15192: email => 'users verified by e-mail',
1.50 raeburn 15193: );
1.224 raeburn 15194: #
15195: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
15196: # is permitted.
15197: #
1.305 raeburn 15198: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 15199:
1.305 raeburn 15200: my (@statuses,%email_rule);
1.228 raeburn 15201: foreach my $item ('login','sso','email') {
1.224 raeburn 15202: if ($item eq 'email') {
1.236 raeburn 15203: if ($env{'form.cancreate_email'}) {
1.305 raeburn 15204: if (@types) {
15205: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
15206: foreach my $status (@poss_statuses) {
15207: if (grep(/^\Q$status\E$/,(@types,'default'))) {
15208: push(@statuses,$status);
15209: }
15210: }
15211: $save_inststatus{'inststatusguest'} = \@statuses;
15212: } else {
15213: push(@statuses,'default');
15214: }
15215: if (@statuses) {
15216: my %curr_rule;
15217: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
15218: foreach my $type (@statuses) {
15219: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 15220: }
1.305 raeburn 15221: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
15222: foreach my $type (@statuses) {
15223: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
15224: }
15225: }
15226: push(@{$cancreate{'selfcreate'}},'email');
15227: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
15228: my %curremaildom;
15229: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
15230: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
15231: }
15232: foreach my $type (@statuses) {
15233: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
15234: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
15235: }
15236: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
15237: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
15238: }
15239: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
15240: #
15241: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
15242: #
15243: my $chosen = $1;
15244: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
15245: my $emaildom;
15246: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
15247: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
15248: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
15249: if (ref($curremaildom{$type}) eq 'HASH') {
15250: if (exists($curremaildom{$type}{$chosen})) {
15251: if ($curremaildom{$type}{$chosen} ne $emaildom) {
15252: push(@{$changes{'cancreate'}},'emaildomain');
15253: }
15254: } elsif ($emaildom ne '') {
15255: push(@{$changes{'cancreate'}},'emaildomain');
15256: }
15257: } elsif ($emaildom ne '') {
15258: push(@{$changes{'cancreate'}},'emaildomain');
15259: }
15260: }
15261: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
15262: } elsif ($chosen eq 'custom') {
15263: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
15264: $email_rule{$type} = [];
15265: if (ref($emailrules) eq 'HASH') {
15266: foreach my $rule (@possemail_rules) {
15267: if (exists($emailrules->{$rule})) {
15268: push(@{$email_rule{$type}},$rule);
15269: }
15270: }
15271: }
15272: if (@{$email_rule{$type}}) {
15273: $cancreate{'emailoptions'}{$type} = 'custom';
15274: if (ref($curr_rule{$type}) eq 'ARRAY') {
15275: if (@{$curr_rule{$type}} > 0) {
15276: foreach my $rule (@{$curr_rule{$type}}) {
15277: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
15278: push(@{$changes{'email_rule'}},$type);
15279: }
15280: }
15281: }
15282: foreach my $type (@{$email_rule{$type}}) {
15283: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
15284: push(@{$changes{'email_rule'}},$type);
15285: }
15286: }
15287: } else {
15288: push(@{$changes{'email_rule'}},$type);
15289: }
15290: }
15291: } else {
15292: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
15293: }
15294: }
15295: }
15296: if (@types) {
15297: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
15298: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
15299: if (@changed) {
15300: push(@{$changes{'inststatus'}},'inststatusguest');
15301: }
15302: } else {
15303: push(@{$changes{'inststatus'}},'inststatusguest');
15304: }
15305: }
15306: } else {
15307: delete($env{'form.cancreate_email'});
15308: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
15309: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
15310: push(@{$changes{'inststatus'}},'inststatusguest');
15311: }
15312: }
15313: }
15314: } else {
15315: $save_inststatus{'inststatusguest'} = [];
15316: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
15317: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
15318: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 15319: }
15320: }
1.224 raeburn 15321: }
15322: } else {
15323: if ($env{'form.cancreate_'.$item}) {
15324: push(@{$cancreate{'selfcreate'}},$item);
15325: }
15326: }
15327: }
1.305 raeburn 15328: my (%userinfo,%savecaptcha);
1.224 raeburn 15329: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
15330: #
1.228 raeburn 15331: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
15332: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 15333: #
1.236 raeburn 15334:
1.244 raeburn 15335: if ($env{'form.cancreate_email'}) {
1.228 raeburn 15336: push(@contexts,'emailusername');
1.305 raeburn 15337: if (@statuses) {
15338: foreach my $type (@statuses) {
1.228 raeburn 15339: if (ref($infofields) eq 'ARRAY') {
15340: foreach my $field (@{$infofields}) {
15341: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
15342: $cancreate{'emailusername'}{$type}{$field} = $1;
15343: }
15344: }
1.224 raeburn 15345: }
15346: }
15347: }
15348: #
15349: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 15350: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 15351: #
15352:
15353: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
15354: @approvalnotify = sort(@approvalnotify);
15355: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
15356: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
15357: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
15358: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
15359: push(@{$changes{'cancreate'}},'notify');
15360: }
15361: } else {
15362: if ($cancreate{'notify'}{'approval'}) {
15363: push(@{$changes{'cancreate'}},'notify');
15364: }
15365: }
15366: } elsif ($cancreate{'notify'}{'approval'}) {
15367: push(@{$changes{'cancreate'}},'notify');
15368: }
15369:
15370: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
15371: }
15372: #
1.236 raeburn 15373: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 15374: # institutional log-in.
15375: #
15376: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
15377: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
15378: ($domdefaults{'auth_def'} eq 'localauth'))) {
15379: $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.').' '.
15380: &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.');
15381: }
15382: }
15383: my @fields = ('lastname','firstname','middlename','generation',
15384: 'permanentemail','id');
1.240 raeburn 15385: my @shibfields = (@fields,'inststatus');
1.224 raeburn 15386: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
15387: #
15388: # Where usernames may created for institutional log-in and/or institutional single sign on:
15389: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
15390: # may self-create accounts
15391: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
15392: # which the user may supply, if institutional data is unavailable.
15393: #
15394: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 15395: if (@types) {
1.305 raeburn 15396: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
15397: push(@contexts,'statustocreate');
1.303 raeburn 15398: foreach my $type (@types) {
1.224 raeburn 15399: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
15400: foreach my $field (@fields) {
15401: if (grep(/^\Q$field\E$/,@modifiable)) {
15402: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
15403: } else {
15404: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
15405: }
15406: }
15407: }
15408: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 15409: foreach my $type (@types) {
1.224 raeburn 15410: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
15411: foreach my $field (@fields) {
15412: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
15413: $curr_usermodify{'selfcreate'}{$type}{$field}) {
15414: push(@{$changes{'selfcreate'}},$type);
15415: last;
15416: }
15417: }
15418: }
15419: }
15420: } else {
1.303 raeburn 15421: foreach my $type (@types) {
1.224 raeburn 15422: push(@{$changes{'selfcreate'}},$type);
15423: }
15424: }
15425: }
1.240 raeburn 15426: foreach my $field (@shibfields) {
15427: if ($env{'form.shibenv_'.$field} ne '') {
15428: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
15429: }
15430: }
15431: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
15432: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
15433: foreach my $field (@shibfields) {
15434: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
15435: push(@{$changes{'cancreate'}},'shibenv');
15436: }
15437: }
15438: } else {
15439: foreach my $field (@shibfields) {
15440: if ($env{'form.shibenv_'.$field}) {
15441: push(@{$changes{'cancreate'}},'shibenv');
15442: last;
15443: }
15444: }
15445: }
15446: }
1.224 raeburn 15447: }
15448: foreach my $item (@contexts) {
15449: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
15450: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
15451: if (ref($cancreate{$item}) eq 'ARRAY') {
15452: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
15453: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15454: push(@{$changes{'cancreate'}},$item);
15455: }
15456: }
15457: }
15458: }
15459: if (ref($cancreate{$item}) eq 'ARRAY') {
15460: foreach my $type (@{$cancreate{$item}}) {
15461: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
15462: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15463: push(@{$changes{'cancreate'}},$item);
15464: }
15465: }
15466: }
15467: }
15468: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
15469: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 15470: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
15471: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
15472: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
15473: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 15474: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15475: push(@{$changes{'cancreate'}},$item);
15476: }
15477: }
15478: }
1.305 raeburn 15479: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
15480: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 15481: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15482: push(@{$changes{'cancreate'}},$item);
15483: }
1.224 raeburn 15484: }
15485: }
15486: }
1.305 raeburn 15487: foreach my $type (keys(%{$cancreate{$item}})) {
15488: if (ref($cancreate{$item}{$type}) eq 'HASH') {
15489: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
15490: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
15491: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 15492: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15493: push(@{$changes{'cancreate'}},$item);
15494: }
15495: }
15496: } else {
15497: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15498: push(@{$changes{'cancreate'}},$item);
15499: }
15500: }
15501: }
1.305 raeburn 15502: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
15503: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 15504: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15505: push(@{$changes{'cancreate'}},$item);
15506: }
1.224 raeburn 15507: }
15508: }
15509: }
15510: }
15511: } elsif ($curr_usercreation{'cancreate'}{$item}) {
15512: if (ref($cancreate{$item}) eq 'ARRAY') {
15513: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
15514: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15515: push(@{$changes{'cancreate'}},$item);
15516: }
15517: }
1.305 raeburn 15518: }
15519: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
15520: if (ref($cancreate{$item}) eq 'HASH') {
15521: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15522: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 15523: }
15524: }
15525: } elsif ($item eq 'emailusername') {
1.228 raeburn 15526: if (ref($cancreate{$item}) eq 'HASH') {
15527: foreach my $type (keys(%{$cancreate{$item}})) {
15528: if (ref($cancreate{$item}{$type}) eq 'HASH') {
15529: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
15530: if ($cancreate{$item}{$type}{$field}) {
15531: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15532: push(@{$changes{'cancreate'}},$item);
15533: }
15534: last;
15535: }
15536: }
15537: }
15538: }
1.224 raeburn 15539: }
15540: }
15541: }
15542: #
15543: # Populate %save_usercreate hash with updates to self-creation configuration.
15544: #
15545: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
15546: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 15547: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 15548: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
15549: if (ref($cancreate{'notify'}) eq 'HASH') {
15550: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
15551: }
1.236 raeburn 15552: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
15553: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
15554: }
1.303 raeburn 15555: if (ref($cancreate{'emailverified'}) eq 'HASH') {
15556: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
15557: }
1.305 raeburn 15558: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
15559: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
15560: }
1.303 raeburn 15561: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
15562: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
15563: }
1.224 raeburn 15564: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
15565: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
15566: }
1.240 raeburn 15567: if (ref($cancreate{'shibenv'}) eq 'HASH') {
15568: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
15569: }
1.224 raeburn 15570: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 15571: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 15572:
15573: my %userconfig_hash = (
15574: usercreation => \%save_usercreate,
15575: usermodification => \%save_usermodify,
1.305 raeburn 15576: inststatus => \%save_inststatus,
1.224 raeburn 15577: );
1.305 raeburn 15578:
1.224 raeburn 15579: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
15580: $dom);
15581: #
1.305 raeburn 15582: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 15583: #
1.27 raeburn 15584: if ($putresult eq 'ok') {
15585: if (keys(%changes) > 0) {
15586: $resulttext = &mt('Changes made:').'<ul>';
15587: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 15588: my %lt = &selfcreation_types();
1.34 raeburn 15589: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 15590: my $chgtext = '';
1.45 raeburn 15591: if ($type eq 'selfcreate') {
1.50 raeburn 15592: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 15593: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 15594: } else {
1.224 raeburn 15595: $chgtext .= &mt('Self-creation of a new account is permitted for:').
15596: '<ul>';
1.50 raeburn 15597: foreach my $case (@{$cancreate{$type}}) {
15598: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
15599: }
15600: $chgtext .= '</ul>';
1.100 raeburn 15601: if (ref($cancreate{$type}) eq 'ARRAY') {
15602: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
15603: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
15604: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 15605: $chgtext .= '<span class="LC_warning">'.
15606: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
15607: '</span><br />';
15608: }
15609: }
15610: }
15611: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 15612: if (!@statuses) {
15613: $chgtext .= '<span class="LC_warning">'.
15614: &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.").
15615: '</span><br />';
1.303 raeburn 15616:
1.100 raeburn 15617: }
15618: }
15619: }
1.43 raeburn 15620: }
1.240 raeburn 15621: } elsif ($type eq 'shibenv') {
15622: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 15623: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 15624: } else {
15625: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
15626: '<ul>';
15627: foreach my $field (@shibfields) {
15628: next if ($cancreate{$type}{$field} eq '');
15629: if ($field eq 'inststatus') {
15630: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
15631: } else {
15632: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
15633: }
15634: }
15635: $chgtext .= '</ul>';
1.303 raeburn 15636: }
1.93 raeburn 15637: } elsif ($type eq 'statustocreate') {
1.96 raeburn 15638: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
15639: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
15640: if (@{$cancreate{'selfcreate'}} > 0) {
15641: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 15642: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 15643: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 15644: $chgtext .= '<br />'.
15645: '<span class="LC_warning">'.
15646: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
15647: '</span>';
15648: }
1.303 raeburn 15649: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 15650: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 15651: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
15652: } else {
15653: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
15654: }
15655: $chgtext .= '<ul>';
15656: foreach my $case (@{$cancreate{$type}}) {
15657: if ($case eq 'default') {
15658: $chgtext .= '<li>'.$othertitle.'</li>';
15659: } else {
1.303 raeburn 15660: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 15661: }
15662: }
1.100 raeburn 15663: $chgtext .= '</ul>';
15664: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 15665: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 15666: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
15667: '</span>';
1.100 raeburn 15668: }
15669: }
15670: } else {
15671: if (@{$cancreate{$type}} == 0) {
15672: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
15673: } else {
15674: $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 15675: }
15676: }
1.303 raeburn 15677: $chgtext .= '<br />';
1.93 raeburn 15678: }
1.236 raeburn 15679: } elsif ($type eq 'selfcreateprocessing') {
15680: my %choices = &Apache::lonlocal::texthash (
15681: automatic => 'Automatic approval',
15682: approval => 'Queued for approval',
15683: );
1.305 raeburn 15684: if (@types) {
15685: if (@statuses) {
1.303 raeburn 15686: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 15687: '<ul>';
1.305 raeburn 15688: foreach my $status (@statuses) {
15689: if ($status eq 'default') {
15690: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 15691: } else {
1.305 raeburn 15692: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 15693: }
15694: }
15695: $chgtext .= '</ul>';
15696: }
15697: } else {
15698: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
15699: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
15700: }
15701: } elsif ($type eq 'emailverified') {
15702: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 15703: all => 'Same as e-mail',
15704: first => 'Omit @domain',
15705: free => 'Free to choose',
1.303 raeburn 15706: );
1.305 raeburn 15707: if (@types) {
15708: if (@statuses) {
1.303 raeburn 15709: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
15710: '<ul>';
1.305 raeburn 15711: foreach my $status (@statuses) {
1.303 raeburn 15712: if ($type eq 'default') {
1.305 raeburn 15713: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 15714: } else {
1.305 raeburn 15715: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 15716: }
15717: }
15718: $chgtext .= '</ul>';
15719: }
15720: } else {
1.305 raeburn 15721: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 15722: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 15723: }
1.305 raeburn 15724: } elsif ($type eq 'emailoptions') {
15725: my %options = &Apache::lonlocal::texthash (
15726: any => 'Any e-mail',
15727: inst => 'Institutional only',
15728: noninst => 'Non-institutional only',
15729: custom => 'Custom restrictions',
15730: );
15731: if (@types) {
15732: if (@statuses) {
15733: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
15734: '<ul>';
15735: foreach my $status (@statuses) {
15736: if ($type eq 'default') {
15737: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
15738: } else {
15739: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 15740: }
15741: }
1.305 raeburn 15742: $chgtext .= '</ul>';
15743: }
15744: } else {
15745: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
15746: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
15747: } else {
15748: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
15749: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 15750: }
1.305 raeburn 15751: }
15752: } elsif ($type eq 'emaildomain') {
15753: my $output;
15754: if (@statuses) {
15755: foreach my $type (@statuses) {
15756: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
15757: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
15758: if ($type eq 'default') {
15759: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15760: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
15761: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
15762: } else {
15763: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
15764: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
15765: }
1.303 raeburn 15766: } else {
1.305 raeburn 15767: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15768: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
15769: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
15770: } else {
15771: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
15772: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
15773: }
1.303 raeburn 15774: }
1.305 raeburn 15775: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
15776: if ($type eq 'default') {
15777: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15778: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
15779: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
15780: } else {
15781: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
15782: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
15783: }
1.303 raeburn 15784: } else {
1.305 raeburn 15785: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15786: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
15787: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
15788: } else {
15789: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
15790: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
15791: }
1.303 raeburn 15792: }
15793: }
15794: }
15795: }
1.305 raeburn 15796: }
15797: if ($output ne '') {
15798: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
15799: '<ul>'.$output.'</ul>';
1.236 raeburn 15800: }
1.165 raeburn 15801: } elsif ($type eq 'captcha') {
1.224 raeburn 15802: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 15803: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
15804: } else {
15805: my %captchas = &captcha_phrases();
1.224 raeburn 15806: if ($captchas{$savecaptcha{$type}}) {
15807: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 15808: } else {
1.210 raeburn 15809: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 15810: }
15811: }
15812: } elsif ($type eq 'recaptchakeys') {
15813: my ($privkey,$pubkey);
1.224 raeburn 15814: if (ref($savecaptcha{$type}) eq 'HASH') {
15815: $pubkey = $savecaptcha{$type}{'public'};
15816: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 15817: }
15818: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
15819: if (!$pubkey) {
15820: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
15821: } else {
15822: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
15823: }
15824: if (!$privkey) {
15825: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
15826: } else {
15827: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
15828: }
15829: $chgtext .= '</ul>';
1.269 raeburn 15830: } elsif ($type eq 'recaptchaversion') {
15831: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 15832: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 15833: }
1.224 raeburn 15834: } elsif ($type eq 'emailusername') {
15835: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 15836: if (@statuses) {
15837: foreach my $type (@statuses) {
1.228 raeburn 15838: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
15839: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 15840: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 15841: '<ul>';
15842: foreach my $field (@{$infofields}) {
15843: if ($cancreate{'emailusername'}{$type}{$field}) {
15844: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
15845: }
15846: }
1.245 raeburn 15847: $chgtext .= '</ul>';
15848: } else {
1.303 raeburn 15849: $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 15850: }
15851: } else {
1.303 raeburn 15852: $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 15853: }
15854: }
15855: }
15856: }
15857: } elsif ($type eq 'notify') {
1.303 raeburn 15858: my $numapprove = 0;
1.224 raeburn 15859: if (ref($changes{'cancreate'}) eq 'ARRAY') {
15860: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
15861: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 15862: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
15863: $numapprove ++;
1.224 raeburn 15864: }
15865: }
1.43 raeburn 15866: }
1.303 raeburn 15867: unless ($numapprove) {
15868: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
15869: }
1.34 raeburn 15870: }
1.224 raeburn 15871: if ($chgtext) {
15872: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 15873: }
15874: }
15875: }
1.305 raeburn 15876: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 15877: my ($emailrules,$emailruleorder) =
15878: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 15879: foreach my $type (@{$changes{'email_rule'}}) {
15880: if (ref($email_rule{$type}) eq 'ARRAY') {
15881: my $chgtext = '<ul>';
15882: foreach my $rule (@{$email_rule{$type}}) {
15883: if (ref($emailrules->{$rule}) eq 'HASH') {
15884: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
15885: }
15886: }
15887: $chgtext .= '</ul>';
1.310 raeburn 15888: my $typename;
1.305 raeburn 15889: if (@types) {
15890: if ($type eq 'default') {
15891: $typename = $othertitle;
15892: } else {
15893: $typename = $usertypes{$type};
15894: }
15895: $chgtext .= &mt('(Affiliation: [_1])',$typename);
15896: }
15897: if (@{$email_rule{$type}} > 0) {
15898: $resulttext .= '<li>'.
15899: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
15900: $usertypes{$type}).
15901: $chgtext.
15902: '</li>';
15903: } else {
15904: $resulttext .= '<li>'.
1.310 raeburn 15905: &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 15906: '</li>'.
1.310 raeburn 15907: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 15908: }
1.43 raeburn 15909: }
15910: }
1.305 raeburn 15911: }
15912: if (ref($changes{'inststatus'}) eq 'ARRAY') {
15913: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
15914: if (@{$save_inststatus{'inststatusguest'}} > 0) {
15915: my $chgtext = '<ul>';
15916: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
15917: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
15918: }
15919: $chgtext .= '</ul>';
15920: $resulttext .= '<li>'.
15921: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
15922: $chgtext.
15923: '</li>';
15924: } else {
15925: $resulttext .= '<li>'.
15926: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
15927: '</li>';
15928: }
1.43 raeburn 15929: }
15930: }
1.224 raeburn 15931: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
15932: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
15933: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
15934: foreach my $type (@{$changes{'selfcreate'}}) {
15935: my $typename = $type;
1.303 raeburn 15936: if (keys(%usertypes) > 0) {
15937: if ($usertypes{$type} ne '') {
15938: $typename = $usertypes{$type};
1.224 raeburn 15939: }
15940: }
15941: my @modifiable;
15942: $resulttext .= '<li>'.
15943: &mt('Self-creation of account by users with status: [_1]',
15944: '<span class="LC_cusr_emph">'.$typename.'</span>').
15945: ' - '.&mt('modifiable fields (if institutional data blank): ');
15946: foreach my $field (@fields) {
15947: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
15948: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 15949: }
15950: }
1.224 raeburn 15951: if (@modifiable > 0) {
15952: $resulttext .= join(', ',@modifiable);
1.43 raeburn 15953: } else {
1.224 raeburn 15954: $resulttext .= &mt('none');
1.43 raeburn 15955: }
1.224 raeburn 15956: $resulttext .= '</li>';
1.28 raeburn 15957: }
1.224 raeburn 15958: $resulttext .= '</ul></li>';
1.28 raeburn 15959: }
1.27 raeburn 15960: $resulttext .= '</ul>';
1.305 raeburn 15961: my $cachetime = 24*60*60;
15962: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
15963: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15964: if (ref($lastactref) eq 'HASH') {
15965: $lastactref->{'domdefaults'} = 1;
15966: }
1.27 raeburn 15967: } else {
1.224 raeburn 15968: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 15969: }
15970: } else {
15971: $resulttext = '<span class="LC_error">'.
1.23 raeburn 15972: &mt('An error occurred: [_1]',$putresult).'</span>';
15973: }
1.43 raeburn 15974: if ($warningmsg ne '') {
15975: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
15976: }
1.23 raeburn 15977: return $resulttext;
15978: }
15979:
1.165 raeburn 15980: sub process_captcha {
15981: my ($container,$changes,$newsettings,$current) = @_;
15982: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
15983: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
15984: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
15985: $newsettings->{'captcha'} = 'original';
15986: }
15987: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 15988: if ($container eq 'cancreate') {
1.169 raeburn 15989: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
15990: push(@{$changes->{'cancreate'}},'captcha');
15991: } elsif (!defined($changes->{'cancreate'})) {
15992: $changes->{'cancreate'} = ['captcha'];
15993: }
15994: } else {
15995: $changes->{'captcha'} = 1;
1.165 raeburn 15996: }
15997: }
1.269 raeburn 15998: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 15999: if ($newsettings->{'captcha'} eq 'recaptcha') {
16000: $newpub = $env{'form.'.$container.'_recaptchapub'};
16001: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 16002: $newpub =~ s/[^\w\-]//g;
16003: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 16004: $newsettings->{'recaptchakeys'} = {
16005: public => $newpub,
16006: private => $newpriv,
16007: };
1.269 raeburn 16008: $newversion = $env{'form.'.$container.'_recaptchaversion'};
16009: $newversion =~ s/\D//g;
16010: if ($newversion ne '2') {
16011: $newversion = 1;
16012: }
16013: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 16014: }
16015: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
16016: $currpub = $current->{'recaptchakeys'}{'public'};
16017: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 16018: unless ($newsettings->{'captcha'} eq 'recaptcha') {
16019: $newsettings->{'recaptchakeys'} = {
16020: public => '',
16021: private => '',
16022: }
16023: }
1.165 raeburn 16024: }
1.269 raeburn 16025: if ($current->{'captcha'} eq 'recaptcha') {
16026: $currversion = $current->{'recaptchaversion'};
16027: if ($currversion ne '2') {
16028: $currversion = 1;
16029: }
16030: }
16031: if ($currversion ne $newversion) {
16032: if ($container eq 'cancreate') {
16033: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
16034: push(@{$changes->{'cancreate'}},'recaptchaversion');
16035: } elsif (!defined($changes->{'cancreate'})) {
16036: $changes->{'cancreate'} = ['recaptchaversion'];
16037: }
16038: } else {
16039: $changes->{'recaptchaversion'} = 1;
16040: }
16041: }
1.165 raeburn 16042: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 16043: if ($container eq 'cancreate') {
16044: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
16045: push(@{$changes->{'cancreate'}},'recaptchakeys');
16046: } elsif (!defined($changes->{'cancreate'})) {
16047: $changes->{'cancreate'} = ['recaptchakeys'];
16048: }
16049: } else {
1.210 raeburn 16050: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 16051: }
16052: }
16053: return;
16054: }
16055:
1.33 raeburn 16056: sub modify_usermodification {
16057: my ($dom,%domconfig) = @_;
1.224 raeburn 16058: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 16059: if (ref($domconfig{'usermodification'}) eq 'HASH') {
16060: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 16061: if ($key eq 'selfcreate') {
16062: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
16063: } else {
16064: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
16065: }
1.33 raeburn 16066: }
16067: }
1.224 raeburn 16068: my @contexts = ('author','course');
1.33 raeburn 16069: my %context_title = (
16070: author => 'In author context',
16071: course => 'In course context',
16072: );
16073: my @fields = ('lastname','firstname','middlename','generation',
16074: 'permanentemail','id');
16075: my %roles = (
16076: author => ['ca','aa'],
16077: course => ['st','ep','ta','in','cr'],
16078: );
16079: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
16080: foreach my $context (@contexts) {
16081: foreach my $role (@{$roles{$context}}) {
16082: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
16083: foreach my $item (@fields) {
16084: if (grep(/^\Q$item\E$/,@modifiable)) {
16085: $modifyhash{$context}{$role}{$item} = 1;
16086: } else {
16087: $modifyhash{$context}{$role}{$item} = 0;
16088: }
16089: }
16090: }
16091: if (ref($curr_usermodification{$context}) eq 'HASH') {
16092: foreach my $role (@{$roles{$context}}) {
16093: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
16094: foreach my $field (@fields) {
16095: if ($modifyhash{$context}{$role}{$field} ne
16096: $curr_usermodification{$context}{$role}{$field}) {
16097: push(@{$changes{$context}},$role);
16098: last;
16099: }
16100: }
16101: }
16102: }
16103: } else {
16104: foreach my $context (@contexts) {
16105: foreach my $role (@{$roles{$context}}) {
16106: push(@{$changes{$context}},$role);
16107: }
16108: }
16109: }
16110: }
16111: my %usermodification_hash = (
16112: usermodification => \%modifyhash,
16113: );
16114: my $putresult = &Apache::lonnet::put_dom('configuration',
16115: \%usermodification_hash,$dom);
16116: if ($putresult eq 'ok') {
16117: if (keys(%changes) > 0) {
16118: $resulttext = &mt('Changes made: ').'<ul>';
16119: foreach my $context (@contexts) {
16120: if (ref($changes{$context}) eq 'ARRAY') {
16121: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
16122: if (ref($changes{$context}) eq 'ARRAY') {
16123: foreach my $role (@{$changes{$context}}) {
16124: my $rolename;
1.224 raeburn 16125: if ($role eq 'cr') {
16126: $rolename = &mt('Custom');
1.33 raeburn 16127: } else {
1.224 raeburn 16128: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 16129: }
16130: my @modifiable;
1.224 raeburn 16131: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 16132: foreach my $field (@fields) {
16133: if ($modifyhash{$context}{$role}{$field}) {
16134: push(@modifiable,$fieldtitles{$field});
16135: }
16136: }
16137: if (@modifiable > 0) {
16138: $resulttext .= join(', ',@modifiable);
16139: } else {
16140: $resulttext .= &mt('none');
16141: }
16142: $resulttext .= '</li>';
16143: }
16144: $resulttext .= '</ul></li>';
16145: }
16146: }
16147: }
16148: $resulttext .= '</ul>';
16149: } else {
16150: $resulttext = &mt('No changes made to user modification settings');
16151: }
16152: } else {
16153: $resulttext = '<span class="LC_error">'.
16154: &mt('An error occurred: [_1]',$putresult).'</span>';
16155: }
16156: return $resulttext;
16157: }
16158:
1.43 raeburn 16159: sub modify_defaults {
1.212 raeburn 16160: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 16161: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 16162: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 16163: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 16164: 'portal_def');
1.325 raeburn 16165: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 16166: foreach my $item (@items) {
16167: $newvalues{$item} = $env{'form.'.$item};
16168: if ($item eq 'auth_def') {
16169: if ($newvalues{$item} ne '') {
16170: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
16171: push(@errors,$item);
16172: }
16173: }
16174: } elsif ($item eq 'lang_def') {
16175: if ($newvalues{$item} ne '') {
16176: if ($newvalues{$item} =~ /^(\w+)/) {
16177: my $langcode = $1;
1.103 raeburn 16178: if ($langcode ne 'x_chef') {
16179: if (code2language($langcode) eq '') {
16180: push(@errors,$item);
16181: }
1.43 raeburn 16182: }
16183: } else {
16184: push(@errors,$item);
16185: }
16186: }
1.54 raeburn 16187: } elsif ($item eq 'timezone_def') {
16188: if ($newvalues{$item} ne '') {
1.62 raeburn 16189: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 16190: push(@errors,$item);
16191: }
16192: }
1.68 raeburn 16193: } elsif ($item eq 'datelocale_def') {
16194: if ($newvalues{$item} ne '') {
16195: my @datelocale_ids = DateTime::Locale->ids();
16196: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
16197: push(@errors,$item);
16198: }
16199: }
1.141 raeburn 16200: } elsif ($item eq 'portal_def') {
16201: if ($newvalues{$item} ne '') {
16202: 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])\/?$/) {
16203: push(@errors,$item);
16204: }
16205: }
1.43 raeburn 16206: }
16207: if (grep(/^\Q$item\E$/,@errors)) {
16208: $newvalues{$item} = $domdefaults{$item};
16209: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
16210: $changes{$item} = 1;
16211: }
1.72 raeburn 16212: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 16213: }
1.354 raeburn 16214: my %staticdefaults = (
16215: 'intauth_cost' => 10,
16216: 'intauth_check' => 0,
16217: 'intauth_switch' => 0,
16218: );
16219: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
16220: if (exists($domdefaults{$item})) {
16221: $newvalues{$item} = $domdefaults{$item};
16222: } else {
16223: $newvalues{$item} = $staticdefaults{$item};
16224: }
16225: }
1.43 raeburn 16226: my %defaults_hash = (
1.72 raeburn 16227: defaults => \%newvalues,
16228: );
1.43 raeburn 16229: my $title = &defaults_titles();
1.236 raeburn 16230:
16231: my $currinststatus;
16232: if (ref($domconfig{'inststatus'}) eq 'HASH') {
16233: $currinststatus = $domconfig{'inststatus'};
16234: } else {
16235: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
16236: $currinststatus = {
16237: inststatustypes => $usertypes,
16238: inststatusorder => $types,
16239: inststatusguest => [],
16240: };
16241: }
16242: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
16243: my @allpos;
16244: my %alltypes;
1.305 raeburn 16245: my @inststatusguest;
16246: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
16247: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
16248: unless (grep(/^\Q$type\E$/,@todelete)) {
16249: push(@inststatusguest,$type);
16250: }
16251: }
16252: }
16253: my ($currtitles,$currorder);
1.236 raeburn 16254: if (ref($currinststatus) eq 'HASH') {
16255: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
16256: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
16257: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
16258: if ($currinststatus->{inststatustypes}->{$type} ne '') {
16259: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
16260: }
16261: }
16262: unless (grep(/^\Q$type\E$/,@todelete)) {
16263: my $position = $env{'form.inststatus_pos_'.$type};
16264: $position =~ s/\D+//g;
16265: $allpos[$position] = $type;
16266: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
16267: $alltypes{$type} =~ s/`//g;
16268: }
16269: }
16270: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
16271: $currtitles =~ s/,$//;
16272: }
16273: }
16274: if ($env{'form.addinststatus'}) {
16275: my $newtype = $env{'form.addinststatus'};
16276: $newtype =~ s/\W//g;
16277: unless (exists($alltypes{$newtype})) {
16278: $alltypes{$newtype} = $env{'form.addinststatus_title'};
16279: $alltypes{$newtype} =~ s/`//g;
16280: my $position = $env{'form.addinststatus_pos'};
16281: $position =~ s/\D+//g;
16282: if ($position ne '') {
16283: $allpos[$position] = $newtype;
16284: }
16285: }
16286: }
1.305 raeburn 16287: my @orderedstatus;
1.236 raeburn 16288: foreach my $type (@allpos) {
16289: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
16290: push(@orderedstatus,$type);
16291: }
16292: }
16293: foreach my $type (keys(%alltypes)) {
16294: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
16295: delete($alltypes{$type});
16296: }
16297: }
16298: $defaults_hash{'inststatus'} = {
16299: inststatustypes => \%alltypes,
16300: inststatusorder => \@orderedstatus,
1.305 raeburn 16301: inststatusguest => \@inststatusguest,
1.236 raeburn 16302: };
16303: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
16304: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
16305: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
16306: }
16307: }
16308: if ($currorder ne join(',',@orderedstatus)) {
16309: $changes{'inststatus'}{'inststatusorder'} = 1;
16310: }
16311: my $newtitles;
16312: foreach my $item (@orderedstatus) {
16313: $newtitles .= $alltypes{$item}.',';
16314: }
16315: $newtitles =~ s/,$//;
16316: if ($currtitles ne $newtitles) {
16317: $changes{'inststatus'}{'inststatustypes'} = 1;
16318: }
1.43 raeburn 16319: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
16320: $dom);
16321: if ($putresult eq 'ok') {
16322: if (keys(%changes) > 0) {
16323: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 16324: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 16325: 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";
16326: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 16327: if ($item eq 'inststatus') {
16328: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 16329: if (@orderedstatus) {
1.236 raeburn 16330: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
16331: foreach my $type (@orderedstatus) {
16332: $resulttext .= $alltypes{$type}.', ';
16333: }
16334: $resulttext =~ s/, $//;
16335: $resulttext .= '</li>';
1.305 raeburn 16336: } else {
16337: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 16338: }
16339: }
16340: } else {
16341: my $value = $env{'form.'.$item};
16342: if ($value eq '') {
16343: $value = &mt('none');
16344: } elsif ($item eq 'auth_def') {
16345: my %authnames = &authtype_names();
16346: my %shortauth = (
16347: internal => 'int',
16348: krb4 => 'krb4',
16349: krb5 => 'krb5',
16350: localauth => 'loc',
1.325 raeburn 16351: lti => 'lti',
1.236 raeburn 16352: );
16353: $value = $authnames{$shortauth{$value}};
16354: }
16355: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
16356: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 16357: }
16358: }
16359: $resulttext .= '</ul>';
16360: $mailmsgtext .= "\n";
16361: my $cachetime = 24*60*60;
1.72 raeburn 16362: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 16363: if (ref($lastactref) eq 'HASH') {
16364: $lastactref->{'domdefaults'} = 1;
16365: }
1.68 raeburn 16366: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 16367: my $notify = 1;
16368: if (ref($domconfig{'contacts'}) eq 'HASH') {
16369: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
16370: $notify = 0;
16371: }
16372: }
16373: if ($notify) {
16374: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
16375: "LON-CAPA Domain Settings Change - $dom",
16376: $mailmsgtext);
16377: }
1.54 raeburn 16378: }
1.43 raeburn 16379: } else {
1.54 raeburn 16380: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 16381: }
16382: } else {
16383: $resulttext = '<span class="LC_error">'.
16384: &mt('An error occurred: [_1]',$putresult).'</span>';
16385: }
16386: if (@errors > 0) {
16387: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
16388: foreach my $item (@errors) {
16389: $resulttext .= ' "'.$title->{$item}.'",';
16390: }
16391: $resulttext =~ s/,$//;
16392: }
16393: return $resulttext;
16394: }
16395:
1.46 raeburn 16396: sub modify_scantron {
1.205 raeburn 16397: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 16398: my ($resulttext,%confhash,%changes,$errors);
16399: my $custom = 'custom.tab';
16400: my $default = 'default.tab';
16401: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 16402: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 16403: &config_check($dom,$confname,$servadm);
16404: if ($env{'form.scantronformat.filename'} ne '') {
16405: my $error;
16406: if ($configuserok eq 'ok') {
16407: if ($switchserver) {
1.130 raeburn 16408: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 16409: } else {
16410: if ($author_ok eq 'ok') {
16411: my ($result,$scantronurl) =
16412: &publishlogo($r,'upload','scantronformat',$dom,
16413: $confname,'scantron','','',$custom);
16414: if ($result eq 'ok') {
16415: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 16416: $changes{'scantronformat'} = 1;
1.46 raeburn 16417: } else {
16418: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
16419: }
16420: } else {
16421: $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);
16422: }
16423: }
16424: } else {
16425: $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);
16426: }
16427: if ($error) {
16428: &Apache::lonnet::logthis($error);
16429: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
16430: }
16431: }
1.48 raeburn 16432: if (ref($domconfig{'scantron'}) eq 'HASH') {
16433: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
16434: if ($env{'form.scantronformat_del'}) {
16435: $confhash{'scantron'}{'scantronformat'} = '';
16436: $changes{'scantronformat'} = 1;
1.347 raeburn 16437: } else {
16438: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 16439: }
16440: }
16441: }
1.347 raeburn 16442: my @options = ('hdr','pad','rem');
1.346 raeburn 16443: my @fields = &scantroncsv_fields();
16444: my %titles = &scantronconfig_titles();
1.347 raeburn 16445: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 16446: my ($newdat,$currdat,%newcol,%currcol);
16447: if (grep(/^dat$/,@formats)) {
16448: $confhash{'scantron'}{config}{dat} = 1;
16449: $newdat = 1;
16450: } else {
16451: $newdat = 0;
16452: }
16453: if (grep(/^csv$/,@formats)) {
16454: my %bynum;
16455: foreach my $field (@fields) {
16456: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
16457: my $posscol = $1;
16458: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 16459: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 16460: $bynum{$posscol} = $field;
16461: $newcol{$field} = $posscol;
16462: }
16463: }
16464: }
1.347 raeburn 16465: if (keys(%newcol)) {
16466: foreach my $option (@options) {
16467: if ($env{'form.scantroncsv_'.$option}) {
16468: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
16469: }
16470: }
16471: }
1.346 raeburn 16472: }
16473: $currdat = 1;
16474: if (ref($domconfig{'scantron'}) eq 'HASH') {
16475: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 16476: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 16477: $currdat = 0;
16478: }
16479: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 16480: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
16481: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
16482: }
1.346 raeburn 16483: }
16484: }
16485: }
16486: if ($currdat != $newdat) {
16487: $changes{'config'} = 1;
16488: } else {
16489: foreach my $field (@fields) {
16490: if ($currcol{$field} ne '') {
16491: if ($currcol{$field} ne $newcol{$field}) {
16492: $changes{'config'} = 1;
16493: last;
1.347 raeburn 16494: }
1.346 raeburn 16495: } elsif ($newcol{$field} ne '') {
16496: $changes{'config'} = 1;
16497: last;
16498: }
16499: }
16500: }
1.46 raeburn 16501: if (keys(%confhash) > 0) {
16502: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
16503: $dom);
16504: if ($putresult eq 'ok') {
16505: if (keys(%changes) > 0) {
1.48 raeburn 16506: if (ref($confhash{'scantron'}) eq 'HASH') {
16507: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 16508: if ($changes{'scantronformat'}) {
16509: if ($confhash{'scantron'}{'scantronformat'} eq '') {
16510: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
16511: } else {
16512: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
16513: }
16514: }
1.347 raeburn 16515: if ($changes{'config'}) {
1.346 raeburn 16516: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
16517: if ($confhash{'scantron'}{'config'}{'dat'}) {
16518: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
16519: }
16520: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 16521: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
16522: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
16523: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
16524: foreach my $field (@fields) {
16525: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
16526: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
16527: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
16528: }
16529: }
16530: $resulttext .= '</ul></li>';
16531: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
16532: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
16533: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
16534: foreach my $option (@options) {
16535: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
16536: $resulttext .= '<li>'.$titles{$option}.'</li>';
16537: }
16538: }
16539: $resulttext .= '</ul></li>';
16540: }
1.346 raeburn 16541: }
16542: }
16543: }
16544: }
16545: } else {
16546: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
16547: }
1.46 raeburn 16548: }
1.48 raeburn 16549: $resulttext .= '</ul>';
16550: } else {
1.130 raeburn 16551: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 16552: }
16553: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16554: if (ref($lastactref) eq 'HASH') {
16555: $lastactref->{'domainconfig'} = 1;
16556: }
1.46 raeburn 16557: } else {
1.346 raeburn 16558: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 16559: }
16560: } else {
16561: $resulttext = '<span class="LC_error">'.
16562: &mt('An error occurred: [_1]',$putresult).'</span>';
16563: }
16564: } else {
1.130 raeburn 16565: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 16566: }
16567: if ($errors) {
1.353 raeburn 16568: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
16569: $errors.'</ul></p>';
1.46 raeburn 16570: }
16571: return $resulttext;
16572: }
16573:
1.48 raeburn 16574: sub modify_coursecategories {
1.239 raeburn 16575: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 16576: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
16577: $cathash);
1.48 raeburn 16578: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 16579: my @catitems = ('unauth','auth');
16580: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 16581: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 16582: $cathash = $domconfig{'coursecategories'}{'cats'};
16583: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
16584: $changes{'togglecats'} = 1;
16585: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
16586: }
16587: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
16588: $changes{'categorize'} = 1;
16589: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
16590: }
1.120 raeburn 16591: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
16592: $changes{'togglecatscomm'} = 1;
16593: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
16594: }
16595: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
16596: $changes{'categorizecomm'} = 1;
16597: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 16598:
16599: }
16600: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
16601: $changes{'togglecatsplace'} = 1;
16602: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
16603: }
16604: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
16605: $changes{'categorizeplace'} = 1;
16606: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 16607: }
1.238 raeburn 16608: foreach my $item (@catitems) {
16609: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
16610: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
16611: $changes{$item} = 1;
16612: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
16613: }
16614: }
16615: }
1.57 raeburn 16616: } else {
16617: $changes{'togglecats'} = 1;
16618: $changes{'categorize'} = 1;
1.124 raeburn 16619: $changes{'togglecatscomm'} = 1;
16620: $changes{'categorizecomm'} = 1;
1.272 raeburn 16621: $changes{'togglecatsplace'} = 1;
16622: $changes{'categorizeplace'} = 1;
1.87 raeburn 16623: $domconfig{'coursecategories'} = {
16624: togglecats => $env{'form.togglecats'},
16625: categorize => $env{'form.categorize'},
1.124 raeburn 16626: togglecatscomm => $env{'form.togglecatscomm'},
16627: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 16628: togglecatsplace => $env{'form.togglecatsplace'},
16629: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 16630: };
1.238 raeburn 16631: foreach my $item (@catitems) {
16632: if ($env{'form.coursecat_'.$item} ne 'std') {
16633: $changes{$item} = 1;
16634: }
16635: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
16636: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
16637: }
16638: }
1.57 raeburn 16639: }
16640: if (ref($cathash) eq 'HASH') {
16641: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 16642: push (@deletecategory,'instcode::0');
16643: }
1.120 raeburn 16644: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
16645: push(@deletecategory,'communities::0');
16646: }
1.272 raeburn 16647: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
16648: push(@deletecategory,'placement::0');
16649: }
1.48 raeburn 16650: }
1.57 raeburn 16651: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
16652: if (ref($cathash) eq 'HASH') {
1.48 raeburn 16653: if (@deletecategory > 0) {
16654: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 16655: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 16656: foreach my $item (@deletecategory) {
1.57 raeburn 16657: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
16658: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 16659: $deletions{$item} = 1;
1.57 raeburn 16660: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 16661: }
16662: }
16663: }
1.57 raeburn 16664: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 16665: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 16666: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 16667: $reorderings{$item} = 1;
1.57 raeburn 16668: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 16669: }
16670: if ($env{'form.addcategory_name_'.$item} ne '') {
16671: my $newcat = $env{'form.addcategory_name_'.$item};
16672: my $newdepth = $depth+1;
16673: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 16674: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 16675: $adds{$newitem} = 1;
16676: }
16677: if ($env{'form.subcat_'.$item} ne '') {
16678: my $newcat = $env{'form.subcat_'.$item};
16679: my $newdepth = $depth+1;
16680: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 16681: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 16682: $adds{$newitem} = 1;
16683: }
16684: }
16685: }
16686: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 16687: if (ref($cathash) eq 'HASH') {
1.48 raeburn 16688: my $newitem = 'instcode::0';
1.57 raeburn 16689: if ($cathash->{$newitem} eq '') {
16690: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 16691: $adds{$newitem} = 1;
16692: }
16693: } else {
16694: my $newitem = 'instcode::0';
1.57 raeburn 16695: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 16696: $adds{$newitem} = 1;
16697: }
16698: }
1.120 raeburn 16699: if ($env{'form.communities'} eq '1') {
16700: if (ref($cathash) eq 'HASH') {
16701: my $newitem = 'communities::0';
16702: if ($cathash->{$newitem} eq '') {
16703: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
16704: $adds{$newitem} = 1;
16705: }
16706: } else {
16707: my $newitem = 'communities::0';
16708: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
16709: $adds{$newitem} = 1;
16710: }
16711: }
1.272 raeburn 16712: if ($env{'form.placement'} eq '1') {
16713: if (ref($cathash) eq 'HASH') {
16714: my $newitem = 'placement::0';
16715: if ($cathash->{$newitem} eq '') {
16716: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
16717: $adds{$newitem} = 1;
16718: }
16719: } else {
16720: my $newitem = 'placement::0';
16721: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
16722: $adds{$newitem} = 1;
16723: }
16724: }
1.48 raeburn 16725: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 16726: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 16727: ($env{'form.addcategory_name'} ne 'communities') &&
16728: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 16729: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
16730: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
16731: $adds{$newitem} = 1;
16732: }
1.48 raeburn 16733: }
1.57 raeburn 16734: my $putresult;
1.48 raeburn 16735: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
16736: if (keys(%deletions) > 0) {
16737: foreach my $key (keys(%deletions)) {
16738: if ($predelallitems{$key} ne '') {
16739: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
16740: }
16741: }
16742: }
16743: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 16744: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 16745: if (ref($chkcats[0]) eq 'ARRAY') {
16746: my $depth = 0;
16747: my $chg = 0;
16748: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
16749: my $name = $chkcats[0][$i];
16750: my $item;
16751: if ($name eq '') {
16752: $chg ++;
16753: } else {
16754: $item = &escape($name).'::0';
16755: if ($chg) {
1.57 raeburn 16756: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 16757: }
16758: $depth ++;
1.57 raeburn 16759: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 16760: $depth --;
16761: }
16762: }
16763: }
1.57 raeburn 16764: }
16765: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
16766: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 16767: if ($putresult eq 'ok') {
1.57 raeburn 16768: my %title = (
1.120 raeburn 16769: togglecats => 'Show/Hide a course in catalog',
16770: categorize => 'Assign a category to a course',
16771: togglecatscomm => 'Show/Hide a community in catalog',
16772: categorizecomm => 'Assign a category to a community',
1.57 raeburn 16773: );
16774: my %level = (
1.120 raeburn 16775: dom => 'set in Domain ("Modify Course/Community")',
16776: crs => 'set in Course ("Course Configuration")',
16777: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 16778: none => 'No catalog',
16779: std => 'Standard catalog',
16780: domonly => 'Domain-only catalog',
16781: codesrch => 'Code search form',
1.57 raeburn 16782: );
1.48 raeburn 16783: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 16784: if ($changes{'togglecats'}) {
16785: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
16786: }
16787: if ($changes{'categorize'}) {
16788: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 16789: }
1.120 raeburn 16790: if ($changes{'togglecatscomm'}) {
16791: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
16792: }
16793: if ($changes{'categorizecomm'}) {
16794: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
16795: }
1.238 raeburn 16796: if ($changes{'unauth'}) {
16797: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
16798: }
16799: if ($changes{'auth'}) {
16800: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
16801: }
1.57 raeburn 16802: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
16803: my $cathash;
16804: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
16805: $cathash = $domconfig{'coursecategories'}{'cats'};
16806: } else {
16807: $cathash = {};
16808: }
16809: my (@cats,@trails,%allitems);
16810: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
16811: if (keys(%deletions) > 0) {
16812: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
16813: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
16814: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
16815: }
16816: $resulttext .= '</ul></li>';
16817: }
16818: if (keys(%reorderings) > 0) {
16819: my %sort_by_trail;
16820: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
16821: foreach my $key (keys(%reorderings)) {
16822: if ($allitems{$key} ne '') {
16823: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
16824: }
1.48 raeburn 16825: }
1.57 raeburn 16826: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
16827: $resulttext .= '<li>'.$trails[$trail].'</li>';
16828: }
16829: $resulttext .= '</ul></li>';
1.48 raeburn 16830: }
1.57 raeburn 16831: if (keys(%adds) > 0) {
16832: my %sort_by_trail;
16833: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
16834: foreach my $key (keys(%adds)) {
16835: if ($allitems{$key} ne '') {
16836: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
16837: }
16838: }
16839: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
16840: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 16841: }
1.57 raeburn 16842: $resulttext .= '</ul></li>';
1.48 raeburn 16843: }
16844: }
16845: $resulttext .= '</ul>';
1.239 raeburn 16846: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 16847: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
16848: if ($changes{'auth'}) {
16849: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
16850: }
16851: if ($changes{'unauth'}) {
16852: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
16853: }
16854: my $cachetime = 24*60*60;
16855: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 16856: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 16857: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 16858: }
16859: }
1.48 raeburn 16860: } else {
16861: $resulttext = '<span class="LC_error">'.
1.57 raeburn 16862: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 16863: }
16864: } else {
1.120 raeburn 16865: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 16866: }
16867: return $resulttext;
16868: }
16869:
1.69 raeburn 16870: sub modify_serverstatuses {
16871: my ($dom,%domconfig) = @_;
16872: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
16873: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
16874: %currserverstatus = %{$domconfig{'serverstatuses'}};
16875: }
16876: my @pages = &serverstatus_pages();
16877: foreach my $type (@pages) {
16878: $newserverstatus{$type}{'namedusers'} = '';
16879: $newserverstatus{$type}{'machines'} = '';
16880: if (defined($env{'form.'.$type.'_namedusers'})) {
16881: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
16882: my @okusers;
16883: foreach my $user (@users) {
16884: my ($uname,$udom) = split(/:/,$user);
16885: if (($udom =~ /^$match_domain$/) &&
16886: (&Apache::lonnet::domain($udom)) &&
16887: ($uname =~ /^$match_username$/)) {
16888: if (!grep(/^\Q$user\E/,@okusers)) {
16889: push(@okusers,$user);
16890: }
16891: }
16892: }
16893: if (@okusers > 0) {
16894: @okusers = sort(@okusers);
16895: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
16896: }
16897: }
16898: if (defined($env{'form.'.$type.'_machines'})) {
16899: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
16900: my @okmachines;
16901: foreach my $ip (@machines) {
16902: my @parts = split(/\./,$ip);
16903: next if (@parts < 4);
16904: my $badip = 0;
16905: for (my $i=0; $i<4; $i++) {
16906: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
16907: $badip = 1;
16908: last;
16909: }
16910: }
16911: if (!$badip) {
16912: push(@okmachines,$ip);
16913: }
16914: }
16915: @okmachines = sort(@okmachines);
16916: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
16917: }
16918: }
16919: my %serverstatushash = (
16920: serverstatuses => \%newserverstatus,
16921: );
16922: foreach my $type (@pages) {
1.83 raeburn 16923: foreach my $setting ('namedusers','machines') {
1.84 raeburn 16924: my (@current,@new);
1.83 raeburn 16925: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 16926: if ($currserverstatus{$type}{$setting} ne '') {
16927: @current = split(/,/,$currserverstatus{$type}{$setting});
16928: }
16929: }
16930: if ($newserverstatus{$type}{$setting} ne '') {
16931: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 16932: }
16933: if (@current > 0) {
16934: if (@new > 0) {
16935: foreach my $item (@current) {
16936: if (!grep(/^\Q$item\E$/,@new)) {
16937: $changes{$type}{$setting} = 1;
1.82 raeburn 16938: last;
16939: }
16940: }
1.84 raeburn 16941: foreach my $item (@new) {
16942: if (!grep(/^\Q$item\E$/,@current)) {
16943: $changes{$type}{$setting} = 1;
16944: last;
1.82 raeburn 16945: }
16946: }
16947: } else {
1.83 raeburn 16948: $changes{$type}{$setting} = 1;
1.69 raeburn 16949: }
1.83 raeburn 16950: } elsif (@new > 0) {
16951: $changes{$type}{$setting} = 1;
1.69 raeburn 16952: }
16953: }
16954: }
16955: if (keys(%changes) > 0) {
1.81 raeburn 16956: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 16957: my $putresult = &Apache::lonnet::put_dom('configuration',
16958: \%serverstatushash,$dom);
16959: if ($putresult eq 'ok') {
16960: $resulttext .= &mt('Changes made:').'<ul>';
16961: foreach my $type (@pages) {
1.84 raeburn 16962: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 16963: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 16964: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 16965: if ($newserverstatus{$type}{'namedusers'} eq '') {
16966: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
16967: } else {
16968: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
16969: }
1.84 raeburn 16970: }
16971: if ($changes{$type}{'machines'}) {
1.69 raeburn 16972: if ($newserverstatus{$type}{'machines'} eq '') {
16973: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
16974: } else {
16975: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
16976: }
16977:
16978: }
16979: $resulttext .= '</ul></li>';
16980: }
16981: }
16982: $resulttext .= '</ul>';
16983: } else {
16984: $resulttext = '<span class="LC_error">'.
16985: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
16986:
16987: }
16988: } else {
16989: $resulttext = &mt('No changes made to access to server status pages');
16990: }
16991: return $resulttext;
16992: }
16993:
1.118 jms 16994: sub modify_helpsettings {
1.285 raeburn 16995: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 16996: my ($resulttext,$errors,%changes,%helphash);
16997: my %defaultchecked = ('submitbugs' => 'on');
16998: my @offon = ('off','on');
1.118 jms 16999: my @toggles = ('submitbugs');
1.285 raeburn 17000: my %current = ('submitbugs' => '',
17001: 'adhoc' => {},
17002: );
1.118 jms 17003: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 17004: %current = %{$domconfig{'helpsettings'}};
17005: }
1.285 raeburn 17006: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 17007: foreach my $item (@toggles) {
17008: if ($defaultchecked{$item} eq 'on') {
17009: if ($current{$item} eq '') {
17010: if ($env{'form.'.$item} eq '0') {
17011: $changes{$item} = 1;
17012: }
17013: } elsif ($current{$item} ne $env{'form.'.$item}) {
17014: $changes{$item} = 1;
17015: }
17016: } elsif ($defaultchecked{$item} eq 'off') {
17017: if ($current{$item} eq '') {
17018: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 17019: $changes{$item} = 1;
17020: }
1.282 raeburn 17021: } elsif ($current{$item} ne $env{'form.'.$item}) {
17022: $changes{$item} = 1;
17023: }
17024: }
17025: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
17026: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
17027: }
17028: }
1.285 raeburn 17029: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 17030: my $confname = $dom.'-domainconfig';
17031: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 17032: my (@allpos,%newsettings,%changedprivs,$newrole);
17033: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 17034: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 17035: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 17036: my %lt = &Apache::lonlocal::texthash(
17037: s => 'system',
17038: d => 'domain',
17039: order => 'Display order',
17040: access => 'Role usage',
1.291 raeburn 17041: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 17042: dh => 'All with domain helpdesk role',
17043: da => 'All with domain helpdesk assistant role',
1.285 raeburn 17044: none => 'None',
17045: status => 'Determined based on institutional status',
17046: inc => 'Include all, but exclude specific personnel',
17047: exc => 'Exclude all, but include specific personnel',
17048: );
17049: for (my $num=0; $num<=$maxnum; $num++) {
17050: my ($prefix,$identifier,$rolename,%curr);
17051: if ($num == $maxnum) {
17052: next unless ($env{'form.newcusthelp'} == $maxnum);
17053: $identifier = 'custhelp'.$num;
17054: $prefix = 'helproles_'.$num;
17055: $rolename = $env{'form.custhelpname'.$num};
17056: $rolename=~s/[^A-Za-z0-9]//gs;
17057: next if ($rolename eq '');
17058: next if (exists($existing{'rolesdef_'.$rolename}));
17059: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
17060: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
17061: $newprivs{'c'},$confname,$dom);
17062: if ($result ne 'ok') {
17063: $errors .= '<li><span class="LC_error">'.
17064: &mt('An error occurred storing the new custom role: [_1]',
17065: $result).'</span></li>';
17066: next;
17067: } else {
17068: $changedprivs{$rolename} = \%newprivs;
17069: $newrole = $rolename;
17070: }
17071: } else {
17072: $prefix = 'helproles_'.$num;
17073: $rolename = $env{'form.'.$prefix};
17074: next if ($rolename eq '');
17075: next unless (exists($existing{'rolesdef_'.$rolename}));
17076: $identifier = 'custhelp'.$num;
17077: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
17078: my %currprivs;
1.289 raeburn 17079: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 17080: split(/\_/,$existing{'rolesdef_'.$rolename});
17081: foreach my $level ('c','d','s') {
17082: if ($newprivs{$level} ne $currprivs{$level}) {
17083: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
17084: $newprivs{'c'},$confname,$dom);
17085: if ($result ne 'ok') {
17086: $errors .= '<li><span class="LC_error">'.
17087: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
17088: $rolename,$result).'</span></li>';
17089: } else {
17090: $changedprivs{$rolename} = \%newprivs;
17091: }
17092: last;
17093: }
17094: }
17095: if (ref($current{'adhoc'}) eq 'HASH') {
17096: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
17097: %curr = %{$current{'adhoc'}{$rolename}};
17098: }
17099: }
17100: }
17101: my $newpos = $env{'form.'.$prefix.'_pos'};
17102: $newpos =~ s/\D+//g;
17103: $allpos[$newpos] = $rolename;
17104: my $newdesc = $env{'form.'.$prefix.'_desc'};
17105: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
17106: if ($curr{'desc'}) {
17107: if ($curr{'desc'} ne $newdesc) {
17108: $changes{'customrole'}{$rolename}{'desc'} = 1;
17109: $newsettings{$rolename}{'desc'} = $newdesc;
17110: }
17111: } elsif ($newdesc ne '') {
17112: $changes{'customrole'}{$rolename}{'desc'} = 1;
17113: $newsettings{$rolename}{'desc'} = $newdesc;
17114: }
17115: my $access = $env{'form.'.$prefix.'_access'};
17116: if (grep(/^\Q$access\E$/,@accesstypes)) {
17117: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
17118: if ($access eq 'status') {
17119: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
17120: if (scalar(@statuses) == 0) {
1.289 raeburn 17121: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 17122: } else {
17123: my (@shownstatus,$numtypes);
17124: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
17125: if (ref($types) eq 'ARRAY') {
17126: $numtypes = scalar(@{$types});
17127: foreach my $type (sort(@statuses)) {
17128: if ($type eq 'default') {
17129: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
17130: } elsif (grep(/^\Q$type\E$/,@{$types})) {
17131: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
17132: push(@shownstatus,$usertypes->{$type});
17133: }
17134: }
17135: }
17136: if (grep(/^default$/,@statuses)) {
17137: push(@shownstatus,$othertitle);
17138: }
17139: if (scalar(@shownstatus) == 1+$numtypes) {
17140: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
17141: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
17142: } else {
17143: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
17144: if (ref($curr{'status'}) eq 'ARRAY') {
17145: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
17146: if (@diffs) {
17147: $changes{'customrole'}{$rolename}{$access} = 1;
17148: }
17149: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
17150: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 17151: }
1.166 raeburn 17152: }
17153: }
1.285 raeburn 17154: } elsif (($access eq 'inc') || ($access eq 'exc')) {
17155: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
17156: my @newspecstaff;
17157: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
17158: foreach my $person (sort(@personnel)) {
17159: if ($domhelpdesk{$person}) {
17160: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
17161: }
17162: }
17163: if (ref($curr{$access}) eq 'ARRAY') {
17164: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
17165: if (@diffs) {
17166: $changes{'customrole'}{$rolename}{$access} = 1;
17167: }
17168: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
17169: $changes{'customrole'}{$rolename}{$access} = 1;
17170: }
17171: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
17172: my ($uname,$udom) = split(/:/,$person);
17173: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
17174: }
17175: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 17176: }
1.285 raeburn 17177: } else {
17178: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
17179: }
17180: unless ($curr{'access'} eq $access) {
17181: $changes{'customrole'}{$rolename}{'access'} = 1;
17182: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 17183: }
17184: }
1.285 raeburn 17185: if (@allpos > 0) {
17186: my $idx = 0;
17187: foreach my $rolename (@allpos) {
17188: if ($rolename ne '') {
17189: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
17190: if (ref($current{'adhoc'}) eq 'HASH') {
17191: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
17192: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
17193: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 17194: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 17195: }
17196: }
1.282 raeburn 17197: }
1.285 raeburn 17198: $idx ++;
1.166 raeburn 17199: }
17200: }
1.118 jms 17201: }
1.123 jms 17202: my $putresult;
17203: if (keys(%changes) > 0) {
1.166 raeburn 17204: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 17205: if ($putresult eq 'ok') {
1.285 raeburn 17206: if (ref($helphash{'helpsettings'}) eq 'HASH') {
17207: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
17208: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
17209: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
17210: }
17211: }
17212: my $cachetime = 24*60*60;
17213: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17214: if (ref($lastactref) eq 'HASH') {
17215: $lastactref->{'domdefaults'} = 1;
17216: }
17217: } else {
17218: $errors .= '<li><span class="LC_error">'.
17219: &mt('An error occurred storing the settings: [_1]',
17220: $putresult).'</span></li>';
17221: }
17222: }
17223: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
17224: $resulttext = &mt('Changes made:').'<ul>';
17225: my (%shownprivs,@levelorder);
17226: @levelorder = ('c','d','s');
17227: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 17228: foreach my $item (sort(keys(%changes))) {
17229: if ($item eq 'submitbugs') {
17230: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
17231: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
17232: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 17233: } elsif ($item eq 'customrole') {
17234: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 17235: my @keyorder = ('order','desc','access','status','exc','inc');
17236: my %keytext = &Apache::lonlocal::texthash(
17237: order => 'Order',
17238: desc => 'Role description',
17239: access => 'Role usage',
1.300 droeschl 17240: status => 'Allowed institutional types',
1.285 raeburn 17241: exc => 'Allowed personnel',
17242: inc => 'Disallowed personnel',
17243: );
1.282 raeburn 17244: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 17245: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
17246: if ($role eq $newrole) {
17247: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
17248: $role).'<ul>';
17249: } else {
17250: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
17251: $role).'<ul>';
17252: }
17253: foreach my $key (@keyorder) {
17254: if ($changes{'customrole'}{$role}{$key}) {
17255: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
17256: $keytext{$key},$newsettings{$role}{$key}).
17257: '</li>';
17258: }
17259: }
17260: if (ref($changedprivs{$role}) eq 'HASH') {
17261: $shownprivs{$role} = 1;
17262: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
17263: foreach my $level (@levelorder) {
17264: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
17265: next if ($item eq '');
17266: my ($priv) = split(/\&/,$item,2);
17267: if (&Apache::lonnet::plaintext($priv)) {
17268: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
17269: unless ($level eq 'c') {
17270: $resulttext .= ' ('.$lt{$level}.')';
17271: }
17272: $resulttext .= '</li>';
17273: }
17274: }
17275: }
17276: $resulttext .= '</ul>';
17277: }
17278: $resulttext .= '</ul></li>';
17279: }
17280: }
17281: }
17282: }
17283: }
17284: }
17285: if (keys(%changedprivs)) {
17286: foreach my $role (sort(keys(%changedprivs))) {
17287: unless ($shownprivs{$role}) {
17288: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
17289: $role).'<ul>'.
17290: '<li>'.&mt('Privileges set to :').'<ul>';
17291: foreach my $level (@levelorder) {
17292: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
17293: next if ($item eq '');
17294: my ($priv) = split(/\&/,$item,2);
17295: if (&Apache::lonnet::plaintext($priv)) {
17296: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
17297: unless ($level eq 'c') {
17298: $resulttext .= ' ('.$lt{$level}.')';
17299: }
17300: $resulttext .= '</li>';
17301: }
1.282 raeburn 17302: }
17303: }
1.285 raeburn 17304: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 17305: }
17306: }
17307: }
1.285 raeburn 17308: $resulttext .= '</ul>';
17309: } else {
17310: $resulttext = &mt('No changes made to help settings');
1.118 jms 17311: }
17312: if ($errors) {
1.168 raeburn 17313: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 17314: $errors.'</ul>';
1.118 jms 17315: }
17316: return $resulttext;
17317: }
17318:
1.121 raeburn 17319: sub modify_coursedefaults {
1.212 raeburn 17320: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 17321: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 17322: my %defaultchecked = (
17323: 'canuse_pdfforms' => 'off',
17324: 'uselcmath' => 'on',
17325: 'usejsme' => 'on'
17326: );
17327: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 17328: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 17329: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
17330: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
17331: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 17332: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 17333: my %staticdefaults = (
17334: anonsurvey_threshold => 10,
17335: uploadquota => 500,
1.257 raeburn 17336: postsubmit => 60,
1.276 raeburn 17337: mysqltables => 172800,
1.198 raeburn 17338: );
1.314 raeburn 17339: my %texoptions = (
17340: MathJax => 'MathJax',
17341: mimetex => &mt('Convert to Images'),
17342: tth => &mt('TeX to HTML'),
17343: );
1.121 raeburn 17344: $defaultshash{'coursedefaults'} = {};
17345:
17346: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
17347: if ($domconfig{'coursedefaults'} eq '') {
17348: $domconfig{'coursedefaults'} = {};
17349: }
17350: }
17351:
17352: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
17353: foreach my $item (@toggles) {
17354: if ($defaultchecked{$item} eq 'on') {
17355: if (($domconfig{'coursedefaults'}{$item} eq '') &&
17356: ($env{'form.'.$item} eq '0')) {
17357: $changes{$item} = 1;
1.192 raeburn 17358: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 17359: $changes{$item} = 1;
17360: }
17361: } elsif ($defaultchecked{$item} eq 'off') {
17362: if (($domconfig{'coursedefaults'}{$item} eq '') &&
17363: ($env{'form.'.$item} eq '1')) {
17364: $changes{$item} = 1;
17365: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
17366: $changes{$item} = 1;
17367: }
17368: }
17369: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
17370: }
1.198 raeburn 17371: foreach my $item (@numbers) {
17372: my ($currdef,$newdef);
1.208 raeburn 17373: $newdef = $env{'form.'.$item};
1.198 raeburn 17374: if ($item eq 'anonsurvey_threshold') {
17375: $currdef = $domconfig{'coursedefaults'}{$item};
17376: $newdef =~ s/\D//g;
17377: if ($newdef eq '' || $newdef < 1) {
17378: $newdef = 1;
17379: }
17380: $defaultshash{'coursedefaults'}{$item} = $newdef;
17381: } else {
1.276 raeburn 17382: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
17383: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
17384: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 17385: }
17386: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 17387: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 17388: }
17389: if ($currdef ne $newdef) {
17390: if ($item eq 'anonsurvey_threshold') {
17391: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
17392: $changes{$item} = 1;
17393: }
1.276 raeburn 17394: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 17395: my $setting = $1;
1.276 raeburn 17396: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
17397: $changes{$setting} = 1;
1.198 raeburn 17398: }
17399: }
1.139 raeburn 17400: }
17401: }
1.314 raeburn 17402: my $texengine;
17403: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
17404: $texengine = $env{'form.texengine'};
1.349 raeburn 17405: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
17406: if ($currdef eq '') {
17407: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 17408: $changes{'texengine'} = 1;
17409: }
1.349 raeburn 17410: } elsif ($currdef ne $texengine) {
1.314 raeburn 17411: $changes{'texengine'} = 1;
17412: }
17413: }
17414: if ($texengine ne '') {
17415: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
17416: }
1.264 raeburn 17417: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
17418: my @currclonecode;
17419: if (ref($currclone) eq 'HASH') {
17420: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
17421: @currclonecode = @{$currclone->{'instcode'}};
17422: }
17423: }
17424: my $newclone;
1.289 raeburn 17425: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 17426: $newclone = $env{'form.canclone'};
17427: }
17428: if ($newclone eq 'instcode') {
17429: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
17430: my (%codedefaults,@code_order,@clonecode);
17431: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
17432: \@code_order);
17433: foreach my $item (@code_order) {
17434: if (grep(/^\Q$item\E$/,@newcodes)) {
17435: push(@clonecode,$item);
17436: }
17437: }
17438: if (@clonecode) {
17439: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
17440: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
17441: if (@diffs) {
17442: $changes{'canclone'} = 1;
17443: }
17444: } else {
17445: $newclone eq '';
17446: }
17447: } elsif ($newclone ne '') {
1.289 raeburn 17448: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
17449: }
1.264 raeburn 17450: if ($newclone ne $currclone) {
17451: $changes{'canclone'} = 1;
17452: }
1.257 raeburn 17453: my %credits;
17454: foreach my $type (@types) {
17455: unless ($type eq 'community') {
17456: $credits{$type} = $env{'form.'.$type.'_credits'};
17457: $credits{$type} =~ s/[^\d.]+//g;
17458: }
17459: }
17460: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
17461: ($env{'form.coursecredits'} eq '1')) {
17462: $changes{'coursecredits'} = 1;
17463: foreach my $type (keys(%credits)) {
17464: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
17465: }
17466: } else {
1.289 raeburn 17467: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 17468: foreach my $type (@types) {
17469: unless ($type eq 'community') {
1.289 raeburn 17470: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 17471: $changes{'coursecredits'} = 1;
17472: }
17473: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
17474: }
17475: }
17476: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
17477: foreach my $type (@types) {
17478: unless ($type eq 'community') {
17479: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
17480: $changes{'coursecredits'} = 1;
17481: last;
17482: }
17483: }
17484: }
17485: }
17486: }
17487: if ($env{'form.postsubmit'} eq '1') {
17488: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
17489: my %currtimeout;
17490: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17491: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
17492: $changes{'postsubmit'} = 1;
17493: }
17494: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17495: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
17496: }
17497: } else {
17498: $changes{'postsubmit'} = 1;
17499: }
17500: foreach my $type (@types) {
17501: my $timeout = $env{'form.'.$type.'_timeout'};
17502: $timeout =~ s/\D//g;
17503: if ($timeout == $staticdefaults{'postsubmit'}) {
17504: $timeout = '';
17505: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
17506: $timeout = '0';
17507: }
17508: unless ($timeout eq '') {
17509: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
17510: }
17511: if (exists($currtimeout{$type})) {
17512: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 17513: $changes{'postsubmit'} = 1;
1.257 raeburn 17514: }
17515: } elsif ($timeout ne '') {
17516: $changes{'postsubmit'} = 1;
17517: }
17518: }
17519: } else {
17520: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
17521: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17522: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
17523: $changes{'postsubmit'} = 1;
17524: }
17525: } else {
17526: $changes{'postsubmit'} = 1;
17527: }
1.192 raeburn 17528: }
1.121 raeburn 17529: }
17530: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
17531: $dom);
17532: if ($putresult eq 'ok') {
17533: if (keys(%changes) > 0) {
1.213 raeburn 17534: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 17535: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 17536: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314 raeburn 17537: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
17538: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257 raeburn 17539: if ($changes{$item}) {
17540: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
17541: }
1.289 raeburn 17542: }
1.192 raeburn 17543: if ($changes{'coursecredits'}) {
17544: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 17545: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
17546: $domdefaults{$type.'credits'} =
17547: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
17548: }
17549: }
17550: }
17551: if ($changes{'postsubmit'}) {
17552: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17553: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
17554: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17555: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
17556: $domdefaults{$type.'postsubtimeout'} =
17557: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
17558: }
17559: }
1.192 raeburn 17560: }
17561: }
1.198 raeburn 17562: if ($changes{'uploadquota'}) {
17563: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
17564: foreach my $type (@types) {
17565: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
17566: }
17567: }
17568: }
1.264 raeburn 17569: if ($changes{'canclone'}) {
17570: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
17571: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
17572: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
17573: if (@clonecodes) {
17574: $domdefaults{'canclone'} = join('+',@clonecodes);
17575: }
17576: }
17577: } else {
17578: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
17579: }
17580: }
1.121 raeburn 17581: my $cachetime = 24*60*60;
17582: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 17583: if (ref($lastactref) eq 'HASH') {
17584: $lastactref->{'domdefaults'} = 1;
17585: }
1.121 raeburn 17586: }
17587: $resulttext = &mt('Changes made:').'<ul>';
17588: foreach my $item (sort(keys(%changes))) {
17589: if ($item eq 'canuse_pdfforms') {
17590: if ($env{'form.'.$item} eq '1') {
17591: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
17592: } else {
17593: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
17594: }
1.257 raeburn 17595: } elsif ($item eq 'uselcmath') {
17596: if ($env{'form.'.$item} eq '1') {
17597: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
17598: } else {
17599: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
17600: }
17601: } elsif ($item eq 'usejsme') {
17602: if ($env{'form.'.$item} eq '1') {
17603: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
17604: } else {
1.289 raeburn 17605: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 17606: }
1.314 raeburn 17607: } elsif ($item eq 'texengine') {
17608: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
17609: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
17610: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
17611: }
1.139 raeburn 17612: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 17613: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 17614: } elsif ($item eq 'uploadquota') {
17615: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
17616: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
17617: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
17618: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 17619: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 17620: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 17621: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
17622: '</ul>'.
17623: '</li>';
17624: } else {
17625: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
17626: }
1.276 raeburn 17627: } elsif ($item eq 'mysqltables') {
17628: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
17629: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
17630: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
17631: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
17632: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
17633: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
17634: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
17635: '</ul>'.
17636: '</li>';
17637: } else {
17638: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
17639: }
1.257 raeburn 17640: } elsif ($item eq 'postsubmit') {
17641: if ($domdefaults{'postsubmit'} eq 'off') {
17642: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
17643: } else {
17644: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 17645: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 17646: $resulttext .= &mt('durations:').'<ul>';
17647: foreach my $type (@types) {
17648: $resulttext .= '<li>';
17649: my $timeout;
17650: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17651: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
17652: }
17653: my $display;
17654: if ($timeout eq '0') {
17655: $display = &mt('unlimited');
17656: } elsif ($timeout eq '') {
17657: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
17658: } else {
17659: $display = &mt('[quant,_1,second]',$timeout);
17660: }
17661: if ($type eq 'community') {
17662: $resulttext .= &mt('Communities');
17663: } elsif ($type eq 'official') {
17664: $resulttext .= &mt('Official courses');
17665: } elsif ($type eq 'unofficial') {
17666: $resulttext .= &mt('Unofficial courses');
17667: } elsif ($type eq 'textbook') {
17668: $resulttext .= &mt('Textbook courses');
1.271 raeburn 17669: } elsif ($type eq 'placement') {
17670: $resulttext .= &mt('Placement tests');
1.257 raeburn 17671: }
17672: $resulttext .= ' -- '.$display.'</li>';
17673: }
17674: $resulttext .= '</ul>';
17675: }
1.289 raeburn 17676: $resulttext .= '</li>';
1.257 raeburn 17677: }
1.192 raeburn 17678: } elsif ($item eq 'coursecredits') {
17679: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
17680: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 17681: ($domdefaults{'unofficialcredits'} eq '') &&
17682: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 17683: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
17684: } else {
17685: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
17686: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
17687: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 17688: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 17689: '</ul>'.
17690: '</li>';
17691: }
17692: } else {
17693: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
17694: }
1.264 raeburn 17695: } elsif ($item eq 'canclone') {
17696: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
17697: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
17698: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
17699: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
17700: }
17701: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
17702: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
17703: } else {
1.289 raeburn 17704: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 17705: }
1.140 raeburn 17706: }
1.121 raeburn 17707: }
17708: $resulttext .= '</ul>';
17709: } else {
17710: $resulttext = &mt('No changes made to course defaults');
17711: }
17712: } else {
17713: $resulttext = '<span class="LC_error">'.
17714: &mt('An error occurred: [_1]',$putresult).'</span>';
17715: }
17716: return $resulttext;
17717: }
17718:
1.231 raeburn 17719: sub modify_selfenrollment {
17720: my ($dom,$lastactref,%domconfig) = @_;
17721: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 17722: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 17723: my %titles = &tool_titles();
1.232 raeburn 17724: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
17725: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 17726: $ordered{'default'} = ['types','registered','approval','limit'];
17727:
17728: my (%roles,%shown,%toplevel);
17729: $roles{'0'} = &Apache::lonnet::plaintext('dc');
17730:
17731: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
17732: if ($domconfig{'selfenrollment'} eq '') {
17733: $domconfig{'selfenrollment'} = {};
17734: }
17735: }
17736: %toplevel = (
17737: admin => 'Configuration Rights',
17738: default => 'Default settings',
17739: validation => 'Validation of self-enrollment requests',
17740: );
1.233 raeburn 17741: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 17742:
17743: if (ref($ordered{'admin'}) eq 'ARRAY') {
17744: foreach my $item (@{$ordered{'admin'}}) {
17745: foreach my $type (@types) {
17746: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
17747: $selfenrollhash{'admin'}{$type}{$item} = 1;
17748: } else {
17749: $selfenrollhash{'admin'}{$type}{$item} = 0;
17750: }
17751: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
17752: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
17753: if ($selfenrollhash{'admin'}{$type}{$item} ne
17754: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
17755: push(@{$changes{'admin'}{$type}},$item);
17756: }
17757: } else {
17758: if (!$selfenrollhash{'admin'}{$type}{$item}) {
17759: push(@{$changes{'admin'}{$type}},$item);
17760: }
17761: }
17762: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
17763: push(@{$changes{'admin'}{$type}},$item);
17764: }
17765: }
17766: }
17767: }
17768:
17769: foreach my $item (@{$ordered{'default'}}) {
17770: foreach my $type (@types) {
17771: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
17772: if ($item eq 'types') {
17773: unless (($value eq 'all') || ($value eq 'dom')) {
17774: $value = '';
17775: }
17776: } elsif ($item eq 'registered') {
17777: unless ($value eq '1') {
17778: $value = 0;
17779: }
17780: } elsif ($item eq 'approval') {
17781: unless ($value =~ /^[012]$/) {
17782: $value = 0;
17783: }
17784: } else {
17785: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
17786: $value = 'none';
17787: }
17788: }
17789: $selfenrollhash{'default'}{$type}{$item} = $value;
17790: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
17791: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
17792: if ($selfenrollhash{'default'}{$type}{$item} ne
17793: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
17794: push(@{$changes{'default'}{$type}},$item);
17795: }
17796: } else {
17797: push(@{$changes{'default'}{$type}},$item);
17798: }
17799: } else {
17800: push(@{$changes{'default'}{$type}},$item);
17801: }
17802: if ($item eq 'limit') {
17803: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
17804: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
17805: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
17806: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
17807: }
17808: } else {
17809: $selfenrollhash{'default'}{$type}{'cap'} = '';
17810: }
17811: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
17812: if ($selfenrollhash{'default'}{$type}{'cap'} ne
17813: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
17814: push(@{$changes{'default'}{$type}},'cap');
17815: }
17816: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
17817: push(@{$changes{'default'}{$type}},'cap');
17818: }
17819: }
17820: }
17821: }
17822:
17823: foreach my $item (@{$itemsref}) {
17824: if ($item eq 'fields') {
17825: my @changed;
17826: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
17827: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
17828: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
17829: }
17830: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
17831: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
17832: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
17833: $domconfig{'selfenrollment'}{'validation'}{$item});
17834: } else {
17835: @changed = @{$selfenrollhash{'validation'}{$item}};
17836: }
17837: } else {
17838: @changed = @{$selfenrollhash{'validation'}{$item}};
17839: }
17840: if (@changed) {
17841: if ($selfenrollhash{'validation'}{$item}) {
17842: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
17843: } else {
17844: $changes{'validation'}{$item} = &mt('None');
17845: }
17846: }
17847: } else {
17848: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
17849: if ($item eq 'markup') {
17850: if ($env{'form.selfenroll_validation_'.$item}) {
17851: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
17852: }
17853: }
17854: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
17855: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
17856: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
17857: }
17858: }
17859: }
17860: }
17861:
17862: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
17863: $dom);
17864: if ($putresult eq 'ok') {
17865: if (keys(%changes) > 0) {
17866: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
17867: $resulttext = &mt('Changes made:').'<ul>';
17868: foreach my $key ('admin','default','validation') {
17869: if (ref($changes{$key}) eq 'HASH') {
17870: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
17871: if ($key eq 'validation') {
17872: foreach my $item (@{$itemsref}) {
17873: if (exists($changes{$key}{$item})) {
17874: if ($item eq 'markup') {
17875: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
17876: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
17877: } else {
17878: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
17879: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
17880: }
17881: }
17882: }
17883: } else {
17884: foreach my $type (@types) {
17885: if ($type eq 'community') {
17886: $roles{'1'} = &mt('Community personnel');
17887: } else {
17888: $roles{'1'} = &mt('Course personnel');
17889: }
17890: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 17891: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
17892: if ($key eq 'admin') {
17893: my @mgrdc = ();
17894: if (ref($ordered{$key}) eq 'ARRAY') {
17895: foreach my $item (@{$ordered{'admin'}}) {
17896: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
17897: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
17898: push(@mgrdc,$item);
17899: }
17900: }
17901: }
17902: if (@mgrdc) {
17903: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
17904: } else {
17905: delete($domdefaults{$type.'selfenrolladmdc'});
17906: }
17907: }
17908: } else {
17909: if (ref($ordered{$key}) eq 'ARRAY') {
17910: foreach my $item (@{$ordered{$key}}) {
17911: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
17912: $domdefaults{$type.'selfenroll'.$item} =
17913: $selfenrollhash{$key}{$type}{$item};
17914: }
17915: }
17916: }
17917: }
17918: }
1.231 raeburn 17919: $resulttext .= '<li>'.$titles{$type}.'<ul>';
17920: foreach my $item (@{$ordered{$key}}) {
17921: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
17922: $resulttext .= '<li>';
17923: if ($key eq 'admin') {
17924: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
17925: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
17926: } else {
17927: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
17928: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
17929: }
17930: $resulttext .= '</li>';
17931: }
17932: }
17933: $resulttext .= '</ul></li>';
17934: }
17935: }
17936: $resulttext .= '</ul></li>';
17937: }
17938: }
1.305 raeburn 17939: }
17940: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
17941: my $cachetime = 24*60*60;
17942: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17943: if (ref($lastactref) eq 'HASH') {
17944: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 17945: }
1.231 raeburn 17946: }
17947: $resulttext .= '</ul>';
17948: } else {
17949: $resulttext = &mt('No changes made to self-enrollment settings');
17950: }
17951: } else {
17952: $resulttext = '<span class="LC_error">'.
17953: &mt('An error occurred: [_1]',$putresult).'</span>';
17954: }
17955: return $resulttext;
17956: }
17957:
1.137 raeburn 17958: sub modify_usersessions {
1.212 raeburn 17959: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 17960: my @hostingtypes = ('version','excludedomain','includedomain');
17961: my @offloadtypes = ('primary','default');
17962: my %types = (
17963: remote => \@hostingtypes,
17964: hosted => \@hostingtypes,
17965: spares => \@offloadtypes,
17966: );
17967: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 17968: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 17969: my (%by_ip,%by_location,@intdoms,@instdoms);
17970: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 17971: my @locations = sort(keys(%by_location));
1.137 raeburn 17972: my (%defaultshash,%changes);
17973: foreach my $prefix (@prefixes) {
17974: $defaultshash{'usersessions'}{$prefix} = {};
17975: }
1.212 raeburn 17976: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 17977: my $resulttext;
1.138 raeburn 17978: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 17979: foreach my $prefix (@prefixes) {
1.145 raeburn 17980: next if ($prefix eq 'spares');
17981: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 17982: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
17983: if ($type eq 'version') {
17984: my $value = $env{'form.'.$prefix.'_'.$type};
17985: my $okvalue;
17986: if ($value ne '') {
17987: if (grep(/^\Q$value\E$/,@lcversions)) {
17988: $okvalue = $value;
17989: }
17990: }
17991: if (ref($domconfig{'usersessions'}) eq 'HASH') {
17992: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
17993: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
17994: if ($inuse == 0) {
17995: $changes{$prefix}{$type} = 1;
17996: } else {
17997: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
17998: $changes{$prefix}{$type} = 1;
17999: }
18000: if ($okvalue ne '') {
18001: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
18002: }
18003: }
18004: } else {
18005: if (($inuse == 1) && ($okvalue ne '')) {
18006: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
18007: $changes{$prefix}{$type} = 1;
18008: }
18009: }
18010: } else {
18011: if (($inuse == 1) && ($okvalue ne '')) {
18012: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
18013: $changes{$prefix}{$type} = 1;
18014: }
18015: }
18016: } else {
18017: if (($inuse == 1) && ($okvalue ne '')) {
18018: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
18019: $changes{$prefix}{$type} = 1;
18020: }
18021: }
18022: } else {
18023: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
18024: my @okvals;
18025: foreach my $val (@vals) {
1.138 raeburn 18026: if ($val =~ /:/) {
18027: my @items = split(/:/,$val);
18028: foreach my $item (@items) {
18029: if (ref($by_location{$item}) eq 'ARRAY') {
18030: push(@okvals,$item);
18031: }
18032: }
18033: } else {
18034: if (ref($by_location{$val}) eq 'ARRAY') {
18035: push(@okvals,$val);
18036: }
1.137 raeburn 18037: }
18038: }
18039: @okvals = sort(@okvals);
18040: if (ref($domconfig{'usersessions'}) eq 'HASH') {
18041: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
18042: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
18043: if ($inuse == 0) {
18044: $changes{$prefix}{$type} = 1;
18045: } else {
18046: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
18047: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
18048: if (@changed > 0) {
18049: $changes{$prefix}{$type} = 1;
18050: }
18051: }
18052: } else {
18053: if ($inuse == 1) {
18054: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
18055: $changes{$prefix}{$type} = 1;
18056: }
18057: }
18058: } else {
18059: if ($inuse == 1) {
18060: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
18061: $changes{$prefix}{$type} = 1;
18062: }
18063: }
18064: } else {
18065: if ($inuse == 1) {
18066: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
18067: $changes{$prefix}{$type} = 1;
18068: }
18069: }
18070: }
18071: }
18072: }
1.145 raeburn 18073:
18074: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 18075: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 18076: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
18077: my $savespares;
18078:
18079: foreach my $lonhost (sort(keys(%servers))) {
18080: my $serverhomeID =
18081: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 18082: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 18083: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
18084: my %spareschg;
18085: foreach my $type (@{$types{'spares'}}) {
18086: my @okspares;
18087: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
18088: foreach my $server (@checked) {
1.152 raeburn 18089: if (&Apache::lonnet::hostname($server) ne '') {
18090: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
18091: unless (grep(/^\Q$server\E$/,@okspares)) {
18092: push(@okspares,$server);
18093: }
1.145 raeburn 18094: }
18095: }
18096: }
18097: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
18098: my $newspare;
1.152 raeburn 18099: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
18100: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 18101: $newspare = $new;
18102: }
18103: }
1.152 raeburn 18104: my @spares;
18105: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
18106: @spares = sort(@okspares,$newspare);
18107: } else {
18108: @spares = sort(@okspares);
18109: }
18110: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 18111: if (ref($spareid{$lonhost}) eq 'HASH') {
18112: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 18113: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 18114: if (@diffs > 0) {
18115: $spareschg{$type} = 1;
18116: }
18117: }
18118: }
18119: }
18120: if (keys(%spareschg) > 0) {
18121: $changes{'spares'}{$lonhost} = \%spareschg;
18122: }
18123: }
1.261 raeburn 18124: $defaultshash{'usersessions'}{'offloadnow'} = {};
18125: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
18126: my @okoffload;
18127: if (@offloadnow) {
18128: foreach my $server (@offloadnow) {
18129: if (&Apache::lonnet::hostname($server) ne '') {
18130: unless (grep(/^\Q$server\E$/,@okoffload)) {
18131: push(@okoffload,$server);
18132: }
18133: }
18134: }
18135: if (@okoffload) {
18136: foreach my $lonhost (@okoffload) {
18137: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
18138: }
18139: }
18140: }
1.145 raeburn 18141: if (ref($domconfig{'usersessions'}) eq 'HASH') {
18142: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
18143: if (ref($changes{'spares'}) eq 'HASH') {
18144: if (keys(%{$changes{'spares'}}) > 0) {
18145: $savespares = 1;
18146: }
18147: }
18148: } else {
18149: $savespares = 1;
18150: }
1.261 raeburn 18151: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
18152: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
18153: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
18154: $changes{'offloadnow'} = 1;
18155: last;
18156: }
18157: }
18158: unless ($changes{'offloadnow'}) {
1.289 raeburn 18159: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 18160: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
18161: $changes{'offloadnow'} = 1;
18162: last;
18163: }
18164: }
18165: }
18166: } elsif (@okoffload) {
18167: $changes{'offloadnow'} = 1;
18168: }
18169: } elsif (@okoffload) {
18170: $changes{'offloadnow'} = 1;
1.145 raeburn 18171: }
1.147 raeburn 18172: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
18173: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 18174: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
18175: $dom);
18176: if ($putresult eq 'ok') {
18177: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
18178: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
18179: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
18180: }
18181: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
18182: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
18183: }
1.261 raeburn 18184: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
18185: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
18186: }
1.137 raeburn 18187: }
18188: my $cachetime = 24*60*60;
18189: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 18190: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 18191: if (ref($lastactref) eq 'HASH') {
18192: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 18193: $lastactref->{'usersessions'} = 1;
1.212 raeburn 18194: }
1.147 raeburn 18195: if (keys(%changes) > 0) {
18196: my %lt = &usersession_titles();
18197: $resulttext = &mt('Changes made:').'<ul>';
18198: foreach my $prefix (@prefixes) {
18199: if (ref($changes{$prefix}) eq 'HASH') {
18200: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
18201: if ($prefix eq 'spares') {
18202: if (ref($changes{$prefix}) eq 'HASH') {
18203: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
18204: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 18205: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 18206: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
18207: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 18208: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
18209: foreach my $type (@{$types{$prefix}}) {
18210: if ($changes{$prefix}{$lonhost}{$type}) {
18211: my $offloadto = &mt('None');
18212: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
18213: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
18214: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
18215: }
1.145 raeburn 18216: }
1.147 raeburn 18217: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 18218: }
1.137 raeburn 18219: }
18220: }
1.147 raeburn 18221: $resulttext .= '</li>';
1.137 raeburn 18222: }
18223: }
1.147 raeburn 18224: } else {
18225: foreach my $type (@{$types{$prefix}}) {
18226: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 18227: my ($newvalue,$notinuse);
1.147 raeburn 18228: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
18229: if (ref($defaultshash{'usersessions'}{$prefix})) {
18230: if ($type eq 'version') {
18231: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 18232: } else {
18233: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
18234: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
18235: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
18236: }
18237: } else {
18238: $notinuse = 1;
1.147 raeburn 18239: }
1.145 raeburn 18240: }
18241: }
18242: }
1.147 raeburn 18243: if ($newvalue eq '') {
18244: if ($type eq 'version') {
18245: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 18246: } elsif ($notinuse) {
18247: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 18248: } else {
18249: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
18250: }
1.145 raeburn 18251: } else {
1.147 raeburn 18252: if ($type eq 'version') {
1.344 raeburn 18253: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 18254: }
18255: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 18256: }
1.137 raeburn 18257: }
18258: }
18259: }
1.147 raeburn 18260: $resulttext .= '</ul>';
1.137 raeburn 18261: }
18262: }
1.261 raeburn 18263: if ($changes{'offloadnow'}) {
18264: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
18265: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
18266: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
18267: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
18268: $resulttext .= '<li>'.$lonhost.'</li>';
18269: }
18270: $resulttext .= '</ul>';
18271: } else {
18272: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
18273: }
18274: } else {
18275: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
18276: }
18277: }
1.147 raeburn 18278: $resulttext .= '</ul>';
18279: } else {
18280: $resulttext = $nochgmsg;
1.137 raeburn 18281: }
18282: } else {
18283: $resulttext = '<span class="LC_error">'.
18284: &mt('An error occurred: [_1]',$putresult).'</span>';
18285: }
18286: } else {
1.147 raeburn 18287: $resulttext = $nochgmsg;
1.137 raeburn 18288: }
18289: return $resulttext;
18290: }
18291:
1.275 raeburn 18292: sub modify_ssl {
18293: my ($dom,$lastactref,%domconfig) = @_;
18294: my (%by_ip,%by_location,@intdoms,@instdoms);
18295: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
18296: my @locations = sort(keys(%by_location));
18297: my %servers = &Apache::lonnet::internet_dom_servers($dom);
18298: my (%defaultshash,%changes);
18299: my $action = 'ssl';
1.293 raeburn 18300: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 18301: foreach my $prefix (@prefixes) {
18302: $defaultshash{$action}{$prefix} = {};
18303: }
18304: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18305: my $resulttext;
18306: my %iphost = &Apache::lonnet::get_iphost();
18307: my @reptypes = ('certreq','nocertreq');
18308: my @connecttypes = ('dom','intdom','other');
18309: my %types = (
1.293 raeburn 18310: connto => \@connecttypes,
18311: connfrom => \@connecttypes,
18312: replication => \@reptypes,
1.275 raeburn 18313: );
18314: foreach my $prefix (sort(keys(%types))) {
18315: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 18316: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 18317: my $value = 'yes';
18318: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
18319: $value = $env{'form.'.$prefix.'_'.$type};
18320: }
1.335 raeburn 18321: if (ref($domconfig{$action}) eq 'HASH') {
18322: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
18323: if ($domconfig{$action}{$prefix}{$type} ne '') {
18324: if ($value ne $domconfig{$action}{$prefix}{$type}) {
18325: $changes{$prefix}{$type} = 1;
18326: }
18327: $defaultshash{$action}{$prefix}{$type} = $value;
18328: } else {
18329: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 18330: $changes{$prefix}{$type} = 1;
18331: }
18332: } else {
18333: $defaultshash{$action}{$prefix}{$type} = $value;
18334: $changes{$prefix}{$type} = 1;
18335: }
18336: } else {
18337: $defaultshash{$action}{$prefix}{$type} = $value;
18338: $changes{$prefix}{$type} = 1;
18339: }
18340: if (($type eq 'dom') && (keys(%servers) == 1)) {
18341: delete($changes{$prefix}{$type});
18342: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
18343: delete($changes{$prefix}{$type});
18344: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
18345: delete($changes{$prefix}{$type});
18346: }
18347: } elsif ($prefix eq 'replication') {
18348: if (@locations > 0) {
18349: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
18350: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
18351: my @okvals;
18352: foreach my $val (@vals) {
18353: if ($val =~ /:/) {
18354: my @items = split(/:/,$val);
18355: foreach my $item (@items) {
18356: if (ref($by_location{$item}) eq 'ARRAY') {
18357: push(@okvals,$item);
18358: }
18359: }
18360: } else {
18361: if (ref($by_location{$val}) eq 'ARRAY') {
18362: push(@okvals,$val);
18363: }
18364: }
18365: }
18366: @okvals = sort(@okvals);
18367: if (ref($domconfig{$action}) eq 'HASH') {
18368: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
18369: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
18370: if ($inuse == 0) {
18371: $changes{$prefix}{$type} = 1;
18372: } else {
18373: $defaultshash{$action}{$prefix}{$type} = \@okvals;
18374: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
18375: if (@changed > 0) {
18376: $changes{$prefix}{$type} = 1;
18377: }
18378: }
18379: } else {
18380: if ($inuse == 1) {
18381: $defaultshash{$action}{$prefix}{$type} = \@okvals;
18382: $changes{$prefix}{$type} = 1;
18383: }
18384: }
18385: } else {
18386: if ($inuse == 1) {
18387: $defaultshash{$action}{$prefix}{$type} = \@okvals;
18388: $changes{$prefix}{$type} = 1;
18389: }
18390: }
18391: } else {
18392: if ($inuse == 1) {
18393: $defaultshash{$action}{$prefix}{$type} = \@okvals;
18394: $changes{$prefix}{$type} = 1;
18395: }
18396: }
18397: }
18398: }
18399: }
18400: }
1.336 raeburn 18401: if (keys(%changes)) {
18402: foreach my $prefix (keys(%changes)) {
18403: if (ref($changes{$prefix}) eq 'HASH') {
18404: if (scalar(keys(%{$changes{$prefix}})) == 0) {
18405: delete($changes{$prefix});
18406: }
18407: } else {
18408: delete($changes{$prefix});
18409: }
18410: }
18411: }
1.275 raeburn 18412: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
18413: if (keys(%changes) > 0) {
18414: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
18415: $dom);
18416: if ($putresult eq 'ok') {
18417: if (ref($defaultshash{$action}) eq 'HASH') {
18418: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
18419: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
18420: }
1.293 raeburn 18421: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 18422: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 18423: }
18424: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 18425: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 18426: }
18427: }
18428: my $cachetime = 24*60*60;
18429: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18430: if (ref($lastactref) eq 'HASH') {
18431: $lastactref->{'domdefaults'} = 1;
18432: }
18433: if (keys(%changes) > 0) {
18434: my %titles = &ssl_titles();
18435: $resulttext = &mt('Changes made:').'<ul>';
18436: foreach my $prefix (@prefixes) {
18437: if (ref($changes{$prefix}) eq 'HASH') {
18438: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
18439: foreach my $type (@{$types{$prefix}}) {
18440: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 18441: my ($newvalue,$notinuse);
1.275 raeburn 18442: if (ref($defaultshash{$action}) eq 'HASH') {
18443: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 18444: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 18445: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 18446: } else {
18447: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
18448: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
18449: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
18450: }
18451: } else {
18452: $notinuse = 1;
1.275 raeburn 18453: }
18454: }
18455: }
1.344 raeburn 18456: if ($notinuse) {
18457: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
18458: } elsif ($newvalue eq '') {
1.275 raeburn 18459: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
18460: } else {
18461: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
18462: }
18463: }
18464: }
18465: }
18466: $resulttext .= '</ul>';
18467: }
18468: }
18469: } else {
18470: $resulttext = $nochgmsg;
18471: }
18472: } else {
18473: $resulttext = '<span class="LC_error">'.
18474: &mt('An error occurred: [_1]',$putresult).'</span>';
18475: }
18476: } else {
18477: $resulttext = $nochgmsg;
18478: }
18479: return $resulttext;
18480: }
18481:
1.279 raeburn 18482: sub modify_trust {
18483: my ($dom,$lastactref,%domconfig) = @_;
18484: my (%by_ip,%by_location,@intdoms,@instdoms);
18485: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
18486: my @locations = sort(keys(%by_location));
18487: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
18488: my @types = ('exc','inc');
18489: my (%defaultshash,%changes);
18490: foreach my $prefix (@prefixes) {
18491: $defaultshash{'trust'}{$prefix} = {};
18492: }
18493: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18494: my $resulttext;
18495: foreach my $prefix (@prefixes) {
18496: foreach my $type (@types) {
18497: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
18498: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
18499: my @okvals;
18500: foreach my $val (@vals) {
18501: if ($val =~ /:/) {
18502: my @items = split(/:/,$val);
18503: foreach my $item (@items) {
18504: if (ref($by_location{$item}) eq 'ARRAY') {
18505: push(@okvals,$item);
18506: }
18507: }
18508: } else {
18509: if (ref($by_location{$val}) eq 'ARRAY') {
18510: push(@okvals,$val);
18511: }
18512: }
18513: }
18514: @okvals = sort(@okvals);
18515: if (ref($domconfig{'trust'}) eq 'HASH') {
18516: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
18517: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
18518: if ($inuse == 0) {
18519: $changes{$prefix}{$type} = 1;
18520: } else {
18521: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
18522: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
18523: if (@changed > 0) {
18524: $changes{$prefix}{$type} = 1;
18525: }
18526: }
18527: } else {
18528: if ($inuse == 1) {
18529: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
18530: $changes{$prefix}{$type} = 1;
18531: }
18532: }
18533: } else {
18534: if ($inuse == 1) {
18535: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
18536: $changes{$prefix}{$type} = 1;
18537: }
18538: }
18539: } else {
18540: if ($inuse == 1) {
18541: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
18542: $changes{$prefix}{$type} = 1;
18543: }
18544: }
18545: }
18546: }
18547: my $nochgmsg = &mt('No changes made to trust settings.');
18548: if (keys(%changes) > 0) {
18549: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
18550: $dom);
18551: if ($putresult eq 'ok') {
18552: if (ref($defaultshash{'trust'}) eq 'HASH') {
18553: foreach my $prefix (@prefixes) {
18554: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
18555: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
18556: }
18557: }
18558: }
18559: my $cachetime = 24*60*60;
18560: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18561: if (ref($lastactref) eq 'HASH') {
18562: $lastactref->{'domdefaults'} = 1;
18563: }
18564: if (keys(%changes) > 0) {
18565: my %lt = &trust_titles();
18566: $resulttext = &mt('Changes made:').'<ul>';
18567: foreach my $prefix (@prefixes) {
18568: if (ref($changes{$prefix}) eq 'HASH') {
18569: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
18570: foreach my $type (@types) {
18571: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 18572: my ($newvalue,$notinuse);
1.279 raeburn 18573: if (ref($defaultshash{'trust'}) eq 'HASH') {
18574: if (ref($defaultshash{'trust'}{$prefix})) {
18575: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
18576: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
18577: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
18578: }
1.344 raeburn 18579: } else {
18580: $notinuse = 1;
1.279 raeburn 18581: }
18582: }
18583: }
1.344 raeburn 18584: if ($notinuse) {
18585: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
18586: } elsif ($newvalue eq '') {
1.279 raeburn 18587: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
18588: } else {
18589: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
18590: }
18591: }
18592: }
18593: $resulttext .= '</ul>';
18594: }
18595: }
18596: $resulttext .= '</ul>';
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.150 raeburn 18610: sub modify_loadbalancing {
18611: my ($dom,%domconfig) = @_;
18612: my $primary_id = &Apache::lonnet::domain($dom,'primary');
18613: my $intdom = &Apache::lonnet::internet_dom($primary_id);
18614: my ($othertitle,$usertypes,$types) =
18615: &Apache::loncommon::sorted_inst_types($dom);
18616: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 18617: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 18618: my @sparestypes = ('primary','default');
18619: my %typetitles = &sparestype_titles();
18620: my $resulttext;
1.342 raeburn 18621: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 18622: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
18623: %existing = %{$domconfig{'loadbalancing'}};
18624: }
18625: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 18626: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 18627: my ($saveloadbalancing,%defaultshash,%changes);
18628: my ($alltypes,$othertypes,$titles) =
18629: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
18630: my %ruletitles = &offloadtype_text();
18631: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
18632: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
18633: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
18634: if ($balancer eq '') {
18635: next;
18636: }
1.210 raeburn 18637: if (!exists($servers{$balancer})) {
1.171 raeburn 18638: if (exists($currbalancer{$balancer})) {
18639: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 18640: }
1.171 raeburn 18641: next;
18642: }
18643: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
18644: push(@{$changes{'delete'}},$balancer);
18645: next;
18646: }
18647: if (!exists($currbalancer{$balancer})) {
18648: push(@{$changes{'add'}},$balancer);
18649: }
18650: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
18651: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
18652: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
18653: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
18654: $saveloadbalancing = 1;
18655: }
18656: foreach my $sparetype (@sparestypes) {
18657: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
18658: my @offloadto;
18659: foreach my $target (@targets) {
18660: if (($servers{$target}) && ($target ne $balancer)) {
18661: if ($sparetype eq 'default') {
18662: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
18663: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 18664: }
18665: }
1.171 raeburn 18666: unless(grep(/^\Q$target\E$/,@offloadto)) {
18667: push(@offloadto,$target);
18668: }
1.150 raeburn 18669: }
18670: }
1.284 raeburn 18671: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
18672: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
18673: push(@offloadto,$balancer);
18674: }
18675: }
18676: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 18677: }
1.342 raeburn 18678: if ($env{'form.loadbalancing_cookie_'.$i}) {
18679: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
18680: if (exists($currbalancer{$balancer})) {
18681: unless ($currcookies{$balancer}) {
18682: $changes{'curr'}{$balancer}{'cookie'} = 1;
18683: }
18684: }
18685: } elsif (exists($currbalancer{$balancer})) {
18686: if ($currcookies{$balancer}) {
18687: $changes{'curr'}{$balancer}{'cookie'} = 1;
18688: }
18689: }
1.171 raeburn 18690: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 18691: foreach my $sparetype (@sparestypes) {
1.171 raeburn 18692: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
18693: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 18694: if (@targetdiffs > 0) {
1.171 raeburn 18695: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 18696: }
1.171 raeburn 18697: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18698: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
18699: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 18700: }
18701: }
18702: }
18703: } else {
1.171 raeburn 18704: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 18705: foreach my $sparetype (@sparestypes) {
1.171 raeburn 18706: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18707: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
18708: $changes{'curr'}{$balancer}{'targets'} = 1;
18709: }
1.150 raeburn 18710: }
18711: }
1.210 raeburn 18712: }
1.150 raeburn 18713: }
18714: my $ishomedom;
1.171 raeburn 18715: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
18716: $ishomedom = 1;
1.150 raeburn 18717: }
18718: if (ref($alltypes) eq 'ARRAY') {
18719: foreach my $type (@{$alltypes}) {
18720: my $rule;
1.210 raeburn 18721: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 18722: (!$ishomedom)) {
1.171 raeburn 18723: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
18724: }
18725: if ($rule eq 'specific') {
1.255 raeburn 18726: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 18727: if (exists($servers{$specifiedhost})) {
1.255 raeburn 18728: $rule = $specifiedhost;
18729: }
1.150 raeburn 18730: }
1.171 raeburn 18731: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
18732: if (ref($currrules{$balancer}) eq 'HASH') {
18733: if ($rule ne $currrules{$balancer}{$type}) {
18734: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 18735: }
18736: } elsif ($rule ne '') {
1.171 raeburn 18737: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 18738: }
18739: }
18740: }
1.171 raeburn 18741: }
18742: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
18743: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
18744: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
18745: $defaultshash{'loadbalancing'} = {};
18746: }
18747: my $putresult = &Apache::lonnet::put_dom('configuration',
18748: \%defaultshash,$dom);
18749: if ($putresult eq 'ok') {
18750: if (keys(%changes) > 0) {
1.252 raeburn 18751: my %toupdate;
1.171 raeburn 18752: if (ref($changes{'delete'}) eq 'ARRAY') {
18753: foreach my $balancer (sort(@{$changes{'delete'}})) {
18754: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 18755: $toupdate{$balancer} = 1;
1.150 raeburn 18756: }
1.171 raeburn 18757: }
18758: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 18759: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 18760: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 18761: $toupdate{$balancer} = 1;
1.171 raeburn 18762: }
18763: }
18764: if (ref($changes{'curr'}) eq 'HASH') {
18765: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 18766: $toupdate{$balancer} = 1;
1.171 raeburn 18767: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
18768: if ($changes{'curr'}{$balancer}{'targets'}) {
18769: my %offloadstr;
18770: foreach my $sparetype (@sparestypes) {
18771: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18772: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
18773: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
18774: }
18775: }
1.150 raeburn 18776: }
1.171 raeburn 18777: if (keys(%offloadstr) == 0) {
18778: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 18779: } else {
1.171 raeburn 18780: my $showoffload;
18781: foreach my $sparetype (@sparestypes) {
18782: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
18783: if (defined($offloadstr{$sparetype})) {
18784: $showoffload .= $offloadstr{$sparetype};
18785: } else {
18786: $showoffload .= &mt('None');
18787: }
18788: $showoffload .= (' 'x3);
18789: }
18790: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 18791: }
18792: }
18793: }
1.171 raeburn 18794: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
18795: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
18796: foreach my $type (@{$alltypes}) {
18797: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
18798: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
18799: my $balancetext;
18800: if ($rule eq '') {
18801: $balancetext = $ruletitles{'default'};
1.209 raeburn 18802: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 18803: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 18804: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 18805: foreach my $sparetype (@sparestypes) {
18806: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18807: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
18808: }
18809: }
1.253 raeburn 18810: foreach my $item (@{$alltypes}) {
18811: next if ($item =~ /^_LC_ipchange/);
18812: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
18813: if ($hasrule eq 'homeserver') {
18814: map { $toupdate{$_} = 1; } (keys(%libraryservers));
18815: } else {
18816: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
18817: if ($servers{$hasrule}) {
18818: $toupdate{$hasrule} = 1;
18819: }
18820: }
18821: }
18822: }
1.254 raeburn 18823: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
18824: $balancetext = $ruletitles{$rule};
18825: } else {
18826: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
18827: $balancetext = $ruletitles{'particular'}.' '.$receiver;
18828: if ($receiver) {
18829: $toupdate{$receiver};
18830: }
18831: }
18832: } else {
18833: $balancetext = $ruletitles{$rule};
1.252 raeburn 18834: }
1.171 raeburn 18835: } else {
18836: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
18837: }
1.210 raeburn 18838: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 18839: }
18840: }
18841: }
18842: }
1.342 raeburn 18843: if ($changes{'curr'}{$balancer}{'cookie'}) {
18844: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
18845: $balancer).'</li>';
18846: }
1.252 raeburn 18847: if (keys(%toupdate)) {
18848: my %thismachine;
18849: my $updatedhere;
18850: my $cachetime = 60*60*24;
18851: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
18852: foreach my $lonhost (keys(%toupdate)) {
18853: if ($thismachine{$lonhost}) {
18854: unless ($updatedhere) {
18855: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
18856: $defaultshash{'loadbalancing'},
18857: $cachetime);
18858: $updatedhere = 1;
18859: }
18860: } else {
18861: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
18862: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
18863: }
18864: }
18865: }
1.150 raeburn 18866: }
1.171 raeburn 18867: }
18868: if ($resulttext ne '') {
18869: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 18870: } else {
18871: $resulttext = $nochgmsg;
18872: }
18873: } else {
1.171 raeburn 18874: $resulttext = $nochgmsg;
1.150 raeburn 18875: }
18876: } else {
1.171 raeburn 18877: $resulttext = '<span class="LC_error">'.
18878: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 18879: }
18880: } else {
1.171 raeburn 18881: $resulttext = $nochgmsg;
1.150 raeburn 18882: }
18883: return $resulttext;
18884: }
18885:
1.48 raeburn 18886: sub recurse_check {
18887: my ($chkcats,$categories,$depth,$name) = @_;
18888: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
18889: my $chg = 0;
18890: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
18891: my $category = $chkcats->[$depth]{$name}[$j];
18892: my $item;
18893: if ($category eq '') {
18894: $chg ++;
18895: } else {
18896: my $deeper = $depth + 1;
18897: $item = &escape($category).':'.&escape($name).':'.$depth;
18898: if ($chg) {
18899: $categories->{$item} -= $chg;
18900: }
18901: &recurse_check($chkcats,$categories,$deeper,$category);
18902: $deeper --;
18903: }
18904: }
18905: }
18906: return;
18907: }
18908:
18909: sub recurse_cat_deletes {
18910: my ($item,$coursecategories,$deletions) = @_;
18911: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
18912: my $subdepth = $depth + 1;
18913: if (ref($coursecategories) eq 'HASH') {
18914: foreach my $subitem (keys(%{$coursecategories})) {
18915: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
18916: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
18917: delete($coursecategories->{$subitem});
18918: $deletions->{$subitem} = 1;
18919: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 18920: }
1.48 raeburn 18921: }
18922: }
18923: return;
18924: }
18925:
1.125 raeburn 18926: sub active_dc_picker {
1.191 raeburn 18927: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 18928: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 18929: my @domcoord = keys(%domcoords);
18930: if (keys(%currhash)) {
18931: foreach my $dc (keys(%currhash)) {
18932: unless (exists($domcoords{$dc})) {
18933: push(@domcoord,$dc);
18934: }
18935: }
18936: }
18937: @domcoord = sort(@domcoord);
1.210 raeburn 18938: my $numdcs = scalar(@domcoord);
1.191 raeburn 18939: my $rows = 0;
18940: my $table;
1.125 raeburn 18941: if ($numdcs > 1) {
1.191 raeburn 18942: $table = '<table>';
18943: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 18944: my $rem = $i%($numinrow);
18945: if ($rem == 0) {
18946: if ($i > 0) {
1.191 raeburn 18947: $table .= '</tr>';
1.125 raeburn 18948: }
1.191 raeburn 18949: $table .= '<tr>';
18950: $rows ++;
1.125 raeburn 18951: }
1.191 raeburn 18952: my $check = '';
18953: if ($inputtype eq 'radio') {
18954: if (keys(%currhash) == 0) {
18955: if (!$i) {
18956: $check = ' checked="checked"';
18957: }
18958: } elsif (exists($currhash{$domcoord[$i]})) {
18959: $check = ' checked="checked"';
18960: }
18961: } else {
18962: if (exists($currhash{$domcoord[$i]})) {
18963: $check = ' checked="checked"';
1.125 raeburn 18964: }
18965: }
1.191 raeburn 18966: if ($i == @domcoord - 1) {
1.125 raeburn 18967: my $colsleft = $numinrow - $rem;
18968: if ($colsleft > 1) {
1.191 raeburn 18969: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 18970: } else {
1.191 raeburn 18971: $table .= '<td class="LC_left_item">';
1.125 raeburn 18972: }
18973: } else {
1.191 raeburn 18974: $table .= '<td class="LC_left_item">';
18975: }
18976: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
18977: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
18978: $table .= '<span class="LC_nobreak"><label>'.
18979: '<input type="'.$inputtype.'" name="'.$name.'"'.
18980: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
18981: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 18982: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 18983: }
1.219 raeburn 18984: $table .= '</label></span></td>';
1.191 raeburn 18985: }
18986: $table .= '</tr></table>';
18987: } elsif ($numdcs == 1) {
1.219 raeburn 18988: my ($dcname,$dcdom) = split(':',$domcoord[0]);
18989: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 18990: if ($inputtype eq 'radio') {
1.247 raeburn 18991: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 18992: if ($user ne $dcname.':'.$dcdom) {
18993: $table .= ' ('.$dcname.':'.$dcdom.')';
18994: }
1.191 raeburn 18995: } else {
18996: my $check;
18997: if (exists($currhash{$domcoord[0]})) {
18998: $check = ' checked="checked"';
1.125 raeburn 18999: }
1.247 raeburn 19000: $table = '<span class="LC_nobreak"><label>'.
19001: '<input type="checkbox" name="'.$name.'" '.
19002: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 19003: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 19004: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 19005: }
1.220 raeburn 19006: $table .= '</label></span>';
1.191 raeburn 19007: $rows ++;
1.125 raeburn 19008: }
19009: }
1.191 raeburn 19010: return ($numdcs,$table,$rows);
1.125 raeburn 19011: }
19012:
1.137 raeburn 19013: sub usersession_titles {
19014: return &Apache::lonlocal::texthash(
19015: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
19016: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 19017: spares => 'Servers offloaded to, when busy',
1.137 raeburn 19018: version => 'LON-CAPA version requirement',
1.138 raeburn 19019: excludedomain => 'Allow all, but exclude specific domains',
19020: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 19021: primary => 'Primary (checked first)',
1.154 raeburn 19022: default => 'Default',
1.137 raeburn 19023: );
19024: }
19025:
1.152 raeburn 19026: sub id_for_thisdom {
19027: my (%servers) = @_;
19028: my %altids;
19029: foreach my $server (keys(%servers)) {
19030: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
19031: if ($serverhome ne $server) {
19032: $altids{$serverhome} = $server;
19033: }
19034: }
19035: return %altids;
19036: }
19037:
1.150 raeburn 19038: sub count_servers {
19039: my ($currbalancer,%servers) = @_;
19040: my (@spares,$numspares);
19041: foreach my $lonhost (sort(keys(%servers))) {
19042: next if ($currbalancer eq $lonhost);
19043: push(@spares,$lonhost);
19044: }
19045: if ($currbalancer) {
19046: $numspares = scalar(@spares);
19047: } else {
19048: $numspares = scalar(@spares) - 1;
19049: }
19050: return ($numspares,@spares);
19051: }
19052:
19053: sub lonbalance_targets_js {
1.171 raeburn 19054: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 19055: my $select = &mt('Select');
19056: my ($alltargets,$allishome,$allinsttypes,@alltypes);
19057: if (ref($servers) eq 'HASH') {
19058: $alltargets = join("','",sort(keys(%{$servers})));
19059: my @homedoms;
19060: foreach my $server (sort(keys(%{$servers}))) {
19061: if (&Apache::lonnet::host_domain($server) eq $dom) {
19062: push(@homedoms,'1');
19063: } else {
19064: push(@homedoms,'0');
19065: }
19066: }
19067: $allishome = join("','",@homedoms);
19068: }
19069: if (ref($types) eq 'ARRAY') {
19070: if (@{$types} > 0) {
19071: @alltypes = @{$types};
19072: }
19073: }
19074: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
19075: $allinsttypes = join("','",@alltypes);
1.342 raeburn 19076: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 19077: if (ref($settings) eq 'HASH') {
19078: %existing = %{$settings};
19079: }
19080: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 19081: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 19082: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 19083: return <<"END";
19084:
19085: <script type="text/javascript">
19086: // <![CDATA[
19087:
1.171 raeburn 19088: currBalancers = new Array('$balancers');
19089:
19090: function toggleTargets(balnum) {
19091: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
19092: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
19093: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
19094: var prevbalancer = prevhostitem.value;
19095: var baltotal = document.getElementById('loadbalancing_total').value;
19096: prevhostitem.value = balancer;
19097: if (prevbalancer != '') {
19098: var prevIdx = currBalancers.indexOf(prevbalancer);
19099: if (prevIdx != -1) {
19100: currBalancers.splice(prevIdx,1);
19101: }
19102: }
1.150 raeburn 19103: if (balancer == '') {
1.171 raeburn 19104: hideSpares(balnum);
1.150 raeburn 19105: } else {
1.171 raeburn 19106: var currIdx = currBalancers.indexOf(balancer);
19107: if (currIdx == -1) {
19108: currBalancers.push(balancer);
19109: }
1.150 raeburn 19110: var homedoms = new Array('$allishome');
1.171 raeburn 19111: var ishomedom = homedoms[lonhostitem.selectedIndex];
19112: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 19113: }
1.171 raeburn 19114: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 19115: return;
19116: }
19117:
1.171 raeburn 19118: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 19119: var alltargets = new Array('$alltargets');
19120: var insttypes = new Array('$allinsttypes');
1.151 raeburn 19121: var offloadtypes = new Array('primary','default');
19122:
1.171 raeburn 19123: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
19124: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 19125:
1.151 raeburn 19126: for (var i=0; i<offloadtypes.length; i++) {
19127: var count = 0;
19128: for (var j=0; j<alltargets.length; j++) {
19129: if (alltargets[j] != balancer) {
1.171 raeburn 19130: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
19131: item.value = alltargets[j];
19132: item.style.textAlign='left';
19133: item.style.textFace='normal';
19134: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
19135: if (currBalancers.indexOf(alltargets[j]) == -1) {
19136: item.disabled = '';
19137: } else {
19138: item.disabled = 'disabled';
19139: item.checked = false;
19140: }
1.151 raeburn 19141: count ++;
19142: }
1.150 raeburn 19143: }
19144: }
1.151 raeburn 19145: for (var k=0; k<insttypes.length; k++) {
19146: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 19147: if (ishomedom == 1) {
1.171 raeburn 19148: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
19149: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 19150: } else {
1.171 raeburn 19151: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
19152: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 19153: }
19154: } else {
1.171 raeburn 19155: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
19156: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 19157: }
1.151 raeburn 19158: if ((insttypes[k] != '_LC_external') &&
19159: ((insttypes[k] != '_LC_internetdom') ||
19160: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 19161: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
19162: item.options.length = 0;
19163: item.options[0] = new Option("","",true,true);
1.210 raeburn 19164: var idx = 0;
1.151 raeburn 19165: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 19166: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
19167: idx ++;
19168: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 19169: }
19170: }
19171: }
19172: }
19173: return;
19174: }
19175:
1.171 raeburn 19176: function hideSpares(balnum) {
1.150 raeburn 19177: var alltargets = new Array('$alltargets');
19178: var insttypes = new Array('$allinsttypes');
19179: var offloadtypes = new Array('primary','default');
19180:
1.171 raeburn 19181: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
19182: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 19183:
19184: var total = alltargets.length - 1;
19185: for (var i=0; i<offloadtypes; i++) {
19186: for (var j=0; j<total; j++) {
1.171 raeburn 19187: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
19188: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
19189: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 19190: }
1.150 raeburn 19191: }
19192: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 19193: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
19194: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 19195: if (insttypes[k] != '_LC_external') {
1.171 raeburn 19196: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
19197: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 19198: }
19199: }
19200: return;
19201: }
19202:
1.171 raeburn 19203: function checkOffloads(item,balnum,type) {
1.150 raeburn 19204: var alltargets = new Array('$alltargets');
19205: var offloadtypes = new Array('primary','default');
19206: if (item.checked) {
19207: var total = alltargets.length - 1;
19208: var other;
19209: if (type == offloadtypes[0]) {
1.151 raeburn 19210: other = offloadtypes[1];
1.150 raeburn 19211: } else {
1.151 raeburn 19212: other = offloadtypes[0];
1.150 raeburn 19213: }
19214: for (var i=0; i<total; i++) {
1.171 raeburn 19215: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 19216: if (server == item.value) {
1.171 raeburn 19217: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
19218: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 19219: }
19220: }
19221: }
19222: }
19223: return;
19224: }
19225:
1.171 raeburn 19226: function singleServerToggle(balnum,type) {
19227: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 19228: if (offloadtoSelIdx == 0) {
1.171 raeburn 19229: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
19230: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 19231:
19232: } else {
1.171 raeburn 19233: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
19234: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 19235: }
19236: return;
19237: }
19238:
1.171 raeburn 19239: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 19240: if (type == '_LC_external') {
1.171 raeburn 19241: return;
1.150 raeburn 19242: }
1.171 raeburn 19243: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 19244: for (var i=0; i<typesRules.length; i++) {
19245: if (formname.elements[typesRules[i]].checked) {
19246: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 19247: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
19248: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 19249: } else {
1.171 raeburn 19250: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
19251: }
19252: }
19253: }
19254: return;
19255: }
19256:
19257: function balancerDeleteChange(balnum) {
19258: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
19259: var baltotal = document.getElementById('loadbalancing_total').value;
19260: var addtarget;
19261: var removetarget;
19262: var action = 'delete';
19263: if (document.getElementById('loadbalancing_delete_'+balnum)) {
19264: var lonhost = hostitem.value;
19265: var currIdx = currBalancers.indexOf(lonhost);
19266: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
19267: if (currIdx != -1) {
19268: currBalancers.splice(currIdx,1);
19269: }
19270: addtarget = lonhost;
19271: } else {
19272: if (currIdx == -1) {
19273: currBalancers.push(lonhost);
19274: }
19275: removetarget = lonhost;
19276: action = 'undelete';
19277: }
19278: balancerChange(balnum,baltotal,action,addtarget,removetarget);
19279: }
19280: return;
19281: }
19282:
19283: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
19284: if (baltotal > 1) {
19285: var offloadtypes = new Array('primary','default');
19286: var alltargets = new Array('$alltargets');
19287: var insttypes = new Array('$allinsttypes');
19288: for (var i=0; i<baltotal; i++) {
19289: if (i != balnum) {
19290: for (var j=0; j<offloadtypes.length; j++) {
19291: var total = alltargets.length - 1;
19292: for (var k=0; k<total; k++) {
19293: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
19294: var server = serveritem.value;
19295: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
19296: if (server == addtarget) {
19297: serveritem.disabled = '';
19298: }
19299: }
19300: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
19301: if (server == removetarget) {
19302: serveritem.disabled = 'disabled';
19303: serveritem.checked = false;
19304: }
19305: }
19306: }
19307: }
19308: for (var j=0; j<insttypes.length; j++) {
19309: if (insttypes[j] != '_LC_external') {
19310: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
19311: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
19312: var currSel = singleserver.selectedIndex;
19313: var currVal = singleserver.options[currSel].value;
19314: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
19315: var numoptions = singleserver.options.length;
19316: var needsnew = 1;
19317: for (var k=0; k<numoptions; k++) {
19318: if (singleserver.options[k] == addtarget) {
19319: needsnew = 0;
19320: break;
19321: }
19322: }
19323: if (needsnew == 1) {
19324: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
19325: }
19326: }
19327: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
19328: singleserver.options.length = 0;
19329: if ((currVal) && (currVal != removetarget)) {
19330: singleserver.options[0] = new Option("","",false,false);
19331: } else {
19332: singleserver.options[0] = new Option("","",true,true);
19333: }
19334: var idx = 0;
19335: for (var m=0; m<alltargets.length; m++) {
19336: if (currBalancers.indexOf(alltargets[m]) == -1) {
19337: idx ++;
19338: if (currVal == alltargets[m]) {
19339: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
19340: } else {
19341: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
19342: }
19343: }
19344: }
19345: }
19346: }
19347: }
19348: }
1.150 raeburn 19349: }
19350: }
19351: }
19352: return;
19353: }
19354:
1.152 raeburn 19355: // ]]>
19356: </script>
19357:
19358: END
19359: }
19360:
19361: sub new_spares_js {
19362: my @sparestypes = ('primary','default');
19363: my $types = join("','",@sparestypes);
19364: my $select = &mt('Select');
19365: return <<"END";
19366:
19367: <script type="text/javascript">
19368: // <![CDATA[
19369:
19370: function updateNewSpares(formname,lonhost) {
19371: var types = new Array('$types');
19372: var include = new Array();
19373: var exclude = new Array();
19374: for (var i=0; i<types.length; i++) {
19375: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
19376: for (var j=0; j<spareboxes.length; j++) {
19377: if (formname.elements[spareboxes[j]].checked) {
19378: exclude.push(formname.elements[spareboxes[j]].value);
19379: } else {
19380: include.push(formname.elements[spareboxes[j]].value);
19381: }
19382: }
19383: }
19384: for (var i=0; i<types.length; i++) {
19385: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
19386: var selIdx = newSpare.selectedIndex;
19387: var currnew = newSpare.options[selIdx].value;
19388: var okSpares = new Array();
19389: for (var j=0; j<newSpare.options.length; j++) {
19390: var possible = newSpare.options[j].value;
19391: if (possible != '') {
19392: if (exclude.indexOf(possible) == -1) {
19393: okSpares.push(possible);
19394: } else {
19395: if (currnew == possible) {
19396: selIdx = 0;
19397: }
19398: }
19399: }
19400: }
19401: for (var k=0; k<include.length; k++) {
19402: if (okSpares.indexOf(include[k]) == -1) {
19403: okSpares.push(include[k]);
19404: }
19405: }
19406: okSpares.sort();
19407: newSpare.options.length = 0;
19408: if (selIdx == 0) {
19409: newSpare.options[0] = new Option("$select","",true,true);
19410: } else {
19411: newSpare.options[0] = new Option("$select","",false,false);
19412: }
19413: for (var m=0; m<okSpares.length; m++) {
19414: var idx = m+1;
19415: var selThis = 0;
19416: if (selIdx != 0) {
19417: if (okSpares[m] == currnew) {
19418: selThis = 1;
19419: }
19420: }
19421: if (selThis == 1) {
19422: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
19423: } else {
19424: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
19425: }
19426: }
19427: }
19428: return;
19429: }
19430:
19431: function checkNewSpares(lonhost,type) {
19432: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
19433: var chosen = newSpare.options[newSpare.selectedIndex].value;
19434: if (chosen != '') {
19435: var othertype;
19436: var othernewSpare;
19437: if (type == 'primary') {
19438: othernewSpare = document.getElementById('newspare_default_'+lonhost);
19439: }
19440: if (type == 'default') {
19441: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
19442: }
19443: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
19444: othernewSpare.selectedIndex = 0;
19445: }
19446: }
19447: return;
19448: }
19449:
19450: // ]]>
19451: </script>
19452:
19453: END
19454:
19455: }
19456:
19457: sub common_domprefs_js {
19458: return <<"END";
19459:
19460: <script type="text/javascript">
19461: // <![CDATA[
19462:
1.150 raeburn 19463: function getIndicesByName(formname,item) {
1.152 raeburn 19464: var group = new Array();
1.150 raeburn 19465: for (var i=0;i<formname.elements.length;i++) {
19466: if (formname.elements[i].name == item) {
1.152 raeburn 19467: group.push(formname.elements[i].id);
1.150 raeburn 19468: }
19469: }
1.152 raeburn 19470: return group;
1.150 raeburn 19471: }
19472:
19473: // ]]>
19474: </script>
19475:
19476: END
1.152 raeburn 19477:
1.150 raeburn 19478: }
19479:
1.165 raeburn 19480: sub recaptcha_js {
19481: my %lt = &captcha_phrases();
19482: return <<"END";
19483:
19484: <script type="text/javascript">
19485: // <![CDATA[
19486:
19487: function updateCaptcha(caller,context) {
19488: var privitem;
19489: var pubitem;
19490: var privtext;
19491: var pubtext;
1.269 raeburn 19492: var versionitem;
19493: var versiontext;
1.165 raeburn 19494: if (document.getElementById(context+'_recaptchapub')) {
19495: pubitem = document.getElementById(context+'_recaptchapub');
19496: } else {
19497: return;
19498: }
19499: if (document.getElementById(context+'_recaptchapriv')) {
19500: privitem = document.getElementById(context+'_recaptchapriv');
19501: } else {
19502: return;
19503: }
19504: if (document.getElementById(context+'_recaptchapubtxt')) {
19505: pubtext = document.getElementById(context+'_recaptchapubtxt');
19506: } else {
19507: return;
19508: }
19509: if (document.getElementById(context+'_recaptchaprivtxt')) {
19510: privtext = document.getElementById(context+'_recaptchaprivtxt');
19511: } else {
19512: return;
19513: }
1.269 raeburn 19514: if (document.getElementById(context+'_recaptchaversion')) {
19515: versionitem = document.getElementById(context+'_recaptchaversion');
19516: } else {
19517: return;
19518: }
19519: if (document.getElementById(context+'_recaptchavertxt')) {
19520: versiontext = document.getElementById(context+'_recaptchavertxt');
19521: } else {
19522: return;
19523: }
1.165 raeburn 19524: if (caller.checked) {
19525: if (caller.value == 'recaptcha') {
19526: pubitem.type = 'text';
19527: privitem.type = 'text';
19528: pubitem.size = '40';
19529: privitem.size = '40';
19530: pubtext.innerHTML = "$lt{'pub'}";
19531: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 19532: versionitem.type = 'text';
19533: versionitem.size = '3';
1.289 raeburn 19534: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 19535: } else {
19536: pubitem.type = 'hidden';
19537: privitem.type = 'hidden';
1.269 raeburn 19538: versionitem.type = 'hidden';
1.165 raeburn 19539: pubtext.innerHTML = '';
19540: privtext.innerHTML = '';
1.269 raeburn 19541: versiontext.innerHTML = '';
1.165 raeburn 19542: }
19543: }
19544: return;
19545: }
19546:
19547: // ]]>
19548: </script>
19549:
19550: END
19551:
19552: }
19553:
1.236 raeburn 19554: sub toggle_display_js {
1.192 raeburn 19555: return <<"END";
19556:
19557: <script type="text/javascript">
19558: // <![CDATA[
19559:
1.236 raeburn 19560: function toggleDisplay(domForm,caller) {
19561: if (document.getElementById(caller)) {
19562: var divitem = document.getElementById(caller);
19563: var optionsElement = domForm.coursecredits;
1.264 raeburn 19564: var checkval = 1;
19565: var dispval = 'block';
1.303 raeburn 19566: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 19567: if (caller == 'emailoptions') {
19568: optionsElement = domForm.cancreate_email;
19569: }
1.257 raeburn 19570: if (caller == 'studentsubmission') {
19571: optionsElement = domForm.postsubmit;
19572: }
1.264 raeburn 19573: if (caller == 'cloneinstcode') {
19574: optionsElement = domForm.canclone;
19575: checkval = 'instcode';
19576: }
1.303 raeburn 19577: if (selfcreateRegExp.test(caller)) {
19578: optionsElement = domForm.elements[caller];
19579: checkval = 'other';
19580: dispval = 'inline'
19581: }
1.236 raeburn 19582: if (optionsElement.length) {
1.192 raeburn 19583: var currval;
1.236 raeburn 19584: for (var i=0; i<optionsElement.length; i++) {
19585: if (optionsElement[i].checked) {
19586: currval = optionsElement[i].value;
1.192 raeburn 19587: }
19588: }
1.264 raeburn 19589: if (currval == checkval) {
19590: divitem.style.display = dispval;
1.192 raeburn 19591: } else {
1.236 raeburn 19592: divitem.style.display = 'none';
1.192 raeburn 19593: }
19594: }
19595: }
19596: return;
19597: }
19598:
19599: // ]]>
19600: </script>
19601:
19602: END
19603:
19604: }
19605:
1.165 raeburn 19606: sub captcha_phrases {
19607: return &Apache::lonlocal::texthash (
19608: priv => 'Private key',
19609: pub => 'Public key',
19610: original => 'original (CAPTCHA)',
19611: recaptcha => 'successor (ReCAPTCHA)',
19612: notused => 'unused',
1.289 raeburn 19613: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 19614: );
19615: }
19616:
1.205 raeburn 19617: sub devalidate_remote_domconfs {
1.212 raeburn 19618: my ($dom,$cachekeys) = @_;
19619: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 19620: my %servers = &Apache::lonnet::internet_dom_servers($dom);
19621: my %thismachine;
19622: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 19623: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
19624: 'directorysrch','passwdconf');
1.260 raeburn 19625: if (keys(%servers)) {
1.205 raeburn 19626: foreach my $server (keys(%servers)) {
19627: next if ($thismachine{$server});
1.212 raeburn 19628: my @cached;
19629: foreach my $name (@posscached) {
19630: if ($cachekeys->{$name}) {
19631: push(@cached,&escape($name).':'.&escape($dom));
19632: }
19633: }
19634: if (@cached) {
19635: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
19636: }
1.205 raeburn 19637: }
19638: }
19639: return;
19640: }
19641:
1.3 raeburn 19642: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>