Annotation of loncom/interface/domainprefs.pm, revision 1.356
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.356 ! raeburn 4: # $Id: domainprefs.pm,v 1.355 2019/04/26 20:15:30 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
1.286 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
1.297 raeburn 30: ###############################################################
1.1 raeburn 31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.210 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.197 raeburn 98: used by course owners to request creation of a course, and to display/store
1.223 bisitz 99: default quota sizes for Authoring Spaces.
1.101 raeburn 100:
101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
1.325 raeburn 107: (official, unofficial, community, textbook, placement, and lti).
1.271 raeburn 108: In each case the radio buttons allow the selection of one of four values:
1.101 raeburn 109:
1.104 raeburn 110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
1.104 raeburn 121: approval
1.101 raeburn 122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
1.143 raeburn 145: - course requests will be processed automatically up to a limit of
1.101 raeburn 146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
1.1 raeburn 158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
1.43 raeburn 166: use Apache::lonmsg();
1.91 raeburn 167: use Apache::lonconfigsettings;
1.232 raeburn 168: use Apache::lonuserutils();
1.235 raeburn 169: use Apache::loncoursequeueadmin();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.275 raeburn 173: use LONCAPA::SSL;
1.9 raeburn 174: use File::Copy;
1.43 raeburn 175: use Locale::Language;
1.62 raeburn 176: use DateTime::TimeZone;
1.68 raeburn 177: use DateTime::Locale;
1.267 raeburn 178: use Time::HiRes qw( sleep );
1.1 raeburn 179:
1.155 raeburn 180: my $registered_cleanup;
181: my $modified_urls;
182:
1.1 raeburn 183: sub handler {
184: my $r=shift;
185: if ($r->header_only) {
186: &Apache::loncommon::content_type($r,'text/html');
187: $r->send_http_header;
188: return OK;
189: }
190:
1.91 raeburn 191: my $context = 'domain';
1.1 raeburn 192: my $dom = $env{'request.role.domain'};
1.5 albertel 193: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 194: if (&Apache::lonnet::allowed('mau',$dom)) {
195: &Apache::loncommon::content_type($r,'text/html');
196: $r->send_http_header;
197: } else {
198: $env{'user.error.msg'}=
199: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
200: return HTTP_NOT_ACCEPTABLE;
201: }
1.155 raeburn 202:
203: $registered_cleanup=0;
204: @{$modified_urls}=();
205:
1.1 raeburn 206: &Apache::lonhtmlcommon::clear_breadcrumbs();
207: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 208: ['phase','actions']);
1.30 raeburn 209: my $phase = 'pickactions';
1.3 raeburn 210: if ( exists($env{'form.phase'}) ) {
211: $phase = $env{'form.phase'};
212: }
1.150 raeburn 213: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 214: my %domconfig =
1.6 raeburn 215: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 216: 'quotas','autoenroll','autoupdate','autocreate',
217: 'directorysrch','usercreation','usermodification',
218: 'contacts','defaults','scantron','coursecategories',
219: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 220: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 221: 'requestauthor','selfenrollment','inststatus',
1.354 raeburn 222: 'ltitools','ssl','trust','lti','passwords'],$dom);
1.320 raeburn 223: my %encconfig =
224: &Apache::lonnet::get_dom('encconfig',['ltitools','lti'],$dom);
1.297 raeburn 225: if (ref($domconfig{'ltitools'}) eq 'HASH') {
226: if (ref($encconfig{'ltitools'}) eq 'HASH') {
227: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
1.320 raeburn 228: if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
229: (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
1.297 raeburn 230: foreach my $item ('key','secret') {
231: $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
232: }
233: }
234: }
235: }
236: }
1.320 raeburn 237: if (ref($domconfig{'lti'}) eq 'HASH') {
238: if (ref($encconfig{'lti'}) eq 'HASH') {
239: foreach my $id (keys(%{$domconfig{'lti'}})) {
240: if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
241: (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
242: foreach my $item ('key','secret') {
243: $domconfig{'lti'}{$id}{$item} = $encconfig{'lti'}{$id}{$item};
244: }
245: }
246: }
247: }
248: }
1.354 raeburn 249: my @prefs_order = ('rolecolors','login','defaults','passwords','quotas','autoenroll',
1.125 raeburn 250: 'autoupdate','autocreate','directorysrch','contacts',
1.224 raeburn 251: 'usercreation','selfcreation','usermodification','scantron',
1.163 raeburn 252: 'requestcourses','requestauthor','coursecategories',
1.267 raeburn 253: 'serverstatuses','helpsettings','coursedefaults',
1.320 raeburn 254: 'ltitools','selfenrollment','usersessions','ssl','trust','lti');
1.171 raeburn 255: my %existing;
256: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
257: %existing = %{$domconfig{'loadbalancing'}};
258: }
259: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 260: push(@prefs_order,'loadbalancing');
261: }
1.30 raeburn 262: my %prefs = (
263: 'rolecolors' =>
264: { text => 'Default color schemes',
1.67 raeburn 265: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 266: header => [{col1 => 'Student Settings',
267: col2 => '',},
268: {col1 => 'Coordinator Settings',
269: col2 => '',},
270: {col1 => 'Author Settings',
271: col2 => '',},
272: {col1 => 'Administrator Settings',
273: col2 => '',}],
1.230 raeburn 274: print => \&print_rolecolors,
275: modify => \&modify_rolecolors,
1.30 raeburn 276: },
1.110 raeburn 277: 'login' =>
1.30 raeburn 278: { text => 'Log-in page options',
1.67 raeburn 279: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 280: header => [{col1 => 'Log-in Page Items',
281: col2 => '',},
282: {col1 => 'Log-in Help',
1.256 raeburn 283: col2 => 'Value'},
284: {col1 => 'Custom HTML in document head',
1.168 raeburn 285: col2 => 'Value'}],
1.230 raeburn 286: print => \&print_login,
287: modify => \&modify_login,
1.30 raeburn 288: },
1.43 raeburn 289: 'defaults' =>
1.236 raeburn 290: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 291: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 292: header => [{col1 => 'Setting',
1.236 raeburn 293: col2 => 'Value'},
294: {col1 => 'Institutional user types',
1.305 raeburn 295: col2 => 'Name displayed'}],
1.230 raeburn 296: print => \&print_defaults,
297: modify => \&modify_defaults,
1.43 raeburn 298: },
1.354 raeburn 299: 'passwords' =>
300: { text => 'Passwords (Internal authentication)',
301: help => 'Domain_Configuration_Passwords',
302: header => [{col1 => 'Resetting Forgotten Password',
303: col2 => 'Settings'},
304: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
305: col2 => 'Settings'},
306: {col1 => 'Rules for LON-CAPA Passwords',
307: col2 => 'Settings'},
308: {col1 => 'Course Owner Changing Student Passwords',
309: col2 => 'Settings'}],
310: print => \&print_passwords,
311: modify => \&modify_passwords,
312: },
1.30 raeburn 313: 'quotas' =>
1.197 raeburn 314: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 315: help => 'Domain_Configuration_Quotas',
1.77 raeburn 316: header => [{col1 => 'User affiliation',
1.72 raeburn 317: col2 => 'Available tools',
1.213 raeburn 318: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 319: print => \&print_quotas,
320: modify => \&modify_quotas,
1.30 raeburn 321: },
322: 'autoenroll' =>
323: { text => 'Auto-enrollment settings',
1.67 raeburn 324: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 325: header => [{col1 => 'Configuration setting',
326: col2 => 'Value(s)'}],
1.230 raeburn 327: print => \&print_autoenroll,
328: modify => \&modify_autoenroll,
1.30 raeburn 329: },
330: 'autoupdate' =>
331: { text => 'Auto-update settings',
1.67 raeburn 332: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 333: header => [{col1 => 'Setting',
334: col2 => 'Value',},
1.131 raeburn 335: {col1 => 'Setting',
336: col2 => 'Affiliation'},
1.43 raeburn 337: {col1 => 'User population',
1.227 bisitz 338: col2 => 'Updatable user data'}],
1.230 raeburn 339: print => \&print_autoupdate,
340: modify => \&modify_autoupdate,
1.30 raeburn 341: },
1.125 raeburn 342: 'autocreate' =>
343: { text => 'Auto-course creation settings',
344: help => 'Domain_Configuration_Auto_Creation',
345: header => [{col1 => 'Configuration Setting',
346: col2 => 'Value',}],
1.230 raeburn 347: print => \&print_autocreate,
348: modify => \&modify_autocreate,
1.125 raeburn 349: },
1.30 raeburn 350: 'directorysrch' =>
1.277 raeburn 351: { text => 'Directory searches',
1.67 raeburn 352: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 353: header => [{col1 => 'Institutional Directory Setting',
354: col2 => 'Value',},
355: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 356: col2 => 'Value',}],
1.230 raeburn 357: print => \&print_directorysrch,
358: modify => \&modify_directorysrch,
1.30 raeburn 359: },
360: 'contacts' =>
1.286 raeburn 361: { text => 'E-mail addresses and helpform',
1.67 raeburn 362: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 363: header => [{col1 => 'Default e-mail addresses',
364: col2 => 'Value',},
365: {col1 => 'Recipient(s) for notifications',
366: col2 => 'Value',},
1.340 raeburn 367: {col1 => 'Nightly status check e-mail',
368: col2 => 'Settings',},
1.286 raeburn 369: {col1 => 'Ask helpdesk form settings',
370: col2 => 'Value',},],
1.230 raeburn 371: print => \&print_contacts,
372: modify => \&modify_contacts,
1.30 raeburn 373: },
374: 'usercreation' =>
375: { text => 'User creation',
1.67 raeburn 376: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 377: header => [{col1 => 'Format rule type',
378: col2 => 'Format rules in force'},
1.34 raeburn 379: {col1 => 'User account creation',
380: col2 => 'Usernames which may be created',},
1.30 raeburn 381: {col1 => 'Context',
1.43 raeburn 382: col2 => 'Assignable authentication types'}],
1.230 raeburn 383: print => \&print_usercreation,
384: modify => \&modify_usercreation,
1.30 raeburn 385: },
1.224 raeburn 386: 'selfcreation' =>
387: { text => 'Users self-creating accounts',
388: help => 'Domain_Configuration_Self_Creation',
389: header => [{col1 => 'Self-creation with institutional username',
390: col2 => 'Enabled?'},
391: {col1 => 'Institutional user type (login/SSO self-creation)',
392: col2 => 'Information user can enter'},
1.303 raeburn 393: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 394: col2 => 'Settings'}],
1.230 raeburn 395: print => \&print_selfcreation,
396: modify => \&modify_selfcreation,
1.224 raeburn 397: },
1.69 raeburn 398: 'usermodification' =>
1.33 raeburn 399: { text => 'User modification',
1.67 raeburn 400: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 401: header => [{col1 => 'Target user has role',
1.227 bisitz 402: col2 => 'User information updatable in author context'},
1.33 raeburn 403: {col1 => 'Target user has role',
1.227 bisitz 404: col2 => 'User information updatable in course context'}],
1.230 raeburn 405: print => \&print_usermodification,
406: modify => \&modify_usermodification,
1.33 raeburn 407: },
1.69 raeburn 408: 'scantron' =>
1.346 raeburn 409: { text => 'Bubblesheet format',
1.67 raeburn 410: help => 'Domain_Configuration_Scantron_Format',
1.346 raeburn 411: header => [ {col1 => 'Bubblesheet format file',
412: col2 => ''},
413: {col1 => 'Bubblesheet data upload formats',
414: col2 => 'Settings'}],
1.230 raeburn 415: print => \&print_scantron,
416: modify => \&modify_scantron,
1.46 raeburn 417: },
1.86 raeburn 418: 'requestcourses' =>
419: {text => 'Request creation of courses',
420: help => 'Domain_Configuration_Request_Courses',
421: header => [{col1 => 'User affiliation',
1.102 raeburn 422: col2 => 'Availability/Processing of requests',},
423: {col1 => 'Setting',
1.216 raeburn 424: col2 => 'Value'},
425: {col1 => 'Available textbooks',
1.235 raeburn 426: col2 => ''},
1.242 raeburn 427: {col1 => 'Available templates',
428: col2 => ''},
1.235 raeburn 429: {col1 => 'Validation (not official courses)',
430: col2 => 'Value'},],
1.230 raeburn 431: print => \&print_quotas,
432: modify => \&modify_quotas,
1.86 raeburn 433: },
1.163 raeburn 434: 'requestauthor' =>
1.223 bisitz 435: {text => 'Request Authoring Space',
1.163 raeburn 436: help => 'Domain_Configuration_Request_Author',
437: header => [{col1 => 'User affiliation',
438: col2 => 'Availability/Processing of requests',},
439: {col1 => 'Setting',
440: col2 => 'Value'}],
1.230 raeburn 441: print => \&print_quotas,
442: modify => \&modify_quotas,
1.163 raeburn 443: },
1.69 raeburn 444: 'coursecategories' =>
1.120 raeburn 445: { text => 'Cataloging of courses/communities',
1.67 raeburn 446: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 447: header => [{col1 => 'Catalog type/availability',
448: col2 => '',},
449: {col1 => 'Category settings for standard catalog',
1.57 raeburn 450: col2 => '',},
451: {col1 => 'Categories',
452: col2 => '',
453: }],
1.230 raeburn 454: print => \&print_coursecategories,
455: modify => \&modify_coursecategories,
1.69 raeburn 456: },
457: 'serverstatuses' =>
1.77 raeburn 458: {text => 'Access to server status pages',
1.69 raeburn 459: help => 'Domain_Configuration_Server_Status',
460: header => [{col1 => 'Status Page',
461: col2 => 'Other named users',
462: col3 => 'Specific IPs',
463: }],
1.230 raeburn 464: print => \&print_serverstatuses,
465: modify => \&modify_serverstatuses,
1.69 raeburn 466: },
1.118 jms 467: 'helpsettings' =>
1.282 raeburn 468: {text => 'Support settings',
1.118 jms 469: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 470: header => [{col1 => 'Help Page Settings (logged-in users)',
471: col2 => 'Value'},
472: {col1 => 'Helpdesk Roles',
473: col2 => 'Settings'},],
1.230 raeburn 474: print => \&print_helpsettings,
475: modify => \&modify_helpsettings,
1.118 jms 476: },
1.121 raeburn 477: 'coursedefaults' =>
478: {text => 'Course/Community defaults',
479: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 480: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
481: col2 => 'Value',},
482: {col1 => 'Defaults which can be overridden for each course by a DC',
483: col2 => 'Value',},],
1.230 raeburn 484: print => \&print_coursedefaults,
485: modify => \&modify_coursedefaults,
1.121 raeburn 486: },
1.231 raeburn 487: 'selfenrollment' =>
488: {text => 'Self-enrollment in Course/Community',
489: help => 'Domain_Configuration_Selfenrollment',
490: header => [{col1 => 'Configuration Rights',
491: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
492: {col1 => 'Defaults',
493: col2 => 'Value'},
494: {col1 => 'Self-enrollment validation (optional)',
495: col2 => 'Value'},],
496: print => \&print_selfenrollment,
497: modify => \&modify_selfenrollment,
498: },
1.120 raeburn 499: 'privacy' =>
500: {text => 'User Privacy',
501: help => 'Domain_Configuration_User_Privacy',
502: header => [{col1 => 'Setting',
503: col2 => 'Value',}],
1.230 raeburn 504: print => \&print_privacy,
505: modify => \&modify_privacy,
1.120 raeburn 506: },
1.141 raeburn 507: 'usersessions' =>
1.145 raeburn 508: {text => 'User session hosting/offloading',
1.137 raeburn 509: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 510: header => [{col1 => 'Domain server',
511: col2 => 'Servers to offload sessions to when busy'},
512: {col1 => 'Hosting of users from other domains',
1.137 raeburn 513: col2 => 'Rules'},
514: {col1 => "Hosting domain's own users elsewhere",
515: col2 => 'Rules'}],
1.230 raeburn 516: print => \&print_usersessions,
517: modify => \&modify_usersessions,
1.137 raeburn 518: },
1.279 raeburn 519: 'loadbalancing' =>
1.185 raeburn 520: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 521: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 522: header => [{col1 => 'Balancers',
1.150 raeburn 523: col2 => 'Default destinations',
1.183 bisitz 524: col3 => 'User affiliation',
1.150 raeburn 525: col4 => 'Overrides'},
526: ],
1.230 raeburn 527: print => \&print_loadbalancing,
528: modify => \&modify_loadbalancing,
1.150 raeburn 529: },
1.279 raeburn 530: 'ltitools' =>
1.267 raeburn 531: {text => 'External Tools (LTI)',
1.296 raeburn 532: help => 'Domain_Configuration_LTI_Tools',
1.267 raeburn 533: header => [{col1 => 'Setting',
534: col2 => 'Value',}],
535: print => \&print_ltitools,
536: modify => \&modify_ltitools,
537: },
1.279 raeburn 538: 'ssl' =>
1.275 raeburn 539: {text => 'LON-CAPA Network (SSL)',
540: help => 'Domain_Configuration_Network_SSL',
541: header => [{col1 => 'Server',
542: col2 => 'Certificate Status'},
543: {col1 => 'Connections to other servers',
544: col2 => 'Rules'},
1.293 raeburn 545: {col1 => 'Connections from other servers',
546: col2 => 'Rules'},
1.275 raeburn 547: {col1 => "Replicating domain's published content",
548: col2 => 'Rules'}],
549: print => \&print_ssl,
550: modify => \&modify_ssl,
551: },
1.279 raeburn 552: 'trust' =>
553: {text => 'Trust Settings',
554: help => 'Domain_Configuration_Trust',
555: header => [{col1 => "Access to this domain's content by others",
556: col2 => 'Rules'},
557: {col1 => "Access to other domain's content by this domain",
558: col2 => 'Rules'},
559: {col1 => "Enrollment in this domain's courses by others",
560: col2 => 'Rules',},
561: {col1 => "Co-author roles in this domain for others",
562: col2 => 'Rules',},
563: {col1 => "Co-author roles for this domain's users elsewhere",
564: col2 => 'Rules',},
565: {col1 => "Domain roles in this domain assignable to others",
566: col2 => 'Rules'},
567: {col1 => "Course catalog for this domain displayed elsewhere",
568: col2 => 'Rules'},
569: {col1 => "Requests for creation of courses in this domain by others",
570: col2 => 'Rules'},
571: {col1 => "Users in other domains can send messages to this domain",
572: col2 => 'Rules'},],
573: print => \&print_trust,
574: modify => \&modify_trust,
575: },
1.320 raeburn 576: 'lti' =>
577: {text => 'LTI Provider',
578: help => 'Domain_Configuration_LTI_Provider',
579: header => [{col1 => 'Setting',
580: col2 => 'Value',}],
581: print => \&print_lti,
582: modify => \&modify_lti,
583: },
1.3 raeburn 584: );
1.110 raeburn 585: if (keys(%servers) > 1) {
586: $prefs{'login'} = { text => 'Log-in page options',
587: help => 'Domain_Configuration_Login_Page',
588: header => [{col1 => 'Log-in Service',
589: col2 => 'Server Setting',},
590: {col1 => 'Log-in Page Items',
1.168 raeburn 591: col2 => ''},
592: {col1 => 'Log-in Help',
1.256 raeburn 593: col2 => 'Value'},
594: {col1 => 'Custom HTML in document head',
1.168 raeburn 595: col2 => 'Value'}],
1.230 raeburn 596: print => \&print_login,
597: modify => \&modify_login,
1.110 raeburn 598: };
599: }
1.174 foxr 600:
1.6 raeburn 601: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 602: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 603: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 604: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 605: text=>"Settings to display/modify"});
1.9 raeburn 606: my $confname = $dom.'-domainconfig';
1.174 foxr 607:
1.3 raeburn 608: if ($phase eq 'process') {
1.212 raeburn 609: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
610: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 611: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 612: $r->rflush();
1.212 raeburn 613: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 614: }
1.30 raeburn 615: } elsif ($phase eq 'display') {
1.192 raeburn 616: my $js = &recaptcha_js().
1.236 raeburn 617: &toggle_display_js();
1.171 raeburn 618: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 619: my ($othertitle,$usertypes,$types) =
620: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 621: $js .= &lonbalance_targets_js($dom,$types,\%servers,
622: $domconfig{'loadbalancing'}).
1.170 raeburn 623: &new_spares_js().
624: &common_domprefs_js().
625: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 626: }
1.216 raeburn 627: if (grep(/^requestcourses$/,@actions)) {
628: my $javascript_validations;
629: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
630: $js .= <<END;
631: <script type="text/javascript">
632: $javascript_validations
633: </script>
634: $coursebrowserjs
635: END
636: }
1.305 raeburn 637: if (grep(/^selfcreation$/,@actions)) {
638: $js .= &selfcreate_javascript();
639: }
1.286 raeburn 640: if (grep(/^contacts$/,@actions)) {
641: $js .= &contacts_javascript();
642: }
1.346 raeburn 643: if (grep(/^scantron$/,@actions)) {
644: $js .= &scantron_javascript();
645: }
1.150 raeburn 646: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 647: } else {
1.180 raeburn 648: # check if domconfig user exists for the domain.
649: my $servadm = $r->dir_config('lonAdmEMail');
650: my ($configuserok,$author_ok,$switchserver) =
651: &config_check($dom,$confname,$servadm);
652: unless ($configuserok eq 'ok') {
1.181 raeburn 653: &Apache::lonconfigsettings::print_header($r,$phase,$context);
654: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 655: $confname).
1.181 raeburn 656: '<br />'
657: );
1.180 raeburn 658: if ($switchserver) {
1.181 raeburn 659: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
660: '<br />'.
661: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
662: '<br />'.
663: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
664: '<br />'.
665: &mt('To do that now, use the following link: [_1]',$switchserver)
666: );
667: } else {
668: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
669: '<br />'.
670: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
671: );
1.180 raeburn 672: }
673: $r->print(&Apache::loncommon::end_page());
674: return OK;
675: }
1.21 raeburn 676: if (keys(%domconfig) == 0) {
677: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 678: my @ids=&Apache::lonnet::current_machine_ids();
679: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 680: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 681: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 682: my $custom_img_count = 0;
683: foreach my $img (@loginimages) {
684: if ($designhash{$dom.'.login.'.$img} ne '') {
685: $custom_img_count ++;
686: }
687: }
688: foreach my $role (@roles) {
689: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
690: $custom_img_count ++;
691: }
692: }
693: if ($custom_img_count > 0) {
1.94 raeburn 694: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 695: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 696: $r->print(
697: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
698: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
699: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
700: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
701: if ($switch_server) {
1.30 raeburn 702: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 703: }
1.91 raeburn 704: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 705: return OK;
706: }
707: }
708: }
1.91 raeburn 709: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 710: }
711: return OK;
712: }
713:
714: sub process_changes {
1.205 raeburn 715: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 716: my %domconfig;
717: if (ref($values) eq 'HASH') {
718: %domconfig = %{$values};
719: }
1.3 raeburn 720: my $output;
721: if ($action eq 'login') {
1.205 raeburn 722: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 723: } elsif ($action eq 'rolecolors') {
1.9 raeburn 724: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 725: $lastactref,%domconfig);
1.3 raeburn 726: } elsif ($action eq 'quotas') {
1.216 raeburn 727: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 728: } elsif ($action eq 'autoenroll') {
1.205 raeburn 729: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 730: } elsif ($action eq 'autoupdate') {
731: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 732: } elsif ($action eq 'autocreate') {
733: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 734: } elsif ($action eq 'directorysrch') {
1.295 raeburn 735: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 736: } elsif ($action eq 'usercreation') {
1.28 raeburn 737: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 738: } elsif ($action eq 'selfcreation') {
1.305 raeburn 739: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 740: } elsif ($action eq 'usermodification') {
741: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 742: } elsif ($action eq 'contacts') {
1.205 raeburn 743: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 744: } elsif ($action eq 'defaults') {
1.212 raeburn 745: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 746: } elsif ($action eq 'scantron') {
1.205 raeburn 747: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 748: } elsif ($action eq 'coursecategories') {
1.239 raeburn 749: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 750: } elsif ($action eq 'serverstatuses') {
751: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 752: } elsif ($action eq 'requestcourses') {
1.216 raeburn 753: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 754: } elsif ($action eq 'requestauthor') {
1.216 raeburn 755: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 756: } elsif ($action eq 'helpsettings') {
1.285 raeburn 757: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 758: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 759: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 760: } elsif ($action eq 'selfenrollment') {
761: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 762: } elsif ($action eq 'usersessions') {
1.212 raeburn 763: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 764: } elsif ($action eq 'loadbalancing') {
765: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 766: } elsif ($action eq 'ltitools') {
767: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 768: } elsif ($action eq 'ssl') {
769: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 770: } elsif ($action eq 'trust') {
771: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 772: } elsif ($action eq 'lti') {
773: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.354 raeburn 774: } elsif ($action eq 'passwords') {
775: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.3 raeburn 776: }
777: return $output;
778: }
779:
780: sub print_config_box {
1.9 raeburn 781: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 782: my $rowtotal = 0;
1.49 raeburn 783: my $output;
784: if ($action eq 'coursecategories') {
785: $output = &coursecategories_javascript($settings);
1.236 raeburn 786: } elsif ($action eq 'defaults') {
787: $output = &defaults_javascript($settings);
1.354 raeburn 788: } elsif ($action eq 'passwords') {
789: $output = &passwords_javascript();
1.282 raeburn 790: } elsif ($action eq 'helpsettings') {
791: my (%privs,%levelscurrent);
792: my %full=();
793: my %levels=(
794: course => {},
795: domain => {},
796: system => {},
797: );
798: my $context = 'domain';
799: my $crstype = 'Course';
800: my $formname = 'display';
801: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
802: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
803: $output =
804: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
805: \@templateroles);
1.334 raeburn 806: } elsif ($action eq 'ltitools') {
807: $output .= <itools_javascript($settings);
808: } elsif ($action eq 'lti') {
809: $output .= <i_javascript($settings);
1.91 raeburn 810: }
1.236 raeburn 811: $output .=
1.30 raeburn 812: '<table class="LC_nested_outer">
1.3 raeburn 813: <tr>
1.306 raeburn 814: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 815: &mt($item->{text}).' '.
816: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
817: '</tr>';
1.30 raeburn 818: $rowtotal ++;
1.110 raeburn 819: my $numheaders = 1;
820: if (ref($item->{'header'}) eq 'ARRAY') {
821: $numheaders = scalar(@{$item->{'header'}});
822: }
823: if ($numheaders > 1) {
1.64 raeburn 824: my $colspan = '';
1.145 raeburn 825: my $rightcolspan = '';
1.238 raeburn 826: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 827: ($action eq 'directorysrch') ||
1.256 raeburn 828: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 829: $colspan = ' colspan="2"';
830: }
1.145 raeburn 831: if ($action eq 'usersessions') {
832: $rightcolspan = ' colspan="3"';
833: }
1.30 raeburn 834: $output .= '
1.3 raeburn 835: <tr>
836: <td>
837: <table class="LC_nested">
838: <tr class="LC_info_row">
1.59 bisitz 839: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 840: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 841: </tr>';
1.69 raeburn 842: $rowtotal ++;
1.230 raeburn 843: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 844: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 845: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 846: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
847: ($action eq 'contacts')) {
1.230 raeburn 848: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354 raeburn 849: } elsif ($action eq 'passwords') {
850: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 851: } elsif ($action eq 'coursecategories') {
1.230 raeburn 852: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346 raeburn 853: } elsif ($action eq 'scantron') {
854: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 855: } elsif ($action eq 'login') {
1.256 raeburn 856: if ($numheaders == 4) {
1.168 raeburn 857: $colspan = ' colspan="2"';
858: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
859: } else {
860: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
861: }
1.230 raeburn 862: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 863: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 864: } elsif ($action eq 'rolecolors') {
1.30 raeburn 865: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 866: }
1.30 raeburn 867: $output .= '
1.6 raeburn 868: </table>
869: </td>
870: </tr>
871: <tr>
872: <td>
873: <table class="LC_nested">
874: <tr class="LC_info_row">
1.230 raeburn 875: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 876: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 877: </tr>';
878: $rowtotal ++;
1.230 raeburn 879: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
880: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 881: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.354 raeburn 882: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'passwords')) {
1.238 raeburn 883: if ($action eq 'coursecategories') {
884: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
885: $colspan = ' colspan="2"';
1.279 raeburn 886: } elsif ($action eq 'trust') {
887: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354 raeburn 888: } elsif ($action eq 'passwords') {
889: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.238 raeburn 890: } else {
891: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
892: }
1.279 raeburn 893: if ($action eq 'trust') {
894: $output .= '
895: </table>
896: </td>
897: </tr>';
898: my @trusthdrs = qw(2 3 4 5 6 7);
899: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
900: for (my $i=0; $i<@trusthdrs; $i++) {
901: $output .= '
902: <tr>
903: <td>
904: <table class="LC_nested">
905: <tr class="LC_info_row">
906: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
907: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
908: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
909: </table>
910: </td>
911: </tr>';
912: }
913: $output .= '
914: <tr>
915: <td>
916: <table class="LC_nested">
917: <tr class="LC_info_row">
918: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
919: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
920: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
921: } else {
922: $output .= '
1.63 raeburn 923: </table>
924: </td>
925: </tr>
926: <tr>
927: <td>
928: <table class="LC_nested">
929: <tr class="LC_info_row">
930: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 931: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 932: </tr>'."\n";
1.279 raeburn 933: if ($action eq 'coursecategories') {
934: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.354 raeburn 935: } elsif (($action eq 'contacts') || ($action eq 'passwords')) {
936: if ($action eq 'passwords') {
937: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
938: } else {
939: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
940: }
941: $output .= '
1.340 raeburn 942: </tr>
943: </table>
944: </td>
945: </tr>
946: <tr>
947: <td>
948: <table class="LC_nested">
949: <tr class="LC_info_row">
950: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.354 raeburn 951: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
952: if ($action eq 'passwords') {
953: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
954: } else {
955: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
956: }
957: $output .= '
1.340 raeburn 958: </table>
959: </td>
960: </tr>
961: <tr>';
1.279 raeburn 962: } else {
963: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
964: }
1.238 raeburn 965: }
1.63 raeburn 966: $rowtotal ++;
1.236 raeburn 967: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282 raeburn 968: ($action eq 'defaults') || ($action eq 'directorysrch') ||
969: ($action eq 'helpsettings')) {
1.230 raeburn 970: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346 raeburn 971: } elsif ($action eq 'scantron') {
972: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293 raeburn 973: } elsif ($action eq 'ssl') {
974: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
975: </table>
976: </td>
977: </tr>
978: <tr>
979: <td>
980: <table class="LC_nested">
981: <tr class="LC_info_row">
982: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
983: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
984: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
985: </table>
986: </td>
987: </tr>
988: <tr>
989: <td>
990: <table class="LC_nested">
991: <tr class="LC_info_row">
992: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
993: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
994: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 995: } elsif ($action eq 'login') {
1.256 raeburn 996: if ($numheaders == 4) {
1.168 raeburn 997: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
998: </table>
999: </td>
1000: </tr>
1001: <tr>
1002: <td>
1003: <table class="LC_nested">
1004: <tr class="LC_info_row">
1005: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 1006: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 1007: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1008: $rowtotal ++;
1009: } else {
1010: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1011: }
1.256 raeburn 1012: $output .= '
1013: </table>
1014: </td>
1015: </tr>
1016: <tr>
1017: <td>
1018: <table class="LC_nested">
1019: <tr class="LC_info_row">';
1020: if ($numheaders == 4) {
1021: $output .= '
1022: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1023: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1024: </tr>';
1025: } else {
1026: $output .= '
1027: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1028: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1029: </tr>';
1030: }
1031: $rowtotal ++;
1032: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1033: } elsif ($action eq 'requestcourses') {
1.247 raeburn 1034: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1035: $rowtotal ++;
1036: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 1037: </table>
1038: </td>
1039: </tr>
1040: <tr>
1041: <td>
1042: <table class="LC_nested">
1043: <tr class="LC_info_row">
1044: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1045: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 1046: &textbookcourses_javascript($settings).
1047: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1048: </table>
1049: </td>
1050: </tr>
1051: <tr>
1052: <td>
1053: <table class="LC_nested">
1054: <tr class="LC_info_row">
1055: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1056: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1057: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 1058: </table>
1059: </td>
1060: </tr>
1061: <tr>
1062: <td>
1063: <table class="LC_nested">
1064: <tr class="LC_info_row">
1.306 raeburn 1065: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1066: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1067: </tr>'.
1068: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1069: } elsif ($action eq 'requestauthor') {
1070: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1071: $rowtotal ++;
1.122 jms 1072: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1073: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1074: </table>
1075: </td>
1076: </tr>
1077: <tr>
1078: <td>
1079: <table class="LC_nested">
1080: <tr class="LC_info_row">
1.306 raeburn 1081: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1082: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1083: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1084: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1085: </tr>'.
1.30 raeburn 1086: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1087: </table>
1088: </td>
1089: </tr>
1090: <tr>
1091: <td>
1092: <table class="LC_nested">
1093: <tr class="LC_info_row">
1.59 bisitz 1094: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1095: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1096: </tr>'.
1.30 raeburn 1097: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1098: $rowtotal += 2;
1.6 raeburn 1099: }
1.3 raeburn 1100: } else {
1.30 raeburn 1101: $output .= '
1.3 raeburn 1102: <tr>
1103: <td>
1104: <table class="LC_nested">
1.30 raeburn 1105: <tr class="LC_info_row">';
1.277 raeburn 1106: if ($action eq 'login') {
1.30 raeburn 1107: $output .= '
1.59 bisitz 1108: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1109: } elsif ($action eq 'serverstatuses') {
1110: $output .= '
1.306 raeburn 1111: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1112: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1113:
1.6 raeburn 1114: } else {
1.30 raeburn 1115: $output .= '
1.306 raeburn 1116: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1117: }
1.72 raeburn 1118: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1119: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1120: &mt($item->{'header'}->[0]->{'col2'});
1121: if ($action eq 'serverstatuses') {
1122: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1123: }
1.69 raeburn 1124: } else {
1.306 raeburn 1125: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1126: &mt($item->{'header'}->[0]->{'col2'});
1127: }
1128: $output .= '</td>';
1129: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1130: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1131: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1132: &mt($item->{'header'}->[0]->{'col3'});
1133: } else {
1.306 raeburn 1134: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1135: &mt($item->{'header'}->[0]->{'col3'});
1136: }
1.69 raeburn 1137: if ($action eq 'serverstatuses') {
1138: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1139: }
1140: $output .= '</td>';
1.6 raeburn 1141: }
1.150 raeburn 1142: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1143: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1144: &mt($item->{'header'}->[0]->{'col4'});
1145: }
1.69 raeburn 1146: $output .= '</tr>';
1.48 raeburn 1147: $rowtotal ++;
1.168 raeburn 1148: if ($action eq 'quotas') {
1.86 raeburn 1149: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1150: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1151: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.320 raeburn 1152: ($action eq 'ltitools') || ($action eq 'lti')) {
1.230 raeburn 1153: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1154: }
1.3 raeburn 1155: }
1.30 raeburn 1156: $output .= '
1.3 raeburn 1157: </table>
1158: </td>
1159: </tr>
1.30 raeburn 1160: </table><br />';
1161: return ($output,$rowtotal);
1.1 raeburn 1162: }
1163:
1.3 raeburn 1164: sub print_login {
1.168 raeburn 1165: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 1166: my ($css_class,$datatable);
1.6 raeburn 1167: my %choices = &login_choices();
1.110 raeburn 1168:
1.168 raeburn 1169: if ($caller eq 'service') {
1.149 raeburn 1170: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1171: my $choice = $choices{'disallowlogin'};
1172: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1173: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1174: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1175: '<th>'.$choices{'server'}.'</th>'.
1176: '<th>'.$choices{'serverpath'}.'</th>'.
1177: '<th>'.$choices{'custompath'}.'</th>'.
1178: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1179: my %disallowed;
1180: if (ref($settings) eq 'HASH') {
1181: if (ref($settings->{'loginvia'}) eq 'HASH') {
1182: %disallowed = %{$settings->{'loginvia'}};
1183: }
1184: }
1185: foreach my $lonhost (sort(keys(%servers))) {
1186: my $direct = 'selected="selected"';
1.128 raeburn 1187: if (ref($disallowed{$lonhost}) eq 'HASH') {
1188: if ($disallowed{$lonhost}{'server'} ne '') {
1189: $direct = '';
1190: }
1.110 raeburn 1191: }
1.115 raeburn 1192: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1193: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1194: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1195: '</option>';
1.184 raeburn 1196: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1197: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1198: my $selected = '';
1.128 raeburn 1199: if (ref($disallowed{$lonhost}) eq 'HASH') {
1200: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1201: $selected = 'selected="selected"';
1202: }
1.110 raeburn 1203: }
1204: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1205: $servers{$hostid}.'</option>';
1206: }
1.128 raeburn 1207: $datatable .= '</select></td>'.
1208: '<td><select name="'.$lonhost.'_serverpath">';
1209: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1210: my $pathname = $path;
1211: if ($path eq 'custom') {
1212: $pathname = &mt('Custom Path').' ->';
1213: }
1214: my $selected = '';
1215: if (ref($disallowed{$lonhost}) eq 'HASH') {
1216: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1217: $selected = 'selected="selected"';
1218: }
1219: } elsif ($path eq '') {
1220: $selected = 'selected="selected"';
1221: }
1222: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1223: }
1224: $datatable .= '</select></td>';
1225: my ($custom,$exempt);
1226: if (ref($disallowed{$lonhost}) eq 'HASH') {
1227: $custom = $disallowed{$lonhost}{'custompath'};
1228: $exempt = $disallowed{$lonhost}{'exempt'};
1229: }
1230: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1231: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1232: '</tr>';
1.110 raeburn 1233: }
1234: $datatable .= '</table></td></tr>';
1235: return $datatable;
1.168 raeburn 1236: } elsif ($caller eq 'page') {
1237: my %defaultchecked = (
1238: 'coursecatalog' => 'on',
1.188 raeburn 1239: 'helpdesk' => 'on',
1.168 raeburn 1240: 'adminmail' => 'off',
1241: 'newuser' => 'off',
1242: );
1.188 raeburn 1243: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1244: my (%checkedon,%checkedoff);
1.42 raeburn 1245: foreach my $item (@toggles) {
1.168 raeburn 1246: if ($defaultchecked{$item} eq 'on') {
1247: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1248: $checkedoff{$item} = ' ';
1.168 raeburn 1249: } elsif ($defaultchecked{$item} eq 'off') {
1250: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1251: $checkedon{$item} = ' ';
1252: }
1.1 raeburn 1253: }
1.168 raeburn 1254: my @images = ('img','logo','domlogo','login');
1255: my @logintext = ('textcol','bgcol');
1256: my @bgs = ('pgbg','mainbg','sidebg');
1257: my @links = ('link','alink','vlink');
1258: my %designhash = &Apache::loncommon::get_domainconf($dom);
1259: my %defaultdesign = %Apache::loncommon::defaultdesign;
1260: my (%is_custom,%designs);
1261: my %defaults = (
1262: font => $defaultdesign{'login.font'},
1263: );
1.6 raeburn 1264: foreach my $item (@images) {
1.168 raeburn 1265: $defaults{$item} = $defaultdesign{'login.'.$item};
1266: $defaults{'showlogo'}{$item} = 1;
1267: }
1268: foreach my $item (@bgs) {
1269: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1270: }
1.41 raeburn 1271: foreach my $item (@logintext) {
1.168 raeburn 1272: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1273: }
1.168 raeburn 1274: foreach my $item (@links) {
1275: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1276: }
1.168 raeburn 1277: if (ref($settings) eq 'HASH') {
1278: foreach my $item (@toggles) {
1279: if ($settings->{$item} eq '1') {
1280: $checkedon{$item} = ' checked="checked" ';
1281: $checkedoff{$item} = ' ';
1282: } elsif ($settings->{$item} eq '0') {
1283: $checkedoff{$item} = ' checked="checked" ';
1284: $checkedon{$item} = ' ';
1285: }
1286: }
1287: foreach my $item (@images) {
1288: if (defined($settings->{$item})) {
1289: $designs{$item} = $settings->{$item};
1290: $is_custom{$item} = 1;
1291: }
1292: if (defined($settings->{'showlogo'}{$item})) {
1293: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1294: }
1295: }
1296: foreach my $item (@logintext) {
1297: if ($settings->{$item} ne '') {
1298: $designs{'logintext'}{$item} = $settings->{$item};
1299: $is_custom{$item} = 1;
1300: }
1301: }
1302: if ($settings->{'font'} ne '') {
1303: $designs{'font'} = $settings->{'font'};
1304: $is_custom{'font'} = 1;
1305: }
1306: foreach my $item (@bgs) {
1307: if ($settings->{$item} ne '') {
1308: $designs{'bgs'}{$item} = $settings->{$item};
1309: $is_custom{$item} = 1;
1310: }
1311: }
1312: foreach my $item (@links) {
1313: if ($settings->{$item} ne '') {
1314: $designs{'links'}{$item} = $settings->{$item};
1315: $is_custom{$item} = 1;
1316: }
1317: }
1318: } else {
1319: if ($designhash{$dom.'.login.font'} ne '') {
1320: $designs{'font'} = $designhash{$dom.'.login.font'};
1321: $is_custom{'font'} = 1;
1322: }
1323: foreach my $item (@images) {
1324: if ($designhash{$dom.'.login.'.$item} ne '') {
1325: $designs{$item} = $designhash{$dom.'.login.'.$item};
1326: $is_custom{$item} = 1;
1327: }
1328: }
1329: foreach my $item (@bgs) {
1330: if ($designhash{$dom.'.login.'.$item} ne '') {
1331: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1332: $is_custom{$item} = 1;
1333: }
1.6 raeburn 1334: }
1.168 raeburn 1335: foreach my $item (@links) {
1336: if ($designhash{$dom.'.login.'.$item} ne '') {
1337: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1338: $is_custom{$item} = 1;
1339: }
1.6 raeburn 1340: }
1341: }
1.168 raeburn 1342: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1343: logo => 'Institution Logo',
1344: domlogo => 'Domain Logo',
1345: login => 'Login box');
1346: my $itemcount = 1;
1347: foreach my $item (@toggles) {
1348: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1349: $datatable .=
1350: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1351: '</td><td>'.
1352: '<span class="LC_nobreak"><label><input type="radio" name="'.
1353: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1354: '</label> <label><input type="radio" name="'.$item.'"'.
1355: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1356: '</tr>';
1357: $itemcount ++;
1.6 raeburn 1358: }
1.168 raeburn 1359: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1360: $datatable .= '</tr></table></td></tr>';
1361: } elsif ($caller eq 'help') {
1362: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1363: my $switchserver = &check_switchserver($dom,$confname);
1364: my $itemcount = 1;
1365: $defaulturl = '/adm/loginproblems.html';
1366: $defaulttype = 'default';
1367: %lt = &Apache::lonlocal::texthash (
1368: del => 'Delete?',
1369: rep => 'Replace:',
1370: upl => 'Upload:',
1371: default => 'Default',
1372: custom => 'Custom',
1373: );
1374: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1375: my @currlangs;
1376: if (ref($settings) eq 'HASH') {
1377: if (ref($settings->{'helpurl'}) eq 'HASH') {
1378: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1379: next if ($settings->{'helpurl'}{$key} eq '');
1380: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1381: $type{$key} = 'custom';
1382: unless ($key eq 'nolang') {
1383: push(@currlangs,$key);
1384: }
1385: }
1386: } elsif ($settings->{'helpurl'} ne '') {
1387: $type{'nolang'} = 'custom';
1388: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1389: }
1390: }
1.168 raeburn 1391: foreach my $lang ('nolang',sort(@currlangs)) {
1392: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1393: $datatable .= '<tr'.$css_class.'>';
1394: if ($url{$lang} eq '') {
1395: $url{$lang} = $defaulturl;
1396: }
1397: if ($type{$lang} eq '') {
1398: $type{$lang} = $defaulttype;
1399: }
1400: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1401: if ($lang eq 'nolang') {
1402: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1403: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1404: } else {
1405: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1406: $langchoices{$lang},
1407: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1408: }
1409: $datatable .= '</span></td>'."\n".
1410: '<td class="LC_left_item">';
1411: if ($type{$lang} eq 'custom') {
1412: $datatable .= '<span class="LC_nobreak"><label>'.
1413: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1414: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1415: } else {
1416: $datatable .= $lt{'upl'};
1417: }
1418: $datatable .='<br />';
1419: if ($switchserver) {
1420: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1421: } else {
1422: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1423: }
1.168 raeburn 1424: $datatable .= '</td></tr>';
1425: $itemcount ++;
1.6 raeburn 1426: }
1.168 raeburn 1427: my @addlangs;
1428: foreach my $lang (sort(keys(%langchoices))) {
1429: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1430: push(@addlangs,$lang);
1431: }
1432: if (@addlangs > 0) {
1433: my %toadd;
1434: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1435: $toadd{''} = &mt('Select');
1436: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1437: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1438: &mt('Add log-in help page for a specific language:').' '.
1439: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1440: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1441: if ($switchserver) {
1442: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1443: } else {
1444: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1445: }
1.168 raeburn 1446: $datatable .= '</td></tr>';
1.169 raeburn 1447: $itemcount ++;
1.6 raeburn 1448: }
1.169 raeburn 1449: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1450: } elsif ($caller eq 'headtag') {
1451: my %domservers = &Apache::lonnet::get_servers($dom);
1452: my $choice = $choices{'headtag'};
1453: $css_class = ' class="LC_odd_row"';
1454: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1455: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1456: '<th>'.$choices{'current'}.'</th>'.
1457: '<th>'.$choices{'action'}.'</th>'.
1458: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1459: my (%currurls,%currexempt);
1460: if (ref($settings) eq 'HASH') {
1461: if (ref($settings->{'headtag'}) eq 'HASH') {
1462: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1463: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1464: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1465: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1466: }
1467: }
1468: }
1469: }
1470: my %lt = &Apache::lonlocal::texthash(
1471: del => 'Delete?',
1472: rep => 'Replace:',
1473: upl => 'Upload:',
1474: curr => 'View contents',
1475: none => 'None',
1476: );
1477: my $switchserver = &check_switchserver($dom,$confname);
1478: foreach my $lonhost (sort(keys(%domservers))) {
1479: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1480: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1481: if ($currurls{$lonhost}) {
1482: $datatable .= '<td class="LC_right_item"><a href="'.
1483: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1484: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1485: '">'.$lt{'curr'}.'</a></td>'.
1486: '<td><span class="LC_nobreak"><label>'.
1487: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1488: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1489: } else {
1490: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1491: }
1492: $datatable .='<br />';
1493: if ($switchserver) {
1494: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1495: } else {
1496: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1497: }
1.330 raeburn 1498: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1499: }
1500: $datatable .= '</table></td></tr>';
1.1 raeburn 1501: }
1.6 raeburn 1502: return $datatable;
1503: }
1504:
1505: sub login_choices {
1506: my %choices =
1507: &Apache::lonlocal::texthash (
1.116 bisitz 1508: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1509: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1510: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1511: disallowlogin => "Login page requests redirected",
1512: hostid => "Server",
1.128 raeburn 1513: server => "Redirect to:",
1514: serverpath => "Path",
1515: custompath => "Custom",
1516: exempt => "Exempt IP(s)",
1.110 raeburn 1517: directlogin => "No redirect",
1518: newuser => "Link to create a user account",
1519: img => "Header",
1520: logo => "Main Logo",
1521: domlogo => "Domain Logo",
1522: login => "Log-in Header",
1523: textcol => "Text color",
1524: bgcol => "Box color",
1525: bgs => "Background colors",
1526: links => "Link colors",
1527: font => "Font color",
1528: pgbg => "Header",
1529: mainbg => "Page",
1530: sidebg => "Login box",
1531: link => "Link",
1532: alink => "Active link",
1533: vlink => "Visited link",
1.256 raeburn 1534: headtag => "Custom markup",
1535: action => "Action",
1536: current => "Current",
1.6 raeburn 1537: );
1538: return %choices;
1539: }
1540:
1541: sub print_rolecolors {
1.30 raeburn 1542: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1543: my %choices = &color_font_choices();
1544: my @bgs = ('pgbg','tabbg','sidebg');
1545: my @links = ('link','alink','vlink');
1546: my @images = ('img');
1547: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1548: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1549: my %defaultdesign = %Apache::loncommon::defaultdesign;
1550: my (%is_custom,%designs);
1.200 raeburn 1551: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1552: if (ref($settings) eq 'HASH') {
1553: if (ref($settings->{$role}) eq 'HASH') {
1554: if ($settings->{$role}->{'img'} ne '') {
1555: $designs{'img'} = $settings->{$role}->{'img'};
1556: $is_custom{'img'} = 1;
1557: }
1558: if ($settings->{$role}->{'font'} ne '') {
1559: $designs{'font'} = $settings->{$role}->{'font'};
1560: $is_custom{'font'} = 1;
1561: }
1.97 tempelho 1562: if ($settings->{$role}->{'fontmenu'} ne '') {
1563: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1564: $is_custom{'fontmenu'} = 1;
1565: }
1.6 raeburn 1566: foreach my $item (@bgs) {
1567: if ($settings->{$role}->{$item} ne '') {
1568: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1569: $is_custom{$item} = 1;
1570: }
1571: }
1572: foreach my $item (@links) {
1573: if ($settings->{$role}->{$item} ne '') {
1574: $designs{'links'}{$item} = $settings->{$role}->{$item};
1575: $is_custom{$item} = 1;
1576: }
1577: }
1578: }
1579: } else {
1580: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1581: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1582: $is_custom{'img'} = 1;
1583: }
1.97 tempelho 1584: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1585: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1586: $is_custom{'fontmenu'} = 1;
1587: }
1.6 raeburn 1588: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1589: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1590: $is_custom{'font'} = 1;
1591: }
1592: foreach my $item (@bgs) {
1593: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1594: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1595: $is_custom{$item} = 1;
1596:
1597: }
1598: }
1599: foreach my $item (@links) {
1600: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1601: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1602: $is_custom{$item} = 1;
1603: }
1604: }
1605: }
1606: my $itemcount = 1;
1.30 raeburn 1607: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1608: $datatable .= '</tr></table></td></tr>';
1609: return $datatable;
1610: }
1611:
1.200 raeburn 1612: sub role_defaults {
1613: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1614: my %defaults;
1615: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1616: return %defaults;
1617: }
1618: my %defaultdesign = %Apache::loncommon::defaultdesign;
1619: if ($role eq 'login') {
1620: %defaults = (
1621: font => $defaultdesign{$role.'.font'},
1622: );
1623: if (ref($logintext) eq 'ARRAY') {
1624: foreach my $item (@{$logintext}) {
1625: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1626: }
1627: }
1628: foreach my $item (@{$images}) {
1629: $defaults{'showlogo'}{$item} = 1;
1630: }
1631: } else {
1632: %defaults = (
1633: img => $defaultdesign{$role.'.img'},
1634: font => $defaultdesign{$role.'.font'},
1635: fontmenu => $defaultdesign{$role.'.fontmenu'},
1636: );
1637: }
1638: foreach my $item (@{$bgs}) {
1639: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1640: }
1641: foreach my $item (@{$links}) {
1642: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1643: }
1644: foreach my $item (@{$images}) {
1645: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1646: }
1647: return %defaults;
1648: }
1649:
1.6 raeburn 1650: sub display_color_options {
1.9 raeburn 1651: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1652: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1653: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1654: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1655: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1656: '<td>'.$choices->{'font'}.'</td>';
1657: if (!$is_custom->{'font'}) {
1.329 raeburn 1658: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1659: } else {
1660: $datatable .= '<td> </td>';
1661: }
1.174 foxr 1662: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1663:
1.8 raeburn 1664: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1665: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1666: ' value="'.$current_color.'" /> '.
1.329 raeburn 1667: ' </span></td></tr>';
1.107 raeburn 1668: unless ($role eq 'login') {
1669: $datatable .= '<tr'.$css_class.'>'.
1670: '<td>'.$choices->{'fontmenu'}.'</td>';
1671: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 1672: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1673: } else {
1674: $datatable .= '<td> </td>';
1675: }
1.202 raeburn 1676: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1677: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1678: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1679: '<input class="colorchooser" type="text" size="10" name="'
1680: .$role.'_fontmenu"'.
1681: ' value="'.$current_color.'" /> '.
1.329 raeburn 1682: ' </span></td></tr>';
1.97 tempelho 1683: }
1.9 raeburn 1684: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1685: foreach my $img (@{$images}) {
1.18 albertel 1686: $itemcount ++;
1.6 raeburn 1687: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1688: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1689: '<td>'.$choices->{$img};
1.41 raeburn 1690: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1691: if ($role eq 'login') {
1692: if ($img eq 'login') {
1693: $login_hdr_pick =
1.135 bisitz 1694: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1695: $logincolors =
1696: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1697: $designs,$defaults);
1.70 raeburn 1698: } elsif ($img ne 'domlogo') {
1699: $datatable.= &logo_display_options($img,$defaults,$designs);
1700: }
1701: }
1702: $datatable .= '</td>';
1.6 raeburn 1703: if ($designs->{$img} ne '') {
1704: $imgfile = $designs->{$img};
1.18 albertel 1705: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1706: } else {
1707: $imgfile = $defaults->{$img};
1708: }
1709: if ($imgfile) {
1.9 raeburn 1710: my ($showfile,$fullsize);
1711: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1712: my $urldir = $1;
1713: my $filename = $2;
1714: my @info = &Apache::lonnet::stat_file($designs->{$img});
1715: if (@info) {
1716: my $thumbfile = 'tn-'.$filename;
1717: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1718: if (@thumb) {
1719: $showfile = $urldir.'/'.$thumbfile;
1720: } else {
1721: $showfile = $imgfile;
1722: }
1723: } else {
1724: $showfile = '';
1725: }
1726: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1727: $showfile = $imgfile;
1.6 raeburn 1728: my $imgdir = $1;
1729: my $filename = $2;
1.159 raeburn 1730: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1731: $showfile = "/$imgdir/tn-".$filename;
1732: } else {
1.159 raeburn 1733: my $input = $londocroot.$imgfile;
1734: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1735: if (!-e $output) {
1.9 raeburn 1736: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1737: my ($fullwidth,$fullheight) = &check_dimensions($input);
1738: if ($fullwidth ne '' && $fullheight ne '') {
1739: if ($fullwidth > $width && $fullheight > $height) {
1740: my $size = $width.'x'.$height;
1.316 raeburn 1741: my @args = ('convert','-sample',$size,$input,$output);
1742: system({$args[0]} @args);
1.159 raeburn 1743: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1744: }
1745: }
1.6 raeburn 1746: }
1747: }
1.16 raeburn 1748: }
1.6 raeburn 1749: if ($showfile) {
1.40 raeburn 1750: if ($showfile =~ m{^/(adm|res)/}) {
1751: if ($showfile =~ m{^/res/}) {
1752: my $local_showfile =
1753: &Apache::lonnet::filelocation('',$showfile);
1754: &Apache::lonnet::repcopy($local_showfile);
1755: }
1756: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1757: }
1758: if ($imgfile) {
1759: if ($imgfile =~ m{^/(adm|res)/}) {
1760: if ($imgfile =~ m{^/res/}) {
1761: my $local_imgfile =
1762: &Apache::lonnet::filelocation('',$imgfile);
1763: &Apache::lonnet::repcopy($local_imgfile);
1764: }
1765: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1766: } else {
1767: $fullsize = $imgfile;
1768: }
1769: }
1.41 raeburn 1770: $datatable .= '<td>';
1771: if ($img eq 'login') {
1.135 bisitz 1772: $datatable .= $login_hdr_pick;
1773: }
1.41 raeburn 1774: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1775: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1776: } else {
1.201 raeburn 1777: $datatable .= '<td> </td><td class="LC_left_item">'.
1778: &mt('Upload:').'<br />';
1.6 raeburn 1779: }
1780: } else {
1.201 raeburn 1781: $datatable .= '<td> </td><td class="LC_left_item">'.
1782: &mt('Upload:').'<br />';
1.6 raeburn 1783: }
1.9 raeburn 1784: if ($switchserver) {
1785: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1786: } else {
1.135 bisitz 1787: if ($img ne 'login') { # suppress file selection for Log-in header
1788: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1789: }
1.9 raeburn 1790: }
1791: $datatable .= '</td></tr>';
1.6 raeburn 1792: }
1793: $itemcount ++;
1794: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1795: $datatable .= '<tr'.$css_class.'>'.
1796: '<td>'.$choices->{'bgs'}.'</td>';
1797: my $bgs_def;
1798: foreach my $item (@{$bgs}) {
1799: if (!$is_custom->{$item}) {
1.329 raeburn 1800: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span class="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 1801: }
1802: }
1803: if ($bgs_def) {
1.8 raeburn 1804: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1805: } else {
1806: $datatable .= '<td> </td>';
1807: }
1808: $datatable .= '<td class="LC_right_item">'.
1809: '<table border="0"><tr>';
1.174 foxr 1810:
1.6 raeburn 1811: foreach my $item (@{$bgs}) {
1.306 raeburn 1812: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 1813: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1814: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1815: $datatable .= ' ';
1.6 raeburn 1816: }
1.174 foxr 1817: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1818: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1819: }
1820: $datatable .= '</tr></table></td></tr>';
1821: $itemcount ++;
1822: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1823: $datatable .= '<tr'.$css_class.'>'.
1824: '<td>'.$choices->{'links'}.'</td>';
1825: my $links_def;
1826: foreach my $item (@{$links}) {
1827: if (!$is_custom->{$item}) {
1.329 raeburn 1828: $links_def .= '<td>'.$choices->{$item}.'<br /><span class="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1829: }
1830: }
1831: if ($links_def) {
1.8 raeburn 1832: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1833: } else {
1834: $datatable .= '<td> </td>';
1835: }
1836: $datatable .= '<td class="LC_right_item">'.
1837: '<table border="0"><tr>';
1838: foreach my $item (@{$links}) {
1.234 raeburn 1839: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 1840: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 1841: if ($designs->{'links'}{$item}) {
1.174 foxr 1842: $datatable.=' ';
1.6 raeburn 1843: }
1.174 foxr 1844: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1845: '" /></td>';
1846: }
1.30 raeburn 1847: $$rowtotal += $itemcount;
1.3 raeburn 1848: return $datatable;
1849: }
1850:
1.70 raeburn 1851: sub logo_display_options {
1852: my ($img,$defaults,$designs) = @_;
1853: my $checkedon;
1854: if (ref($defaults) eq 'HASH') {
1855: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1856: if ($defaults->{'showlogo'}{$img}) {
1857: $checkedon = 'checked="checked" ';
1858: }
1859: }
1860: }
1861: if (ref($designs) eq 'HASH') {
1862: if (ref($designs->{'showlogo'}) eq 'HASH') {
1863: if (defined($designs->{'showlogo'}{$img})) {
1864: if ($designs->{'showlogo'}{$img} == 0) {
1865: $checkedon = '';
1866: } elsif ($designs->{'showlogo'}{$img} == 1) {
1867: $checkedon = 'checked="checked" ';
1868: }
1869: }
1870: }
1871: }
1872: return '<br /><label> <input type="checkbox" name="'.
1873: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1874: &mt('show').'</label>'."\n";
1875: }
1876:
1.41 raeburn 1877: sub login_header_options {
1.135 bisitz 1878: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1879: my $output = '';
1.41 raeburn 1880: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1881: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1882: if (!$is_custom->{'textcol'}) {
1883: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1884: ' ';
1885: }
1886: if (!$is_custom->{'bgcol'}) {
1887: $output .= $choices->{'bgcol'}.': '.
1888: '<span id="css_'.$role.'_font" style="background-color: '.
1889: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1890: }
1891: $output .= '<br />';
1892: }
1893: $output .='<br />';
1894: return $output;
1895: }
1896:
1897: sub login_text_colors {
1.201 raeburn 1898: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1899: my $color_menu = '<table border="0"><tr>';
1900: foreach my $item (@{$logintext}) {
1.306 raeburn 1901: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 1902: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1903: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1904: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1905: }
1906: $color_menu .= '</tr></table><br />';
1907: return $color_menu;
1908: }
1909:
1910: sub image_changes {
1911: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1912: my $output;
1.135 bisitz 1913: if ($img eq 'login') {
1.331 raeburn 1914: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 1915: } elsif (!$is_custom) {
1.70 raeburn 1916: if ($img ne 'domlogo') {
1.331 raeburn 1917: $output = &mt('Default image:').'<br />';
1.41 raeburn 1918: } else {
1.331 raeburn 1919: $output = &mt('Default in use:').'<br />';
1.41 raeburn 1920: }
1921: }
1.331 raeburn 1922: if ($img ne 'login') {
1.135 bisitz 1923: if ($img_import) {
1924: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1925: }
1926: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1927: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1928: if ($is_custom) {
1929: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1930: '<input type="checkbox" name="'.
1931: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1932: '</label> '.&mt('Replace:').'</span><br />';
1933: } else {
1.306 raeburn 1934: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1935: }
1.41 raeburn 1936: }
1937: return $output;
1938: }
1939:
1.3 raeburn 1940: sub print_quotas {
1.86 raeburn 1941: my ($dom,$settings,$rowtotal,$action) = @_;
1942: my $context;
1943: if ($action eq 'quotas') {
1944: $context = 'tools';
1945: } else {
1946: $context = $action;
1947: }
1.197 raeburn 1948: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1949: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1950: my $typecount = 0;
1.101 raeburn 1951: my ($css_class,%titles);
1.86 raeburn 1952: if ($context eq 'requestcourses') {
1.325 raeburn 1953: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 1954: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1955: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1956: %titles = &courserequest_titles();
1.163 raeburn 1957: } elsif ($context eq 'requestauthor') {
1958: @usertools = ('author');
1959: @options = ('norequest','approval','automatic');
1.210 raeburn 1960: %titles = &authorrequest_titles();
1.86 raeburn 1961: } else {
1.162 raeburn 1962: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1963: %titles = &tool_titles();
1.86 raeburn 1964: }
1.26 raeburn 1965: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1966: foreach my $type (@{$types}) {
1.197 raeburn 1967: my ($currdefquota,$currauthorquota);
1.163 raeburn 1968: unless (($context eq 'requestcourses') ||
1969: ($context eq 'requestauthor')) {
1.86 raeburn 1970: if (ref($settings) eq 'HASH') {
1971: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1972: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1973: } else {
1974: $currdefquota = $settings->{$type};
1975: }
1.197 raeburn 1976: if (ref($settings->{authorquota}) eq 'HASH') {
1977: $currauthorquota = $settings->{authorquota}->{$type};
1978: }
1.78 raeburn 1979: }
1.72 raeburn 1980: }
1.3 raeburn 1981: if (defined($usertypes->{$type})) {
1982: $typecount ++;
1983: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1984: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1985: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1986: '<td class="LC_left_item">';
1.101 raeburn 1987: if ($context eq 'requestcourses') {
1988: $datatable .= '<table><tr>';
1989: }
1990: my %cell;
1.72 raeburn 1991: foreach my $item (@usertools) {
1.101 raeburn 1992: if ($context eq 'requestcourses') {
1993: my ($curroption,$currlimit);
1994: if (ref($settings) eq 'HASH') {
1995: if (ref($settings->{$item}) eq 'HASH') {
1996: $curroption = $settings->{$item}->{$type};
1997: if ($curroption =~ /^autolimit=(\d*)$/) {
1998: $currlimit = $1;
1999: }
2000: }
2001: }
2002: if (!$curroption) {
2003: $curroption = 'norequest';
2004: }
2005: $datatable .= '<th>'.$titles{$item}.'</th>';
2006: foreach my $option (@options) {
2007: my $val = $option;
2008: if ($option eq 'norequest') {
2009: $val = 0;
2010: }
2011: if ($option eq 'validate') {
2012: my $canvalidate = 0;
2013: if (ref($validations{$item}) eq 'HASH') {
2014: if ($validations{$item}{$type}) {
2015: $canvalidate = 1;
2016: }
2017: }
2018: next if (!$canvalidate);
2019: }
2020: my $checked = '';
2021: if ($option eq $curroption) {
2022: $checked = ' checked="checked"';
2023: } elsif ($option eq 'autolimit') {
2024: if ($curroption =~ /^autolimit/) {
2025: $checked = ' checked="checked"';
2026: }
2027: }
2028: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2029: '<input type="radio" name="crsreq_'.$item.
2030: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2031: $titles{$option}.'</label>';
1.101 raeburn 2032: if ($option eq 'autolimit') {
1.127 raeburn 2033: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2034: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2035: 'value="'.$currlimit.'" />';
1.101 raeburn 2036: }
1.127 raeburn 2037: $cell{$item} .= '</span> ';
1.103 raeburn 2038: if ($option eq 'autolimit') {
1.127 raeburn 2039: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2040: }
1.101 raeburn 2041: }
1.163 raeburn 2042: } elsif ($context eq 'requestauthor') {
2043: my $curroption;
2044: if (ref($settings) eq 'HASH') {
2045: $curroption = $settings->{$type};
2046: }
2047: if (!$curroption) {
2048: $curroption = 'norequest';
2049: }
2050: foreach my $option (@options) {
2051: my $val = $option;
2052: if ($option eq 'norequest') {
2053: $val = 0;
2054: }
2055: my $checked = '';
2056: if ($option eq $curroption) {
2057: $checked = ' checked="checked"';
2058: }
2059: $datatable .= '<span class="LC_nobreak"><label>'.
2060: '<input type="radio" name="authorreq_'.$type.
2061: '" value="'.$val.'"'.$checked.' />'.
2062: $titles{$option}.'</label></span> ';
2063: }
1.101 raeburn 2064: } else {
2065: my $checked = 'checked="checked" ';
2066: if (ref($settings) eq 'HASH') {
2067: if (ref($settings->{$item}) eq 'HASH') {
2068: if ($settings->{$item}->{$type} == 0) {
2069: $checked = '';
2070: } elsif ($settings->{$item}->{$type} == 1) {
2071: $checked = 'checked="checked" ';
2072: }
1.78 raeburn 2073: }
1.72 raeburn 2074: }
1.101 raeburn 2075: $datatable .= '<span class="LC_nobreak"><label>'.
2076: '<input type="checkbox" name="'.$context.'_'.$item.
2077: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2078: '</label></span> ';
1.72 raeburn 2079: }
1.101 raeburn 2080: }
2081: if ($context eq 'requestcourses') {
2082: $datatable .= '</tr><tr>';
2083: foreach my $item (@usertools) {
1.106 raeburn 2084: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2085: }
2086: $datatable .= '</tr></table>';
1.72 raeburn 2087: }
1.86 raeburn 2088: $datatable .= '</td>';
1.163 raeburn 2089: unless (($context eq 'requestcourses') ||
2090: ($context eq 'requestauthor')) {
1.86 raeburn 2091: $datatable .=
1.197 raeburn 2092: '<td class="LC_right_item">'.
2093: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2094: '<input type="text" name="quota_'.$type.
1.72 raeburn 2095: '" value="'.$currdefquota.
1.197 raeburn 2096: '" size="5" /></span>'.(' ' x 2).
2097: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2098: '<input type="text" name="authorquota_'.$type.
2099: '" value="'.$currauthorquota.
2100: '" size="5" /></span></td>';
1.86 raeburn 2101: }
2102: $datatable .= '</tr>';
1.3 raeburn 2103: }
2104: }
2105: }
1.163 raeburn 2106: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2107: $defaultquota = '20';
1.197 raeburn 2108: $authorquota = '500';
1.86 raeburn 2109: if (ref($settings) eq 'HASH') {
2110: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2111: $defaultquota = $settings->{'defaultquota'}->{'default'};
2112: } elsif (defined($settings->{'default'})) {
2113: $defaultquota = $settings->{'default'};
2114: }
1.197 raeburn 2115: if (ref($settings->{'authorquota'}) eq 'HASH') {
2116: $authorquota = $settings->{'authorquota'}->{'default'};
2117: }
1.3 raeburn 2118: }
2119: }
2120: $typecount ++;
2121: $css_class = $typecount%2?' class="LC_odd_row"':'';
2122: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2123: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2124: '<td class="LC_left_item">';
1.101 raeburn 2125: if ($context eq 'requestcourses') {
2126: $datatable .= '<table><tr>';
2127: }
2128: my %defcell;
1.72 raeburn 2129: foreach my $item (@usertools) {
1.101 raeburn 2130: if ($context eq 'requestcourses') {
2131: my ($curroption,$currlimit);
2132: if (ref($settings) eq 'HASH') {
2133: if (ref($settings->{$item}) eq 'HASH') {
2134: $curroption = $settings->{$item}->{'default'};
2135: if ($curroption =~ /^autolimit=(\d*)$/) {
2136: $currlimit = $1;
2137: }
2138: }
2139: }
2140: if (!$curroption) {
2141: $curroption = 'norequest';
2142: }
2143: $datatable .= '<th>'.$titles{$item}.'</th>';
2144: foreach my $option (@options) {
2145: my $val = $option;
2146: if ($option eq 'norequest') {
2147: $val = 0;
2148: }
2149: if ($option eq 'validate') {
2150: my $canvalidate = 0;
2151: if (ref($validations{$item}) eq 'HASH') {
2152: if ($validations{$item}{'default'}) {
2153: $canvalidate = 1;
2154: }
2155: }
2156: next if (!$canvalidate);
2157: }
2158: my $checked = '';
2159: if ($option eq $curroption) {
2160: $checked = ' checked="checked"';
2161: } elsif ($option eq 'autolimit') {
2162: if ($curroption =~ /^autolimit/) {
2163: $checked = ' checked="checked"';
2164: }
2165: }
2166: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2167: '<input type="radio" name="crsreq_'.$item.
2168: '_default" value="'.$val.'"'.$checked.' />'.
2169: $titles{$option}.'</label>';
2170: if ($option eq 'autolimit') {
1.127 raeburn 2171: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2172: $item.'_limit_default" size="1" '.
2173: 'value="'.$currlimit.'" />';
2174: }
1.127 raeburn 2175: $defcell{$item} .= '</span> ';
1.104 raeburn 2176: if ($option eq 'autolimit') {
1.127 raeburn 2177: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2178: }
1.101 raeburn 2179: }
1.163 raeburn 2180: } elsif ($context eq 'requestauthor') {
2181: my $curroption;
2182: if (ref($settings) eq 'HASH') {
1.172 raeburn 2183: $curroption = $settings->{'default'};
1.163 raeburn 2184: }
2185: if (!$curroption) {
2186: $curroption = 'norequest';
2187: }
2188: foreach my $option (@options) {
2189: my $val = $option;
2190: if ($option eq 'norequest') {
2191: $val = 0;
2192: }
2193: my $checked = '';
2194: if ($option eq $curroption) {
2195: $checked = ' checked="checked"';
2196: }
2197: $datatable .= '<span class="LC_nobreak"><label>'.
2198: '<input type="radio" name="authorreq_default"'.
2199: ' value="'.$val.'"'.$checked.' />'.
2200: $titles{$option}.'</label></span> ';
2201: }
1.101 raeburn 2202: } else {
2203: my $checked = 'checked="checked" ';
2204: if (ref($settings) eq 'HASH') {
2205: if (ref($settings->{$item}) eq 'HASH') {
2206: if ($settings->{$item}->{'default'} == 0) {
2207: $checked = '';
2208: } elsif ($settings->{$item}->{'default'} == 1) {
2209: $checked = 'checked="checked" ';
2210: }
1.78 raeburn 2211: }
1.72 raeburn 2212: }
1.101 raeburn 2213: $datatable .= '<span class="LC_nobreak"><label>'.
2214: '<input type="checkbox" name="'.$context.'_'.$item.
2215: '" value="default" '.$checked.'/>'.$titles{$item}.
2216: '</label></span> ';
2217: }
2218: }
2219: if ($context eq 'requestcourses') {
2220: $datatable .= '</tr><tr>';
2221: foreach my $item (@usertools) {
1.106 raeburn 2222: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2223: }
1.101 raeburn 2224: $datatable .= '</tr></table>';
1.72 raeburn 2225: }
1.86 raeburn 2226: $datatable .= '</td>';
1.163 raeburn 2227: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2228: $datatable .= '<td class="LC_right_item">'.
2229: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2230: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2231: $defaultquota.'" size="5" /></span>'.(' ' x2).
2232: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2233: '<input type="text" name="authorquota" value="'.
2234: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2235: }
2236: $datatable .= '</tr>';
1.72 raeburn 2237: $typecount ++;
2238: $css_class = $typecount%2?' class="LC_odd_row"':'';
2239: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2240: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2241: if ($context eq 'requestcourses') {
1.109 raeburn 2242: $datatable .= &mt('(overrides affiliation, if set)').
2243: '</td>'.
2244: '<td class="LC_left_item">'.
2245: '<table><tr>';
1.101 raeburn 2246: } else {
1.109 raeburn 2247: $datatable .= &mt('(overrides affiliation, if checked)').
2248: '</td>'.
2249: '<td class="LC_left_item" colspan="2">'.
2250: '<br />';
1.101 raeburn 2251: }
2252: my %advcell;
1.72 raeburn 2253: foreach my $item (@usertools) {
1.101 raeburn 2254: if ($context eq 'requestcourses') {
2255: my ($curroption,$currlimit);
2256: if (ref($settings) eq 'HASH') {
2257: if (ref($settings->{$item}) eq 'HASH') {
2258: $curroption = $settings->{$item}->{'_LC_adv'};
2259: if ($curroption =~ /^autolimit=(\d*)$/) {
2260: $currlimit = $1;
2261: }
2262: }
2263: }
2264: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2265: my $checked = '';
2266: if ($curroption eq '') {
2267: $checked = ' checked="checked"';
2268: }
2269: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2270: '<input type="radio" name="crsreq_'.$item.
2271: '__LC_adv" value=""'.$checked.' />'.
2272: &mt('No override set').'</label></span> ';
1.101 raeburn 2273: foreach my $option (@options) {
2274: my $val = $option;
2275: if ($option eq 'norequest') {
2276: $val = 0;
2277: }
2278: if ($option eq 'validate') {
2279: my $canvalidate = 0;
2280: if (ref($validations{$item}) eq 'HASH') {
2281: if ($validations{$item}{'_LC_adv'}) {
2282: $canvalidate = 1;
2283: }
2284: }
2285: next if (!$canvalidate);
2286: }
2287: my $checked = '';
1.104 raeburn 2288: if ($val eq $curroption) {
1.101 raeburn 2289: $checked = ' checked="checked"';
2290: } elsif ($option eq 'autolimit') {
2291: if ($curroption =~ /^autolimit/) {
2292: $checked = ' checked="checked"';
2293: }
2294: }
2295: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2296: '<input type="radio" name="crsreq_'.$item.
2297: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2298: $titles{$option}.'</label>';
2299: if ($option eq 'autolimit') {
1.127 raeburn 2300: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2301: $item.'_limit__LC_adv" size="1" '.
2302: 'value="'.$currlimit.'" />';
2303: }
1.127 raeburn 2304: $advcell{$item} .= '</span> ';
1.104 raeburn 2305: if ($option eq 'autolimit') {
1.127 raeburn 2306: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2307: }
1.101 raeburn 2308: }
1.163 raeburn 2309: } elsif ($context eq 'requestauthor') {
2310: my $curroption;
2311: if (ref($settings) eq 'HASH') {
2312: $curroption = $settings->{'_LC_adv'};
2313: }
2314: my $checked = '';
2315: if ($curroption eq '') {
2316: $checked = ' checked="checked"';
2317: }
2318: $datatable .= '<span class="LC_nobreak"><label>'.
2319: '<input type="radio" name="authorreq__LC_adv"'.
2320: ' value=""'.$checked.' />'.
2321: &mt('No override set').'</label></span> ';
2322: foreach my $option (@options) {
2323: my $val = $option;
2324: if ($option eq 'norequest') {
2325: $val = 0;
2326: }
2327: my $checked = '';
2328: if ($val eq $curroption) {
2329: $checked = ' checked="checked"';
2330: }
2331: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2332: '<input type="radio" name="authorreq__LC_adv"'.
2333: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2334: $titles{$option}.'</label></span> ';
2335: }
1.101 raeburn 2336: } else {
2337: my $checked = 'checked="checked" ';
2338: if (ref($settings) eq 'HASH') {
2339: if (ref($settings->{$item}) eq 'HASH') {
2340: if ($settings->{$item}->{'_LC_adv'} == 0) {
2341: $checked = '';
2342: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2343: $checked = 'checked="checked" ';
2344: }
1.79 raeburn 2345: }
1.72 raeburn 2346: }
1.101 raeburn 2347: $datatable .= '<span class="LC_nobreak"><label>'.
2348: '<input type="checkbox" name="'.$context.'_'.$item.
2349: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2350: '</label></span> ';
2351: }
2352: }
2353: if ($context eq 'requestcourses') {
2354: $datatable .= '</tr><tr>';
2355: foreach my $item (@usertools) {
1.106 raeburn 2356: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2357: }
1.101 raeburn 2358: $datatable .= '</tr></table>';
1.72 raeburn 2359: }
1.98 raeburn 2360: $datatable .= '</td></tr>';
1.30 raeburn 2361: $$rowtotal += $typecount;
1.3 raeburn 2362: return $datatable;
2363: }
2364:
1.163 raeburn 2365: sub print_requestmail {
1.305 raeburn 2366: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2367: my ($now,$datatable,%currapp);
1.102 raeburn 2368: $now = time;
2369: if (ref($settings) eq 'HASH') {
2370: if (ref($settings->{'notify'}) eq 'HASH') {
2371: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2372: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2373: }
2374: }
2375: }
1.191 raeburn 2376: my $numinrow = 2;
1.224 raeburn 2377: my $css_class;
1.305 raeburn 2378: if ($$rowtotal%2) {
2379: $css_class = 'LC_odd_row';
2380: }
2381: if ($customcss) {
2382: $css_class .= " $customcss";
2383: }
2384: $css_class =~ s/^\s+//;
2385: if ($css_class) {
2386: $css_class = ' class="'.$css_class.'"';
2387: }
2388: if ($rowstyle) {
2389: $css_class .= ' style="'.$rowstyle.'"';
2390: }
1.163 raeburn 2391: my $text;
2392: if ($action eq 'requestcourses') {
2393: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2394: } elsif ($action eq 'requestauthor') {
2395: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2396: } else {
1.224 raeburn 2397: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2398: }
1.224 raeburn 2399: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2400: ' <td>'.$text.'</td>'.
1.102 raeburn 2401: ' <td class="LC_left_item">';
1.191 raeburn 2402: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2403: $action.'notifyapproval',%currapp);
1.191 raeburn 2404: if ($numdc > 0) {
2405: $datatable .= $table;
1.102 raeburn 2406: } else {
2407: $datatable .= &mt('There are no active Domain Coordinators');
2408: }
2409: $datatable .='</td></tr>';
2410: return $datatable;
2411: }
2412:
1.216 raeburn 2413: sub print_studentcode {
2414: my ($settings,$rowtotal) = @_;
2415: my $rownum = 0;
1.218 raeburn 2416: my ($output,%current);
1.325 raeburn 2417: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2418: if (ref($settings) eq 'HASH') {
2419: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2420: foreach my $type (@crstypes) {
2421: $current{$type} = $settings->{'uniquecode'}{$type};
2422: }
1.218 raeburn 2423: }
2424: }
2425: $output .= '<tr>'.
2426: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2427: '<td class="LC_left_item">';
2428: foreach my $type (@crstypes) {
2429: my $check = ' ';
2430: if ($current{$type}) {
2431: $check = ' checked="checked" ';
2432: }
2433: $output .= '<span class="LC_nobreak"><label>'.
2434: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2435: &mt($type).'</label></span>'.(' 'x2).' ';
2436: }
2437: $output .= '</td></tr>';
2438: $$rowtotal ++;
2439: return $output;
1.216 raeburn 2440: }
2441:
2442: sub print_textbookcourses {
1.242 raeburn 2443: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2444: my $rownum = 0;
2445: my $css_class;
2446: my $itemcount = 1;
2447: my $maxnum = 0;
2448: my $bookshash;
2449: if (ref($settings) eq 'HASH') {
1.242 raeburn 2450: $bookshash = $settings->{$type};
1.216 raeburn 2451: }
2452: my %ordered;
2453: if (ref($bookshash) eq 'HASH') {
2454: foreach my $item (keys(%{$bookshash})) {
2455: if (ref($bookshash->{$item}) eq 'HASH') {
2456: my $num = $bookshash->{$item}{'order'};
2457: $ordered{$num} = $item;
2458: }
2459: }
2460: }
2461: my $confname = $dom.'-domainconfig';
2462: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2463: my $maxnum = scalar(keys(%ordered));
2464: my $datatable;
1.216 raeburn 2465: if (keys(%ordered)) {
2466: my @items = sort { $a <=> $b } keys(%ordered);
2467: for (my $i=0; $i<@items; $i++) {
2468: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2469: my $key = $ordered{$items[$i]};
2470: my %coursehash=&Apache::lonnet::coursedescription($key);
2471: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2472: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2473: if (ref($bookshash->{$key}) eq 'HASH') {
2474: $subject = $bookshash->{$key}->{'subject'};
2475: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2476: if ($type eq 'textbooks') {
1.243 raeburn 2477: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2478: $author = $bookshash->{$key}->{'author'};
2479: $image = $bookshash->{$key}->{'image'};
2480: if ($image ne '') {
2481: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2482: my $imagethumb = "$path/tn-".$imagefile;
2483: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2484: }
1.216 raeburn 2485: }
2486: }
1.242 raeburn 2487: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2488: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2489: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2490: for (my $k=0; $k<=$maxnum; $k++) {
2491: my $vpos = $k+1;
2492: my $selstr;
2493: if ($k == $i) {
2494: $selstr = ' selected="selected" ';
2495: }
2496: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2497: }
2498: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2499: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2500: &mt('Delete?').'</label></span></td>'.
2501: '<td colspan="2">'.
1.242 raeburn 2502: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2503: (' 'x2).
1.242 raeburn 2504: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2505: if ($type eq 'textbooks') {
2506: $datatable .= (' 'x2).
1.243 raeburn 2507: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2508: (' 'x2).
1.242 raeburn 2509: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2510: (' 'x2).
2511: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2512: if ($image) {
1.267 raeburn 2513: $datatable .= $imgsrc.
1.242 raeburn 2514: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2515: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2516: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2517: }
2518: if ($switchserver) {
2519: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2520: } else {
2521: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2522: }
1.216 raeburn 2523: }
1.242 raeburn 2524: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2525: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2526: $coursetitle.'</span></td></tr>'."\n";
2527: $itemcount ++;
2528: }
2529: }
2530: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2531: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2532: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2533: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2534: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2535: for (my $k=0; $k<$maxnum+1; $k++) {
2536: my $vpos = $k+1;
2537: my $selstr;
2538: if ($k == $maxnum) {
2539: $selstr = ' selected="selected" ';
2540: }
2541: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2542: }
2543: $datatable .= '</select> '."\n".
1.334 raeburn 2544: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 2545: '<td colspan="2">'.
1.242 raeburn 2546: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2547: (' 'x2).
1.242 raeburn 2548: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2549: (' 'x2);
2550: if ($type eq 'textbooks') {
1.243 raeburn 2551: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2552: (' 'x2).
2553: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2554: (' 'x2).
2555: '<span class="LC_nobreak">'.&mt('Image:').' ';
2556: if ($switchserver) {
2557: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2558: } else {
2559: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2560: }
1.334 raeburn 2561: $datatable .= '</span>'."\n";
1.216 raeburn 2562: }
1.334 raeburn 2563: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2564: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2565: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2566: &Apache::loncommon::selectcourse_link
1.334 raeburn 2567: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 2568: '</span></td>'."\n".
2569: '</tr>'."\n";
2570: $itemcount ++;
2571: return $datatable;
2572: }
2573:
1.217 raeburn 2574: sub textbookcourses_javascript {
1.242 raeburn 2575: my ($settings) = @_;
2576: return unless(ref($settings) eq 'HASH');
2577: my (%ordered,%total,%jstext);
2578: foreach my $type ('textbooks','templates') {
2579: $total{$type} = 0;
2580: if (ref($settings->{$type}) eq 'HASH') {
2581: foreach my $item (keys(%{$settings->{$type}})) {
2582: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2583: my $num = $settings->{$type}->{$item}{'order'};
2584: $ordered{$type}{$num} = $item;
2585: }
2586: }
2587: $total{$type} = scalar(keys(%{$settings->{$type}}));
2588: }
2589: my @jsarray = ();
2590: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2591: push(@jsarray,$ordered{$type}{$item});
2592: }
2593: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2594: }
2595: return <<"ENDSCRIPT";
2596: <script type="text/javascript">
2597: // <![CDATA[
1.242 raeburn 2598: function reorderBooks(form,item,caller) {
1.217 raeburn 2599: var changedVal;
1.242 raeburn 2600: $jstext{'textbooks'};
2601: $jstext{'templates'};
2602: var newpos;
2603: var maxh;
2604: if (caller == 'textbooks') {
2605: newpos = 'textbooks_addbook_pos';
2606: maxh = 1 + $total{'textbooks'};
2607: } else {
2608: newpos = 'templates_addbook_pos';
2609: maxh = 1 + $total{'templates'};
2610: }
1.217 raeburn 2611: var current = new Array;
2612: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2613: if (item == newpos) {
2614: changedVal = newitemVal;
2615: } else {
2616: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2617: current[newitemVal] = newpos;
2618: }
1.242 raeburn 2619: if (caller == 'textbooks') {
2620: for (var i=0; i<textbooks.length; i++) {
2621: var elementName = 'textbooks_'+textbooks[i];
2622: if (elementName != item) {
2623: if (form.elements[elementName]) {
2624: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2625: current[currVal] = elementName;
2626: }
2627: }
2628: }
2629: }
2630: if (caller == 'templates') {
2631: for (var i=0; i<templates.length; i++) {
2632: var elementName = 'templates_'+templates[i];
2633: if (elementName != item) {
2634: if (form.elements[elementName]) {
2635: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2636: current[currVal] = elementName;
2637: }
1.217 raeburn 2638: }
2639: }
2640: }
2641: var oldVal;
2642: for (var j=0; j<maxh; j++) {
2643: if (current[j] == undefined) {
2644: oldVal = j;
2645: }
2646: }
2647: if (oldVal < changedVal) {
2648: for (var k=oldVal+1; k<=changedVal ; k++) {
2649: var elementName = current[k];
2650: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2651: }
2652: } else {
2653: for (var k=changedVal; k<oldVal; k++) {
2654: var elementName = current[k];
2655: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2656: }
2657: }
2658: return;
2659: }
2660:
2661: // ]]>
2662: </script>
2663:
2664: ENDSCRIPT
2665: }
2666:
1.267 raeburn 2667: sub ltitools_javascript {
2668: my ($settings) = @_;
1.319 raeburn 2669: my $togglejs = <itools_toggle_js();
2670: unless (ref($settings) eq 'HASH') {
2671: return $togglejs;
2672: }
1.267 raeburn 2673: my (%ordered,$total,%jstext);
2674: $total = 0;
2675: foreach my $item (keys(%{$settings})) {
2676: if (ref($settings->{$item}) eq 'HASH') {
2677: my $num = $settings->{$item}{'order'};
2678: $ordered{$num} = $item;
2679: }
2680: }
2681: $total = scalar(keys(%{$settings}));
2682: my @jsarray = ();
2683: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2684: push(@jsarray,$ordered{$item});
2685: }
2686: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2687: return <<"ENDSCRIPT";
2688: <script type="text/javascript">
2689: // <![CDATA[
1.319 raeburn 2690: function reorderLTITools(form,item) {
1.267 raeburn 2691: var changedVal;
2692: $jstext
2693: var newpos = 'ltitools_add_pos';
2694: var maxh = 1 + $total;
2695: var current = new Array;
2696: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2697: if (item == newpos) {
2698: changedVal = newitemVal;
2699: } else {
2700: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2701: current[newitemVal] = newpos;
2702: }
2703: for (var i=0; i<ltitools.length; i++) {
2704: var elementName = 'ltitools_'+ltitools[i];
2705: if (elementName != item) {
2706: if (form.elements[elementName]) {
2707: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2708: current[currVal] = elementName;
2709: }
2710: }
2711: }
2712: var oldVal;
2713: for (var j=0; j<maxh; j++) {
2714: if (current[j] == undefined) {
2715: oldVal = j;
2716: }
2717: }
2718: if (oldVal < changedVal) {
2719: for (var k=oldVal+1; k<=changedVal ; k++) {
2720: var elementName = current[k];
2721: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2722: }
2723: } else {
2724: for (var k=changedVal; k<oldVal; k++) {
2725: var elementName = current[k];
2726: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2727: }
2728: }
2729: return;
2730: }
2731:
2732: // ]]>
2733: </script>
2734:
1.319 raeburn 2735: $togglejs
2736:
2737: ENDSCRIPT
2738: }
2739:
2740: sub ltitools_toggle_js {
2741: return <<"ENDSCRIPT";
2742: <script type="text/javascript">
2743: // <![CDATA[
2744:
2745: function toggleLTITools(form,setting,item) {
2746: var radioname = '';
2747: var divid = '';
2748: if ((setting == 'passback') || (setting == 'roster')) {
2749: radioname = 'ltitools_'+setting+'_'+item;
2750: divid = 'ltitools_'+setting+'time_'+item;
2751: var num = form.elements[radioname].length;
2752: if (num) {
2753: var setvis = '';
2754: for (var i=0; i<num; i++) {
2755: if (form.elements[radioname][i].checked) {
2756: if (form.elements[radioname][i].value == '1') {
2757: if (document.getElementById(divid)) {
2758: document.getElementById(divid).style.display = 'inline-block';
2759: }
2760: setvis = 1;
2761: }
2762: break;
2763: }
2764: }
2765: }
2766: if (!setvis) {
2767: if (document.getElementById(divid)) {
2768: document.getElementById(divid).style.display = 'none';
2769: }
2770: }
2771: }
1.324 raeburn 2772: if (setting == 'user') {
2773: divid = 'ltitools_'+setting+'_div_'+item;
2774: var checkid = 'ltitools_'+setting+'_field_'+item;
2775: if (document.getElementById(divid)) {
2776: if (document.getElementById(checkid)) {
2777: if (document.getElementById(checkid).checked) {
2778: document.getElementById(divid).style.display = 'inline-block';
2779: } else {
2780: document.getElementById(divid).style.display = 'none';
2781: }
2782: }
2783: }
2784: }
1.319 raeburn 2785: return;
2786: }
2787: // ]]>
2788: </script>
2789:
1.267 raeburn 2790: ENDSCRIPT
2791: }
2792:
1.320 raeburn 2793: sub lti_javascript {
2794: my ($settings) = @_;
2795: my $togglejs = <i_toggle_js();
2796: unless (ref($settings) eq 'HASH') {
2797: return $togglejs;
2798: }
2799: my (%ordered,$total,%jstext);
2800: $total = 0;
2801: foreach my $item (keys(%{$settings})) {
2802: if (ref($settings->{$item}) eq 'HASH') {
2803: my $num = $settings->{$item}{'order'};
2804: $ordered{$num} = $item;
2805: }
2806: }
2807: $total = scalar(keys(%{$settings}));
2808: my @jsarray = ();
2809: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2810: push(@jsarray,$ordered{$item});
2811: }
2812: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
2813: return <<"ENDSCRIPT";
2814: <script type="text/javascript">
2815: // <![CDATA[
2816: function reorderLTI(form,item) {
2817: var changedVal;
2818: $jstext
2819: var newpos = 'lti_pos_add';
2820: var maxh = 1 + $total;
2821: var current = new Array;
2822: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2823: if (item == newpos) {
2824: changedVal = newitemVal;
2825: } else {
2826: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2827: current[newitemVal] = newpos;
2828: }
2829: for (var i=0; i<lti.length; i++) {
2830: var elementName = 'lti_pos_'+lti[i];
2831: if (elementName != item) {
2832: if (form.elements[elementName]) {
2833: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2834: current[currVal] = elementName;
2835: }
2836: }
2837: }
2838: var oldVal;
2839: for (var j=0; j<maxh; j++) {
2840: if (current[j] == undefined) {
2841: oldVal = j;
2842: }
2843: }
2844: if (oldVal < changedVal) {
2845: for (var k=oldVal+1; k<=changedVal ; k++) {
2846: var elementName = current[k];
2847: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2848: }
2849: } else {
2850: for (var k=changedVal; k<oldVal; k++) {
2851: var elementName = current[k];
2852: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2853: }
2854: }
2855: return;
2856: }
2857: // ]]>
2858: </script>
2859:
2860: $togglejs
2861:
2862: ENDSCRIPT
2863: }
2864:
2865: sub lti_toggle_js {
1.325 raeburn 2866: my %lcauthparmtext = &Apache::lonlocal::texthash (
2867: localauth => 'Local auth argument',
2868: krb => 'Kerberos domain',
2869: );
1.320 raeburn 2870: return <<"ENDSCRIPT";
2871: <script type="text/javascript">
2872: // <![CDATA[
2873:
2874: function toggleLTI(form,setting,item) {
1.345 raeburn 2875: if (setting == 'requser') {
2876: var fieldsets = document.getElementsByClassName('ltioption_'+item);
2877: if (fieldsets.length) {
2878: var radioname = 'lti_'+setting+'_'+item;
2879: var num = form.elements[radioname].length;
2880: if (num) {
2881: var setvis = '';
2882: for (var i=0; i<num; i++) {
2883: if (form.elements[radioname][i].checked) {
2884: if (form.elements[radioname][i].value == '1') {
2885: setvis = 1;
2886: break;
2887: }
2888: }
2889: }
1.352 raeburn 2890: for (var j=0; j<fieldsets.length; j++) {
1.345 raeburn 2891: if (setvis) {
2892: fieldsets[j].style.display = 'block';
2893: } else {
2894: fieldsets[j].style.display = 'none';
2895: }
2896: }
2897: }
2898: }
2899: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback')) {
1.320 raeburn 2900: var radioname = '';
2901: var divid = '';
2902: if (setting == 'user') {
2903: radioname = 'lti_mapuser_'+item;
2904: divid = 'lti_userfield_'+item;
1.343 raeburn 2905: } else if (setting == 'crs') {
1.320 raeburn 2906: radioname = 'lti_mapcrs_'+item;
2907: divid = 'lti_crsfield_'+item;
1.337 raeburn 2908: } else {
1.351 raeburn 2909: radioname = 'lti_passback_'+item;
1.337 raeburn 2910: divid = 'lti_passback_'+item;
1.320 raeburn 2911: }
2912: var num = form.elements[radioname].length;
2913: if (num) {
2914: var setvis = '';
2915: for (var i=0; i<num; i++) {
2916: if (form.elements[radioname][i].checked) {
1.337 raeburn 2917: if (setting == 'passback') {
2918: if (form.elements[radioname][i].value == '1') {
2919: if (document.getElementById(divid)) {
2920: document.getElementById(divid).style.display = 'inline-block';
2921: }
2922: setvis = 1;
2923: break;
2924: }
2925: } else {
2926: if (form.elements[radioname][i].value == 'other') {
2927: if (document.getElementById(divid)) {
2928: document.getElementById(divid).style.display = 'inline-block';
2929: }
2930: setvis = 1;
2931: break;
1.320 raeburn 2932: }
2933: }
2934: }
2935: }
2936: if (!setvis) {
2937: if (document.getElementById(divid)) {
2938: document.getElementById(divid).style.display = 'none';
2939: }
2940: }
2941: }
2942: } else if ((setting == 'sec') || (setting == 'secsrc')) {
2943: var numsec = form.elements['lti_crssec_'+item].length;
2944: if (numsec) {
2945: var setvis = '';
2946: for (var i=0; i<numsec; i++) {
2947: if (form.elements['lti_crssec_'+item][i].checked) {
2948: if (form.elements['lti_crssec_'+item][i].value == '1') {
2949: if (document.getElementById('lti_crssecfield_'+item)) {
2950: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
2951: setvis = 1;
2952: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
2953: if (numsrcsec) {
2954: var setsrcvis = '';
2955: for (var j=0; j<numsrcsec; j++) {
2956: if (form.elements['lti_crssecsrc_'+item][j].checked) {
2957: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
2958: if (document.getElementById('lti_secsrcfield_'+item)) {
2959: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
2960: setsrcvis = 1;
2961: }
2962: }
2963: }
2964: }
2965: if (!setsrcvis) {
2966: if (document.getElementById('lti_secsrcfield_'+item)) {
2967: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
2968: }
2969: }
2970: }
2971: }
2972: }
2973: }
2974: }
2975: if (!setvis) {
2976: if (document.getElementById('lti_crssecfield_'+item)) {
2977: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
2978: }
2979: if (document.getElementById('lti_secsrcfield_'+item)) {
2980: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
2981: }
2982: }
2983: }
1.325 raeburn 2984: } else if (setting == 'lcauth') {
2985: var numauth = form.elements['lti_lcauth_'+item].length;
2986: if (numauth) {
2987: for (var i=0; i<numauth; i++) {
2988: if (form.elements['lti_lcauth_'+item][i].checked) {
2989: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
2990: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
2991: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
2992: } else {
2993: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
2994: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
2995: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
2996: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
2997: } else {
2998: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
2999: }
3000: }
3001: }
3002: }
3003: }
3004: }
3005: }
1.326 raeburn 3006: } else if (setting == 'lcmenu') {
3007: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3008: var divid = 'lti_menufield_'+item;
3009: var setvis = '';
3010: for (var i=0; i<menus.length; i++) {
3011: var radioname = menus[i];
3012: var num = form.elements[radioname].length;
3013: if (num) {
3014: for (var j=0; j<num; j++) {
3015: if (form.elements[radioname][j].checked) {
3016: if (form.elements[radioname][j].value == '1') {
3017: if (document.getElementById(divid)) {
3018: document.getElementById(divid).style.display = 'inline-block';
3019: }
3020: setvis = 1;
3021: break;
3022: }
3023: }
3024: }
3025: }
3026: if (setvis == 1) {
3027: break;
3028: }
3029: }
3030: if (!setvis) {
3031: if (document.getElementById(divid)) {
3032: document.getElementById(divid).style.display = 'none';
3033: }
3034: }
1.320 raeburn 3035: }
3036: return;
3037: }
3038: // ]]>
3039: </script>
3040:
3041: ENDSCRIPT
3042: }
3043:
1.3 raeburn 3044: sub print_autoenroll {
1.30 raeburn 3045: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3046: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 3047: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 3048: if (ref($settings) eq 'HASH') {
3049: if (exists($settings->{'run'})) {
3050: if ($settings->{'run'} eq '0') {
3051: $runoff = ' checked="checked" ';
3052: $runon = ' ';
3053: } else {
3054: $runon = ' checked="checked" ';
3055: $runoff = ' ';
3056: }
3057: } else {
3058: if ($autorun) {
3059: $runon = ' checked="checked" ';
3060: $runoff = ' ';
3061: } else {
3062: $runoff = ' checked="checked" ';
3063: $runon = ' ';
3064: }
3065: }
1.129 raeburn 3066: if (exists($settings->{'co-owners'})) {
3067: if ($settings->{'co-owners'} eq '0') {
3068: $coownersoff = ' checked="checked" ';
3069: $coownerson = ' ';
3070: } else {
3071: $coownerson = ' checked="checked" ';
3072: $coownersoff = ' ';
3073: }
3074: } else {
3075: $coownersoff = ' checked="checked" ';
3076: $coownerson = ' ';
3077: }
1.3 raeburn 3078: if (exists($settings->{'sender_domain'})) {
3079: $defdom = $settings->{'sender_domain'};
3080: }
1.274 raeburn 3081: if (exists($settings->{'autofailsafe'})) {
3082: $failsafe = $settings->{'autofailsafe'};
3083: }
1.14 raeburn 3084: } else {
3085: if ($autorun) {
3086: $runon = ' checked="checked" ';
3087: $runoff = ' ';
3088: } else {
3089: $runoff = ' checked="checked" ';
3090: $runon = ' ';
3091: }
1.3 raeburn 3092: }
3093: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3094: my $notif_sender;
3095: if (ref($settings) eq 'HASH') {
3096: $notif_sender = $settings->{'sender_uname'};
3097: }
1.3 raeburn 3098: my $datatable='<tr class="LC_odd_row">'.
3099: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3100: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3101: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3102: $runon.' value="1" />'.&mt('Yes').'</label> '.
3103: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3104: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3105: '</tr><tr>'.
3106: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3107: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3108: &mt('username').': '.
3109: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3110: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3111: ': '.$domform.'</span></td></tr>'.
3112: '<tr class="LC_odd_row">'.
3113: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3114: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3115: '<input type="radio" name="autoassign_coowners"'.
3116: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3117: '<label><input type="radio" name="autoassign_coowners"'.
3118: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 3119: '</tr><tr>'.
3120: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
3121: '<td class="LC_right_item"><span class="LC_nobreak">'.
3122: '<input type="text" name="autoenroll_failsafe"'.
1.333 raeburn 3123: ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.274 raeburn 3124: $$rowtotal += 4;
1.3 raeburn 3125: return $datatable;
3126: }
3127:
3128: sub print_autoupdate {
1.30 raeburn 3129: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 3130: my $datatable;
3131: if ($position eq 'top') {
3132: my $updateon = ' ';
3133: my $updateoff = ' checked="checked" ';
3134: my $classlistson = ' ';
3135: my $classlistsoff = ' checked="checked" ';
3136: if (ref($settings) eq 'HASH') {
3137: if ($settings->{'run'} eq '1') {
3138: $updateon = $updateoff;
3139: $updateoff = ' ';
3140: }
3141: if ($settings->{'classlists'} eq '1') {
3142: $classlistson = $classlistsoff;
3143: $classlistsoff = ' ';
3144: }
3145: }
3146: my %title = (
3147: run => 'Auto-update active?',
3148: classlists => 'Update information in classlists?',
3149: );
3150: $datatable = '<tr class="LC_odd_row">'.
3151: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 3152: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3153: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 3154: $updateon.' value="1" />'.&mt('Yes').'</label> '.
3155: '<label><input type="radio" name="autoupdate_run"'.
3156: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3157: '</tr><tr>'.
3158: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 3159: '<td class="LC_right_item"><span class="LC_nobreak">'.
3160: '<label><input type="radio" name="classlists"'.
3161: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
3162: '<label><input type="radio" name="classlists"'.
3163: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3164: '</tr>';
1.30 raeburn 3165: $$rowtotal += 2;
1.131 raeburn 3166: } elsif ($position eq 'middle') {
3167: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3168: my $numinrow = 3;
3169: my $locknamesettings;
3170: $datatable .= &insttypes_row($settings,$types,$usertypes,
3171: $dom,$numinrow,$othertitle,
1.305 raeburn 3172: 'lockablenames',$rowtotal);
1.131 raeburn 3173: $$rowtotal ++;
1.3 raeburn 3174: } else {
1.44 raeburn 3175: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3176: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3177: 'permanentemail','id');
1.33 raeburn 3178: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3179: my $numrows = 0;
1.26 raeburn 3180: if (ref($types) eq 'ARRAY') {
3181: if (@{$types} > 0) {
3182: $datatable =
3183: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3184: \@fields,$types,\$numrows);
1.30 raeburn 3185: $$rowtotal += @{$types};
1.26 raeburn 3186: }
1.3 raeburn 3187: }
3188: $datatable .=
3189: &usertype_update_row($settings,{'default' => $othertitle},
3190: \%fieldtitles,\@fields,['default'],
3191: \$numrows);
1.30 raeburn 3192: $$rowtotal ++;
1.3 raeburn 3193: }
3194: return $datatable;
3195: }
3196:
1.125 raeburn 3197: sub print_autocreate {
3198: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 3199: my (%createon,%createoff,%currhash);
1.125 raeburn 3200: my @types = ('xml','req');
3201: if (ref($settings) eq 'HASH') {
3202: foreach my $item (@types) {
3203: $createoff{$item} = ' checked="checked" ';
3204: $createon{$item} = ' ';
3205: if (exists($settings->{$item})) {
3206: if ($settings->{$item}) {
3207: $createon{$item} = ' checked="checked" ';
3208: $createoff{$item} = ' ';
3209: }
3210: }
3211: }
1.210 raeburn 3212: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 3213: $currhash{$settings->{'xmldc'}} = 1;
3214: }
1.125 raeburn 3215: } else {
3216: foreach my $item (@types) {
3217: $createoff{$item} = ' checked="checked" ';
3218: $createon{$item} = ' ';
3219: }
3220: }
3221: $$rowtotal += 2;
1.191 raeburn 3222: my $numinrow = 2;
1.125 raeburn 3223: my $datatable='<tr class="LC_odd_row">'.
3224: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3225: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3226: '<input type="radio" name="autocreate_xml"'.
3227: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3228: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3229: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3230: '</td></tr><tr>'.
3231: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3232: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3233: '<input type="radio" name="autocreate_req"'.
3234: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3235: '<label><input type="radio" name="autocreate_req"'.
3236: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 3237: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3238: 'autocreate_xmldc',%currhash);
1.247 raeburn 3239: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3240: if ($numdc > 1) {
1.247 raeburn 3241: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3242: '</td><td class="LC_left_item">';
1.125 raeburn 3243: } else {
1.247 raeburn 3244: $datatable .= &mt('Course creation processed as:').
3245: '</td><td class="LC_right_item">';
1.125 raeburn 3246: }
1.247 raeburn 3247: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 3248: $$rowtotal += $rows;
1.125 raeburn 3249: return $datatable;
3250: }
3251:
1.23 raeburn 3252: sub print_directorysrch {
1.277 raeburn 3253: my ($position,$dom,$settings,$rowtotal) = @_;
3254: my $datatable;
3255: if ($position eq 'top') {
3256: my $instsrchon = ' ';
3257: my $instsrchoff = ' checked="checked" ';
3258: my ($exacton,$containson,$beginson);
3259: my $instlocalon = ' ';
3260: my $instlocaloff = ' checked="checked" ';
3261: if (ref($settings) eq 'HASH') {
3262: if ($settings->{'available'} eq '1') {
3263: $instsrchon = $instsrchoff;
3264: $instsrchoff = ' ';
3265: }
3266: if ($settings->{'localonly'} eq '1') {
3267: $instlocalon = $instlocaloff;
3268: $instlocaloff = ' ';
3269: }
3270: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3271: foreach my $type (@{$settings->{'searchtypes'}}) {
3272: if ($type eq 'exact') {
3273: $exacton = ' checked="checked" ';
3274: } elsif ($type eq 'contains') {
3275: $containson = ' checked="checked" ';
3276: } elsif ($type eq 'begins') {
3277: $beginson = ' checked="checked" ';
3278: }
3279: }
3280: } else {
3281: if ($settings->{'searchtypes'} eq 'exact') {
3282: $exacton = ' checked="checked" ';
3283: } elsif ($settings->{'searchtypes'} eq 'contains') {
3284: $containson = ' checked="checked" ';
3285: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 3286: $exacton = ' checked="checked" ';
3287: $containson = ' checked="checked" ';
3288: }
3289: }
1.277 raeburn 3290: }
3291: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3292: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3293:
3294: my $numinrow = 4;
3295: my $cansrchrow = 0;
3296: $datatable='<tr class="LC_odd_row">'.
3297: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3298: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3299: '<input type="radio" name="dirsrch_available"'.
3300: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3301: '<label><input type="radio" name="dirsrch_available"'.
3302: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3303: '</tr><tr>'.
3304: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3305: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3306: '<input type="radio" name="dirsrch_instlocalonly"'.
3307: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3308: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3309: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3310: '</tr>';
3311: $$rowtotal += 2;
3312: if (ref($usertypes) eq 'HASH') {
3313: if (keys(%{$usertypes}) > 0) {
3314: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 3315: $numinrow,$othertitle,'cansearch',
3316: $rowtotal);
1.277 raeburn 3317: $cansrchrow = 1;
1.25 raeburn 3318: }
1.23 raeburn 3319: }
1.277 raeburn 3320: if ($cansrchrow) {
3321: $$rowtotal ++;
3322: $datatable .= '<tr>';
3323: } else {
3324: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 3325: }
1.277 raeburn 3326: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3327: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3328: foreach my $title (@{$titleorder}) {
3329: if (defined($searchtitles->{$title})) {
3330: my $check = ' ';
3331: if (ref($settings) eq 'HASH') {
3332: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3333: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3334: $check = ' checked="checked" ';
3335: }
1.39 raeburn 3336: }
1.25 raeburn 3337: }
1.277 raeburn 3338: $datatable .= '<td class="LC_left_item">'.
3339: '<span class="LC_nobreak"><label>'.
3340: '<input type="checkbox" name="searchby" '.
3341: 'value="'.$title.'"'.$check.'/>'.
3342: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 3343: }
3344: }
1.277 raeburn 3345: $datatable .= '</tr></table></td></tr>';
3346: $$rowtotal ++;
3347: if ($cansrchrow) {
3348: $datatable .= '<tr class="LC_odd_row">';
3349: } else {
3350: $datatable .= '<tr>';
3351: }
3352: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3353: '<td class="LC_left_item" colspan="2">'.
3354: '<span class="LC_nobreak"><label>'.
3355: '<input type="checkbox" name="searchtypes" '.
3356: $exacton.' value="exact" />'.&mt('Exact match').
3357: '</label> '.
3358: '<label><input type="checkbox" name="searchtypes" '.
3359: $beginson.' value="begins" />'.&mt('Begins with').
3360: '</label> '.
3361: '<label><input type="checkbox" name="searchtypes" '.
3362: $containson.' value="contains" />'.&mt('Contains').
3363: '</label></span></td></tr>';
3364: $$rowtotal ++;
1.26 raeburn 3365: } else {
1.277 raeburn 3366: my $domsrchon = ' checked="checked" ';
3367: my $domsrchoff = ' ';
3368: my $domlocalon = ' ';
3369: my $domlocaloff = ' checked="checked" ';
3370: if (ref($settings) eq 'HASH') {
3371: if ($settings->{'lclocalonly'} eq '1') {
3372: $domlocalon = $domlocaloff;
3373: $domlocaloff = ' ';
3374: }
3375: if ($settings->{'lcavailable'} eq '0') {
3376: $domsrchoff = $domsrchon;
3377: $domsrchon = ' ';
3378: }
3379: }
3380: $datatable='<tr class="LC_odd_row">'.
3381: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3382: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3383: '<input type="radio" name="dirsrch_domavailable"'.
3384: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3385: '<label><input type="radio" name="dirsrch_domavailable"'.
3386: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3387: '</tr><tr>'.
3388: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3389: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3390: '<input type="radio" name="dirsrch_domlocalonly"'.
3391: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3392: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3393: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3394: '</tr>';
3395: $$rowtotal += 2;
1.26 raeburn 3396: }
1.25 raeburn 3397: return $datatable;
3398: }
3399:
1.28 raeburn 3400: sub print_contacts {
1.286 raeburn 3401: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3402: my $datatable;
3403: my @contacts = ('adminemail','supportemail');
1.286 raeburn 3404: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 3405: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 3406: if ($position eq 'top') {
3407: if (ref($settings) eq 'HASH') {
3408: foreach my $item (@contacts) {
3409: if (exists($settings->{$item})) {
3410: $to{$item} = $settings->{$item};
3411: }
3412: }
3413: }
3414: } elsif ($position eq 'middle') {
3415: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 3416: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 3417: foreach my $type (@mailings) {
3418: $otheremails{$type} = '';
3419: }
1.340 raeburn 3420: } elsif ($position eq 'lower') {
3421: if (ref($settings) eq 'HASH') {
3422: if (ref($settings->{'lonstatus'}) eq 'HASH') {
3423: %lonstatus = %{$settings->{'lonstatus'}};
3424: }
3425: }
1.286 raeburn 3426: } else {
3427: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 3428: foreach my $type (@mailings) {
3429: $otheremails{$type} = '';
3430: }
1.286 raeburn 3431: $bccemails{'helpdeskmail'} = '';
3432: $bccemails{'otherdomsmail'} = '';
3433: $includestr{'helpdeskmail'} = '';
3434: $includestr{'otherdomsmail'} = '';
3435: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3436: }
1.28 raeburn 3437: if (ref($settings) eq 'HASH') {
1.340 raeburn 3438: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 3439: foreach my $type (@mailings) {
3440: if (exists($settings->{$type})) {
3441: if (ref($settings->{$type}) eq 'HASH') {
3442: foreach my $item (@contacts) {
3443: if ($settings->{$type}{$item}) {
3444: $checked{$type}{$item} = ' checked="checked" ';
3445: }
3446: }
3447: $otheremails{$type} = $settings->{$type}{'others'};
3448: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3449: $bccemails{$type} = $settings->{$type}{'bcc'};
3450: if ($settings->{$type}{'include'} ne '') {
3451: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3452: $includestr{$type} = &unescape($includestr{$type});
3453: }
3454: }
3455: }
3456: } elsif ($type eq 'lonstatusmail') {
3457: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3458: }
1.28 raeburn 3459: }
3460: }
1.286 raeburn 3461: if ($position eq 'bottom') {
3462: foreach my $type (@mailings) {
3463: $bccemails{$type} = $settings->{$type}{'bcc'};
3464: if ($settings->{$type}{'include'} ne '') {
3465: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3466: $includestr{$type} = &unescape($includestr{$type});
3467: }
3468: }
3469: if (ref($settings->{'helpform'}) eq 'HASH') {
3470: if (ref($fields) eq 'ARRAY') {
3471: foreach my $field (@{$fields}) {
3472: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3473: }
1.286 raeburn 3474: }
3475: if (exists($settings->{'helpform'}{'maxsize'})) {
3476: $maxsize = $settings->{'helpform'}{'maxsize'};
3477: } else {
1.289 raeburn 3478: $maxsize = '1.0';
1.286 raeburn 3479: }
3480: } else {
3481: if (ref($fields) eq 'ARRAY') {
3482: foreach my $field (@{$fields}) {
3483: $currfield{$field} = 'yes';
1.134 raeburn 3484: }
1.28 raeburn 3485: }
1.286 raeburn 3486: $maxsize = '1.0';
1.28 raeburn 3487: }
3488: }
3489: } else {
1.286 raeburn 3490: if ($position eq 'top') {
3491: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3492: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3493: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3494: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 3495: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3496: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3497: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3498: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 3499: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3500: } elsif ($position eq 'bottom') {
3501: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3502: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3503: if (ref($fields) eq 'ARRAY') {
3504: foreach my $field (@{$fields}) {
3505: $currfield{$field} = 'yes';
3506: }
3507: }
3508: $maxsize = '1.0';
3509: }
1.28 raeburn 3510: }
3511: my ($titles,$short_titles) = &contact_titles();
3512: my $rownum = 0;
3513: my $css_class;
1.286 raeburn 3514: if ($position eq 'top') {
3515: foreach my $item (@contacts) {
3516: $css_class = $rownum%2?' class="LC_odd_row"':'';
3517: $datatable .= '<tr'.$css_class.'>'.
3518: '<td><span class="LC_nobreak">'.$titles->{$item}.
3519: '</span></td><td class="LC_right_item">'.
3520: '<input type="text" name="'.$item.'" value="'.
3521: $to{$item}.'" /></td></tr>';
3522: $rownum ++;
3523: }
1.315 raeburn 3524: } elsif ($position eq 'bottom') {
3525: $css_class = $rownum%2?' class="LC_odd_row"':'';
3526: $datatable .= '<tr'.$css_class.'>'.
3527: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3528: &mt('(e-mail, subject, and description always shown)').
3529: '</td><td class="LC_left_item">';
3530: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3531: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3532: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3533: foreach my $field (@{$fields}) {
3534: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3535: if (($field eq 'screenshot') || ($field eq 'cc')) {
3536: $datatable .= ' '.&mt('(logged-in users)');
3537: }
3538: $datatable .='</td><td>';
3539: my $clickaction;
3540: if ($field eq 'screenshot') {
3541: $clickaction = ' onclick="screenshotSize(this);"';
3542: }
3543: if (ref($possoptions->{$field}) eq 'ARRAY') {
3544: foreach my $option (@{$possoptions->{$field}}) {
3545: my $checked;
3546: if ($currfield{$field} eq $option) {
3547: $checked = ' checked="checked"';
3548: }
3549: $datatable .= '<span class="LC_nobreak"><label>'.
3550: '<input type="radio" name="helpform_'.$field.'" '.
3551: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3552: '</label></span>'.(' 'x2);
3553: }
3554: }
3555: if ($field eq 'screenshot') {
3556: my $display;
3557: if ($currfield{$field} eq 'no') {
3558: $display = ' style="display:none"';
3559: }
1.334 raeburn 3560: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 3561: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3562: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3563: }
3564: $datatable .= '</td></tr>';
3565: }
3566: $datatable .= '</table>';
3567: }
3568: $datatable .= '</td></tr>'."\n";
3569: $rownum ++;
3570: }
1.340 raeburn 3571: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 3572: foreach my $type (@mailings) {
3573: $css_class = $rownum%2?' class="LC_odd_row"':'';
3574: $datatable .= '<tr'.$css_class.'>'.
3575: '<td><span class="LC_nobreak">'.
3576: $titles->{$type}.': </span></td>'.
3577: '<td class="LC_left_item">';
3578: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3579: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3580: }
3581: $datatable .= '<span class="LC_nobreak">';
3582: foreach my $item (@contacts) {
3583: $datatable .= '<label>'.
3584: '<input type="checkbox" name="'.$type.'"'.
3585: $checked{$type}{$item}.
3586: ' value="'.$item.'" />'.$short_titles->{$item}.
3587: '</label> ';
3588: }
3589: $datatable .= '</span><br />'.&mt('Others').': '.
3590: '<input type="text" name="'.$type.'_others" '.
3591: 'value="'.$otheremails{$type}.'" />';
3592: my %locchecked;
3593: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3594: foreach my $loc ('s','b') {
3595: if ($includeloc{$type} eq $loc) {
3596: $locchecked{$loc} = ' checked="checked"';
3597: last;
3598: }
3599: }
3600: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3601: '<input type="text" name="'.$type.'_bcc" '.
3602: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3603: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3604: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 3605: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 3606: '<span class="LC_nobreak">'.&mt('Location:').' '.
3607: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3608: (' 'x2).
3609: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3610: '</span></fieldset>';
3611: }
3612: $datatable .= '</td></tr>'."\n";
3613: $rownum ++;
3614: }
1.28 raeburn 3615: }
1.286 raeburn 3616: if ($position eq 'middle') {
3617: my %choices;
1.340 raeburn 3618: my $corelink = &core_link_msu();
3619: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 3620: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 3621: $corelink);
3622: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
3623: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 3624: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 3625: 'reportupdates' => 'on',
3626: 'reportstatus' => 'on');
1.286 raeburn 3627: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3628: \%choices,$rownum);
3629: $datatable .= $reports;
1.340 raeburn 3630: } elsif ($position eq 'lower') {
3631: $css_class = $rownum%2?' class="LC_odd_row"':'';
3632: my ($threshold,$sysmail,%excluded,%weights);
3633: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
3634: if ($lonstatus{'threshold'} =~ /^\d+$/) {
3635: $threshold = $lonstatus{'threshold'};
3636: } else {
3637: $threshold = $defaults->{'threshold'};
3638: }
3639: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
3640: $sysmail = $lonstatus{'sysmail'};
3641: } else {
3642: $sysmail = $defaults->{'sysmail'};
3643: }
3644: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 3645: foreach my $type ('E','W','N','U') {
1.340 raeburn 3646: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
3647: $weights{$type} = $lonstatus{'weights'}{$type};
3648: } else {
3649: $weights{$type} = $defaults->{$type};
3650: }
3651: }
3652: } else {
1.341 raeburn 3653: foreach my $type ('E','W','N','U') {
1.340 raeburn 3654: $weights{$type} = $defaults->{$type};
3655: }
3656: }
3657: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
3658: if (@{$lonstatus{'excluded'}} > 0) {
3659: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
3660: }
3661: }
3662: $datatable .= '<tr'.$css_class.'>'.
3663: '<td class="LC_left_item"><span class="LC_nobreak">'.
3664: $titles->{'errorthreshold'}.
3665: '</span></td><td class="LC_left_item">'.
3666: '<input type="text" name="errorthreshold" value="'.
3667: $threshold.'" size="5" /></td></tr>';
3668: $rownum ++;
3669: $css_class = $rownum%2?' class="LC_odd_row"':'';
3670: $datatable .= '<tr'.$css_class.'>'.
3671: '<td class="LC_left_item">'.
3672: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
3673: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 3674: foreach my $type ('E','W','N','U') {
1.340 raeburn 3675: $datatable .= '<td>'.$names->{$type}.'<br />'.
3676: '<input type="text" name="errorweights_'.$type.'" value="'.
3677: $weights{$type}.'" size="5" /></td>';
3678: }
3679: $datatable .= '</tr></table></tr>';
3680: $rownum ++;
3681: $css_class = $rownum%2?' class="LC_odd_row"':'';
3682: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
3683: $titles->{'errorexcluded'}.'</td>'.
3684: '<td class="LC_left_item"><table>';
3685: my $numinrow = 4;
3686: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
3687: for (my $i=0; $i<@ids; $i++) {
3688: my $rem = $i%($numinrow);
3689: if ($rem == 0) {
3690: if ($i > 0) {
3691: $datatable .= '</tr>';
3692: }
3693: $datatable .= '<tr>';
3694: }
3695: my $check;
3696: if ($excluded{$ids[$i]}) {
3697: $check = ' checked="checked" ';
3698: }
3699: $datatable .= '<td class="LC_left_item">'.
3700: '<span class="LC_nobreak"><label>'.
3701: '<input type="checkbox" name="errorexcluded" '.
3702: 'value="'.$ids[$i].'"'.$check.' />'.
3703: $ids[$i].'</label></span></td>';
3704: }
3705: my $colsleft = $numinrow - @ids%($numinrow);
3706: if ($colsleft > 1 ) {
3707: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3708: ' </td>';
3709: } elsif ($colsleft == 1) {
3710: $datatable .= '<td class="LC_left_item"> </td>';
3711: }
3712: $datatable .= '</tr></table></td></tr>';
3713: $rownum ++;
3714: $css_class = $rownum%2?' class="LC_odd_row"':'';
3715: $datatable .= '<tr'.$css_class.'>'.
3716: '<td class="LC_left_item"><span class="LC_nobreak">'.
3717: $titles->{'errorsysmail'}.
3718: '</span></td><td class="LC_left_item">'.
3719: '<input type="text" name="errorsysmail" value="'.
3720: $sysmail.'" size="5" /></td></tr>';
3721: $rownum ++;
1.286 raeburn 3722: } elsif ($position eq 'bottom') {
1.315 raeburn 3723: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3724: my (@posstypes,%usertypeshash);
3725: if (ref($types) eq 'ARRAY') {
3726: @posstypes = @{$types};
3727: }
3728: if (@posstypes) {
3729: if (ref($usertypes) eq 'HASH') {
3730: %usertypeshash = %{$usertypes};
3731: }
3732: my @overridden;
3733: my $numinrow = 4;
3734: if (ref($settings) eq 'HASH') {
3735: if (ref($settings->{'overrides'}) eq 'HASH') {
3736: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3737: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3738: push(@overridden,$key);
3739: foreach my $item (@contacts) {
3740: if ($settings->{'overrides'}{$key}{$item}) {
3741: $checked{'override_'.$key}{$item} = ' checked="checked" ';
3742: }
3743: }
3744: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3745: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3746: $includeloc{'override_'.$key} = '';
3747: $includestr{'override_'.$key} = '';
3748: if ($settings->{'overrides'}{$key}{'include'} ne '') {
3749: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3750: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3751: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3752: }
1.286 raeburn 3753: }
3754: }
3755: }
1.315 raeburn 3756: }
3757: my $customclass = 'LC_helpdesk_override';
3758: my $optionsprefix = 'LC_options_helpdesk_';
3759:
3760: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3761:
3762: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3763: $numinrow,$othertitle,'overrides',
3764: \$rownum,$onclicktypes,$customclass);
3765: $rownum ++;
3766: $usertypeshash{'default'} = $othertitle;
3767: foreach my $status (@posstypes) {
3768: my $css_class;
3769: if ($rownum%2) {
3770: $css_class = 'LC_odd_row ';
3771: }
3772: $css_class .= $customclass;
3773: my $rowid = $optionsprefix.$status;
3774: my $hidden = 1;
3775: my $currstyle = 'display:none';
3776: if (grep(/^\Q$status\E$/,@overridden)) {
3777: $currstyle = 'display:table-row';
3778: $hidden = 0;
3779: }
3780: my $key = 'override_'.$status;
3781: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3782: $includeloc{$key},$includestr{$key},$status,$rowid,
3783: $usertypeshash{$status},$css_class,$currstyle,
3784: \@contacts,$short_titles);
3785: unless ($hidden) {
3786: $rownum ++;
1.286 raeburn 3787: }
3788: }
1.134 raeburn 3789: }
1.28 raeburn 3790: }
1.30 raeburn 3791: $$rowtotal += $rownum;
1.28 raeburn 3792: return $datatable;
3793: }
3794:
1.340 raeburn 3795: sub core_link_msu {
3796: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3797: &mt('LON-CAPA core group - MSU'),600,500);
3798: }
3799:
1.315 raeburn 3800: sub overridden_helpdesk {
3801: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3802: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3803: my $class = 'LC_left_item';
3804: if ($css_class) {
3805: $css_class = ' class="'.$css_class.'"';
3806: }
3807: if ($rowid) {
3808: $rowid = ' id="'.$rowid.'"';
3809: }
3810: if ($rowstyle) {
3811: $rowstyle = ' style="'.$rowstyle.'"';
3812: }
3813: my ($output,$description);
3814: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3815: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3816: "<td>$description</td>\n".
3817: '<td class="'.$class.'" colspan="2">'.
3818: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3819: '<span class="LC_nobreak">';
3820: if (ref($contacts) eq 'ARRAY') {
3821: foreach my $item (@{$contacts}) {
3822: my $check;
3823: if (ref($checked) eq 'HASH') {
3824: $check = $checked->{$item};
3825: }
3826: my $title;
3827: if (ref($short_titles) eq 'HASH') {
3828: $title = $short_titles->{$item};
3829: }
3830: $output .= '<label>'.
3831: '<input type="checkbox" name="override_'.$type.'"'.$check.
3832: ' value="'.$item.'" />'.$title.'</label> ';
3833: }
3834: }
3835: $output .= '</span><br />'.&mt('Others').': '.
3836: '<input type="text" name="override_'.$type.'_others" '.
3837: 'value="'.$otheremails.'" />';
3838: my %locchecked;
3839: foreach my $loc ('s','b') {
3840: if ($includeloc eq $loc) {
3841: $locchecked{$loc} = ' checked="checked"';
3842: last;
3843: }
3844: }
3845: $output .= '<br />'.&mt('Bcc:').(' 'x6).
3846: '<input type="text" name="override_'.$type.'_bcc" '.
3847: 'value="'.$bccemails.'" /></fieldset>'.
3848: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3849: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 3850: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 3851: '<span class="LC_nobreak">'.&mt('Location:').' '.
3852: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3853: (' 'x2).
3854: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3855: '</span></fieldset>'.
3856: '</td></tr>'."\n";
3857: return $output;
3858: }
3859:
1.286 raeburn 3860: sub contacts_javascript {
3861: return <<"ENDSCRIPT";
3862:
3863: <script type="text/javascript">
3864: // <![CDATA[
3865:
3866: function screenshotSize(field) {
3867: if (document.getElementById('help_screenshotsize')) {
3868: if (field.value == 'no') {
1.289 raeburn 3869: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 3870: } else {
3871: document.getElementById('help_screenshotsize').style.display="";
3872: }
3873: }
3874: return;
3875: }
3876:
1.315 raeburn 3877: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
3878: if (form.elements[checkbox].length != undefined) {
3879: var count = 0;
3880: if (docount) {
3881: for (var i=0; i<form.elements[checkbox].length; i++) {
3882: if (form.elements[checkbox][i].checked) {
3883: count ++;
3884: }
3885: }
3886: }
3887: for (var i=0; i<form.elements[checkbox].length; i++) {
3888: var type = form.elements[checkbox][i].value;
3889: if (document.getElementById(prefix+type)) {
3890: if (form.elements[checkbox][i].checked) {
3891: document.getElementById(prefix+type).style.display = 'table-row';
3892: if (count % 2 == 1) {
3893: document.getElementById(prefix+type).className = target+' LC_odd_row';
3894: } else {
3895: document.getElementById(prefix+type).className = target;
3896: }
3897: count ++;
3898: } else {
3899: document.getElementById(prefix+type).style.display = 'none';
3900: }
3901: }
3902: }
3903: }
3904: return;
3905: }
3906:
3907:
1.286 raeburn 3908: // ]]>
3909: </script>
3910:
3911: ENDSCRIPT
3912: }
3913:
1.118 jms 3914: sub print_helpsettings {
1.282 raeburn 3915: my ($position,$dom,$settings,$rowtotal) = @_;
3916: my $confname = $dom.'-domainconfig';
1.285 raeburn 3917: my $formname = 'display';
1.168 raeburn 3918: my ($datatable,$itemcount);
1.282 raeburn 3919: if ($position eq 'top') {
3920: $itemcount = 1;
3921: my (%choices,%defaultchecked,@toggles);
3922: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3923: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3924: &mt('LON-CAPA bug tracker'),600,500));
3925: %defaultchecked = ('submitbugs' => 'on');
3926: @toggles = ('submitbugs');
3927: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3928: \%choices,$itemcount);
3929: $$rowtotal ++;
3930: } else {
3931: my $css_class;
3932: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 3933: my (%customroles,%ordered,%current);
1.301 raeburn 3934: if (ref($settings) eq 'HASH') {
3935: if (ref($settings->{'adhoc'}) eq 'HASH') {
3936: %current = %{$settings->{'adhoc'}};
3937: }
1.285 raeburn 3938: }
3939: my $count = 0;
3940: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 3941: if ($key=~/^rolesdef\_(\w+)$/) {
3942: my $rolename = $1;
1.285 raeburn 3943: my (%privs,$order);
1.282 raeburn 3944: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3945: $customroles{$rolename} = \%privs;
1.285 raeburn 3946: if (ref($current{$rolename}) eq 'HASH') {
3947: $order = $current{$rolename}{'order'};
3948: }
3949: if ($order eq '') {
3950: $order = $count;
3951: }
3952: $ordered{$order} = $rolename;
3953: $count++;
3954: }
3955: }
3956: my $maxnum = scalar(keys(%ordered));
3957: my @roles_by_num = ();
3958: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3959: push(@roles_by_num,$item);
3960: }
3961: my $context = 'domprefs';
3962: my $crstype = 'Course';
3963: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 3964: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 3965: my ($numstatustypes,@jsarray);
3966: if (ref($types) eq 'ARRAY') {
3967: if (@{$types} > 0) {
3968: $numstatustypes = scalar(@{$types});
3969: push(@accesstypes,'status');
3970: @jsarray = ('bystatus');
1.282 raeburn 3971: }
3972: }
1.290 raeburn 3973: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 3974: if (keys(%domhelpdesk)) {
3975: push(@accesstypes,('inc','exc'));
3976: push(@jsarray,('notinc','notexc'));
3977: }
3978: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 3979: my $context = 'domprefs';
3980: my $crstype = 'Course';
1.285 raeburn 3981: my $prefix = 'helproles_';
3982: my $add_class = 'LC_hidden';
3983: foreach my $num (@roles_by_num) {
3984: my $role = $ordered{$num};
3985: my ($desc,$access,@statuses);
3986: if (ref($current{$role}) eq 'HASH') {
3987: $desc = $current{$role}{'desc'};
3988: $access = $current{$role}{'access'};
3989: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3990: @statuses = @{$current{$role}{'insttypes'}};
3991: }
3992: }
3993: if ($desc eq '') {
3994: $desc = $role;
3995: }
3996: my $identifier = 'custhelp'.$num;
1.282 raeburn 3997: my %full=();
3998: my %levels= (
3999: course => {},
4000: domain => {},
4001: system => {},
4002: );
4003: my %levelscurrent=(
4004: course => {},
4005: domain => {},
4006: system => {},
4007: );
4008: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4009: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4010: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 4011: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 4012: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 4013: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4014: for (my $k=0; $k<=$maxnum; $k++) {
4015: my $vpos = $k+1;
4016: my $selstr;
4017: if ($k == $num) {
4018: $selstr = ' selected="selected" ';
4019: }
4020: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4021: }
4022: $datatable .= '</select>'.(' 'x2).
4023: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4024: '</td>'.
4025: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4026: &mt('Name shown to users:').
4027: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4028: '</fieldset>'.
4029: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4030: $othertitle,$usertypes,$types,\%domhelpdesk).
4031: '<fieldset>'.
4032: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 4033: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 4034: \%levelscurrent,$identifier,
4035: 'LC_hidden',$prefix.$num.'_privs').
4036: '</fieldset></td>';
1.282 raeburn 4037: $itemcount ++;
4038: }
4039: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4040: my $newcust = 'custhelp'.$count;
4041: my (%privs,%levelscurrent);
4042: my %full=();
4043: my %levels= (
4044: course => {},
4045: domain => {},
4046: system => {},
4047: );
4048: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4049: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 4050: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 4051: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 4052: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4053: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4054: for (my $k=0; $k<$maxnum+1; $k++) {
4055: my $vpos = $k+1;
4056: my $selstr;
4057: if ($k == $maxnum) {
4058: $selstr = ' selected="selected" ';
4059: }
4060: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4061: }
4062: $datatable .= '</select> '."\n".
1.282 raeburn 4063: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4064: '</label></span></td>'.
1.285 raeburn 4065: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4066: '<span class="LC_nobreak">'.
4067: &mt('Internal name:').
4068: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4069: '</span>'.(' 'x4).
4070: '<span class="LC_nobreak">'.
4071: &mt('Name shown to users:').
4072: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4073: '</span></fieldset>'.
4074: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4075: $usertypes,$types,\%domhelpdesk).
4076: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 4077: &Apache::lonuserutils::custom_role_header($context,$crstype,
4078: \@templateroles,$newcust).
4079: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4080: \%levelscurrent,$newcust).
1.334 raeburn 4081: '</fieldset>'.
4082: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4083: '</td></tr>';
1.282 raeburn 4084: $count ++;
4085: $$rowtotal += $count;
4086: }
1.166 raeburn 4087: return $datatable;
1.121 raeburn 4088: }
4089:
1.285 raeburn 4090: sub adhocbutton {
4091: my ($prefix,$num,$field,$visibility) = @_;
4092: my %lt = &Apache::lonlocal::texthash(
4093: show => 'Show details',
4094: hide => 'Hide details',
4095: );
4096: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4097: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4098: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4099: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4100: }
4101:
4102: sub helpsettings_javascript {
4103: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4104: return unless(ref($roles_by_num) eq 'ARRAY');
4105: my %html_js_lt = &Apache::lonlocal::texthash(
4106: show => 'Show details',
4107: hide => 'Hide details',
4108: );
4109: &html_escape(\%html_js_lt);
4110: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4111: return <<"ENDSCRIPT";
4112: <script type="text/javascript">
4113: // <![CDATA[
4114:
4115: function reorderHelpRoles(form,item) {
4116: var changedVal;
4117: $jstext
4118: var newpos = 'helproles_${total}_pos';
4119: var maxh = 1 + $total;
4120: var current = new Array();
4121: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4122: if (item == newpos) {
4123: changedVal = newitemVal;
4124: } else {
4125: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4126: current[newitemVal] = newpos;
4127: }
4128: for (var i=0; i<helproles.length; i++) {
4129: var elementName = 'helproles_'+helproles[i]+'_pos';
4130: if (elementName != item) {
4131: if (form.elements[elementName]) {
4132: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4133: current[currVal] = elementName;
4134: }
4135: }
4136: }
4137: var oldVal;
4138: for (var j=0; j<maxh; j++) {
4139: if (current[j] == undefined) {
4140: oldVal = j;
4141: }
4142: }
4143: if (oldVal < changedVal) {
4144: for (var k=oldVal+1; k<=changedVal ; k++) {
4145: var elementName = current[k];
4146: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4147: }
4148: } else {
4149: for (var k=changedVal; k<oldVal; k++) {
4150: var elementName = current[k];
4151: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4152: }
4153: }
4154: return;
4155: }
4156:
4157: function helpdeskAccess(num) {
4158: var curraccess = null;
4159: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4160: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4161: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4162: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4163: }
4164: }
4165: }
4166: var shown = Array();
4167: var hidden = Array();
4168: if (curraccess == 'none') {
4169: hidden = Array('$hiddenstr');
4170: } else {
4171: if (curraccess == 'status') {
4172: shown = Array('bystatus');
4173: hidden = Array('notinc','notexc');
4174: } else {
4175: if (curraccess == 'exc') {
4176: shown = Array('notexc');
4177: hidden = Array('notinc','bystatus');
4178: }
4179: if (curraccess == 'inc') {
4180: shown = Array('notinc');
4181: hidden = Array('notexc','bystatus');
4182: }
1.293 raeburn 4183: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 4184: hidden = Array('notinc','notexc','bystatus');
4185: }
4186: }
4187: }
4188: if (hidden.length > 0) {
4189: for (var i=0; i<hidden.length; i++) {
4190: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4191: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4192: }
4193: }
4194: }
4195: if (shown.length > 0) {
4196: for (var i=0; i<shown.length; i++) {
4197: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4198: if (shown[i] == 'privs') {
4199: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4200: } else {
4201: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4202: }
4203: }
4204: }
4205: }
4206: return;
4207: }
4208:
4209: function toggleHelpdeskItem(num,field) {
4210: if (document.getElementById('helproles_'+num+'_'+field)) {
4211: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 4212: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 4213: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4214: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4215: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4216: }
4217: } else {
4218: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4219: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4220: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4221: }
4222: }
4223: }
4224: return;
4225: }
4226:
4227: // ]]>
4228: </script>
4229:
4230: ENDSCRIPT
4231: }
4232:
4233: sub helpdeskroles_access {
4234: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4235: $usertypes,$types,$domhelpdesk) = @_;
4236: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4237: my %lt = &Apache::lonlocal::texthash(
4238: 'rou' => 'Role usage',
4239: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 4240: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4241: 'dh' => 'All with domain helpdesk role',
4242: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 4243: 'none' => 'None',
4244: 'status' => 'Determined based on institutional status',
4245: 'inc' => 'Include all, but exclude specific personnel',
4246: 'exc' => 'Exclude all, but include specific personnel',
4247: );
4248: my %usecheck = (
4249: all => ' checked="checked"',
4250: );
4251: my %displaydiv = (
4252: status => 'none',
4253: inc => 'none',
4254: exc => 'none',
4255: priv => 'block',
4256: );
4257: my $output;
4258: if (ref($current) eq 'HASH') {
4259: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4260: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4261: $usecheck{$current->{access}} = $usecheck{'all'};
4262: delete($usecheck{'all'});
4263: if ($current->{access} =~ /^(status|inc|exc)$/) {
4264: my $access = $1;
4265: $displaydiv{$access} = 'inline';
4266: } elsif ($current->{access} eq 'none') {
4267: $displaydiv{'priv'} = 'none';
4268: }
4269: }
4270: }
4271: }
4272: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4273: '<p>'.$lt{'whi'}.'</p>';
4274: foreach my $access (@{$accesstypes}) {
4275: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4276: ' onclick="helpdeskAccess('."'$num'".');" />'.
4277: $lt{$access}.'</label>';
4278: if ($access eq 'status') {
4279: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4280: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4281: $othertitle,$usertypes,$types).
4282: '</div>';
4283: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4284: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4285: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4286: '</div>';
4287: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4288: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4289: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4290: '</div>';
4291: }
4292: $output .= '</p>';
4293: }
4294: $output .= '</fieldset>';
4295: return $output;
4296: }
4297:
1.121 raeburn 4298: sub radiobutton_prefs {
1.192 raeburn 4299: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 4300: $additional,$align) = @_;
1.121 raeburn 4301: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4302: (ref($choices) eq 'HASH'));
4303:
1.170 raeburn 4304: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 4305:
4306: foreach my $item (@{$toggles}) {
4307: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4308: $checkedon{$item} = ' checked="checked" ';
4309: $checkedoff{$item} = ' ';
1.121 raeburn 4310: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4311: $checkedoff{$item} = ' checked="checked" ';
4312: $checkedon{$item} = ' ';
4313: }
4314: }
4315: if (ref($settings) eq 'HASH') {
1.121 raeburn 4316: foreach my $item (@{$toggles}) {
1.118 jms 4317: if ($settings->{$item} eq '1') {
4318: $checkedon{$item} = ' checked="checked" ';
4319: $checkedoff{$item} = ' ';
4320: } elsif ($settings->{$item} eq '0') {
4321: $checkedoff{$item} = ' checked="checked" ';
4322: $checkedon{$item} = ' ';
4323: }
4324: }
1.121 raeburn 4325: }
1.192 raeburn 4326: if ($onclick) {
4327: $onclick = ' onclick="'.$onclick.'"';
4328: }
1.121 raeburn 4329: foreach my $item (@{$toggles}) {
1.118 jms 4330: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4331: $datatable .=
1.306 raeburn 4332: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 4333: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 4334: '</span></td>';
4335: if ($align eq 'left') {
4336: $datatable .= '<td class="LC_left_item">';
4337: } else {
4338: $datatable .= '<td class="LC_right_item">';
4339: }
1.289 raeburn 4340: $datatable .=
1.257 raeburn 4341: '<span class="LC_nobreak">'.
1.118 jms 4342: '<label><input type="radio" name="'.
1.192 raeburn 4343: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 4344: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 4345: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
4346: '</span>'.$additional.
4347: '</td>'.
1.118 jms 4348: '</tr>';
4349: $itemcount ++;
1.121 raeburn 4350: }
4351: return ($datatable,$itemcount);
4352: }
4353:
1.267 raeburn 4354: sub print_ltitools {
4355: my ($dom,$settings,$rowtotal) = @_;
4356: my $rownum = 0;
4357: my $css_class;
4358: my $itemcount = 1;
4359: my $maxnum = 0;
4360: my %ordered;
4361: if (ref($settings) eq 'HASH') {
4362: foreach my $item (keys(%{$settings})) {
4363: if (ref($settings->{$item}) eq 'HASH') {
4364: my $num = $settings->{$item}{'order'};
4365: $ordered{$num} = $item;
4366: }
4367: }
4368: }
4369: my $confname = $dom.'-domainconfig';
4370: my $switchserver = &check_switchserver($dom,$confname);
4371: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 4372: my $datatable;
1.267 raeburn 4373: my %lt = <itools_names();
4374: my @courseroles = ('cc','in','ta','ep','st');
4375: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.324 raeburn 4376: my @fields = ('fullname','firstname','lastname','email','roles','user');
1.267 raeburn 4377: if (keys(%ordered)) {
4378: my @items = sort { $a <=> $b } keys(%ordered);
4379: for (my $i=0; $i<@items; $i++) {
4380: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4381: my $item = $ordered{$items[$i]};
1.323 raeburn 4382: my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267 raeburn 4383: if (ref($settings->{$item}) eq 'HASH') {
4384: $title = $settings->{$item}->{'title'};
4385: $url = $settings->{$item}->{'url'};
4386: $key = $settings->{$item}->{'key'};
4387: $secret = $settings->{$item}->{'secret'};
1.322 raeburn 4388: $lifetime = $settings->{$item}->{'lifetime'};
1.267 raeburn 4389: my $image = $settings->{$item}->{'image'};
4390: if ($image ne '') {
4391: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
4392: }
1.323 raeburn 4393: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
4394: $sigsel{'HMAC-256'} = ' selected="selected"';
4395: } else {
4396: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
4397: }
1.267 raeburn 4398: }
1.319 raeburn 4399: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267 raeburn 4400: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4401: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
4402: for (my $k=0; $k<=$maxnum; $k++) {
4403: my $vpos = $k+1;
4404: my $selstr;
4405: if ($k == $i) {
4406: $selstr = ' selected="selected" ';
4407: }
4408: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4409: }
4410: $datatable .= '</select>'.(' 'x2).
4411: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4412: &mt('Delete?').'</label></span></td>'.
4413: '<td colspan="2">'.
4414: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4415: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267 raeburn 4416: (' 'x2).
4417: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4418: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4419: (' 'x2).
4420: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4421: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4422: (' 'x2).
4423: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
4424: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
4425: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267 raeburn 4426: '<br /><br />'.
1.323 raeburn 4427: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267 raeburn 4428: ' value="'.$url.'" /></span>'.
4429: (' 'x2).
1.319 raeburn 4430: '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267 raeburn 4431: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4432: (' 'x2).
1.322 raeburn 4433: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
4434: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
4435: (' 'x2).
1.267 raeburn 4436: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4437: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4438: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltitools_secret_'.$i.'.type='."'text'".' } else { this.form.ltitools_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
4439: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4440: '</fieldset>'.
4441: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4442: '<span class="LC_nobreak">'.&mt('Display target:');
4443: my %currdisp;
4444: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4445: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4446: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 4447: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4448: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 4449: } else {
4450: $currdisp{'iframe'} = ' checked="checked"';
4451: }
4452: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4453: $currdisp{'width'} = $1;
4454: }
4455: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4456: $currdisp{'height'} = $1;
4457: }
1.296 raeburn 4458: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4459: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 4460: } else {
4461: $currdisp{'iframe'} = ' checked="checked"';
4462: }
1.298 raeburn 4463: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4464: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4465: $lt{$disp}.'</label>'.(' 'x2);
4466: }
4467: $datatable .= (' 'x4);
4468: foreach my $dimen ('width','height') {
4469: $datatable .= '<label>'.$lt{$dimen}.' '.
4470: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4471: (' 'x2);
4472: }
1.334 raeburn 4473: $datatable .= '</span><br />'.
1.296 raeburn 4474: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 4475: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
1.296 raeburn 4476: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4477: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
4478: '</textarea></div><div style=""></div><br />';
1.319 raeburn 4479: my %units = (
4480: 'passback' => 'days',
4481: 'roster' => 'seconds',
4482: );
1.267 raeburn 4483: foreach my $extra ('passback','roster') {
1.319 raeburn 4484: my $validsty = 'none';
4485: my $currvalid;
1.267 raeburn 4486: my $checkedon = '';
4487: my $checkedoff = ' checked="checked"';
4488: if ($settings->{$item}->{$extra}) {
4489: $checkedon = $checkedoff;
4490: $checkedoff = '';
1.319 raeburn 4491: $validsty = 'inline-block';
4492: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
4493: $currvalid = $settings->{$item}->{$extra.'valid'};
4494: }
4495: }
4496: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
4497: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4498: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
4499: &mt('No').'</label>'.(' 'x2).
4500: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
4501: &mt('Yes').'</label></span></div>'.
4502: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
4503: '<span class="LC_nobreak">'.
4504: &mt("at least [_1] $units{$extra} after launch",
4505: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
4506: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4507: }
1.319 raeburn 4508: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
1.267 raeburn 4509: if ($imgsrc) {
4510: $datatable .= $imgsrc.
4511: '<label><input type="checkbox" name="ltitools_image_del"'.
4512: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
4513: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
4514: } else {
4515: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4516: }
4517: if ($switchserver) {
4518: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4519: } else {
4520: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
4521: }
4522: $datatable .= '</span></fieldset>';
1.324 raeburn 4523: my (%checkedfields,%rolemaps,$userincdom);
1.267 raeburn 4524: if (ref($settings->{$item}) eq 'HASH') {
4525: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
4526: %checkedfields = %{$settings->{$item}->{'fields'}};
4527: }
1.324 raeburn 4528: $userincdom = $settings->{$item}->{'incdom'};
1.267 raeburn 4529: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
4530: %rolemaps = %{$settings->{$item}->{'roles'}};
4531: $checkedfields{'roles'} = 1;
4532: }
4533: }
4534: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4535: '<span class="LC_nobreak">';
1.324 raeburn 4536: my $userfieldstyle = 'display:none;';
4537: my $seluserdom = '';
4538: my $unseluserdom = ' selected="selected"';
1.267 raeburn 4539: foreach my $field (@fields) {
1.324 raeburn 4540: my ($checked,$onclick,$id,$spacer);
1.267 raeburn 4541: if ($checkedfields{$field}) {
4542: $checked = ' checked="checked"';
4543: }
1.324 raeburn 4544: if ($field eq 'user') {
4545: $id = ' id="ltitools_user_field_'.$i.'"';
4546: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
4547: if ($checked) {
4548: $userfieldstyle = 'display:inline-block';
4549: if ($userincdom) {
4550: $seluserdom = $unseluserdom;
4551: $unseluserdom = '';
4552: }
4553: }
4554: } else {
4555: $spacer = (' ' x2);
4556: }
1.267 raeburn 4557: $datatable .= '<label>'.
1.324 raeburn 4558: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
4559: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4560: }
1.324 raeburn 4561: $datatable .= '</span>';
4562: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
4563: '<span class="LC_nobreak"> : '.
4564: '<select name="ltitools_userincdom_'.$i.'">'.
4565: '<option value="">'.&mt('Select').'</option>'.
4566: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
4567: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
4568: '</select></span></div>';
4569: $datatable .= '</fieldset>'.
1.267 raeburn 4570: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4571: foreach my $role (@courseroles) {
4572: my ($selected,$selectnone);
4573: if (!$rolemaps{$role}) {
4574: $selectnone = ' selected="selected"';
4575: }
1.306 raeburn 4576: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4577: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4578: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
4579: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4580: foreach my $ltirole (@ltiroles) {
4581: unless ($selectnone) {
4582: if ($rolemaps{$role} eq $ltirole) {
4583: $selected = ' selected="selected"';
4584: } else {
4585: $selected = '';
4586: }
4587: }
4588: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
4589: }
4590: $datatable .= '</select></td>';
4591: }
1.273 raeburn 4592: $datatable .= '</tr></table></fieldset>';
4593: my %courseconfig;
4594: if (ref($settings->{$item}) eq 'HASH') {
4595: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
4596: %courseconfig = %{$settings->{$item}->{'crsconf'}};
4597: }
4598: }
4599: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4600: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 4601: my $checked;
4602: if ($courseconfig{$item}) {
4603: $checked = ' checked="checked"';
4604: }
4605: $datatable .= '<label>'.
4606: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
4607: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
4608: }
4609: $datatable .= '</span></fieldset>'.
1.267 raeburn 4610: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4611: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
4612: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
4613: my %custom = %{$settings->{$item}->{'custom'}};
4614: if (keys(%custom) > 0) {
4615: foreach my $key (sort(keys(%custom))) {
4616: $datatable .= '<tr><td><span class="LC_nobreak">'.
4617: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
4618: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
4619: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
4620: ' value="'.$custom{$key}.'" /></td></tr>';
4621: }
4622: }
4623: }
4624: $datatable .= '<tr><td><span class="LC_nobreak">'.
4625: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
4626: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
4627: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
4628: $datatable .= '</table></fieldset></td></tr>'."\n";
4629: $itemcount ++;
4630: }
4631: }
4632: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319 raeburn 4633: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267 raeburn 4634: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4635: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
4636: '<select name="ltitools_add_pos"'.$chgstr.'>';
4637: for (my $k=0; $k<$maxnum+1; $k++) {
4638: my $vpos = $k+1;
4639: my $selstr;
4640: if ($k == $maxnum) {
4641: $selstr = ' selected="selected" ';
4642: }
4643: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4644: }
4645: $datatable .= '</select> '."\n".
1.334 raeburn 4646: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.267 raeburn 4647: '<td colspan="2">'.
4648: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4649: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267 raeburn 4650: (' 'x2).
4651: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
4652: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4653: (' 'x2).
4654: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
4655: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4656: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
4657: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
4658: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267 raeburn 4659: '<br />'.
1.323 raeburn 4660: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267 raeburn 4661: (' 'x2).
4662: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
4663: (' 'x2).
1.322 raeburn 4664: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
4665: (' 'x2).
1.267 raeburn 4666: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
4667: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltitools_add_secret.type='."'text'".' } else { this.form.ltitools_add_secret.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n".
4668: '</fieldset>'.
4669: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4670: '<span class="LC_nobreak">'.&mt('Display target:');
4671: my %defaultdisp;
4672: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 4673: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4674: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
4675: $lt{$disp}.'</label>'.(' 'x2);
4676: }
4677: $datatable .= (' 'x4);
4678: foreach my $dimen ('width','height') {
4679: $datatable .= '<label>'.$lt{$dimen}.' '.
4680: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
4681: (' 'x2);
4682: }
1.334 raeburn 4683: $datatable .= '</span><br />'.
1.296 raeburn 4684: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 4685: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
1.296 raeburn 4686: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
1.334 raeburn 4687: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
1.296 raeburn 4688: '</div><div style=""></div><br />';
1.319 raeburn 4689: my %units = (
4690: 'passback' => 'days',
4691: 'roster' => 'seconds',
4692: );
4693: my %defaulttimes = (
4694: 'passback' => '7',
1.322 raeburn 4695: 'roster' => '300',
1.319 raeburn 4696: );
1.267 raeburn 4697: foreach my $extra ('passback','roster') {
1.319 raeburn 4698: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
4699: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4700: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
4701: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
4702: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
4703: &mt('Yes').'</label></span></div>'.
4704: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
4705: '<span class="LC_nobreak">'.
4706: &mt("at least [_1] $units{$extra} after launch",
4707: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
4708: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4709: }
1.319 raeburn 4710: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
1.267 raeburn 4711: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4712: if ($switchserver) {
4713: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4714: } else {
4715: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
4716: }
4717: $datatable .= '</span></fieldset>'.
4718: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4719: '<span class="LC_nobreak">';
4720: foreach my $field (@fields) {
1.324 raeburn 4721: my ($id,$onclick,$spacer);
4722: if ($field eq 'user') {
4723: $id = ' id="ltitools_user_field_add"';
4724: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
4725: } else {
4726: $spacer = (' ' x2);
4727: }
1.267 raeburn 4728: $datatable .= '<label>'.
1.324 raeburn 4729: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
4730: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4731: }
1.324 raeburn 4732: $datatable .= '</span>'.
4733: '<div style="display:none;" id="ltitools_user_div_add">'.
4734: '<span class="LC_nobreak"> : '.
4735: '<select name="ltitools_userincdom_add">'.
4736: '<option value="" selected="selected">'.&mt('Select').'</option>'.
4737: '<option value="0">'.&mt('username').'</option>'.
4738: '<option value="1">'.&mt('username:domain').'</option>'.
4739: '</select></span></div></fieldset>';
4740: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1.267 raeburn 4741: foreach my $role (@courseroles) {
4742: my ($checked,$checkednone);
1.306 raeburn 4743: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4744: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4745: '<select name="ltitools_add_roles_'.$role.'">'.
4746: '<option value="" selected="selected">'.&mt('Select').'</option>';
4747: foreach my $ltirole (@ltiroles) {
4748: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
4749: }
4750: $datatable .= '</select></td>';
4751: }
4752: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 4753: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4754: foreach my $item ('label','title','target','linktext','explanation','append') {
1.296 raeburn 4755: $datatable .= '<label>'.
4756: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4757: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 4758: }
4759: $datatable .= '</span></fieldset>'.
1.267 raeburn 4760: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4761: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4762: '<tr><td><span class="LC_nobreak">'.
4763: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4764: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4765: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
1.334 raeburn 4766: '</table></fieldset>'."\n".
1.267 raeburn 4767: '</td>'."\n".
4768: '</tr>'."\n";
4769: $itemcount ++;
4770: return $datatable;
4771: }
4772:
4773: sub ltitools_names {
4774: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 4775: 'title' => 'Title',
4776: 'version' => 'Version',
4777: 'msgtype' => 'Message Type',
1.323 raeburn 4778: 'sigmethod' => 'Signature Method',
1.296 raeburn 4779: 'url' => 'URL',
4780: 'key' => 'Key',
1.322 raeburn 4781: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 4782: 'secret' => 'Secret',
4783: 'icon' => 'Icon',
1.324 raeburn 4784: 'user' => 'User',
1.296 raeburn 4785: 'fullname' => 'Full Name',
4786: 'firstname' => 'First Name',
4787: 'lastname' => 'Last Name',
4788: 'email' => 'E-mail',
4789: 'roles' => 'Role',
1.298 raeburn 4790: 'window' => 'Window',
4791: 'tab' => 'Tab',
1.296 raeburn 4792: 'iframe' => 'iFrame',
4793: 'height' => 'Height',
4794: 'width' => 'Width',
4795: 'linktext' => 'Default Link Text',
4796: 'explanation' => 'Default Explanation',
4797: 'passback' => 'Tool can return grades:',
4798: 'roster' => 'Tool can retrieve roster:',
4799: 'crstarget' => 'Display target',
4800: 'crslabel' => 'Course label',
4801: 'crstitle' => 'Course title',
4802: 'crslinktext' => 'Link Text',
4803: 'crsexplanation' => 'Explanation',
1.318 raeburn 4804: 'crsappend' => 'Provider URL',
1.267 raeburn 4805: );
4806: return %lt;
4807: }
4808:
1.320 raeburn 4809: sub print_lti {
4810: my ($dom,$settings,$rowtotal) = @_;
4811: my $itemcount = 1;
4812: my $maxnum = 0;
4813: my $css_class;
4814: my %ordered;
4815: if (ref($settings) eq 'HASH') {
4816: foreach my $item (keys(%{$settings})) {
4817: if (ref($settings->{$item}) eq 'HASH') {
4818: my $num = $settings->{$item}{'order'};
4819: $ordered{$num} = $item;
4820: }
4821: }
4822: }
4823: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 4824: my $datatable;
1.320 raeburn 4825: my %lt = <i_names();
4826: if (keys(%ordered)) {
4827: my @items = sort { $a <=> $b } keys(%ordered);
4828: for (my $i=0; $i<@items; $i++) {
4829: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4830: my $item = $ordered{$items[$i]};
1.345 raeburn 4831: my ($key,$secret,$lifetime,$consumer,$requser,$current);
1.320 raeburn 4832: if (ref($settings->{$item}) eq 'HASH') {
4833: $key = $settings->{$item}->{'key'};
4834: $secret = $settings->{$item}->{'secret'};
4835: $lifetime = $settings->{$item}->{'lifetime'};
4836: $consumer = $settings->{$item}->{'consumer'};
1.345 raeburn 4837: $requser = $settings->{$item}->{'requser'};
1.320 raeburn 4838: $current = $settings->{$item};
4839: }
1.345 raeburn 4840: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
4841: my %checkedrequser = (
4842: yes => ' checked="checked"',
4843: no => '',
4844: );
4845: if (!$requser) {
4846: $checkedrequser{'no'} = $checkedrequser{'yes'};
4847: $checkedrequser{'yes'} = '';
1.352 raeburn 4848: }
1.320 raeburn 4849: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
4850: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4851: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
4852: for (my $k=0; $k<=$maxnum; $k++) {
4853: my $vpos = $k+1;
4854: my $selstr;
4855: if ($k == $i) {
4856: $selstr = ' selected="selected" ';
4857: }
4858: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4859: }
4860: $datatable .= '</select>'.(' 'x2).
4861: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
4862: &mt('Delete?').'</label></span></td>'.
4863: '<td colspan="2">'.
4864: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4865: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 4866: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
1.320 raeburn 4867: (' 'x2).
4868: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
4869: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4870: (' 'x2).
4871: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.345 raeburn 4872: 'value="'.$lifetime.'" size="3" /></span>'.
4873: (' 'x2).
4874: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
4875: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
4876: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 4877: '<br /><br />'.
4878: '<span class="LC_nobreak">'.$lt{'key'}.
4879: ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
4880: (' 'x2).
4881: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4882: '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
4883: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.lti_secret_'.$i.'.type='."'text'".' } else { this.form.lti_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
4884: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
1.325 raeburn 4885: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
1.320 raeburn 4886: $itemcount ++;
4887: }
4888: }
4889: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4890: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
4891: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4892: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
4893: '<select name="lti_pos_add"'.$chgstr.'>';
4894: for (my $k=0; $k<$maxnum+1; $k++) {
4895: my $vpos = $k+1;
4896: my $selstr;
4897: if ($k == $maxnum) {
4898: $selstr = ' selected="selected" ';
4899: }
4900: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4901: }
4902: $datatable .= '</select> '."\n".
1.334 raeburn 4903: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.320 raeburn 4904: '<td colspan="2">'.
4905: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4906: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 4907: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
1.320 raeburn 4908: (' 'x2).
4909: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
4910: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4911: (' 'x2).
1.345 raeburn 4912: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span> '."\n".
4913: (' 'x2).
4914: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
4915: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
4916: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 4917: '<br /><br />'.
4918: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
4919: (' 'x2).
4920: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
4921: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.lti_secret_add.type='."'text'".' } else { this.form.lti_secret_add.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n".
1.325 raeburn 4922: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
1.320 raeburn 4923: '</td>'."\n".
4924: '</tr>'."\n";
4925: $$rowtotal ++;
4926: return $datatable;;
4927: }
4928:
4929: sub lti_names {
4930: my %lt = &Apache::lonlocal::texthash(
4931: 'version' => 'LTI Version',
4932: 'url' => 'URL',
4933: 'key' => 'Key',
1.322 raeburn 4934: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 4935: 'consumer' => 'Consumer',
1.320 raeburn 4936: 'secret' => 'Secret',
1.345 raeburn 4937: 'requser' => "User's identity sent",
1.320 raeburn 4938: 'email' => 'Email address',
4939: 'sourcedid' => 'User ID',
4940: 'other' => 'Other',
4941: 'passback' => 'Can return grades to Consumer:',
4942: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 4943: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 4944: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 4945: );
4946: return %lt;
4947: }
4948:
4949: sub lti_options {
1.325 raeburn 4950: my ($num,$current,$itemcount,%lt) = @_;
1.320 raeburn 4951: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield);
4952: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
4953: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
4954: $checked{'makecrs'}{'N'} = ' checked="checked"';
4955: $checked{'mapcrstype'} = {};
4956: $checked{'makeuser'} = {};
4957: $checked{'selfenroll'} = {};
4958: $checked{'crssec'} = {};
4959: $checked{'crssecsrc'} = {};
1.325 raeburn 4960: $checked{'lcauth'} = {};
1.326 raeburn 4961: $checked{'menuitem'} = {};
1.325 raeburn 4962: if ($num eq 'add') {
4963: $checked{'lcauth'}{'lti'} = ' checked="checked"';
4964: }
1.320 raeburn 4965: my $userfieldsty = 'none';
4966: my $crsfieldsty = 'none';
4967: my $crssecfieldsty = 'none';
4968: my $secsrcfieldsty = 'none';
1.337 raeburn 4969: my $passbacksty = 'none';
1.345 raeburn 4970: my $optionsty = 'block';
1.325 raeburn 4971: my $lcauthparm;
4972: my $lcauthparmstyle = 'display:none';
4973: my $lcauthparmtext;
1.326 raeburn 4974: my $menusty;
1.325 raeburn 4975: my $numinrow = 4;
1.326 raeburn 4976: my %menutitles = <imenu_titles();
1.320 raeburn 4977:
4978: if (ref($current) eq 'HASH') {
1.345 raeburn 4979: if (!$current->{'requser'}) {
4980: $optionsty = 'none';
4981: }
1.320 raeburn 4982: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
4983: $checked{'mapuser'}{'sourcedid'} = '';
4984: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
4985: $checked{'mapuser'}{'email'} = ' checked="checked"';
4986: } else {
4987: $checked{'mapuser'}{'other'} = ' checked="checked"';
4988: $userfield = $current->{'mapuser'};
4989: $userfieldsty = 'inline-block';
4990: }
4991: }
4992: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
4993: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
4994: if ($current->{'mapcrs'} eq 'context_id') {
4995: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
4996: } else {
4997: $checked{'mapcrs'}{'other'} = ' checked="checked"';
4998: $cidfield = $current->{'mapcrs'};
4999: $crsfieldsty = 'inline-block';
5000: }
5001: }
5002: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
5003: foreach my $type (@{$current->{'mapcrstype'}}) {
5004: $checked{'mapcrstype'}{$type} = ' checked="checked"';
5005: }
5006: }
1.345 raeburn 5007: if ($current->{'makecrs'}) {
1.320 raeburn 5008: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 5009: }
1.320 raeburn 5010: if (ref($current->{'makeuser'}) eq 'ARRAY') {
5011: foreach my $role (@{$current->{'makeuser'}}) {
5012: $checked{'makeuser'}{$role} = ' checked="checked"';
5013: }
5014: }
1.325 raeburn 5015: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
5016: $checked{'lcauth'}{$1} = ' checked="checked"';
5017: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
5018: $lcauthparm = $current->{'lcauthparm'};
5019: $lcauthparmstyle = 'display:table-row';
5020: if ($current->{'lcauth'} eq 'localauth') {
5021: $lcauthparmtext = &mt('Local auth argument');
5022: } else {
5023: $lcauthparmtext = &mt('Kerberos domain');
5024: }
5025: }
5026: }
1.320 raeburn 5027: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
5028: foreach my $role (@{$current->{'selfenroll'}}) {
5029: $checked{'selfenroll'}{$role} = ' checked="checked"';
5030: }
5031: }
5032: if (ref($current->{'maproles'}) eq 'HASH') {
5033: %rolemaps = %{$current->{'maproles'}};
5034: }
5035: if ($current->{'section'} ne '') {
5036: $checked{'crssec'}{'Y'} = ' checked="checked"';
5037: $crssecfieldsty = 'inline-block';
5038: if ($current->{'section'} eq 'course_section_sourcedid') {
5039: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
5040: } else {
5041: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
5042: $crssecsrc = $current->{'section'};
5043: $secsrcfieldsty = 'inline-block';
5044: }
5045: } else {
5046: $checked{'crssec'}{'N'} = ' checked="checked"';
5047: }
1.326 raeburn 5048: if ($current->{'topmenu'}) {
5049: $checked{'topmenu'}{'Y'} = ' checked="checked"';
5050: } else {
5051: $checked{'topmenu'}{'N'} = ' checked="checked"';
5052: }
5053: if ($current->{'inlinemenu'}) {
5054: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5055: } else {
5056: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
5057: }
5058: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
5059: $menusty = 'inline-block';
5060: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
5061: foreach my $item (@{$current->{'lcmenu'}}) {
5062: if (exists($menutitles{$item})) {
5063: $checked{'menuitem'}{$item} = ' checked="checked"';
5064: }
5065: }
5066: }
5067: } else {
5068: $menusty = 'none';
5069: }
1.320 raeburn 5070: } else {
5071: $checked{'makecrs'}{'N'} = ' checked="checked"';
5072: $checked{'crssec'}{'N'} = ' checked="checked"';
1.326 raeburn 5073: $checked{'topmenu'}{'N'} = ' checked="checked"';
5074: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5075: $checked{'menuitem'}{'grades'} = ' checked="checked"';
5076: $menusty = 'inline-block';
1.320 raeburn 5077: }
1.325 raeburn 5078: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 5079: my %coursetypetitles = &Apache::lonlocal::texthash (
5080: official => 'Official',
5081: unofficial => 'Unofficial',
5082: community => 'Community',
5083: textbook => 'Textbook',
5084: placement => 'Placement Test',
1.325 raeburn 5085: lti => 'LTI Provider',
1.320 raeburn 5086: );
1.325 raeburn 5087: my @authtypes = ('internal','krb4','krb5','localauth');
5088: my %shortauth = (
5089: internal => 'int',
5090: krb4 => 'krb4',
5091: krb5 => 'krb5',
5092: localauth => 'loc'
5093: );
5094: my %authnames = &authtype_names();
1.320 raeburn 5095: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
5096: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
5097: my @courseroles = ('cc','in','ta','ep','st');
5098: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
5099: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
5100: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
5101: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 5102: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 5103: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.345 raeburn 5104: my $output = '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 5105: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
5106: foreach my $option ('sourcedid','email','other') {
5107: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
5108: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
5109: ($option eq 'other' ? '' : (' 'x2) );
5110: }
5111: $output .= '</span></div>'.
5112: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
5113: '<input type="text" name="lti_customuser_'.$num.'" '.
5114: 'value="'.$userfield.'" /></div></fieldset>'.
1.345 raeburn 5115: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
1.320 raeburn 5116: foreach my $ltirole (@lticourseroles) {
5117: my ($selected,$selectnone);
5118: if ($rolemaps{$ltirole} eq '') {
5119: $selectnone = ' selected="selected"';
5120: }
5121: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
5122: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
5123: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5124: foreach my $role (@courseroles) {
5125: unless ($selectnone) {
5126: if ($rolemaps{$ltirole} eq $role) {
5127: $selected = ' selected="selected"';
5128: } else {
5129: $selected = '';
5130: }
5131: }
5132: $output .= '<option value="'.$role.'"'.$selected.'>'.
5133: &Apache::lonnet::plaintext($role,'Course').
5134: '</option>';
5135: }
5136: $output .= '</select></td>';
5137: }
5138: $output .= '</tr></table></fieldset>'.
1.345 raeburn 5139: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 5140: foreach my $ltirole (@ltiroles) {
5141: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
5142: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
5143: }
5144: $output .= '</fieldset>'.
1.345 raeburn 5145: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 5146: '<table>'.
5147: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
5148: '</table>'.
5149: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
5150: '<td class="LC_left_item">';
5151: foreach my $auth ('lti',@authtypes) {
5152: my $authtext;
5153: if ($auth eq 'lti') {
5154: $authtext = &mt('None');
5155: } else {
5156: $authtext = $authnames{$shortauth{$auth}};
5157: }
5158: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
5159: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
5160: $authtext.'</label></span> ';
5161: }
5162: $output .= '</td></tr>'.
5163: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
5164: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
5165: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
5166: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
5167: '</table></fieldset>'.
1.345 raeburn 5168: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 5169: '<div class="LC_floatleft"><span class="LC_nobreak">'.
5170: &mt('Unique course identifier').': ';
5171: foreach my $option ('course_offering_sourcedid','context_id','other') {
5172: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
5173: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
5174: ($option eq 'other' ? '' : (' 'x2) );
5175: }
1.334 raeburn 5176: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 5177: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
5178: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
5179: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
5180: foreach my $type (@coursetypes) {
5181: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
5182: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
5183: (' 'x2);
5184: }
5185: $output .= '</span></fieldset>'.
1.345 raeburn 5186: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 5187: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
5188: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
5189: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
5190: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
5191: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
5192: '</fieldset>'.
1.345 raeburn 5193: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 5194: foreach my $lticrsrole (@lticourseroles) {
5195: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
5196: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
5197: }
5198: $output .= '</fieldset>'.
1.345 raeburn 5199: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 5200: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
5201: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
5202: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
5203: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 5204: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 5205: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
5206: '<span class="LC_nobreak">'.&mt('From').':<label>'.
5207: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
5208: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
5209: &mt('Standard field').'</label>'.(' 'x2).
5210: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
5211: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 5212: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 5213: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 5214: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
5215: my ($pb1p1chk,$pb1p0chk,$onclickpb);
5216: foreach my $extra ('roster','passback') {
1.320 raeburn 5217: my $checkedon = '';
5218: my $checkedoff = ' checked="checked"';
1.337 raeburn 5219: if ($extra eq 'passback') {
5220: $pb1p1chk = ' checked="checked"';
5221: $pb1p0chk = '';
5222: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
5223: } else {
5224: $onclickpb = '';
5225: }
1.320 raeburn 5226: if (ref($current) eq 'HASH') {
5227: if (($current->{$extra})) {
5228: $checkedon = $checkedoff;
5229: $checkedoff = '';
1.337 raeburn 5230: if ($extra eq 'passback') {
5231: $passbacksty = 'inline-block';
5232: }
5233: if ($current->{'passbackformat'} eq '1.0') {
5234: $pb1p0chk = ' checked="checked"';
5235: $pb1p1chk = '';
5236: }
1.320 raeburn 5237: }
5238: }
5239: $output .= $lt{$extra}.' '.
1.337 raeburn 5240: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 5241: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 5242: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 5243: &mt('Yes').'</label><br />';
5244: }
1.337 raeburn 5245: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
5246: '<span class="LC_nobreak">'.&mt('Grade format').
5247: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
5248: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
5249: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
5250: &mt('Outcomes Extension (1.0)').'</label></span></div></fieldset>'.
1.345 raeburn 5251: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Course defaults (Course Coordinator can override)').'</legend>'.
1.326 raeburn 5252: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
5253: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
5254: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5255: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
1.334 raeburn 5256: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
1.326 raeburn 5257: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5258: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
5259: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
5260: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5261: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
1.334 raeburn 5262: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
1.326 raeburn 5263: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5264: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
5265: '<span class="LC_nobreak">'.&mt('Menu items').': ';
5266: foreach my $type ('fullname','coursetitle','role','logout','grades') {
5267: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
5268: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
5269: (' 'x2);
5270: }
1.334 raeburn 5271: $output .= '</span></div></fieldset>';
1.320 raeburn 5272: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
5273: #
5274: # $output .= '</fieldset>'.
5275: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
5276: return $output;
5277: }
5278:
1.326 raeburn 5279: sub ltimenu_titles {
5280: return &Apache::lonlocal::texthash(
5281: fullname => 'Full name',
5282: coursetitle => 'Course title',
5283: role => 'Role',
5284: logout => 'Logout',
5285: grades => 'Grades',
5286: );
5287: }
5288:
1.121 raeburn 5289: sub print_coursedefaults {
1.139 raeburn 5290: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 5291: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 5292: my $itemcount = 1;
1.192 raeburn 5293: my %choices = &Apache::lonlocal::texthash (
5294: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 5295: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 5296: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
5297: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 5298: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
5299: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.314 raeburn 5300: texengine => 'Default method to display mathematics',
1.257 raeburn 5301: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 5302: canclone => "People who may clone a course (besides course's owner and coordinators)",
5303: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 5304: );
1.198 raeburn 5305: my %staticdefaults = (
5306: anonsurvey_threshold => 10,
5307: uploadquota => 500,
1.257 raeburn 5308: postsubmit => 60,
1.276 raeburn 5309: mysqltables => 172800,
1.198 raeburn 5310: );
1.139 raeburn 5311: if ($position eq 'top') {
1.257 raeburn 5312: %defaultchecked = (
5313: 'canuse_pdfforms' => 'off',
5314: 'uselcmath' => 'on',
5315: 'usejsme' => 'on',
1.289 raeburn 5316: 'canclone' => 'none',
1.257 raeburn 5317: );
5318: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.349 raeburn 5319: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 5320: if (ref($settings) eq 'HASH') {
5321: if ($settings->{'texengine'}) {
5322: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
5323: $deftex = $settings->{'texengine'};
5324: }
5325: }
5326: }
5327: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5328: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
5329: '<span class="LC_nobreak">'.$choices{'texengine'}.
5330: '</span></td><td class="LC_right_item">'.
5331: '<select name="texengine">'."\n";
5332: my %texoptions = (
5333: MathJax => 'MathJax',
5334: mimetex => &mt('Convert to Images'),
5335: tth => &mt('TeX to HTML'),
5336: );
5337: foreach my $renderer ('MathJax','mimetex','tth') {
5338: my $selected = '';
5339: if ($renderer eq $deftex) {
5340: $selected = ' selected="selected"';
5341: }
5342: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
5343: }
5344: $mathdisp .= '</select></td></tr>'."\n";
5345: $itemcount ++;
1.139 raeburn 5346: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 5347: \%choices,$itemcount);
1.314 raeburn 5348: $datatable = $mathdisp.$datatable;
1.264 raeburn 5349: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5350: $datatable .=
1.306 raeburn 5351: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 5352: '<span class="LC_nobreak">'.$choices{'canclone'}.
5353: '</span></td><td class="LC_left_item">';
5354: my $currcanclone = 'none';
5355: my $onclick;
5356: my @cloneoptions = ('none','domain');
5357: my %clonetitles = (
5358: none => 'No additional course requesters',
5359: domain => "Any course requester in course's domain",
5360: instcode => 'Course requests for official courses ...',
5361: );
5362: my (%codedefaults,@code_order,@posscodes);
5363: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
5364: \@code_order) eq 'ok') {
5365: if (@code_order > 0) {
5366: push(@cloneoptions,'instcode');
5367: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
5368: }
5369: }
5370: if (ref($settings) eq 'HASH') {
5371: if ($settings->{'canclone'}) {
5372: if (ref($settings->{'canclone'}) eq 'HASH') {
5373: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
5374: if (@code_order > 0) {
5375: $currcanclone = 'instcode';
5376: @posscodes = @{$settings->{'canclone'}{'instcode'}};
5377: }
5378: }
5379: } elsif ($settings->{'canclone'} eq 'domain') {
5380: $currcanclone = $settings->{'canclone'};
5381: }
5382: }
1.289 raeburn 5383: }
1.264 raeburn 5384: foreach my $option (@cloneoptions) {
5385: my ($checked,$additional);
5386: if ($currcanclone eq $option) {
5387: $checked = ' checked="checked"';
5388: }
5389: if ($option eq 'instcode') {
5390: if (@code_order) {
5391: my $show = 'none';
5392: if ($checked) {
5393: $show = 'block';
5394: }
1.317 raeburn 5395: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 5396: &mt('Institutional codes for new and cloned course have identical:').
5397: '<br />';
5398: foreach my $item (@code_order) {
5399: my $codechk;
5400: if ($checked) {
5401: if (grep(/^\Q$item\E$/,@posscodes)) {
5402: $codechk = ' checked="checked"';
5403: }
5404: }
5405: $additional .= '<label>'.
5406: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
5407: $item.'</label>';
5408: }
5409: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
5410: }
5411: }
5412: $datatable .=
5413: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
5414: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
5415: '</label> '.$additional.'</span><br />';
5416: }
5417: $datatable .= '</td>'.
5418: '</tr>';
5419: $itemcount ++;
1.139 raeburn 5420: } else {
5421: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 5422: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 5423: my $currusecredits = 0;
1.257 raeburn 5424: my $postsubmitclient = 1;
1.271 raeburn 5425: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 5426: if (ref($settings) eq 'HASH') {
5427: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 5428: if (ref($settings->{'uploadquota'}) eq 'HASH') {
5429: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
5430: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
5431: }
5432: }
1.192 raeburn 5433: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 5434: foreach my $type (@types) {
5435: next if ($type eq 'community');
5436: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
5437: if ($defcredits{$type} ne '') {
5438: $currusecredits = 1;
5439: }
5440: }
5441: }
5442: if (ref($settings->{'postsubmit'}) eq 'HASH') {
5443: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
5444: $postsubmitclient = 0;
5445: foreach my $type (@types) {
5446: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5447: }
5448: } else {
5449: foreach my $type (@types) {
5450: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
5451: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 5452: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 5453: } else {
5454: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5455: }
5456: } else {
5457: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5458: }
5459: }
5460: }
5461: } else {
5462: foreach my $type (@types) {
5463: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 5464: }
5465: }
1.276 raeburn 5466: if (ref($settings->{'mysqltables'}) eq 'HASH') {
5467: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
5468: $currmysql{$type} = $settings->{'mysqltables'}{$type};
5469: }
5470: } else {
5471: foreach my $type (@types) {
5472: $currmysql{$type} = $staticdefaults{'mysqltables'};
5473: }
5474: }
1.258 raeburn 5475: } else {
5476: foreach my $type (@types) {
5477: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5478: }
1.139 raeburn 5479: }
5480: if (!$currdefresponder) {
1.198 raeburn 5481: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 5482: } elsif ($currdefresponder < 1) {
5483: $currdefresponder = 1;
5484: }
1.198 raeburn 5485: foreach my $type (@types) {
5486: if ($curruploadquota{$type} eq '') {
5487: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
5488: }
5489: }
1.139 raeburn 5490: $datatable .=
1.192 raeburn 5491: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5492: $choices{'anonsurvey_threshold'}.
1.139 raeburn 5493: '</span></td>'.
5494: '<td class="LC_right_item"><span class="LC_nobreak">'.
5495: '<input type="text" name="anonsurvey_threshold"'.
5496: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 5497: '</td></tr>'."\n";
5498: $itemcount ++;
5499: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5500: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5501: $choices{'uploadquota'}.
5502: '</span></td>'.
1.306 raeburn 5503: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 5504: '<table><tr>';
1.198 raeburn 5505: foreach my $type (@types) {
1.306 raeburn 5506: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 5507: '<input type="text" name="uploadquota_'.$type.'"'.
5508: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
5509: }
5510: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 5511: $itemcount ++;
1.236 raeburn 5512: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 5513: my $display = 'none';
1.192 raeburn 5514: if ($currusecredits) {
5515: $display = 'block';
5516: }
5517: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 5518: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
5519: foreach my $type (@types) {
5520: next if ($type eq 'community');
1.306 raeburn 5521: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5522: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 5523: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 5524: }
5525: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 5526: %defaultchecked = ('coursecredits' => 'off');
5527: @toggles = ('coursecredits');
5528: my $current = {
5529: 'coursecredits' => $currusecredits,
5530: };
5531: (my $table,$itemcount) =
5532: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 5533: \%choices,$itemcount,$onclick,$additional,'left');
5534: $datatable .= $table;
5535: $onclick = "toggleDisplay(this.form,'studentsubmission');";
5536: my $display = 'none';
5537: if ($postsubmitclient) {
5538: $display = 'block';
5539: }
5540: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 5541: &mt('Number of seconds submit is disabled').'<br />'.
5542: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
5543: '<table><tr>';
1.257 raeburn 5544: foreach my $type (@types) {
1.306 raeburn 5545: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5546: '<input type="text" name="'.$type.'_timeout" value="'.
5547: $deftimeout{$type}.'" size="5" /></td>';
5548: }
5549: $additional .= '</tr></table></div>'."\n";
5550: %defaultchecked = ('postsubmit' => 'on');
5551: @toggles = ('postsubmit');
1.280 raeburn 5552: $current = {
5553: 'postsubmit' => $postsubmitclient,
5554: };
1.257 raeburn 5555: ($table,$itemcount) =
5556: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
5557: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 5558: $datatable .= $table;
1.276 raeburn 5559: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5560: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5561: $choices{'mysqltables'}.
5562: '</span></td>'.
1.306 raeburn 5563: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 5564: '<table><tr>';
5565: foreach my $type (@types) {
1.306 raeburn 5566: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 5567: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 5568: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 5569: }
5570: $datatable .= '</tr></table></td></tr>'."\n";
5571: $itemcount ++;
5572:
1.139 raeburn 5573: }
1.192 raeburn 5574: $$rowtotal += $itemcount;
1.121 raeburn 5575: return $datatable;
1.118 jms 5576: }
5577:
1.231 raeburn 5578: sub print_selfenrollment {
5579: my ($position,$dom,$settings,$rowtotal) = @_;
5580: my ($css_class,$datatable);
5581: my $itemcount = 1;
1.271 raeburn 5582: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 5583: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 5584: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
5585: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 5586: my @rows;
5587: my $key;
5588: if ($position eq 'top') {
5589: $key = 'admin';
5590: if (ref($rowsref) eq 'ARRAY') {
5591: @rows = @{$rowsref};
5592: }
5593: } elsif ($position eq 'middle') {
5594: $key = 'default';
5595: @rows = ('types','registered','approval','limit');
5596: }
5597: foreach my $row (@rows) {
5598: if (defined($titlesref->{$row})) {
5599: $itemcount ++;
5600: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5601: $datatable .= '<tr'.$css_class.'>'.
5602: '<td>'.$titlesref->{$row}.'</td>'.
5603: '<td class="LC_left_item">'.
5604: '<table><tr>';
5605: my (%current,%currentcap);
5606: if (ref($settings) eq 'HASH') {
5607: if (ref($settings->{$key}) eq 'HASH') {
5608: foreach my $type (@types) {
5609: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5610: $current{$type} = $settings->{$key}->{$type}->{$row};
5611: }
5612: if (($row eq 'limit') && ($key eq 'default')) {
5613: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5614: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
5615: }
5616: }
5617: }
5618: }
5619: }
5620: my %roles = (
5621: '0' => &Apache::lonnet::plaintext('dc'),
5622: );
5623:
5624: foreach my $type (@types) {
5625: unless (($row eq 'registered') && ($key eq 'default')) {
5626: $datatable .= '<th>'.&mt($type).'</th>';
5627: }
5628: }
5629: unless (($row eq 'registered') && ($key eq 'default')) {
5630: $datatable .= '</tr><tr>';
5631: }
5632: foreach my $type (@types) {
5633: if ($type eq 'community') {
5634: $roles{'1'} = &mt('Community personnel');
5635: } else {
5636: $roles{'1'} = &mt('Course personnel');
5637: }
5638: $datatable .= '<td style="vertical-align: top">';
5639: if ($position eq 'top') {
5640: my %checked;
5641: if ($current{$type} eq '0') {
5642: $checked{'0'} = ' checked="checked"';
5643: } else {
5644: $checked{'1'} = ' checked="checked"';
5645: }
5646: foreach my $role ('1','0') {
5647: $datatable .= '<span class="LC_nobreak"><label>'.
5648: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
5649: 'value="'.$role.'"'.$checked{$role}.' />'.
5650: $roles{$role}.'</label></span> ';
5651: }
5652: } else {
5653: if ($row eq 'types') {
5654: my %checked;
5655: if ($current{$type} =~ /^(all|dom)$/) {
5656: $checked{$1} = ' checked="checked"';
5657: } else {
5658: $checked{''} = ' checked="checked"';
5659: }
5660: foreach my $val ('','dom','all') {
5661: $datatable .= '<span class="LC_nobreak"><label>'.
5662: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5663: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5664: }
5665: } elsif ($row eq 'registered') {
5666: my %checked;
5667: if ($current{$type} eq '1') {
5668: $checked{'1'} = ' checked="checked"';
5669: } else {
5670: $checked{'0'} = ' checked="checked"';
5671: }
5672: foreach my $val ('0','1') {
5673: $datatable .= '<span class="LC_nobreak"><label>'.
5674: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5675: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5676: }
5677: } elsif ($row eq 'approval') {
5678: my %checked;
5679: if ($current{$type} =~ /^([12])$/) {
5680: $checked{$1} = ' checked="checked"';
5681: } else {
5682: $checked{'0'} = ' checked="checked"';
5683: }
5684: for my $val (0..2) {
5685: $datatable .= '<span class="LC_nobreak"><label>'.
5686: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5687: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5688: }
5689: } elsif ($row eq 'limit') {
5690: my %checked;
5691: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
5692: $checked{$1} = ' checked="checked"';
5693: } else {
5694: $checked{'none'} = ' checked="checked"';
5695: }
5696: my $cap;
5697: if ($currentcap{$type} =~ /^\d+$/) {
5698: $cap = $currentcap{$type};
5699: }
5700: foreach my $val ('none','allstudents','selfenrolled') {
5701: $datatable .= '<span class="LC_nobreak"><label>'.
5702: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5703: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5704: }
5705: $datatable .= '<br />'.
5706: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
5707: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
5708: '</span>';
5709: }
5710: }
5711: $datatable .= '</td>';
5712: }
5713: $datatable .= '</tr>';
5714: }
5715: $datatable .= '</table></td></tr>';
5716: }
5717: } elsif ($position eq 'bottom') {
1.235 raeburn 5718: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
5719: }
5720: $$rowtotal += $itemcount;
5721: return $datatable;
5722: }
5723:
5724: sub print_validation_rows {
5725: my ($caller,$dom,$settings,$rowtotal) = @_;
5726: my ($itemsref,$namesref,$fieldsref);
5727: if ($caller eq 'selfenroll') {
5728: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
5729: } elsif ($caller eq 'requestcourses') {
5730: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
5731: }
5732: my %currvalidation;
5733: if (ref($settings) eq 'HASH') {
5734: if (ref($settings->{'validation'}) eq 'HASH') {
5735: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 5736: }
1.235 raeburn 5737: }
5738: my $datatable;
5739: my $itemcount = 0;
5740: foreach my $item (@{$itemsref}) {
5741: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5742: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5743: $namesref->{$item}.
5744: '</span></td>'.
5745: '<td class="LC_left_item">';
5746: if (($item eq 'url') || ($item eq 'button')) {
5747: $datatable .= '<span class="LC_nobreak">'.
5748: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
5749: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
5750: } elsif ($item eq 'fields') {
5751: my @currfields;
5752: if (ref($currvalidation{$item}) eq 'ARRAY') {
5753: @currfields = @{$currvalidation{$item}};
5754: }
5755: foreach my $field (@{$fieldsref}) {
5756: my $check = '';
5757: if (grep(/^\Q$field\E$/,@currfields)) {
5758: $check = ' checked="checked"';
5759: }
5760: $datatable .= '<span class="LC_nobreak"><label>'.
5761: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
5762: ' value="'.$field.'"'.$check.' />'.$field.
5763: '</label></span> ';
5764: }
5765: } elsif ($item eq 'markup') {
1.334 raeburn 5766: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 5767: $currvalidation{$item}.
1.231 raeburn 5768: '</textarea>';
1.235 raeburn 5769: }
5770: $datatable .= '</td></tr>'."\n";
5771: if (ref($rowtotal)) {
1.231 raeburn 5772: $itemcount ++;
5773: }
5774: }
1.235 raeburn 5775: if ($caller eq 'requestcourses') {
5776: my %currhash;
1.248 raeburn 5777: if (ref($settings) eq 'HASH') {
5778: if (ref($settings->{'validation'}) eq 'HASH') {
5779: if ($settings->{'validation'}{'dc'} ne '') {
5780: $currhash{$settings->{'validation'}{'dc'}} = 1;
5781: }
1.235 raeburn 5782: }
5783: }
5784: my $numinrow = 2;
5785: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
5786: 'validationdc',%currhash);
1.247 raeburn 5787: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 5788: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 5789: if ($numdc > 1) {
1.247 raeburn 5790: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 5791: } else {
1.247 raeburn 5792: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 5793: }
1.247 raeburn 5794: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 5795: $itemcount ++;
5796: }
5797: if (ref($rowtotal)) {
5798: $$rowtotal += $itemcount;
5799: }
1.231 raeburn 5800: return $datatable;
5801: }
5802:
1.354 raeburn 5803: sub print_passwords {
5804: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
5805: my ($datatable,$css_class);
5806: my $itemcount = 0;
5807: my %titles = &Apache::lonlocal::texthash (
5808: captcha => '"Forgot Password" CAPTCHA validation',
5809: link => 'Reset link expiration (hours)',
5810: case => 'Case-sensitive usernames/e-mail',
5811: prelink => 'Information required (form 1)',
5812: postlink => 'Information required (form 2)',
5813: emailsrc => 'LON-CAPA e-mail address type(s)',
5814: customtext => 'Domain specific text (HTML)',
5815: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
5816: intauth_check => 'Check bcrypt cost if authenticated',
5817: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
5818: permanent => 'Permanent e-mail address',
5819: critical => 'Critical notification address',
5820: notify => 'Notification address',
5821: min => 'Minimum password length',
5822: max => 'Maximum password length',
5823: chars => 'Required characters',
5824: expire => 'Password expiration (days)',
1.356 ! raeburn 5825: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 5826: );
5827: if ($position eq 'top') {
5828: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5829: my $shownlinklife = 2;
5830: my $prelink = 'both';
5831: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
5832: if (ref($settings) eq 'HASH') {
5833: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
5834: $shownlinklife = $settings->{resetlink};
5835: }
5836: if (ref($settings->{resetcase}) eq 'ARRAY') {
5837: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
5838: }
5839: if ($settings->{resetprelink} =~ /^(both|either)$/) {
5840: $prelink = $settings->{resetprelink};
5841: }
5842: if (ref($settings->{resetpostlink}) eq 'HASH') {
5843: %postlink = %{$settings->{resetpostlink}};
5844: }
5845: if (ref($settings->{resetemail}) eq 'ARRAY') {
5846: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
5847: }
5848: if ($settings->{resetremove}) {
5849: $nostdtext = 1;
5850: }
5851: if ($settings->{resetcustom}) {
5852: $customurl = $settings->{resetcustom};
5853: }
5854: } else {
5855: if (ref($types) eq 'ARRAY') {
5856: foreach my $item (@{$types}) {
5857: $casesens{$item} = 1;
5858: $postlink{$item} = ['username','email'];
5859: }
5860: }
5861: $casesens{'default'} = 1;
5862: $postlink{'default'} = ['username','email'];
5863: $prelink = 'both';
5864: %emailsrc = (
5865: permanent => 1,
5866: critical => 1,
5867: notify => 1,
5868: );
5869: }
5870: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
5871: $itemcount ++;
5872: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5873: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
5874: '<td class="LC_left_item">'.
5875: '<input type="textbox" value="'.$shownlinklife.'" '.
5876: 'name="passwords_link" size="3" /></td></tr>';
5877: $itemcount ++;
5878: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5879: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
5880: '<td class="LC_left_item">';
5881: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5882: foreach my $item (@{$types}) {
5883: my $checkedcase;
5884: if ($casesens{$item}) {
5885: $checkedcase = ' checked="checked"';
5886: }
5887: $datatable .= '<span class="LC_nobreak"><label>'.
5888: '<input type="checkbox" name="passwords_case_sensitive" value="'.
5889: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
5890: '<span> ';
5891: }
5892: }
5893: my $checkedcase;
5894: if ($casesens{'default'}) {
5895: $checkedcase = ' checked="checked"';
5896: }
5897: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
5898: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
5899: $othertitle.'</label></span></td>';
5900: $itemcount ++;
5901: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5902: my %checkedpre = (
5903: both => ' checked="checked"',
5904: either => '',
5905: );
5906: if ($prelink eq 'either') {
5907: $checkedpre{either} = ' checked="checked"';
5908: $checkedpre{both} = '';
5909: }
5910: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
5911: '<td class="LC_left_item"><span class="LC_nobreak">'.
5912: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
5913: &mt('Both username and e-mail address').'</label></span> '.
5914: '<span class="LC_nobreak"><label>'.
5915: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
5916: &mt('Either username or e-mail address').'</label></span></td></tr>';
5917: $itemcount ++;
5918: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5919: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
5920: '<td class="LC_left_item">';
5921: my %postlinked;
5922: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5923: foreach my $item (@{$types}) {
5924: undef(%postlinked);
5925: $datatable .= '<fieldset style="display: inline-block;">'.
5926: '<legend>'.$usertypes->{$item}.'</legend>';
5927: if (ref($postlink{$item}) eq 'ARRAY') {
5928: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
5929: }
5930: foreach my $field ('email','username') {
5931: my $checked;
5932: if ($postlinked{$field}) {
5933: $checked = ' checked="checked"';
5934: }
5935: $datatable .= '<span class="LC_nobreak"><label>'.
5936: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
5937: $field.'"'.$checked.' />'.$field.'</label>'.
5938: '<span> ';
5939: }
5940: $datatable .= '</fieldset>';
5941: }
5942: }
5943: if (ref($postlink{'default'}) eq 'ARRAY') {
5944: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
5945: }
5946: $datatable .= '<fieldset style="display: inline-block;">'.
5947: '<legend>'.$othertitle.'</legend>';
5948: foreach my $field ('email','username') {
5949: my $checked;
5950: if ($postlinked{$field}) {
5951: $checked = ' checked="checked"';
5952: }
5953: $datatable .= '<span class="LC_nobreak"><label>'.
5954: '<input type="checkbox" name="passwords_postlink_default" value="'.
5955: $field.'"'.$checked.' />'.$field.'</label>'.
5956: '<span> ';
5957: }
5958: $datatable .= '</fieldset></td></tr>';
5959: $itemcount ++;
5960: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5961: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
5962: '<td class="LC_left_item">';
5963: foreach my $type ('permanent','critical','notify') {
5964: my $checkedemail;
5965: if ($emailsrc{$type}) {
5966: $checkedemail = ' checked="checked"';
5967: }
5968: $datatable .= '<span class="LC_nobreak"><label>'.
5969: '<input type="checkbox" name="passwords_emailsrc" value="'.
5970: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
5971: '<span> ';
5972: }
5973: $datatable .= '</td></tr>';
5974: $itemcount ++;
5975: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5976: my $switchserver = &check_switchserver($dom,$confname);
5977: my ($showstd,$noshowstd);
5978: if ($nostdtext) {
5979: $noshowstd = ' checked="checked"';
5980: } else {
5981: $showstd = ' checked="checked"';
5982: }
5983: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
5984: '<td class="LC_left_item"><span class="LC_nobreak">'.
5985: &mt('Retain standard text:').
5986: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
5987: &mt('Yes').'</label>'.' '.
5988: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
5989: &mt('No').'</label></span><br />'.
5990: '<span class="LC_fontsize_small">'.
5991: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
5992: &mt('Include custom text:');
5993: if ($customurl) {
5994: my $link = &Apache::loncommon::modal_link($customurl,&mt('Custom text file'),600,500,
5995: undef,undef,undef,undef,'background-color:#ffffff');
5996: $datatable .= '<span class="LC_nobreak"> '.$link.
5997: '<label><input type="checkbox" name="passwords_custom_del"'.
5998: ' value="1" />'.&mt('Delete?').'</label></span>'.
5999: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
6000: }
6001: if ($switchserver) {
6002: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
6003: } else {
6004: $datatable .='<span class="LC_nobreak"> '.
6005: '<input type="file" name="passwords_customfile" /></span>';
6006: }
6007: $datatable .= '</td></tr>';
6008: } elsif ($position eq 'middle') {
6009: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
6010: my @items = ('intauth_cost','intauth_check','intauth_switch');
6011: my %defaults;
6012: if (ref($domconf{'defaults'}) eq 'HASH') {
6013: %defaults = %{$domconf{'defaults'}};
6014: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
6015: $defaults{'intauth_cost'} = 10;
6016: }
6017: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
6018: $defaults{'intauth_check'} = 0;
6019: }
6020: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
6021: $defaults{'intauth_switch'} = 0;
6022: }
6023: } else {
6024: %defaults = (
6025: 'intauth_cost' => 10,
6026: 'intauth_check' => 0,
6027: 'intauth_switch' => 0,
6028: );
6029: }
6030: foreach my $item (@items) {
6031: if ($itemcount%2) {
6032: $css_class = '';
6033: } else {
6034: $css_class = ' class="LC_odd_row" ';
6035: }
6036: $datatable .= '<tr'.$css_class.'>'.
6037: '<td><span class="LC_nobreak">'.$titles{$item}.
6038: '</span></td><td class="LC_left_item" colspan="3">';
6039: if ($item eq 'intauth_switch') {
6040: my @options = (0,1,2);
6041: my %optiondesc = &Apache::lonlocal::texthash (
6042: 0 => 'No',
6043: 1 => 'Yes',
6044: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
6045: );
6046: $datatable .= '<table width="100%">';
6047: foreach my $option (@options) {
6048: my $checked = ' ';
6049: if ($defaults{$item} eq $option) {
6050: $checked = ' checked="checked"';
6051: }
6052: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6053: '<label><input type="radio" name="'.$item.
6054: '" value="'.$option.'"'.$checked.' />'.
6055: $optiondesc{$option}.'</label></span></td></tr>';
6056: }
6057: $datatable .= '</table>';
6058: } elsif ($item eq 'intauth_check') {
6059: my @options = (0,1,2);
6060: my %optiondesc = &Apache::lonlocal::texthash (
6061: 0 => 'No',
6062: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
6063: 2 => 'Yes, disallow login if stored cost is less than domain default',
6064: );
6065: $datatable .= '<table width="100%">';
6066: foreach my $option (@options) {
6067: my $checked = ' ';
6068: my $onclick;
6069: if ($defaults{$item} eq $option) {
6070: $checked = ' checked="checked"';
6071: }
6072: if ($option == 2) {
6073: $onclick = ' onclick="javascript:warnIntAuth(this);"';
6074: }
6075: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6076: '<label><input type="radio" name="'.$item.
6077: '" value="'.$option.'"'.$checked.$onclick.' />'.
6078: $optiondesc{$option}.'</label></span></td></tr>';
6079: }
6080: $datatable .= '</table>';
6081: } else {
6082: $datatable .= '<input type="text" name="'.$item.'" value="'.
6083: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
6084: }
6085: $datatable .= '</td></tr>';
6086: $itemcount ++;
6087: }
6088: } elsif ($position eq 'lower') {
1.356 ! raeburn 6089: my ($min,$max,%chars,$expire,$numsaved);
1.354 raeburn 6090: if (ref($settings) eq 'HASH') {
6091: if ($settings->{min}) {
6092: $min = $settings->{min};
6093: }
6094: if ($settings->{max}) {
6095: $max = $settings->{max};
6096: }
6097: if (ref($settings->{chars}) eq 'ARRAY') {
6098: map { $chars{$_} = 1; } (@{$settings->{chars}});
6099: }
6100: if ($settings->{expire}) {
6101: $expire = $settings->{expire};
6102: }
1.356 ! raeburn 6103: if ($settings->(numsaved}) {
! 6104: $numsaved = $settings->(numsaved};
! 6105: }
1.354 raeburn 6106: } else {
6107: $min = '7';
6108: }
6109: my %rulenames = &Apache::lonlocal::texthash(
6110: uc => 'At least one upper case letter',
6111: lc => 'At least one lower case letter',
6112: num => 'At least one number',
6113: spec => 'At least one non-alphanumeric',
6114: );
6115: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6116: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
6117: '<td class="LC_left_item"><span class="LC_nobreak">'.
6118: '<input type="text" name="passwords_min" value="'.$min.'" size="3" />'.
6119: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no minimum)').'</span>'.
6120: '</span></td></tr>';
6121: $itemcount ++;
6122: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6123: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
6124: '<td class="LC_left_item"><span class="LC_nobreak">'.
6125: '<input type="text" name="passwords_max" value="'.$max.'" size="3" />'.
6126: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
6127: '</span></td></tr>';
6128: $itemcount ++;
6129: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6130: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
6131: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
6132: '</span></td>';
6133: my $numinrow = 2;
6134: my @possrules = ('uc','lc','num','spec');
6135: $datatable .= '<td class="LC_left_item"><table>';
6136: for (my $i=0; $i<@possrules; $i++) {
6137: my ($rem,$checked);
6138: if ($chars{$possrules[$i]}) {
6139: $checked = ' checked="checked"';
6140: }
6141: $rem = $i%($numinrow);
6142: if ($rem == 0) {
6143: if ($i > 0) {
6144: $datatable .= '</tr>';
6145: }
6146: $datatable .= '<tr>';
6147: }
6148: $datatable .= '<td><span class="LC_nobreak"><label>'.
6149: '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
6150: $rulenames{$possrules[$i]}.'</label></span></td>';
6151: }
6152: my $rem = @possrules%($numinrow);
6153: my $colsleft = $numinrow - $rem;
6154: if ($colsleft > 1 ) {
6155: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6156: ' </td>';
6157: } elsif ($colsleft == 1) {
6158: $datatable .= '<td class="LC_left_item"> </td>';
6159: }
6160: $datatable .='</table></td></tr>';
6161: $itemcount ++;
6162: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6163: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
6164: '<td class="LC_left_item"><span class="LC_nobreak">'.
6165: '<input type="text" name="passwords_expire" value="'.$expire.'" size="4" />'.
6166: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
6167: '</span></td></tr>';
1.356 ! raeburn 6168: $itemcount ++;
! 6169: $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 6170: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
! 6171: '<td class="LC_left_item"><span class="LC_nobreak">'.
! 6172: '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" />'.
! 6173: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
! 6174: '</span></td></tr>';
1.354 raeburn 6175: } else {
6176: my $checkedon;
6177: my $checkedoff = ' checked="checked"';
6178: if (ref($settings) eq 'HASH') {
6179: if ($settings->{crsownerchg}) {
6180: $checkedon = $checkedoff;
6181: $checkedoff = '';
6182: }
6183: }
6184: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6185: $datatable .= '<tr '.$css_class.'>'.
6186: '<td>'.
6187: &mt('Requirements').'<ul>'.
6188: '<li>'.&mt("Course 'type' is not a Community").'</li>'.
6189: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
6190: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
6191: '</ul>'.
6192: '</td>'.
6193: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
6194: '<label><input type="radio" name="passwords_crsowner" value="1"'.$checkedon.' />'.&mt('Yes').'</label></span> '.
6195: '<span class="LC_nobreak"><label><input type="radio" name="passwords_crsowner" value="0"'.$checkedoff.' />'.
6196: &mt('No').'</label></span>'.
6197: '</td></tr>';
6198:
6199: }
6200: return $datatable;
6201: }
6202:
1.137 raeburn 6203: sub print_usersessions {
6204: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 6205: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 6206: my (%by_ip,%by_location,@intdoms,@instdoms);
6207: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 6208:
6209: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 6210: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 6211: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 6212: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 6213: if ($position eq 'top') {
1.152 raeburn 6214: if (keys(%serverhomes) > 1) {
1.145 raeburn 6215: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 6216: my $curroffloadnow;
6217: if (ref($settings) eq 'HASH') {
6218: if (ref($settings->{'offloadnow'}) eq 'HASH') {
6219: $curroffloadnow = $settings->{'offloadnow'};
6220: }
6221: }
6222: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 6223: } else {
1.140 raeburn 6224: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 6225: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
6226: '</td></tr>';
1.140 raeburn 6227: }
1.137 raeburn 6228: } else {
1.279 raeburn 6229: my %titles = &usersession_titles();
6230: my ($prefix,@types);
6231: if ($position eq 'bottom') {
6232: $prefix = 'remote';
6233: @types = ('version','excludedomain','includedomain');
1.145 raeburn 6234: } else {
1.279 raeburn 6235: $prefix = 'hosted';
6236: @types = ('excludedomain','includedomain');
6237: }
6238: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
6239: }
6240: $$rowtotal += $itemcount;
6241: return $datatable;
6242: }
6243:
6244: sub rules_by_location {
6245: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
6246: my ($datatable,$itemcount,$css_class);
6247: if (keys(%{$by_location}) == 0) {
6248: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6249: $datatable = '<tr'.$css_class.'><td colspan="2">'.
6250: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
6251: '</td></tr>';
6252: $itemcount = 1;
6253: } else {
6254: $itemcount = 0;
6255: my $numinrow = 5;
6256: my (%current,%checkedon,%checkedoff);
6257: my @locations = sort(keys(%{$by_location}));
6258: foreach my $type (@{$types}) {
6259: $checkedon{$type} = '';
6260: $checkedoff{$type} = ' checked="checked"';
6261: }
6262: if (ref($settings) eq 'HASH') {
6263: if (ref($settings->{$prefix}) eq 'HASH') {
6264: foreach my $key (keys(%{$settings->{$prefix}})) {
6265: $current{$key} = $settings->{$prefix}{$key};
6266: if ($key eq 'version') {
6267: if ($current{$key} ne '') {
1.145 raeburn 6268: $checkedon{$key} = ' checked="checked"';
6269: $checkedoff{$key} = '';
6270: }
1.279 raeburn 6271: } elsif (ref($current{$key}) eq 'ARRAY') {
6272: $checkedon{$key} = ' checked="checked"';
6273: $checkedoff{$key} = '';
1.137 raeburn 6274: }
6275: }
6276: }
1.279 raeburn 6277: }
6278: foreach my $type (@{$types}) {
6279: next if ($type ne 'version' && !@locations);
6280: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6281: $datatable .= '<tr'.$css_class.'>
6282: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
6283: <span class="LC_nobreak">
6284: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
6285: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
6286: if ($type eq 'version') {
6287: my @lcversions = &Apache::lonnet::all_loncaparevs();
6288: my $selector = '<select name="'.$prefix.'_version">';
6289: foreach my $version (@lcversions) {
6290: my $selected = '';
6291: if ($current{'version'} eq $version) {
6292: $selected = ' selected="selected"';
1.145 raeburn 6293: }
1.279 raeburn 6294: $selector .= ' <option value="'.$version.'"'.
6295: $selected.'>'.$version.'</option>';
6296: }
6297: $selector .= '</select> ';
6298: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
6299: } else {
6300: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
6301: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
6302: ' />'.(' 'x2).
6303: '<input type="button" value="'.&mt('uncheck all').'" '.
6304: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
6305: "\n".
6306: '</div><div><table>';
6307: my $rem;
6308: for (my $i=0; $i<@locations; $i++) {
6309: my ($showloc,$value,$checkedtype);
6310: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
6311: my $ip = $by_location->{$locations[$i]}->[0];
6312: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6313: $value = join(':',@{$by_ip->{$ip}});
6314: $showloc = join(', ',@{$by_ip->{$ip}});
6315: if (ref($current{$type}) eq 'ARRAY') {
6316: foreach my $loc (@{$by_ip->{$ip}}) {
6317: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
6318: $checkedtype = ' checked="checked"';
6319: last;
1.145 raeburn 6320: }
1.138 raeburn 6321: }
6322: }
6323: }
1.137 raeburn 6324: }
1.279 raeburn 6325: $rem = $i%($numinrow);
6326: if ($rem == 0) {
6327: if ($i > 0) {
6328: $datatable .= '</tr>';
6329: }
6330: $datatable .= '<tr>';
6331: }
6332: $datatable .= '<td class="LC_left_item">'.
6333: '<span class="LC_nobreak"><label>'.
6334: '<input type="checkbox" name="'.$prefix.'_'.$type.
6335: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
6336: '</label></span></td>';
6337: }
6338: $rem = @locations%($numinrow);
6339: my $colsleft = $numinrow - $rem;
6340: if ($colsleft > 1 ) {
6341: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6342: ' </td>';
6343: } elsif ($colsleft == 1) {
6344: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 6345: }
1.279 raeburn 6346: $datatable .= '</tr></table>';
1.137 raeburn 6347: }
1.279 raeburn 6348: $datatable .= '</td></tr>';
6349: $itemcount ++;
1.137 raeburn 6350: }
6351: }
1.279 raeburn 6352: return ($datatable,$itemcount);
1.137 raeburn 6353: }
6354:
1.275 raeburn 6355: sub print_ssl {
6356: my ($position,$dom,$settings,$rowtotal) = @_;
6357: my ($css_class,$datatable);
6358: my $itemcount = 1;
6359: if ($position eq 'top') {
1.281 raeburn 6360: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6361: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6362: my $same_institution;
6363: if ($intdom ne '') {
6364: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
6365: if (ref($internet_names) eq 'ARRAY') {
6366: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
6367: $same_institution = 1;
6368: }
6369: }
6370: }
1.275 raeburn 6371: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 6372: $datatable = '<tr'.$css_class.'><td colspan="2">';
6373: if ($same_institution) {
6374: my %domservers = &Apache::lonnet::get_servers($dom);
6375: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
6376: } else {
6377: $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.");
6378: }
6379: $datatable .= '</td></tr>';
1.275 raeburn 6380: $itemcount ++;
6381: } else {
6382: my %titles = &ssl_titles();
6383: my (%by_ip,%by_location,@intdoms,@instdoms);
6384: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
6385: my @alldoms = &Apache::lonnet::all_domains();
6386: my %serverhomes = %Apache::lonnet::serverhomeIDs;
6387: my @domservers = &Apache::lonnet::get_servers($dom);
6388: my %servers = &Apache::lonnet::internet_dom_servers($dom);
6389: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 6390: if (($position eq 'connto') || ($position eq 'connfrom')) {
6391: my $legacy;
6392: unless (ref($settings) eq 'HASH') {
6393: my $name;
6394: if ($position eq 'connto') {
6395: $name = 'loncAllowInsecure';
6396: } else {
6397: $name = 'londAllowInsecure';
6398: }
6399: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
6400: my @ids=&Apache::lonnet::current_machine_ids();
6401: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
6402: my %what = (
6403: $name => 1,
6404: );
6405: my ($result,$returnhash) =
6406: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
6407: if ($result eq 'ok') {
6408: if (ref($returnhash) eq 'HASH') {
6409: $legacy = $returnhash->{$name};
6410: }
6411: }
6412: } else {
6413: $legacy = $Apache::lonnet::perlvar{$name};
6414: }
6415: }
1.275 raeburn 6416: foreach my $type ('dom','intdom','other') {
6417: my %checked;
6418: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6419: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
6420: '<td class="LC_right_item">';
6421: my $skip;
6422: if ($type eq 'dom') {
6423: unless (keys(%servers) > 1) {
6424: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
6425: $skip = 1;
6426: }
6427: }
6428: if ($type eq 'intdom') {
6429: unless (@instdoms > 1) {
6430: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
6431: $skip = 1;
6432: }
6433: } elsif ($type eq 'other') {
6434: if (keys(%by_location) == 0) {
6435: $datatable .= &mt('Nothing to set here, as there are no other institutions');
6436: $skip = 1;
6437: }
6438: }
6439: unless ($skip) {
6440: $checked{'yes'} = ' checked="checked"';
6441: if (ref($settings) eq 'HASH') {
1.293 raeburn 6442: if (ref($settings->{$position}) eq 'HASH') {
6443: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 6444: $checked{$1} = $checked{'yes'};
6445: delete($checked{'yes'});
6446: }
6447: }
1.293 raeburn 6448: } else {
6449: if ($legacy == 0) {
6450: $checked{'req'} = $checked{'yes'};
6451: delete($checked{'yes'});
6452: }
1.275 raeburn 6453: }
6454: foreach my $option ('no','yes','req') {
6455: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 6456: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 6457: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
6458: '</label></span>'.(' 'x2);
6459: }
6460: }
6461: $datatable .= '</td></tr>';
6462: $itemcount ++;
6463: }
6464: } else {
6465: my $prefix = 'replication';
6466: my @types = ('certreq','nocertreq');
1.279 raeburn 6467: if (keys(%by_location) == 0) {
6468: $datatable .= '<tr'.$css_class.'><td>'.
6469: &mt('Nothing to set here, as there are no other institutions').
6470: '</td></tr>';
6471: $itemcount ++;
1.275 raeburn 6472: } else {
1.279 raeburn 6473: ($datatable,$itemcount) =
6474: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 6475: }
6476: }
6477: }
6478: $$rowtotal += $itemcount;
6479: return $datatable;
6480: }
6481:
6482: sub ssl_titles {
6483: return &Apache::lonlocal::texthash (
6484: dom => 'LON-CAPA servers/VMs from same domain',
6485: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
6486: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 6487: connto => 'Connections to other servers',
6488: connfrom => 'Connections from other servers',
1.275 raeburn 6489: replication => 'Replicating content to other institutions',
6490: certreq => 'Client certificate required, but specific domains exempt',
6491: nocertreq => 'No client certificate required, except for specific domains',
6492: no => 'SSL not used',
6493: yes => 'SSL Optional (used if available)',
6494: req => 'SSL Required',
6495: );
1.279 raeburn 6496: }
6497:
6498: sub print_trust {
6499: my ($prefix,$dom,$settings,$rowtotal) = @_;
6500: my ($css_class,$datatable,%checked,%choices);
6501: my (%by_ip,%by_location,@intdoms,@instdoms);
6502: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
6503: my $itemcount = 1;
6504: my %titles = &trust_titles();
6505: my @types = ('exc','inc');
6506: if ($prefix eq 'top') {
6507: $prefix = 'content';
6508: } elsif ($prefix eq 'bottom') {
6509: $prefix = 'msg';
6510: }
6511: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
6512: $$rowtotal += $itemcount;
6513: return $datatable;
6514: }
6515:
6516: sub trust_titles {
6517: return &Apache::lonlocal::texthash(
6518: content => "Access to this domain's content by others",
6519: shared => "Access to other domain's content by this domain",
6520: enroll => "Enrollment in this domain's courses by others",
6521: othcoau => "Co-author roles in this domain for others",
6522: coaurem => "Co-author roles for this domain's users elsewhere",
6523: domroles => "Domain roles in this domain assignable to others",
6524: catalog => "Course Catalog for this domain displayed elsewhere",
6525: reqcrs => "Requests for creation of courses in this domain by others",
6526: msg => "Users in other domains can send messages to this domain",
6527: exc => "Allow all, but exclude specific domains",
6528: inc => "Deny all, but include specific domains",
6529: );
1.275 raeburn 6530: }
6531:
1.138 raeburn 6532: sub build_location_hashes {
1.275 raeburn 6533: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 6534: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 6535: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 6536: my %iphost = &Apache::lonnet::get_iphost();
6537: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
6538: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
6539: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
6540: foreach my $id (@{$iphost{$primary_ip}}) {
6541: my $intdom = &Apache::lonnet::internet_dom($id);
6542: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
6543: push(@{$intdoms},$intdom);
6544: }
6545: }
6546: }
6547: foreach my $ip (keys(%iphost)) {
6548: if (ref($iphost{$ip}) eq 'ARRAY') {
6549: foreach my $id (@{$iphost{$ip}}) {
6550: my $location = &Apache::lonnet::internet_dom($id);
6551: if ($location) {
1.275 raeburn 6552: if (grep(/^\Q$location\E$/,@{$intdoms})) {
6553: my $dom = &Apache::lonnet::host_domain($id);
6554: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
6555: push(@{$instdoms},$dom);
6556: }
6557: next;
6558: }
1.138 raeburn 6559: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6560: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
6561: push(@{$by_ip->{$ip}},$location);
6562: }
6563: } else {
6564: $by_ip->{$ip} = [$location];
6565: }
6566: }
6567: }
6568: }
6569: }
6570: foreach my $ip (sort(keys(%{$by_ip}))) {
6571: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6572: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
6573: my $first = $by_ip->{$ip}->[0];
6574: if (ref($by_location->{$first}) eq 'ARRAY') {
6575: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
6576: push(@{$by_location->{$first}},$ip);
6577: }
6578: } else {
6579: $by_location->{$first} = [$ip];
6580: }
6581: }
6582: }
6583: return;
6584: }
6585:
1.145 raeburn 6586: sub current_offloads_to {
6587: my ($dom,$settings,$servers) = @_;
6588: my (%spareid,%otherdomconfigs);
1.152 raeburn 6589: if (ref($servers) eq 'HASH') {
1.145 raeburn 6590: foreach my $lonhost (sort(keys(%{$servers}))) {
6591: my $gotspares;
1.152 raeburn 6592: if (ref($settings) eq 'HASH') {
6593: if (ref($settings->{'spares'}) eq 'HASH') {
6594: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
6595: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
6596: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
6597: $gotspares = 1;
6598: }
1.145 raeburn 6599: }
6600: }
6601: unless ($gotspares) {
6602: my $gotspares;
6603: my $serverhomeID =
6604: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
6605: my $serverhomedom =
6606: &Apache::lonnet::host_domain($serverhomeID);
6607: if ($serverhomedom ne $dom) {
6608: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
6609: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
6610: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
6611: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
6612: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
6613: $gotspares = 1;
6614: }
6615: }
6616: } else {
6617: $otherdomconfigs{$serverhomedom} =
6618: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
6619: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
6620: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
6621: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
6622: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
6623: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
6624: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
6625: $gotspares = 1;
6626: }
6627: }
6628: }
6629: }
6630: }
6631: }
6632: }
6633: unless ($gotspares) {
6634: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
6635: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6636: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6637: } else {
6638: my $server_hostname = &Apache::lonnet::hostname($lonhost);
6639: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
6640: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
6641: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6642: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6643: } else {
1.150 raeburn 6644: my %what = (
6645: spareid => 1,
6646: );
6647: my ($result,$returnhash) =
6648: &Apache::lonnet::get_remote_globals($lonhost,\%what);
6649: if ($result eq 'ok') {
6650: if (ref($returnhash) eq 'HASH') {
6651: if (ref($returnhash->{'spareid'}) eq 'HASH') {
6652: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
6653: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
6654: }
6655: }
1.145 raeburn 6656: }
6657: }
6658: }
6659: }
6660: }
6661: }
6662: return %spareid;
6663: }
6664:
6665: sub spares_row {
1.261 raeburn 6666: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 6667: my $css_class;
6668: my $numinrow = 4;
6669: my $itemcount = 1;
6670: my $datatable;
1.152 raeburn 6671: my %typetitles = &sparestype_titles();
6672: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 6673: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 6674: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
6675: my ($othercontrol,$serverdom);
6676: if ($serverhome ne $server) {
6677: $serverdom = &Apache::lonnet::host_domain($serverhome);
6678: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6679: } else {
6680: $serverdom = &Apache::lonnet::host_domain($server);
6681: if ($serverdom ne $dom) {
6682: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6683: }
6684: }
6685: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 6686: my $checkednow;
6687: if (ref($curroffloadnow) eq 'HASH') {
6688: if ($curroffloadnow->{$server}) {
6689: $checkednow = ' checked="checked"';
6690: }
6691: }
1.145 raeburn 6692: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6693: $datatable .= '<tr'.$css_class.'>
6694: <td rowspan="2">
1.183 bisitz 6695: <span class="LC_nobreak">'.
6696: &mt('[_1] when busy, offloads to:'
1.261 raeburn 6697: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 6698: '<span class="LC_nobreak">'."\n".
1.261 raeburn 6699: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
6700: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 6701: "\n";
1.145 raeburn 6702: my (%current,%canselect);
1.152 raeburn 6703: my @choices =
6704: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
6705: foreach my $type ('primary','default') {
6706: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 6707: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
6708: my @spares = @{$spareid->{$server}{$type}};
6709: if (@spares > 0) {
1.152 raeburn 6710: if ($othercontrol) {
6711: $current{$type} = join(', ',@spares);
6712: } else {
6713: $current{$type} .= '<table>';
6714: my $numspares = scalar(@spares);
6715: for (my $i=0; $i<@spares; $i++) {
6716: my $rem = $i%($numinrow);
6717: if ($rem == 0) {
6718: if ($i > 0) {
6719: $current{$type} .= '</tr>';
6720: }
6721: $current{$type} .= '<tr>';
1.145 raeburn 6722: }
1.152 raeburn 6723: $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'".');" /> '.
6724: $spareid->{$server}{$type}[$i].
6725: '</label></td>'."\n";
6726: }
6727: my $rem = @spares%($numinrow);
6728: my $colsleft = $numinrow - $rem;
6729: if ($colsleft > 1 ) {
6730: $current{$type} .= '<td colspan="'.$colsleft.
6731: '" class="LC_left_item">'.
6732: ' </td>';
6733: } elsif ($colsleft == 1) {
6734: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 6735: }
1.152 raeburn 6736: $current{$type} .= '</tr></table>';
1.150 raeburn 6737: }
1.145 raeburn 6738: }
6739: }
6740: if ($current{$type} eq '') {
6741: $current{$type} = &mt('None specified');
6742: }
1.152 raeburn 6743: if ($othercontrol) {
6744: if ($type eq 'primary') {
6745: $canselect{$type} = $othercontrol;
6746: }
6747: } else {
6748: $canselect{$type} =
6749: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
6750: '<select name="newspare_'.$type.'_'.$server.'" '.
6751: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
6752: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
6753: if (@choices > 0) {
6754: foreach my $lonhost (@choices) {
6755: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
6756: }
6757: }
6758: $canselect{$type} .= '</select>'."\n";
6759: }
6760: } else {
6761: $current{$type} = &mt('Could not be determined');
6762: if ($type eq 'primary') {
6763: $canselect{$type} = $othercontrol;
6764: }
1.145 raeburn 6765: }
1.152 raeburn 6766: if ($type eq 'default') {
6767: $datatable .= '<tr'.$css_class.'>';
6768: }
6769: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
6770: '<td>'.$current{$type}.'</td>'."\n".
6771: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 6772: }
6773: $itemcount ++;
6774: }
6775: }
6776: $$rowtotal += $itemcount;
6777: return $datatable;
6778: }
6779:
1.152 raeburn 6780: sub possible_newspares {
6781: my ($server,$currspares,$serverhomes,$altids) = @_;
6782: my $serverhostname = &Apache::lonnet::hostname($server);
6783: my %excluded;
6784: if ($serverhostname ne '') {
6785: %excluded = (
6786: $serverhostname => 1,
6787: );
6788: }
6789: if (ref($currspares) eq 'HASH') {
6790: foreach my $type (keys(%{$currspares})) {
6791: if (ref($currspares->{$type}) eq 'ARRAY') {
6792: if (@{$currspares->{$type}} > 0) {
6793: foreach my $curr (@{$currspares->{$type}}) {
6794: my $hostname = &Apache::lonnet::hostname($curr);
6795: $excluded{$hostname} = 1;
6796: }
6797: }
6798: }
6799: }
6800: }
6801: my @choices;
6802: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
6803: if (keys(%{$serverhomes}) > 1) {
6804: foreach my $name (sort(keys(%{$serverhomes}))) {
6805: unless ($excluded{$name}) {
6806: if (exists($altids->{$serverhomes->{$name}})) {
6807: push(@choices,$altids->{$serverhomes->{$name}});
6808: } else {
6809: push(@choices,$serverhomes->{$name});
1.145 raeburn 6810: }
6811: }
6812: }
6813: }
6814: }
1.152 raeburn 6815: return sort(@choices);
1.145 raeburn 6816: }
6817:
1.150 raeburn 6818: sub print_loadbalancing {
6819: my ($dom,$settings,$rowtotal) = @_;
6820: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6821: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6822: my $numinrow = 1;
6823: my $datatable;
6824: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 6825: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 6826: if (ref($settings) eq 'HASH') {
6827: %existing = %{$settings};
6828: }
6829: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
6830: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 6831: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 6832: } else {
6833: return;
6834: }
6835: my ($othertitle,$usertypes,$types) =
6836: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 6837: my $rownum = 8;
1.150 raeburn 6838: if (ref($types) eq 'ARRAY') {
6839: $rownum += scalar(@{$types});
6840: }
1.171 raeburn 6841: my @css_class = ('LC_odd_row','LC_even_row');
6842: my $balnum = 0;
6843: my $islast;
6844: my (@toshow,$disabledtext);
6845: if (keys(%currbalancer) > 0) {
6846: @toshow = sort(keys(%currbalancer));
6847: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
6848: push(@toshow,'');
6849: }
6850: } else {
6851: @toshow = ('');
6852: $disabledtext = &mt('No existing load balancer');
6853: }
6854: foreach my $lonhost (@toshow) {
6855: if ($balnum == scalar(@toshow)-1) {
6856: $islast = 1;
6857: } else {
6858: $islast = 0;
6859: }
6860: my $cssidx = $balnum%2;
6861: my $targets_div_style = 'display: none';
6862: my $disabled_div_style = 'display: block';
6863: my $homedom_div_style = 'display: none';
6864: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 6865: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 6866: '<p>';
6867: if ($lonhost eq '') {
1.210 raeburn 6868: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 6869: if (keys(%currbalancer) > 0) {
6870: $datatable .= &mt('Add balancer:');
6871: } else {
6872: $datatable .= &mt('Enable balancer:');
6873: }
6874: $datatable .= ' '.
6875: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
6876: ' id="loadbalancing_lonhost_'.$balnum.'"'.
6877: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
6878: '<option value="" selected="selected">'.&mt('None').
6879: '</option>'."\n";
6880: foreach my $server (sort(keys(%servers))) {
6881: next if ($currbalancer{$server});
6882: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
6883: }
1.210 raeburn 6884: $datatable .=
1.171 raeburn 6885: '</select>'."\n".
6886: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
6887: } else {
6888: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
6889: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
6890: &mt('Stop balancing').'</label>'.
6891: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
6892: $targets_div_style = 'display: block';
6893: $disabled_div_style = 'display: none';
6894: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
6895: $homedom_div_style = 'display: block';
6896: }
6897: }
1.306 raeburn 6898: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 6899: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
6900: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
6901: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
6902: my ($numspares,@spares) = &count_servers($lonhost,%servers);
6903: my @sparestypes = ('primary','default');
6904: my %typetitles = &sparestype_titles();
1.284 raeburn 6905: my %hostherechecked = (
6906: no => ' checked="checked"',
6907: );
1.342 raeburn 6908: my %balcookiechecked = (
6909: no => ' checked="checked"',
6910: );
1.171 raeburn 6911: foreach my $sparetype (@sparestypes) {
6912: my $targettable;
6913: for (my $i=0; $i<$numspares; $i++) {
6914: my $checked;
6915: if (ref($currtargets{$lonhost}) eq 'HASH') {
6916: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6917: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6918: $checked = ' checked="checked"';
6919: }
6920: }
6921: }
6922: my ($chkboxval,$disabled);
6923: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
6924: $chkboxval = $spares[$i];
6925: }
6926: if (exists($currbalancer{$spares[$i]})) {
6927: $disabled = ' disabled="disabled"';
6928: }
1.210 raeburn 6929: $targettable .=
1.253 raeburn 6930: '<td><span class="LC_nobreak"><label>'.
6931: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 6932: $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 6933: '</span></label></span></td>';
1.171 raeburn 6934: my $rem = $i%($numinrow);
6935: if ($rem == 0) {
6936: if (($i > 0) && ($i < $numspares-1)) {
6937: $targettable .= '</tr>';
6938: }
6939: if ($i < $numspares-1) {
6940: $targettable .= '<tr>';
1.150 raeburn 6941: }
6942: }
6943: }
1.171 raeburn 6944: if ($targettable ne '') {
6945: my $rem = $numspares%($numinrow);
6946: my $colsleft = $numinrow - $rem;
6947: if ($colsleft > 1 ) {
6948: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6949: ' </td>';
6950: } elsif ($colsleft == 1) {
6951: $targettable .= '<td class="LC_left_item"> </td>';
6952: }
6953: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
6954: '<table><tr>'.$targettable.'</tr></table><br />';
6955: }
1.284 raeburn 6956: $hostherechecked{$sparetype} = '';
6957: if (ref($currtargets{$lonhost}) eq 'HASH') {
6958: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6959: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6960: $hostherechecked{$sparetype} = ' checked="checked"';
6961: $hostherechecked{'no'} = '';
6962: }
6963: }
6964: }
6965: }
1.342 raeburn 6966: if ($currcookies{$lonhost}) {
6967: %balcookiechecked = (
6968: yes => ' checked="checked"',
6969: );
6970: }
1.284 raeburn 6971: $datatable .= &mt('Hosting on balancer itself').'<br />'.
6972: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
6973: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
6974: foreach my $sparetype (@sparestypes) {
6975: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
6976: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
6977: '</i></label><br />';
1.171 raeburn 6978: }
1.342 raeburn 6979: $datatable .= &mt('Use balancer cookie').'<br />'.
6980: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
6981: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
6982: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
6983: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
6984: '</div></td></tr>'.
1.171 raeburn 6985: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
6986: $othertitle,$usertypes,$types,\%servers,
6987: \%currbalancer,$lonhost,
6988: $targets_div_style,$homedom_div_style,
6989: $css_class[$cssidx],$balnum,$islast);
6990: $$rowtotal += $rownum;
6991: $balnum ++;
6992: }
6993: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
6994: return $datatable;
6995: }
6996:
6997: sub get_loadbalancers_config {
1.342 raeburn 6998: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 6999: return unless ((ref($servers) eq 'HASH') &&
7000: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 7001: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
7002: (ref($currcookies) eq 'HASH'));
1.171 raeburn 7003: if (keys(%{$existing}) > 0) {
7004: my $oldlonhost;
7005: foreach my $key (sort(keys(%{$existing}))) {
7006: if ($key eq 'lonhost') {
7007: $oldlonhost = $existing->{'lonhost'};
7008: $currbalancer->{$oldlonhost} = 1;
7009: } elsif ($key eq 'targets') {
7010: if ($oldlonhost) {
7011: $currtargets->{$oldlonhost} = $existing->{'targets'};
7012: }
7013: } elsif ($key eq 'rules') {
7014: if ($oldlonhost) {
7015: $currrules->{$oldlonhost} = $existing->{'rules'};
7016: }
7017: } elsif (ref($existing->{$key}) eq 'HASH') {
7018: $currbalancer->{$key} = 1;
7019: $currtargets->{$key} = $existing->{$key}{'targets'};
7020: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 7021: if ($existing->{$key}{'cookie'}) {
7022: $currcookies->{$key} = 1;
7023: }
1.150 raeburn 7024: }
7025: }
1.171 raeburn 7026: } else {
7027: my ($balancerref,$targetsref) =
7028: &Apache::lonnet::get_lonbalancer_config($servers);
7029: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
7030: foreach my $server (sort(keys(%{$balancerref}))) {
7031: $currbalancer->{$server} = 1;
7032: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 7033: }
7034: }
7035: }
1.171 raeburn 7036: return;
1.150 raeburn 7037: }
7038:
7039: sub loadbalancing_rules {
7040: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 7041: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
7042: $css_class,$balnum,$islast) = @_;
1.150 raeburn 7043: my $output;
1.171 raeburn 7044: my $num = 0;
1.210 raeburn 7045: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 7046: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
7047: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
7048: foreach my $type (@{$alltypes}) {
1.171 raeburn 7049: $num ++;
1.150 raeburn 7050: my $current;
7051: if (ref($currrules) eq 'HASH') {
7052: $current = $currrules->{$type};
7053: }
1.253 raeburn 7054: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 7055: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 7056: $current = '';
7057: }
7058: }
7059: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 7060: $servers,$currbalancer,$lonhost,$dom,
7061: $targets_div_style,$homedom_div_style,
7062: $css_class,$balnum,$num,$islast);
1.150 raeburn 7063: }
7064: }
7065: return $output;
7066: }
7067:
7068: sub loadbalancing_titles {
7069: my ($dom,$intdom,$usertypes,$types) = @_;
7070: my %othertypes = (
7071: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
7072: '_LC_author' => &mt('Users from [_1] with author role',$dom),
7073: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
7074: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 7075: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
7076: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 7077: );
1.209 raeburn 7078: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 7079: my @available;
1.150 raeburn 7080: if (ref($types) eq 'ARRAY') {
1.302 raeburn 7081: @available = @{$types};
1.150 raeburn 7082: }
1.302 raeburn 7083: unless (grep(/^default$/,@available)) {
7084: push(@available,'default');
7085: }
7086: unshift(@alltypes,@available);
1.150 raeburn 7087: my %titles;
7088: foreach my $type (@alltypes) {
7089: if ($type =~ /^_LC_/) {
7090: $titles{$type} = $othertypes{$type};
7091: } elsif ($type eq 'default') {
7092: $titles{$type} = &mt('All users from [_1]',$dom);
7093: if (ref($types) eq 'ARRAY') {
7094: if (@{$types} > 0) {
7095: $titles{$type} = &mt('Other users from [_1]',$dom);
7096: }
7097: }
7098: } elsif (ref($usertypes) eq 'HASH') {
7099: $titles{$type} = $usertypes->{$type};
7100: }
7101: }
7102: return (\@alltypes,\%othertypes,\%titles);
7103: }
7104:
7105: sub loadbalance_rule_row {
1.171 raeburn 7106: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
7107: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 7108: my @rulenames;
1.150 raeburn 7109: my %ruletitles = &offloadtype_text();
1.209 raeburn 7110: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 7111: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 7112: } else {
1.209 raeburn 7113: @rulenames = ('default','homeserver');
7114: if ($type eq '_LC_external') {
7115: push(@rulenames,'externalbalancer');
7116: } else {
7117: push(@rulenames,'specific');
7118: }
7119: push(@rulenames,'none');
1.150 raeburn 7120: }
7121: my $style = $targets_div_style;
1.253 raeburn 7122: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 7123: $style = $homedom_div_style;
7124: }
1.171 raeburn 7125: my $space;
7126: if ($islast && $num == 1) {
1.317 raeburn 7127: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 7128: }
1.210 raeburn 7129: my $output =
1.306 raeburn 7130: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 7131: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
7132: '<td valaign="top">'.$space.
7133: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 7134: for (my $i=0; $i<@rulenames; $i++) {
7135: my $rule = $rulenames[$i];
7136: my ($checked,$extra);
7137: if ($rulenames[$i] eq 'default') {
7138: $rule = '';
7139: }
7140: if ($rulenames[$i] eq 'specific') {
7141: if (ref($servers) eq 'HASH') {
7142: my $default;
7143: if (($current ne '') && (exists($servers->{$current}))) {
7144: $checked = ' checked="checked"';
7145: }
7146: unless ($checked) {
7147: $default = ' selected="selected"';
7148: }
1.210 raeburn 7149: $extra =
1.171 raeburn 7150: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
7151: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
7152: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
7153: '<option value=""'.$default.'></option>'."\n";
7154: foreach my $server (sort(keys(%{$servers}))) {
7155: if (ref($currbalancer) eq 'HASH') {
7156: next if (exists($currbalancer->{$server}));
7157: }
1.150 raeburn 7158: my $selected;
1.171 raeburn 7159: if ($server eq $current) {
1.150 raeburn 7160: $selected = ' selected="selected"';
7161: }
1.171 raeburn 7162: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 7163: }
7164: $extra .= '</select>';
7165: }
7166: } elsif ($rule eq $current) {
7167: $checked = ' checked="checked"';
7168: }
7169: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 7170: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
7171: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
7172: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 7173: ')"'.$checked.' /> ';
7174: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
7175: $output .= $ruletitles{'particular'};
7176: } else {
7177: $output .= $ruletitles{$rulenames[$i]};
7178: }
7179: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 7180: }
7181: $output .= '</div></td></tr>'."\n";
7182: return $output;
7183: }
7184:
7185: sub offloadtype_text {
7186: my %ruletitles = &Apache::lonlocal::texthash (
7187: 'default' => 'Offloads to default destinations',
7188: 'homeserver' => "Offloads to user's home server",
7189: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
7190: 'specific' => 'Offloads to specific server',
1.161 raeburn 7191: 'none' => 'No offload',
1.209 raeburn 7192: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
7193: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 7194: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 7195: );
7196: return %ruletitles;
7197: }
7198:
7199: sub sparestype_titles {
7200: my %typestitles = &Apache::lonlocal::texthash (
7201: 'primary' => 'primary',
7202: 'default' => 'default',
7203: );
7204: return %typestitles;
7205: }
7206:
1.28 raeburn 7207: sub contact_titles {
7208: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 7209: 'supportemail' => 'Support E-mail address',
7210: 'adminemail' => 'Default Server Admin E-mail address',
7211: 'errormail' => 'Error reports to be e-mailed to',
7212: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 7213: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
7214: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 7215: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
7216: 'requestsmail' => 'E-mail from course requests requiring approval',
7217: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 7218: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 7219: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.340 raeburn 7220: 'errorthreshold' => 'Error/warning threshold for status e-mail',
7221: 'errorsysmail' => 'Error threshold for e-mail to core group',
7222: 'errorweights' => 'Weights used to compute error count',
7223: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 7224: );
7225: my %short_titles = &Apache::lonlocal::texthash (
7226: adminemail => 'Admin E-mail address',
7227: supportemail => 'Support E-mail',
7228: );
7229: return (\%titles,\%short_titles);
7230: }
7231:
1.286 raeburn 7232: sub helpform_fields {
7233: my %titles = &Apache::lonlocal::texthash (
7234: 'username' => 'Name',
7235: 'user' => 'Username/domain',
7236: 'phone' => 'Phone',
7237: 'cc' => 'Cc e-mail',
7238: 'course' => 'Course Details',
7239: 'section' => 'Sections',
1.289 raeburn 7240: 'screenshot' => 'File upload',
1.286 raeburn 7241: );
7242: my @fields = ('username','phone','user','course','section','cc','screenshot');
7243: my %possoptions = (
7244: username => ['yes','no','req'],
1.289 raeburn 7245: phone => ['yes','no','req'],
1.286 raeburn 7246: user => ['yes','no'],
1.289 raeburn 7247: cc => ['yes','no'],
1.286 raeburn 7248: course => ['yes','no'],
7249: section => ['yes','no'],
7250: screenshot => ['yes','no'],
7251: );
7252: my %fieldoptions = &Apache::lonlocal::texthash (
7253: 'yes' => 'Optional',
7254: 'req' => 'Required',
7255: 'no' => "Not shown",
7256: );
7257: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
7258: }
7259:
1.72 raeburn 7260: sub tool_titles {
7261: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 7262: aboutme => 'Personal web page',
1.86 raeburn 7263: blog => 'Blog',
1.162 raeburn 7264: webdav => 'WebDAV',
1.86 raeburn 7265: portfolio => 'Portfolio',
1.88 bisitz 7266: official => 'Official courses (with institutional codes)',
7267: unofficial => 'Unofficial courses',
1.98 raeburn 7268: community => 'Communities',
1.216 raeburn 7269: textbook => 'Textbook courses',
1.271 raeburn 7270: placement => 'Placement tests',
1.86 raeburn 7271: );
1.72 raeburn 7272: return %titles;
7273: }
7274:
1.101 raeburn 7275: sub courserequest_titles {
7276: my %titles = &Apache::lonlocal::texthash (
7277: official => 'Official',
7278: unofficial => 'Unofficial',
7279: community => 'Communities',
1.216 raeburn 7280: textbook => 'Textbook',
1.271 raeburn 7281: placement => 'Placement tests',
1.325 raeburn 7282: lti => 'LTI Provider',
1.101 raeburn 7283: norequest => 'Not allowed',
1.325 raeburn 7284: approval => 'Approval by DC',
1.101 raeburn 7285: validate => 'With validation',
7286: autolimit => 'Numerical limit',
1.103 raeburn 7287: unlimited => '(blank for unlimited)',
1.101 raeburn 7288: );
7289: return %titles;
7290: }
7291:
1.163 raeburn 7292: sub authorrequest_titles {
7293: my %titles = &Apache::lonlocal::texthash (
7294: norequest => 'Not allowed',
7295: approval => 'Approval by Dom. Coord.',
7296: automatic => 'Automatic approval',
7297: );
7298: return %titles;
1.210 raeburn 7299: }
1.163 raeburn 7300:
1.101 raeburn 7301: sub courserequest_conditions {
7302: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 7303: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 7304: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 7305: );
7306: return %conditions;
7307: }
7308:
7309:
1.27 raeburn 7310: sub print_usercreation {
1.30 raeburn 7311: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 7312: my $numinrow = 4;
1.28 raeburn 7313: my $datatable;
7314: if ($position eq 'top') {
1.30 raeburn 7315: $$rowtotal ++;
1.34 raeburn 7316: my $rowcount = 0;
1.32 raeburn 7317: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 7318: if (ref($rules) eq 'HASH') {
7319: if (keys(%{$rules}) > 0) {
1.32 raeburn 7320: $datatable .= &user_formats_row('username',$settings,$rules,
7321: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 7322: $$rowtotal ++;
1.32 raeburn 7323: $rowcount ++;
7324: }
7325: }
7326: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
7327: if (ref($idrules) eq 'HASH') {
7328: if (keys(%{$idrules}) > 0) {
7329: $datatable .= &user_formats_row('id',$settings,$idrules,
7330: $idruleorder,$numinrow,$rowcount);
7331: $$rowtotal ++;
7332: $rowcount ++;
1.28 raeburn 7333: }
7334: }
1.39 raeburn 7335: if ($rowcount == 0) {
7336: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
7337: $$rowtotal ++;
7338: $rowcount ++;
7339: }
1.34 raeburn 7340: } elsif ($position eq 'middle') {
1.224 raeburn 7341: my @creators = ('author','course','requestcrs');
1.37 raeburn 7342: my ($rules,$ruleorder) =
7343: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 7344: my %lt = &usercreation_types();
7345: my %checked;
7346: if (ref($settings) eq 'HASH') {
7347: if (ref($settings->{'cancreate'}) eq 'HASH') {
7348: foreach my $item (@creators) {
7349: $checked{$item} = $settings->{'cancreate'}{$item};
7350: }
7351: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
7352: foreach my $item (@creators) {
7353: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
7354: $checked{$item} = 'none';
7355: }
7356: }
7357: }
7358: }
7359: my $rownum = 0;
7360: foreach my $item (@creators) {
7361: $rownum ++;
1.224 raeburn 7362: if ($checked{$item} eq '') {
7363: $checked{$item} = 'any';
1.34 raeburn 7364: }
7365: my $css_class;
7366: if ($rownum%2) {
7367: $css_class = '';
7368: } else {
7369: $css_class = ' class="LC_odd_row" ';
7370: }
7371: $datatable .= '<tr'.$css_class.'>'.
7372: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 7373: '</span></td><td style="text-align: right">';
1.224 raeburn 7374: my @options = ('any');
7375: if (ref($rules) eq 'HASH') {
7376: if (keys(%{$rules}) > 0) {
7377: push(@options,('official','unofficial'));
1.37 raeburn 7378: }
7379: }
1.224 raeburn 7380: push(@options,'none');
1.37 raeburn 7381: foreach my $option (@options) {
1.50 raeburn 7382: my $type = 'radio';
1.34 raeburn 7383: my $check = ' ';
1.224 raeburn 7384: if ($checked{$item} eq $option) {
7385: $check = ' checked="checked" ';
1.34 raeburn 7386: }
7387: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 7388: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 7389: $item.'" value="'.$option.'"'.$check.'/> '.
7390: $lt{$option}.'</label> </span>';
7391: }
7392: $datatable .= '</td></tr>';
7393: }
1.28 raeburn 7394: } else {
7395: my @contexts = ('author','course','domain');
1.325 raeburn 7396: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 7397: my %checked;
7398: if (ref($settings) eq 'HASH') {
7399: if (ref($settings->{'authtypes'}) eq 'HASH') {
7400: foreach my $item (@contexts) {
7401: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
7402: foreach my $auth (@authtypes) {
7403: if ($settings->{'authtypes'}{$item}{$auth}) {
7404: $checked{$item}{$auth} = ' checked="checked" ';
7405: }
7406: }
7407: }
7408: }
1.27 raeburn 7409: }
1.35 raeburn 7410: } else {
7411: foreach my $item (@contexts) {
1.36 raeburn 7412: foreach my $auth (@authtypes) {
1.35 raeburn 7413: $checked{$item}{$auth} = ' checked="checked" ';
7414: }
7415: }
1.27 raeburn 7416: }
1.28 raeburn 7417: my %title = &context_names();
7418: my %authname = &authtype_names();
7419: my $rownum = 0;
7420: my $css_class;
7421: foreach my $item (@contexts) {
7422: if ($rownum%2) {
7423: $css_class = '';
7424: } else {
7425: $css_class = ' class="LC_odd_row" ';
7426: }
1.30 raeburn 7427: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 7428: '<td>'.$title{$item}.
7429: '</td><td class="LC_left_item">'.
7430: '<span class="LC_nobreak">';
7431: foreach my $auth (@authtypes) {
7432: $datatable .= '<label>'.
7433: '<input type="checkbox" name="'.$item.'_auth" '.
7434: $checked{$item}{$auth}.' value="'.$auth.'" />'.
7435: $authname{$auth}.'</label> ';
7436: }
7437: $datatable .= '</span></td></tr>';
7438: $rownum ++;
1.27 raeburn 7439: }
1.30 raeburn 7440: $$rowtotal += $rownum;
1.27 raeburn 7441: }
7442: return $datatable;
7443: }
7444:
1.224 raeburn 7445: sub print_selfcreation {
7446: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 7447: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
7448: $emaildomain,$datatable);
1.224 raeburn 7449: if (ref($settings) eq 'HASH') {
7450: if (ref($settings->{'cancreate'}) eq 'HASH') {
7451: $createsettings = $settings->{'cancreate'};
1.236 raeburn 7452: if (ref($createsettings) eq 'HASH') {
7453: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
7454: @selfcreate = @{$createsettings->{'selfcreate'}};
7455: } elsif ($createsettings->{'selfcreate'} ne '') {
7456: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
7457: @selfcreate = ('email','login','sso');
7458: } elsif ($createsettings->{'selfcreate'} ne 'none') {
7459: @selfcreate = ($createsettings->{'selfcreate'});
7460: }
7461: }
7462: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
7463: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 7464: }
1.305 raeburn 7465: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
7466: $emailoptions = $createsettings->{'emailoptions'};
7467: }
1.303 raeburn 7468: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
7469: $emailverified = $createsettings->{'emailverified'};
7470: }
7471: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
7472: $emaildomain = $createsettings->{'emaildomain'};
7473: }
1.224 raeburn 7474: }
7475: }
7476: }
7477: my %radiohash;
7478: my $numinrow = 4;
7479: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 7480: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 7481: if ($position eq 'top') {
7482: my %choices = &Apache::lonlocal::texthash (
7483: cancreate_login => 'Institutional Login',
7484: cancreate_sso => 'Institutional Single Sign On',
7485: );
7486: my @toggles = sort(keys(%choices));
7487: my %defaultchecked = (
7488: 'cancreate_login' => 'off',
7489: 'cancreate_sso' => 'off',
7490: );
1.228 raeburn 7491: my ($onclick,$itemcount);
1.224 raeburn 7492: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
7493: \%choices,$itemcount,$onclick);
1.228 raeburn 7494: $$rowtotal += $itemcount;
7495:
1.224 raeburn 7496: if (ref($usertypes) eq 'HASH') {
7497: if (keys(%{$usertypes}) > 0) {
7498: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
7499: $dom,$numinrow,$othertitle,
1.305 raeburn 7500: 'statustocreate',$rowtotal);
1.224 raeburn 7501: $$rowtotal ++;
7502: }
7503: }
1.240 raeburn 7504: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
7505: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7506: $fieldtitles{'inststatus'} = &mt('Institutional status');
7507: my $rem;
7508: my $numperrow = 2;
7509: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
7510: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 7511: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 7512: '<td class="LC_left_item">'."\n".
1.334 raeburn 7513: '<table>'."\n";
1.240 raeburn 7514: for (my $i=0; $i<@fields; $i++) {
7515: $rem = $i%($numperrow);
7516: if ($rem == 0) {
7517: if ($i > 0) {
7518: $datatable .= '</tr>';
7519: }
7520: $datatable .= '<tr>';
7521: }
7522: my $currval;
1.248 raeburn 7523: if (ref($createsettings) eq 'HASH') {
7524: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
7525: $currval = $createsettings->{'shibenv'}{$fields[$i]};
7526: }
1.240 raeburn 7527: }
7528: $datatable .= '<td class="LC_left_item">'.
7529: '<span class="LC_nobreak">'.
7530: '<input type="text" name="shibenv_'.$fields[$i].'" '.
7531: 'value="'.$currval.'" size="10" /> '.
7532: $fieldtitles{$fields[$i]}.'</span></td>';
7533: }
7534: my $colsleft = $numperrow - $rem;
7535: if ($colsleft > 1 ) {
7536: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7537: ' </td>';
7538: } elsif ($colsleft == 1) {
7539: $datatable .= '<td class="LC_left_item"> </td>';
7540: }
7541: $datatable .= '</tr></table></td></tr>';
7542: $$rowtotal ++;
1.224 raeburn 7543: } elsif ($position eq 'middle') {
7544: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 7545: my @posstypes;
1.224 raeburn 7546: if (ref($types) eq 'ARRAY') {
1.302 raeburn 7547: @posstypes = @{$types};
7548: }
7549: unless (grep(/^default$/,@posstypes)) {
7550: push(@posstypes,'default');
7551: }
7552: my %usertypeshash;
7553: if (ref($usertypes) eq 'HASH') {
7554: %usertypeshash = %{$usertypes};
7555: }
7556: $usertypeshash{'default'} = $othertitle;
7557: foreach my $status (@posstypes) {
7558: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
7559: $numinrow,$$rowtotal,\%usertypeshash);
7560: $$rowtotal ++;
1.224 raeburn 7561: }
7562: } else {
1.236 raeburn 7563: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 7564: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 7565: );
7566: my @toggles = sort(keys(%choices));
7567: my %defaultchecked = (
7568: 'cancreate_email' => 'off',
7569: );
1.305 raeburn 7570: my $customclass = 'LC_selfcreate_email';
7571: my $classprefix = 'LC_canmodify_emailusername_';
7572: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 7573: my $display = 'none';
1.305 raeburn 7574: my $rowstyle = 'display:none';
1.236 raeburn 7575: if (grep(/^\Qemail\E$/,@selfcreate)) {
7576: $display = 'block';
1.305 raeburn 7577: $rowstyle = 'display:table-row';
1.236 raeburn 7578: }
1.305 raeburn 7579: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
7580: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
7581: \%choices,$$rowtotal,$onclick);
7582: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
7583: $rowstyle);
7584: $$rowtotal ++;
7585: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
7586: $rowstyle);
7587: $$rowtotal ++;
7588: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 7589: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 7590: my ($emailrules,$emailruleorder) =
7591: &Apache::lonnet::inst_userrules($dom,'email');
7592: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7593: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7594: if (ref($types) eq 'ARRAY') {
7595: @posstypes = @{$types};
7596: }
7597: if (@posstypes) {
7598: unless (grep(/^default$/,@posstypes)) {
7599: push(@posstypes,'default');
1.302 raeburn 7600: }
7601: if (ref($usertypes) eq 'HASH') {
7602: %usertypeshash = %{$usertypes};
7603: }
1.305 raeburn 7604: my $currassign;
7605: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
7606: $currassign = {
7607: selfassign => $domdefaults{'inststatusguest'},
7608: };
7609: @ordered = @{$domdefaults{'inststatusguest'}};
7610: } else {
7611: $currassign = { selfassign => [] };
7612: }
7613: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
7614: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
7615: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
7616: $numinrow,$othertitle,'selfassign',
7617: $rowtotal,$onclicktypes,$customclass,
7618: $rowstyle);
7619: $$rowtotal ++;
1.302 raeburn 7620: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 7621: foreach my $status (@posstypes) {
7622: my $css_class;
7623: if ($$rowtotal%2) {
7624: $css_class = 'LC_odd_row ';
7625: }
7626: $css_class .= $customclass;
7627: my $rowid = $optionsprefix.$status;
7628: my $hidden = 1;
7629: my $currstyle = 'display:none';
7630: if (grep(/^\Q$status\E$/,@ordered)) {
7631: $currstyle = $rowstyle;
7632: $hidden = 0;
7633: }
7634: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7635: $emailrules,$emailruleorder,$settings,$status,$rowid,
7636: $usertypeshash{$status},$css_class,$currstyle,$intdom);
7637: unless ($hidden) {
7638: $$rowtotal ++;
7639: }
1.224 raeburn 7640: }
1.302 raeburn 7641: } else {
1.305 raeburn 7642: my $css_class;
7643: if ($$rowtotal%2) {
7644: $css_class = 'LC_odd_row ';
7645: }
7646: $css_class .= $customclass;
1.302 raeburn 7647: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 7648: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7649: $emailrules,$emailruleorder,$settings,'default','',
7650: $othertitle,$css_class,$rowstyle,$intdom);
7651: $$rowtotal ++;
1.224 raeburn 7652: }
7653: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 7654: $numinrow = 1;
1.305 raeburn 7655: if (@posstypes) {
7656: foreach my $status (@posstypes) {
7657: my $rowid = $classprefix.$status;
7658: my $datarowstyle = 'display:none';
7659: if (grep(/^\Q$status\E$/,@ordered)) {
7660: $datarowstyle = $rowstyle;
7661: }
7662: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
7663: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7664: $infotitles,$rowid,$customclass,$datarowstyle);
7665: unless ($datarowstyle eq 'display:none') {
7666: $$rowtotal ++;
7667: }
1.224 raeburn 7668: }
1.305 raeburn 7669: } else {
7670: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
7671: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7672: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 7673: }
7674: }
7675: return $datatable;
7676: }
7677:
1.305 raeburn 7678: sub selfcreate_javascript {
7679: return <<"ENDSCRIPT";
7680:
7681: <script type="text/javascript">
7682: // <![CDATA[
7683:
7684: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
7685: var x = document.getElementsByClassName(target);
7686: var insttypes = 0;
7687: var insttypeRegExp = new RegExp(prefix);
7688: if ((x.length != undefined) && (x.length > 0)) {
7689: if (form.elements[radio].length != undefined) {
7690: for (var i=0; i<form.elements[radio].length; i++) {
7691: if (form.elements[radio][i].checked) {
7692: if (form.elements[radio][i].value == 1) {
7693: for (var j=0; j<x.length; j++) {
7694: if (x[j].id == 'undefined') {
7695: x[j].style.display = 'table-row';
7696: } else if (insttypeRegExp.test(x[j].id)) {
7697: insttypes ++;
7698: } else {
7699: x[j].style.display = 'table-row';
7700: }
7701: }
7702: } else {
7703: for (var j=0; j<x.length; j++) {
7704: x[j].style.display = 'none';
7705: }
1.236 raeburn 7706: }
1.305 raeburn 7707: break;
7708: }
7709: }
7710: if (insttypes > 0) {
7711: toggleDataRow(form,checkbox,target,altprefix);
7712: toggleDataRow(form,checkbox,target,prefix,1);
7713: }
7714: }
7715: }
7716: return;
7717: }
7718:
7719: function toggleDataRow(form,checkbox,target,prefix,docount) {
7720: if (form.elements[checkbox].length != undefined) {
7721: var count = 0;
7722: if (docount) {
7723: for (var i=0; i<form.elements[checkbox].length; i++) {
7724: if (form.elements[checkbox][i].checked) {
7725: count ++;
1.236 raeburn 7726: }
1.305 raeburn 7727: }
7728: }
7729: for (var i=0; i<form.elements[checkbox].length; i++) {
7730: var type = form.elements[checkbox][i].value;
7731: if (document.getElementById(prefix+type)) {
7732: if (form.elements[checkbox][i].checked) {
7733: document.getElementById(prefix+type).style.display = 'table-row';
7734: if (count % 2 == 1) {
7735: document.getElementById(prefix+type).className = target+' LC_odd_row';
7736: } else {
7737: document.getElementById(prefix+type).className = target;
1.236 raeburn 7738: }
1.305 raeburn 7739: count ++;
1.236 raeburn 7740: } else {
1.305 raeburn 7741: document.getElementById(prefix+type).style.display = 'none';
7742: }
7743: }
7744: }
7745: }
7746: return;
7747: }
7748:
7749: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
7750: var caller = radio+'_'+status;
7751: if (form.elements[caller].length != undefined) {
7752: for (var i=0; i<form.elements[caller].length; i++) {
7753: if (form.elements[caller][i].checked) {
7754: if (document.getElementById(altprefix+'_inst_'+status)) {
7755: var curr = form.elements[caller][i].value;
7756: if (prefix) {
7757: document.getElementById(prefix+'_'+status).style.display = 'none';
7758: }
7759: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
7760: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
7761: if (curr == 'custom') {
7762: if (prefix) {
7763: document.getElementById(prefix+'_'+status).style.display = 'inline';
7764: }
7765: } else if (curr == 'inst') {
7766: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
7767: } else if (curr == 'noninst') {
7768: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 7769: }
1.305 raeburn 7770: break;
1.236 raeburn 7771: }
7772: }
7773: }
7774: }
7775: }
7776:
1.305 raeburn 7777: // ]]>
7778: </script>
7779:
7780: ENDSCRIPT
7781: }
7782:
7783: sub noninst_users {
7784: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
7785: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
7786: my $class = 'LC_left_item';
7787: if ($css_class) {
7788: $css_class = ' class="'.$css_class.'"';
7789: }
7790: if ($rowid) {
7791: $rowid = ' id="'.$rowid.'"';
7792: }
7793: if ($rowstyle) {
7794: $rowstyle = ' style="'.$rowstyle.'"';
7795: }
7796: my ($output,$description);
7797: if ($type eq 'default') {
7798: $description = &mt('Requests for: [_1]',$typetitle);
7799: } else {
7800: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
7801: }
7802: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
7803: "<td>$description</td>\n".
7804: '<td class="'.$class.'" colspan="2">'.
7805: '<table><tr>';
7806: my %headers = &Apache::lonlocal::texthash(
7807: approve => 'Processing',
7808: email => 'E-mail',
7809: username => 'Username',
7810: );
7811: foreach my $item ('approve','email','username') {
7812: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 7813: }
1.305 raeburn 7814: $output .= '</tr><tr>';
7815: foreach my $item ('approve','email','username') {
1.306 raeburn 7816: $output .= '<td style="vertical-align: top">';
1.305 raeburn 7817: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
7818: if ($item eq 'approve') {
7819: %choices = &Apache::lonlocal::texthash (
7820: automatic => 'Automatically approved',
7821: approval => 'Queued for approval',
7822: );
7823: @options = ('automatic','approval');
7824: $hashref = $processing;
7825: $defoption = 'automatic';
7826: $name = 'cancreate_emailprocess_'.$type;
7827: } elsif ($item eq 'email') {
7828: %choices = &Apache::lonlocal::texthash (
7829: any => 'Any e-mail',
7830: inst => 'Institutional only',
7831: noninst => 'Non-institutional only',
7832: custom => 'Custom restrictions',
7833: );
7834: @options = ('any','inst','noninst');
7835: my $showcustom;
7836: if (ref($emailrules) eq 'HASH') {
7837: if (keys(%{$emailrules}) > 0) {
7838: push(@options,'custom');
7839: $showcustom = 'cancreate_emailrule';
7840: if (ref($settings) eq 'HASH') {
7841: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
7842: foreach my $rule (@{$settings->{'email_rule'}}) {
7843: if (exists($emailrules->{$rule})) {
7844: $hascustom ++;
7845: }
7846: }
7847: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
7848: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
7849: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
7850: if (exists($emailrules->{$rule})) {
7851: $hascustom ++;
7852: }
7853: }
7854: }
7855: }
7856: }
7857: }
7858: }
7859: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
7860: "'cancreate_emaildomain','$type'".');"';
7861: $hashref = $emailoptions;
7862: $defoption = 'any';
7863: $name = 'cancreate_emailoptions_'.$type;
7864: } elsif ($item eq 'username') {
7865: %choices = &Apache::lonlocal::texthash (
7866: all => 'Same as e-mail',
7867: first => 'Omit @domain',
7868: free => 'Free to choose',
7869: );
7870: @options = ('all','first','free');
7871: $hashref = $emailverified;
7872: $defoption = 'all';
7873: $name = 'cancreate_usernameoptions_'.$type;
7874: }
7875: foreach my $option (@options) {
7876: my $checked;
7877: if (ref($hashref) eq 'HASH') {
7878: if ($type eq '') {
7879: if (!exists($hashref->{'default'})) {
7880: if ($option eq $defoption) {
7881: $checked = ' checked="checked"';
7882: }
7883: } else {
7884: if ($hashref->{'default'} eq $option) {
7885: $checked = ' checked="checked"';
7886: }
1.303 raeburn 7887: }
7888: } else {
1.305 raeburn 7889: if (!exists($hashref->{$type})) {
7890: if ($option eq $defoption) {
7891: $checked = ' checked="checked"';
7892: }
7893: } else {
7894: if ($hashref->{$type} eq $option) {
7895: $checked = ' checked="checked"';
7896: }
1.303 raeburn 7897: }
7898: }
1.305 raeburn 7899: } elsif (($item eq 'email') && ($hascustom)) {
7900: if ($option eq 'custom') {
7901: $checked = ' checked="checked"';
7902: }
7903: } elsif ($option eq $defoption) {
7904: $checked = ' checked="checked"';
7905: }
7906: $output .= '<span class="LC_nobreak"><label>'.
7907: '<input type="radio" name="'.$name.'"'.
7908: $checked.' value="'.$option.'"'.$onclick.' />'.
7909: $choices{$option}.'</label></span><br />';
7910: if ($item eq 'email') {
7911: if ($option eq 'custom') {
7912: my $id = 'cancreate_emailrule_'.$type;
7913: my $display = 'none';
7914: if ($checked) {
7915: $display = 'inline';
1.303 raeburn 7916: }
1.305 raeburn 7917: my $numinrow = 2;
7918: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
7919: '<legend>'.&mt('Disallow').'</legend><table>'.
7920: &user_formats_row('email',$settings,$emailrules,
7921: $emailruleorder,$numinrow,'',$type);
7922: '</table></fieldset>';
7923: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
7924: my %text = &Apache::lonlocal::texthash (
7925: inst => 'must end:',
7926: noninst => 'cannot end:',
7927: );
7928: my $value;
7929: if (ref($emaildomain) eq 'HASH') {
7930: if (ref($emaildomain->{$type}) eq 'HASH') {
7931: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 7932: }
7933: }
1.305 raeburn 7934: if ($value eq '') {
7935: $value = '@'.$intdom;
7936: }
7937: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
7938: my $display = 'none';
7939: if ($checked) {
7940: $display = 'inline';
7941: }
7942: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
7943: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
7944: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
7945: '</div>';
1.303 raeburn 7946: }
7947: }
7948: }
1.305 raeburn 7949: $output .= '</td>'."\n";
1.303 raeburn 7950: }
1.305 raeburn 7951: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 7952: return $output;
7953: }
7954:
1.165 raeburn 7955: sub captcha_choice {
1.305 raeburn 7956: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 7957: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
7958: $vertext,$currver);
1.165 raeburn 7959: my %lt = &captcha_phrases();
7960: $keyentry = 'hidden';
1.354 raeburn 7961: my $colspan=2;
1.165 raeburn 7962: if ($context eq 'cancreate') {
1.224 raeburn 7963: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 7964: } elsif ($context eq 'login') {
7965: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 7966: } elsif ($context eq 'passwords') {
7967: $rowname = &mt('"Forgot Password" CAPTCHA validation');
7968: $colspan=1;
1.165 raeburn 7969: }
7970: if (ref($settings) eq 'HASH') {
7971: if ($settings->{'captcha'}) {
7972: $checked{$settings->{'captcha'}} = ' checked="checked"';
7973: } else {
7974: $checked{'original'} = ' checked="checked"';
7975: }
7976: if ($settings->{'captcha'} eq 'recaptcha') {
7977: $pubtext = $lt{'pub'};
7978: $privtext = $lt{'priv'};
7979: $keyentry = 'text';
1.269 raeburn 7980: $vertext = $lt{'ver'};
7981: $currver = $settings->{'recaptchaversion'};
7982: if ($currver ne '2') {
7983: $currver = 1;
7984: }
1.165 raeburn 7985: }
7986: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
7987: $currpub = $settings->{'recaptchakeys'}{'public'};
7988: $currpriv = $settings->{'recaptchakeys'}{'private'};
7989: }
7990: } else {
7991: $checked{'original'} = ' checked="checked"';
7992: }
1.305 raeburn 7993: my $css_class;
7994: if ($itemcount%2) {
7995: $css_class = 'LC_odd_row';
7996: }
7997: if ($customcss) {
7998: $css_class .= " $customcss";
7999: }
8000: $css_class =~ s/^\s+//;
8001: if ($css_class) {
8002: $css_class = ' class="'.$css_class.'"';
8003: }
8004: if ($rowstyle) {
8005: $css_class .= ' style="'.$rowstyle.'"';
8006: }
1.169 raeburn 8007: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 8008: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 8009: '<table><tr><td>'."\n";
8010: foreach my $option ('original','recaptcha','notused') {
8011: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
8012: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
8013: $lt{$option}.'</label></span>';
8014: unless ($option eq 'notused') {
8015: $output .= (' 'x2)."\n";
8016: }
8017: }
8018: #
8019: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
8020: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 8021: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 8022: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 8023: #
1.165 raeburn 8024: $output .= '</td></tr>'."\n".
1.305 raeburn 8025: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 8026: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
8027: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
8028: $currpub.'" size="40" /></span><br />'."\n".
8029: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
8030: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 8031: $currpriv.'" size="40" /></span><br />'.
8032: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
8033: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
8034: $currver.'" size="3" /></span><br />'.
8035: '</td></tr></table>'."\n".
1.165 raeburn 8036: '</td></tr>';
8037: return $output;
8038: }
8039:
1.32 raeburn 8040: sub user_formats_row {
1.305 raeburn 8041: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 8042: my $output;
8043: my %text = (
8044: 'username' => 'new usernames',
8045: 'id' => 'IDs',
8046: );
1.305 raeburn 8047: unless ($type eq 'email') {
8048: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
8049: $output = '<tr '.$css_class.'>'.
8050: '<td><span class="LC_nobreak">'.
8051: &mt("Format rules to check for $text{$type}: ").
8052: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 8053: }
1.27 raeburn 8054: my $rem;
8055: if (ref($ruleorder) eq 'ARRAY') {
8056: for (my $i=0; $i<@{$ruleorder}; $i++) {
8057: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
8058: my $rem = $i%($numinrow);
8059: if ($rem == 0) {
8060: if ($i > 0) {
8061: $output .= '</tr>';
8062: }
8063: $output .= '<tr>';
8064: }
8065: my $check = ' ';
1.39 raeburn 8066: if (ref($settings) eq 'HASH') {
8067: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
8068: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
8069: $check = ' checked="checked" ';
8070: }
1.305 raeburn 8071: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
8072: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
8073: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
8074: $check = ' checked="checked" ';
8075: }
8076: }
1.27 raeburn 8077: }
8078: }
1.305 raeburn 8079: my $name = $type.'_rule';
8080: if ($type eq 'email') {
8081: $name .= '_'.$status;
8082: }
1.27 raeburn 8083: $output .= '<td class="LC_left_item">'.
8084: '<span class="LC_nobreak"><label>'.
1.311 raeburn 8085: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 8086: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
8087: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
8088: }
8089: }
8090: $rem = @{$ruleorder}%($numinrow);
8091: }
1.305 raeburn 8092: my $colsleft;
8093: if ($rem) {
8094: $colsleft = $numinrow - $rem;
8095: }
1.27 raeburn 8096: if ($colsleft > 1 ) {
8097: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8098: ' </td>';
8099: } elsif ($colsleft == 1) {
8100: $output .= '<td class="LC_left_item"> </td>';
8101: }
1.305 raeburn 8102: $output .= '</tr></table>';
8103: unless ($type eq 'email') {
8104: $output .= '</td></tr>';
8105: }
1.27 raeburn 8106: return $output;
8107: }
8108:
1.34 raeburn 8109: sub usercreation_types {
8110: my %lt = &Apache::lonlocal::texthash (
8111: author => 'When adding a co-author',
8112: course => 'When adding a user to a course',
1.100 raeburn 8113: requestcrs => 'When requesting a course',
1.34 raeburn 8114: any => 'Any',
8115: official => 'Institutional only ',
8116: unofficial => 'Non-institutional only',
8117: none => 'None',
8118: );
8119: return %lt;
1.48 raeburn 8120: }
1.34 raeburn 8121:
1.224 raeburn 8122: sub selfcreation_types {
8123: my %lt = &Apache::lonlocal::texthash (
8124: selfcreate => 'User creates own account',
8125: any => 'Any',
8126: official => 'Institutional only ',
8127: unofficial => 'Non-institutional only',
8128: email => 'E-mail address',
8129: login => 'Institutional Login',
8130: sso => 'SSO',
8131: );
8132: }
8133:
1.28 raeburn 8134: sub authtype_names {
8135: my %lt = &Apache::lonlocal::texthash(
8136: int => 'Internal',
8137: krb4 => 'Kerberos 4',
8138: krb5 => 'Kerberos 5',
8139: loc => 'Local',
1.325 raeburn 8140: lti => 'LTI',
1.28 raeburn 8141: );
8142: return %lt;
8143: }
8144:
8145: sub context_names {
8146: my %context_title = &Apache::lonlocal::texthash(
8147: author => 'Creating users when an Author',
8148: course => 'Creating users when in a course',
8149: domain => 'Creating users when a Domain Coordinator',
8150: );
8151: return %context_title;
8152: }
8153:
1.33 raeburn 8154: sub print_usermodification {
8155: my ($position,$dom,$settings,$rowtotal) = @_;
8156: my $numinrow = 4;
8157: my ($context,$datatable,$rowcount);
8158: if ($position eq 'top') {
8159: $rowcount = 0;
8160: $context = 'author';
8161: foreach my $role ('ca','aa') {
8162: $datatable .= &modifiable_userdata_row($context,$role,$settings,
8163: $numinrow,$rowcount);
8164: $$rowtotal ++;
8165: $rowcount ++;
8166: }
1.230 raeburn 8167: } elsif ($position eq 'bottom') {
1.33 raeburn 8168: $context = 'course';
8169: $rowcount = 0;
8170: foreach my $role ('st','ep','ta','in','cr') {
8171: $datatable .= &modifiable_userdata_row($context,$role,$settings,
8172: $numinrow,$rowcount);
8173: $$rowtotal ++;
8174: $rowcount ++;
8175: }
8176: }
8177: return $datatable;
8178: }
8179:
1.43 raeburn 8180: sub print_defaults {
1.236 raeburn 8181: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 8182: my $rownum = 0;
1.294 raeburn 8183: my ($datatable,$css_class,$titles);
8184: unless ($position eq 'bottom') {
8185: $titles = &defaults_titles($dom);
8186: }
1.236 raeburn 8187: if ($position eq 'top') {
8188: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
8189: 'datelocale_def','portal_def');
8190: my %defaults;
8191: if (ref($settings) eq 'HASH') {
8192: %defaults = %{$settings};
1.43 raeburn 8193: } else {
1.236 raeburn 8194: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8195: foreach my $item (@items) {
8196: $defaults{$item} = $domdefaults{$item};
8197: }
1.43 raeburn 8198: }
1.236 raeburn 8199: foreach my $item (@items) {
8200: if ($rownum%2) {
8201: $css_class = '';
8202: } else {
8203: $css_class = ' class="LC_odd_row" ';
8204: }
8205: $datatable .= '<tr'.$css_class.'>'.
8206: '<td><span class="LC_nobreak">'.$titles->{$item}.
8207: '</span></td><td class="LC_right_item" colspan="3">';
8208: if ($item eq 'auth_def') {
1.325 raeburn 8209: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 8210: my %shortauth = (
8211: internal => 'int',
8212: krb4 => 'krb4',
8213: krb5 => 'krb5',
1.325 raeburn 8214: localauth => 'loc',
8215: lti => 'lti',
1.236 raeburn 8216: );
8217: my %authnames = &authtype_names();
8218: foreach my $auth (@authtypes) {
8219: my $checked = ' ';
8220: if ($defaults{$item} eq $auth) {
8221: $checked = ' checked="checked" ';
8222: }
8223: $datatable .= '<label><input type="radio" name="'.$item.
8224: '" value="'.$auth.'"'.$checked.'/>'.
8225: $authnames{$shortauth{$auth}}.'</label> ';
8226: }
8227: } elsif ($item eq 'timezone_def') {
8228: my $includeempty = 1;
8229: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
8230: } elsif ($item eq 'datelocale_def') {
8231: my $includeempty = 1;
8232: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
8233: } elsif ($item eq 'lang_def') {
1.263 raeburn 8234: my $includeempty = 1;
8235: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 8236: } else {
8237: my $size;
8238: if ($item eq 'portal_def') {
8239: $size = ' size="25"';
8240: }
8241: $datatable .= '<input type="text" name="'.$item.'" value="'.
8242: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 8243: }
1.236 raeburn 8244: $datatable .= '</td></tr>';
8245: $rownum ++;
8246: }
1.354 raeburn 8247: } else {
1.294 raeburn 8248: my %defaults;
8249: if (ref($settings) eq 'HASH') {
1.354 raeburn 8250: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
8251: my $maxnum = @{$settings->{'inststatusorder'}};
8252: for (my $i=0; $i<$maxnum; $i++) {
8253: $css_class = $rownum%2?' class="LC_odd_row"':'';
8254: my $item = $settings->{'inststatusorder'}->[$i];
8255: my $title = $settings->{'inststatustypes'}->{$item};
8256: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
8257: $datatable .= '<tr'.$css_class.'>'.
8258: '<td><span class="LC_nobreak">'.
8259: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
8260: for (my $k=0; $k<=$maxnum; $k++) {
8261: my $vpos = $k+1;
8262: my $selstr;
8263: if ($k == $i) {
8264: $selstr = ' selected="selected" ';
8265: }
8266: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8267: }
8268: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
8269: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
8270: &mt('delete').'</span></td>'.
8271: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed:').
8272: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
8273: '</span></td></tr>';
8274: }
8275: $css_class = $rownum%2?' class="LC_odd_row"':'';
8276: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
8277: $datatable .= '<tr '.$css_class.'>'.
8278: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
8279: for (my $k=0; $k<=$maxnum; $k++) {
8280: my $vpos = $k+1;
8281: my $selstr;
8282: if ($k == $maxnum) {
8283: $selstr = ' selected="selected" ';
8284: }
8285: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8286: }
8287: $datatable .= '</select> '.&mt('Internal ID:').
8288: '<input type="text" size="10" name="addinststatus" value="" />'.
8289: ' '.&mt('(new)').
8290: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
8291: &mt('Name displayed:').
8292: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
8293: '</tr>'."\n";
8294: $rownum ++;
1.294 raeburn 8295: }
1.354 raeburn 8296: }
8297: }
8298: $$rowtotal += $rownum;
1.43 raeburn 8299: return $datatable;
8300: }
8301:
1.168 raeburn 8302: sub get_languages_hash {
8303: my %langchoices;
8304: foreach my $id (&Apache::loncommon::languageids()) {
8305: my $code = &Apache::loncommon::supportedlanguagecode($id);
8306: if ($code ne '') {
8307: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
8308: }
8309: }
8310: return %langchoices;
8311: }
8312:
1.43 raeburn 8313: sub defaults_titles {
1.141 raeburn 8314: my ($dom) = @_;
1.43 raeburn 8315: my %titles = &Apache::lonlocal::texthash (
8316: 'auth_def' => 'Default authentication type',
8317: 'auth_arg_def' => 'Default authentication argument',
8318: 'lang_def' => 'Default language',
1.54 raeburn 8319: 'timezone_def' => 'Default timezone',
1.68 raeburn 8320: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 8321: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 8322: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
8323: 'intauth_check' => 'Check bcrypt cost if authenticated',
8324: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 8325: );
1.141 raeburn 8326: if ($dom) {
8327: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
8328: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
8329: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
8330: $protocol = 'http' if ($protocol ne 'https');
8331: if ($uint_dom) {
8332: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
8333: $uint_dom);
8334: }
8335: }
1.43 raeburn 8336: return (\%titles);
8337: }
8338:
1.346 raeburn 8339: sub print_scantron {
8340: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
8341: if ($position eq 'top') {
8342: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
8343: } else {
8344: return &print_scantronconfig($dom,$settings,\$rowtotal);
8345: }
8346: }
8347:
8348: sub scantron_javascript {
8349: return <<"ENDSCRIPT";
8350:
8351: <script type="text/javascript">
8352: // <![CDATA[
8353:
8354: function toggleScantron(form) {
1.347 raeburn 8355: var csvfieldset = new Array();
1.346 raeburn 8356: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 8357: csvfieldset.push(document.getElementById('scantroncsv_cols'));
8358: }
8359: if (document.getElementById('scantroncsv_options')) {
8360: csvfieldset.push(document.getElementById('scantroncsv_options'));
8361: }
8362: if (csvfieldset.length) {
1.346 raeburn 8363: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 8364: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 8365: if (scantroncsv.checked) {
1.347 raeburn 8366: for (var i=0; i<csvfieldset.length; i++) {
8367: csvfieldset[i].style.display = 'block';
8368: }
1.346 raeburn 8369: } else {
1.347 raeburn 8370: for (var i=0; i<csvfieldset.length; i++) {
8371: csvfieldset[i].style.display = 'none';
8372: }
1.346 raeburn 8373: var csvselects = document.getElementsByClassName('scantronconfig_csv');
8374: if (csvselects.length) {
8375: for (var j=0; j<csvselects.length; j++) {
8376: csvselects[j].selectedIndex = 0;
8377: }
8378: }
8379: }
8380: }
8381: }
8382: return;
8383: }
8384: // ]]>
8385: </script>
8386:
8387: ENDSCRIPT
8388:
8389: }
8390:
1.46 raeburn 8391: sub print_scantronformat {
8392: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
8393: my $itemcount = 1;
1.60 raeburn 8394: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
8395: %confhash);
1.46 raeburn 8396: my $switchserver = &check_switchserver($dom,$confname);
8397: my %lt = &Apache::lonlocal::texthash (
1.95 www 8398: default => 'Default bubblesheet format file error',
8399: custom => 'Custom bubblesheet format file error',
1.46 raeburn 8400: );
8401: my %scantronfiles = (
8402: default => 'default.tab',
8403: custom => 'custom.tab',
8404: );
8405: foreach my $key (keys(%scantronfiles)) {
8406: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
8407: .$scantronfiles{$key};
8408: }
8409: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
8410: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
8411: if (!$switchserver) {
8412: my $servadm = $r->dir_config('lonAdmEMail');
8413: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
8414: if ($configuserok eq 'ok') {
8415: if ($author_ok eq 'ok') {
8416: my %legacyfile = (
1.346 raeburn 8417: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
8418: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 8419: );
8420: my %md5chk;
8421: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 8422: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
8423: chomp($md5chk{$type});
1.46 raeburn 8424: }
8425: if ($md5chk{'default'} ne $md5chk{'custom'}) {
8426: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 8427: ($scantronurls{$type},my $error) =
1.46 raeburn 8428: &legacy_scantronformat($r,$dom,$confname,
8429: $type,$legacyfile{$type},
8430: $scantronurls{$type},
8431: $scantronfiles{$type});
1.60 raeburn 8432: if ($error ne '') {
8433: $error{$type} = $error;
8434: }
8435: }
8436: if (keys(%error) == 0) {
8437: $is_custom = 1;
1.346 raeburn 8438: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 8439: $scantronurls{'custom'};
1.346 raeburn 8440: my $putresult =
1.60 raeburn 8441: &Apache::lonnet::put_dom('configuration',
8442: \%confhash,$dom);
8443: if ($putresult ne 'ok') {
1.346 raeburn 8444: $error{'custom'} =
1.60 raeburn 8445: '<span class="LC_error">'.
8446: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
8447: }
1.46 raeburn 8448: }
8449: } else {
1.60 raeburn 8450: ($scantronurls{'default'},my $error) =
1.46 raeburn 8451: &legacy_scantronformat($r,$dom,$confname,
8452: 'default',$legacyfile{'default'},
8453: $scantronurls{'default'},
8454: $scantronfiles{'default'});
1.60 raeburn 8455: if ($error eq '') {
8456: $confhash{'scantron'}{'scantronformat'} = '';
8457: my $putresult =
8458: &Apache::lonnet::put_dom('configuration',
8459: \%confhash,$dom);
8460: if ($putresult ne 'ok') {
8461: $error{'default'} =
8462: '<span class="LC_error">'.
8463: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
8464: }
8465: } else {
8466: $error{'default'} = $error;
8467: }
1.46 raeburn 8468: }
8469: }
8470: }
8471: } else {
1.95 www 8472: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 8473: }
8474: }
8475: if (ref($settings) eq 'HASH') {
8476: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
8477: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
8478: if ((!@info) || ($info[0] eq 'no_such_dir')) {
8479: $scantronurl = '';
8480: } else {
8481: $scantronurl = $settings->{'scantronformat'};
8482: }
8483: $is_custom = 1;
8484: } else {
8485: $scantronurl = $scantronurls{'default'};
8486: }
8487: } else {
1.60 raeburn 8488: if ($is_custom) {
8489: $scantronurl = $scantronurls{'custom'};
8490: } else {
8491: $scantronurl = $scantronurls{'default'};
8492: }
1.46 raeburn 8493: }
8494: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8495: $datatable .= '<tr'.$css_class.'>';
8496: if (!$is_custom) {
1.65 raeburn 8497: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
8498: '<span class="LC_nobreak">';
1.46 raeburn 8499: if ($scantronurl) {
1.199 raeburn 8500: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
8501: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 8502: } else {
8503: $datatable = &mt('File unavailable for display');
8504: }
1.65 raeburn 8505: $datatable .= '</span></td>';
1.60 raeburn 8506: if (keys(%error) == 0) {
1.306 raeburn 8507: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 8508: if (!$switchserver) {
8509: $datatable .= &mt('Upload:').'<br />';
8510: }
8511: } else {
8512: my $errorstr;
8513: foreach my $key (sort(keys(%error))) {
8514: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
8515: }
8516: $datatable .= '<td>'.$errorstr;
8517: }
1.46 raeburn 8518: } else {
8519: if (keys(%error) > 0) {
8520: my $errorstr;
8521: foreach my $key (sort(keys(%error))) {
8522: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
8523: }
1.60 raeburn 8524: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 8525: } elsif ($scantronurl) {
1.199 raeburn 8526: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
8527: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 8528: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 8529: $link.
8530: '<label><input type="checkbox" name="scantronformat_del"'.
8531: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 8532: '<td><span class="LC_nobreak"> '.
8533: &mt('Replace:').'</span><br />';
1.46 raeburn 8534: }
8535: }
8536: if (keys(%error) == 0) {
8537: if ($switchserver) {
8538: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
8539: } else {
1.65 raeburn 8540: $datatable .='<span class="LC_nobreak"> '.
8541: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 8542: }
8543: }
8544: $datatable .= '</td></tr>';
8545: $$rowtotal ++;
8546: return $datatable;
8547: }
8548:
8549: sub legacy_scantronformat {
8550: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
8551: my ($url,$error);
8552: my @statinfo = &Apache::lonnet::stat_file($newurl);
8553: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
8554: (my $result,$url) =
8555: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
8556: '','',$newfile);
8557: if ($result ne 'ok') {
1.130 raeburn 8558: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 8559: }
8560: }
8561: return ($url,$error);
8562: }
1.43 raeburn 8563:
1.346 raeburn 8564: sub print_scantronconfig {
8565: my ($dom,$settings,$rowtotal) = @_;
8566: my $itemcount = 2;
8567: my $is_checked = ' checked="checked"';
1.347 raeburn 8568: my %optionson = (
8569: hdr => ' checked="checked"',
8570: pad => ' checked="checked"',
8571: rem => ' checked="checked"',
8572: );
8573: my %optionsoff = (
8574: hdr => '',
8575: pad => '',
8576: rem => '',
8577: );
1.346 raeburn 8578: my $currcsvsty = 'none';
1.347 raeburn 8579: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 8580: my @fields = &scantroncsv_fields();
8581: my %titles = &scantronconfig_titles();
8582: if (ref($settings) eq 'HASH') {
8583: if (ref($settings->{config}) eq 'HASH') {
8584: if ($settings->{config}->{dat}) {
8585: $checked{'dat'} = $is_checked;
8586: }
8587: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 8588: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
8589: %csvfields = %{$settings->{config}->{csv}->{fields}};
8590: if (keys(%csvfields) > 0) {
8591: $checked{'csv'} = $is_checked;
8592: $currcsvsty = 'block';
8593: }
8594: }
8595: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
8596: %csvoptions = %{$settings->{config}->{csv}->{options}};
8597: foreach my $option (keys(%optionson)) {
8598: unless ($csvoptions{$option}) {
8599: $optionsoff{$option} = $optionson{$option};
8600: $optionson{$option} = '';
8601: }
8602: }
1.346 raeburn 8603: }
8604: }
8605: } else {
8606: $checked{'dat'} = $is_checked;
8607: }
8608: } else {
8609: $checked{'dat'} = $is_checked;
8610: }
8611: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
8612: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8613: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
8614: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
8615: foreach my $item ('dat','csv') {
8616: my $id;
8617: if ($item eq 'csv') {
8618: $id = 'id="scantronconfcsv" ';
1.347 raeburn 8619: }
1.346 raeburn 8620: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
8621: $titles{$item}.'</label>'.(' 'x3);
8622: if ($item eq 'csv') {
8623: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
8624: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
8625: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
8626: foreach my $col (@fields) {
8627: my $selnone;
8628: if ($csvfields{$col} eq '') {
8629: $selnone = ' selected="selected"';
8630: }
8631: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
8632: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
8633: '<option value=""'.$selnone.'></option>';
8634: for (my $i=0; $i<20; $i++) {
8635: my $shown = $i+1;
8636: my $sel;
8637: unless ($selnone) {
8638: if (exists($csvfields{$col})) {
8639: if ($csvfields{$col} == $i) {
8640: $sel = ' selected="selected"';
8641: }
8642: }
8643: }
8644: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
8645: }
8646: $datatable .= '</select></td></tr>';
8647: }
1.347 raeburn 8648: $datatable .= '</table></fieldset>'.
8649: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
8650: '<legend>'.&mt('CSV Options').'</legend>';
8651: foreach my $option ('hdr','pad','rem') {
8652: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
8653: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
8654: &mt('Yes').'</label>'.(' 'x2)."\n".
8655: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
8656: }
8657: $datatable .= '</fieldset>';
1.346 raeburn 8658: $itemcount ++;
8659: }
8660: }
8661: $datatable .= '</td></tr>';
8662: $$rowtotal ++;
8663: return $datatable;
8664: }
8665:
8666: sub scantronconfig_titles {
8667: return &Apache::lonlocal::texthash(
8668: dat => 'Standard format (.dat)',
8669: csv => 'Comma separated values (.csv)',
1.347 raeburn 8670: hdr => 'Remove first line in file (contains column titles)',
8671: pad => 'Prepend 0s to PaperID',
1.348 raeburn 8672: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 8673: CODE => 'CODE',
8674: ID => 'Student ID',
8675: PaperID => 'Paper ID',
8676: FirstName => 'First Name',
8677: LastName => 'Last Name',
8678: FirstQuestion => 'First Question Response',
8679: Section => 'Section',
8680: );
8681: }
8682:
8683: sub scantroncsv_fields {
8684: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
8685: }
8686:
1.49 raeburn 8687: sub print_coursecategories {
1.57 raeburn 8688: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
8689: my $datatable;
8690: if ($position eq 'top') {
1.238 raeburn 8691: my (%checked);
8692: my @catitems = ('unauth','auth');
8693: my @cattypes = ('std','domonly','codesrch','none');
8694: $checked{'unauth'} = 'std';
8695: $checked{'auth'} = 'std';
8696: if (ref($settings) eq 'HASH') {
8697: foreach my $type (@cattypes) {
8698: if ($type eq $settings->{'unauth'}) {
8699: $checked{'unauth'} = $type;
8700: }
8701: if ($type eq $settings->{'auth'}) {
8702: $checked{'auth'} = $type;
8703: }
8704: }
8705: }
8706: my %lt = &Apache::lonlocal::texthash (
8707: unauth => 'Catalog type for unauthenticated users',
8708: auth => 'Catalog type for authenticated users',
8709: none => 'No catalog',
8710: std => 'Standard catalog',
8711: domonly => 'Domain-only catalog',
8712: codesrch => "Code search form",
8713: );
8714: my $itemcount = 0;
8715: foreach my $item (@catitems) {
8716: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8717: $datatable .= '<tr '.$css_class.'>'.
8718: '<td>'.$lt{$item}.'</td>'.
8719: '<td class="LC_right_item"><span class="LC_nobreak">';
8720: foreach my $type (@cattypes) {
8721: my $ischecked;
8722: if ($checked{$item} eq $type) {
8723: $ischecked=' checked="checked"';
8724: }
8725: $datatable .= '<label>'.
8726: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
8727: ' />'.$lt{$type}.'</label> ';
8728: }
1.327 raeburn 8729: $datatable .= '</span></td></tr>';
1.238 raeburn 8730: $itemcount ++;
8731: }
8732: $$rowtotal += $itemcount;
8733: } elsif ($position eq 'middle') {
1.57 raeburn 8734: my $toggle_cats_crs = ' ';
8735: my $toggle_cats_dom = ' checked="checked" ';
8736: my $can_cat_crs = ' ';
8737: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 8738: my $toggle_catscomm_comm = ' ';
8739: my $toggle_catscomm_dom = ' checked="checked" ';
8740: my $can_catcomm_comm = ' ';
8741: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 8742: my $toggle_catsplace_place = ' ';
8743: my $toggle_catsplace_dom = ' checked="checked" ';
8744: my $can_catplace_place = ' ';
8745: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 8746:
1.57 raeburn 8747: if (ref($settings) eq 'HASH') {
8748: if ($settings->{'togglecats'} eq 'crs') {
8749: $toggle_cats_crs = $toggle_cats_dom;
8750: $toggle_cats_dom = ' ';
8751: }
8752: if ($settings->{'categorize'} eq 'crs') {
8753: $can_cat_crs = $can_cat_dom;
8754: $can_cat_dom = ' ';
8755: }
1.120 raeburn 8756: if ($settings->{'togglecatscomm'} eq 'comm') {
8757: $toggle_catscomm_comm = $toggle_catscomm_dom;
8758: $toggle_catscomm_dom = ' ';
8759: }
8760: if ($settings->{'categorizecomm'} eq 'comm') {
8761: $can_catcomm_comm = $can_catcomm_dom;
8762: $can_catcomm_dom = ' ';
8763: }
1.272 raeburn 8764: if ($settings->{'togglecatsplace'} eq 'place') {
8765: $toggle_catsplace_place = $toggle_catsplace_dom;
8766: $toggle_catsplace_dom = ' ';
8767: }
8768: if ($settings->{'categorizeplace'} eq 'place') {
8769: $can_catplace_place = $can_catplace_dom;
8770: $can_catplace_dom = ' ';
8771: }
1.57 raeburn 8772: }
8773: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 8774: togglecats => 'Show/Hide a course in catalog',
8775: togglecatscomm => 'Show/Hide a community in catalog',
8776: togglecatsplace => 'Show/Hide a placement test in catalog',
8777: categorize => 'Assign a category to a course',
8778: categorizecomm => 'Assign a category to a community',
8779: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 8780: );
8781: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 8782: dom => 'Set in Domain',
8783: crs => 'Set in Course',
8784: comm => 'Set in Community',
8785: place => 'Set in Placement Test',
1.57 raeburn 8786: );
8787: $datatable = '<tr class="LC_odd_row">'.
8788: '<td>'.$title{'togglecats'}.'</td>'.
8789: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8790: '<input type="radio" name="togglecats"'.
8791: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8792: '<label><input type="radio" name="togglecats"'.
8793: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
8794: '</tr><tr>'.
8795: '<td>'.$title{'categorize'}.'</td>'.
8796: '<td class="LC_right_item"><span class="LC_nobreak">'.
8797: '<label><input type="radio" name="categorize"'.
8798: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8799: '<label><input type="radio" name="categorize"'.
8800: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 8801: '</tr><tr class="LC_odd_row">'.
8802: '<td>'.$title{'togglecatscomm'}.'</td>'.
8803: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8804: '<input type="radio" name="togglecatscomm"'.
8805: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8806: '<label><input type="radio" name="togglecatscomm"'.
8807: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
8808: '</tr><tr>'.
8809: '<td>'.$title{'categorizecomm'}.'</td>'.
8810: '<td class="LC_right_item"><span class="LC_nobreak">'.
8811: '<label><input type="radio" name="categorizecomm"'.
8812: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8813: '<label><input type="radio" name="categorizecomm"'.
8814: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 8815: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 8816: '<td>'.$title{'togglecatsplace'}.'</td>'.
8817: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8818: '<input type="radio" name="togglecatsplace"'.
8819: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8820: '<label><input type="radio" name="togglecatscomm"'.
8821: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
8822: '</tr><tr>'.
8823: '<td>'.$title{'categorizeplace'}.'</td>'.
8824: '<td class="LC_right_item"><span class="LC_nobreak">'.
8825: '<label><input type="radio" name="categorizeplace"'.
8826: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8827: '<label><input type="radio" name="categorizeplace"'.
8828: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 8829: '</tr>';
1.272 raeburn 8830: $$rowtotal += 6;
1.57 raeburn 8831: } else {
8832: my $css_class;
8833: my $itemcount = 1;
8834: my $cathash;
8835: if (ref($settings) eq 'HASH') {
8836: $cathash = $settings->{'cats'};
8837: }
8838: if (ref($cathash) eq 'HASH') {
8839: my (@cats,@trails,%allitems,%idx,@jsarray);
8840: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
8841: \%allitems,\%idx,\@jsarray);
8842: my $maxdepth = scalar(@cats);
8843: my $colattrib = '';
8844: if ($maxdepth > 2) {
8845: $colattrib = ' colspan="2" ';
8846: }
8847: my @path;
8848: if (@cats > 0) {
8849: if (ref($cats[0]) eq 'ARRAY') {
8850: my $numtop = @{$cats[0]};
8851: my $maxnum = $numtop;
1.120 raeburn 8852: my %default_names = (
8853: instcode => &mt('Official courses'),
8854: communities => &mt('Communities'),
1.272 raeburn 8855: placement => &mt('Placement Tests'),
1.120 raeburn 8856: );
8857:
8858: if ((!grep(/^instcode$/,@{$cats[0]})) ||
8859: ($cathash->{'instcode::0'} eq '') ||
8860: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 8861: ($cathash->{'communities::0'} eq '') ||
8862: (!grep(/^placement$/,@{$cats[0]})) ||
8863: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 8864: $maxnum ++;
8865: }
8866: my $lastidx;
8867: for (my $i=0; $i<$numtop; $i++) {
8868: my $parent = $cats[0][$i];
8869: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8870: my $item = &escape($parent).'::0';
8871: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
8872: $lastidx = $idx{$item};
8873: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8874: .'<select name="'.$item.'"'.$chgstr.'>';
8875: for (my $k=0; $k<=$maxnum; $k++) {
8876: my $vpos = $k+1;
8877: my $selstr;
8878: if ($k == $i) {
8879: $selstr = ' selected="selected" ';
8880: }
8881: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8882: }
1.214 raeburn 8883: $datatable .= '</select></span></td><td>';
1.272 raeburn 8884: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 8885: $datatable .= '<span class="LC_nobreak">'
8886: .$default_names{$parent}.'</span>';
8887: if ($parent eq 'instcode') {
8888: $datatable .= '<br /><span class="LC_nobreak">('
8889: .&mt('with institutional codes')
8890: .')</span></td><td'.$colattrib.'>';
8891: } else {
8892: $datatable .= '<table><tr><td>';
8893: }
8894: $datatable .= '<span class="LC_nobreak">'
8895: .'<label><input type="radio" name="'
8896: .$parent.'" value="1" checked="checked" />'
8897: .&mt('Display').'</label>';
8898: if ($parent eq 'instcode') {
8899: $datatable .= ' ';
8900: } else {
8901: $datatable .= '</span></td></tr><tr><td>'
8902: .'<span class="LC_nobreak">';
8903: }
8904: $datatable .= '<label><input type="radio" name="'
8905: .$parent.'" value="0" />'
8906: .&mt('Do not display').'</label></span>';
1.272 raeburn 8907: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 8908: $datatable .= '</td></tr></table>';
8909: }
8910: $datatable .= '</td>';
1.57 raeburn 8911: } else {
8912: $datatable .= $parent
1.214 raeburn 8913: .' <span class="LC_nobreak"><label>'
8914: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 8915: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
8916: }
8917: my $depth = 1;
8918: push(@path,$parent);
8919: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
8920: pop(@path);
8921: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
8922: $itemcount ++;
8923: }
1.48 raeburn 8924: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 8925: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
8926: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 8927: for (my $k=0; $k<=$maxnum; $k++) {
8928: my $vpos = $k+1;
8929: my $selstr;
1.57 raeburn 8930: if ($k == $numtop) {
1.48 raeburn 8931: $selstr = ' selected="selected" ';
8932: }
8933: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8934: }
1.59 bisitz 8935: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 8936: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
8937: .'</tr>'."\n";
1.48 raeburn 8938: $itemcount ++;
1.272 raeburn 8939: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 8940: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
8941: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8942: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
8943: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
8944: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
8945: for (my $k=0; $k<=$maxnum; $k++) {
8946: my $vpos = $k+1;
8947: my $selstr;
8948: if ($k == $maxnum) {
8949: $selstr = ' selected="selected" ';
8950: }
8951: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 8952: }
1.120 raeburn 8953: $datatable .= '</select></span></td>'.
8954: '<td><span class="LC_nobreak">'.
8955: $default_names{$default}.'</span>';
8956: if ($default eq 'instcode') {
8957: $datatable .= '<br /><span class="LC_nobreak">('
8958: .&mt('with institutional codes').')</span>';
8959: }
8960: $datatable .= '</td>'
8961: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
8962: .&mt('Display').'</label> '
8963: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
8964: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 8965: }
8966: }
8967: }
1.57 raeburn 8968: } else {
8969: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 8970: }
8971: } else {
1.327 raeburn 8972: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 8973: .&initialize_categories($itemcount);
1.48 raeburn 8974: }
1.57 raeburn 8975: $$rowtotal += $itemcount;
1.48 raeburn 8976: }
8977: return $datatable;
8978: }
8979:
1.69 raeburn 8980: sub print_serverstatuses {
8981: my ($dom,$settings,$rowtotal) = @_;
8982: my $datatable;
8983: my @pages = &serverstatus_pages();
8984: my (%namedaccess,%machineaccess);
8985: foreach my $type (@pages) {
8986: $namedaccess{$type} = '';
8987: $machineaccess{$type}= '';
8988: }
8989: if (ref($settings) eq 'HASH') {
8990: foreach my $type (@pages) {
8991: if (exists($settings->{$type})) {
8992: if (ref($settings->{$type}) eq 'HASH') {
8993: foreach my $key (keys(%{$settings->{$type}})) {
8994: if ($key eq 'namedusers') {
8995: $namedaccess{$type} = $settings->{$type}->{$key};
8996: } elsif ($key eq 'machines') {
8997: $machineaccess{$type} = $settings->{$type}->{$key};
8998: }
8999: }
9000: }
9001: }
9002: }
9003: }
1.81 raeburn 9004: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 9005: my $rownum = 0;
9006: my $css_class;
9007: foreach my $type (@pages) {
9008: $rownum ++;
9009: $css_class = $rownum%2?' class="LC_odd_row"':'';
9010: $datatable .= '<tr'.$css_class.'>'.
9011: '<td><span class="LC_nobreak">'.
9012: $titles->{$type}.'</span></td>'.
9013: '<td class="LC_left_item">'.
9014: '<input type="text" name="'.$type.'_namedusers" '.
9015: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
9016: '<td class="LC_right_item">'.
9017: '<span class="LC_nobreak">'.
9018: '<input type="text" name="'.$type.'_machines" '.
9019: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 9020: '</span></td></tr>'."\n";
1.69 raeburn 9021: }
9022: $$rowtotal += $rownum;
9023: return $datatable;
9024: }
9025:
9026: sub serverstatus_pages {
9027: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 9028: 'checksums','clusterstatus','certstatus','metadata_keywords',
9029: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
9030: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 9031: }
9032:
1.236 raeburn 9033: sub defaults_javascript {
9034: my ($settings) = @_;
1.354 raeburn 9035: return unless (ref($settings) eq 'HASH');
1.236 raeburn 9036: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
9037: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
9038: if ($maxnum eq '') {
9039: $maxnum = 0;
9040: }
9041: $maxnum ++;
1.249 raeburn 9042: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 9043: return <<"ENDSCRIPT";
9044: <script type="text/javascript">
9045: // <![CDATA[
9046: function reorderTypes(form,caller) {
9047: var changedVal;
9048: $jstext
9049: var newpos = 'addinststatus_pos';
9050: var current = new Array;
9051: var maxh = $maxnum;
9052: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
9053: var oldVal;
9054: if (caller == newpos) {
9055: changedVal = newitemVal;
9056: } else {
9057: var curritem = 'inststatus_pos_'+caller;
9058: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
9059: current[newitemVal] = newpos;
9060: }
9061: for (var i=0; i<inststatuses.length; i++) {
9062: if (inststatuses[i] != caller) {
9063: var elementName = 'inststatus_pos_'+inststatuses[i];
9064: if (form.elements[elementName]) {
9065: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
9066: current[currVal] = elementName;
9067: }
9068: }
9069: }
9070: for (var j=0; j<maxh; j++) {
9071: if (current[j] == undefined) {
9072: oldVal = j;
9073: }
9074: }
9075: if (oldVal < changedVal) {
9076: for (var k=oldVal+1; k<=changedVal ; k++) {
9077: var elementName = current[k];
9078: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
9079: }
9080: } else {
9081: for (var k=changedVal; k<oldVal; k++) {
9082: var elementName = current[k];
9083: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
9084: }
9085: }
9086: return;
9087: }
9088:
9089: // ]]>
9090: </script>
9091:
9092: ENDSCRIPT
9093: }
1.354 raeburn 9094: return;
9095: }
9096:
9097: sub passwords_javascript {
9098: 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.');
9099: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
9100: &js_escape(\$intauthcheck);
9101: &js_escape(\$intauthcost);
9102: my $intauthjs = <<"ENDSCRIPT";
9103:
9104: function warnIntAuth(field) {
9105: if (field.name == 'intauth_check') {
9106: if (field.value == '2') {
9107: alert('$intauthcheck');
9108: }
9109: }
9110: if (field.name == 'intauth_cost') {
9111: field.value.replace(/\s/g,'');
9112: if (field.value != '') {
9113: var regexdigit=/^\\d+\$/;
9114: if (!regexdigit.test(field.value)) {
9115: alert('$intauthcost');
9116: }
9117: }
9118: }
9119: return;
9120: }
9121:
9122: ENDSCRIPT
9123: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 9124: }
9125:
1.49 raeburn 9126: sub coursecategories_javascript {
9127: my ($settings) = @_;
1.57 raeburn 9128: my ($output,$jstext,$cathash);
1.49 raeburn 9129: if (ref($settings) eq 'HASH') {
1.57 raeburn 9130: $cathash = $settings->{'cats'};
9131: }
9132: if (ref($cathash) eq 'HASH') {
1.49 raeburn 9133: my (@cats,@jsarray,%idx);
1.57 raeburn 9134: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 9135: if (@jsarray > 0) {
9136: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
9137: for (my $i=0; $i<@jsarray; $i++) {
9138: if (ref($jsarray[$i]) eq 'ARRAY') {
9139: my $catstr = join('","',@{$jsarray[$i]});
9140: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
9141: }
9142: }
9143: }
9144: } else {
9145: $jstext = ' var categories = Array(1);'."\n".
9146: ' categories[0] = Array("instcode_pos");'."\n";
9147: }
1.237 bisitz 9148: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
9149: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 9150: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 9151: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
9152: &js_escape(\$instcode_reserved);
9153: &js_escape(\$communities_reserved);
1.272 raeburn 9154: &js_escape(\$placement_reserved);
1.265 damieng 9155: &js_escape(\$choose_again);
1.49 raeburn 9156: $output = <<"ENDSCRIPT";
9157: <script type="text/javascript">
1.109 raeburn 9158: // <![CDATA[
1.49 raeburn 9159: function reorderCats(form,parent,item,idx) {
9160: var changedVal;
9161: $jstext
9162: var newpos = 'addcategory_pos';
9163: if (parent == '') {
9164: var has_instcode = 0;
9165: var maxtop = categories[idx].length;
9166: for (var j=0; j<maxtop; j++) {
9167: if (categories[idx][j] == 'instcode::0') {
9168: has_instcode == 1;
9169: }
9170: }
9171: if (has_instcode == 0) {
9172: categories[idx][maxtop] = 'instcode_pos';
9173: }
9174: } else {
9175: newpos += '_'+parent;
9176: }
9177: var maxh = 1 + categories[idx].length;
9178: var current = new Array;
9179: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
9180: if (item == newpos) {
9181: changedVal = newitemVal;
9182: } else {
9183: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
9184: current[newitemVal] = newpos;
9185: }
9186: for (var i=0; i<categories[idx].length; i++) {
9187: var elementName = categories[idx][i];
9188: if (elementName != item) {
9189: if (form.elements[elementName]) {
9190: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
9191: current[currVal] = elementName;
9192: }
9193: }
9194: }
9195: var oldVal;
9196: for (var j=0; j<maxh; j++) {
9197: if (current[j] == undefined) {
9198: oldVal = j;
9199: }
9200: }
9201: if (oldVal < changedVal) {
9202: for (var k=oldVal+1; k<=changedVal ; k++) {
9203: var elementName = current[k];
9204: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
9205: }
9206: } else {
9207: for (var k=changedVal; k<oldVal; k++) {
9208: var elementName = current[k];
9209: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
9210: }
9211: }
9212: return;
9213: }
1.120 raeburn 9214:
9215: function categoryCheck(form) {
9216: if (form.elements['addcategory_name'].value == 'instcode') {
9217: alert('$instcode_reserved\\n$choose_again');
9218: return false;
9219: }
9220: if (form.elements['addcategory_name'].value == 'communities') {
9221: alert('$communities_reserved\\n$choose_again');
9222: return false;
9223: }
1.272 raeburn 9224: if (form.elements['addcategory_name'].value == 'placement') {
9225: alert('$placement_reserved\\n$choose_again');
9226: return false;
9227: }
1.120 raeburn 9228: return true;
9229: }
9230:
1.109 raeburn 9231: // ]]>
1.49 raeburn 9232: </script>
9233:
9234: ENDSCRIPT
9235: return $output;
9236: }
9237:
1.48 raeburn 9238: sub initialize_categories {
9239: my ($itemcount) = @_;
1.120 raeburn 9240: my ($datatable,$css_class,$chgstr);
9241: my %default_names = (
9242: instcode => 'Official courses (with institutional codes)',
9243: communities => 'Communities',
1.272 raeburn 9244: placement => 'Placement Tests',
1.120 raeburn 9245: );
1.328 raeburn 9246: my %selnum = (
9247: instcode => '0',
9248: communities => '1',
9249: placement => '2',
9250: );
9251: my %selected;
1.272 raeburn 9252: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 9253: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 9254: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 9255: map { $selected{$selnum{$_}} = '' } keys(%selnum);
9256: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 9257: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 9258: .'<select name="'.$default.'_pos"'.$chgstr.'>'
9259: .'<option value="0"'.$selected{'0'}.'>1</option>'
9260: .'<option value="1"'.$selected{'1'}.'>2</option>'
9261: .'<option value="2"'.$selected{'2'}.'>3</option>'
9262: .'<option value="3">4</option></select> '
1.120 raeburn 9263: .$default_names{$default}
9264: .'</span></td><td><span class="LC_nobreak">'
9265: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
9266: .&mt('Display').'</label> <label>'
9267: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 9268: .'</label></span></td></tr>';
1.120 raeburn 9269: $itemcount ++;
9270: }
1.48 raeburn 9271: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 9272: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 9273: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 9274: .'<select name="addcategory_pos"'.$chgstr.'>'
9275: .'<option value="0">1</option>'
9276: .'<option value="1">2</option>'
1.328 raeburn 9277: .'<option value="2">3</option>'
9278: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 9279: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
9280: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
9281: .'</td></tr>';
1.48 raeburn 9282: return $datatable;
9283: }
9284:
9285: sub build_category_rows {
1.49 raeburn 9286: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
9287: my ($text,$name,$item,$chgstr);
1.48 raeburn 9288: if (ref($cats) eq 'ARRAY') {
9289: my $maxdepth = scalar(@{$cats});
9290: if (ref($cats->[$depth]) eq 'HASH') {
9291: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9292: my $numchildren = @{$cats->[$depth]{$parent}};
9293: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 9294: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 9295: my ($idxnum,$parent_name,$parent_item);
9296: my $higher = $depth - 1;
9297: if ($higher == 0) {
9298: $parent_name = &escape($parent).'::'.$higher;
9299: } else {
9300: if (ref($path) eq 'ARRAY') {
9301: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
9302: }
9303: }
9304: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 9305: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 9306: if ($j < $numchildren) {
1.48 raeburn 9307: $name = $cats->[$depth]{$parent}[$j];
9308: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 9309: $idxnum = $idx->{$item};
9310: } else {
9311: $name = $parent_name;
9312: $item = $parent_item;
1.48 raeburn 9313: }
1.49 raeburn 9314: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
9315: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 9316: for (my $i=0; $i<=$numchildren; $i++) {
9317: my $vpos = $i+1;
9318: my $selstr;
9319: if ($j == $i) {
9320: $selstr = ' selected="selected" ';
9321: }
9322: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
9323: }
9324: $text .= '</select> ';
9325: if ($j < $numchildren) {
9326: my $deeper = $depth+1;
9327: $text .= $name.' '
9328: .'<label><input type="checkbox" name="deletecategory" value="'
9329: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
9330: if(ref($path) eq 'ARRAY') {
9331: push(@{$path},$name);
1.49 raeburn 9332: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 9333: pop(@{$path});
9334: }
9335: } else {
1.330 raeburn 9336: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 9337: if ($j == $numchildren) {
9338: $text .= $name;
9339: } else {
9340: $text .= $item;
9341: }
9342: $text .= '" value="" />';
9343: }
9344: $text .= '</td></tr>';
9345: }
9346: $text .= '</table></td>';
9347: } else {
9348: my $higher = $depth-1;
9349: if ($higher == 0) {
9350: $name = &escape($parent).'::'.$higher;
9351: } else {
9352: if (ref($path) eq 'ARRAY') {
9353: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
9354: }
9355: }
9356: my $colspan;
9357: if ($parent ne 'instcode') {
9358: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 9359: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 9360: }
9361: }
9362: }
9363: }
9364: return $text;
9365: }
9366:
1.33 raeburn 9367: sub modifiable_userdata_row {
1.305 raeburn 9368: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
9369: $rowid,$customcss,$rowstyle) = @_;
1.228 raeburn 9370: my ($role,$rolename,$statustype);
9371: $role = $item;
1.224 raeburn 9372: if ($context eq 'cancreate') {
1.305 raeburn 9373: if ($item =~ /^(emailusername)_(.+)$/) {
9374: $role = $1;
9375: $statustype = $2;
1.228 raeburn 9376: if (ref($usertypes) eq 'HASH') {
9377: if ($usertypes->{$statustype}) {
9378: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
9379: } else {
9380: $rolename = &mt('Data provided by user');
9381: }
9382: }
1.224 raeburn 9383: }
9384: } elsif ($context eq 'selfcreate') {
1.63 raeburn 9385: if (ref($usertypes) eq 'HASH') {
9386: $rolename = $usertypes->{$role};
9387: } else {
9388: $rolename = $role;
9389: }
1.325 raeburn 9390: } elsif ($context eq 'lti') {
9391: $rolename = &mt('Institutional data used (if available)');
1.33 raeburn 9392: } else {
1.63 raeburn 9393: if ($role eq 'cr') {
9394: $rolename = &mt('Custom role');
9395: } else {
9396: $rolename = &Apache::lonnet::plaintext($role);
9397: }
1.33 raeburn 9398: }
1.224 raeburn 9399: my (@fields,%fieldtitles);
9400: if (ref($fieldsref) eq 'ARRAY') {
9401: @fields = @{$fieldsref};
9402: } else {
9403: @fields = ('lastname','firstname','middlename','generation',
9404: 'permanentemail','id');
9405: }
9406: if ((ref($titlesref) eq 'HASH')) {
9407: %fieldtitles = %{$titlesref};
9408: } else {
9409: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9410: }
1.33 raeburn 9411: my $output;
1.305 raeburn 9412: my $css_class;
9413: if ($rowcount%2) {
9414: $css_class = 'LC_odd_row';
9415: }
9416: if ($customcss) {
9417: $css_class .= " $customcss";
9418: }
9419: $css_class =~ s/^\s+//;
9420: if ($css_class) {
9421: $css_class = ' class="'.$css_class.'"';
9422: }
9423: if ($rowstyle) {
9424: $css_class .= ' style="'.$rowstyle.'"';
9425: }
9426: if ($rowid) {
9427: $rowid = ' id="'.$rowid.'"';
9428: }
9429: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 9430: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
9431: '<td class="LC_left_item" colspan="2"><table>';
9432: my $rem;
9433: my %checks;
1.325 raeburn 9434: my %current;
1.33 raeburn 9435: if (ref($settings) eq 'HASH') {
1.325 raeburn 9436: my $hashref;
9437: if ($context eq 'lti') {
9438: if (ref($settings) eq 'HASH') {
9439: $hashref = $settings->{'instdata'};
9440: }
9441: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 9442: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 9443: $hashref = $settings->{'lti_instdata'};
9444: }
9445: if ($role eq 'emailusername') {
9446: if ($statustype) {
9447: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
9448: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 9449: }
1.325 raeburn 9450: }
9451: }
9452: }
9453: if (ref($hashref) eq 'HASH') {
9454: foreach my $field (@fields) {
9455: if ($hashref->{$field}) {
9456: if ($role eq 'emailusername') {
9457: $checks{$field} = $hashref->{$field};
9458: } else {
9459: $checks{$field} = ' checked="checked" ';
1.33 raeburn 9460: }
9461: }
9462: }
9463: }
9464: }
1.305 raeburn 9465:
9466: my $total = scalar(@fields);
9467: for (my $i=0; $i<$total; $i++) {
9468: $rem = $i%($numinrow);
1.33 raeburn 9469: if ($rem == 0) {
9470: if ($i > 0) {
9471: $output .= '</tr>';
9472: }
9473: $output .= '<tr>';
9474: }
9475: my $check = ' ';
1.228 raeburn 9476: unless ($role eq 'emailusername') {
9477: if (exists($checks{$fields[$i]})) {
1.354 raeburn 9478: $check = $checks{$fields[$i]};
1.325 raeburn 9479: } elsif ($context ne 'lti') {
1.228 raeburn 9480: if ($role eq 'st') {
9481: if (ref($settings) ne 'HASH') {
9482: $check = ' checked="checked" ';
9483: }
1.33 raeburn 9484: }
9485: }
9486: }
9487: $output .= '<td class="LC_left_item">'.
1.228 raeburn 9488: '<span class="LC_nobreak">';
1.325 raeburn 9489: my $prefix = 'canmodify';
1.228 raeburn 9490: if ($role eq 'emailusername') {
9491: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
9492: $checks{$fields[$i]} = 'omit';
9493: }
9494: foreach my $option ('required','optional','omit') {
9495: my $checked='';
9496: if ($checks{$fields[$i]} eq $option) {
9497: $checked='checked="checked" ';
9498: }
9499: $output .= '<label>'.
1.325 raeburn 9500: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 9501: &mt($option).'</label>'.(' ' x2);
9502: }
9503: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
9504: } else {
1.325 raeburn 9505: if ($context eq 'lti') {
9506: $prefix = 'lti';
9507: }
1.228 raeburn 9508: $output .= '<label>'.
1.325 raeburn 9509: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 9510: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
9511: '</label>';
9512: }
9513: $output .= '</span></td>';
1.33 raeburn 9514: }
1.305 raeburn 9515: $rem = $total%$numinrow;
9516: my $colsleft;
9517: if ($rem) {
9518: $colsleft = $numinrow - $rem;
9519: }
9520: if ($colsleft > 1) {
1.33 raeburn 9521: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9522: ' </td>';
9523: } elsif ($colsleft == 1) {
9524: $output .= '<td class="LC_left_item"> </td>';
9525: }
9526: $output .= '</tr></table></td></tr>';
9527: return $output;
9528: }
1.28 raeburn 9529:
1.93 raeburn 9530: sub insttypes_row {
1.305 raeburn 9531: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
9532: $customcss,$rowstyle) = @_;
1.93 raeburn 9533: my %lt = &Apache::lonlocal::texthash (
9534: cansearch => 'Users allowed to search',
9535: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 9536: lockablenames => 'User preference to lock name',
1.305 raeburn 9537: selfassign => 'Self-reportable affiliations',
1.315 raeburn 9538: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 9539: );
9540: my $showdom;
9541: if ($context eq 'cansearch') {
9542: $showdom = ' ('.$dom.')';
9543: }
1.165 raeburn 9544: my $class = 'LC_left_item';
9545: if ($context eq 'statustocreate') {
9546: $class = 'LC_right_item';
9547: }
1.305 raeburn 9548: my $css_class;
9549: if ($$rowtotal%2) {
9550: $css_class = 'LC_odd_row';
9551: }
9552: if ($customcss) {
9553: $css_class .= ' '.$customcss;
9554: }
9555: $css_class =~ s/^\s+//;
9556: if ($css_class) {
9557: $css_class = ' class="'.$css_class.'"';
9558: }
9559: if ($rowstyle) {
9560: $css_class .= ' style="'.$rowstyle.'"';
9561: }
9562: if ($onclick) {
9563: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 9564: }
9565: my $output = '<tr'.$css_class.'>'.
9566: '<td>'.$lt{$context}.$showdom.
9567: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 9568: my $rem;
9569: if (ref($types) eq 'ARRAY') {
9570: for (my $i=0; $i<@{$types}; $i++) {
9571: if (defined($usertypes->{$types->[$i]})) {
9572: my $rem = $i%($numinrow);
9573: if ($rem == 0) {
9574: if ($i > 0) {
9575: $output .= '</tr>';
9576: }
9577: $output .= '<tr>';
1.23 raeburn 9578: }
1.26 raeburn 9579: my $check = ' ';
1.99 raeburn 9580: if (ref($settings) eq 'HASH') {
9581: if (ref($settings->{$context}) eq 'ARRAY') {
9582: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
9583: $check = ' checked="checked" ';
9584: }
1.315 raeburn 9585: } elsif (ref($settings->{$context}) eq 'HASH') {
9586: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
9587: $check = ' checked="checked" ';
9588: }
1.99 raeburn 9589: } elsif ($context eq 'statustocreate') {
1.26 raeburn 9590: $check = ' checked="checked" ';
9591: }
1.23 raeburn 9592: }
1.26 raeburn 9593: $output .= '<td class="LC_left_item">'.
9594: '<span class="LC_nobreak"><label>'.
1.93 raeburn 9595: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 9596: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 9597: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 9598: }
9599: }
1.26 raeburn 9600: $rem = @{$types}%($numinrow);
1.23 raeburn 9601: }
9602: my $colsleft = $numinrow - $rem;
1.315 raeburn 9603: if ($context eq 'overrides') {
9604: if ($colsleft > 1) {
9605: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9606: } else {
9607: $output .= '<td class="LC_left_item">';
9608: }
9609: $output .= ' ';
1.23 raeburn 9610: } else {
1.334 raeburn 9611: if ($rem == 0) {
1.315 raeburn 9612: $output .= '<tr>';
9613: }
9614: if ($colsleft > 1) {
9615: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9616: } else {
9617: $output .= '<td class="LC_left_item">';
9618: }
9619: my $defcheck = ' ';
9620: if (ref($settings) eq 'HASH') {
9621: if (ref($settings->{$context}) eq 'ARRAY') {
9622: if (grep(/^default$/,@{$settings->{$context}})) {
9623: $defcheck = ' checked="checked" ';
9624: }
9625: } elsif ($context eq 'statustocreate') {
1.99 raeburn 9626: $defcheck = ' checked="checked" ';
9627: }
1.26 raeburn 9628: }
1.315 raeburn 9629: $output .= '<span class="LC_nobreak"><label>'.
9630: '<input type="checkbox" name="'.$context.'" '.
9631: 'value="default"'.$defcheck.$onclick.' />'.
9632: $othertitle.'</label></span>';
1.23 raeburn 9633: }
1.315 raeburn 9634: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 9635: return $output;
1.23 raeburn 9636: }
9637:
9638: sub sorted_searchtitles {
9639: my %searchtitles = &Apache::lonlocal::texthash(
9640: 'uname' => 'username',
9641: 'lastname' => 'last name',
9642: 'lastfirst' => 'last name, first name',
9643: );
9644: my @titleorder = ('uname','lastname','lastfirst');
9645: return (\%searchtitles,\@titleorder);
9646: }
9647:
1.25 raeburn 9648: sub sorted_searchtypes {
9649: my %srchtypes_desc = (
9650: exact => 'is exact match',
9651: contains => 'contains ..',
9652: begins => 'begins with ..',
9653: );
9654: my @srchtypeorder = ('exact','begins','contains');
9655: return (\%srchtypes_desc,\@srchtypeorder);
9656: }
9657:
1.3 raeburn 9658: sub usertype_update_row {
9659: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
9660: my $datatable;
9661: my $numinrow = 4;
9662: foreach my $type (@{$types}) {
9663: if (defined($usertypes->{$type})) {
9664: $$rownums ++;
9665: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
9666: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
9667: '</td><td class="LC_left_item"><table>';
9668: for (my $i=0; $i<@{$fields}; $i++) {
9669: my $rem = $i%($numinrow);
9670: if ($rem == 0) {
9671: if ($i > 0) {
9672: $datatable .= '</tr>';
9673: }
9674: $datatable .= '<tr>';
9675: }
9676: my $check = ' ';
1.39 raeburn 9677: if (ref($settings) eq 'HASH') {
9678: if (ref($settings->{'fields'}) eq 'HASH') {
9679: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
9680: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
9681: $check = ' checked="checked" ';
9682: }
1.3 raeburn 9683: }
9684: }
9685: }
9686:
9687: if ($i == @{$fields}-1) {
9688: my $colsleft = $numinrow - $rem;
9689: if ($colsleft > 1) {
9690: $datatable .= '<td colspan="'.$colsleft.'">';
9691: } else {
9692: $datatable .= '<td>';
9693: }
9694: } else {
9695: $datatable .= '<td>';
9696: }
1.8 raeburn 9697: $datatable .= '<span class="LC_nobreak"><label>'.
9698: '<input type="checkbox" name="updateable_'.$type.
9699: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
9700: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 9701: }
9702: $datatable .= '</tr></table></td></tr>';
9703: }
9704: }
9705: return $datatable;
1.1 raeburn 9706: }
9707:
9708: sub modify_login {
1.205 raeburn 9709: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 9710: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
9711: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
9712: %title = ( coursecatalog => 'Display course catalog',
9713: adminmail => 'Display administrator E-mail address',
1.188 raeburn 9714: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 9715: newuser => 'Link for visitors to create a user account',
9716: loginheader => 'Log-in box header');
9717: @offon = ('off','on');
1.112 raeburn 9718: if (ref($domconfig{login}) eq 'HASH') {
9719: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
9720: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
9721: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
9722: }
9723: }
9724: }
1.9 raeburn 9725: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
9726: \%domconfig,\%loginhash);
1.188 raeburn 9727: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9728: foreach my $item (@toggles) {
9729: $loginhash{login}{$item} = $env{'form.'.$item};
9730: }
1.41 raeburn 9731: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 9732: if (ref($colchanges{'login'}) eq 'HASH') {
9733: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
9734: \%loginhash);
9735: }
1.110 raeburn 9736:
1.149 raeburn 9737: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 9738: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 9739: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 9740: if (keys(%servers) > 1) {
9741: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 9742: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
9743: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
9744: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
9745: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
9746: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
9747: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9748: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9749: $changes{'loginvia'}{$lonhost} = 1;
9750: } else {
9751: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
9752: $changes{'loginvia'}{$lonhost} = 1;
9753: }
9754: } else {
9755: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9756: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9757: $changes{'loginvia'}{$lonhost} = 1;
9758: }
9759: }
9760: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
9761: foreach my $item (@loginvia_attribs) {
9762: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
9763: }
9764: } else {
9765: foreach my $item (@loginvia_attribs) {
9766: my $new = $env{'form.'.$lonhost.'_'.$item};
9767: if (($item eq 'serverpath') && ($new eq 'custom')) {
9768: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
9769: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9770: $new = '/';
9771: }
9772: }
9773: if (($item eq 'custompath') &&
9774: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9775: $new = '';
9776: }
9777: if ($new ne $curr_loginvia{$lonhost}{$item}) {
9778: $changes{'loginvia'}{$lonhost} = 1;
9779: }
9780: if ($item eq 'exempt') {
1.256 raeburn 9781: $new = &check_exempt_addresses($new);
1.128 raeburn 9782: }
9783: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9784: }
9785: }
1.112 raeburn 9786: } else {
1.128 raeburn 9787: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9788: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 9789: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 9790: foreach my $item (@loginvia_attribs) {
9791: my $new = $env{'form.'.$lonhost.'_'.$item};
9792: if (($item eq 'serverpath') && ($new eq 'custom')) {
9793: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9794: $new = '/';
9795: }
9796: }
9797: if (($item eq 'custompath') &&
9798: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9799: $new = '';
9800: }
9801: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9802: }
1.110 raeburn 9803: }
9804: }
9805: }
9806: }
1.119 raeburn 9807:
1.168 raeburn 9808: my $servadm = $r->dir_config('lonAdmEMail');
9809: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
9810: if (ref($domconfig{'login'}) eq 'HASH') {
9811: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
9812: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
9813: if ($lang eq 'nolang') {
9814: push(@currlangs,$lang);
9815: } elsif (defined($langchoices{$lang})) {
9816: push(@currlangs,$lang);
9817: } else {
9818: next;
9819: }
9820: }
9821: }
9822: }
9823: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
9824: if (@currlangs > 0) {
9825: foreach my $lang (@currlangs) {
9826: if (grep(/^\Q$lang\E$/,@delurls)) {
9827: $changes{'helpurl'}{$lang} = 1;
9828: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
9829: $changes{'helpurl'}{$lang} = 1;
9830: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
9831: push(@newlangs,$lang);
9832: } else {
9833: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9834: }
9835: }
9836: }
9837: unless (grep(/^nolang$/,@currlangs)) {
9838: if ($env{'form.loginhelpurl_nolang.filename'}) {
9839: $changes{'helpurl'}{'nolang'} = 1;
9840: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
9841: push(@newlangs,'nolang');
9842: }
9843: }
9844: if ($env{'form.loginhelpurl_add_lang'}) {
9845: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
9846: ($env{'form.loginhelpurl_add_file.filename'})) {
9847: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
9848: $addedfile = $env{'form.loginhelpurl_add_lang'};
9849: }
9850: }
9851: if ((@newlangs > 0) || ($addedfile)) {
9852: my $error;
9853: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9854: if ($configuserok eq 'ok') {
9855: if ($switchserver) {
9856: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
9857: } elsif ($author_ok eq 'ok') {
9858: my @allnew = @newlangs;
9859: if ($addedfile ne '') {
9860: push(@allnew,$addedfile);
9861: }
9862: foreach my $lang (@allnew) {
9863: my $formelem = 'loginhelpurl_'.$lang;
9864: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
9865: $formelem = 'loginhelpurl_add_file';
9866: }
9867: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9868: "help/$lang",'','',$newfile{$lang});
9869: if ($result eq 'ok') {
9870: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
9871: $changes{'helpurl'}{$lang} = 1;
9872: } else {
9873: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
9874: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 9875: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 9876: (!grep(/^\Q$lang\E$/,@delurls))) {
9877: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9878: }
9879: }
9880: }
9881: } else {
9882: $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);
9883: }
9884: } else {
9885: $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);
9886: }
9887: if ($error) {
9888: &Apache::lonnet::logthis($error);
9889: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9890: }
9891: }
1.256 raeburn 9892:
9893: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
9894: if (ref($domconfig{'login'}) eq 'HASH') {
9895: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
9896: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
9897: if ($domservers{$lonhost}) {
9898: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9899: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 9900: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 9901: }
9902: }
9903: }
9904: }
9905: }
9906: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
9907: foreach my $lonhost (sort(keys(%domservers))) {
9908: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9909: $changes{'headtag'}{$lonhost} = 1;
9910: } else {
9911: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
9912: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
9913: }
9914: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
9915: push(@newhosts,$lonhost);
9916: } elsif ($currheadtagurls{$lonhost}) {
9917: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
9918: if ($currexempt{$lonhost}) {
1.289 raeburn 9919: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 9920: $changes{'headtag'}{$lonhost} = 1;
9921: }
9922: } elsif ($possexempt{$lonhost}) {
9923: $changes{'headtag'}{$lonhost} = 1;
9924: }
9925: if ($possexempt{$lonhost}) {
9926: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9927: }
9928: }
9929: }
9930: }
9931: if (@newhosts) {
9932: my $error;
9933: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9934: if ($configuserok eq 'ok') {
9935: if ($switchserver) {
9936: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
9937: } elsif ($author_ok eq 'ok') {
9938: foreach my $lonhost (@newhosts) {
9939: my $formelem = 'loginheadtag_'.$lonhost;
9940: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9941: "login/headtag/$lonhost",'','',
9942: $env{'form.loginheadtag_'.$lonhost.'.filename'});
9943: if ($result eq 'ok') {
9944: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
9945: $changes{'headtag'}{$lonhost} = 1;
9946: if ($possexempt{$lonhost}) {
9947: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9948: }
9949: } else {
9950: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
9951: $newheadtagurls{$lonhost},$result);
9952: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9953: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
9954: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
9955: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
9956: }
9957: }
9958: }
9959: } else {
9960: $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);
9961: }
9962: } else {
9963: $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);
9964: }
9965: if ($error) {
9966: &Apache::lonnet::logthis($error);
9967: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9968: }
9969: }
1.169 raeburn 9970: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 9971:
9972: my $defaulthelpfile = '/adm/loginproblems.html';
9973: my $defaulttext = &mt('Default in use');
9974:
1.1 raeburn 9975: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
9976: $dom);
9977: if ($putresult eq 'ok') {
1.188 raeburn 9978: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9979: my %defaultchecked = (
9980: 'coursecatalog' => 'on',
1.188 raeburn 9981: 'helpdesk' => 'on',
1.42 raeburn 9982: 'adminmail' => 'off',
1.43 raeburn 9983: 'newuser' => 'off',
1.42 raeburn 9984: );
1.55 raeburn 9985: if (ref($domconfig{'login'}) eq 'HASH') {
9986: foreach my $item (@toggles) {
9987: if ($defaultchecked{$item} eq 'on') {
9988: if (($domconfig{'login'}{$item} eq '0') &&
9989: ($env{'form.'.$item} eq '1')) {
9990: $changes{$item} = 1;
9991: } elsif (($domconfig{'login'}{$item} eq '' ||
9992: $domconfig{'login'}{$item} eq '1') &&
9993: ($env{'form.'.$item} eq '0')) {
9994: $changes{$item} = 1;
9995: }
9996: } elsif ($defaultchecked{$item} eq 'off') {
9997: if (($domconfig{'login'}{$item} eq '1') &&
9998: ($env{'form.'.$item} eq '0')) {
9999: $changes{$item} = 1;
10000: } elsif (($domconfig{'login'}{$item} eq '' ||
10001: $domconfig{'login'}{$item} eq '0') &&
10002: ($env{'form.'.$item} eq '1')) {
10003: $changes{$item} = 1;
10004: }
1.42 raeburn 10005: }
10006: }
1.41 raeburn 10007: }
1.6 raeburn 10008: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 10009: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10010: if (ref($lastactref) eq 'HASH') {
10011: $lastactref->{'domainconfig'} = 1;
10012: }
1.1 raeburn 10013: $resulttext = &mt('Changes made:').'<ul>';
10014: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 10015: if ($item eq 'loginvia') {
1.112 raeburn 10016: if (ref($changes{$item}) eq 'HASH') {
10017: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
10018: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 10019: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
10020: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
10021: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
10022: $protocol = 'http' if ($protocol ne 'https');
10023: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
10024:
10025: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
10026: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
10027: } else {
10028: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
10029: }
10030: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
10031: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
10032: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
10033: }
10034: $resulttext .= '</li>';
10035: } else {
10036: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
10037: }
1.112 raeburn 10038: } else {
1.128 raeburn 10039: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 10040: }
10041: }
1.128 raeburn 10042: $resulttext .= '</ul></li>';
1.112 raeburn 10043: }
1.168 raeburn 10044: } elsif ($item eq 'helpurl') {
10045: if (ref($changes{$item}) eq 'HASH') {
10046: foreach my $lang (sort(keys(%{$changes{$item}}))) {
10047: if (grep(/^\Q$lang\E$/,@delurls)) {
10048: my ($chg,$link);
10049: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
10050: if ($lang eq 'nolang') {
10051: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
10052: } else {
10053: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
10054: }
10055: $resulttext .= '<li>'.$chg.'</li>';
10056: } else {
10057: my $chg;
10058: if ($lang eq 'nolang') {
10059: $chg = &mt('custom log-in help file for no preferred language');
10060: } else {
10061: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
10062: }
10063: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
10064: $loginhash{'login'}{'helpurl'}{$lang}.
10065: '?inhibitmenu=yes',$chg,600,500).
10066: '</li>';
10067: }
10068: }
10069: }
1.256 raeburn 10070: } elsif ($item eq 'headtag') {
10071: if (ref($changes{$item}) eq 'HASH') {
10072: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
10073: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
10074: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
10075: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
10076: $resulttext .= '<li><a href="'.
10077: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
10078: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
10079: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
10080: if ($possexempt{$lonhost}) {
10081: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
10082: } else {
10083: $resulttext .= &mt('included for any client IP');
10084: }
10085: $resulttext .= '</li>';
10086: }
10087: }
10088: }
1.169 raeburn 10089: } elsif ($item eq 'captcha') {
10090: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 10091: my $chgtxt;
1.169 raeburn 10092: if ($loginhash{'login'}{$item} eq 'notused') {
10093: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
10094: } else {
10095: my %captchas = &captcha_phrases();
10096: if ($captchas{$loginhash{'login'}{$item}}) {
10097: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
10098: } else {
10099: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
10100: }
10101: }
10102: $resulttext .= '<li>'.$chgtxt.'</li>';
10103: }
10104: } elsif ($item eq 'recaptchakeys') {
10105: if (ref($loginhash{'login'}) eq 'HASH') {
10106: my ($privkey,$pubkey);
10107: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
10108: $pubkey = $loginhash{'login'}{$item}{'public'};
10109: $privkey = $loginhash{'login'}{$item}{'private'};
10110: }
10111: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
10112: if (!$pubkey) {
10113: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
10114: } else {
10115: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
10116: }
10117: if (!$privkey) {
10118: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
10119: } else {
1.251 raeburn 10120: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 10121: }
10122: $chgtxt .= '</ul>';
10123: $resulttext .= '<li>'.$chgtxt.'</li>';
10124: }
1.269 raeburn 10125: } elsif ($item eq 'recaptchaversion') {
10126: if (ref($loginhash{'login'}) eq 'HASH') {
10127: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 10128: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 10129: '</li>';
10130: }
10131: }
1.41 raeburn 10132: } else {
10133: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
10134: }
1.1 raeburn 10135: }
1.6 raeburn 10136: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 10137: } else {
10138: $resulttext = &mt('No changes made to log-in page settings');
10139: }
10140: } else {
1.11 albertel 10141: $resulttext = '<span class="LC_error">'.
10142: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10143: }
1.6 raeburn 10144: if ($errors) {
1.9 raeburn 10145: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 10146: $errors.'</ul>';
10147: }
10148: return $resulttext;
10149: }
10150:
1.256 raeburn 10151: sub check_exempt_addresses {
10152: my ($iplist) = @_;
10153: $iplist =~ s/^\s+//;
10154: $iplist =~ s/\s+$//;
10155: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
10156: my (@okips,$new);
10157: foreach my $ip (@poss_ips) {
10158: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
10159: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
10160: push(@okips,$ip);
10161: }
10162: }
10163: }
10164: if (@okips > 0) {
10165: $new = join(',',@okips);
10166: } else {
10167: $new = '';
10168: }
10169: return $new;
10170: }
10171:
1.6 raeburn 10172: sub color_font_choices {
10173: my %choices =
10174: &Apache::lonlocal::texthash (
10175: img => "Header",
10176: bgs => "Background colors",
10177: links => "Link colors",
1.55 raeburn 10178: images => "Images",
1.6 raeburn 10179: font => "Font color",
1.201 raeburn 10180: fontmenu => "Font menu",
1.76 raeburn 10181: pgbg => "Page",
1.6 raeburn 10182: tabbg => "Header",
10183: sidebg => "Border",
10184: link => "Link",
10185: alink => "Active link",
10186: vlink => "Visited link",
10187: );
10188: return %choices;
10189: }
10190:
10191: sub modify_rolecolors {
1.205 raeburn 10192: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 10193: my ($resulttext,%rolehash);
10194: $rolehash{'rolecolors'} = {};
1.55 raeburn 10195: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
10196: if ($domconfig{'rolecolors'} eq '') {
10197: $domconfig{'rolecolors'} = {};
10198: }
10199: }
1.9 raeburn 10200: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 10201: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
10202: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
10203: $dom);
10204: if ($putresult eq 'ok') {
10205: if (keys(%changes) > 0) {
1.41 raeburn 10206: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10207: if (ref($lastactref) eq 'HASH') {
10208: $lastactref->{'domainconfig'} = 1;
10209: }
1.6 raeburn 10210: $resulttext = &display_colorchgs($dom,\%changes,$roles,
10211: $rolehash{'rolecolors'});
10212: } else {
10213: $resulttext = &mt('No changes made to default color schemes');
10214: }
10215: } else {
1.11 albertel 10216: $resulttext = '<span class="LC_error">'.
10217: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 10218: }
10219: if ($errors) {
10220: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10221: $errors.'</ul>';
10222: }
10223: return $resulttext;
10224: }
10225:
10226: sub modify_colors {
1.9 raeburn 10227: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 10228: my (%changes,%choices);
1.51 raeburn 10229: my @bgs;
1.6 raeburn 10230: my @links = ('link','alink','vlink');
1.41 raeburn 10231: my @logintext;
1.6 raeburn 10232: my @images;
10233: my $servadm = $r->dir_config('lonAdmEMail');
10234: my $errors;
1.200 raeburn 10235: my %defaults;
1.6 raeburn 10236: foreach my $role (@{$roles}) {
10237: if ($role eq 'login') {
1.12 raeburn 10238: %choices = &login_choices();
1.41 raeburn 10239: @logintext = ('textcol','bgcol');
1.12 raeburn 10240: } else {
10241: %choices = &color_font_choices();
10242: }
10243: if ($role eq 'login') {
1.41 raeburn 10244: @images = ('img','logo','domlogo','login');
1.51 raeburn 10245: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 10246: } else {
10247: @images = ('img');
1.200 raeburn 10248: @bgs = ('pgbg','tabbg','sidebg');
10249: }
10250: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
10251: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
10252: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
10253: }
10254: if ($role eq 'login') {
10255: foreach my $item (@logintext) {
1.234 raeburn 10256: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10257: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10258: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10259: }
10260: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 10261: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10262: }
10263: }
10264: } else {
1.234 raeburn 10265: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
10266: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
10267: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
10268: }
10269: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 10270: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
10271: }
1.6 raeburn 10272: }
1.200 raeburn 10273: foreach my $item (@bgs) {
1.234 raeburn 10274: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10275: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10276: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10277: }
10278: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 10279: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10280: }
10281: }
10282: foreach my $item (@links) {
1.234 raeburn 10283: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10284: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10285: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10286: }
10287: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 10288: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10289: }
1.6 raeburn 10290: }
1.46 raeburn 10291: my ($configuserok,$author_ok,$switchserver) =
10292: &config_check($dom,$confname,$servadm);
1.9 raeburn 10293: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 10294: if (ref($domconfig->{$role}) ne 'HASH') {
10295: $domconfig->{$role} = {};
10296: }
1.8 raeburn 10297: foreach my $img (@images) {
1.70 raeburn 10298: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
10299: if (defined($env{'form.login_showlogo_'.$img})) {
10300: $confhash->{$role}{'showlogo'}{$img} = 1;
10301: } else {
10302: $confhash->{$role}{'showlogo'}{$img} = 0;
10303: }
10304: }
1.18 albertel 10305: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
10306: && !defined($domconfig->{$role}{$img})
10307: && !$env{'form.'.$role.'_del_'.$img}
10308: && $env{'form.'.$role.'_import_'.$img}) {
10309: # import the old configured image from the .tab setting
10310: # if they haven't provided a new one
10311: $domconfig->{$role}{$img} =
10312: $env{'form.'.$role.'_import_'.$img};
10313: }
1.6 raeburn 10314: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 10315: my $error;
1.6 raeburn 10316: if ($configuserok eq 'ok') {
1.9 raeburn 10317: if ($switchserver) {
1.12 raeburn 10318: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 10319: } else {
10320: if ($author_ok eq 'ok') {
10321: my ($result,$logourl) =
10322: &publishlogo($r,'upload',$role.'_'.$img,
10323: $dom,$confname,$img,$width,$height);
10324: if ($result eq 'ok') {
10325: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 10326: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 10327: } else {
1.12 raeburn 10328: $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 10329: }
10330: } else {
1.46 raeburn 10331: $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 10332: }
10333: }
10334: } else {
1.46 raeburn 10335: $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 10336: }
10337: if ($error) {
1.8 raeburn 10338: &Apache::lonnet::logthis($error);
1.11 albertel 10339: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 10340: }
10341: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 10342: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
10343: my $error;
10344: if ($configuserok eq 'ok') {
10345: # is confname an author?
10346: if ($switchserver eq '') {
10347: if ($author_ok eq 'ok') {
10348: my ($result,$logourl) =
10349: &publishlogo($r,'copy',$domconfig->{$role}{$img},
10350: $dom,$confname,$img,$width,$height);
10351: if ($result eq 'ok') {
10352: $confhash->{$role}{$img} = $logourl;
1.18 albertel 10353: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 10354: }
10355: }
10356: }
10357: }
1.6 raeburn 10358: }
10359: }
10360: }
10361: if (ref($domconfig) eq 'HASH') {
10362: if (ref($domconfig->{$role}) eq 'HASH') {
10363: foreach my $img (@images) {
10364: if ($domconfig->{$role}{$img} ne '') {
10365: if ($env{'form.'.$role.'_del_'.$img}) {
10366: $confhash->{$role}{$img} = '';
1.12 raeburn 10367: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 10368: } else {
1.9 raeburn 10369: if ($confhash->{$role}{$img} eq '') {
10370: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
10371: }
1.6 raeburn 10372: }
10373: } else {
10374: if ($env{'form.'.$role.'_del_'.$img}) {
10375: $confhash->{$role}{$img} = '';
1.12 raeburn 10376: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 10377: }
10378: }
1.70 raeburn 10379: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
10380: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
10381: if ($confhash->{$role}{'showlogo'}{$img} ne
10382: $domconfig->{$role}{'showlogo'}{$img}) {
10383: $changes{$role}{'showlogo'}{$img} = 1;
10384: }
10385: } else {
10386: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
10387: $changes{$role}{'showlogo'}{$img} = 1;
10388: }
10389: }
10390: }
10391: }
1.6 raeburn 10392: if ($domconfig->{$role}{'font'} ne '') {
10393: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
10394: $changes{$role}{'font'} = 1;
10395: }
10396: } else {
10397: if ($confhash->{$role}{'font'}) {
10398: $changes{$role}{'font'} = 1;
10399: }
10400: }
1.107 raeburn 10401: if ($role ne 'login') {
10402: if ($domconfig->{$role}{'fontmenu'} ne '') {
10403: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
10404: $changes{$role}{'fontmenu'} = 1;
10405: }
10406: } else {
10407: if ($confhash->{$role}{'fontmenu'}) {
10408: $changes{$role}{'fontmenu'} = 1;
10409: }
1.97 tempelho 10410: }
10411: }
1.6 raeburn 10412: foreach my $item (@bgs) {
10413: if ($domconfig->{$role}{$item} ne '') {
10414: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10415: $changes{$role}{'bgs'}{$item} = 1;
10416: }
10417: } else {
10418: if ($confhash->{$role}{$item}) {
10419: $changes{$role}{'bgs'}{$item} = 1;
10420: }
10421: }
10422: }
10423: foreach my $item (@links) {
10424: if ($domconfig->{$role}{$item} ne '') {
10425: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10426: $changes{$role}{'links'}{$item} = 1;
10427: }
10428: } else {
10429: if ($confhash->{$role}{$item}) {
10430: $changes{$role}{'links'}{$item} = 1;
10431: }
10432: }
10433: }
1.41 raeburn 10434: foreach my $item (@logintext) {
10435: if ($domconfig->{$role}{$item} ne '') {
10436: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10437: $changes{$role}{'logintext'}{$item} = 1;
10438: }
10439: } else {
10440: if ($confhash->{$role}{$item}) {
10441: $changes{$role}{'logintext'}{$item} = 1;
10442: }
10443: }
10444: }
1.6 raeburn 10445: } else {
10446: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 10447: \@logintext,$confhash,\%changes);
1.6 raeburn 10448: }
10449: } else {
10450: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 10451: \@logintext,$confhash,\%changes);
1.6 raeburn 10452: }
10453: }
10454: return ($errors,%changes);
10455: }
10456:
1.46 raeburn 10457: sub config_check {
10458: my ($dom,$confname,$servadm) = @_;
10459: my ($configuserok,$author_ok,$switchserver,%currroles);
10460: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
10461: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
10462: $confname,$servadm);
10463: if ($configuserok eq 'ok') {
10464: $switchserver = &check_switchserver($dom,$confname);
10465: if ($switchserver eq '') {
10466: $author_ok = &check_authorstatus($dom,$confname,%currroles);
10467: }
10468: }
10469: return ($configuserok,$author_ok,$switchserver);
10470: }
10471:
1.6 raeburn 10472: sub default_change_checker {
1.41 raeburn 10473: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 10474: foreach my $item (@{$links}) {
10475: if ($confhash->{$role}{$item}) {
10476: $changes->{$role}{'links'}{$item} = 1;
10477: }
10478: }
10479: foreach my $item (@{$bgs}) {
10480: if ($confhash->{$role}{$item}) {
10481: $changes->{$role}{'bgs'}{$item} = 1;
10482: }
10483: }
1.41 raeburn 10484: foreach my $item (@{$logintext}) {
10485: if ($confhash->{$role}{$item}) {
10486: $changes->{$role}{'logintext'}{$item} = 1;
10487: }
10488: }
1.6 raeburn 10489: foreach my $img (@{$images}) {
10490: if ($env{'form.'.$role.'_del_'.$img}) {
10491: $confhash->{$role}{$img} = '';
1.12 raeburn 10492: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 10493: }
1.70 raeburn 10494: if ($role eq 'login') {
10495: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
10496: $changes->{$role}{'showlogo'}{$img} = 1;
10497: }
10498: }
1.6 raeburn 10499: }
10500: if ($confhash->{$role}{'font'}) {
10501: $changes->{$role}{'font'} = 1;
10502: }
1.48 raeburn 10503: }
1.6 raeburn 10504:
10505: sub display_colorchgs {
10506: my ($dom,$changes,$roles,$confhash) = @_;
10507: my (%choices,$resulttext);
10508: if (!grep(/^login$/,@{$roles})) {
10509: $resulttext = &mt('Changes made:').'<br />';
10510: }
10511: foreach my $role (@{$roles}) {
10512: if ($role eq 'login') {
10513: %choices = &login_choices();
10514: } else {
10515: %choices = &color_font_choices();
10516: }
10517: if (ref($changes->{$role}) eq 'HASH') {
10518: if ($role ne 'login') {
10519: $resulttext .= '<h4>'.&mt($role).'</h4>';
10520: }
10521: foreach my $key (sort(keys(%{$changes->{$role}}))) {
10522: if ($role ne 'login') {
10523: $resulttext .= '<ul>';
10524: }
10525: if (ref($changes->{$role}{$key}) eq 'HASH') {
10526: if ($role ne 'login') {
10527: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
10528: }
10529: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 10530: if (($role eq 'login') && ($key eq 'showlogo')) {
10531: if ($confhash->{$role}{$key}{$item}) {
10532: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
10533: } else {
10534: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
10535: }
10536: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 10537: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
10538: } else {
1.12 raeburn 10539: my $newitem = $confhash->{$role}{$item};
10540: if ($key eq 'images') {
1.306 raeburn 10541: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 10542: }
10543: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 10544: }
10545: }
10546: if ($role ne 'login') {
10547: $resulttext .= '</ul></li>';
10548: }
10549: } else {
10550: if ($confhash->{$role}{$key} eq '') {
10551: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
10552: } else {
10553: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
10554: }
10555: }
10556: if ($role ne 'login') {
10557: $resulttext .= '</ul>';
10558: }
10559: }
10560: }
10561: }
1.3 raeburn 10562: return $resulttext;
1.1 raeburn 10563: }
10564:
1.9 raeburn 10565: sub thumb_dimensions {
10566: return ('200','50');
10567: }
10568:
1.16 raeburn 10569: sub check_dimensions {
10570: my ($inputfile) = @_;
10571: my ($fullwidth,$fullheight);
10572: if ($inputfile =~ m|^[/\w.\-]+$|) {
10573: if (open(PIPE,"identify $inputfile 2>&1 |")) {
10574: my $imageinfo = <PIPE>;
10575: if (!close(PIPE)) {
10576: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
10577: }
10578: chomp($imageinfo);
10579: my ($fullsize) =
1.21 raeburn 10580: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 10581: if ($fullsize) {
10582: ($fullwidth,$fullheight) = split(/x/,$fullsize);
10583: }
10584: }
10585: }
10586: return ($fullwidth,$fullheight);
10587: }
10588:
1.9 raeburn 10589: sub check_configuser {
10590: my ($uhome,$dom,$confname,$servadm) = @_;
10591: my ($configuserok,%currroles);
10592: if ($uhome eq 'no_host') {
10593: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
10594: my $configpass = &LONCAPA::Enrollment::create_password();
10595: $configuserok =
10596: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
10597: $configpass,'','','','','',undef,$servadm);
10598: } else {
10599: $configuserok = 'ok';
10600: %currroles =
10601: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
10602: }
10603: return ($configuserok,%currroles);
10604: }
10605:
10606: sub check_authorstatus {
10607: my ($dom,$confname,%currroles) = @_;
10608: my $author_ok;
1.40 raeburn 10609: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 10610: my $start = time;
10611: my $end = 0;
10612: $author_ok =
10613: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 10614: 'au',$end,$start,'','','domconfig');
1.9 raeburn 10615: } else {
10616: $author_ok = 'ok';
10617: }
10618: return $author_ok;
10619: }
10620:
10621: sub publishlogo {
1.46 raeburn 10622: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 10623: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 10624: if ($action eq 'upload') {
10625: $fname=$env{'form.'.$formname.'.filename'};
10626: chop($env{'form.'.$formname});
10627: } else {
10628: ($fname) = ($formname =~ /([^\/]+)$/);
10629: }
1.46 raeburn 10630: if ($savefileas ne '') {
10631: $fname = $savefileas;
10632: }
1.9 raeburn 10633: $fname=&Apache::lonnet::clean_filename($fname);
10634: # See if there is anything left
10635: unless ($fname) { return ('error: no uploaded file'); }
10636: $fname="$subdir/$fname";
1.210 raeburn 10637: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 10638: my $filepath="$docroot/priv";
10639: my $relpath = "$dom/$confname";
1.9 raeburn 10640: my ($fnamepath,$file,$fetchthumb);
10641: $file=$fname;
10642: if ($fname=~m|/|) {
10643: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
10644: }
1.164 raeburn 10645: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 10646: my $count;
1.164 raeburn 10647: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 10648: $filepath.="/$parts[$count]";
10649: if ((-e $filepath)!=1) {
10650: mkdir($filepath,02770);
10651: }
10652: }
10653: # Check for bad extension and disallow upload
10654: if ($file=~/\.(\w+)$/ &&
10655: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
10656: $output =
1.207 bisitz 10657: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 10658: } elsif ($file=~/\.(\w+)$/ &&
10659: !defined(&Apache::loncommon::fileembstyle($1))) {
10660: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
10661: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 10662: $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 10663: } elsif (-d "$filepath/$file") {
1.195 bisitz 10664: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 10665: } else {
10666: my $source = $filepath.'/'.$file;
10667: my $logfile;
1.316 raeburn 10668: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 10669: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 10670: }
10671: print $logfile
10672: "\n================= Publish ".localtime()." ================\n".
10673: $env{'user.name'}.':'.$env{'user.domain'}."\n";
10674: # Save the file
1.316 raeburn 10675: if (!open(FH,">",$source)) {
1.9 raeburn 10676: &Apache::lonnet::logthis('Failed to create '.$source);
10677: return (&mt('Failed to create file'));
10678: }
10679: if ($action eq 'upload') {
10680: if (!print FH ($env{'form.'.$formname})) {
10681: &Apache::lonnet::logthis('Failed to write to '.$source);
10682: return (&mt('Failed to write file'));
10683: }
10684: } else {
10685: my $original = &Apache::lonnet::filelocation('',$formname);
10686: if(!copy($original,$source)) {
10687: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
10688: return (&mt('Failed to write file'));
10689: }
10690: }
10691: close(FH);
10692: chmod(0660, $source); # Permissions to rw-rw---.
10693:
10694: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
10695: my $copyfile=$targetdir.'/'.$file;
10696:
10697: my @parts=split(/\//,$targetdir);
10698: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
10699: for (my $count=5;$count<=$#parts;$count++) {
10700: $path.="/$parts[$count]";
10701: if (!-e $path) {
10702: print $logfile "\nCreating directory ".$path;
10703: mkdir($path,02770);
10704: }
10705: }
10706: my $versionresult;
10707: if (-e $copyfile) {
10708: $versionresult = &logo_versioning($targetdir,$file,$logfile);
10709: } else {
10710: $versionresult = 'ok';
10711: }
10712: if ($versionresult eq 'ok') {
10713: if (copy($source,$copyfile)) {
10714: print $logfile "\nCopied original source to ".$copyfile."\n";
10715: $output = 'ok';
10716: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 10717: push(@{$modified_urls},[$copyfile,$source]);
10718: my $metaoutput =
10719: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
10720: unless ($registered_cleanup) {
10721: my $handlers = $r->get_handlers('PerlCleanupHandler');
10722: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
10723: $registered_cleanup=1;
10724: }
1.9 raeburn 10725: } else {
10726: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
10727: $output = &mt('Failed to copy file to RES space').", $!";
10728: }
10729: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
10730: my $inputfile = $filepath.'/'.$file;
10731: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 10732: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
10733: if ($fullwidth ne '' && $fullheight ne '') {
10734: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
10735: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 10736: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
10737: system({$args[0]} @args);
1.16 raeburn 10738: chmod(0660, $filepath.'/tn-'.$file);
10739: if (-e $outfile) {
10740: my $copyfile=$targetdir.'/tn-'.$file;
10741: if (copy($outfile,$copyfile)) {
10742: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 10743: my $thumb_metaoutput =
10744: &write_metadata($dom,$confname,$formname,
10745: $targetdir,'tn-'.$file,$logfile);
10746: push(@{$modified_urls},[$copyfile,$outfile]);
10747: unless ($registered_cleanup) {
10748: my $handlers = $r->get_handlers('PerlCleanupHandler');
10749: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
10750: $registered_cleanup=1;
10751: }
1.267 raeburn 10752: $madethumb = 1;
1.16 raeburn 10753: } else {
10754: print $logfile "\nUnable to write ".$copyfile.
10755: ':'.$!."\n";
10756: }
10757: }
1.9 raeburn 10758: }
10759: }
10760: }
10761: } else {
10762: $output = $versionresult;
10763: }
10764: }
1.267 raeburn 10765: return ($output,$logourl,$madethumb);
1.9 raeburn 10766: }
10767:
10768: sub logo_versioning {
10769: my ($targetdir,$file,$logfile) = @_;
10770: my $target = $targetdir.'/'.$file;
10771: my ($maxversion,$fn,$extn,$output);
10772: $maxversion = 0;
10773: if ($file =~ /^(.+)\.(\w+)$/) {
10774: $fn=$1;
10775: $extn=$2;
10776: }
10777: opendir(DIR,$targetdir);
10778: while (my $filename=readdir(DIR)) {
10779: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
10780: $maxversion=($1>$maxversion)?$1:$maxversion;
10781: }
10782: }
10783: $maxversion++;
10784: print $logfile "\nCreating old version ".$maxversion."\n";
10785: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
10786: if (copy($target,$copyfile)) {
10787: print $logfile "Copied old target to ".$copyfile."\n";
10788: $copyfile=$copyfile.'.meta';
10789: if (copy($target.'.meta',$copyfile)) {
10790: print $logfile "Copied old target metadata to ".$copyfile."\n";
10791: $output = 'ok';
10792: } else {
10793: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
10794: $output = &mt('Failed to copy old meta').", $!, ";
10795: }
10796: } else {
10797: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
10798: $output = &mt('Failed to copy old target').", $!, ";
10799: }
10800: return $output;
10801: }
10802:
10803: sub write_metadata {
10804: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
10805: my (%metadatafields,%metadatakeys,$output);
10806: $metadatafields{'title'}=$formname;
10807: $metadatafields{'creationdate'}=time;
10808: $metadatafields{'lastrevisiondate'}=time;
10809: $metadatafields{'copyright'}='public';
10810: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
10811: $env{'user.domain'};
10812: $metadatafields{'authorspace'}=$confname.':'.$dom;
10813: $metadatafields{'domain'}=$dom;
10814: {
10815: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
10816: my $mfh;
1.316 raeburn 10817: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 10818: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 10819: unless ($_=~/\./) {
10820: my $unikey=$_;
10821: $unikey=~/^([A-Za-z]+)/;
10822: my $tag=$1;
10823: $tag=~tr/A-Z/a-z/;
10824: print $mfh "\n\<$tag";
10825: foreach (split(/\,/,$metadatakeys{$unikey})) {
10826: my $value=$metadatafields{$unikey.'.'.$_};
10827: $value=~s/\"/\'\'/g;
10828: print $mfh ' '.$_.'="'.$value.'"';
10829: }
10830: print $mfh '>'.
10831: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
10832: .'</'.$tag.'>';
10833: }
10834: }
10835: $output = 'ok';
10836: print $logfile "\nWrote metadata";
10837: close($mfh);
10838: } else {
10839: print $logfile "\nFailed to open metadata file";
1.9 raeburn 10840: $output = &mt('Could not write metadata');
10841: }
10842: }
1.155 raeburn 10843: return $output;
10844: }
10845:
10846: sub notifysubscribed {
10847: foreach my $targetsource (@{$modified_urls}){
10848: next unless (ref($targetsource) eq 'ARRAY');
10849: my ($target,$source)=@{$targetsource};
10850: if ($source ne '') {
1.316 raeburn 10851: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 10852: print $logfh "\nCleanup phase: Notifications\n";
10853: my @subscribed=&subscribed_hosts($target);
10854: foreach my $subhost (@subscribed) {
10855: print $logfh "\nNotifying host ".$subhost.':';
10856: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
10857: print $logfh $reply;
10858: }
10859: my @subscribedmeta=&subscribed_hosts("$target.meta");
10860: foreach my $subhost (@subscribedmeta) {
10861: print $logfh "\nNotifying host for metadata only ".$subhost.':';
10862: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
10863: $subhost);
10864: print $logfh $reply;
10865: }
10866: print $logfh "\n============ Done ============\n";
1.160 raeburn 10867: close($logfh);
1.155 raeburn 10868: }
10869: }
10870: }
10871: return OK;
10872: }
10873:
10874: sub subscribed_hosts {
10875: my ($target) = @_;
10876: my @subscribed;
1.316 raeburn 10877: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 10878: while (my $subline=<$fh>) {
10879: if ($subline =~ /^($match_lonid):/) {
10880: my $host = $1;
10881: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
10882: unless (grep(/^\Q$host\E$/,@subscribed)) {
10883: push(@subscribed,$host);
10884: }
10885: }
10886: }
10887: }
10888: }
10889: return @subscribed;
1.9 raeburn 10890: }
10891:
10892: sub check_switchserver {
10893: my ($dom,$confname) = @_;
10894: my ($allowed,$switchserver);
10895: my $home = &Apache::lonnet::homeserver($confname,$dom);
10896: if ($home eq 'no_host') {
10897: $home = &Apache::lonnet::domain($dom,'primary');
10898: }
10899: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 10900: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
10901: if (!$allowed) {
1.180 raeburn 10902: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 10903: }
10904: return $switchserver;
10905: }
10906:
1.1 raeburn 10907: sub modify_quotas {
1.216 raeburn 10908: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 10909: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 10910: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 10911: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
10912: $validationfieldsref);
1.86 raeburn 10913: if ($action eq 'quotas') {
10914: $context = 'tools';
1.163 raeburn 10915: } else {
1.86 raeburn 10916: $context = $action;
10917: }
10918: if ($context eq 'requestcourses') {
1.325 raeburn 10919: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 10920: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 10921: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
10922: %titles = &courserequest_titles();
10923: $toolregexp = join('|',@usertools);
10924: %conditions = &courserequest_conditions();
1.216 raeburn 10925: $confname = $dom.'-domainconfig';
10926: my $servadm = $r->dir_config('lonAdmEMail');
10927: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 10928: ($validationitemsref,$validationnamesref,$validationfieldsref) =
10929: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 10930: } elsif ($context eq 'requestauthor') {
10931: @usertools = ('author');
10932: %titles = &authorrequest_titles();
1.86 raeburn 10933: } else {
1.162 raeburn 10934: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 10935: %titles = &tool_titles();
1.86 raeburn 10936: }
1.212 raeburn 10937: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 10938: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10939: foreach my $key (keys(%env)) {
1.101 raeburn 10940: if ($context eq 'requestcourses') {
10941: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
10942: my $item = $1;
10943: my $type = $2;
10944: if ($type =~ /^limit_(.+)/) {
10945: $limithash{$item}{$1} = $env{$key};
10946: } else {
10947: $confhash{$item}{$type} = $env{$key};
10948: }
10949: }
1.163 raeburn 10950: } elsif ($context eq 'requestauthor') {
10951: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
10952: $confhash{$1} = $env{$key};
10953: }
1.101 raeburn 10954: } else {
1.86 raeburn 10955: if ($key =~ /^form\.quota_(.+)$/) {
10956: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 10957: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
10958: $confhash{'authorquota'}{$1} = $env{$key};
10959: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 10960: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
10961: }
1.72 raeburn 10962: }
10963: }
1.163 raeburn 10964: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 10965: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 10966: @approvalnotify = sort(@approvalnotify);
10967: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 10968: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 10969: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
10970: foreach my $type (@hasuniquecode) {
10971: if (grep(/^\Q$type\E$/,@crstypes)) {
10972: $confhash{'uniquecode'}{$type} = 1;
10973: }
1.216 raeburn 10974: }
1.242 raeburn 10975: my (%newbook,%allpos);
1.216 raeburn 10976: if ($context eq 'requestcourses') {
1.242 raeburn 10977: foreach my $type ('textbooks','templates') {
10978: @{$allpos{$type}} = ();
10979: my $invalid;
10980: if ($type eq 'textbooks') {
10981: $invalid = &mt('Invalid LON-CAPA course for textbook');
10982: } else {
10983: $invalid = &mt('Invalid LON-CAPA course for template');
10984: }
10985: if ($env{'form.'.$type.'_addbook'}) {
10986: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
10987: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
10988: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
10989: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
10990: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
10991: } else {
10992: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
10993: my $position = $env{'form.'.$type.'_addbook_pos'};
10994: $position =~ s/\D+//g;
10995: if ($position ne '') {
10996: $allpos{$type}[$position] = $newbook{$type};
10997: }
1.216 raeburn 10998: }
1.242 raeburn 10999: } else {
11000: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 11001: }
11002: }
1.242 raeburn 11003: }
1.216 raeburn 11004: }
1.102 raeburn 11005: if (ref($domconfig{$action}) eq 'HASH') {
11006: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
11007: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
11008: $changes{'notify'}{'approval'} = 1;
11009: }
11010: } else {
1.144 raeburn 11011: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 11012: $changes{'notify'}{'approval'} = 1;
11013: }
11014: }
1.218 raeburn 11015: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
11016: if (ref($confhash{'uniquecode'}) eq 'HASH') {
11017: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
11018: unless ($confhash{'uniquecode'}{$crstype}) {
11019: $changes{'uniquecode'} = 1;
11020: }
11021: }
11022: unless ($changes{'uniquecode'}) {
11023: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
11024: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
11025: $changes{'uniquecode'} = 1;
11026: }
11027: }
11028: }
11029: } else {
11030: $changes{'uniquecode'} = 1;
11031: }
11032: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
11033: $changes{'uniquecode'} = 1;
1.216 raeburn 11034: }
11035: if ($context eq 'requestcourses') {
1.242 raeburn 11036: foreach my $type ('textbooks','templates') {
11037: if (ref($domconfig{$action}{$type}) eq 'HASH') {
11038: my %deletions;
11039: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
11040: if (@todelete) {
11041: map { $deletions{$_} = 1; } @todelete;
11042: }
11043: my %imgdeletions;
11044: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
11045: if (@todeleteimages) {
11046: map { $imgdeletions{$_} = 1; } @todeleteimages;
11047: }
11048: my $maxnum = $env{'form.'.$type.'_maxnum'};
11049: for (my $i=0; $i<=$maxnum; $i++) {
11050: my $itemid = $env{'form.'.$type.'_id_'.$i};
11051: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
11052: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
11053: if ($deletions{$key}) {
11054: if ($domconfig{$action}{$type}{$key}{'image'}) {
11055: #FIXME need to obsolete item in RES space
11056: }
11057: next;
11058: } else {
11059: my $newpos = $env{'form.'.$itemid};
11060: $newpos =~ s/\D+//g;
1.243 raeburn 11061: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 11062: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 11063: ($type eq 'templates'));
1.242 raeburn 11064: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
11065: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
11066: $changes{$type}{$key} = 1;
11067: }
11068: }
11069: $allpos{$type}[$newpos] = $key;
11070: }
11071: if ($imgdeletions{$key}) {
11072: $changes{$type}{$key} = 1;
1.216 raeburn 11073: #FIXME need to obsolete item in RES space
1.242 raeburn 11074: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
11075: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 11076: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
11077: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
11078: } else {
11079: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
11080: $cdom,$cnum,$type,$configuserok,
11081: $switchserver,$author_ok);
11082: if ($imgurl) {
11083: $confhash{$type}{$key}{'image'} = $imgurl;
11084: $changes{$type}{$key} = 1;
11085: }
11086: if ($error) {
11087: &Apache::lonnet::logthis($error);
11088: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11089: }
11090: }
1.242 raeburn 11091: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
11092: $confhash{$type}{$key}{'image'} =
11093: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 11094: }
11095: }
11096: }
11097: }
11098: }
11099: }
1.102 raeburn 11100: } else {
1.144 raeburn 11101: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 11102: $changes{'notify'}{'approval'} = 1;
11103: }
1.218 raeburn 11104: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 11105: $changes{'uniquecode'} = 1;
11106: }
11107: }
11108: if ($context eq 'requestcourses') {
1.242 raeburn 11109: foreach my $type ('textbooks','templates') {
11110: if ($newbook{$type}) {
11111: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 11112: foreach my $item ('subject','title','publisher','author') {
11113: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11114: ($type eq 'template'));
1.242 raeburn 11115: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
11116: if ($env{'form.'.$type.'_addbook_'.$item}) {
11117: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
11118: }
11119: }
11120: if ($type eq 'textbooks') {
11121: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
11122: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 11123: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
11124: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
11125: } else {
11126: my ($imageurl,$error) =
11127: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
11128: $configuserok,$switchserver,$author_ok);
11129: if ($imageurl) {
11130: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
11131: }
11132: if ($error) {
11133: &Apache::lonnet::logthis($error);
11134: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11135: }
1.242 raeburn 11136: }
11137: }
1.216 raeburn 11138: }
11139: }
1.242 raeburn 11140: if (@{$allpos{$type}} > 0) {
11141: my $idx = 0;
11142: foreach my $item (@{$allpos{$type}}) {
11143: if ($item ne '') {
11144: $confhash{$type}{$item}{'order'} = $idx;
11145: if (ref($domconfig{$action}) eq 'HASH') {
11146: if (ref($domconfig{$action}{$type}) eq 'HASH') {
11147: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
11148: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
11149: $changes{$type}{$item} = 1;
11150: }
1.216 raeburn 11151: }
11152: }
11153: }
1.242 raeburn 11154: $idx ++;
1.216 raeburn 11155: }
11156: }
11157: }
11158: }
1.235 raeburn 11159: if (ref($validationitemsref) eq 'ARRAY') {
11160: foreach my $item (@{$validationitemsref}) {
11161: if ($item eq 'fields') {
11162: my @changed;
11163: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
11164: if (@{$confhash{'validation'}{$item}} > 0) {
11165: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
11166: }
1.266 raeburn 11167: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11168: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11169: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
11170: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
11171: $domconfig{'requestcourses'}{'validation'}{$item});
11172: } else {
11173: @changed = @{$confhash{'validation'}{$item}};
11174: }
1.235 raeburn 11175: } else {
11176: @changed = @{$confhash{'validation'}{$item}};
11177: }
11178: } else {
11179: @changed = @{$confhash{'validation'}{$item}};
11180: }
11181: if (@changed) {
11182: if ($confhash{'validation'}{$item}) {
11183: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
11184: } else {
11185: $changes{'validation'}{$item} = &mt('None');
11186: }
11187: }
11188: } else {
11189: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
11190: if ($item eq 'markup') {
11191: if ($env{'form.requestcourses_validation_'.$item}) {
11192: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
11193: }
11194: }
1.266 raeburn 11195: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11196: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11197: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
11198: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11199: }
11200: } else {
11201: if ($confhash{'validation'}{$item} ne '') {
11202: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11203: }
1.235 raeburn 11204: }
11205: } else {
11206: if ($confhash{'validation'}{$item} ne '') {
11207: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11208: }
11209: }
11210: }
11211: }
11212: }
11213: if ($env{'form.validationdc'}) {
11214: my $newval = $env{'form.validationdc'};
1.285 raeburn 11215: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 11216: if (exists($domcoords{$newval})) {
11217: $confhash{'validation'}{'dc'} = $newval;
11218: }
11219: }
11220: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 11221: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11222: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11223: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
11224: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
11225: if ($confhash{'validation'}{'dc'} eq '') {
11226: $changes{'validation'}{'dc'} = &mt('None');
11227: } else {
11228: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11229: }
1.235 raeburn 11230: }
1.266 raeburn 11231: } elsif ($confhash{'validation'}{'dc'} ne '') {
11232: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 11233: }
11234: } elsif ($confhash{'validation'}{'dc'} ne '') {
11235: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11236: }
11237: } elsif ($confhash{'validation'}{'dc'} ne '') {
11238: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 11239: }
1.266 raeburn 11240: } else {
11241: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11242: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11243: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
11244: $changes{'validation'}{'dc'} = &mt('None');
11245: }
11246: }
1.235 raeburn 11247: }
11248: }
1.102 raeburn 11249: }
11250: } else {
1.86 raeburn 11251: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 11252: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 11253: }
1.72 raeburn 11254: foreach my $item (@usertools) {
11255: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 11256: my $unset;
1.101 raeburn 11257: if ($context eq 'requestcourses') {
1.104 raeburn 11258: $unset = '0';
11259: if ($type eq '_LC_adv') {
11260: $unset = '';
11261: }
1.101 raeburn 11262: if ($confhash{$item}{$type} eq 'autolimit') {
11263: $confhash{$item}{$type} .= '=';
11264: unless ($limithash{$item}{$type} =~ /\D/) {
11265: $confhash{$item}{$type} .= $limithash{$item}{$type};
11266: }
11267: }
1.163 raeburn 11268: } elsif ($context eq 'requestauthor') {
11269: $unset = '0';
11270: if ($type eq '_LC_adv') {
11271: $unset = '';
11272: }
1.72 raeburn 11273: } else {
1.101 raeburn 11274: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
11275: $confhash{$item}{$type} = 1;
11276: } else {
11277: $confhash{$item}{$type} = 0;
11278: }
1.72 raeburn 11279: }
1.86 raeburn 11280: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 11281: if ($action eq 'requestauthor') {
11282: if ($domconfig{$action}{$type} ne $confhash{$type}) {
11283: $changes{$type} = 1;
11284: }
11285: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 11286: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
11287: $changes{$item}{$type} = 1;
11288: }
11289: } else {
11290: if ($context eq 'requestcourses') {
1.104 raeburn 11291: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 11292: $changes{$item}{$type} = 1;
11293: }
11294: } else {
11295: if (!$confhash{$item}{$type}) {
11296: $changes{$item}{$type} = 1;
11297: }
11298: }
11299: }
11300: } else {
11301: if ($context eq 'requestcourses') {
1.104 raeburn 11302: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 11303: $changes{$item}{$type} = 1;
11304: }
1.163 raeburn 11305: } elsif ($context eq 'requestauthor') {
11306: if ($confhash{$type} ne $unset) {
11307: $changes{$type} = 1;
11308: }
1.72 raeburn 11309: } else {
11310: if (!$confhash{$item}{$type}) {
11311: $changes{$item}{$type} = 1;
11312: }
11313: }
11314: }
1.1 raeburn 11315: }
11316: }
1.163 raeburn 11317: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 11318: if (ref($domconfig{'quotas'}) eq 'HASH') {
11319: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
11320: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
11321: if (exists($confhash{'defaultquota'}{$key})) {
11322: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
11323: $changes{'defaultquota'}{$key} = 1;
11324: }
11325: } else {
11326: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 11327: }
11328: }
1.86 raeburn 11329: } else {
11330: foreach my $key (keys(%{$domconfig{'quotas'}})) {
11331: if (exists($confhash{'defaultquota'}{$key})) {
11332: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
11333: $changes{'defaultquota'}{$key} = 1;
11334: }
11335: } else {
11336: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 11337: }
1.1 raeburn 11338: }
11339: }
1.197 raeburn 11340: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
11341: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
11342: if (exists($confhash{'authorquota'}{$key})) {
11343: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
11344: $changes{'authorquota'}{$key} = 1;
11345: }
11346: } else {
11347: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
11348: }
11349: }
11350: }
1.1 raeburn 11351: }
1.86 raeburn 11352: if (ref($confhash{'defaultquota'}) eq 'HASH') {
11353: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
11354: if (ref($domconfig{'quotas'}) eq 'HASH') {
11355: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
11356: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
11357: $changes{'defaultquota'}{$key} = 1;
11358: }
11359: } else {
11360: if (!exists($domconfig{'quotas'}{$key})) {
11361: $changes{'defaultquota'}{$key} = 1;
11362: }
1.72 raeburn 11363: }
11364: } else {
1.86 raeburn 11365: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 11366: }
1.1 raeburn 11367: }
11368: }
1.197 raeburn 11369: if (ref($confhash{'authorquota'}) eq 'HASH') {
11370: foreach my $key (keys(%{$confhash{'authorquota'}})) {
11371: if (ref($domconfig{'quotas'}) eq 'HASH') {
11372: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
11373: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
11374: $changes{'authorquota'}{$key} = 1;
11375: }
11376: } else {
11377: $changes{'authorquota'}{$key} = 1;
11378: }
11379: } else {
11380: $changes{'authorquota'}{$key} = 1;
11381: }
11382: }
11383: }
1.1 raeburn 11384: }
1.72 raeburn 11385:
1.163 raeburn 11386: if ($context eq 'requestauthor') {
11387: $domdefaults{'requestauthor'} = \%confhash;
11388: } else {
11389: foreach my $key (keys(%confhash)) {
1.242 raeburn 11390: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 11391: $domdefaults{$key} = $confhash{$key};
11392: }
1.163 raeburn 11393: }
1.72 raeburn 11394: }
1.163 raeburn 11395:
1.1 raeburn 11396: my %quotahash = (
1.86 raeburn 11397: $action => { %confhash }
1.1 raeburn 11398: );
11399: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
11400: $dom);
11401: if ($putresult eq 'ok') {
11402: if (keys(%changes) > 0) {
1.72 raeburn 11403: my $cachetime = 24*60*60;
11404: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 11405: if (ref($lastactref) eq 'HASH') {
11406: $lastactref->{'domdefaults'} = 1;
11407: }
1.1 raeburn 11408: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 11409: unless (($context eq 'requestcourses') ||
1.163 raeburn 11410: ($context eq 'requestauthor')) {
1.86 raeburn 11411: if (ref($changes{'defaultquota'}) eq 'HASH') {
11412: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
11413: foreach my $type (@{$types},'default') {
11414: if (defined($changes{'defaultquota'}{$type})) {
11415: my $typetitle = $usertypes->{$type};
11416: if ($type eq 'default') {
11417: $typetitle = $othertitle;
11418: }
1.213 raeburn 11419: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 11420: }
11421: }
1.86 raeburn 11422: $resulttext .= '</ul></li>';
1.72 raeburn 11423: }
1.197 raeburn 11424: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 11425: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 11426: foreach my $type (@{$types},'default') {
11427: if (defined($changes{'authorquota'}{$type})) {
11428: my $typetitle = $usertypes->{$type};
11429: if ($type eq 'default') {
11430: $typetitle = $othertitle;
11431: }
1.213 raeburn 11432: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 11433: }
11434: }
11435: $resulttext .= '</ul></li>';
11436: }
1.72 raeburn 11437: }
1.80 raeburn 11438: my %newenv;
1.72 raeburn 11439: foreach my $item (@usertools) {
1.163 raeburn 11440: my (%haschgs,%inconf);
11441: if ($context eq 'requestauthor') {
11442: %haschgs = %changes;
1.210 raeburn 11443: %inconf = %confhash;
1.163 raeburn 11444: } else {
11445: if (ref($changes{$item}) eq 'HASH') {
11446: %haschgs = %{$changes{$item}};
11447: }
11448: if (ref($confhash{$item}) eq 'HASH') {
11449: %inconf = %{$confhash{$item}};
11450: }
11451: }
11452: if (keys(%haschgs) > 0) {
1.80 raeburn 11453: my $newacc =
11454: &Apache::lonnet::usertools_access($env{'user.name'},
11455: $env{'user.domain'},
1.86 raeburn 11456: $item,'reload',$context);
1.210 raeburn 11457: if (($context eq 'requestcourses') ||
1.163 raeburn 11458: ($context eq 'requestauthor')) {
1.108 raeburn 11459: if ($env{'environment.canrequest.'.$item} ne $newacc) {
11460: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 11461: }
11462: } else {
11463: if ($env{'environment.availabletools.'.$item} ne $newacc) {
11464: $newenv{'environment.availabletools.'.$item} = $newacc;
11465: }
1.80 raeburn 11466: }
1.163 raeburn 11467: unless ($context eq 'requestauthor') {
11468: $resulttext .= '<li>'.$titles{$item}.'<ul>';
11469: }
1.72 raeburn 11470: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 11471: if ($haschgs{$type}) {
1.72 raeburn 11472: my $typetitle = $usertypes->{$type};
11473: if ($type eq 'default') {
11474: $typetitle = $othertitle;
11475: } elsif ($type eq '_LC_adv') {
11476: $typetitle = 'LON-CAPA Advanced Users';
11477: }
1.163 raeburn 11478: if ($inconf{$type}) {
1.101 raeburn 11479: if ($context eq 'requestcourses') {
11480: my $cond;
1.163 raeburn 11481: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 11482: if ($1 eq '') {
11483: $cond = &mt('(Automatic processing of any request).');
11484: } else {
11485: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
11486: }
11487: } else {
1.163 raeburn 11488: $cond = $conditions{$inconf{$type}};
1.101 raeburn 11489: }
11490: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 11491: } elsif ($context eq 'requestauthor') {
11492: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
11493: $titles{$inconf{$type}},$typetitle);
11494:
1.101 raeburn 11495: } else {
11496: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
11497: }
1.72 raeburn 11498: } else {
1.104 raeburn 11499: if ($type eq '_LC_adv') {
1.163 raeburn 11500: if ($inconf{$type} eq '0') {
1.104 raeburn 11501: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
11502: } else {
11503: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
11504: }
11505: } else {
11506: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
11507: }
1.72 raeburn 11508: }
11509: }
1.26 raeburn 11510: }
1.163 raeburn 11511: unless ($context eq 'requestauthor') {
11512: $resulttext .= '</ul></li>';
11513: }
1.26 raeburn 11514: }
1.1 raeburn 11515: }
1.163 raeburn 11516: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 11517: if (ref($changes{'notify'}) eq 'HASH') {
11518: if ($changes{'notify'}{'approval'}) {
11519: if (ref($confhash{'notify'}) eq 'HASH') {
11520: if ($confhash{'notify'}{'approval'}) {
11521: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
11522: } else {
1.163 raeburn 11523: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 11524: }
11525: }
11526: }
11527: }
11528: }
1.216 raeburn 11529: if ($action eq 'requestcourses') {
11530: my @offon = ('off','on');
11531: if ($changes{'uniquecode'}) {
1.218 raeburn 11532: if (ref($confhash{'uniquecode'}) eq 'HASH') {
11533: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
11534: $resulttext .= '<li>'.
11535: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
11536: '</li>';
11537: } else {
11538: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
11539: '</li>';
11540: }
1.216 raeburn 11541: }
1.242 raeburn 11542: foreach my $type ('textbooks','templates') {
11543: if (ref($changes{$type}) eq 'HASH') {
11544: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
11545: foreach my $key (sort(keys(%{$changes{$type}}))) {
11546: my %coursehash = &Apache::lonnet::coursedescription($key);
11547: my $coursetitle = $coursehash{'description'};
11548: my $position = $confhash{$type}{$key}{'order'} + 1;
11549: $resulttext .= '<li>';
1.243 raeburn 11550: foreach my $item ('subject','title','publisher','author') {
11551: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11552: ($type eq 'templates'));
1.242 raeburn 11553: my $name = $item.':';
11554: $name =~ s/^(\w)/\U$1/;
11555: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
11556: }
11557: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
11558: if ($type eq 'textbooks') {
11559: if ($confhash{$type}{$key}{'image'}) {
11560: $resulttext .= ' '.&mt('Image: [_1]',
11561: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
11562: ' alt="Textbook cover" />').'<br />';
11563: }
11564: }
11565: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 11566: }
1.242 raeburn 11567: $resulttext .= '</ul></li>';
1.216 raeburn 11568: }
11569: }
1.235 raeburn 11570: if (ref($changes{'validation'}) eq 'HASH') {
11571: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
11572: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
11573: foreach my $item (@{$validationitemsref}) {
11574: if (exists($changes{'validation'}{$item})) {
11575: if ($item eq 'markup') {
11576: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
11577: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
11578: } else {
11579: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
11580: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
11581: }
11582: }
11583: }
11584: if (exists($changes{'validation'}{'dc'})) {
11585: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
11586: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
11587: }
11588: }
11589: }
1.216 raeburn 11590: }
1.1 raeburn 11591: $resulttext .= '</ul>';
1.80 raeburn 11592: if (keys(%newenv)) {
11593: &Apache::lonnet::appenv(\%newenv);
11594: }
1.1 raeburn 11595: } else {
1.86 raeburn 11596: if ($context eq 'requestcourses') {
11597: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 11598: } elsif ($context eq 'requestauthor') {
11599: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 11600: } else {
1.90 weissno 11601: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 11602: }
1.1 raeburn 11603: }
11604: } else {
1.11 albertel 11605: $resulttext = '<span class="LC_error">'.
11606: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11607: }
1.216 raeburn 11608: if ($errors) {
11609: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
11610: '<ul>'.$errors.'</ul></p>';
11611: }
1.3 raeburn 11612: return $resulttext;
1.1 raeburn 11613: }
11614:
1.216 raeburn 11615: sub process_textbook_image {
1.242 raeburn 11616: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 11617: my $filename = $env{'form.'.$caller.'.filename'};
11618: my ($error,$url);
11619: my ($width,$height) = (50,50);
11620: if ($configuserok eq 'ok') {
11621: if ($switchserver) {
11622: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
11623: $switchserver);
11624: } elsif ($author_ok eq 'ok') {
11625: my ($result,$imageurl) =
11626: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 11627: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 11628: if ($result eq 'ok') {
11629: $url = $imageurl;
11630: } else {
11631: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
11632: }
11633: } else {
11634: $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);
11635: }
11636: } else {
11637: $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);
11638: }
11639: return ($url,$error);
11640: }
11641:
1.267 raeburn 11642: sub modify_ltitools {
11643: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
11644: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 11645: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 11646: my $confname = $dom.'-domainconfig';
11647: my $servadm = $r->dir_config('lonAdmEMail');
11648: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11649: my (%posslti,%possfield);
11650: my @courseroles = ('cc','in','ta','ep','st');
11651: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
11652: map { $posslti{$_} = 1; } @ltiroles;
11653: my @allfields = ('fullname','firstname','lastname','email','user','roles');
11654: map { $possfield{$_} = 1; } @allfields;
11655: my %lt = <itools_names();
11656: if ($env{'form.ltitools_add'}) {
11657: my $title = $env{'form.ltitools_add_title'};
11658: $title =~ s/(`)/'/g;
11659: ($newid,my $error) = &get_ltitools_id($dom,$title);
11660: if ($newid) {
11661: my $position = $env{'form.ltitools_add_pos'};
11662: $position =~ s/\D+//g;
11663: if ($position ne '') {
11664: $allpos[$position] = $newid;
11665: }
11666: $changes{$newid} = 1;
1.322 raeburn 11667: foreach my $item ('title','url','key','secret','lifetime') {
1.267 raeburn 11668: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322 raeburn 11669: if ($item eq 'lifetime') {
11670: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
11671: }
1.267 raeburn 11672: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 11673: if (($item eq 'key') || ($item eq 'secret')) {
11674: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
11675: } else {
11676: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
11677: }
1.267 raeburn 11678: }
11679: }
11680: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
11681: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
11682: }
11683: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
11684: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
11685: }
1.323 raeburn 11686: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
11687: $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
11688: } else {
11689: $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
11690: }
1.296 raeburn 11691: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 11692: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
11693: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 11694: if (($item eq 'width') || ($item eq 'height')) {
11695: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
11696: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
11697: }
11698: } else {
11699: if ($env{'form.ltitools_add_'.$item} ne '') {
11700: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
11701: }
1.267 raeburn 11702: }
11703: }
11704: if ($env{'form.ltitools_add_target'} eq 'window') {
11705: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 11706: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
11707: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 11708: } else {
11709: $confhash{$newid}{'display'}{'target'} = 'iframe';
11710: }
11711: foreach my $item ('passback','roster') {
1.319 raeburn 11712: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 11713: $confhash{$newid}{$item} = 1;
1.319 raeburn 11714: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
11715: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
11716: $lifetime =~ s/^\s+|\s+$//g;
11717: if ($lifetime =~ /^\d+\.?\d*$/) {
11718: $confhash{$newid}{$item.'valid'} = $lifetime;
11719: }
11720: }
1.267 raeburn 11721: }
11722: }
11723: if ($env{'form.ltitools_add_image.filename'} ne '') {
11724: my ($imageurl,$error) =
1.307 raeburn 11725: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 11726: $configuserok,$switchserver,$author_ok);
11727: if ($imageurl) {
11728: $confhash{$newid}{'image'} = $imageurl;
11729: }
11730: if ($error) {
11731: &Apache::lonnet::logthis($error);
11732: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11733: }
11734: }
11735: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
11736: foreach my $field (@fields) {
11737: if ($possfield{$field}) {
11738: if ($field eq 'roles') {
11739: foreach my $role (@courseroles) {
11740: my $choice = $env{'form.ltitools_add_roles_'.$role};
11741: if (($choice ne '') && ($posslti{$choice})) {
11742: $confhash{$newid}{'roles'}{$role} = $choice;
11743: if ($role eq 'cc') {
11744: $confhash{$newid}{'roles'}{'co'} = $choice;
11745: }
11746: }
11747: }
11748: } else {
11749: $confhash{$newid}{'fields'}{$field} = 1;
11750: }
11751: }
11752: }
1.324 raeburn 11753: if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
11754: if ($confhash{$newid}{'fields'}{'user'}) {
11755: if ($env{'form.ltitools_userincdom_add'}) {
11756: $confhash{$newid}{'incdom'} = 1;
11757: }
11758: }
11759: }
1.273 raeburn 11760: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
11761: foreach my $item (@courseconfig) {
11762: $confhash{$newid}{'crsconf'}{$item} = 1;
11763: }
1.267 raeburn 11764: if ($env{'form.ltitools_add_custom'}) {
11765: my $name = $env{'form.ltitools_add_custom_name'};
11766: my $value = $env{'form.ltitools_add_custom_value'};
11767: $value =~ s/(`)/'/g;
11768: $name =~ s/(`)/'/g;
11769: $confhash{$newid}{'custom'}{$name} = $value;
11770: }
11771: } else {
11772: my $error = &mt('Failed to acquire unique ID for new external tool');
11773: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11774: }
11775: }
11776: if (ref($domconfig{$action}) eq 'HASH') {
11777: my %deletions;
11778: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
11779: if (@todelete) {
11780: map { $deletions{$_} = 1; } @todelete;
11781: }
11782: my %customadds;
11783: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
11784: if (@newcustom) {
11785: map { $customadds{$_} = 1; } @newcustom;
11786: }
11787: my %imgdeletions;
11788: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
11789: if (@todeleteimages) {
11790: map { $imgdeletions{$_} = 1; } @todeleteimages;
11791: }
11792: my $maxnum = $env{'form.ltitools_maxnum'};
11793: for (my $i=0; $i<=$maxnum; $i++) {
11794: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 11795: $itemid =~ s/\D+//g;
1.267 raeburn 11796: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11797: if ($deletions{$itemid}) {
11798: if ($domconfig{$action}{$itemid}{'image'}) {
11799: #FIXME need to obsolete item in RES space
11800: }
11801: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
11802: next;
11803: } else {
11804: my $newpos = $env{'form.ltitools_'.$itemid};
11805: $newpos =~ s/\D+//g;
1.322 raeburn 11806: foreach my $item ('title','url','lifetime') {
1.267 raeburn 11807: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11808: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
11809: $changes{$itemid} = 1;
11810: }
11811: }
1.297 raeburn 11812: foreach my $item ('key','secret') {
11813: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11814: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
11815: $changes{$itemid} = 1;
11816: }
11817: }
1.267 raeburn 11818: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
11819: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
11820: }
11821: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
11822: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
11823: }
1.323 raeburn 11824: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
11825: $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
11826: } else {
11827: $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
11828: }
11829: if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
11830: if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
11831: $changes{$itemid} = 1;
11832: }
11833: } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
11834: $changes{$itemid} = 1;
11835: }
1.267 raeburn 11836: foreach my $size ('width','height') {
11837: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
11838: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
11839: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
11840: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
11841: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11842: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
11843: $changes{$itemid} = 1;
11844: }
11845: } else {
11846: $changes{$itemid} = 1;
11847: }
1.296 raeburn 11848: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11849: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
11850: $changes{$itemid} = 1;
11851: }
11852: }
11853: }
11854: foreach my $item ('linktext','explanation') {
11855: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
11856: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
11857: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
11858: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11859: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11860: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
11861: $changes{$itemid} = 1;
11862: }
11863: } else {
11864: $changes{$itemid} = 1;
11865: }
11866: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11867: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
11868: $changes{$itemid} = 1;
11869: }
1.267 raeburn 11870: }
11871: }
11872: if ($env{'form.ltitools_target_'.$i} eq 'window') {
11873: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 11874: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
11875: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 11876: } else {
11877: $confhash{$itemid}{'display'}{'target'} = 'iframe';
11878: }
11879: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11880: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
11881: $changes{$itemid} = 1;
11882: }
11883: } else {
11884: $changes{$itemid} = 1;
11885: }
11886: foreach my $extra ('passback','roster') {
11887: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
11888: $confhash{$itemid}{$extra} = 1;
1.319 raeburn 11889: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
1.338 raeburn 11890: my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
1.319 raeburn 11891: $lifetime =~ s/^\s+|\s+$//g;
11892: if ($lifetime =~ /^\d+\.?\d*$/) {
11893: $confhash{$itemid}{$extra.'valid'} = $lifetime;
11894: }
11895: }
1.267 raeburn 11896: }
11897: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
11898: $changes{$itemid} = 1;
11899: }
1.319 raeburn 11900: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
11901: $changes{$itemid} = 1;
11902: }
1.267 raeburn 11903: }
1.273 raeburn 11904: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 11905: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 11906: if (grep(/^\Q$item\E$/,@courseconfig)) {
11907: $confhash{$itemid}{'crsconf'}{$item} = 1;
11908: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
11909: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
11910: $changes{$itemid} = 1;
11911: }
11912: } else {
11913: $changes{$itemid} = 1;
11914: }
11915: }
11916: }
1.267 raeburn 11917: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
11918: foreach my $field (@fields) {
11919: if ($possfield{$field}) {
11920: if ($field eq 'roles') {
11921: foreach my $role (@courseroles) {
11922: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
11923: if (($choice ne '') && ($posslti{$choice})) {
11924: $confhash{$itemid}{'roles'}{$role} = $choice;
11925: if ($role eq 'cc') {
11926: $confhash{$itemid}{'roles'}{'co'} = $choice;
11927: }
11928: }
11929: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
11930: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
11931: $changes{$itemid} = 1;
11932: }
11933: } elsif ($confhash{$itemid}{'roles'}{$role}) {
11934: $changes{$itemid} = 1;
11935: }
11936: }
11937: } else {
11938: $confhash{$itemid}{'fields'}{$field} = 1;
11939: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
11940: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
11941: $changes{$itemid} = 1;
11942: }
11943: } else {
11944: $changes{$itemid} = 1;
11945: }
11946: }
11947: }
11948: }
1.324 raeburn 11949: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
11950: if ($confhash{$itemid}{'fields'}{'user'}) {
11951: if ($env{'form.ltitools_userincdom_'.$i}) {
11952: $confhash{$itemid}{'incdom'} = 1;
11953: }
11954: if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
11955: $changes{$itemid} = 1;
11956: }
11957: }
11958: }
1.267 raeburn 11959: $allpos[$newpos] = $itemid;
11960: }
11961: if ($imgdeletions{$itemid}) {
11962: $changes{$itemid} = 1;
11963: #FIXME need to obsolete item in RES space
11964: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
11965: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
11966: $itemid,$configuserok,$switchserver,
11967: $author_ok);
11968: if ($imgurl) {
11969: $confhash{$itemid}{'image'} = $imgurl;
11970: $changes{$itemid} = 1;
11971: }
11972: if ($error) {
11973: &Apache::lonnet::logthis($error);
11974: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11975: }
11976: } elsif ($domconfig{$action}{$itemid}{'image'}) {
11977: $confhash{$itemid}{'image'} =
11978: $domconfig{$action}{$itemid}{'image'};
11979: }
11980: if ($customadds{$i}) {
11981: my $name = $env{'form.ltitools_custom_name_'.$i};
11982: $name =~ s/(`)/'/g;
11983: $name =~ s/^\s+//;
11984: $name =~ s/\s+$//;
11985: my $value = $env{'form.ltitools_custom_value_'.$i};
11986: $value =~ s/(`)/'/g;
11987: $value =~ s/^\s+//;
11988: $value =~ s/\s+$//;
11989: if ($name ne '') {
11990: $confhash{$itemid}{'custom'}{$name} = $value;
11991: $changes{$itemid} = 1;
11992: }
11993: }
11994: my %customdels;
11995: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
11996: if (@customdeletions) {
11997: $changes{$itemid} = 1;
11998: }
11999: map { $customdels{$_} = 1; } @customdeletions;
12000: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
12001: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
12002: unless ($customdels{$key}) {
12003: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
12004: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
12005: }
12006: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
12007: $changes{$itemid} = 1;
12008: }
12009: }
12010: }
12011: }
12012: unless ($changes{$itemid}) {
12013: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
12014: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
12015: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
12016: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
12017: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
12018: $changes{$itemid} = 1;
12019: last;
12020: }
12021: }
12022: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
12023: $changes{$itemid} = 1;
12024: }
12025: }
12026: last if ($changes{$itemid});
12027: }
12028: }
12029: }
12030: }
12031: }
12032: if (@allpos > 0) {
12033: my $idx = 0;
12034: foreach my $itemid (@allpos) {
12035: if ($itemid ne '') {
12036: $confhash{$itemid}{'order'} = $idx;
12037: if (ref($domconfig{$action}) eq 'HASH') {
12038: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12039: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
12040: $changes{$itemid} = 1;
12041: }
12042: }
12043: }
12044: $idx ++;
12045: }
12046: }
12047: }
12048: my %ltitoolshash = (
12049: $action => { %confhash }
12050: );
12051: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
12052: $dom);
12053: if ($putresult eq 'ok') {
1.297 raeburn 12054: my %ltienchash = (
12055: $action => { %encconfig }
12056: );
12057: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267 raeburn 12058: if (keys(%changes) > 0) {
12059: my $cachetime = 24*60*60;
1.297 raeburn 12060: my %ltiall = %confhash;
12061: foreach my $id (keys(%ltiall)) {
12062: if (ref($encconfig{$id}) eq 'HASH') {
12063: foreach my $item ('key','secret') {
12064: $ltiall{$id}{$item} = $encconfig{$id}{$item};
12065: }
12066: }
12067: }
12068: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 12069: if (ref($lastactref) eq 'HASH') {
12070: $lastactref->{'ltitools'} = 1;
12071: }
12072: $resulttext = &mt('Changes made:').'<ul>';
12073: my %bynum;
12074: foreach my $itemid (sort(keys(%changes))) {
12075: my $position = $confhash{$itemid}{'order'};
12076: $bynum{$position} = $itemid;
12077: }
12078: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
12079: my $itemid = $bynum{$pos};
12080: if (ref($confhash{$itemid}) ne 'HASH') {
12081: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
12082: } else {
12083: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
12084: if ($confhash{$itemid}{'image'}) {
12085: $resulttext .= ' '.
12086: '<img src="'.$confhash{$itemid}{'image'}.'"'.
12087: ' alt="'.&mt('Tool Provider icon').'" />';
12088: }
12089: $resulttext .= '</li><ul>';
12090: my $position = $pos + 1;
12091: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323 raeburn 12092: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267 raeburn 12093: if ($confhash{$itemid}{$item} ne '') {
12094: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
12095: }
12096: }
1.297 raeburn 12097: if ($encconfig{$itemid}{'key'} ne '') {
12098: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
12099: }
12100: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 12101: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 12102: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 12103: $resulttext .= ('*'x$num).'</li>';
12104: }
1.273 raeburn 12105: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 12106: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 12107: my $numconfig = 0;
12108: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
12109: foreach my $item (@possconfig) {
12110: if ($confhash{$itemid}{'crsconf'}{$item}) {
12111: $numconfig ++;
1.296 raeburn 12112: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 12113: }
12114: }
12115: }
12116: if (!$numconfig) {
12117: $resulttext .= &mt('None');
12118: }
12119: $resulttext .= '</li>';
1.267 raeburn 12120: foreach my $item ('passback','roster') {
12121: $resulttext .= '<li>'.$lt{$item}.' ';
12122: if ($confhash{$itemid}{$item}) {
12123: $resulttext .= &mt('Yes');
1.319 raeburn 12124: if ($confhash{$itemid}{$item.'valid'}) {
12125: if ($item eq 'passback') {
12126: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
12127: $confhash{$itemid}{$item.'valid'});
12128: } else {
12129: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
12130: $confhash{$itemid}{$item.'valid'});
12131: }
12132: }
1.267 raeburn 12133: } else {
12134: $resulttext .= &mt('No');
12135: }
12136: $resulttext .= '</li>';
12137: }
12138: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
12139: my $displaylist;
12140: if ($confhash{$itemid}{'display'}{'target'}) {
12141: $displaylist = &mt('Display target').': '.
12142: $confhash{$itemid}{'display'}{'target'}.',';
12143: }
12144: foreach my $size ('width','height') {
12145: if ($confhash{$itemid}{'display'}{$size}) {
12146: $displaylist .= (' 'x2).$lt{$size}.': '.
12147: $confhash{$itemid}{'display'}{$size}.',';
12148: }
12149: }
12150: if ($displaylist) {
12151: $displaylist =~ s/,$//;
12152: $resulttext .= '<li>'.$displaylist.'</li>';
12153: }
1.296 raeburn 12154: foreach my $item ('linktext','explanation') {
12155: if ($confhash{$itemid}{'display'}{$item}) {
12156: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
12157: }
12158: }
12159: }
1.267 raeburn 12160: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
12161: my $fieldlist;
12162: foreach my $field (@allfields) {
12163: if ($confhash{$itemid}{'fields'}{$field}) {
12164: $fieldlist .= (' 'x2).$lt{$field}.',';
12165: }
12166: }
12167: if ($fieldlist) {
12168: $fieldlist =~ s/,$//;
1.324 raeburn 12169: if ($confhash{$itemid}{'fields'}{'user'}) {
12170: if ($confhash{$itemid}{'incdom'}) {
12171: $fieldlist .= ' ('.&mt('username:domain').')';
12172: } else {
12173: $fieldlist .= ' ('.&mt('username').')';
12174: }
12175: }
1.267 raeburn 12176: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
12177: }
12178: }
12179: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
12180: my $rolemaps;
12181: foreach my $role (@courseroles) {
12182: if ($confhash{$itemid}{'roles'}{$role}) {
12183: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
12184: $confhash{$itemid}{'roles'}{$role}.',';
12185: }
12186: }
12187: if ($rolemaps) {
12188: $rolemaps =~ s/,$//;
12189: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
12190: }
12191: }
12192: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
12193: my $customlist;
12194: if (keys(%{$confhash{$itemid}{'custom'}})) {
12195: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
12196: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
12197: }
12198: }
12199: if ($customlist) {
1.317 raeburn 12200: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 12201: }
12202: }
12203: $resulttext .= '</ul></li>';
12204: }
12205: }
12206: $resulttext .= '</ul>';
12207: } else {
12208: $resulttext = &mt('No changes made.');
12209: }
12210: } else {
12211: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
12212: }
12213: if ($errors) {
12214: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12215: $errors.'</ul>';
12216: }
12217: return $resulttext;
12218: }
12219:
12220: sub process_ltitools_image {
12221: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
12222: my $filename = $env{'form.'.$caller.'.filename'};
12223: my ($error,$url);
12224: my ($width,$height) = (21,21);
12225: if ($configuserok eq 'ok') {
12226: if ($switchserver) {
12227: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
12228: $switchserver);
12229: } elsif ($author_ok eq 'ok') {
12230: my ($result,$imageurl,$madethumb) =
12231: &publishlogo($r,'upload',$caller,$dom,$confname,
12232: "ltitools/$itemid/icon",$width,$height);
12233: if ($result eq 'ok') {
12234: if ($madethumb) {
12235: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
12236: my $imagethumb = "$path/tn-".$imagefile;
12237: $url = $imagethumb;
12238: } else {
12239: $url = $imageurl;
12240: }
12241: } else {
12242: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
12243: }
12244: } else {
12245: $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);
12246: }
12247: } else {
12248: $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);
12249: }
12250: return ($url,$error);
12251: }
12252:
12253: sub get_ltitools_id {
12254: my ($cdom,$title) = @_;
12255: # get lock on ltitools db
12256: my $lockhash = {
12257: lock => $env{'user.name'}.
12258: ':'.$env{'user.domain'},
12259: };
12260: my $tries = 0;
12261: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
12262: my ($id,$error);
12263:
12264: while (($gotlock ne 'ok') && ($tries<10)) {
12265: $tries ++;
12266: sleep (0.1);
12267: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
12268: }
12269: if ($gotlock eq 'ok') {
12270: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
12271: if ($currids{'lock'}) {
12272: delete($currids{'lock'});
12273: if (keys(%currids)) {
12274: my @curr = sort { $a <=> $b } keys(%currids);
12275: if ($curr[-1] =~ /^\d+$/) {
12276: $id = 1 + $curr[-1];
12277: }
12278: } else {
12279: $id = 1;
12280: }
12281: if ($id) {
12282: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
12283: $error = 'nostore';
12284: }
12285: } else {
12286: $error = 'nonumber';
12287: }
12288: }
12289: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
12290: } else {
12291: $error = 'nolock';
12292: }
12293: return ($id,$error);
12294: }
12295:
1.320 raeburn 12296: sub modify_lti {
12297: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
12298: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12299: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
12300: my (%posslti,%posslticrs,%posscrstype);
12301: my @courseroles = ('cc','in','ta','ep','st');
12302: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
12303: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
12304: my @coursetypes = ('official','unofficial','community','textbook','placement');
12305: my %coursetypetitles = &Apache::lonlocal::texthash (
12306: official => 'Official',
12307: unofficial => 'Unofficial',
12308: community => 'Community',
12309: textbook => 'Textbook',
12310: placement => 'Placement Test',
12311: );
1.325 raeburn 12312: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 12313: my %lt = <i_names();
12314: map { $posslti{$_} = 1; } @ltiroles;
12315: map { $posslticrs{$_} = 1; } @lticourseroles;
12316: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 12317:
1.326 raeburn 12318: my %menutitles = <imenu_titles();
12319:
1.320 raeburn 12320: my (@items,%deletions,%itemids);
12321: if ($env{'form.lti_add'}) {
12322: my $consumer = $env{'form.lti_consumer_add'};
12323: $consumer =~ s/(`)/'/g;
12324: ($newid,my $error) = &get_lti_id($dom,$consumer);
12325: if ($newid) {
12326: $itemids{'add'} = $newid;
12327: push(@items,'add');
12328: $changes{$newid} = 1;
12329: } else {
12330: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
12331: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12332: }
12333: }
12334: if (ref($domconfig{$action}) eq 'HASH') {
12335: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
12336: if (@todelete) {
12337: map { $deletions{$_} = 1; } @todelete;
12338: }
12339: my $maxnum = $env{'form.lti_maxnum'};
12340: for (my $i=0; $i<=$maxnum; $i++) {
12341: my $itemid = $env{'form.lti_id_'.$i};
12342: $itemid =~ s/\D+//g;
12343: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12344: if ($deletions{$itemid}) {
12345: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
12346: } else {
12347: push(@items,$i);
12348: $itemids{$i} = $itemid;
12349: }
12350: }
12351: }
12352: }
12353: foreach my $idx (@items) {
12354: my $itemid = $itemids{$idx};
12355: next unless ($itemid);
12356: my $position = $env{'form.lti_pos_'.$idx};
12357: $position =~ s/\D+//g;
12358: if ($position ne '') {
12359: $allpos[$position] = $itemid;
12360: }
1.345 raeburn 12361: foreach my $item ('consumer','key','secret','lifetime','requser') {
1.320 raeburn 12362: my $formitem = 'form.lti_'.$item.'_'.$idx;
12363: $env{$formitem} =~ s/(`)/'/g;
12364: if ($item eq 'lifetime') {
12365: $env{$formitem} =~ s/[^\d.]//g;
12366: }
12367: if ($env{$formitem} ne '') {
12368: if (($item eq 'key') || ($item eq 'secret')) {
12369: $encconfig{$itemid}{$item} = $env{$formitem};
12370: } else {
12371: $confhash{$itemid}{$item} = $env{$formitem};
12372: unless (($idx eq 'add') || ($changes{$itemid})) {
12373: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
12374: $changes{$itemid} = 1;
12375: }
12376: }
12377: }
12378: }
12379: }
12380: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
12381: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
12382: }
1.345 raeburn 12383: if ($confhash{$itemid}{'requser'}) {
12384: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
12385: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
12386: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
12387: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
12388: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
12389: my $mapuser = $env{'form.lti_customuser_'.$idx};
12390: $mapuser =~ s/(`)/'/g;
12391: $mapuser =~ s/^\s+|\s+$//g;
12392: $confhash{$itemid}{'mapuser'} = $mapuser;
12393: }
12394: foreach my $ltirole (@lticourseroles) {
12395: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
12396: if (grep(/^\Q$possrole\E$/,@courseroles)) {
12397: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
12398: }
12399: }
12400: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
12401: my @makeuser;
12402: foreach my $ltirole (sort(@possmakeuser)) {
12403: if ($posslti{$ltirole}) {
12404: push(@makeuser,$ltirole);
12405: }
12406: }
12407: $confhash{$itemid}{'makeuser'} = \@makeuser;
12408: if (@makeuser) {
12409: my $lcauth = $env{'form.lti_lcauth_'.$idx};
12410: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
12411: $confhash{$itemid}{'lcauth'} = $lcauth;
12412: if ($lcauth ne 'internal') {
12413: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
12414: $lcauthparm =~ s/^(\s+|\s+)$//g;
12415: $lcauthparm =~ s/`//g;
12416: if ($lcauthparm ne '') {
12417: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
12418: }
12419: }
12420: } else {
12421: $confhash{$itemid}{'lcauth'} = 'lti';
12422: }
1.320 raeburn 12423: }
1.345 raeburn 12424: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
12425: if (@possinstdata) {
12426: foreach my $field (@possinstdata) {
12427: if (exists($fieldtitles{$field})) {
12428: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 12429: }
12430: }
12431: }
1.345 raeburn 12432: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
12433: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
12434: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
12435: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
12436: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
12437: $mapcrs =~ s/(`)/'/g;
12438: $mapcrs =~ s/^\s+|\s+$//g;
12439: $confhash{$itemid}{'mapcrs'} = $mapcrs;
12440: }
12441: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
12442: my @crstypes;
12443: foreach my $type (sort(@posstypes)) {
12444: if ($posscrstype{$type}) {
12445: push(@crstypes,$type);
1.325 raeburn 12446: }
12447: }
1.345 raeburn 12448: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
12449: if ($env{'form.lti_makecrs_'.$idx}) {
12450: $confhash{$itemid}{'makecrs'} = 1;
1.320 raeburn 12451: }
1.345 raeburn 12452: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
12453: my @selfenroll;
12454: foreach my $type (sort(@possenroll)) {
12455: if ($posslticrs{$type}) {
12456: push(@selfenroll,$type);
12457: }
1.320 raeburn 12458: }
1.345 raeburn 12459: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
12460: if ($env{'form.lti_crssec_'.$idx}) {
12461: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
12462: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
12463: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
12464: my $section = $env{'form.lti_customsection_'.$idx};
12465: $section =~ s/(`)/'/g;
12466: $section =~ s/^\s+|\s+$//g;
12467: if ($section ne '') {
12468: $confhash{$itemid}{'section'} = $section;
12469: }
1.320 raeburn 12470: }
12471: }
1.345 raeburn 12472: foreach my $field ('passback','roster','topmenu','inlinemenu') {
12473: if ($env{'form.lti_'.$field.'_'.$idx}) {
12474: $confhash{$itemid}{$field} = 1;
12475: }
1.320 raeburn 12476: }
1.345 raeburn 12477: if ($env{'form.lti_passback_'.$idx}) {
12478: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
12479: $confhash{$itemid}{'passbackformat'} = '1.0';
12480: } else {
12481: $confhash{$itemid}{'passbackformat'} = '1.1';
12482: }
1.337 raeburn 12483: }
1.345 raeburn 12484: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
12485: $confhash{$itemid}{lcmenu} = [];
12486: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
12487: foreach my $field (@possmenu) {
12488: if (exists($menutitles{$field})) {
12489: if ($field eq 'grades') {
12490: next unless ($env{'form.lti_inlinemenu_'.$idx});
12491: }
12492: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 12493: }
12494: }
12495: }
1.345 raeburn 12496: unless (($idx eq 'add') || ($changes{$itemid})) {
12497: foreach my $field ('mapuser','mapcrs','makecrs','section','passback','roster','lcauth','lcauthparm','topmenu','inlinemenu') {
12498: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.337 raeburn 12499: $changes{$itemid} = 1;
12500: }
12501: }
1.320 raeburn 12502: unless ($changes{$itemid}) {
1.345 raeburn 12503: if ($domconfig{$action}{$itemid}{'passback'} eq $confhash{$itemid}{'passback'}) {
12504: if ($domconfig{$action}{$itemid}{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 12505: $changes{$itemid} = 1;
12506: }
1.345 raeburn 12507: }
1.320 raeburn 12508: }
1.345 raeburn 12509: foreach my $field ('makeuser','mapcrstype','selfenroll','instdata','lcmenu') {
12510: unless ($changes{$itemid}) {
12511: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
12512: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
12513: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
12514: $confhash{$itemid}{$field});
12515: if (@diffs) {
12516: $changes{$itemid} = 1;
12517: }
12518: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
12519: $changes{$itemid} = 1;
12520: }
12521: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
12522: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 12523: $changes{$itemid} = 1;
12524: }
12525: }
1.345 raeburn 12526: }
12527: }
12528: unless ($changes{$itemid}) {
12529: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
12530: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
12531: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
12532: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
12533: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.320 raeburn 12534: $changes{$itemid} = 1;
12535: last;
12536: }
12537: }
1.345 raeburn 12538: unless ($changes{$itemid}) {
12539: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
12540: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
12541: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
12542: $changes{$itemid} = 1;
12543: last;
12544: }
12545: }
12546: }
12547: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
12548: $changes{$itemid} = 1;
1.320 raeburn 12549: }
1.345 raeburn 12550: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
12551: unless ($changes{$itemid}) {
12552: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
12553: $changes{$itemid} = 1;
12554: }
1.320 raeburn 12555: }
12556: }
12557: }
12558: }
12559: }
12560: }
12561: if (@allpos > 0) {
12562: my $idx = 0;
12563: foreach my $itemid (@allpos) {
12564: if ($itemid ne '') {
12565: $confhash{$itemid}{'order'} = $idx;
12566: if (ref($domconfig{$action}) eq 'HASH') {
12567: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12568: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
12569: $changes{$itemid} = 1;
12570: }
12571: }
12572: }
12573: $idx ++;
12574: }
12575: }
12576: }
12577: my %ltihash = (
12578: $action => { %confhash }
12579: );
12580: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
12581: $dom);
12582: if ($putresult eq 'ok') {
12583: my %ltienchash = (
12584: $action => { %encconfig }
12585: );
12586: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
12587: if (keys(%changes) > 0) {
12588: my $cachetime = 24*60*60;
12589: my %ltiall = %confhash;
12590: foreach my $id (keys(%ltiall)) {
12591: if (ref($encconfig{$id}) eq 'HASH') {
12592: foreach my $item ('key','secret') {
12593: $ltiall{$id}{$item} = $encconfig{$id}{$item};
12594: }
12595: }
12596: }
12597: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
12598: if (ref($lastactref) eq 'HASH') {
12599: $lastactref->{'lti'} = 1;
12600: }
12601: $resulttext = &mt('Changes made:').'<ul>';
12602: my %bynum;
12603: foreach my $itemid (sort(keys(%changes))) {
12604: my $position = $confhash{$itemid}{'order'};
12605: $bynum{$position} = $itemid;
12606: }
12607: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
12608: my $itemid = $bynum{$pos};
12609: if (ref($confhash{$itemid}) ne 'HASH') {
12610: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
12611: } else {
12612: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b></li><ul>';
12613: my $position = $pos + 1;
12614: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
12615: foreach my $item ('version','lifetime') {
12616: if ($confhash{$itemid}{$item} ne '') {
12617: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
12618: }
12619: }
12620: if ($encconfig{$itemid}{'key'} ne '') {
12621: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
12622: }
12623: if ($encconfig{$itemid}{'secret'} ne '') {
12624: $resulttext .= '<li>'.$lt{'secret'}.': ';
12625: my $num = length($encconfig{$itemid}{'secret'});
12626: $resulttext .= ('*'x$num).'</li>';
12627: }
1.345 raeburn 12628: if ($confhash{$itemid}{'requser'}) {
12629: if ($confhash{$itemid}{'mapuser'}) {
12630: my $shownmapuser;
12631: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
12632: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
12633: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
12634: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
12635: } else {
12636: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 12637: }
1.345 raeburn 12638: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 12639: }
1.345 raeburn 12640: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
12641: my $rolemaps;
12642: foreach my $role (@ltiroles) {
12643: if ($confhash{$itemid}{'maproles'}{$role}) {
12644: $rolemaps .= (' 'x2).$role.'='.
12645: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
12646: 'Course').',';
12647: }
12648: }
12649: if ($rolemaps) {
12650: $rolemaps =~ s/,$//;
12651: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
12652: }
12653: }
12654: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
12655: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
12656: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
12657: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
12658: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
12659: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
12660: } else {
12661: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
12662: $confhash{$itemid}{'lcauth'});
12663: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
12664: $resulttext .= '; '.&mt('a randomly generated password will be created');
12665: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
12666: if ($confhash{$itemid}{'lcauthparm'} ne '') {
12667: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
12668: }
12669: } else {
12670: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
12671: }
12672: }
12673: $resulttext .= '</li>';
12674: } else {
12675: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
12676: }
1.320 raeburn 12677: }
1.345 raeburn 12678: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
12679: if (@{$confhash{$itemid}{'instdata'}} > 0) {
12680: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
12681: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 12682: } else {
1.345 raeburn 12683: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 12684: }
1.320 raeburn 12685: }
1.345 raeburn 12686: if ($confhash{$itemid}{'mapcrs'}) {
12687: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
12688: }
12689: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
12690: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
12691: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
12692: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
12693: '</li>';
12694: } else {
12695: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
12696: }
1.325 raeburn 12697: }
1.345 raeburn 12698: if ($confhash{$itemid}{'makecrs'}) {
12699: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
1.320 raeburn 12700: } else {
1.345 raeburn 12701: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
1.320 raeburn 12702: }
1.345 raeburn 12703: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
12704: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
12705: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
12706: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
12707: '</li>';
12708: } else {
12709: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
12710: }
1.320 raeburn 12711: }
1.345 raeburn 12712: if ($confhash{$itemid}{'section'}) {
12713: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
12714: $resulttext .= '<li>'.&mt('User section from standard field:').
12715: ' (course_section_sourcedid)'.'</li>';
12716: } else {
12717: $resulttext .= '<li>'.&mt('User section from:').' '.
12718: $confhash{$itemid}{'section'}.'</li>';
12719: }
1.320 raeburn 12720: } else {
1.345 raeburn 12721: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
1.320 raeburn 12722: }
1.345 raeburn 12723: foreach my $item ('passback','roster','topmenu','inlinemenu') {
12724: $resulttext .= '<li>'.$lt{$item}.': ';
12725: if ($confhash{$itemid}{$item}) {
12726: $resulttext .= &mt('Yes');
12727: if ($item eq 'passback') {
12728: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
12729: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
12730: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
12731: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
12732: }
1.337 raeburn 12733: }
1.345 raeburn 12734: } else {
12735: $resulttext .= &mt('No');
1.337 raeburn 12736: }
1.345 raeburn 12737: $resulttext .= '</li>';
1.320 raeburn 12738: }
1.345 raeburn 12739: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
12740: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
12741: $resulttext .= '<li>'.&mt('Menu items:').' '.
12742: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
12743: } else {
12744: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
12745: }
1.326 raeburn 12746: }
12747: }
1.320 raeburn 12748: $resulttext .= '</ul></li>';
12749: }
12750: }
12751: $resulttext .= '</ul>';
12752: } else {
12753: $resulttext = &mt('No changes made.');
12754: }
12755: } else {
12756: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
12757: }
12758: if ($errors) {
12759: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12760: $errors.'</ul>';
12761: }
12762: return $resulttext;
12763: }
12764:
12765: sub get_lti_id {
12766: my ($domain,$consumer) = @_;
12767: # get lock on lti db
12768: my $lockhash = {
12769: lock => $env{'user.name'}.
12770: ':'.$env{'user.domain'},
12771: };
12772: my $tries = 0;
12773: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
12774: my ($id,$error);
12775:
12776: while (($gotlock ne 'ok') && ($tries<10)) {
12777: $tries ++;
12778: sleep (0.1);
12779: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
12780: }
12781: if ($gotlock eq 'ok') {
12782: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
12783: if ($currids{'lock'}) {
12784: delete($currids{'lock'});
12785: if (keys(%currids)) {
12786: my @curr = sort { $a <=> $b } keys(%currids);
12787: if ($curr[-1] =~ /^\d+$/) {
12788: $id = 1 + $curr[-1];
12789: }
12790: } else {
12791: $id = 1;
12792: }
12793: if ($id) {
12794: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
12795: $error = 'nostore';
12796: }
12797: } else {
12798: $error = 'nonumber';
12799: }
12800: }
12801: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
12802: } else {
12803: $error = 'nolock';
12804: }
12805: return ($id,$error);
12806: }
12807:
1.3 raeburn 12808: sub modify_autoenroll {
1.205 raeburn 12809: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 12810: my ($resulttext,%changes);
12811: my %currautoenroll;
12812: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
12813: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
12814: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
12815: }
12816: }
12817: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
12818: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 12819: sender => 'Sender for notification messages',
1.274 raeburn 12820: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
12821: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 12822: my @offon = ('off','on');
1.17 raeburn 12823: my $sender_uname = $env{'form.sender_uname'};
12824: my $sender_domain = $env{'form.sender_domain'};
12825: if ($sender_domain eq '') {
12826: $sender_uname = '';
12827: } elsif ($sender_uname eq '') {
12828: $sender_domain = '';
12829: }
1.129 raeburn 12830: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 12831: my $failsafe = $env{'form.autoenroll_failsafe'};
12832: $failsafe =~ s{^\s+|\s+$}{}g;
12833: if ($failsafe =~ /\D/) {
12834: undef($failsafe);
12835: }
1.1 raeburn 12836: my %autoenrollhash = (
1.129 raeburn 12837: autoenroll => { 'run' => $env{'form.autoenroll_run'},
12838: 'sender_uname' => $sender_uname,
12839: 'sender_domain' => $sender_domain,
12840: 'co-owners' => $coowners,
1.274 raeburn 12841: 'autofailsafe' => $failsafe,
1.1 raeburn 12842: }
12843: );
1.4 raeburn 12844: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
12845: $dom);
1.1 raeburn 12846: if ($putresult eq 'ok') {
12847: if (exists($currautoenroll{'run'})) {
12848: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
12849: $changes{'run'} = 1;
12850: }
12851: } elsif ($autorun) {
12852: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 12853: $changes{'run'} = 1;
1.1 raeburn 12854: }
12855: }
1.17 raeburn 12856: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 12857: $changes{'sender'} = 1;
12858: }
1.17 raeburn 12859: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 12860: $changes{'sender'} = 1;
12861: }
1.129 raeburn 12862: if ($currautoenroll{'co-owners'} ne '') {
12863: if ($currautoenroll{'co-owners'} ne $coowners) {
12864: $changes{'coowners'} = 1;
12865: }
12866: } elsif ($coowners) {
12867: $changes{'coowners'} = 1;
1.274 raeburn 12868: }
12869: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
12870: $changes{'autofailsafe'} = 1;
12871: }
1.1 raeburn 12872: if (keys(%changes) > 0) {
12873: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 12874: if ($changes{'run'}) {
1.1 raeburn 12875: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
12876: }
12877: if ($changes{'sender'}) {
1.17 raeburn 12878: if ($sender_uname eq '' || $sender_domain eq '') {
12879: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
12880: } else {
12881: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
12882: }
1.1 raeburn 12883: }
1.129 raeburn 12884: if ($changes{'coowners'}) {
12885: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
12886: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12887: if (ref($lastactref) eq 'HASH') {
12888: $lastactref->{'domainconfig'} = 1;
12889: }
1.129 raeburn 12890: }
1.274 raeburn 12891: if ($changes{'autofailsafe'}) {
12892: if ($failsafe ne '') {
1.299 raeburn 12893: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 12894: } else {
1.299 raeburn 12895: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 12896: }
12897: &Apache::lonnet::get_domain_defaults($dom,1);
12898: if (ref($lastactref) eq 'HASH') {
12899: $lastactref->{'domdefaults'} = 1;
12900: }
12901: }
1.1 raeburn 12902: $resulttext .= '</ul>';
12903: } else {
12904: $resulttext = &mt('No changes made to auto-enrollment settings');
12905: }
12906: } else {
1.11 albertel 12907: $resulttext = '<span class="LC_error">'.
12908: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12909: }
1.3 raeburn 12910: return $resulttext;
1.1 raeburn 12911: }
12912:
12913: sub modify_autoupdate {
1.3 raeburn 12914: my ($dom,%domconfig) = @_;
1.1 raeburn 12915: my ($resulttext,%currautoupdate,%fields,%changes);
12916: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
12917: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
12918: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
12919: }
12920: }
12921: my @offon = ('off','on');
12922: my %title = &Apache::lonlocal::texthash (
12923: run => 'Auto-update:',
12924: classlists => 'Updates to user information in classlists?'
12925: );
1.44 raeburn 12926: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 12927: my %fieldtitles = &Apache::lonlocal::texthash (
12928: id => 'Student/Employee ID',
1.20 raeburn 12929: permanentemail => 'E-mail address',
1.1 raeburn 12930: lastname => 'Last Name',
12931: firstname => 'First Name',
12932: middlename => 'Middle Name',
1.132 raeburn 12933: generation => 'Generation',
1.1 raeburn 12934: );
1.142 raeburn 12935: $othertitle = &mt('All users');
1.1 raeburn 12936: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 12937: $othertitle = &mt('Other users');
1.1 raeburn 12938: }
12939: foreach my $key (keys(%env)) {
12940: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 12941: my ($usertype,$item) = ($1,$2);
12942: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
12943: if ($usertype eq 'default') {
12944: push(@{$fields{$1}},$2);
12945: } elsif (ref($types) eq 'ARRAY') {
12946: if (grep(/^\Q$usertype\E$/,@{$types})) {
12947: push(@{$fields{$1}},$2);
12948: }
12949: }
12950: }
1.1 raeburn 12951: }
12952: }
1.131 raeburn 12953: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
12954: @lockablenames = sort(@lockablenames);
12955: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
12956: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
12957: if (@changed) {
12958: $changes{'lockablenames'} = 1;
12959: }
12960: } else {
12961: if (@lockablenames) {
12962: $changes{'lockablenames'} = 1;
12963: }
12964: }
1.1 raeburn 12965: my %updatehash = (
12966: autoupdate => { run => $env{'form.autoupdate_run'},
12967: classlists => $env{'form.classlists'},
12968: fields => {%fields},
1.131 raeburn 12969: lockablenames => \@lockablenames,
1.1 raeburn 12970: }
12971: );
12972: foreach my $key (keys(%currautoupdate)) {
12973: if (($key eq 'run') || ($key eq 'classlists')) {
12974: if (exists($updatehash{autoupdate}{$key})) {
12975: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
12976: $changes{$key} = 1;
12977: }
12978: }
12979: } elsif ($key eq 'fields') {
12980: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 12981: foreach my $item (@{$types},'default') {
1.1 raeburn 12982: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
12983: my $change = 0;
12984: foreach my $type (@{$currautoupdate{$key}{$item}}) {
12985: if (!exists($fields{$item})) {
12986: $change = 1;
1.132 raeburn 12987: last;
1.1 raeburn 12988: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 12989: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 12990: $change = 1;
1.132 raeburn 12991: last;
1.1 raeburn 12992: }
12993: }
12994: }
12995: if ($change) {
12996: push(@{$changes{$key}},$item);
12997: }
1.26 raeburn 12998: }
1.1 raeburn 12999: }
13000: }
1.131 raeburn 13001: } elsif ($key eq 'lockablenames') {
13002: if (ref($currautoupdate{$key}) eq 'ARRAY') {
13003: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
13004: if (@changed) {
13005: $changes{'lockablenames'} = 1;
13006: }
13007: } else {
13008: if (@lockablenames) {
13009: $changes{'lockablenames'} = 1;
13010: }
13011: }
13012: }
13013: }
13014: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
13015: if (@lockablenames) {
13016: $changes{'lockablenames'} = 1;
1.1 raeburn 13017: }
13018: }
1.26 raeburn 13019: foreach my $item (@{$types},'default') {
13020: if (defined($fields{$item})) {
13021: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 13022: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
13023: my $change = 0;
13024: if (ref($fields{$item}) eq 'ARRAY') {
13025: foreach my $type (@{$fields{$item}}) {
13026: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
13027: $change = 1;
13028: last;
13029: }
13030: }
13031: }
13032: if ($change) {
13033: push(@{$changes{'fields'}},$item);
13034: }
13035: } else {
1.26 raeburn 13036: push(@{$changes{'fields'}},$item);
13037: }
13038: } else {
13039: push(@{$changes{'fields'}},$item);
1.1 raeburn 13040: }
13041: }
13042: }
13043: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
13044: $dom);
13045: if ($putresult eq 'ok') {
13046: if (keys(%changes) > 0) {
13047: $resulttext = &mt('Changes made:').'<ul>';
13048: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 13049: if ($key eq 'lockablenames') {
13050: $resulttext .= '<li>';
13051: if (@lockablenames) {
13052: $usertypes->{'default'} = $othertitle;
13053: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
13054: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
13055: } else {
13056: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
13057: }
13058: $resulttext .= '</li>';
13059: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 13060: foreach my $item (@{$changes{$key}}) {
13061: my @newvalues;
13062: foreach my $type (@{$fields{$item}}) {
13063: push(@newvalues,$fieldtitles{$type});
13064: }
1.3 raeburn 13065: my $newvaluestr;
13066: if (@newvalues > 0) {
13067: $newvaluestr = join(', ',@newvalues);
13068: } else {
13069: $newvaluestr = &mt('none');
1.6 raeburn 13070: }
1.1 raeburn 13071: if ($item eq 'default') {
1.26 raeburn 13072: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 13073: } else {
1.26 raeburn 13074: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 13075: }
13076: }
13077: } else {
13078: my $newvalue;
13079: if ($key eq 'run') {
13080: $newvalue = $offon[$env{'form.autoupdate_run'}];
13081: } else {
13082: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 13083: }
1.1 raeburn 13084: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
13085: }
13086: }
13087: $resulttext .= '</ul>';
13088: } else {
1.3 raeburn 13089: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 13090: }
13091: } else {
1.11 albertel 13092: $resulttext = '<span class="LC_error">'.
13093: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13094: }
1.3 raeburn 13095: return $resulttext;
1.1 raeburn 13096: }
13097:
1.125 raeburn 13098: sub modify_autocreate {
13099: my ($dom,%domconfig) = @_;
13100: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
13101: if (ref($domconfig{'autocreate'}) eq 'HASH') {
13102: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
13103: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
13104: }
13105: }
13106: my %title= ( xml => 'Auto-creation of courses in XML course description files',
13107: req => 'Auto-creation of validated requests for official courses',
13108: xmldc => 'Identity of course creator of courses from XML files',
13109: );
13110: my @types = ('xml','req');
13111: foreach my $item (@types) {
13112: $newvals{$item} = $env{'form.autocreate_'.$item};
13113: $newvals{$item} =~ s/\D//g;
13114: $newvals{$item} = 0 if ($newvals{$item} eq '');
13115: }
13116: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 13117: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 13118: unless (exists($domcoords{$newvals{'xmldc'}})) {
13119: $newvals{'xmldc'} = '';
13120: }
13121: %autocreatehash = (
13122: autocreate => { xml => $newvals{'xml'},
13123: req => $newvals{'req'},
13124: }
13125: );
13126: if ($newvals{'xmldc'} ne '') {
13127: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
13128: }
13129: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
13130: $dom);
13131: if ($putresult eq 'ok') {
13132: my @items = @types;
13133: if ($newvals{'xml'}) {
13134: push(@items,'xmldc');
13135: }
13136: foreach my $item (@items) {
13137: if (exists($currautocreate{$item})) {
13138: if ($currautocreate{$item} ne $newvals{$item}) {
13139: $changes{$item} = 1;
13140: }
13141: } elsif ($newvals{$item}) {
13142: $changes{$item} = 1;
13143: }
13144: }
13145: if (keys(%changes) > 0) {
13146: my @offon = ('off','on');
13147: $resulttext = &mt('Changes made:').'<ul>';
13148: foreach my $item (@types) {
13149: if ($changes{$item}) {
13150: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 13151: $resulttext .= '<li>'.
13152: &mt("$title{$item} set to [_1]$newtxt [_2]",
13153: '<b>','</b>').
13154: '</li>';
1.125 raeburn 13155: }
13156: }
13157: if ($changes{'xmldc'}) {
13158: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
13159: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 13160: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 13161: }
13162: $resulttext .= '</ul>';
13163: } else {
13164: $resulttext = &mt('No changes made to auto-creation settings');
13165: }
13166: } else {
13167: $resulttext = '<span class="LC_error">'.
13168: &mt('An error occurred: [_1]',$putresult).'</span>';
13169: }
13170: return $resulttext;
13171: }
13172:
1.23 raeburn 13173: sub modify_directorysrch {
1.295 raeburn 13174: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 13175: my ($resulttext,%changes);
13176: my %currdirsrch;
13177: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
13178: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
13179: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
13180: }
13181: }
1.277 raeburn 13182: my %title = ( available => 'Institutional directory search available',
13183: localonly => 'Other domains can search institution',
13184: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 13185: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 13186: searchby => 'Search types',
13187: searchtypes => 'Search latitude');
13188: my @offon = ('off','on');
1.24 raeburn 13189: my @otherdoms = ('Yes','No');
1.23 raeburn 13190:
1.25 raeburn 13191: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 13192: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
13193: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
13194:
1.44 raeburn 13195: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 13196: if (keys(%{$usertypes}) == 0) {
13197: @cansearch = ('default');
13198: } else {
13199: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
13200: foreach my $type (@{$currdirsrch{'cansearch'}}) {
13201: if (!grep(/^\Q$type\E$/,@cansearch)) {
13202: push(@{$changes{'cansearch'}},$type);
13203: }
1.23 raeburn 13204: }
1.26 raeburn 13205: foreach my $type (@cansearch) {
13206: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
13207: push(@{$changes{'cansearch'}},$type);
13208: }
1.23 raeburn 13209: }
1.26 raeburn 13210: } else {
13211: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 13212: }
13213: }
13214:
13215: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
13216: foreach my $by (@{$currdirsrch{'searchby'}}) {
13217: if (!grep(/^\Q$by\E$/,@searchby)) {
13218: push(@{$changes{'searchby'}},$by);
13219: }
13220: }
13221: foreach my $by (@searchby) {
13222: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
13223: push(@{$changes{'searchby'}},$by);
13224: }
13225: }
13226: } else {
13227: push(@{$changes{'searchby'}},@searchby);
13228: }
1.25 raeburn 13229:
13230: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
13231: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
13232: if (!grep(/^\Q$type\E$/,@searchtypes)) {
13233: push(@{$changes{'searchtypes'}},$type);
13234: }
13235: }
13236: foreach my $type (@searchtypes) {
13237: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
13238: push(@{$changes{'searchtypes'}},$type);
13239: }
13240: }
13241: } else {
13242: if (exists($currdirsrch{'searchtypes'})) {
13243: foreach my $type (@searchtypes) {
13244: if ($type ne $currdirsrch{'searchtypes'}) {
13245: push(@{$changes{'searchtypes'}},$type);
13246: }
13247: }
13248: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
13249: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
13250: }
13251: } else {
13252: push(@{$changes{'searchtypes'}},@searchtypes);
13253: }
13254: }
13255:
1.23 raeburn 13256: my %dirsrch_hash = (
13257: directorysrch => { available => $env{'form.dirsrch_available'},
13258: cansearch => \@cansearch,
1.277 raeburn 13259: localonly => $env{'form.dirsrch_instlocalonly'},
13260: lclocalonly => $env{'form.dirsrch_domlocalonly'},
13261: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 13262: searchby => \@searchby,
1.25 raeburn 13263: searchtypes => \@searchtypes,
1.23 raeburn 13264: }
13265: );
13266: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
13267: $dom);
13268: if ($putresult eq 'ok') {
13269: if (exists($currdirsrch{'available'})) {
13270: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
13271: $changes{'available'} = 1;
13272: }
13273: } else {
13274: if ($env{'form.dirsrch_available'} eq '1') {
13275: $changes{'available'} = 1;
13276: }
13277: }
1.277 raeburn 13278: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 13279: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
13280: $changes{'lcavailable'} = 1;
13281: }
1.277 raeburn 13282: } else {
13283: if ($env{'form.dirsrch_lcavailable'} eq '1') {
13284: $changes{'lcavailable'} = 1;
13285: }
13286: }
1.24 raeburn 13287: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 13288: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
13289: $changes{'localonly'} = 1;
13290: }
1.24 raeburn 13291: } else {
1.277 raeburn 13292: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 13293: $changes{'localonly'} = 1;
13294: }
13295: }
1.277 raeburn 13296: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 13297: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
13298: $changes{'lclocalonly'} = 1;
13299: }
1.277 raeburn 13300: } else {
13301: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
13302: $changes{'lclocalonly'} = 1;
13303: }
13304: }
1.23 raeburn 13305: if (keys(%changes) > 0) {
13306: $resulttext = &mt('Changes made:').'<ul>';
13307: if ($changes{'available'}) {
13308: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
13309: }
1.277 raeburn 13310: if ($changes{'lcavailable'}) {
13311: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
13312: }
1.24 raeburn 13313: if ($changes{'localonly'}) {
1.277 raeburn 13314: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 13315: }
1.277 raeburn 13316: if ($changes{'lclocalonly'}) {
13317: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 13318: }
1.23 raeburn 13319: if (ref($changes{'cansearch'}) eq 'ARRAY') {
13320: my $chgtext;
1.26 raeburn 13321: if (ref($usertypes) eq 'HASH') {
13322: if (keys(%{$usertypes}) > 0) {
13323: foreach my $type (@{$types}) {
13324: if (grep(/^\Q$type\E$/,@cansearch)) {
13325: $chgtext .= $usertypes->{$type}.'; ';
13326: }
13327: }
13328: if (grep(/^default$/,@cansearch)) {
13329: $chgtext .= $othertitle;
13330: } else {
13331: $chgtext =~ s/\; $//;
13332: }
1.210 raeburn 13333: $resulttext .=
1.178 raeburn 13334: '<li>'.
13335: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
13336: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
13337: '</li>';
1.23 raeburn 13338: }
13339: }
13340: }
13341: if (ref($changes{'searchby'}) eq 'ARRAY') {
13342: my ($searchtitles,$titleorder) = &sorted_searchtitles();
13343: my $chgtext;
13344: foreach my $type (@{$titleorder}) {
13345: if (grep(/^\Q$type\E$/,@searchby)) {
13346: if (defined($searchtitles->{$type})) {
13347: $chgtext .= $searchtitles->{$type}.'; ';
13348: }
13349: }
13350: }
13351: $chgtext =~ s/\; $//;
13352: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
13353: }
1.25 raeburn 13354: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
13355: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
13356: my $chgtext;
13357: foreach my $type (@{$srchtypeorder}) {
13358: if (grep(/^\Q$type\E$/,@searchtypes)) {
13359: if (defined($srchtypes_desc->{$type})) {
13360: $chgtext .= $srchtypes_desc->{$type}.'; ';
13361: }
13362: }
13363: }
13364: $chgtext =~ s/\; $//;
1.178 raeburn 13365: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 13366: }
13367: $resulttext .= '</ul>';
1.295 raeburn 13368: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
13369: if (ref($lastactref) eq 'HASH') {
13370: $lastactref->{'directorysrch'} = 1;
13371: }
1.23 raeburn 13372: } else {
1.277 raeburn 13373: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 13374: }
13375: } else {
13376: $resulttext = '<span class="LC_error">'.
1.27 raeburn 13377: &mt('An error occurred: [_1]',$putresult).'</span>';
13378: }
13379: return $resulttext;
13380: }
13381:
1.28 raeburn 13382: sub modify_contacts {
1.205 raeburn 13383: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 13384: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
13385: if (ref($domconfig{'contacts'}) eq 'HASH') {
13386: foreach my $key (keys(%{$domconfig{'contacts'}})) {
13387: $currsetting{$key} = $domconfig{'contacts'}{$key};
13388: }
13389: }
1.286 raeburn 13390: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 13391: my @contacts = ('supportemail','adminemail');
1.286 raeburn 13392: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 13393: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 13394: my @toggles = ('reporterrors','reportupdates','reportstatus');
13395: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 13396: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 13397: foreach my $type (@mailings) {
13398: @{$newsetting{$type}} =
13399: &Apache::loncommon::get_env_multiple('form.'.$type);
13400: foreach my $item (@contacts) {
13401: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
13402: $contacts_hash{contacts}{$type}{$item} = 1;
13403: } else {
13404: $contacts_hash{contacts}{$type}{$item} = 0;
13405: }
1.289 raeburn 13406: }
1.28 raeburn 13407: $others{$type} = $env{'form.'.$type.'_others'};
13408: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 13409: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13410: $bcc{$type} = $env{'form.'.$type.'_bcc'};
13411: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 13412: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
13413: $includestr{$type} = $env{'form.'.$type.'_includestr'};
13414: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
13415: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
13416: }
1.134 raeburn 13417: }
1.28 raeburn 13418: }
13419: foreach my $item (@contacts) {
13420: $to{$item} = $env{'form.'.$item};
13421: $contacts_hash{'contacts'}{$item} = $to{$item};
13422: }
1.203 raeburn 13423: foreach my $item (@toggles) {
13424: if ($env{'form.'.$item} =~ /^(0|1)$/) {
13425: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
13426: }
13427: }
1.340 raeburn 13428: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
13429: foreach my $item (@lonstatus) {
13430: if ($item eq 'excluded') {
13431: my (%serverhomes,@excluded);
13432: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
13433: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
13434: if (@possexcluded) {
13435: foreach my $id (sort(@possexcluded)) {
13436: if ($serverhomes{$id}) {
13437: push(@excluded,$id);
13438: }
13439: }
13440: }
13441: if (@excluded) {
13442: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
13443: }
13444: } elsif ($item eq 'weights') {
13445: foreach my $type ('E','W','N') {
13446: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
13447: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
13448: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
13449: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
13450: $env{'form.error'.$item.'_'.$type};
13451: }
13452: }
13453: }
13454: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
13455: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
13456: if ($env{'form.error'.$item} =~ /^\d+$/) {
13457: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
13458: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
13459: }
13460: }
13461: }
13462: }
1.286 raeburn 13463: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
13464: foreach my $field (@{$fields}) {
13465: if (ref($possoptions->{$field}) eq 'ARRAY') {
13466: my $value = $env{'form.helpform_'.$field};
13467: $value =~ s/^\s+|\s+$//g;
13468: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 13469: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 13470: if ($field eq 'screenshot') {
13471: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
13472: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 13473: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 13474: }
13475: }
13476: }
13477: }
13478: }
13479: }
1.315 raeburn 13480: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13481: my (@statuses,%usertypeshash,@overrides);
13482: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
13483: @statuses = @{$types};
13484: if (ref($usertypes) eq 'HASH') {
13485: %usertypeshash = %{$usertypes};
13486: }
13487: }
13488: if (@statuses) {
13489: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
13490: foreach my $type (@possoverrides) {
13491: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
13492: push(@overrides,$type);
13493: }
13494: }
13495: if (@overrides) {
13496: foreach my $type (@overrides) {
13497: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
13498: foreach my $item (@contacts) {
13499: if (grep(/^\Q$item\E$/,@standard)) {
13500: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
13501: $newsetting{'override_'.$type}{$item} = 1;
13502: } else {
13503: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
13504: $newsetting{'override_'.$type}{$item} = 0;
13505: }
13506: }
13507: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
13508: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
13509: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
13510: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
13511: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
13512: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
13513: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
13514: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
13515: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
13516: }
13517: }
13518: }
13519: }
1.28 raeburn 13520: if (keys(%currsetting) > 0) {
13521: foreach my $item (@contacts) {
13522: if ($to{$item} ne $currsetting{$item}) {
13523: $changes{$item} = 1;
13524: }
13525: }
13526: foreach my $type (@mailings) {
13527: foreach my $item (@contacts) {
13528: if (ref($currsetting{$type}) eq 'HASH') {
13529: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
13530: push(@{$changes{$type}},$item);
13531: }
13532: } else {
13533: push(@{$changes{$type}},@{$newsetting{$type}});
13534: }
13535: }
13536: if ($others{$type} ne $currsetting{$type}{'others'}) {
13537: push(@{$changes{$type}},'others');
13538: }
1.289 raeburn 13539: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13540: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
13541: push(@{$changes{$type}},'bcc');
13542: }
1.286 raeburn 13543: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
13544: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
13545: push(@{$changes{$type}},'include');
13546: }
13547: }
13548: }
13549: if (ref($fields) eq 'ARRAY') {
13550: if (ref($currsetting{'helpform'}) eq 'HASH') {
13551: foreach my $field (@{$fields}) {
13552: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
13553: push(@{$changes{'helpform'}},$field);
13554: }
13555: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
13556: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
13557: push(@{$changes{'helpform'}},'maxsize');
13558: }
13559: }
13560: }
13561: } else {
13562: foreach my $field (@{$fields}) {
13563: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
13564: push(@{$changes{'helpform'}},$field);
13565: }
13566: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
13567: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
13568: push(@{$changes{'helpform'}},'maxsize');
13569: }
13570: }
13571: }
1.134 raeburn 13572: }
1.28 raeburn 13573: }
1.315 raeburn 13574: if (@statuses) {
13575: if (ref($currsetting{'overrides'}) eq 'HASH') {
13576: foreach my $key (keys(%{$currsetting{'overrides'}})) {
13577: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
13578: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
13579: foreach my $item (@contacts,'bcc','others','include') {
13580: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
13581: push(@{$changes{'overrides'}},$key);
13582: last;
13583: }
13584: }
13585: } else {
13586: push(@{$changes{'overrides'}},$key);
13587: }
13588: }
13589: }
13590: foreach my $key (@overrides) {
13591: unless (exists($currsetting{'overrides'}{$key})) {
13592: push(@{$changes{'overrides'}},$key);
13593: }
13594: }
13595: } else {
13596: foreach my $key (@overrides) {
13597: push(@{$changes{'overrides'}},$key);
13598: }
13599: }
13600: }
1.340 raeburn 13601: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
13602: foreach my $key ('excluded','weights','threshold','sysmail') {
13603: if ($key eq 'excluded') {
13604: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
13605: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
13606: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
13607: (@{$currsetting{'lonstatus'}{$key}})) {
13608: my @diffs =
13609: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
13610: $currsetting{'lonstatus'}{$key});
13611: if (@diffs) {
13612: push(@{$changes{'lonstatus'}},$key);
13613: }
13614: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
13615: push(@{$changes{'lonstatus'}},$key);
13616: }
13617: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
13618: (@{$currsetting{'lonstatus'}{$key}})) {
13619: push(@{$changes{'lonstatus'}},$key);
13620: }
13621: } elsif ($key eq 'weights') {
13622: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
13623: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
13624: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 13625: foreach my $type ('E','W','N','U') {
1.340 raeburn 13626: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
13627: $currsetting{'lonstatus'}{$key}{$type}) {
13628: push(@{$changes{'lonstatus'}},$key);
13629: last;
13630: }
13631: }
13632: } else {
1.341 raeburn 13633: foreach my $type ('E','W','N','U') {
1.340 raeburn 13634: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
13635: push(@{$changes{'lonstatus'}},$key);
13636: last;
13637: }
13638: }
13639: }
13640: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 13641: foreach my $type ('E','W','N','U') {
1.340 raeburn 13642: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
13643: push(@{$changes{'lonstatus'}},$key);
13644: last;
13645: }
13646: }
13647: }
13648: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
13649: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
13650: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
13651: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
13652: push(@{$changes{'lonstatus'}},$key);
13653: }
13654: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
13655: push(@{$changes{'lonstatus'}},$key);
13656: }
13657: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
13658: push(@{$changes{'lonstatus'}},$key);
13659: }
13660: }
13661: }
13662: } else {
13663: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
13664: foreach my $key ('excluded','weights','threshold','sysmail') {
13665: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
13666: push(@{$changes{'lonstatus'}},$key);
13667: }
13668: }
13669: }
13670: }
1.28 raeburn 13671: } else {
13672: my %default;
13673: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
13674: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
13675: $default{'errormail'} = 'adminemail';
13676: $default{'packagesmail'} = 'adminemail';
13677: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 13678: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 13679: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 13680: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 13681: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 13682: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 13683: foreach my $item (@contacts) {
13684: if ($to{$item} ne $default{$item}) {
1.286 raeburn 13685: $changes{$item} = 1;
1.203 raeburn 13686: }
1.28 raeburn 13687: }
13688: foreach my $type (@mailings) {
13689: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
13690: push(@{$changes{$type}},@{$newsetting{$type}});
13691: }
13692: if ($others{$type} ne '') {
13693: push(@{$changes{$type}},'others');
1.134 raeburn 13694: }
1.286 raeburn 13695: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13696: if ($bcc{$type} ne '') {
13697: push(@{$changes{$type}},'bcc');
13698: }
1.286 raeburn 13699: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
13700: push(@{$changes{$type}},'include');
13701: }
1.134 raeburn 13702: }
1.28 raeburn 13703: }
1.286 raeburn 13704: if (ref($fields) eq 'ARRAY') {
13705: foreach my $field (@{$fields}) {
13706: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
13707: push(@{$changes{'helpform'}},$field);
13708: }
13709: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
13710: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
13711: push(@{$changes{'helpform'}},'maxsize');
13712: }
13713: }
13714: }
1.289 raeburn 13715: }
1.340 raeburn 13716: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
13717: foreach my $key ('excluded','weights','threshold','sysmail') {
13718: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
13719: push(@{$changes{'lonstatus'}},$key);
13720: }
13721: }
13722: }
1.28 raeburn 13723: }
1.203 raeburn 13724: foreach my $item (@toggles) {
13725: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
13726: $changes{$item} = 1;
13727: } elsif ((!$env{'form.'.$item}) &&
13728: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
13729: $changes{$item} = 1;
13730: }
13731: }
1.28 raeburn 13732: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
13733: $dom);
13734: if ($putresult eq 'ok') {
13735: if (keys(%changes) > 0) {
1.205 raeburn 13736: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13737: if (ref($lastactref) eq 'HASH') {
13738: $lastactref->{'domainconfig'} = 1;
13739: }
1.28 raeburn 13740: my ($titles,$short_titles) = &contact_titles();
13741: $resulttext = &mt('Changes made:').'<ul>';
13742: foreach my $item (@contacts) {
13743: if ($changes{$item}) {
13744: $resulttext .= '<li>'.$titles->{$item}.
13745: &mt(' set to: ').
13746: '<span class="LC_cusr_emph">'.
13747: $to{$item}.'</span></li>';
13748: }
13749: }
13750: foreach my $type (@mailings) {
13751: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 13752: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 13753: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 13754: } else {
13755: $resulttext .= '<li>'.$titles->{$type}.': ';
13756: }
1.28 raeburn 13757: my @text;
13758: foreach my $item (@{$newsetting{$type}}) {
13759: push(@text,$short_titles->{$item});
13760: }
13761: if ($others{$type} ne '') {
13762: push(@text,$others{$type});
13763: }
1.286 raeburn 13764: if (@text) {
13765: $resulttext .= '<span class="LC_cusr_emph">'.
13766: join(', ',@text).'</span>';
13767: }
13768: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13769: if ($bcc{$type} ne '') {
1.286 raeburn 13770: my $bcctext;
13771: if (@text) {
1.289 raeburn 13772: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 13773: } else {
13774: $bcctext = '(Bcc)';
13775: }
13776: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
13777: } elsif (!@text) {
13778: $resulttext .= &mt('No one');
13779: }
1.289 raeburn 13780: if ($includestr{$type} ne '') {
1.286 raeburn 13781: if ($includeloc{$type} eq 'b') {
13782: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
13783: } elsif ($includeloc{$type} eq 's') {
13784: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
13785: }
1.134 raeburn 13786: }
1.286 raeburn 13787: } elsif (!@text) {
13788: $resulttext .= &mt('No recipients');
1.134 raeburn 13789: }
13790: $resulttext .= '</li>';
1.28 raeburn 13791: }
13792: }
1.315 raeburn 13793: if (ref($changes{'overrides'}) eq 'ARRAY') {
13794: my @deletions;
13795: foreach my $type (@{$changes{'overrides'}}) {
13796: if ($usertypeshash{$type}) {
13797: if (grep(/^\Q$type\E/,@overrides)) {
13798: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
13799: $usertypeshash{$type}).'<ul><li>';
13800: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
13801: my @text;
13802: foreach my $item (@contacts) {
13803: if ($newsetting{'override_'.$type}{$item}) {
13804: push(@text,$short_titles->{$item});
13805: }
13806: }
13807: if ($newsetting{'override_'.$type}{'others'} ne '') {
13808: push(@text,$newsetting{'override_'.$type}{'others'});
13809: }
13810:
13811: if (@text) {
13812: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
13813: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
13814: }
13815: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
13816: my $bcctext;
13817: if (@text) {
13818: $bcctext = ' '.&mt('with Bcc to');
13819: } else {
13820: $bcctext = '(Bcc)';
13821: }
13822: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
13823: } elsif (!@text) {
13824: $resulttext .= &mt('Helpdesk e-mail sent to no one');
13825: }
13826: $resulttext .= '</li>';
13827: if ($newsetting{'override_'.$type}{'include'} ne '') {
13828: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
13829: if ($loc eq 'b') {
13830: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
13831: } elsif ($loc eq 's') {
13832: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
13833: }
13834: }
13835: }
13836: $resulttext .= '</li></ul></li>';
13837: } else {
13838: push(@deletions,$usertypeshash{$type});
13839: }
13840: }
13841: }
13842: if (@deletions) {
13843: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
13844: join(', ',@deletions)).'</li>';
13845: }
13846: }
1.203 raeburn 13847: my @offon = ('off','on');
1.340 raeburn 13848: my $corelink = &core_link_msu();
1.203 raeburn 13849: if ($changes{'reporterrors'}) {
13850: $resulttext .= '<li>'.
13851: &mt('E-mail error reports to [_1] set to "'.
13852: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 13853: $corelink).
1.203 raeburn 13854: '</li>';
13855: }
13856: if ($changes{'reportupdates'}) {
13857: $resulttext .= '<li>'.
13858: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
13859: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 13860: $corelink).
1.203 raeburn 13861: '</li>';
13862: }
1.340 raeburn 13863: if ($changes{'reportstatus'}) {
13864: $resulttext .= '<li>'.
13865: &mt('E-mail status if errors above threshold to [_1] set to "'.
13866: $offon[$env{'form.reportstatus'}].'".',
13867: $corelink).
13868: '</li>';
13869: }
13870: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
13871: $resulttext .= '<li>'.
13872: &mt('Nightly status check e-mail settings').':<ul>';
13873: my (%defval,%use_def,%shown);
13874: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
13875: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
13876: $defval{'weights'} =
1.341 raeburn 13877: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 13878: $defval{'excluded'} = &mt('None');
13879: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
13880: foreach my $item ('threshold','sysmail','weights','excluded') {
13881: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
13882: if (($item eq 'threshold') || ($item eq 'sysmail')) {
13883: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
13884: } elsif ($item eq 'weights') {
13885: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 13886: foreach my $type ('E','W','N','U') {
1.340 raeburn 13887: $shown{$item} .= $lonstatus_names->{$type}.'=';
13888: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
13889: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
13890: } else {
13891: $shown{$item} .= $lonstatus_defs->{$type};
13892: }
13893: $shown{$item} .= ', ';
13894: }
13895: $shown{$item} =~ s/, $//;
13896: } else {
13897: $shown{$item} = $defval{$item};
13898: }
13899: } elsif ($item eq 'excluded') {
13900: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
13901: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
13902: } else {
13903: $shown{$item} = $defval{$item};
13904: }
13905: }
13906: } else {
13907: $shown{$item} = $defval{$item};
13908: }
13909: }
13910: } else {
13911: foreach my $item ('threshold','weights','excluded','sysmail') {
13912: $shown{$item} = $defval{$item};
13913: }
13914: }
13915: foreach my $item ('threshold','weights','excluded','sysmail') {
13916: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
13917: $shown{$item}).'</li>';
13918: }
13919: $resulttext .= '</ul></li>';
13920: }
1.286 raeburn 13921: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
13922: my (@optional,@required,@unused,$maxsizechg);
13923: foreach my $field (@{$changes{'helpform'}}) {
13924: if ($field eq 'maxsize') {
13925: $maxsizechg = 1;
13926: next;
13927: }
13928: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 13929: push(@optional,$field);
1.286 raeburn 13930: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
13931: push(@unused,$field);
13932: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 13933: push(@required,$field);
1.286 raeburn 13934: }
13935: }
13936: if (@optional) {
13937: $resulttext .= '<li>'.
13938: &mt('Help form fields changed to "Optional": [_1].',
13939: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
13940: '</li>';
13941: }
13942: if (@required) {
13943: $resulttext .= '<li>'.
13944: &mt('Help form fields changed to "Required": [_1].',
13945: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
13946: '</li>';
13947: }
13948: if (@unused) {
13949: $resulttext .= '<li>'.
13950: &mt('Help form fields changed to "Not shown": [_1].',
13951: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
13952: '</li>';
13953: }
13954: if ($maxsizechg) {
13955: $resulttext .= '<li>'.
13956: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
13957: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
13958: '</li>';
13959: }
13960: }
1.28 raeburn 13961: $resulttext .= '</ul>';
13962: } else {
1.288 raeburn 13963: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 13964: }
13965: } else {
13966: $resulttext = '<span class="LC_error">'.
13967: &mt('An error occurred: [_1].',$putresult).'</span>';
13968: }
13969: return $resulttext;
13970: }
13971:
1.354 raeburn 13972: sub modify_passwords {
13973: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 13974: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
13975: $updatedefaults,$updateconf);
1.354 raeburn 13976: my $customfn = 'resetpw.html';
13977: if (ref($domconfig{'passwords'}) eq 'HASH') {
13978: %current = %{$domconfig{'passwords'}};
13979: }
13980: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13981: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13982: if (ref($types) eq 'ARRAY') {
13983: @oktypes = @{$types};
13984: }
13985: push(@oktypes,'default');
13986:
13987: my %titles = &Apache::lonlocal::texthash (
13988: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
13989: intauth_check => 'Check bcrypt cost if authenticated',
13990: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
13991: permanent => 'Permanent e-mail address',
13992: critical => 'Critical notification address',
13993: notify => 'Notification address',
13994: min => 'Minimum password length',
13995: max => 'Maximum password length',
13996: chars => 'Required characters',
13997: expire => 'Password expiration (days)',
1.356 ! raeburn 13998: numsaved => 'Number of previous passwords to save',
1.354 raeburn 13999: reset => 'Resetting Forgotten Password',
14000: intauth => 'Encryption of Stored Passwords (Internal Auth)',
14001: rules => 'Rules for LON-CAPA Passwords',
14002: crsownerchg => 'Course Owner Changing Student Passwords',
14003: username => 'Username',
14004: email => 'E-mail address',
14005: );
14006:
14007: #
14008: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
14009: #
14010: my (%curr_defaults,%save_defaults);
14011: if (ref($domconfig{'defaults'}) eq 'HASH') {
14012: foreach my $key (keys(%{$domconfig{'defaults'}})) {
14013: if ($key =~ /^intauth_(cost|check|switch)$/) {
14014: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
14015: } else {
14016: $save_defaults{$key} = $domconfig{'defaults'}{$key};
14017: }
14018: }
14019: }
14020: my %staticdefaults = (
14021: 'resetlink' => 2,
14022: 'resetcase' => \@oktypes,
14023: 'resetprelink' => 'both',
14024: 'resetemail' => ['critical','notify','permanent'],
14025: 'intauth_cost' => 10,
14026: 'intauth_check' => 0,
14027: 'intauth_switch' => 0,
14028: 'min' => 7,
14029: );
14030: foreach my $type (@oktypes) {
14031: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
14032: }
14033: my $linklife = $env{'form.passwords_link'};
14034: $linklife =~ s/^\s+|\s+$//g;
14035: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
14036: $newvalues{'resetlink'} = $linklife;
14037: if ($current{'resetlink'}) {
14038: if ($current{'resetlink'} ne $linklife) {
14039: $changes{'reset'} = 1;
14040: }
14041: } elsif (!exists($domconfig{passwords})) {
14042: if ($staticdefaults{'resetlink'} ne $linklife) {
14043: $changes{'reset'} = 1;
14044: }
14045: }
14046: } elsif ($current{'resetlink'}) {
14047: $changes{'reset'} = 1;
14048: }
14049: my @casesens;
14050: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
14051: foreach my $case (sort(@posscase)) {
14052: if (grep(/^\Q$case\E$/,@oktypes)) {
14053: push(@casesens,$case);
14054: }
14055: }
14056: $newvalues{'resetcase'} = \@casesens;
14057: if (ref($current{'resetcase'}) eq 'ARRAY') {
14058: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
14059: if (@diffs > 0) {
14060: $changes{'reset'} = 1;
14061: }
14062: } elsif (!exists($domconfig{passwords})) {
14063: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
14064: if (@diffs > 0) {
14065: $changes{'reset'} = 1;
14066: }
14067: }
14068: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
14069: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
14070: if (exists($current{'resetprelink'})) {
14071: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
14072: $changes{'reset'} = 1;
14073: }
14074: } elsif (!exists($domconfig{passwords})) {
14075: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
14076: $changes{'reset'} = 1;
14077: }
14078: }
14079: } elsif ($current{'resetprelink'}) {
14080: $changes{'reset'} = 1;
14081: }
14082: foreach my $type (@oktypes) {
14083: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
14084: my @postlink;
14085: foreach my $item (sort(@possplink)) {
14086: if ($item =~ /^(email|username)$/) {
14087: push(@postlink,$item);
14088: }
14089: }
14090: $newvalues{'resetpostlink'}{$type} = \@postlink;
14091: unless ($changes{'reset'}) {
14092: if (ref($current{'resetpostlink'}) eq 'HASH') {
14093: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
14094: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
14095: if (@diffs > 0) {
14096: $changes{'reset'} = 1;
14097: }
14098: } else {
14099: $changes{'reset'} = 1;
14100: }
14101: } elsif (!exists($domconfig{passwords})) {
14102: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
14103: if (@diffs > 0) {
14104: $changes{'reset'} = 1;
14105: }
14106: }
14107: }
14108: }
14109: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
14110: my @resetemail;
14111: foreach my $item (sort(@possemailsrc)) {
14112: if ($item =~ /^(permanent|critical|notify)$/) {
14113: push(@resetemail,$item);
14114: }
14115: }
14116: $newvalues{'resetemail'} = \@resetemail;
14117: unless ($changes{'reset'}) {
14118: if (ref($current{'resetemail'}) eq 'ARRAY') {
14119: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
14120: if (@diffs > 0) {
14121: $changes{'reset'} = 1;
14122: }
14123: } elsif (!exists($domconfig{passwords})) {
14124: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
14125: if (@diffs > 0) {
14126: $changes{'reset'} = 1;
14127: }
14128: }
14129: }
14130: if ($env{'form.passwords_stdtext'} == 0) {
14131: $newvalues{'resetremove'} = 1;
14132: unless ($current{'resetremove'}) {
14133: $changes{'reset'} = 1;
14134: }
14135: } elsif ($current{'resetremove'}) {
14136: $changes{'reset'} = 1;
14137: }
14138: if ($env{'form.passwords_customfile.filename'} ne '') {
14139: my $servadm = $r->dir_config('lonAdmEMail');
14140: my ($configuserok,$author_ok,$switchserver) =
14141: &config_check($dom,$confname,$servadm);
14142: my $error;
14143: if ($configuserok eq 'ok') {
14144: if ($switchserver) {
14145: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
14146: } else {
14147: if ($author_ok eq 'ok') {
14148: my ($result,$customurl) =
14149: &publishlogo($r,'upload','passwords_customfile',$dom,
14150: $confname,'customtext/resetpw','','',$customfn);
14151: if ($result eq 'ok') {
14152: $newvalues{'resetcustom'} = $customurl;
14153: $changes{'reset'} = 1;
14154: } else {
14155: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
14156: }
14157: } else {
14158: $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);
14159: }
14160: }
14161: } else {
14162: $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);
14163: }
14164: if ($error) {
14165: &Apache::lonnet::logthis($error);
14166: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14167: }
14168: } elsif ($current{'resetcustom'}) {
14169: if ($env{'form.passwords_custom_del'}) {
14170: $changes{'reset'} = 1;
14171: } else {
14172: $newvalues{'resetcustom'} = $current{'resetcustom'};
14173: }
14174: }
14175: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
14176: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
14177: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
14178: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
14179: $changes{'intauth'} = 1;
14180: }
14181: } else {
14182: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
14183: }
14184: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
14185: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
14186: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
14187: $changes{'intauth'} = 1;
14188: }
14189: } else {
14190: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
14191: }
14192: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
14193: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
14194: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
14195: $changes{'intauth'} = 1;
14196: }
14197: } else {
14198: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
14199: }
14200: foreach my $item ('cost','check','switch') {
14201: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
14202: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
14203: $updatedefaults = 1;
14204: }
14205: }
1.356 ! raeburn 14206: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 14207: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.356 ! raeburn 14208: my $ruleok;
! 14209: if ($rule eq 'expire') {
! 14210: if ($env{'form.passwords_'.$rule} =~ /^\d+(|\.\d*)$/) {
! 14211: $ruleok = 1;
! 14212: }
! 14213: } elsif ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
! 14214: $ruleok = 1;
! 14215: }
! 14216: if ($ruleok) {
1.354 raeburn 14217: $newvalues{$rule} = $env{'form.passwords_'.$rule};
14218: if (exists($current{$rule})) {
14219: if ($newvalues{$rule} ne $current{$rule}) {
14220: $changes{'rules'} = 1;
14221: }
14222: } elsif ($rule eq 'min') {
14223: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
14224: $changes{'rules'} = 1;
14225: }
14226: }
14227: } elsif (exists($current{$rule})) {
14228: $changes{'rules'} = 1;
14229: }
14230: }
14231: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
14232: my @chars;
14233: foreach my $item (sort(@posschars)) {
14234: if ($item =~ /^(uc|lc|num|spec)$/) {
14235: push(@chars,$item);
14236: }
14237: }
14238: $newvalues{'chars'} = \@chars;
14239: unless ($changes{'rules'}) {
14240: if (ref($current{'chars'}) eq 'ARRAY') {
14241: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
14242: if (@diffs > 0) {
14243: $changes{'rules'} = 1;
14244: }
14245: } else {
14246: if (@chars > 0) {
14247: $changes{'rules'} = 1;
14248: }
14249: }
14250: }
14251: if ($env{'form.passwords_crsowner'}) {
14252: $newvalues{'crsownerchg'} = 1;
14253: unless ($current{'crsownerchg'}) {
14254: $changes{'crsownerchg'} = 1;
14255: }
14256: } elsif ($current{'crsownerchg'}) {
14257: $changes{'crsownerchg'} = 1;
14258: }
14259:
14260: my %confighash = (
14261: defaults => \%save_defaults,
14262: passwords => \%newvalues,
14263: );
14264: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
14265:
14266: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
14267: if ($putresult eq 'ok') {
14268: if (keys(%changes) > 0) {
14269: $resulttext = &mt('Changes made: ').'<ul>';
14270: foreach my $key ('reset','intauth','rules','crsownerchg') {
14271: if ($changes{$key}) {
1.355 raeburn 14272: unless ($key eq 'intauth') {
14273: $updateconf = 1;
14274: }
1.354 raeburn 14275: $resulttext .= '<li>'.$titles{$key}.':<ul>';
14276: if ($key eq 'reset') {
14277: if ($confighash{'passwords'}{'captcha'} eq 'original') {
14278: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
14279: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
14280: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
14281: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />'.
14282: &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchapub'}).'</br>'.
14283: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchapriv'}).'</li>';
14284: } else {
14285: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
14286: }
14287: if ($confighash{'passwords'}{'resetlink'}) {
14288: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
14289: } else {
14290: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
14291: &mt('Will default to 2 hours').'</li>';
14292: }
14293: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
14294: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
14295: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
14296: } else {
14297: my $casesens;
14298: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
14299: if ($type eq 'default') {
14300: $casesens .= $othertitle.', ';
14301: } elsif ($usertypes->{$type} ne '') {
14302: $casesens .= $usertypes->{$type}.', ';
14303: }
14304: }
14305: $casesens =~ s/\Q, \E$//;
14306: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
14307: }
14308: } else {
14309: $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>';
14310: }
14311: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
14312: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
14313: } else {
14314: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
14315: }
14316: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
14317: my $output;
14318: if (ref($types) eq 'ARRAY') {
14319: foreach my $type (@{$types}) {
14320: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
14321: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
14322: $output .= $usertypes->{$type}.' -- '.&mt('none');
14323: } else {
14324: $output .= $usertypes->{$type}.' -- '.
14325: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
14326: }
14327: }
14328: }
14329: }
14330: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
14331: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
14332: $output .= $othertitle.' -- '.&mt('none');
14333: } else {
14334: $output .= $othertitle.' -- '.
14335: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
14336: }
14337: }
14338: if ($output) {
14339: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
14340: } else {
14341: $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>';
14342: }
14343: } else {
14344: $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>';
14345: }
14346: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
14347: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
14348: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
14349: } else {
14350: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
14351: }
14352: } else {
14353: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA usedfor verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
14354: }
14355: if ($confighash{'passwords'}{'resetremove'}) {
14356: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
14357: } else {
14358: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
14359: }
14360: if ($confighash{'passwords'}{'resetcustom'}) {
14361: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
14362: $titles{custom},600,500);
14363: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes [_1]',$customlink).'</li>';
14364: } else {
14365: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
14366: }
14367: } elsif ($key eq 'intauth') {
14368: foreach my $item ('cost','switch','check') {
14369: my $value = $save_defaults{$key.'_'.$item};
14370: if ($item eq 'switch') {
14371: my %optiondesc = &Apache::lonlocal::texthash (
14372: 0 => 'No',
14373: 1 => 'Yes',
14374: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
14375: );
14376: if ($value =~ /^(0|1|2)$/) {
14377: $value = $optiondesc{$value};
14378: } else {
14379: $value = &mt('none -- defaults to No');
14380: }
14381: } elsif ($item eq 'check') {
14382: my %optiondesc = &Apache::lonlocal::texthash (
14383: 0 => 'No',
14384: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
14385: 2 => 'Yes, disallow login if stored cost is less than domain default',
14386: );
14387: if ($value =~ /^(0|1|2)$/) {
14388: $value = $optiondesc{$value};
14389: } else {
14390: $value = &mt('none -- defaults to No');
14391: }
14392: }
14393: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
14394: }
14395: } elsif ($key eq 'rules') {
1.356 ! raeburn 14396: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 14397: if ($confighash{'passwords'}{$rule} eq '') {
14398: if ($rule eq 'min') {
1.356 ! raeburn 14399: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
! 14400: ' '.&mt('Default of 7 will be used').'</li>';
! 14401: } else {
! 14402: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 14403: }
14404: } else {
14405: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
14406: }
14407: }
14408: } elsif ($key eq 'crsownerchg') {
14409: if ($confighash{'passwords'}{'crsownerchg'}) {
14410: $resulttext .= '<li>'.&mt('Course owner may change student passwords.').'</li>';
14411: } else {
14412: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.');
14413: }
14414: }
14415: $resulttext .= '</ul></li>';
14416: }
14417: }
14418: $resulttext .= '</ul>';
14419: } else {
14420: $resulttext = &mt('No changes made to password settings');
14421: }
1.355 raeburn 14422: my $cachetime = 24*60*60;
1.354 raeburn 14423: if ($updatedefaults) {
14424: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14425: if (ref($lastactref) eq 'HASH') {
14426: $lastactref->{'domdefaults'} = 1;
14427: }
14428: }
1.355 raeburn 14429: if ($updateconf) {
14430: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
14431: if (ref($lastactref) eq 'HASH') {
14432: $lastactref->{'passwdconf'} = 1;
14433: }
14434: }
1.354 raeburn 14435: } else {
14436: $resulttext = '<span class="LC_error">'.
14437: &mt('An error occurred: [_1]',$putresult).'</span>';
14438: }
14439: if ($errors) {
14440: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
14441: $errors.'</ul></p>';
14442: }
14443: return $resulttext;
14444: }
14445:
1.28 raeburn 14446: sub modify_usercreation {
1.27 raeburn 14447: my ($dom,%domconfig) = @_;
1.224 raeburn 14448: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 14449: my $warningmsg;
1.27 raeburn 14450: if (ref($domconfig{'usercreation'}) eq 'HASH') {
14451: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 14452: if ($key eq 'cancreate') {
14453: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
14454: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 14455: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
14456: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
14457: } else {
1.224 raeburn 14458: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
14459: }
14460: }
14461: }
14462: } elsif ($key eq 'email_rule') {
14463: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
14464: } else {
14465: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
14466: }
1.27 raeburn 14467: }
14468: }
14469: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 14470: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 14471: my @contexts = ('author','course','requestcrs');
1.34 raeburn 14472: foreach my $item(@contexts) {
1.224 raeburn 14473: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 14474: }
1.34 raeburn 14475: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
14476: foreach my $item (@contexts) {
1.224 raeburn 14477: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
14478: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 14479: }
1.27 raeburn 14480: }
1.34 raeburn 14481: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
14482: foreach my $item (@contexts) {
1.43 raeburn 14483: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 14484: if ($cancreate{$item} ne 'any') {
14485: push(@{$changes{'cancreate'}},$item);
14486: }
14487: } else {
14488: if ($cancreate{$item} ne 'none') {
14489: push(@{$changes{'cancreate'}},$item);
14490: }
1.27 raeburn 14491: }
14492: }
14493: } else {
1.43 raeburn 14494: foreach my $item (@contexts) {
1.34 raeburn 14495: push(@{$changes{'cancreate'}},$item);
14496: }
1.27 raeburn 14497: }
1.34 raeburn 14498:
1.27 raeburn 14499: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
14500: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
14501: if (!grep(/^\Q$type\E$/,@username_rule)) {
14502: push(@{$changes{'username_rule'}},$type);
14503: }
14504: }
14505: foreach my $type (@username_rule) {
14506: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
14507: push(@{$changes{'username_rule'}},$type);
14508: }
14509: }
14510: } else {
14511: push(@{$changes{'username_rule'}},@username_rule);
14512: }
14513:
1.32 raeburn 14514: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
14515: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
14516: if (!grep(/^\Q$type\E$/,@id_rule)) {
14517: push(@{$changes{'id_rule'}},$type);
14518: }
14519: }
14520: foreach my $type (@id_rule) {
14521: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
14522: push(@{$changes{'id_rule'}},$type);
14523: }
14524: }
14525: } else {
14526: push(@{$changes{'id_rule'}},@id_rule);
14527: }
14528:
1.43 raeburn 14529: my @authen_contexts = ('author','course','domain');
1.325 raeburn 14530: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 14531: my %authhash;
1.43 raeburn 14532: foreach my $item (@authen_contexts) {
1.28 raeburn 14533: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
14534: foreach my $auth (@authtypes) {
14535: if (grep(/^\Q$auth\E$/,@authallowed)) {
14536: $authhash{$item}{$auth} = 1;
14537: } else {
14538: $authhash{$item}{$auth} = 0;
14539: }
14540: }
14541: }
14542: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 14543: foreach my $item (@authen_contexts) {
1.28 raeburn 14544: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
14545: foreach my $auth (@authtypes) {
14546: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
14547: push(@{$changes{'authtypes'}},$item);
14548: last;
14549: }
14550: }
14551: }
14552: }
14553: } else {
1.43 raeburn 14554: foreach my $item (@authen_contexts) {
1.28 raeburn 14555: push(@{$changes{'authtypes'}},$item);
14556: }
14557: }
14558:
1.224 raeburn 14559: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
14560: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
14561: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
14562: $save_usercreate{'id_rule'} = \@id_rule;
14563: $save_usercreate{'username_rule'} = \@username_rule,
14564: $save_usercreate{'authtypes'} = \%authhash;
14565:
1.27 raeburn 14566: my %usercreation_hash = (
1.224 raeburn 14567: usercreation => \%save_usercreate,
14568: );
1.27 raeburn 14569:
14570: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
14571: $dom);
1.50 raeburn 14572:
1.224 raeburn 14573: if ($putresult eq 'ok') {
14574: if (keys(%changes) > 0) {
14575: $resulttext = &mt('Changes made:').'<ul>';
14576: if (ref($changes{'cancreate'}) eq 'ARRAY') {
14577: my %lt = &usercreation_types();
14578: foreach my $type (@{$changes{'cancreate'}}) {
14579: my $chgtext = $lt{$type}.', ';
14580: if ($cancreate{$type} eq 'none') {
14581: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
14582: } elsif ($cancreate{$type} eq 'any') {
14583: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
14584: } elsif ($cancreate{$type} eq 'official') {
14585: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
14586: } elsif ($cancreate{$type} eq 'unofficial') {
14587: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
14588: }
14589: $resulttext .= '<li>'.$chgtext.'</li>';
14590: }
14591: }
14592: if (ref($changes{'username_rule'}) eq 'ARRAY') {
14593: my ($rules,$ruleorder) =
14594: &Apache::lonnet::inst_userrules($dom,'username');
14595: my $chgtext = '<ul>';
14596: foreach my $type (@username_rule) {
14597: if (ref($rules->{$type}) eq 'HASH') {
14598: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
14599: }
14600: }
14601: $chgtext .= '</ul>';
14602: if (@username_rule > 0) {
14603: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
14604: } else {
14605: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
14606: }
14607: }
14608: if (ref($changes{'id_rule'}) eq 'ARRAY') {
14609: my ($idrules,$idruleorder) =
14610: &Apache::lonnet::inst_userrules($dom,'id');
14611: my $chgtext = '<ul>';
14612: foreach my $type (@id_rule) {
14613: if (ref($idrules->{$type}) eq 'HASH') {
14614: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
14615: }
14616: }
14617: $chgtext .= '</ul>';
14618: if (@id_rule > 0) {
14619: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
14620: } else {
14621: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
14622: }
14623: }
14624: my %authname = &authtype_names();
14625: my %context_title = &context_names();
14626: if (ref($changes{'authtypes'}) eq 'ARRAY') {
14627: my $chgtext = '<ul>';
14628: foreach my $type (@{$changes{'authtypes'}}) {
14629: my @allowed;
14630: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
14631: foreach my $auth (@authtypes) {
14632: if ($authhash{$type}{$auth}) {
14633: push(@allowed,$authname{$auth});
14634: }
14635: }
14636: if (@allowed > 0) {
14637: $chgtext .= join(', ',@allowed).'</li>';
14638: } else {
14639: $chgtext .= &mt('none').'</li>';
14640: }
14641: }
14642: $chgtext .= '</ul>';
14643: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
14644: $resulttext .= '</li>';
14645: }
14646: $resulttext .= '</ul>';
14647: } else {
14648: $resulttext = &mt('No changes made to user creation settings');
14649: }
14650: } else {
14651: $resulttext = '<span class="LC_error">'.
14652: &mt('An error occurred: [_1]',$putresult).'</span>';
14653: }
14654: if ($warningmsg ne '') {
14655: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
14656: }
14657: return $resulttext;
14658: }
14659:
14660: sub modify_selfcreation {
1.305 raeburn 14661: my ($dom,$lastactref,%domconfig) = @_;
14662: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
14663: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
14664: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 14665: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
14666: if (ref($typesref) eq 'ARRAY') {
14667: @types = @{$typesref};
14668: }
14669: if (ref($usertypesref) eq 'HASH') {
14670: %usertypes = %{$usertypesref};
1.228 raeburn 14671: }
1.303 raeburn 14672: $usertypes{'default'} = $othertitle;
1.224 raeburn 14673: #
14674: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
14675: #
14676: if (ref($domconfig{'usercreation'}) eq 'HASH') {
14677: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
14678: if ($key eq 'cancreate') {
14679: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
14680: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
14681: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 14682: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
14683: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
14684: ($item eq 'emailusername') || ($item eq 'shibenv') ||
14685: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 14686: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 14687: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
14688: } else {
14689: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
14690: }
14691: }
14692: }
14693: } elsif ($key eq 'email_rule') {
14694: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
14695: } else {
14696: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
14697: }
14698: }
14699: }
14700: #
14701: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
14702: #
14703: if (ref($domconfig{'usermodification'}) eq 'HASH') {
14704: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
14705: if ($key eq 'selfcreate') {
14706: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
14707: } else {
14708: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
14709: }
14710: }
14711: }
1.305 raeburn 14712: #
14713: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
14714: #
14715: if (ref($domconfig{'inststatus'}) eq 'HASH') {
14716: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
14717: if ($key eq 'inststatusguest') {
14718: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
14719: } else {
14720: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
14721: }
14722: }
14723: }
1.224 raeburn 14724:
14725: my @contexts = ('selfcreate');
14726: @{$cancreate{'selfcreate'}} = ();
14727: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 14728: if (@types) {
14729: @{$cancreate{'statustocreate'}} = ();
14730: }
1.236 raeburn 14731: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 14732: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 14733: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 14734: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 14735: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 14736: my %selfcreatetypes = (
14737: sso => 'users authenticated by institutional single sign on',
14738: login => 'users authenticated by institutional log-in',
1.303 raeburn 14739: email => 'users verified by e-mail',
1.50 raeburn 14740: );
1.224 raeburn 14741: #
14742: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
14743: # is permitted.
14744: #
1.305 raeburn 14745: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 14746:
1.305 raeburn 14747: my (@statuses,%email_rule);
1.228 raeburn 14748: foreach my $item ('login','sso','email') {
1.224 raeburn 14749: if ($item eq 'email') {
1.236 raeburn 14750: if ($env{'form.cancreate_email'}) {
1.305 raeburn 14751: if (@types) {
14752: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
14753: foreach my $status (@poss_statuses) {
14754: if (grep(/^\Q$status\E$/,(@types,'default'))) {
14755: push(@statuses,$status);
14756: }
14757: }
14758: $save_inststatus{'inststatusguest'} = \@statuses;
14759: } else {
14760: push(@statuses,'default');
14761: }
14762: if (@statuses) {
14763: my %curr_rule;
14764: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
14765: foreach my $type (@statuses) {
14766: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 14767: }
1.305 raeburn 14768: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
14769: foreach my $type (@statuses) {
14770: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
14771: }
14772: }
14773: push(@{$cancreate{'selfcreate'}},'email');
14774: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
14775: my %curremaildom;
14776: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
14777: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
14778: }
14779: foreach my $type (@statuses) {
14780: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
14781: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
14782: }
14783: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
14784: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
14785: }
14786: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
14787: #
14788: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
14789: #
14790: my $chosen = $1;
14791: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
14792: my $emaildom;
14793: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
14794: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
14795: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
14796: if (ref($curremaildom{$type}) eq 'HASH') {
14797: if (exists($curremaildom{$type}{$chosen})) {
14798: if ($curremaildom{$type}{$chosen} ne $emaildom) {
14799: push(@{$changes{'cancreate'}},'emaildomain');
14800: }
14801: } elsif ($emaildom ne '') {
14802: push(@{$changes{'cancreate'}},'emaildomain');
14803: }
14804: } elsif ($emaildom ne '') {
14805: push(@{$changes{'cancreate'}},'emaildomain');
14806: }
14807: }
14808: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
14809: } elsif ($chosen eq 'custom') {
14810: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
14811: $email_rule{$type} = [];
14812: if (ref($emailrules) eq 'HASH') {
14813: foreach my $rule (@possemail_rules) {
14814: if (exists($emailrules->{$rule})) {
14815: push(@{$email_rule{$type}},$rule);
14816: }
14817: }
14818: }
14819: if (@{$email_rule{$type}}) {
14820: $cancreate{'emailoptions'}{$type} = 'custom';
14821: if (ref($curr_rule{$type}) eq 'ARRAY') {
14822: if (@{$curr_rule{$type}} > 0) {
14823: foreach my $rule (@{$curr_rule{$type}}) {
14824: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
14825: push(@{$changes{'email_rule'}},$type);
14826: }
14827: }
14828: }
14829: foreach my $type (@{$email_rule{$type}}) {
14830: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
14831: push(@{$changes{'email_rule'}},$type);
14832: }
14833: }
14834: } else {
14835: push(@{$changes{'email_rule'}},$type);
14836: }
14837: }
14838: } else {
14839: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
14840: }
14841: }
14842: }
14843: if (@types) {
14844: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
14845: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
14846: if (@changed) {
14847: push(@{$changes{'inststatus'}},'inststatusguest');
14848: }
14849: } else {
14850: push(@{$changes{'inststatus'}},'inststatusguest');
14851: }
14852: }
14853: } else {
14854: delete($env{'form.cancreate_email'});
14855: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
14856: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
14857: push(@{$changes{'inststatus'}},'inststatusguest');
14858: }
14859: }
14860: }
14861: } else {
14862: $save_inststatus{'inststatusguest'} = [];
14863: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
14864: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
14865: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 14866: }
14867: }
1.224 raeburn 14868: }
14869: } else {
14870: if ($env{'form.cancreate_'.$item}) {
14871: push(@{$cancreate{'selfcreate'}},$item);
14872: }
14873: }
14874: }
1.305 raeburn 14875: my (%userinfo,%savecaptcha);
1.224 raeburn 14876: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
14877: #
1.228 raeburn 14878: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
14879: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 14880: #
1.236 raeburn 14881:
1.244 raeburn 14882: if ($env{'form.cancreate_email'}) {
1.228 raeburn 14883: push(@contexts,'emailusername');
1.305 raeburn 14884: if (@statuses) {
14885: foreach my $type (@statuses) {
1.228 raeburn 14886: if (ref($infofields) eq 'ARRAY') {
14887: foreach my $field (@{$infofields}) {
14888: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
14889: $cancreate{'emailusername'}{$type}{$field} = $1;
14890: }
14891: }
1.224 raeburn 14892: }
14893: }
14894: }
14895: #
14896: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 14897: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 14898: #
14899:
14900: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
14901: @approvalnotify = sort(@approvalnotify);
14902: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
14903: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
14904: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
14905: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
14906: push(@{$changes{'cancreate'}},'notify');
14907: }
14908: } else {
14909: if ($cancreate{'notify'}{'approval'}) {
14910: push(@{$changes{'cancreate'}},'notify');
14911: }
14912: }
14913: } elsif ($cancreate{'notify'}{'approval'}) {
14914: push(@{$changes{'cancreate'}},'notify');
14915: }
14916:
14917: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
14918: }
14919: #
1.236 raeburn 14920: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 14921: # institutional log-in.
14922: #
14923: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
14924: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
14925: ($domdefaults{'auth_def'} eq 'localauth'))) {
14926: $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.').' '.
14927: &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.');
14928: }
14929: }
14930: my @fields = ('lastname','firstname','middlename','generation',
14931: 'permanentemail','id');
1.240 raeburn 14932: my @shibfields = (@fields,'inststatus');
1.224 raeburn 14933: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14934: #
14935: # Where usernames may created for institutional log-in and/or institutional single sign on:
14936: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
14937: # may self-create accounts
14938: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
14939: # which the user may supply, if institutional data is unavailable.
14940: #
14941: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 14942: if (@types) {
1.305 raeburn 14943: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
14944: push(@contexts,'statustocreate');
1.303 raeburn 14945: foreach my $type (@types) {
1.224 raeburn 14946: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
14947: foreach my $field (@fields) {
14948: if (grep(/^\Q$field\E$/,@modifiable)) {
14949: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
14950: } else {
14951: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
14952: }
14953: }
14954: }
14955: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 14956: foreach my $type (@types) {
1.224 raeburn 14957: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
14958: foreach my $field (@fields) {
14959: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
14960: $curr_usermodify{'selfcreate'}{$type}{$field}) {
14961: push(@{$changes{'selfcreate'}},$type);
14962: last;
14963: }
14964: }
14965: }
14966: }
14967: } else {
1.303 raeburn 14968: foreach my $type (@types) {
1.224 raeburn 14969: push(@{$changes{'selfcreate'}},$type);
14970: }
14971: }
14972: }
1.240 raeburn 14973: foreach my $field (@shibfields) {
14974: if ($env{'form.shibenv_'.$field} ne '') {
14975: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
14976: }
14977: }
14978: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
14979: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
14980: foreach my $field (@shibfields) {
14981: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
14982: push(@{$changes{'cancreate'}},'shibenv');
14983: }
14984: }
14985: } else {
14986: foreach my $field (@shibfields) {
14987: if ($env{'form.shibenv_'.$field}) {
14988: push(@{$changes{'cancreate'}},'shibenv');
14989: last;
14990: }
14991: }
14992: }
14993: }
1.224 raeburn 14994: }
14995: foreach my $item (@contexts) {
14996: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
14997: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
14998: if (ref($cancreate{$item}) eq 'ARRAY') {
14999: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
15000: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15001: push(@{$changes{'cancreate'}},$item);
15002: }
15003: }
15004: }
15005: }
15006: if (ref($cancreate{$item}) eq 'ARRAY') {
15007: foreach my $type (@{$cancreate{$item}}) {
15008: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
15009: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15010: push(@{$changes{'cancreate'}},$item);
15011: }
15012: }
15013: }
15014: }
15015: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
15016: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 15017: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
15018: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
15019: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
15020: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 15021: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15022: push(@{$changes{'cancreate'}},$item);
15023: }
15024: }
15025: }
1.305 raeburn 15026: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
15027: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 15028: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15029: push(@{$changes{'cancreate'}},$item);
15030: }
1.224 raeburn 15031: }
15032: }
15033: }
1.305 raeburn 15034: foreach my $type (keys(%{$cancreate{$item}})) {
15035: if (ref($cancreate{$item}{$type}) eq 'HASH') {
15036: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
15037: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
15038: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 15039: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15040: push(@{$changes{'cancreate'}},$item);
15041: }
15042: }
15043: } else {
15044: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15045: push(@{$changes{'cancreate'}},$item);
15046: }
15047: }
15048: }
1.305 raeburn 15049: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
15050: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 15051: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15052: push(@{$changes{'cancreate'}},$item);
15053: }
1.224 raeburn 15054: }
15055: }
15056: }
15057: }
15058: } elsif ($curr_usercreation{'cancreate'}{$item}) {
15059: if (ref($cancreate{$item}) eq 'ARRAY') {
15060: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
15061: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15062: push(@{$changes{'cancreate'}},$item);
15063: }
15064: }
1.305 raeburn 15065: }
15066: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
15067: if (ref($cancreate{$item}) eq 'HASH') {
15068: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15069: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 15070: }
15071: }
15072: } elsif ($item eq 'emailusername') {
1.228 raeburn 15073: if (ref($cancreate{$item}) eq 'HASH') {
15074: foreach my $type (keys(%{$cancreate{$item}})) {
15075: if (ref($cancreate{$item}{$type}) eq 'HASH') {
15076: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
15077: if ($cancreate{$item}{$type}{$field}) {
15078: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15079: push(@{$changes{'cancreate'}},$item);
15080: }
15081: last;
15082: }
15083: }
15084: }
15085: }
1.224 raeburn 15086: }
15087: }
15088: }
15089: #
15090: # Populate %save_usercreate hash with updates to self-creation configuration.
15091: #
15092: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
15093: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 15094: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 15095: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
15096: if (ref($cancreate{'notify'}) eq 'HASH') {
15097: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
15098: }
1.236 raeburn 15099: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
15100: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
15101: }
1.303 raeburn 15102: if (ref($cancreate{'emailverified'}) eq 'HASH') {
15103: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
15104: }
1.305 raeburn 15105: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
15106: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
15107: }
1.303 raeburn 15108: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
15109: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
15110: }
1.224 raeburn 15111: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
15112: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
15113: }
1.240 raeburn 15114: if (ref($cancreate{'shibenv'}) eq 'HASH') {
15115: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
15116: }
1.224 raeburn 15117: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 15118: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 15119:
15120: my %userconfig_hash = (
15121: usercreation => \%save_usercreate,
15122: usermodification => \%save_usermodify,
1.305 raeburn 15123: inststatus => \%save_inststatus,
1.224 raeburn 15124: );
1.305 raeburn 15125:
1.224 raeburn 15126: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
15127: $dom);
15128: #
1.305 raeburn 15129: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 15130: #
1.27 raeburn 15131: if ($putresult eq 'ok') {
15132: if (keys(%changes) > 0) {
15133: $resulttext = &mt('Changes made:').'<ul>';
15134: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 15135: my %lt = &selfcreation_types();
1.34 raeburn 15136: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 15137: my $chgtext = '';
1.45 raeburn 15138: if ($type eq 'selfcreate') {
1.50 raeburn 15139: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 15140: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 15141: } else {
1.224 raeburn 15142: $chgtext .= &mt('Self-creation of a new account is permitted for:').
15143: '<ul>';
1.50 raeburn 15144: foreach my $case (@{$cancreate{$type}}) {
15145: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
15146: }
15147: $chgtext .= '</ul>';
1.100 raeburn 15148: if (ref($cancreate{$type}) eq 'ARRAY') {
15149: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
15150: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
15151: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 15152: $chgtext .= '<span class="LC_warning">'.
15153: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
15154: '</span><br />';
15155: }
15156: }
15157: }
15158: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 15159: if (!@statuses) {
15160: $chgtext .= '<span class="LC_warning">'.
15161: &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.").
15162: '</span><br />';
1.303 raeburn 15163:
1.100 raeburn 15164: }
15165: }
15166: }
1.43 raeburn 15167: }
1.240 raeburn 15168: } elsif ($type eq 'shibenv') {
15169: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 15170: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 15171: } else {
15172: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
15173: '<ul>';
15174: foreach my $field (@shibfields) {
15175: next if ($cancreate{$type}{$field} eq '');
15176: if ($field eq 'inststatus') {
15177: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
15178: } else {
15179: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
15180: }
15181: }
15182: $chgtext .= '</ul>';
1.303 raeburn 15183: }
1.93 raeburn 15184: } elsif ($type eq 'statustocreate') {
1.96 raeburn 15185: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
15186: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
15187: if (@{$cancreate{'selfcreate'}} > 0) {
15188: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 15189: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 15190: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 15191: $chgtext .= '<br />'.
15192: '<span class="LC_warning">'.
15193: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
15194: '</span>';
15195: }
1.303 raeburn 15196: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 15197: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 15198: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
15199: } else {
15200: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
15201: }
15202: $chgtext .= '<ul>';
15203: foreach my $case (@{$cancreate{$type}}) {
15204: if ($case eq 'default') {
15205: $chgtext .= '<li>'.$othertitle.'</li>';
15206: } else {
1.303 raeburn 15207: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 15208: }
15209: }
1.100 raeburn 15210: $chgtext .= '</ul>';
15211: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 15212: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 15213: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
15214: '</span>';
1.100 raeburn 15215: }
15216: }
15217: } else {
15218: if (@{$cancreate{$type}} == 0) {
15219: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
15220: } else {
15221: $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 15222: }
15223: }
1.303 raeburn 15224: $chgtext .= '<br />';
1.93 raeburn 15225: }
1.236 raeburn 15226: } elsif ($type eq 'selfcreateprocessing') {
15227: my %choices = &Apache::lonlocal::texthash (
15228: automatic => 'Automatic approval',
15229: approval => 'Queued for approval',
15230: );
1.305 raeburn 15231: if (@types) {
15232: if (@statuses) {
1.303 raeburn 15233: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 15234: '<ul>';
1.305 raeburn 15235: foreach my $status (@statuses) {
15236: if ($status eq 'default') {
15237: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 15238: } else {
1.305 raeburn 15239: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 15240: }
15241: }
15242: $chgtext .= '</ul>';
15243: }
15244: } else {
15245: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
15246: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
15247: }
15248: } elsif ($type eq 'emailverified') {
15249: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 15250: all => 'Same as e-mail',
15251: first => 'Omit @domain',
15252: free => 'Free to choose',
1.303 raeburn 15253: );
1.305 raeburn 15254: if (@types) {
15255: if (@statuses) {
1.303 raeburn 15256: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
15257: '<ul>';
1.305 raeburn 15258: foreach my $status (@statuses) {
1.303 raeburn 15259: if ($type eq 'default') {
1.305 raeburn 15260: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 15261: } else {
1.305 raeburn 15262: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 15263: }
15264: }
15265: $chgtext .= '</ul>';
15266: }
15267: } else {
1.305 raeburn 15268: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 15269: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 15270: }
1.305 raeburn 15271: } elsif ($type eq 'emailoptions') {
15272: my %options = &Apache::lonlocal::texthash (
15273: any => 'Any e-mail',
15274: inst => 'Institutional only',
15275: noninst => 'Non-institutional only',
15276: custom => 'Custom restrictions',
15277: );
15278: if (@types) {
15279: if (@statuses) {
15280: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
15281: '<ul>';
15282: foreach my $status (@statuses) {
15283: if ($type eq 'default') {
15284: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
15285: } else {
15286: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 15287: }
15288: }
1.305 raeburn 15289: $chgtext .= '</ul>';
15290: }
15291: } else {
15292: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
15293: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
15294: } else {
15295: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
15296: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 15297: }
1.305 raeburn 15298: }
15299: } elsif ($type eq 'emaildomain') {
15300: my $output;
15301: if (@statuses) {
15302: foreach my $type (@statuses) {
15303: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
15304: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
15305: if ($type eq 'default') {
15306: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15307: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
15308: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
15309: } else {
15310: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
15311: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
15312: }
1.303 raeburn 15313: } else {
1.305 raeburn 15314: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15315: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
15316: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
15317: } else {
15318: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
15319: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
15320: }
1.303 raeburn 15321: }
1.305 raeburn 15322: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
15323: if ($type eq 'default') {
15324: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15325: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
15326: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
15327: } else {
15328: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
15329: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
15330: }
1.303 raeburn 15331: } else {
1.305 raeburn 15332: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15333: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
15334: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
15335: } else {
15336: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
15337: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
15338: }
1.303 raeburn 15339: }
15340: }
15341: }
15342: }
1.305 raeburn 15343: }
15344: if ($output ne '') {
15345: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
15346: '<ul>'.$output.'</ul>';
1.236 raeburn 15347: }
1.165 raeburn 15348: } elsif ($type eq 'captcha') {
1.224 raeburn 15349: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 15350: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
15351: } else {
15352: my %captchas = &captcha_phrases();
1.224 raeburn 15353: if ($captchas{$savecaptcha{$type}}) {
15354: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 15355: } else {
1.210 raeburn 15356: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 15357: }
15358: }
15359: } elsif ($type eq 'recaptchakeys') {
15360: my ($privkey,$pubkey);
1.224 raeburn 15361: if (ref($savecaptcha{$type}) eq 'HASH') {
15362: $pubkey = $savecaptcha{$type}{'public'};
15363: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 15364: }
15365: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
15366: if (!$pubkey) {
15367: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
15368: } else {
15369: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
15370: }
15371: if (!$privkey) {
15372: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
15373: } else {
15374: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
15375: }
15376: $chgtext .= '</ul>';
1.269 raeburn 15377: } elsif ($type eq 'recaptchaversion') {
15378: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 15379: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 15380: }
1.224 raeburn 15381: } elsif ($type eq 'emailusername') {
15382: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 15383: if (@statuses) {
15384: foreach my $type (@statuses) {
1.228 raeburn 15385: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
15386: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 15387: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 15388: '<ul>';
15389: foreach my $field (@{$infofields}) {
15390: if ($cancreate{'emailusername'}{$type}{$field}) {
15391: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
15392: }
15393: }
1.245 raeburn 15394: $chgtext .= '</ul>';
15395: } else {
1.303 raeburn 15396: $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 15397: }
15398: } else {
1.303 raeburn 15399: $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 15400: }
15401: }
15402: }
15403: }
15404: } elsif ($type eq 'notify') {
1.303 raeburn 15405: my $numapprove = 0;
1.224 raeburn 15406: if (ref($changes{'cancreate'}) eq 'ARRAY') {
15407: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
15408: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 15409: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
15410: $numapprove ++;
1.224 raeburn 15411: }
15412: }
1.43 raeburn 15413: }
1.303 raeburn 15414: unless ($numapprove) {
15415: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
15416: }
1.34 raeburn 15417: }
1.224 raeburn 15418: if ($chgtext) {
15419: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 15420: }
15421: }
15422: }
1.305 raeburn 15423: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 15424: my ($emailrules,$emailruleorder) =
15425: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 15426: foreach my $type (@{$changes{'email_rule'}}) {
15427: if (ref($email_rule{$type}) eq 'ARRAY') {
15428: my $chgtext = '<ul>';
15429: foreach my $rule (@{$email_rule{$type}}) {
15430: if (ref($emailrules->{$rule}) eq 'HASH') {
15431: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
15432: }
15433: }
15434: $chgtext .= '</ul>';
1.310 raeburn 15435: my $typename;
1.305 raeburn 15436: if (@types) {
15437: if ($type eq 'default') {
15438: $typename = $othertitle;
15439: } else {
15440: $typename = $usertypes{$type};
15441: }
15442: $chgtext .= &mt('(Affiliation: [_1])',$typename);
15443: }
15444: if (@{$email_rule{$type}} > 0) {
15445: $resulttext .= '<li>'.
15446: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
15447: $usertypes{$type}).
15448: $chgtext.
15449: '</li>';
15450: } else {
15451: $resulttext .= '<li>'.
1.310 raeburn 15452: &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 15453: '</li>'.
1.310 raeburn 15454: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 15455: }
1.43 raeburn 15456: }
15457: }
1.305 raeburn 15458: }
15459: if (ref($changes{'inststatus'}) eq 'ARRAY') {
15460: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
15461: if (@{$save_inststatus{'inststatusguest'}} > 0) {
15462: my $chgtext = '<ul>';
15463: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
15464: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
15465: }
15466: $chgtext .= '</ul>';
15467: $resulttext .= '<li>'.
15468: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
15469: $chgtext.
15470: '</li>';
15471: } else {
15472: $resulttext .= '<li>'.
15473: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
15474: '</li>';
15475: }
1.43 raeburn 15476: }
15477: }
1.224 raeburn 15478: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
15479: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
15480: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
15481: foreach my $type (@{$changes{'selfcreate'}}) {
15482: my $typename = $type;
1.303 raeburn 15483: if (keys(%usertypes) > 0) {
15484: if ($usertypes{$type} ne '') {
15485: $typename = $usertypes{$type};
1.224 raeburn 15486: }
15487: }
15488: my @modifiable;
15489: $resulttext .= '<li>'.
15490: &mt('Self-creation of account by users with status: [_1]',
15491: '<span class="LC_cusr_emph">'.$typename.'</span>').
15492: ' - '.&mt('modifiable fields (if institutional data blank): ');
15493: foreach my $field (@fields) {
15494: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
15495: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 15496: }
15497: }
1.224 raeburn 15498: if (@modifiable > 0) {
15499: $resulttext .= join(', ',@modifiable);
1.43 raeburn 15500: } else {
1.224 raeburn 15501: $resulttext .= &mt('none');
1.43 raeburn 15502: }
1.224 raeburn 15503: $resulttext .= '</li>';
1.28 raeburn 15504: }
1.224 raeburn 15505: $resulttext .= '</ul></li>';
1.28 raeburn 15506: }
1.27 raeburn 15507: $resulttext .= '</ul>';
1.305 raeburn 15508: my $cachetime = 24*60*60;
15509: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
15510: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15511: if (ref($lastactref) eq 'HASH') {
15512: $lastactref->{'domdefaults'} = 1;
15513: }
1.27 raeburn 15514: } else {
1.224 raeburn 15515: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 15516: }
15517: } else {
15518: $resulttext = '<span class="LC_error">'.
1.23 raeburn 15519: &mt('An error occurred: [_1]',$putresult).'</span>';
15520: }
1.43 raeburn 15521: if ($warningmsg ne '') {
15522: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
15523: }
1.23 raeburn 15524: return $resulttext;
15525: }
15526:
1.165 raeburn 15527: sub process_captcha {
15528: my ($container,$changes,$newsettings,$current) = @_;
15529: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
15530: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
15531: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
15532: $newsettings->{'captcha'} = 'original';
15533: }
15534: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 15535: if ($container eq 'cancreate') {
1.169 raeburn 15536: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
15537: push(@{$changes->{'cancreate'}},'captcha');
15538: } elsif (!defined($changes->{'cancreate'})) {
15539: $changes->{'cancreate'} = ['captcha'];
15540: }
15541: } else {
15542: $changes->{'captcha'} = 1;
1.165 raeburn 15543: }
15544: }
1.269 raeburn 15545: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 15546: if ($newsettings->{'captcha'} eq 'recaptcha') {
15547: $newpub = $env{'form.'.$container.'_recaptchapub'};
15548: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 15549: $newpub =~ s/[^\w\-]//g;
15550: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 15551: $newsettings->{'recaptchakeys'} = {
15552: public => $newpub,
15553: private => $newpriv,
15554: };
1.269 raeburn 15555: $newversion = $env{'form.'.$container.'_recaptchaversion'};
15556: $newversion =~ s/\D//g;
15557: if ($newversion ne '2') {
15558: $newversion = 1;
15559: }
15560: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 15561: }
15562: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
15563: $currpub = $current->{'recaptchakeys'}{'public'};
15564: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 15565: unless ($newsettings->{'captcha'} eq 'recaptcha') {
15566: $newsettings->{'recaptchakeys'} = {
15567: public => '',
15568: private => '',
15569: }
15570: }
1.165 raeburn 15571: }
1.269 raeburn 15572: if ($current->{'captcha'} eq 'recaptcha') {
15573: $currversion = $current->{'recaptchaversion'};
15574: if ($currversion ne '2') {
15575: $currversion = 1;
15576: }
15577: }
15578: if ($currversion ne $newversion) {
15579: if ($container eq 'cancreate') {
15580: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
15581: push(@{$changes->{'cancreate'}},'recaptchaversion');
15582: } elsif (!defined($changes->{'cancreate'})) {
15583: $changes->{'cancreate'} = ['recaptchaversion'];
15584: }
15585: } else {
15586: $changes->{'recaptchaversion'} = 1;
15587: }
15588: }
1.165 raeburn 15589: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 15590: if ($container eq 'cancreate') {
15591: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
15592: push(@{$changes->{'cancreate'}},'recaptchakeys');
15593: } elsif (!defined($changes->{'cancreate'})) {
15594: $changes->{'cancreate'} = ['recaptchakeys'];
15595: }
15596: } else {
1.210 raeburn 15597: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 15598: }
15599: }
15600: return;
15601: }
15602:
1.33 raeburn 15603: sub modify_usermodification {
15604: my ($dom,%domconfig) = @_;
1.224 raeburn 15605: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 15606: if (ref($domconfig{'usermodification'}) eq 'HASH') {
15607: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 15608: if ($key eq 'selfcreate') {
15609: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
15610: } else {
15611: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
15612: }
1.33 raeburn 15613: }
15614: }
1.224 raeburn 15615: my @contexts = ('author','course');
1.33 raeburn 15616: my %context_title = (
15617: author => 'In author context',
15618: course => 'In course context',
15619: );
15620: my @fields = ('lastname','firstname','middlename','generation',
15621: 'permanentemail','id');
15622: my %roles = (
15623: author => ['ca','aa'],
15624: course => ['st','ep','ta','in','cr'],
15625: );
15626: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
15627: foreach my $context (@contexts) {
15628: foreach my $role (@{$roles{$context}}) {
15629: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
15630: foreach my $item (@fields) {
15631: if (grep(/^\Q$item\E$/,@modifiable)) {
15632: $modifyhash{$context}{$role}{$item} = 1;
15633: } else {
15634: $modifyhash{$context}{$role}{$item} = 0;
15635: }
15636: }
15637: }
15638: if (ref($curr_usermodification{$context}) eq 'HASH') {
15639: foreach my $role (@{$roles{$context}}) {
15640: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
15641: foreach my $field (@fields) {
15642: if ($modifyhash{$context}{$role}{$field} ne
15643: $curr_usermodification{$context}{$role}{$field}) {
15644: push(@{$changes{$context}},$role);
15645: last;
15646: }
15647: }
15648: }
15649: }
15650: } else {
15651: foreach my $context (@contexts) {
15652: foreach my $role (@{$roles{$context}}) {
15653: push(@{$changes{$context}},$role);
15654: }
15655: }
15656: }
15657: }
15658: my %usermodification_hash = (
15659: usermodification => \%modifyhash,
15660: );
15661: my $putresult = &Apache::lonnet::put_dom('configuration',
15662: \%usermodification_hash,$dom);
15663: if ($putresult eq 'ok') {
15664: if (keys(%changes) > 0) {
15665: $resulttext = &mt('Changes made: ').'<ul>';
15666: foreach my $context (@contexts) {
15667: if (ref($changes{$context}) eq 'ARRAY') {
15668: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
15669: if (ref($changes{$context}) eq 'ARRAY') {
15670: foreach my $role (@{$changes{$context}}) {
15671: my $rolename;
1.224 raeburn 15672: if ($role eq 'cr') {
15673: $rolename = &mt('Custom');
1.33 raeburn 15674: } else {
1.224 raeburn 15675: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 15676: }
15677: my @modifiable;
1.224 raeburn 15678: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 15679: foreach my $field (@fields) {
15680: if ($modifyhash{$context}{$role}{$field}) {
15681: push(@modifiable,$fieldtitles{$field});
15682: }
15683: }
15684: if (@modifiable > 0) {
15685: $resulttext .= join(', ',@modifiable);
15686: } else {
15687: $resulttext .= &mt('none');
15688: }
15689: $resulttext .= '</li>';
15690: }
15691: $resulttext .= '</ul></li>';
15692: }
15693: }
15694: }
15695: $resulttext .= '</ul>';
15696: } else {
15697: $resulttext = &mt('No changes made to user modification settings');
15698: }
15699: } else {
15700: $resulttext = '<span class="LC_error">'.
15701: &mt('An error occurred: [_1]',$putresult).'</span>';
15702: }
15703: return $resulttext;
15704: }
15705:
1.43 raeburn 15706: sub modify_defaults {
1.212 raeburn 15707: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 15708: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 15709: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 15710: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 15711: 'portal_def');
1.325 raeburn 15712: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 15713: foreach my $item (@items) {
15714: $newvalues{$item} = $env{'form.'.$item};
15715: if ($item eq 'auth_def') {
15716: if ($newvalues{$item} ne '') {
15717: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
15718: push(@errors,$item);
15719: }
15720: }
15721: } elsif ($item eq 'lang_def') {
15722: if ($newvalues{$item} ne '') {
15723: if ($newvalues{$item} =~ /^(\w+)/) {
15724: my $langcode = $1;
1.103 raeburn 15725: if ($langcode ne 'x_chef') {
15726: if (code2language($langcode) eq '') {
15727: push(@errors,$item);
15728: }
1.43 raeburn 15729: }
15730: } else {
15731: push(@errors,$item);
15732: }
15733: }
1.54 raeburn 15734: } elsif ($item eq 'timezone_def') {
15735: if ($newvalues{$item} ne '') {
1.62 raeburn 15736: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 15737: push(@errors,$item);
15738: }
15739: }
1.68 raeburn 15740: } elsif ($item eq 'datelocale_def') {
15741: if ($newvalues{$item} ne '') {
15742: my @datelocale_ids = DateTime::Locale->ids();
15743: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
15744: push(@errors,$item);
15745: }
15746: }
1.141 raeburn 15747: } elsif ($item eq 'portal_def') {
15748: if ($newvalues{$item} ne '') {
15749: 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])\/?$/) {
15750: push(@errors,$item);
15751: }
15752: }
1.43 raeburn 15753: }
15754: if (grep(/^\Q$item\E$/,@errors)) {
15755: $newvalues{$item} = $domdefaults{$item};
15756: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
15757: $changes{$item} = 1;
15758: }
1.72 raeburn 15759: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 15760: }
1.354 raeburn 15761: my %staticdefaults = (
15762: 'intauth_cost' => 10,
15763: 'intauth_check' => 0,
15764: 'intauth_switch' => 0,
15765: );
15766: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
15767: if (exists($domdefaults{$item})) {
15768: $newvalues{$item} = $domdefaults{$item};
15769: } else {
15770: $newvalues{$item} = $staticdefaults{$item};
15771: }
15772: }
1.43 raeburn 15773: my %defaults_hash = (
1.72 raeburn 15774: defaults => \%newvalues,
15775: );
1.43 raeburn 15776: my $title = &defaults_titles();
1.236 raeburn 15777:
15778: my $currinststatus;
15779: if (ref($domconfig{'inststatus'}) eq 'HASH') {
15780: $currinststatus = $domconfig{'inststatus'};
15781: } else {
15782: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
15783: $currinststatus = {
15784: inststatustypes => $usertypes,
15785: inststatusorder => $types,
15786: inststatusguest => [],
15787: };
15788: }
15789: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
15790: my @allpos;
15791: my %alltypes;
1.305 raeburn 15792: my @inststatusguest;
15793: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
15794: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
15795: unless (grep(/^\Q$type\E$/,@todelete)) {
15796: push(@inststatusguest,$type);
15797: }
15798: }
15799: }
15800: my ($currtitles,$currorder);
1.236 raeburn 15801: if (ref($currinststatus) eq 'HASH') {
15802: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
15803: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
15804: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
15805: if ($currinststatus->{inststatustypes}->{$type} ne '') {
15806: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
15807: }
15808: }
15809: unless (grep(/^\Q$type\E$/,@todelete)) {
15810: my $position = $env{'form.inststatus_pos_'.$type};
15811: $position =~ s/\D+//g;
15812: $allpos[$position] = $type;
15813: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
15814: $alltypes{$type} =~ s/`//g;
15815: }
15816: }
15817: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
15818: $currtitles =~ s/,$//;
15819: }
15820: }
15821: if ($env{'form.addinststatus'}) {
15822: my $newtype = $env{'form.addinststatus'};
15823: $newtype =~ s/\W//g;
15824: unless (exists($alltypes{$newtype})) {
15825: $alltypes{$newtype} = $env{'form.addinststatus_title'};
15826: $alltypes{$newtype} =~ s/`//g;
15827: my $position = $env{'form.addinststatus_pos'};
15828: $position =~ s/\D+//g;
15829: if ($position ne '') {
15830: $allpos[$position] = $newtype;
15831: }
15832: }
15833: }
1.305 raeburn 15834: my @orderedstatus;
1.236 raeburn 15835: foreach my $type (@allpos) {
15836: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
15837: push(@orderedstatus,$type);
15838: }
15839: }
15840: foreach my $type (keys(%alltypes)) {
15841: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
15842: delete($alltypes{$type});
15843: }
15844: }
15845: $defaults_hash{'inststatus'} = {
15846: inststatustypes => \%alltypes,
15847: inststatusorder => \@orderedstatus,
1.305 raeburn 15848: inststatusguest => \@inststatusguest,
1.236 raeburn 15849: };
15850: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
15851: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
15852: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
15853: }
15854: }
15855: if ($currorder ne join(',',@orderedstatus)) {
15856: $changes{'inststatus'}{'inststatusorder'} = 1;
15857: }
15858: my $newtitles;
15859: foreach my $item (@orderedstatus) {
15860: $newtitles .= $alltypes{$item}.',';
15861: }
15862: $newtitles =~ s/,$//;
15863: if ($currtitles ne $newtitles) {
15864: $changes{'inststatus'}{'inststatustypes'} = 1;
15865: }
1.43 raeburn 15866: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
15867: $dom);
15868: if ($putresult eq 'ok') {
15869: if (keys(%changes) > 0) {
15870: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 15871: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 15872: 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";
15873: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 15874: if ($item eq 'inststatus') {
15875: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 15876: if (@orderedstatus) {
1.236 raeburn 15877: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
15878: foreach my $type (@orderedstatus) {
15879: $resulttext .= $alltypes{$type}.', ';
15880: }
15881: $resulttext =~ s/, $//;
15882: $resulttext .= '</li>';
1.305 raeburn 15883: } else {
15884: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 15885: }
15886: }
15887: } else {
15888: my $value = $env{'form.'.$item};
15889: if ($value eq '') {
15890: $value = &mt('none');
15891: } elsif ($item eq 'auth_def') {
15892: my %authnames = &authtype_names();
15893: my %shortauth = (
15894: internal => 'int',
15895: krb4 => 'krb4',
15896: krb5 => 'krb5',
15897: localauth => 'loc',
1.325 raeburn 15898: lti => 'lti',
1.236 raeburn 15899: );
15900: $value = $authnames{$shortauth{$value}};
15901: }
15902: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
15903: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 15904: }
15905: }
15906: $resulttext .= '</ul>';
15907: $mailmsgtext .= "\n";
15908: my $cachetime = 24*60*60;
1.72 raeburn 15909: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 15910: if (ref($lastactref) eq 'HASH') {
15911: $lastactref->{'domdefaults'} = 1;
15912: }
1.68 raeburn 15913: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 15914: my $notify = 1;
15915: if (ref($domconfig{'contacts'}) eq 'HASH') {
15916: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
15917: $notify = 0;
15918: }
15919: }
15920: if ($notify) {
15921: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
15922: "LON-CAPA Domain Settings Change - $dom",
15923: $mailmsgtext);
15924: }
1.54 raeburn 15925: }
1.43 raeburn 15926: } else {
1.54 raeburn 15927: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 15928: }
15929: } else {
15930: $resulttext = '<span class="LC_error">'.
15931: &mt('An error occurred: [_1]',$putresult).'</span>';
15932: }
15933: if (@errors > 0) {
15934: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
15935: foreach my $item (@errors) {
15936: $resulttext .= ' "'.$title->{$item}.'",';
15937: }
15938: $resulttext =~ s/,$//;
15939: }
15940: return $resulttext;
15941: }
15942:
1.46 raeburn 15943: sub modify_scantron {
1.205 raeburn 15944: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 15945: my ($resulttext,%confhash,%changes,$errors);
15946: my $custom = 'custom.tab';
15947: my $default = 'default.tab';
15948: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 15949: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 15950: &config_check($dom,$confname,$servadm);
15951: if ($env{'form.scantronformat.filename'} ne '') {
15952: my $error;
15953: if ($configuserok eq 'ok') {
15954: if ($switchserver) {
1.130 raeburn 15955: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 15956: } else {
15957: if ($author_ok eq 'ok') {
15958: my ($result,$scantronurl) =
15959: &publishlogo($r,'upload','scantronformat',$dom,
15960: $confname,'scantron','','',$custom);
15961: if ($result eq 'ok') {
15962: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 15963: $changes{'scantronformat'} = 1;
1.46 raeburn 15964: } else {
15965: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
15966: }
15967: } else {
15968: $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);
15969: }
15970: }
15971: } else {
15972: $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);
15973: }
15974: if ($error) {
15975: &Apache::lonnet::logthis($error);
15976: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15977: }
15978: }
1.48 raeburn 15979: if (ref($domconfig{'scantron'}) eq 'HASH') {
15980: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
15981: if ($env{'form.scantronformat_del'}) {
15982: $confhash{'scantron'}{'scantronformat'} = '';
15983: $changes{'scantronformat'} = 1;
1.347 raeburn 15984: } else {
15985: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 15986: }
15987: }
15988: }
1.347 raeburn 15989: my @options = ('hdr','pad','rem');
1.346 raeburn 15990: my @fields = &scantroncsv_fields();
15991: my %titles = &scantronconfig_titles();
1.347 raeburn 15992: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 15993: my ($newdat,$currdat,%newcol,%currcol);
15994: if (grep(/^dat$/,@formats)) {
15995: $confhash{'scantron'}{config}{dat} = 1;
15996: $newdat = 1;
15997: } else {
15998: $newdat = 0;
15999: }
16000: if (grep(/^csv$/,@formats)) {
16001: my %bynum;
16002: foreach my $field (@fields) {
16003: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
16004: my $posscol = $1;
16005: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 16006: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 16007: $bynum{$posscol} = $field;
16008: $newcol{$field} = $posscol;
16009: }
16010: }
16011: }
1.347 raeburn 16012: if (keys(%newcol)) {
16013: foreach my $option (@options) {
16014: if ($env{'form.scantroncsv_'.$option}) {
16015: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
16016: }
16017: }
16018: }
1.346 raeburn 16019: }
16020: $currdat = 1;
16021: if (ref($domconfig{'scantron'}) eq 'HASH') {
16022: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 16023: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 16024: $currdat = 0;
16025: }
16026: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 16027: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
16028: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
16029: }
1.346 raeburn 16030: }
16031: }
16032: }
16033: if ($currdat != $newdat) {
16034: $changes{'config'} = 1;
16035: } else {
16036: foreach my $field (@fields) {
16037: if ($currcol{$field} ne '') {
16038: if ($currcol{$field} ne $newcol{$field}) {
16039: $changes{'config'} = 1;
16040: last;
1.347 raeburn 16041: }
1.346 raeburn 16042: } elsif ($newcol{$field} ne '') {
16043: $changes{'config'} = 1;
16044: last;
16045: }
16046: }
16047: }
1.46 raeburn 16048: if (keys(%confhash) > 0) {
16049: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
16050: $dom);
16051: if ($putresult eq 'ok') {
16052: if (keys(%changes) > 0) {
1.48 raeburn 16053: if (ref($confhash{'scantron'}) eq 'HASH') {
16054: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 16055: if ($changes{'scantronformat'}) {
16056: if ($confhash{'scantron'}{'scantronformat'} eq '') {
16057: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
16058: } else {
16059: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
16060: }
16061: }
1.347 raeburn 16062: if ($changes{'config'}) {
1.346 raeburn 16063: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
16064: if ($confhash{'scantron'}{'config'}{'dat'}) {
16065: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
16066: }
16067: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 16068: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
16069: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
16070: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
16071: foreach my $field (@fields) {
16072: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
16073: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
16074: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
16075: }
16076: }
16077: $resulttext .= '</ul></li>';
16078: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
16079: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
16080: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
16081: foreach my $option (@options) {
16082: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
16083: $resulttext .= '<li>'.$titles{$option}.'</li>';
16084: }
16085: }
16086: $resulttext .= '</ul></li>';
16087: }
1.346 raeburn 16088: }
16089: }
16090: }
16091: }
16092: } else {
16093: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
16094: }
1.46 raeburn 16095: }
1.48 raeburn 16096: $resulttext .= '</ul>';
16097: } else {
1.130 raeburn 16098: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 16099: }
16100: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16101: if (ref($lastactref) eq 'HASH') {
16102: $lastactref->{'domainconfig'} = 1;
16103: }
1.46 raeburn 16104: } else {
1.346 raeburn 16105: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 16106: }
16107: } else {
16108: $resulttext = '<span class="LC_error">'.
16109: &mt('An error occurred: [_1]',$putresult).'</span>';
16110: }
16111: } else {
1.130 raeburn 16112: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 16113: }
16114: if ($errors) {
1.353 raeburn 16115: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
16116: $errors.'</ul></p>';
1.46 raeburn 16117: }
16118: return $resulttext;
16119: }
16120:
1.48 raeburn 16121: sub modify_coursecategories {
1.239 raeburn 16122: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 16123: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
16124: $cathash);
1.48 raeburn 16125: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 16126: my @catitems = ('unauth','auth');
16127: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 16128: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 16129: $cathash = $domconfig{'coursecategories'}{'cats'};
16130: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
16131: $changes{'togglecats'} = 1;
16132: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
16133: }
16134: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
16135: $changes{'categorize'} = 1;
16136: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
16137: }
1.120 raeburn 16138: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
16139: $changes{'togglecatscomm'} = 1;
16140: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
16141: }
16142: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
16143: $changes{'categorizecomm'} = 1;
16144: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 16145:
16146: }
16147: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
16148: $changes{'togglecatsplace'} = 1;
16149: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
16150: }
16151: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
16152: $changes{'categorizeplace'} = 1;
16153: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 16154: }
1.238 raeburn 16155: foreach my $item (@catitems) {
16156: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
16157: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
16158: $changes{$item} = 1;
16159: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
16160: }
16161: }
16162: }
1.57 raeburn 16163: } else {
16164: $changes{'togglecats'} = 1;
16165: $changes{'categorize'} = 1;
1.124 raeburn 16166: $changes{'togglecatscomm'} = 1;
16167: $changes{'categorizecomm'} = 1;
1.272 raeburn 16168: $changes{'togglecatsplace'} = 1;
16169: $changes{'categorizeplace'} = 1;
1.87 raeburn 16170: $domconfig{'coursecategories'} = {
16171: togglecats => $env{'form.togglecats'},
16172: categorize => $env{'form.categorize'},
1.124 raeburn 16173: togglecatscomm => $env{'form.togglecatscomm'},
16174: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 16175: togglecatsplace => $env{'form.togglecatsplace'},
16176: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 16177: };
1.238 raeburn 16178: foreach my $item (@catitems) {
16179: if ($env{'form.coursecat_'.$item} ne 'std') {
16180: $changes{$item} = 1;
16181: }
16182: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
16183: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
16184: }
16185: }
1.57 raeburn 16186: }
16187: if (ref($cathash) eq 'HASH') {
16188: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 16189: push (@deletecategory,'instcode::0');
16190: }
1.120 raeburn 16191: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
16192: push(@deletecategory,'communities::0');
16193: }
1.272 raeburn 16194: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
16195: push(@deletecategory,'placement::0');
16196: }
1.48 raeburn 16197: }
1.57 raeburn 16198: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
16199: if (ref($cathash) eq 'HASH') {
1.48 raeburn 16200: if (@deletecategory > 0) {
16201: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 16202: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 16203: foreach my $item (@deletecategory) {
1.57 raeburn 16204: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
16205: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 16206: $deletions{$item} = 1;
1.57 raeburn 16207: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 16208: }
16209: }
16210: }
1.57 raeburn 16211: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 16212: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 16213: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 16214: $reorderings{$item} = 1;
1.57 raeburn 16215: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 16216: }
16217: if ($env{'form.addcategory_name_'.$item} ne '') {
16218: my $newcat = $env{'form.addcategory_name_'.$item};
16219: my $newdepth = $depth+1;
16220: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 16221: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 16222: $adds{$newitem} = 1;
16223: }
16224: if ($env{'form.subcat_'.$item} ne '') {
16225: my $newcat = $env{'form.subcat_'.$item};
16226: my $newdepth = $depth+1;
16227: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 16228: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 16229: $adds{$newitem} = 1;
16230: }
16231: }
16232: }
16233: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 16234: if (ref($cathash) eq 'HASH') {
1.48 raeburn 16235: my $newitem = 'instcode::0';
1.57 raeburn 16236: if ($cathash->{$newitem} eq '') {
16237: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 16238: $adds{$newitem} = 1;
16239: }
16240: } else {
16241: my $newitem = 'instcode::0';
1.57 raeburn 16242: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 16243: $adds{$newitem} = 1;
16244: }
16245: }
1.120 raeburn 16246: if ($env{'form.communities'} eq '1') {
16247: if (ref($cathash) eq 'HASH') {
16248: my $newitem = 'communities::0';
16249: if ($cathash->{$newitem} eq '') {
16250: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
16251: $adds{$newitem} = 1;
16252: }
16253: } else {
16254: my $newitem = 'communities::0';
16255: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
16256: $adds{$newitem} = 1;
16257: }
16258: }
1.272 raeburn 16259: if ($env{'form.placement'} eq '1') {
16260: if (ref($cathash) eq 'HASH') {
16261: my $newitem = 'placement::0';
16262: if ($cathash->{$newitem} eq '') {
16263: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
16264: $adds{$newitem} = 1;
16265: }
16266: } else {
16267: my $newitem = 'placement::0';
16268: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
16269: $adds{$newitem} = 1;
16270: }
16271: }
1.48 raeburn 16272: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 16273: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 16274: ($env{'form.addcategory_name'} ne 'communities') &&
16275: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 16276: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
16277: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
16278: $adds{$newitem} = 1;
16279: }
1.48 raeburn 16280: }
1.57 raeburn 16281: my $putresult;
1.48 raeburn 16282: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
16283: if (keys(%deletions) > 0) {
16284: foreach my $key (keys(%deletions)) {
16285: if ($predelallitems{$key} ne '') {
16286: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
16287: }
16288: }
16289: }
16290: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 16291: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 16292: if (ref($chkcats[0]) eq 'ARRAY') {
16293: my $depth = 0;
16294: my $chg = 0;
16295: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
16296: my $name = $chkcats[0][$i];
16297: my $item;
16298: if ($name eq '') {
16299: $chg ++;
16300: } else {
16301: $item = &escape($name).'::0';
16302: if ($chg) {
1.57 raeburn 16303: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 16304: }
16305: $depth ++;
1.57 raeburn 16306: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 16307: $depth --;
16308: }
16309: }
16310: }
1.57 raeburn 16311: }
16312: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
16313: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 16314: if ($putresult eq 'ok') {
1.57 raeburn 16315: my %title = (
1.120 raeburn 16316: togglecats => 'Show/Hide a course in catalog',
16317: categorize => 'Assign a category to a course',
16318: togglecatscomm => 'Show/Hide a community in catalog',
16319: categorizecomm => 'Assign a category to a community',
1.57 raeburn 16320: );
16321: my %level = (
1.120 raeburn 16322: dom => 'set in Domain ("Modify Course/Community")',
16323: crs => 'set in Course ("Course Configuration")',
16324: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 16325: none => 'No catalog',
16326: std => 'Standard catalog',
16327: domonly => 'Domain-only catalog',
16328: codesrch => 'Code search form',
1.57 raeburn 16329: );
1.48 raeburn 16330: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 16331: if ($changes{'togglecats'}) {
16332: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
16333: }
16334: if ($changes{'categorize'}) {
16335: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 16336: }
1.120 raeburn 16337: if ($changes{'togglecatscomm'}) {
16338: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
16339: }
16340: if ($changes{'categorizecomm'}) {
16341: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
16342: }
1.238 raeburn 16343: if ($changes{'unauth'}) {
16344: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
16345: }
16346: if ($changes{'auth'}) {
16347: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
16348: }
1.57 raeburn 16349: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
16350: my $cathash;
16351: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
16352: $cathash = $domconfig{'coursecategories'}{'cats'};
16353: } else {
16354: $cathash = {};
16355: }
16356: my (@cats,@trails,%allitems);
16357: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
16358: if (keys(%deletions) > 0) {
16359: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
16360: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
16361: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
16362: }
16363: $resulttext .= '</ul></li>';
16364: }
16365: if (keys(%reorderings) > 0) {
16366: my %sort_by_trail;
16367: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
16368: foreach my $key (keys(%reorderings)) {
16369: if ($allitems{$key} ne '') {
16370: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
16371: }
1.48 raeburn 16372: }
1.57 raeburn 16373: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
16374: $resulttext .= '<li>'.$trails[$trail].'</li>';
16375: }
16376: $resulttext .= '</ul></li>';
1.48 raeburn 16377: }
1.57 raeburn 16378: if (keys(%adds) > 0) {
16379: my %sort_by_trail;
16380: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
16381: foreach my $key (keys(%adds)) {
16382: if ($allitems{$key} ne '') {
16383: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
16384: }
16385: }
16386: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
16387: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 16388: }
1.57 raeburn 16389: $resulttext .= '</ul></li>';
1.48 raeburn 16390: }
16391: }
16392: $resulttext .= '</ul>';
1.239 raeburn 16393: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 16394: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
16395: if ($changes{'auth'}) {
16396: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
16397: }
16398: if ($changes{'unauth'}) {
16399: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
16400: }
16401: my $cachetime = 24*60*60;
16402: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 16403: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 16404: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 16405: }
16406: }
1.48 raeburn 16407: } else {
16408: $resulttext = '<span class="LC_error">'.
1.57 raeburn 16409: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 16410: }
16411: } else {
1.120 raeburn 16412: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 16413: }
16414: return $resulttext;
16415: }
16416:
1.69 raeburn 16417: sub modify_serverstatuses {
16418: my ($dom,%domconfig) = @_;
16419: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
16420: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
16421: %currserverstatus = %{$domconfig{'serverstatuses'}};
16422: }
16423: my @pages = &serverstatus_pages();
16424: foreach my $type (@pages) {
16425: $newserverstatus{$type}{'namedusers'} = '';
16426: $newserverstatus{$type}{'machines'} = '';
16427: if (defined($env{'form.'.$type.'_namedusers'})) {
16428: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
16429: my @okusers;
16430: foreach my $user (@users) {
16431: my ($uname,$udom) = split(/:/,$user);
16432: if (($udom =~ /^$match_domain$/) &&
16433: (&Apache::lonnet::domain($udom)) &&
16434: ($uname =~ /^$match_username$/)) {
16435: if (!grep(/^\Q$user\E/,@okusers)) {
16436: push(@okusers,$user);
16437: }
16438: }
16439: }
16440: if (@okusers > 0) {
16441: @okusers = sort(@okusers);
16442: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
16443: }
16444: }
16445: if (defined($env{'form.'.$type.'_machines'})) {
16446: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
16447: my @okmachines;
16448: foreach my $ip (@machines) {
16449: my @parts = split(/\./,$ip);
16450: next if (@parts < 4);
16451: my $badip = 0;
16452: for (my $i=0; $i<4; $i++) {
16453: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
16454: $badip = 1;
16455: last;
16456: }
16457: }
16458: if (!$badip) {
16459: push(@okmachines,$ip);
16460: }
16461: }
16462: @okmachines = sort(@okmachines);
16463: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
16464: }
16465: }
16466: my %serverstatushash = (
16467: serverstatuses => \%newserverstatus,
16468: );
16469: foreach my $type (@pages) {
1.83 raeburn 16470: foreach my $setting ('namedusers','machines') {
1.84 raeburn 16471: my (@current,@new);
1.83 raeburn 16472: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 16473: if ($currserverstatus{$type}{$setting} ne '') {
16474: @current = split(/,/,$currserverstatus{$type}{$setting});
16475: }
16476: }
16477: if ($newserverstatus{$type}{$setting} ne '') {
16478: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 16479: }
16480: if (@current > 0) {
16481: if (@new > 0) {
16482: foreach my $item (@current) {
16483: if (!grep(/^\Q$item\E$/,@new)) {
16484: $changes{$type}{$setting} = 1;
1.82 raeburn 16485: last;
16486: }
16487: }
1.84 raeburn 16488: foreach my $item (@new) {
16489: if (!grep(/^\Q$item\E$/,@current)) {
16490: $changes{$type}{$setting} = 1;
16491: last;
1.82 raeburn 16492: }
16493: }
16494: } else {
1.83 raeburn 16495: $changes{$type}{$setting} = 1;
1.69 raeburn 16496: }
1.83 raeburn 16497: } elsif (@new > 0) {
16498: $changes{$type}{$setting} = 1;
1.69 raeburn 16499: }
16500: }
16501: }
16502: if (keys(%changes) > 0) {
1.81 raeburn 16503: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 16504: my $putresult = &Apache::lonnet::put_dom('configuration',
16505: \%serverstatushash,$dom);
16506: if ($putresult eq 'ok') {
16507: $resulttext .= &mt('Changes made:').'<ul>';
16508: foreach my $type (@pages) {
1.84 raeburn 16509: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 16510: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 16511: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 16512: if ($newserverstatus{$type}{'namedusers'} eq '') {
16513: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
16514: } else {
16515: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
16516: }
1.84 raeburn 16517: }
16518: if ($changes{$type}{'machines'}) {
1.69 raeburn 16519: if ($newserverstatus{$type}{'machines'} eq '') {
16520: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
16521: } else {
16522: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
16523: }
16524:
16525: }
16526: $resulttext .= '</ul></li>';
16527: }
16528: }
16529: $resulttext .= '</ul>';
16530: } else {
16531: $resulttext = '<span class="LC_error">'.
16532: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
16533:
16534: }
16535: } else {
16536: $resulttext = &mt('No changes made to access to server status pages');
16537: }
16538: return $resulttext;
16539: }
16540:
1.118 jms 16541: sub modify_helpsettings {
1.285 raeburn 16542: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 16543: my ($resulttext,$errors,%changes,%helphash);
16544: my %defaultchecked = ('submitbugs' => 'on');
16545: my @offon = ('off','on');
1.118 jms 16546: my @toggles = ('submitbugs');
1.285 raeburn 16547: my %current = ('submitbugs' => '',
16548: 'adhoc' => {},
16549: );
1.118 jms 16550: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 16551: %current = %{$domconfig{'helpsettings'}};
16552: }
1.285 raeburn 16553: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 16554: foreach my $item (@toggles) {
16555: if ($defaultchecked{$item} eq 'on') {
16556: if ($current{$item} eq '') {
16557: if ($env{'form.'.$item} eq '0') {
16558: $changes{$item} = 1;
16559: }
16560: } elsif ($current{$item} ne $env{'form.'.$item}) {
16561: $changes{$item} = 1;
16562: }
16563: } elsif ($defaultchecked{$item} eq 'off') {
16564: if ($current{$item} eq '') {
16565: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 16566: $changes{$item} = 1;
16567: }
1.282 raeburn 16568: } elsif ($current{$item} ne $env{'form.'.$item}) {
16569: $changes{$item} = 1;
16570: }
16571: }
16572: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
16573: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
16574: }
16575: }
1.285 raeburn 16576: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 16577: my $confname = $dom.'-domainconfig';
16578: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 16579: my (@allpos,%newsettings,%changedprivs,$newrole);
16580: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 16581: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 16582: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 16583: my %lt = &Apache::lonlocal::texthash(
16584: s => 'system',
16585: d => 'domain',
16586: order => 'Display order',
16587: access => 'Role usage',
1.291 raeburn 16588: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 16589: dh => 'All with domain helpdesk role',
16590: da => 'All with domain helpdesk assistant role',
1.285 raeburn 16591: none => 'None',
16592: status => 'Determined based on institutional status',
16593: inc => 'Include all, but exclude specific personnel',
16594: exc => 'Exclude all, but include specific personnel',
16595: );
16596: for (my $num=0; $num<=$maxnum; $num++) {
16597: my ($prefix,$identifier,$rolename,%curr);
16598: if ($num == $maxnum) {
16599: next unless ($env{'form.newcusthelp'} == $maxnum);
16600: $identifier = 'custhelp'.$num;
16601: $prefix = 'helproles_'.$num;
16602: $rolename = $env{'form.custhelpname'.$num};
16603: $rolename=~s/[^A-Za-z0-9]//gs;
16604: next if ($rolename eq '');
16605: next if (exists($existing{'rolesdef_'.$rolename}));
16606: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
16607: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
16608: $newprivs{'c'},$confname,$dom);
16609: if ($result ne 'ok') {
16610: $errors .= '<li><span class="LC_error">'.
16611: &mt('An error occurred storing the new custom role: [_1]',
16612: $result).'</span></li>';
16613: next;
16614: } else {
16615: $changedprivs{$rolename} = \%newprivs;
16616: $newrole = $rolename;
16617: }
16618: } else {
16619: $prefix = 'helproles_'.$num;
16620: $rolename = $env{'form.'.$prefix};
16621: next if ($rolename eq '');
16622: next unless (exists($existing{'rolesdef_'.$rolename}));
16623: $identifier = 'custhelp'.$num;
16624: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
16625: my %currprivs;
1.289 raeburn 16626: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 16627: split(/\_/,$existing{'rolesdef_'.$rolename});
16628: foreach my $level ('c','d','s') {
16629: if ($newprivs{$level} ne $currprivs{$level}) {
16630: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
16631: $newprivs{'c'},$confname,$dom);
16632: if ($result ne 'ok') {
16633: $errors .= '<li><span class="LC_error">'.
16634: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
16635: $rolename,$result).'</span></li>';
16636: } else {
16637: $changedprivs{$rolename} = \%newprivs;
16638: }
16639: last;
16640: }
16641: }
16642: if (ref($current{'adhoc'}) eq 'HASH') {
16643: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
16644: %curr = %{$current{'adhoc'}{$rolename}};
16645: }
16646: }
16647: }
16648: my $newpos = $env{'form.'.$prefix.'_pos'};
16649: $newpos =~ s/\D+//g;
16650: $allpos[$newpos] = $rolename;
16651: my $newdesc = $env{'form.'.$prefix.'_desc'};
16652: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
16653: if ($curr{'desc'}) {
16654: if ($curr{'desc'} ne $newdesc) {
16655: $changes{'customrole'}{$rolename}{'desc'} = 1;
16656: $newsettings{$rolename}{'desc'} = $newdesc;
16657: }
16658: } elsif ($newdesc ne '') {
16659: $changes{'customrole'}{$rolename}{'desc'} = 1;
16660: $newsettings{$rolename}{'desc'} = $newdesc;
16661: }
16662: my $access = $env{'form.'.$prefix.'_access'};
16663: if (grep(/^\Q$access\E$/,@accesstypes)) {
16664: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
16665: if ($access eq 'status') {
16666: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
16667: if (scalar(@statuses) == 0) {
1.289 raeburn 16668: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 16669: } else {
16670: my (@shownstatus,$numtypes);
16671: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
16672: if (ref($types) eq 'ARRAY') {
16673: $numtypes = scalar(@{$types});
16674: foreach my $type (sort(@statuses)) {
16675: if ($type eq 'default') {
16676: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
16677: } elsif (grep(/^\Q$type\E$/,@{$types})) {
16678: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
16679: push(@shownstatus,$usertypes->{$type});
16680: }
16681: }
16682: }
16683: if (grep(/^default$/,@statuses)) {
16684: push(@shownstatus,$othertitle);
16685: }
16686: if (scalar(@shownstatus) == 1+$numtypes) {
16687: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
16688: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
16689: } else {
16690: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
16691: if (ref($curr{'status'}) eq 'ARRAY') {
16692: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
16693: if (@diffs) {
16694: $changes{'customrole'}{$rolename}{$access} = 1;
16695: }
16696: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
16697: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 16698: }
1.166 raeburn 16699: }
16700: }
1.285 raeburn 16701: } elsif (($access eq 'inc') || ($access eq 'exc')) {
16702: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
16703: my @newspecstaff;
16704: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
16705: foreach my $person (sort(@personnel)) {
16706: if ($domhelpdesk{$person}) {
16707: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
16708: }
16709: }
16710: if (ref($curr{$access}) eq 'ARRAY') {
16711: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
16712: if (@diffs) {
16713: $changes{'customrole'}{$rolename}{$access} = 1;
16714: }
16715: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
16716: $changes{'customrole'}{$rolename}{$access} = 1;
16717: }
16718: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
16719: my ($uname,$udom) = split(/:/,$person);
16720: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
16721: }
16722: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 16723: }
1.285 raeburn 16724: } else {
16725: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
16726: }
16727: unless ($curr{'access'} eq $access) {
16728: $changes{'customrole'}{$rolename}{'access'} = 1;
16729: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 16730: }
16731: }
1.285 raeburn 16732: if (@allpos > 0) {
16733: my $idx = 0;
16734: foreach my $rolename (@allpos) {
16735: if ($rolename ne '') {
16736: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
16737: if (ref($current{'adhoc'}) eq 'HASH') {
16738: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
16739: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
16740: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 16741: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 16742: }
16743: }
1.282 raeburn 16744: }
1.285 raeburn 16745: $idx ++;
1.166 raeburn 16746: }
16747: }
1.118 jms 16748: }
1.123 jms 16749: my $putresult;
16750: if (keys(%changes) > 0) {
1.166 raeburn 16751: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 16752: if ($putresult eq 'ok') {
1.285 raeburn 16753: if (ref($helphash{'helpsettings'}) eq 'HASH') {
16754: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
16755: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
16756: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
16757: }
16758: }
16759: my $cachetime = 24*60*60;
16760: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16761: if (ref($lastactref) eq 'HASH') {
16762: $lastactref->{'domdefaults'} = 1;
16763: }
16764: } else {
16765: $errors .= '<li><span class="LC_error">'.
16766: &mt('An error occurred storing the settings: [_1]',
16767: $putresult).'</span></li>';
16768: }
16769: }
16770: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
16771: $resulttext = &mt('Changes made:').'<ul>';
16772: my (%shownprivs,@levelorder);
16773: @levelorder = ('c','d','s');
16774: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 16775: foreach my $item (sort(keys(%changes))) {
16776: if ($item eq 'submitbugs') {
16777: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
16778: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
16779: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 16780: } elsif ($item eq 'customrole') {
16781: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 16782: my @keyorder = ('order','desc','access','status','exc','inc');
16783: my %keytext = &Apache::lonlocal::texthash(
16784: order => 'Order',
16785: desc => 'Role description',
16786: access => 'Role usage',
1.300 droeschl 16787: status => 'Allowed institutional types',
1.285 raeburn 16788: exc => 'Allowed personnel',
16789: inc => 'Disallowed personnel',
16790: );
1.282 raeburn 16791: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 16792: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
16793: if ($role eq $newrole) {
16794: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
16795: $role).'<ul>';
16796: } else {
16797: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
16798: $role).'<ul>';
16799: }
16800: foreach my $key (@keyorder) {
16801: if ($changes{'customrole'}{$role}{$key}) {
16802: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
16803: $keytext{$key},$newsettings{$role}{$key}).
16804: '</li>';
16805: }
16806: }
16807: if (ref($changedprivs{$role}) eq 'HASH') {
16808: $shownprivs{$role} = 1;
16809: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
16810: foreach my $level (@levelorder) {
16811: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
16812: next if ($item eq '');
16813: my ($priv) = split(/\&/,$item,2);
16814: if (&Apache::lonnet::plaintext($priv)) {
16815: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
16816: unless ($level eq 'c') {
16817: $resulttext .= ' ('.$lt{$level}.')';
16818: }
16819: $resulttext .= '</li>';
16820: }
16821: }
16822: }
16823: $resulttext .= '</ul>';
16824: }
16825: $resulttext .= '</ul></li>';
16826: }
16827: }
16828: }
16829: }
16830: }
16831: }
16832: if (keys(%changedprivs)) {
16833: foreach my $role (sort(keys(%changedprivs))) {
16834: unless ($shownprivs{$role}) {
16835: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
16836: $role).'<ul>'.
16837: '<li>'.&mt('Privileges set to :').'<ul>';
16838: foreach my $level (@levelorder) {
16839: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
16840: next if ($item eq '');
16841: my ($priv) = split(/\&/,$item,2);
16842: if (&Apache::lonnet::plaintext($priv)) {
16843: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
16844: unless ($level eq 'c') {
16845: $resulttext .= ' ('.$lt{$level}.')';
16846: }
16847: $resulttext .= '</li>';
16848: }
1.282 raeburn 16849: }
16850: }
1.285 raeburn 16851: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 16852: }
16853: }
16854: }
1.285 raeburn 16855: $resulttext .= '</ul>';
16856: } else {
16857: $resulttext = &mt('No changes made to help settings');
1.118 jms 16858: }
16859: if ($errors) {
1.168 raeburn 16860: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 16861: $errors.'</ul>';
1.118 jms 16862: }
16863: return $resulttext;
16864: }
16865:
1.121 raeburn 16866: sub modify_coursedefaults {
1.212 raeburn 16867: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 16868: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 16869: my %defaultchecked = (
16870: 'canuse_pdfforms' => 'off',
16871: 'uselcmath' => 'on',
16872: 'usejsme' => 'on'
16873: );
16874: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 16875: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 16876: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
16877: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
16878: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 16879: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 16880: my %staticdefaults = (
16881: anonsurvey_threshold => 10,
16882: uploadquota => 500,
1.257 raeburn 16883: postsubmit => 60,
1.276 raeburn 16884: mysqltables => 172800,
1.198 raeburn 16885: );
1.314 raeburn 16886: my %texoptions = (
16887: MathJax => 'MathJax',
16888: mimetex => &mt('Convert to Images'),
16889: tth => &mt('TeX to HTML'),
16890: );
1.121 raeburn 16891: $defaultshash{'coursedefaults'} = {};
16892:
16893: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
16894: if ($domconfig{'coursedefaults'} eq '') {
16895: $domconfig{'coursedefaults'} = {};
16896: }
16897: }
16898:
16899: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
16900: foreach my $item (@toggles) {
16901: if ($defaultchecked{$item} eq 'on') {
16902: if (($domconfig{'coursedefaults'}{$item} eq '') &&
16903: ($env{'form.'.$item} eq '0')) {
16904: $changes{$item} = 1;
1.192 raeburn 16905: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 16906: $changes{$item} = 1;
16907: }
16908: } elsif ($defaultchecked{$item} eq 'off') {
16909: if (($domconfig{'coursedefaults'}{$item} eq '') &&
16910: ($env{'form.'.$item} eq '1')) {
16911: $changes{$item} = 1;
16912: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
16913: $changes{$item} = 1;
16914: }
16915: }
16916: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
16917: }
1.198 raeburn 16918: foreach my $item (@numbers) {
16919: my ($currdef,$newdef);
1.208 raeburn 16920: $newdef = $env{'form.'.$item};
1.198 raeburn 16921: if ($item eq 'anonsurvey_threshold') {
16922: $currdef = $domconfig{'coursedefaults'}{$item};
16923: $newdef =~ s/\D//g;
16924: if ($newdef eq '' || $newdef < 1) {
16925: $newdef = 1;
16926: }
16927: $defaultshash{'coursedefaults'}{$item} = $newdef;
16928: } else {
1.276 raeburn 16929: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
16930: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
16931: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 16932: }
16933: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 16934: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 16935: }
16936: if ($currdef ne $newdef) {
16937: if ($item eq 'anonsurvey_threshold') {
16938: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
16939: $changes{$item} = 1;
16940: }
1.276 raeburn 16941: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 16942: my $setting = $1;
1.276 raeburn 16943: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
16944: $changes{$setting} = 1;
1.198 raeburn 16945: }
16946: }
1.139 raeburn 16947: }
16948: }
1.314 raeburn 16949: my $texengine;
16950: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
16951: $texengine = $env{'form.texengine'};
1.349 raeburn 16952: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
16953: if ($currdef eq '') {
16954: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 16955: $changes{'texengine'} = 1;
16956: }
1.349 raeburn 16957: } elsif ($currdef ne $texengine) {
1.314 raeburn 16958: $changes{'texengine'} = 1;
16959: }
16960: }
16961: if ($texengine ne '') {
16962: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
16963: }
1.264 raeburn 16964: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
16965: my @currclonecode;
16966: if (ref($currclone) eq 'HASH') {
16967: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
16968: @currclonecode = @{$currclone->{'instcode'}};
16969: }
16970: }
16971: my $newclone;
1.289 raeburn 16972: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 16973: $newclone = $env{'form.canclone'};
16974: }
16975: if ($newclone eq 'instcode') {
16976: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
16977: my (%codedefaults,@code_order,@clonecode);
16978: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
16979: \@code_order);
16980: foreach my $item (@code_order) {
16981: if (grep(/^\Q$item\E$/,@newcodes)) {
16982: push(@clonecode,$item);
16983: }
16984: }
16985: if (@clonecode) {
16986: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
16987: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
16988: if (@diffs) {
16989: $changes{'canclone'} = 1;
16990: }
16991: } else {
16992: $newclone eq '';
16993: }
16994: } elsif ($newclone ne '') {
1.289 raeburn 16995: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
16996: }
1.264 raeburn 16997: if ($newclone ne $currclone) {
16998: $changes{'canclone'} = 1;
16999: }
1.257 raeburn 17000: my %credits;
17001: foreach my $type (@types) {
17002: unless ($type eq 'community') {
17003: $credits{$type} = $env{'form.'.$type.'_credits'};
17004: $credits{$type} =~ s/[^\d.]+//g;
17005: }
17006: }
17007: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
17008: ($env{'form.coursecredits'} eq '1')) {
17009: $changes{'coursecredits'} = 1;
17010: foreach my $type (keys(%credits)) {
17011: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
17012: }
17013: } else {
1.289 raeburn 17014: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 17015: foreach my $type (@types) {
17016: unless ($type eq 'community') {
1.289 raeburn 17017: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 17018: $changes{'coursecredits'} = 1;
17019: }
17020: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
17021: }
17022: }
17023: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
17024: foreach my $type (@types) {
17025: unless ($type eq 'community') {
17026: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
17027: $changes{'coursecredits'} = 1;
17028: last;
17029: }
17030: }
17031: }
17032: }
17033: }
17034: if ($env{'form.postsubmit'} eq '1') {
17035: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
17036: my %currtimeout;
17037: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17038: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
17039: $changes{'postsubmit'} = 1;
17040: }
17041: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17042: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
17043: }
17044: } else {
17045: $changes{'postsubmit'} = 1;
17046: }
17047: foreach my $type (@types) {
17048: my $timeout = $env{'form.'.$type.'_timeout'};
17049: $timeout =~ s/\D//g;
17050: if ($timeout == $staticdefaults{'postsubmit'}) {
17051: $timeout = '';
17052: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
17053: $timeout = '0';
17054: }
17055: unless ($timeout eq '') {
17056: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
17057: }
17058: if (exists($currtimeout{$type})) {
17059: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 17060: $changes{'postsubmit'} = 1;
1.257 raeburn 17061: }
17062: } elsif ($timeout ne '') {
17063: $changes{'postsubmit'} = 1;
17064: }
17065: }
17066: } else {
17067: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
17068: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17069: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
17070: $changes{'postsubmit'} = 1;
17071: }
17072: } else {
17073: $changes{'postsubmit'} = 1;
17074: }
1.192 raeburn 17075: }
1.121 raeburn 17076: }
17077: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
17078: $dom);
17079: if ($putresult eq 'ok') {
17080: if (keys(%changes) > 0) {
1.213 raeburn 17081: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 17082: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 17083: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314 raeburn 17084: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
17085: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257 raeburn 17086: if ($changes{$item}) {
17087: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
17088: }
1.289 raeburn 17089: }
1.192 raeburn 17090: if ($changes{'coursecredits'}) {
17091: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 17092: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
17093: $domdefaults{$type.'credits'} =
17094: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
17095: }
17096: }
17097: }
17098: if ($changes{'postsubmit'}) {
17099: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17100: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
17101: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17102: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
17103: $domdefaults{$type.'postsubtimeout'} =
17104: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
17105: }
17106: }
1.192 raeburn 17107: }
17108: }
1.198 raeburn 17109: if ($changes{'uploadquota'}) {
17110: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
17111: foreach my $type (@types) {
17112: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
17113: }
17114: }
17115: }
1.264 raeburn 17116: if ($changes{'canclone'}) {
17117: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
17118: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
17119: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
17120: if (@clonecodes) {
17121: $domdefaults{'canclone'} = join('+',@clonecodes);
17122: }
17123: }
17124: } else {
17125: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
17126: }
17127: }
1.121 raeburn 17128: my $cachetime = 24*60*60;
17129: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 17130: if (ref($lastactref) eq 'HASH') {
17131: $lastactref->{'domdefaults'} = 1;
17132: }
1.121 raeburn 17133: }
17134: $resulttext = &mt('Changes made:').'<ul>';
17135: foreach my $item (sort(keys(%changes))) {
17136: if ($item eq 'canuse_pdfforms') {
17137: if ($env{'form.'.$item} eq '1') {
17138: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
17139: } else {
17140: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
17141: }
1.257 raeburn 17142: } elsif ($item eq 'uselcmath') {
17143: if ($env{'form.'.$item} eq '1') {
17144: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
17145: } else {
17146: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
17147: }
17148: } elsif ($item eq 'usejsme') {
17149: if ($env{'form.'.$item} eq '1') {
17150: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
17151: } else {
1.289 raeburn 17152: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 17153: }
1.314 raeburn 17154: } elsif ($item eq 'texengine') {
17155: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
17156: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
17157: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
17158: }
1.139 raeburn 17159: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 17160: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 17161: } elsif ($item eq 'uploadquota') {
17162: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
17163: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
17164: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
17165: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 17166: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 17167: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 17168: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
17169: '</ul>'.
17170: '</li>';
17171: } else {
17172: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
17173: }
1.276 raeburn 17174: } elsif ($item eq 'mysqltables') {
17175: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
17176: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
17177: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
17178: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
17179: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
17180: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
17181: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
17182: '</ul>'.
17183: '</li>';
17184: } else {
17185: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
17186: }
1.257 raeburn 17187: } elsif ($item eq 'postsubmit') {
17188: if ($domdefaults{'postsubmit'} eq 'off') {
17189: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
17190: } else {
17191: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 17192: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 17193: $resulttext .= &mt('durations:').'<ul>';
17194: foreach my $type (@types) {
17195: $resulttext .= '<li>';
17196: my $timeout;
17197: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17198: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
17199: }
17200: my $display;
17201: if ($timeout eq '0') {
17202: $display = &mt('unlimited');
17203: } elsif ($timeout eq '') {
17204: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
17205: } else {
17206: $display = &mt('[quant,_1,second]',$timeout);
17207: }
17208: if ($type eq 'community') {
17209: $resulttext .= &mt('Communities');
17210: } elsif ($type eq 'official') {
17211: $resulttext .= &mt('Official courses');
17212: } elsif ($type eq 'unofficial') {
17213: $resulttext .= &mt('Unofficial courses');
17214: } elsif ($type eq 'textbook') {
17215: $resulttext .= &mt('Textbook courses');
1.271 raeburn 17216: } elsif ($type eq 'placement') {
17217: $resulttext .= &mt('Placement tests');
1.257 raeburn 17218: }
17219: $resulttext .= ' -- '.$display.'</li>';
17220: }
17221: $resulttext .= '</ul>';
17222: }
1.289 raeburn 17223: $resulttext .= '</li>';
1.257 raeburn 17224: }
1.192 raeburn 17225: } elsif ($item eq 'coursecredits') {
17226: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
17227: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 17228: ($domdefaults{'unofficialcredits'} eq '') &&
17229: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 17230: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
17231: } else {
17232: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
17233: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
17234: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 17235: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 17236: '</ul>'.
17237: '</li>';
17238: }
17239: } else {
17240: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
17241: }
1.264 raeburn 17242: } elsif ($item eq 'canclone') {
17243: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
17244: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
17245: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
17246: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
17247: }
17248: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
17249: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
17250: } else {
1.289 raeburn 17251: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 17252: }
1.140 raeburn 17253: }
1.121 raeburn 17254: }
17255: $resulttext .= '</ul>';
17256: } else {
17257: $resulttext = &mt('No changes made to course defaults');
17258: }
17259: } else {
17260: $resulttext = '<span class="LC_error">'.
17261: &mt('An error occurred: [_1]',$putresult).'</span>';
17262: }
17263: return $resulttext;
17264: }
17265:
1.231 raeburn 17266: sub modify_selfenrollment {
17267: my ($dom,$lastactref,%domconfig) = @_;
17268: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 17269: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 17270: my %titles = &tool_titles();
1.232 raeburn 17271: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
17272: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 17273: $ordered{'default'} = ['types','registered','approval','limit'];
17274:
17275: my (%roles,%shown,%toplevel);
17276: $roles{'0'} = &Apache::lonnet::plaintext('dc');
17277:
17278: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
17279: if ($domconfig{'selfenrollment'} eq '') {
17280: $domconfig{'selfenrollment'} = {};
17281: }
17282: }
17283: %toplevel = (
17284: admin => 'Configuration Rights',
17285: default => 'Default settings',
17286: validation => 'Validation of self-enrollment requests',
17287: );
1.233 raeburn 17288: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 17289:
17290: if (ref($ordered{'admin'}) eq 'ARRAY') {
17291: foreach my $item (@{$ordered{'admin'}}) {
17292: foreach my $type (@types) {
17293: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
17294: $selfenrollhash{'admin'}{$type}{$item} = 1;
17295: } else {
17296: $selfenrollhash{'admin'}{$type}{$item} = 0;
17297: }
17298: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
17299: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
17300: if ($selfenrollhash{'admin'}{$type}{$item} ne
17301: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
17302: push(@{$changes{'admin'}{$type}},$item);
17303: }
17304: } else {
17305: if (!$selfenrollhash{'admin'}{$type}{$item}) {
17306: push(@{$changes{'admin'}{$type}},$item);
17307: }
17308: }
17309: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
17310: push(@{$changes{'admin'}{$type}},$item);
17311: }
17312: }
17313: }
17314: }
17315:
17316: foreach my $item (@{$ordered{'default'}}) {
17317: foreach my $type (@types) {
17318: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
17319: if ($item eq 'types') {
17320: unless (($value eq 'all') || ($value eq 'dom')) {
17321: $value = '';
17322: }
17323: } elsif ($item eq 'registered') {
17324: unless ($value eq '1') {
17325: $value = 0;
17326: }
17327: } elsif ($item eq 'approval') {
17328: unless ($value =~ /^[012]$/) {
17329: $value = 0;
17330: }
17331: } else {
17332: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
17333: $value = 'none';
17334: }
17335: }
17336: $selfenrollhash{'default'}{$type}{$item} = $value;
17337: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
17338: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
17339: if ($selfenrollhash{'default'}{$type}{$item} ne
17340: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
17341: push(@{$changes{'default'}{$type}},$item);
17342: }
17343: } else {
17344: push(@{$changes{'default'}{$type}},$item);
17345: }
17346: } else {
17347: push(@{$changes{'default'}{$type}},$item);
17348: }
17349: if ($item eq 'limit') {
17350: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
17351: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
17352: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
17353: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
17354: }
17355: } else {
17356: $selfenrollhash{'default'}{$type}{'cap'} = '';
17357: }
17358: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
17359: if ($selfenrollhash{'default'}{$type}{'cap'} ne
17360: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
17361: push(@{$changes{'default'}{$type}},'cap');
17362: }
17363: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
17364: push(@{$changes{'default'}{$type}},'cap');
17365: }
17366: }
17367: }
17368: }
17369:
17370: foreach my $item (@{$itemsref}) {
17371: if ($item eq 'fields') {
17372: my @changed;
17373: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
17374: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
17375: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
17376: }
17377: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
17378: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
17379: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
17380: $domconfig{'selfenrollment'}{'validation'}{$item});
17381: } else {
17382: @changed = @{$selfenrollhash{'validation'}{$item}};
17383: }
17384: } else {
17385: @changed = @{$selfenrollhash{'validation'}{$item}};
17386: }
17387: if (@changed) {
17388: if ($selfenrollhash{'validation'}{$item}) {
17389: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
17390: } else {
17391: $changes{'validation'}{$item} = &mt('None');
17392: }
17393: }
17394: } else {
17395: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
17396: if ($item eq 'markup') {
17397: if ($env{'form.selfenroll_validation_'.$item}) {
17398: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
17399: }
17400: }
17401: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
17402: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
17403: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
17404: }
17405: }
17406: }
17407: }
17408:
17409: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
17410: $dom);
17411: if ($putresult eq 'ok') {
17412: if (keys(%changes) > 0) {
17413: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
17414: $resulttext = &mt('Changes made:').'<ul>';
17415: foreach my $key ('admin','default','validation') {
17416: if (ref($changes{$key}) eq 'HASH') {
17417: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
17418: if ($key eq 'validation') {
17419: foreach my $item (@{$itemsref}) {
17420: if (exists($changes{$key}{$item})) {
17421: if ($item eq 'markup') {
17422: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
17423: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
17424: } else {
17425: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
17426: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
17427: }
17428: }
17429: }
17430: } else {
17431: foreach my $type (@types) {
17432: if ($type eq 'community') {
17433: $roles{'1'} = &mt('Community personnel');
17434: } else {
17435: $roles{'1'} = &mt('Course personnel');
17436: }
17437: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 17438: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
17439: if ($key eq 'admin') {
17440: my @mgrdc = ();
17441: if (ref($ordered{$key}) eq 'ARRAY') {
17442: foreach my $item (@{$ordered{'admin'}}) {
17443: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
17444: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
17445: push(@mgrdc,$item);
17446: }
17447: }
17448: }
17449: if (@mgrdc) {
17450: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
17451: } else {
17452: delete($domdefaults{$type.'selfenrolladmdc'});
17453: }
17454: }
17455: } else {
17456: if (ref($ordered{$key}) eq 'ARRAY') {
17457: foreach my $item (@{$ordered{$key}}) {
17458: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
17459: $domdefaults{$type.'selfenroll'.$item} =
17460: $selfenrollhash{$key}{$type}{$item};
17461: }
17462: }
17463: }
17464: }
17465: }
1.231 raeburn 17466: $resulttext .= '<li>'.$titles{$type}.'<ul>';
17467: foreach my $item (@{$ordered{$key}}) {
17468: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
17469: $resulttext .= '<li>';
17470: if ($key eq 'admin') {
17471: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
17472: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
17473: } else {
17474: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
17475: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
17476: }
17477: $resulttext .= '</li>';
17478: }
17479: }
17480: $resulttext .= '</ul></li>';
17481: }
17482: }
17483: $resulttext .= '</ul></li>';
17484: }
17485: }
1.305 raeburn 17486: }
17487: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
17488: my $cachetime = 24*60*60;
17489: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17490: if (ref($lastactref) eq 'HASH') {
17491: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 17492: }
1.231 raeburn 17493: }
17494: $resulttext .= '</ul>';
17495: } else {
17496: $resulttext = &mt('No changes made to self-enrollment settings');
17497: }
17498: } else {
17499: $resulttext = '<span class="LC_error">'.
17500: &mt('An error occurred: [_1]',$putresult).'</span>';
17501: }
17502: return $resulttext;
17503: }
17504:
1.137 raeburn 17505: sub modify_usersessions {
1.212 raeburn 17506: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 17507: my @hostingtypes = ('version','excludedomain','includedomain');
17508: my @offloadtypes = ('primary','default');
17509: my %types = (
17510: remote => \@hostingtypes,
17511: hosted => \@hostingtypes,
17512: spares => \@offloadtypes,
17513: );
17514: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 17515: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 17516: my (%by_ip,%by_location,@intdoms,@instdoms);
17517: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 17518: my @locations = sort(keys(%by_location));
1.137 raeburn 17519: my (%defaultshash,%changes);
17520: foreach my $prefix (@prefixes) {
17521: $defaultshash{'usersessions'}{$prefix} = {};
17522: }
1.212 raeburn 17523: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 17524: my $resulttext;
1.138 raeburn 17525: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 17526: foreach my $prefix (@prefixes) {
1.145 raeburn 17527: next if ($prefix eq 'spares');
17528: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 17529: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
17530: if ($type eq 'version') {
17531: my $value = $env{'form.'.$prefix.'_'.$type};
17532: my $okvalue;
17533: if ($value ne '') {
17534: if (grep(/^\Q$value\E$/,@lcversions)) {
17535: $okvalue = $value;
17536: }
17537: }
17538: if (ref($domconfig{'usersessions'}) eq 'HASH') {
17539: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
17540: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
17541: if ($inuse == 0) {
17542: $changes{$prefix}{$type} = 1;
17543: } else {
17544: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
17545: $changes{$prefix}{$type} = 1;
17546: }
17547: if ($okvalue ne '') {
17548: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
17549: }
17550: }
17551: } else {
17552: if (($inuse == 1) && ($okvalue ne '')) {
17553: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
17554: $changes{$prefix}{$type} = 1;
17555: }
17556: }
17557: } else {
17558: if (($inuse == 1) && ($okvalue ne '')) {
17559: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
17560: $changes{$prefix}{$type} = 1;
17561: }
17562: }
17563: } else {
17564: if (($inuse == 1) && ($okvalue ne '')) {
17565: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
17566: $changes{$prefix}{$type} = 1;
17567: }
17568: }
17569: } else {
17570: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
17571: my @okvals;
17572: foreach my $val (@vals) {
1.138 raeburn 17573: if ($val =~ /:/) {
17574: my @items = split(/:/,$val);
17575: foreach my $item (@items) {
17576: if (ref($by_location{$item}) eq 'ARRAY') {
17577: push(@okvals,$item);
17578: }
17579: }
17580: } else {
17581: if (ref($by_location{$val}) eq 'ARRAY') {
17582: push(@okvals,$val);
17583: }
1.137 raeburn 17584: }
17585: }
17586: @okvals = sort(@okvals);
17587: if (ref($domconfig{'usersessions'}) eq 'HASH') {
17588: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
17589: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
17590: if ($inuse == 0) {
17591: $changes{$prefix}{$type} = 1;
17592: } else {
17593: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
17594: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
17595: if (@changed > 0) {
17596: $changes{$prefix}{$type} = 1;
17597: }
17598: }
17599: } else {
17600: if ($inuse == 1) {
17601: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
17602: $changes{$prefix}{$type} = 1;
17603: }
17604: }
17605: } else {
17606: if ($inuse == 1) {
17607: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
17608: $changes{$prefix}{$type} = 1;
17609: }
17610: }
17611: } else {
17612: if ($inuse == 1) {
17613: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
17614: $changes{$prefix}{$type} = 1;
17615: }
17616: }
17617: }
17618: }
17619: }
1.145 raeburn 17620:
17621: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 17622: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 17623: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
17624: my $savespares;
17625:
17626: foreach my $lonhost (sort(keys(%servers))) {
17627: my $serverhomeID =
17628: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 17629: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 17630: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
17631: my %spareschg;
17632: foreach my $type (@{$types{'spares'}}) {
17633: my @okspares;
17634: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
17635: foreach my $server (@checked) {
1.152 raeburn 17636: if (&Apache::lonnet::hostname($server) ne '') {
17637: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
17638: unless (grep(/^\Q$server\E$/,@okspares)) {
17639: push(@okspares,$server);
17640: }
1.145 raeburn 17641: }
17642: }
17643: }
17644: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
17645: my $newspare;
1.152 raeburn 17646: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
17647: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 17648: $newspare = $new;
17649: }
17650: }
1.152 raeburn 17651: my @spares;
17652: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
17653: @spares = sort(@okspares,$newspare);
17654: } else {
17655: @spares = sort(@okspares);
17656: }
17657: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 17658: if (ref($spareid{$lonhost}) eq 'HASH') {
17659: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 17660: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 17661: if (@diffs > 0) {
17662: $spareschg{$type} = 1;
17663: }
17664: }
17665: }
17666: }
17667: if (keys(%spareschg) > 0) {
17668: $changes{'spares'}{$lonhost} = \%spareschg;
17669: }
17670: }
1.261 raeburn 17671: $defaultshash{'usersessions'}{'offloadnow'} = {};
17672: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
17673: my @okoffload;
17674: if (@offloadnow) {
17675: foreach my $server (@offloadnow) {
17676: if (&Apache::lonnet::hostname($server) ne '') {
17677: unless (grep(/^\Q$server\E$/,@okoffload)) {
17678: push(@okoffload,$server);
17679: }
17680: }
17681: }
17682: if (@okoffload) {
17683: foreach my $lonhost (@okoffload) {
17684: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
17685: }
17686: }
17687: }
1.145 raeburn 17688: if (ref($domconfig{'usersessions'}) eq 'HASH') {
17689: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
17690: if (ref($changes{'spares'}) eq 'HASH') {
17691: if (keys(%{$changes{'spares'}}) > 0) {
17692: $savespares = 1;
17693: }
17694: }
17695: } else {
17696: $savespares = 1;
17697: }
1.261 raeburn 17698: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
17699: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
17700: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
17701: $changes{'offloadnow'} = 1;
17702: last;
17703: }
17704: }
17705: unless ($changes{'offloadnow'}) {
1.289 raeburn 17706: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 17707: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
17708: $changes{'offloadnow'} = 1;
17709: last;
17710: }
17711: }
17712: }
17713: } elsif (@okoffload) {
17714: $changes{'offloadnow'} = 1;
17715: }
17716: } elsif (@okoffload) {
17717: $changes{'offloadnow'} = 1;
1.145 raeburn 17718: }
1.147 raeburn 17719: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
17720: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 17721: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
17722: $dom);
17723: if ($putresult eq 'ok') {
17724: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
17725: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
17726: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
17727: }
17728: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
17729: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
17730: }
1.261 raeburn 17731: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
17732: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
17733: }
1.137 raeburn 17734: }
17735: my $cachetime = 24*60*60;
17736: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 17737: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 17738: if (ref($lastactref) eq 'HASH') {
17739: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 17740: $lastactref->{'usersessions'} = 1;
1.212 raeburn 17741: }
1.147 raeburn 17742: if (keys(%changes) > 0) {
17743: my %lt = &usersession_titles();
17744: $resulttext = &mt('Changes made:').'<ul>';
17745: foreach my $prefix (@prefixes) {
17746: if (ref($changes{$prefix}) eq 'HASH') {
17747: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
17748: if ($prefix eq 'spares') {
17749: if (ref($changes{$prefix}) eq 'HASH') {
17750: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
17751: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 17752: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 17753: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
17754: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 17755: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
17756: foreach my $type (@{$types{$prefix}}) {
17757: if ($changes{$prefix}{$lonhost}{$type}) {
17758: my $offloadto = &mt('None');
17759: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
17760: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
17761: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
17762: }
1.145 raeburn 17763: }
1.147 raeburn 17764: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 17765: }
1.137 raeburn 17766: }
17767: }
1.147 raeburn 17768: $resulttext .= '</li>';
1.137 raeburn 17769: }
17770: }
1.147 raeburn 17771: } else {
17772: foreach my $type (@{$types{$prefix}}) {
17773: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 17774: my ($newvalue,$notinuse);
1.147 raeburn 17775: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
17776: if (ref($defaultshash{'usersessions'}{$prefix})) {
17777: if ($type eq 'version') {
17778: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 17779: } else {
17780: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
17781: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
17782: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
17783: }
17784: } else {
17785: $notinuse = 1;
1.147 raeburn 17786: }
1.145 raeburn 17787: }
17788: }
17789: }
1.147 raeburn 17790: if ($newvalue eq '') {
17791: if ($type eq 'version') {
17792: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 17793: } elsif ($notinuse) {
17794: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 17795: } else {
17796: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
17797: }
1.145 raeburn 17798: } else {
1.147 raeburn 17799: if ($type eq 'version') {
1.344 raeburn 17800: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 17801: }
17802: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 17803: }
1.137 raeburn 17804: }
17805: }
17806: }
1.147 raeburn 17807: $resulttext .= '</ul>';
1.137 raeburn 17808: }
17809: }
1.261 raeburn 17810: if ($changes{'offloadnow'}) {
17811: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
17812: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
17813: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
17814: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
17815: $resulttext .= '<li>'.$lonhost.'</li>';
17816: }
17817: $resulttext .= '</ul>';
17818: } else {
17819: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
17820: }
17821: } else {
17822: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
17823: }
17824: }
1.147 raeburn 17825: $resulttext .= '</ul>';
17826: } else {
17827: $resulttext = $nochgmsg;
1.137 raeburn 17828: }
17829: } else {
17830: $resulttext = '<span class="LC_error">'.
17831: &mt('An error occurred: [_1]',$putresult).'</span>';
17832: }
17833: } else {
1.147 raeburn 17834: $resulttext = $nochgmsg;
1.137 raeburn 17835: }
17836: return $resulttext;
17837: }
17838:
1.275 raeburn 17839: sub modify_ssl {
17840: my ($dom,$lastactref,%domconfig) = @_;
17841: my (%by_ip,%by_location,@intdoms,@instdoms);
17842: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
17843: my @locations = sort(keys(%by_location));
17844: my %servers = &Apache::lonnet::internet_dom_servers($dom);
17845: my (%defaultshash,%changes);
17846: my $action = 'ssl';
1.293 raeburn 17847: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 17848: foreach my $prefix (@prefixes) {
17849: $defaultshash{$action}{$prefix} = {};
17850: }
17851: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
17852: my $resulttext;
17853: my %iphost = &Apache::lonnet::get_iphost();
17854: my @reptypes = ('certreq','nocertreq');
17855: my @connecttypes = ('dom','intdom','other');
17856: my %types = (
1.293 raeburn 17857: connto => \@connecttypes,
17858: connfrom => \@connecttypes,
17859: replication => \@reptypes,
1.275 raeburn 17860: );
17861: foreach my $prefix (sort(keys(%types))) {
17862: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 17863: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 17864: my $value = 'yes';
17865: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
17866: $value = $env{'form.'.$prefix.'_'.$type};
17867: }
1.335 raeburn 17868: if (ref($domconfig{$action}) eq 'HASH') {
17869: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
17870: if ($domconfig{$action}{$prefix}{$type} ne '') {
17871: if ($value ne $domconfig{$action}{$prefix}{$type}) {
17872: $changes{$prefix}{$type} = 1;
17873: }
17874: $defaultshash{$action}{$prefix}{$type} = $value;
17875: } else {
17876: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 17877: $changes{$prefix}{$type} = 1;
17878: }
17879: } else {
17880: $defaultshash{$action}{$prefix}{$type} = $value;
17881: $changes{$prefix}{$type} = 1;
17882: }
17883: } else {
17884: $defaultshash{$action}{$prefix}{$type} = $value;
17885: $changes{$prefix}{$type} = 1;
17886: }
17887: if (($type eq 'dom') && (keys(%servers) == 1)) {
17888: delete($changes{$prefix}{$type});
17889: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
17890: delete($changes{$prefix}{$type});
17891: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
17892: delete($changes{$prefix}{$type});
17893: }
17894: } elsif ($prefix eq 'replication') {
17895: if (@locations > 0) {
17896: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
17897: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
17898: my @okvals;
17899: foreach my $val (@vals) {
17900: if ($val =~ /:/) {
17901: my @items = split(/:/,$val);
17902: foreach my $item (@items) {
17903: if (ref($by_location{$item}) eq 'ARRAY') {
17904: push(@okvals,$item);
17905: }
17906: }
17907: } else {
17908: if (ref($by_location{$val}) eq 'ARRAY') {
17909: push(@okvals,$val);
17910: }
17911: }
17912: }
17913: @okvals = sort(@okvals);
17914: if (ref($domconfig{$action}) eq 'HASH') {
17915: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
17916: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
17917: if ($inuse == 0) {
17918: $changes{$prefix}{$type} = 1;
17919: } else {
17920: $defaultshash{$action}{$prefix}{$type} = \@okvals;
17921: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
17922: if (@changed > 0) {
17923: $changes{$prefix}{$type} = 1;
17924: }
17925: }
17926: } else {
17927: if ($inuse == 1) {
17928: $defaultshash{$action}{$prefix}{$type} = \@okvals;
17929: $changes{$prefix}{$type} = 1;
17930: }
17931: }
17932: } else {
17933: if ($inuse == 1) {
17934: $defaultshash{$action}{$prefix}{$type} = \@okvals;
17935: $changes{$prefix}{$type} = 1;
17936: }
17937: }
17938: } else {
17939: if ($inuse == 1) {
17940: $defaultshash{$action}{$prefix}{$type} = \@okvals;
17941: $changes{$prefix}{$type} = 1;
17942: }
17943: }
17944: }
17945: }
17946: }
17947: }
1.336 raeburn 17948: if (keys(%changes)) {
17949: foreach my $prefix (keys(%changes)) {
17950: if (ref($changes{$prefix}) eq 'HASH') {
17951: if (scalar(keys(%{$changes{$prefix}})) == 0) {
17952: delete($changes{$prefix});
17953: }
17954: } else {
17955: delete($changes{$prefix});
17956: }
17957: }
17958: }
1.275 raeburn 17959: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
17960: if (keys(%changes) > 0) {
17961: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
17962: $dom);
17963: if ($putresult eq 'ok') {
17964: if (ref($defaultshash{$action}) eq 'HASH') {
17965: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
17966: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
17967: }
1.293 raeburn 17968: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 17969: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 17970: }
17971: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 17972: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 17973: }
17974: }
17975: my $cachetime = 24*60*60;
17976: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17977: if (ref($lastactref) eq 'HASH') {
17978: $lastactref->{'domdefaults'} = 1;
17979: }
17980: if (keys(%changes) > 0) {
17981: my %titles = &ssl_titles();
17982: $resulttext = &mt('Changes made:').'<ul>';
17983: foreach my $prefix (@prefixes) {
17984: if (ref($changes{$prefix}) eq 'HASH') {
17985: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
17986: foreach my $type (@{$types{$prefix}}) {
17987: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 17988: my ($newvalue,$notinuse);
1.275 raeburn 17989: if (ref($defaultshash{$action}) eq 'HASH') {
17990: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 17991: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 17992: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 17993: } else {
17994: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
17995: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
17996: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
17997: }
17998: } else {
17999: $notinuse = 1;
1.275 raeburn 18000: }
18001: }
18002: }
1.344 raeburn 18003: if ($notinuse) {
18004: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
18005: } elsif ($newvalue eq '') {
1.275 raeburn 18006: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
18007: } else {
18008: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
18009: }
18010: }
18011: }
18012: }
18013: $resulttext .= '</ul>';
18014: }
18015: }
18016: } else {
18017: $resulttext = $nochgmsg;
18018: }
18019: } else {
18020: $resulttext = '<span class="LC_error">'.
18021: &mt('An error occurred: [_1]',$putresult).'</span>';
18022: }
18023: } else {
18024: $resulttext = $nochgmsg;
18025: }
18026: return $resulttext;
18027: }
18028:
1.279 raeburn 18029: sub modify_trust {
18030: my ($dom,$lastactref,%domconfig) = @_;
18031: my (%by_ip,%by_location,@intdoms,@instdoms);
18032: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
18033: my @locations = sort(keys(%by_location));
18034: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
18035: my @types = ('exc','inc');
18036: my (%defaultshash,%changes);
18037: foreach my $prefix (@prefixes) {
18038: $defaultshash{'trust'}{$prefix} = {};
18039: }
18040: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18041: my $resulttext;
18042: foreach my $prefix (@prefixes) {
18043: foreach my $type (@types) {
18044: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
18045: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
18046: my @okvals;
18047: foreach my $val (@vals) {
18048: if ($val =~ /:/) {
18049: my @items = split(/:/,$val);
18050: foreach my $item (@items) {
18051: if (ref($by_location{$item}) eq 'ARRAY') {
18052: push(@okvals,$item);
18053: }
18054: }
18055: } else {
18056: if (ref($by_location{$val}) eq 'ARRAY') {
18057: push(@okvals,$val);
18058: }
18059: }
18060: }
18061: @okvals = sort(@okvals);
18062: if (ref($domconfig{'trust'}) eq 'HASH') {
18063: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
18064: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
18065: if ($inuse == 0) {
18066: $changes{$prefix}{$type} = 1;
18067: } else {
18068: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
18069: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
18070: if (@changed > 0) {
18071: $changes{$prefix}{$type} = 1;
18072: }
18073: }
18074: } else {
18075: if ($inuse == 1) {
18076: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
18077: $changes{$prefix}{$type} = 1;
18078: }
18079: }
18080: } else {
18081: if ($inuse == 1) {
18082: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
18083: $changes{$prefix}{$type} = 1;
18084: }
18085: }
18086: } else {
18087: if ($inuse == 1) {
18088: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
18089: $changes{$prefix}{$type} = 1;
18090: }
18091: }
18092: }
18093: }
18094: my $nochgmsg = &mt('No changes made to trust settings.');
18095: if (keys(%changes) > 0) {
18096: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
18097: $dom);
18098: if ($putresult eq 'ok') {
18099: if (ref($defaultshash{'trust'}) eq 'HASH') {
18100: foreach my $prefix (@prefixes) {
18101: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
18102: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
18103: }
18104: }
18105: }
18106: my $cachetime = 24*60*60;
18107: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18108: if (ref($lastactref) eq 'HASH') {
18109: $lastactref->{'domdefaults'} = 1;
18110: }
18111: if (keys(%changes) > 0) {
18112: my %lt = &trust_titles();
18113: $resulttext = &mt('Changes made:').'<ul>';
18114: foreach my $prefix (@prefixes) {
18115: if (ref($changes{$prefix}) eq 'HASH') {
18116: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
18117: foreach my $type (@types) {
18118: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 18119: my ($newvalue,$notinuse);
1.279 raeburn 18120: if (ref($defaultshash{'trust'}) eq 'HASH') {
18121: if (ref($defaultshash{'trust'}{$prefix})) {
18122: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
18123: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
18124: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
18125: }
1.344 raeburn 18126: } else {
18127: $notinuse = 1;
1.279 raeburn 18128: }
18129: }
18130: }
1.344 raeburn 18131: if ($notinuse) {
18132: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
18133: } elsif ($newvalue eq '') {
1.279 raeburn 18134: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
18135: } else {
18136: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
18137: }
18138: }
18139: }
18140: $resulttext .= '</ul>';
18141: }
18142: }
18143: $resulttext .= '</ul>';
18144: } else {
18145: $resulttext = $nochgmsg;
18146: }
18147: } else {
18148: $resulttext = '<span class="LC_error">'.
18149: &mt('An error occurred: [_1]',$putresult).'</span>';
18150: }
18151: } else {
18152: $resulttext = $nochgmsg;
18153: }
18154: return $resulttext;
18155: }
18156:
1.150 raeburn 18157: sub modify_loadbalancing {
18158: my ($dom,%domconfig) = @_;
18159: my $primary_id = &Apache::lonnet::domain($dom,'primary');
18160: my $intdom = &Apache::lonnet::internet_dom($primary_id);
18161: my ($othertitle,$usertypes,$types) =
18162: &Apache::loncommon::sorted_inst_types($dom);
18163: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 18164: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 18165: my @sparestypes = ('primary','default');
18166: my %typetitles = &sparestype_titles();
18167: my $resulttext;
1.342 raeburn 18168: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 18169: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
18170: %existing = %{$domconfig{'loadbalancing'}};
18171: }
18172: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 18173: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 18174: my ($saveloadbalancing,%defaultshash,%changes);
18175: my ($alltypes,$othertypes,$titles) =
18176: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
18177: my %ruletitles = &offloadtype_text();
18178: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
18179: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
18180: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
18181: if ($balancer eq '') {
18182: next;
18183: }
1.210 raeburn 18184: if (!exists($servers{$balancer})) {
1.171 raeburn 18185: if (exists($currbalancer{$balancer})) {
18186: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 18187: }
1.171 raeburn 18188: next;
18189: }
18190: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
18191: push(@{$changes{'delete'}},$balancer);
18192: next;
18193: }
18194: if (!exists($currbalancer{$balancer})) {
18195: push(@{$changes{'add'}},$balancer);
18196: }
18197: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
18198: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
18199: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
18200: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
18201: $saveloadbalancing = 1;
18202: }
18203: foreach my $sparetype (@sparestypes) {
18204: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
18205: my @offloadto;
18206: foreach my $target (@targets) {
18207: if (($servers{$target}) && ($target ne $balancer)) {
18208: if ($sparetype eq 'default') {
18209: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
18210: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 18211: }
18212: }
1.171 raeburn 18213: unless(grep(/^\Q$target\E$/,@offloadto)) {
18214: push(@offloadto,$target);
18215: }
1.150 raeburn 18216: }
18217: }
1.284 raeburn 18218: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
18219: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
18220: push(@offloadto,$balancer);
18221: }
18222: }
18223: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 18224: }
1.342 raeburn 18225: if ($env{'form.loadbalancing_cookie_'.$i}) {
18226: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
18227: if (exists($currbalancer{$balancer})) {
18228: unless ($currcookies{$balancer}) {
18229: $changes{'curr'}{$balancer}{'cookie'} = 1;
18230: }
18231: }
18232: } elsif (exists($currbalancer{$balancer})) {
18233: if ($currcookies{$balancer}) {
18234: $changes{'curr'}{$balancer}{'cookie'} = 1;
18235: }
18236: }
1.171 raeburn 18237: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 18238: foreach my $sparetype (@sparestypes) {
1.171 raeburn 18239: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
18240: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 18241: if (@targetdiffs > 0) {
1.171 raeburn 18242: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 18243: }
1.171 raeburn 18244: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18245: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
18246: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 18247: }
18248: }
18249: }
18250: } else {
1.171 raeburn 18251: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 18252: foreach my $sparetype (@sparestypes) {
1.171 raeburn 18253: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18254: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
18255: $changes{'curr'}{$balancer}{'targets'} = 1;
18256: }
1.150 raeburn 18257: }
18258: }
1.210 raeburn 18259: }
1.150 raeburn 18260: }
18261: my $ishomedom;
1.171 raeburn 18262: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
18263: $ishomedom = 1;
1.150 raeburn 18264: }
18265: if (ref($alltypes) eq 'ARRAY') {
18266: foreach my $type (@{$alltypes}) {
18267: my $rule;
1.210 raeburn 18268: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 18269: (!$ishomedom)) {
1.171 raeburn 18270: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
18271: }
18272: if ($rule eq 'specific') {
1.255 raeburn 18273: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 18274: if (exists($servers{$specifiedhost})) {
1.255 raeburn 18275: $rule = $specifiedhost;
18276: }
1.150 raeburn 18277: }
1.171 raeburn 18278: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
18279: if (ref($currrules{$balancer}) eq 'HASH') {
18280: if ($rule ne $currrules{$balancer}{$type}) {
18281: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 18282: }
18283: } elsif ($rule ne '') {
1.171 raeburn 18284: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 18285: }
18286: }
18287: }
1.171 raeburn 18288: }
18289: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
18290: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
18291: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
18292: $defaultshash{'loadbalancing'} = {};
18293: }
18294: my $putresult = &Apache::lonnet::put_dom('configuration',
18295: \%defaultshash,$dom);
18296: if ($putresult eq 'ok') {
18297: if (keys(%changes) > 0) {
1.252 raeburn 18298: my %toupdate;
1.171 raeburn 18299: if (ref($changes{'delete'}) eq 'ARRAY') {
18300: foreach my $balancer (sort(@{$changes{'delete'}})) {
18301: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 18302: $toupdate{$balancer} = 1;
1.150 raeburn 18303: }
1.171 raeburn 18304: }
18305: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 18306: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 18307: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 18308: $toupdate{$balancer} = 1;
1.171 raeburn 18309: }
18310: }
18311: if (ref($changes{'curr'}) eq 'HASH') {
18312: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 18313: $toupdate{$balancer} = 1;
1.171 raeburn 18314: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
18315: if ($changes{'curr'}{$balancer}{'targets'}) {
18316: my %offloadstr;
18317: foreach my $sparetype (@sparestypes) {
18318: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18319: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
18320: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
18321: }
18322: }
1.150 raeburn 18323: }
1.171 raeburn 18324: if (keys(%offloadstr) == 0) {
18325: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 18326: } else {
1.171 raeburn 18327: my $showoffload;
18328: foreach my $sparetype (@sparestypes) {
18329: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
18330: if (defined($offloadstr{$sparetype})) {
18331: $showoffload .= $offloadstr{$sparetype};
18332: } else {
18333: $showoffload .= &mt('None');
18334: }
18335: $showoffload .= (' 'x3);
18336: }
18337: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 18338: }
18339: }
18340: }
1.171 raeburn 18341: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
18342: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
18343: foreach my $type (@{$alltypes}) {
18344: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
18345: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
18346: my $balancetext;
18347: if ($rule eq '') {
18348: $balancetext = $ruletitles{'default'};
1.209 raeburn 18349: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 18350: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 18351: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 18352: foreach my $sparetype (@sparestypes) {
18353: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18354: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
18355: }
18356: }
1.253 raeburn 18357: foreach my $item (@{$alltypes}) {
18358: next if ($item =~ /^_LC_ipchange/);
18359: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
18360: if ($hasrule eq 'homeserver') {
18361: map { $toupdate{$_} = 1; } (keys(%libraryservers));
18362: } else {
18363: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
18364: if ($servers{$hasrule}) {
18365: $toupdate{$hasrule} = 1;
18366: }
18367: }
18368: }
18369: }
1.254 raeburn 18370: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
18371: $balancetext = $ruletitles{$rule};
18372: } else {
18373: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
18374: $balancetext = $ruletitles{'particular'}.' '.$receiver;
18375: if ($receiver) {
18376: $toupdate{$receiver};
18377: }
18378: }
18379: } else {
18380: $balancetext = $ruletitles{$rule};
1.252 raeburn 18381: }
1.171 raeburn 18382: } else {
18383: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
18384: }
1.210 raeburn 18385: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 18386: }
18387: }
18388: }
18389: }
1.342 raeburn 18390: if ($changes{'curr'}{$balancer}{'cookie'}) {
18391: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
18392: $balancer).'</li>';
18393: }
1.252 raeburn 18394: if (keys(%toupdate)) {
18395: my %thismachine;
18396: my $updatedhere;
18397: my $cachetime = 60*60*24;
18398: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
18399: foreach my $lonhost (keys(%toupdate)) {
18400: if ($thismachine{$lonhost}) {
18401: unless ($updatedhere) {
18402: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
18403: $defaultshash{'loadbalancing'},
18404: $cachetime);
18405: $updatedhere = 1;
18406: }
18407: } else {
18408: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
18409: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
18410: }
18411: }
18412: }
1.150 raeburn 18413: }
1.171 raeburn 18414: }
18415: if ($resulttext ne '') {
18416: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 18417: } else {
18418: $resulttext = $nochgmsg;
18419: }
18420: } else {
1.171 raeburn 18421: $resulttext = $nochgmsg;
1.150 raeburn 18422: }
18423: } else {
1.171 raeburn 18424: $resulttext = '<span class="LC_error">'.
18425: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 18426: }
18427: } else {
1.171 raeburn 18428: $resulttext = $nochgmsg;
1.150 raeburn 18429: }
18430: return $resulttext;
18431: }
18432:
1.48 raeburn 18433: sub recurse_check {
18434: my ($chkcats,$categories,$depth,$name) = @_;
18435: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
18436: my $chg = 0;
18437: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
18438: my $category = $chkcats->[$depth]{$name}[$j];
18439: my $item;
18440: if ($category eq '') {
18441: $chg ++;
18442: } else {
18443: my $deeper = $depth + 1;
18444: $item = &escape($category).':'.&escape($name).':'.$depth;
18445: if ($chg) {
18446: $categories->{$item} -= $chg;
18447: }
18448: &recurse_check($chkcats,$categories,$deeper,$category);
18449: $deeper --;
18450: }
18451: }
18452: }
18453: return;
18454: }
18455:
18456: sub recurse_cat_deletes {
18457: my ($item,$coursecategories,$deletions) = @_;
18458: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
18459: my $subdepth = $depth + 1;
18460: if (ref($coursecategories) eq 'HASH') {
18461: foreach my $subitem (keys(%{$coursecategories})) {
18462: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
18463: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
18464: delete($coursecategories->{$subitem});
18465: $deletions->{$subitem} = 1;
18466: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 18467: }
1.48 raeburn 18468: }
18469: }
18470: return;
18471: }
18472:
1.125 raeburn 18473: sub active_dc_picker {
1.191 raeburn 18474: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 18475: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 18476: my @domcoord = keys(%domcoords);
18477: if (keys(%currhash)) {
18478: foreach my $dc (keys(%currhash)) {
18479: unless (exists($domcoords{$dc})) {
18480: push(@domcoord,$dc);
18481: }
18482: }
18483: }
18484: @domcoord = sort(@domcoord);
1.210 raeburn 18485: my $numdcs = scalar(@domcoord);
1.191 raeburn 18486: my $rows = 0;
18487: my $table;
1.125 raeburn 18488: if ($numdcs > 1) {
1.191 raeburn 18489: $table = '<table>';
18490: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 18491: my $rem = $i%($numinrow);
18492: if ($rem == 0) {
18493: if ($i > 0) {
1.191 raeburn 18494: $table .= '</tr>';
1.125 raeburn 18495: }
1.191 raeburn 18496: $table .= '<tr>';
18497: $rows ++;
1.125 raeburn 18498: }
1.191 raeburn 18499: my $check = '';
18500: if ($inputtype eq 'radio') {
18501: if (keys(%currhash) == 0) {
18502: if (!$i) {
18503: $check = ' checked="checked"';
18504: }
18505: } elsif (exists($currhash{$domcoord[$i]})) {
18506: $check = ' checked="checked"';
18507: }
18508: } else {
18509: if (exists($currhash{$domcoord[$i]})) {
18510: $check = ' checked="checked"';
1.125 raeburn 18511: }
18512: }
1.191 raeburn 18513: if ($i == @domcoord - 1) {
1.125 raeburn 18514: my $colsleft = $numinrow - $rem;
18515: if ($colsleft > 1) {
1.191 raeburn 18516: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 18517: } else {
1.191 raeburn 18518: $table .= '<td class="LC_left_item">';
1.125 raeburn 18519: }
18520: } else {
1.191 raeburn 18521: $table .= '<td class="LC_left_item">';
18522: }
18523: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
18524: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
18525: $table .= '<span class="LC_nobreak"><label>'.
18526: '<input type="'.$inputtype.'" name="'.$name.'"'.
18527: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
18528: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 18529: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 18530: }
1.219 raeburn 18531: $table .= '</label></span></td>';
1.191 raeburn 18532: }
18533: $table .= '</tr></table>';
18534: } elsif ($numdcs == 1) {
1.219 raeburn 18535: my ($dcname,$dcdom) = split(':',$domcoord[0]);
18536: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 18537: if ($inputtype eq 'radio') {
1.247 raeburn 18538: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 18539: if ($user ne $dcname.':'.$dcdom) {
18540: $table .= ' ('.$dcname.':'.$dcdom.')';
18541: }
1.191 raeburn 18542: } else {
18543: my $check;
18544: if (exists($currhash{$domcoord[0]})) {
18545: $check = ' checked="checked"';
1.125 raeburn 18546: }
1.247 raeburn 18547: $table = '<span class="LC_nobreak"><label>'.
18548: '<input type="checkbox" name="'.$name.'" '.
18549: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 18550: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 18551: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 18552: }
1.220 raeburn 18553: $table .= '</label></span>';
1.191 raeburn 18554: $rows ++;
1.125 raeburn 18555: }
18556: }
1.191 raeburn 18557: return ($numdcs,$table,$rows);
1.125 raeburn 18558: }
18559:
1.137 raeburn 18560: sub usersession_titles {
18561: return &Apache::lonlocal::texthash(
18562: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
18563: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 18564: spares => 'Servers offloaded to, when busy',
1.137 raeburn 18565: version => 'LON-CAPA version requirement',
1.138 raeburn 18566: excludedomain => 'Allow all, but exclude specific domains',
18567: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 18568: primary => 'Primary (checked first)',
1.154 raeburn 18569: default => 'Default',
1.137 raeburn 18570: );
18571: }
18572:
1.152 raeburn 18573: sub id_for_thisdom {
18574: my (%servers) = @_;
18575: my %altids;
18576: foreach my $server (keys(%servers)) {
18577: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
18578: if ($serverhome ne $server) {
18579: $altids{$serverhome} = $server;
18580: }
18581: }
18582: return %altids;
18583: }
18584:
1.150 raeburn 18585: sub count_servers {
18586: my ($currbalancer,%servers) = @_;
18587: my (@spares,$numspares);
18588: foreach my $lonhost (sort(keys(%servers))) {
18589: next if ($currbalancer eq $lonhost);
18590: push(@spares,$lonhost);
18591: }
18592: if ($currbalancer) {
18593: $numspares = scalar(@spares);
18594: } else {
18595: $numspares = scalar(@spares) - 1;
18596: }
18597: return ($numspares,@spares);
18598: }
18599:
18600: sub lonbalance_targets_js {
1.171 raeburn 18601: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 18602: my $select = &mt('Select');
18603: my ($alltargets,$allishome,$allinsttypes,@alltypes);
18604: if (ref($servers) eq 'HASH') {
18605: $alltargets = join("','",sort(keys(%{$servers})));
18606: my @homedoms;
18607: foreach my $server (sort(keys(%{$servers}))) {
18608: if (&Apache::lonnet::host_domain($server) eq $dom) {
18609: push(@homedoms,'1');
18610: } else {
18611: push(@homedoms,'0');
18612: }
18613: }
18614: $allishome = join("','",@homedoms);
18615: }
18616: if (ref($types) eq 'ARRAY') {
18617: if (@{$types} > 0) {
18618: @alltypes = @{$types};
18619: }
18620: }
18621: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
18622: $allinsttypes = join("','",@alltypes);
1.342 raeburn 18623: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 18624: if (ref($settings) eq 'HASH') {
18625: %existing = %{$settings};
18626: }
18627: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 18628: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 18629: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 18630: return <<"END";
18631:
18632: <script type="text/javascript">
18633: // <![CDATA[
18634:
1.171 raeburn 18635: currBalancers = new Array('$balancers');
18636:
18637: function toggleTargets(balnum) {
18638: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
18639: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
18640: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
18641: var prevbalancer = prevhostitem.value;
18642: var baltotal = document.getElementById('loadbalancing_total').value;
18643: prevhostitem.value = balancer;
18644: if (prevbalancer != '') {
18645: var prevIdx = currBalancers.indexOf(prevbalancer);
18646: if (prevIdx != -1) {
18647: currBalancers.splice(prevIdx,1);
18648: }
18649: }
1.150 raeburn 18650: if (balancer == '') {
1.171 raeburn 18651: hideSpares(balnum);
1.150 raeburn 18652: } else {
1.171 raeburn 18653: var currIdx = currBalancers.indexOf(balancer);
18654: if (currIdx == -1) {
18655: currBalancers.push(balancer);
18656: }
1.150 raeburn 18657: var homedoms = new Array('$allishome');
1.171 raeburn 18658: var ishomedom = homedoms[lonhostitem.selectedIndex];
18659: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 18660: }
1.171 raeburn 18661: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 18662: return;
18663: }
18664:
1.171 raeburn 18665: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 18666: var alltargets = new Array('$alltargets');
18667: var insttypes = new Array('$allinsttypes');
1.151 raeburn 18668: var offloadtypes = new Array('primary','default');
18669:
1.171 raeburn 18670: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
18671: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 18672:
1.151 raeburn 18673: for (var i=0; i<offloadtypes.length; i++) {
18674: var count = 0;
18675: for (var j=0; j<alltargets.length; j++) {
18676: if (alltargets[j] != balancer) {
1.171 raeburn 18677: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
18678: item.value = alltargets[j];
18679: item.style.textAlign='left';
18680: item.style.textFace='normal';
18681: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
18682: if (currBalancers.indexOf(alltargets[j]) == -1) {
18683: item.disabled = '';
18684: } else {
18685: item.disabled = 'disabled';
18686: item.checked = false;
18687: }
1.151 raeburn 18688: count ++;
18689: }
1.150 raeburn 18690: }
18691: }
1.151 raeburn 18692: for (var k=0; k<insttypes.length; k++) {
18693: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 18694: if (ishomedom == 1) {
1.171 raeburn 18695: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
18696: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 18697: } else {
1.171 raeburn 18698: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
18699: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 18700: }
18701: } else {
1.171 raeburn 18702: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
18703: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 18704: }
1.151 raeburn 18705: if ((insttypes[k] != '_LC_external') &&
18706: ((insttypes[k] != '_LC_internetdom') ||
18707: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 18708: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
18709: item.options.length = 0;
18710: item.options[0] = new Option("","",true,true);
1.210 raeburn 18711: var idx = 0;
1.151 raeburn 18712: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 18713: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
18714: idx ++;
18715: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 18716: }
18717: }
18718: }
18719: }
18720: return;
18721: }
18722:
1.171 raeburn 18723: function hideSpares(balnum) {
1.150 raeburn 18724: var alltargets = new Array('$alltargets');
18725: var insttypes = new Array('$allinsttypes');
18726: var offloadtypes = new Array('primary','default');
18727:
1.171 raeburn 18728: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
18729: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 18730:
18731: var total = alltargets.length - 1;
18732: for (var i=0; i<offloadtypes; i++) {
18733: for (var j=0; j<total; j++) {
1.171 raeburn 18734: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
18735: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
18736: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 18737: }
1.150 raeburn 18738: }
18739: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 18740: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
18741: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 18742: if (insttypes[k] != '_LC_external') {
1.171 raeburn 18743: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
18744: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 18745: }
18746: }
18747: return;
18748: }
18749:
1.171 raeburn 18750: function checkOffloads(item,balnum,type) {
1.150 raeburn 18751: var alltargets = new Array('$alltargets');
18752: var offloadtypes = new Array('primary','default');
18753: if (item.checked) {
18754: var total = alltargets.length - 1;
18755: var other;
18756: if (type == offloadtypes[0]) {
1.151 raeburn 18757: other = offloadtypes[1];
1.150 raeburn 18758: } else {
1.151 raeburn 18759: other = offloadtypes[0];
1.150 raeburn 18760: }
18761: for (var i=0; i<total; i++) {
1.171 raeburn 18762: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 18763: if (server == item.value) {
1.171 raeburn 18764: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
18765: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 18766: }
18767: }
18768: }
18769: }
18770: return;
18771: }
18772:
1.171 raeburn 18773: function singleServerToggle(balnum,type) {
18774: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 18775: if (offloadtoSelIdx == 0) {
1.171 raeburn 18776: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
18777: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 18778:
18779: } else {
1.171 raeburn 18780: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
18781: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 18782: }
18783: return;
18784: }
18785:
1.171 raeburn 18786: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 18787: if (type == '_LC_external') {
1.171 raeburn 18788: return;
1.150 raeburn 18789: }
1.171 raeburn 18790: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 18791: for (var i=0; i<typesRules.length; i++) {
18792: if (formname.elements[typesRules[i]].checked) {
18793: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 18794: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
18795: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 18796: } else {
1.171 raeburn 18797: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
18798: }
18799: }
18800: }
18801: return;
18802: }
18803:
18804: function balancerDeleteChange(balnum) {
18805: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
18806: var baltotal = document.getElementById('loadbalancing_total').value;
18807: var addtarget;
18808: var removetarget;
18809: var action = 'delete';
18810: if (document.getElementById('loadbalancing_delete_'+balnum)) {
18811: var lonhost = hostitem.value;
18812: var currIdx = currBalancers.indexOf(lonhost);
18813: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
18814: if (currIdx != -1) {
18815: currBalancers.splice(currIdx,1);
18816: }
18817: addtarget = lonhost;
18818: } else {
18819: if (currIdx == -1) {
18820: currBalancers.push(lonhost);
18821: }
18822: removetarget = lonhost;
18823: action = 'undelete';
18824: }
18825: balancerChange(balnum,baltotal,action,addtarget,removetarget);
18826: }
18827: return;
18828: }
18829:
18830: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
18831: if (baltotal > 1) {
18832: var offloadtypes = new Array('primary','default');
18833: var alltargets = new Array('$alltargets');
18834: var insttypes = new Array('$allinsttypes');
18835: for (var i=0; i<baltotal; i++) {
18836: if (i != balnum) {
18837: for (var j=0; j<offloadtypes.length; j++) {
18838: var total = alltargets.length - 1;
18839: for (var k=0; k<total; k++) {
18840: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
18841: var server = serveritem.value;
18842: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
18843: if (server == addtarget) {
18844: serveritem.disabled = '';
18845: }
18846: }
18847: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
18848: if (server == removetarget) {
18849: serveritem.disabled = 'disabled';
18850: serveritem.checked = false;
18851: }
18852: }
18853: }
18854: }
18855: for (var j=0; j<insttypes.length; j++) {
18856: if (insttypes[j] != '_LC_external') {
18857: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
18858: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
18859: var currSel = singleserver.selectedIndex;
18860: var currVal = singleserver.options[currSel].value;
18861: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
18862: var numoptions = singleserver.options.length;
18863: var needsnew = 1;
18864: for (var k=0; k<numoptions; k++) {
18865: if (singleserver.options[k] == addtarget) {
18866: needsnew = 0;
18867: break;
18868: }
18869: }
18870: if (needsnew == 1) {
18871: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
18872: }
18873: }
18874: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
18875: singleserver.options.length = 0;
18876: if ((currVal) && (currVal != removetarget)) {
18877: singleserver.options[0] = new Option("","",false,false);
18878: } else {
18879: singleserver.options[0] = new Option("","",true,true);
18880: }
18881: var idx = 0;
18882: for (var m=0; m<alltargets.length; m++) {
18883: if (currBalancers.indexOf(alltargets[m]) == -1) {
18884: idx ++;
18885: if (currVal == alltargets[m]) {
18886: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
18887: } else {
18888: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
18889: }
18890: }
18891: }
18892: }
18893: }
18894: }
18895: }
1.150 raeburn 18896: }
18897: }
18898: }
18899: return;
18900: }
18901:
1.152 raeburn 18902: // ]]>
18903: </script>
18904:
18905: END
18906: }
18907:
18908: sub new_spares_js {
18909: my @sparestypes = ('primary','default');
18910: my $types = join("','",@sparestypes);
18911: my $select = &mt('Select');
18912: return <<"END";
18913:
18914: <script type="text/javascript">
18915: // <![CDATA[
18916:
18917: function updateNewSpares(formname,lonhost) {
18918: var types = new Array('$types');
18919: var include = new Array();
18920: var exclude = new Array();
18921: for (var i=0; i<types.length; i++) {
18922: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
18923: for (var j=0; j<spareboxes.length; j++) {
18924: if (formname.elements[spareboxes[j]].checked) {
18925: exclude.push(formname.elements[spareboxes[j]].value);
18926: } else {
18927: include.push(formname.elements[spareboxes[j]].value);
18928: }
18929: }
18930: }
18931: for (var i=0; i<types.length; i++) {
18932: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
18933: var selIdx = newSpare.selectedIndex;
18934: var currnew = newSpare.options[selIdx].value;
18935: var okSpares = new Array();
18936: for (var j=0; j<newSpare.options.length; j++) {
18937: var possible = newSpare.options[j].value;
18938: if (possible != '') {
18939: if (exclude.indexOf(possible) == -1) {
18940: okSpares.push(possible);
18941: } else {
18942: if (currnew == possible) {
18943: selIdx = 0;
18944: }
18945: }
18946: }
18947: }
18948: for (var k=0; k<include.length; k++) {
18949: if (okSpares.indexOf(include[k]) == -1) {
18950: okSpares.push(include[k]);
18951: }
18952: }
18953: okSpares.sort();
18954: newSpare.options.length = 0;
18955: if (selIdx == 0) {
18956: newSpare.options[0] = new Option("$select","",true,true);
18957: } else {
18958: newSpare.options[0] = new Option("$select","",false,false);
18959: }
18960: for (var m=0; m<okSpares.length; m++) {
18961: var idx = m+1;
18962: var selThis = 0;
18963: if (selIdx != 0) {
18964: if (okSpares[m] == currnew) {
18965: selThis = 1;
18966: }
18967: }
18968: if (selThis == 1) {
18969: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
18970: } else {
18971: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
18972: }
18973: }
18974: }
18975: return;
18976: }
18977:
18978: function checkNewSpares(lonhost,type) {
18979: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
18980: var chosen = newSpare.options[newSpare.selectedIndex].value;
18981: if (chosen != '') {
18982: var othertype;
18983: var othernewSpare;
18984: if (type == 'primary') {
18985: othernewSpare = document.getElementById('newspare_default_'+lonhost);
18986: }
18987: if (type == 'default') {
18988: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
18989: }
18990: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
18991: othernewSpare.selectedIndex = 0;
18992: }
18993: }
18994: return;
18995: }
18996:
18997: // ]]>
18998: </script>
18999:
19000: END
19001:
19002: }
19003:
19004: sub common_domprefs_js {
19005: return <<"END";
19006:
19007: <script type="text/javascript">
19008: // <![CDATA[
19009:
1.150 raeburn 19010: function getIndicesByName(formname,item) {
1.152 raeburn 19011: var group = new Array();
1.150 raeburn 19012: for (var i=0;i<formname.elements.length;i++) {
19013: if (formname.elements[i].name == item) {
1.152 raeburn 19014: group.push(formname.elements[i].id);
1.150 raeburn 19015: }
19016: }
1.152 raeburn 19017: return group;
1.150 raeburn 19018: }
19019:
19020: // ]]>
19021: </script>
19022:
19023: END
1.152 raeburn 19024:
1.150 raeburn 19025: }
19026:
1.165 raeburn 19027: sub recaptcha_js {
19028: my %lt = &captcha_phrases();
19029: return <<"END";
19030:
19031: <script type="text/javascript">
19032: // <![CDATA[
19033:
19034: function updateCaptcha(caller,context) {
19035: var privitem;
19036: var pubitem;
19037: var privtext;
19038: var pubtext;
1.269 raeburn 19039: var versionitem;
19040: var versiontext;
1.165 raeburn 19041: if (document.getElementById(context+'_recaptchapub')) {
19042: pubitem = document.getElementById(context+'_recaptchapub');
19043: } else {
19044: return;
19045: }
19046: if (document.getElementById(context+'_recaptchapriv')) {
19047: privitem = document.getElementById(context+'_recaptchapriv');
19048: } else {
19049: return;
19050: }
19051: if (document.getElementById(context+'_recaptchapubtxt')) {
19052: pubtext = document.getElementById(context+'_recaptchapubtxt');
19053: } else {
19054: return;
19055: }
19056: if (document.getElementById(context+'_recaptchaprivtxt')) {
19057: privtext = document.getElementById(context+'_recaptchaprivtxt');
19058: } else {
19059: return;
19060: }
1.269 raeburn 19061: if (document.getElementById(context+'_recaptchaversion')) {
19062: versionitem = document.getElementById(context+'_recaptchaversion');
19063: } else {
19064: return;
19065: }
19066: if (document.getElementById(context+'_recaptchavertxt')) {
19067: versiontext = document.getElementById(context+'_recaptchavertxt');
19068: } else {
19069: return;
19070: }
1.165 raeburn 19071: if (caller.checked) {
19072: if (caller.value == 'recaptcha') {
19073: pubitem.type = 'text';
19074: privitem.type = 'text';
19075: pubitem.size = '40';
19076: privitem.size = '40';
19077: pubtext.innerHTML = "$lt{'pub'}";
19078: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 19079: versionitem.type = 'text';
19080: versionitem.size = '3';
1.289 raeburn 19081: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 19082: } else {
19083: pubitem.type = 'hidden';
19084: privitem.type = 'hidden';
1.269 raeburn 19085: versionitem.type = 'hidden';
1.165 raeburn 19086: pubtext.innerHTML = '';
19087: privtext.innerHTML = '';
1.269 raeburn 19088: versiontext.innerHTML = '';
1.165 raeburn 19089: }
19090: }
19091: return;
19092: }
19093:
19094: // ]]>
19095: </script>
19096:
19097: END
19098:
19099: }
19100:
1.236 raeburn 19101: sub toggle_display_js {
1.192 raeburn 19102: return <<"END";
19103:
19104: <script type="text/javascript">
19105: // <![CDATA[
19106:
1.236 raeburn 19107: function toggleDisplay(domForm,caller) {
19108: if (document.getElementById(caller)) {
19109: var divitem = document.getElementById(caller);
19110: var optionsElement = domForm.coursecredits;
1.264 raeburn 19111: var checkval = 1;
19112: var dispval = 'block';
1.303 raeburn 19113: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 19114: if (caller == 'emailoptions') {
19115: optionsElement = domForm.cancreate_email;
19116: }
1.257 raeburn 19117: if (caller == 'studentsubmission') {
19118: optionsElement = domForm.postsubmit;
19119: }
1.264 raeburn 19120: if (caller == 'cloneinstcode') {
19121: optionsElement = domForm.canclone;
19122: checkval = 'instcode';
19123: }
1.303 raeburn 19124: if (selfcreateRegExp.test(caller)) {
19125: optionsElement = domForm.elements[caller];
19126: checkval = 'other';
19127: dispval = 'inline'
19128: }
1.236 raeburn 19129: if (optionsElement.length) {
1.192 raeburn 19130: var currval;
1.236 raeburn 19131: for (var i=0; i<optionsElement.length; i++) {
19132: if (optionsElement[i].checked) {
19133: currval = optionsElement[i].value;
1.192 raeburn 19134: }
19135: }
1.264 raeburn 19136: if (currval == checkval) {
19137: divitem.style.display = dispval;
1.192 raeburn 19138: } else {
1.236 raeburn 19139: divitem.style.display = 'none';
1.192 raeburn 19140: }
19141: }
19142: }
19143: return;
19144: }
19145:
19146: // ]]>
19147: </script>
19148:
19149: END
19150:
19151: }
19152:
1.165 raeburn 19153: sub captcha_phrases {
19154: return &Apache::lonlocal::texthash (
19155: priv => 'Private key',
19156: pub => 'Public key',
19157: original => 'original (CAPTCHA)',
19158: recaptcha => 'successor (ReCAPTCHA)',
19159: notused => 'unused',
1.289 raeburn 19160: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 19161: );
19162: }
19163:
1.205 raeburn 19164: sub devalidate_remote_domconfs {
1.212 raeburn 19165: my ($dom,$cachekeys) = @_;
19166: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 19167: my %servers = &Apache::lonnet::internet_dom_servers($dom);
19168: my %thismachine;
19169: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 19170: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
19171: 'directorysrch','passwdconf');
1.260 raeburn 19172: if (keys(%servers)) {
1.205 raeburn 19173: foreach my $server (keys(%servers)) {
19174: next if ($thismachine{$server});
1.212 raeburn 19175: my @cached;
19176: foreach my $name (@posscached) {
19177: if ($cachekeys->{$name}) {
19178: push(@cached,&escape($name).':'.&escape($dom));
19179: }
19180: }
19181: if (@cached) {
19182: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
19183: }
1.205 raeburn 19184: }
19185: }
19186: return;
19187: }
19188:
1.3 raeburn 19189: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>