Annotation of loncom/interface/domainprefs.pm, revision 1.376
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.376 ! raeburn 4: # $Id: domainprefs.pm,v 1.375 2021/01/01 14:45:38 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.373 raeburn 179: use Net::CIDR;
1.1 raeburn 180:
1.155 raeburn 181: my $registered_cleanup;
182: my $modified_urls;
183:
1.1 raeburn 184: sub handler {
185: my $r=shift;
186: if ($r->header_only) {
187: &Apache::loncommon::content_type($r,'text/html');
188: $r->send_http_header;
189: return OK;
190: }
191:
1.91 raeburn 192: my $context = 'domain';
1.1 raeburn 193: my $dom = $env{'request.role.domain'};
1.5 albertel 194: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 195: if (&Apache::lonnet::allowed('mau',$dom)) {
196: &Apache::loncommon::content_type($r,'text/html');
197: $r->send_http_header;
198: } else {
199: $env{'user.error.msg'}=
200: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
201: return HTTP_NOT_ACCEPTABLE;
202: }
1.155 raeburn 203:
204: $registered_cleanup=0;
205: @{$modified_urls}=();
206:
1.1 raeburn 207: &Apache::lonhtmlcommon::clear_breadcrumbs();
208: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 209: ['phase','actions']);
1.30 raeburn 210: my $phase = 'pickactions';
1.3 raeburn 211: if ( exists($env{'form.phase'}) ) {
212: $phase = $env{'form.phase'};
213: }
1.150 raeburn 214: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 215: my %domconfig =
1.6 raeburn 216: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 217: 'quotas','autoenroll','autoupdate','autocreate',
218: 'directorysrch','usercreation','usermodification',
219: 'contacts','defaults','scantron','coursecategories',
220: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 221: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 222: 'requestauthor','selfenrollment','inststatus',
1.372 raeburn 223: 'ltitools','ssl','trust','lti','privacy','passwords',
1.373 raeburn 224: 'proctoring','wafproxy'],$dom);
1.320 raeburn 225: my %encconfig =
1.372 raeburn 226: &Apache::lonnet::get_dom('encconfig',['ltitools','lti','proctoring'],$dom);
1.297 raeburn 227: if (ref($domconfig{'ltitools'}) eq 'HASH') {
228: if (ref($encconfig{'ltitools'}) eq 'HASH') {
229: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
1.320 raeburn 230: if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
231: (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
1.297 raeburn 232: foreach my $item ('key','secret') {
233: $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
234: }
235: }
236: }
237: }
238: }
1.320 raeburn 239: if (ref($domconfig{'lti'}) eq 'HASH') {
240: if (ref($encconfig{'lti'}) eq 'HASH') {
241: foreach my $id (keys(%{$domconfig{'lti'}})) {
242: if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
243: (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
244: foreach my $item ('key','secret') {
245: $domconfig{'lti'}{$id}{$item} = $encconfig{'lti'}{$id}{$item};
246: }
247: }
248: }
249: }
250: }
1.372 raeburn 251: if (ref($domconfig{'proctoring'}) eq 'HASH') {
252: if (ref($encconfig{'proctoring'}) eq 'HASH') {
253: foreach my $provider (keys(%{$domconfig{'proctoring'}})) {
254: if ((ref($domconfig{'proctoring'}{$provider}) eq 'HASH') &&
255: (ref($encconfig{'proctoring'}{$provider}) eq 'HASH')) {
256: foreach my $item ('key','secret') {
257: $domconfig{'proctoring'}{$provider}{$item} = $encconfig{'proctoring'}{$provider}{$item};
258: }
259: }
260: }
261: }
262: }
1.373 raeburn 263: my @prefs_order = ('rolecolors','login','defaults','wafproxy','passwords','quotas',
264: 'autoenroll','autoupdate','autocreate','directorysrch',
265: 'contacts','privacy','usercreation','selfcreation',
1.374 raeburn 266: 'usermodification','scantron','requestcourses','requestauthor',
1.373 raeburn 267: 'coursecategories','serverstatuses','helpsettings','coursedefaults',
1.372 raeburn 268: 'ltitools','proctoring','selfenrollment','usersessions','ssl',
269: 'trust','lti');
1.171 raeburn 270: my %existing;
271: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
272: %existing = %{$domconfig{'loadbalancing'}};
273: }
274: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 275: push(@prefs_order,'loadbalancing');
276: }
1.30 raeburn 277: my %prefs = (
278: 'rolecolors' =>
279: { text => 'Default color schemes',
1.67 raeburn 280: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 281: header => [{col1 => 'Student Settings',
282: col2 => '',},
283: {col1 => 'Coordinator Settings',
284: col2 => '',},
285: {col1 => 'Author Settings',
286: col2 => '',},
287: {col1 => 'Administrator Settings',
288: col2 => '',}],
1.230 raeburn 289: print => \&print_rolecolors,
290: modify => \&modify_rolecolors,
1.30 raeburn 291: },
1.110 raeburn 292: 'login' =>
1.30 raeburn 293: { text => 'Log-in page options',
1.67 raeburn 294: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 295: header => [{col1 => 'Log-in Page Items',
296: col2 => '',},
297: {col1 => 'Log-in Help',
1.256 raeburn 298: col2 => 'Value'},
299: {col1 => 'Custom HTML in document head',
1.168 raeburn 300: col2 => 'Value'}],
1.230 raeburn 301: print => \&print_login,
302: modify => \&modify_login,
1.30 raeburn 303: },
1.43 raeburn 304: 'defaults' =>
1.236 raeburn 305: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 306: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 307: header => [{col1 => 'Setting',
1.236 raeburn 308: col2 => 'Value'},
309: {col1 => 'Institutional user types',
1.305 raeburn 310: col2 => 'Name displayed'}],
1.230 raeburn 311: print => \&print_defaults,
312: modify => \&modify_defaults,
1.43 raeburn 313: },
1.373 raeburn 314: 'wafproxy' =>
315: { text => 'Web Application Firewall/Reverse Proxy',
316: help => 'Domain_Configuration_WAF_Proxy',
317: header => [{col1 => 'Domain server',
318: col2 => 'Alias for WAF/Reverse Proxy',
319: },
320: {col1 => 'Setting',
321: col2 => 'Value',}],
322: print => \&print_wafproxy,
323: modify => \&modify_wafproxy,
324: },
1.354 raeburn 325: 'passwords' =>
326: { text => 'Passwords (Internal authentication)',
327: help => 'Domain_Configuration_Passwords',
328: header => [{col1 => 'Resetting Forgotten Password',
329: col2 => 'Settings'},
330: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
331: col2 => 'Settings'},
332: {col1 => 'Rules for LON-CAPA Passwords',
333: col2 => 'Settings'},
334: {col1 => 'Course Owner Changing Student Passwords',
335: col2 => 'Settings'}],
336: print => \&print_passwords,
337: modify => \&modify_passwords,
338: },
1.30 raeburn 339: 'quotas' =>
1.197 raeburn 340: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 341: help => 'Domain_Configuration_Quotas',
1.77 raeburn 342: header => [{col1 => 'User affiliation',
1.72 raeburn 343: col2 => 'Available tools',
1.213 raeburn 344: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 345: print => \&print_quotas,
346: modify => \&modify_quotas,
1.30 raeburn 347: },
348: 'autoenroll' =>
349: { text => 'Auto-enrollment settings',
1.67 raeburn 350: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 351: header => [{col1 => 'Configuration setting',
352: col2 => 'Value(s)'}],
1.230 raeburn 353: print => \&print_autoenroll,
354: modify => \&modify_autoenroll,
1.30 raeburn 355: },
356: 'autoupdate' =>
357: { text => 'Auto-update settings',
1.67 raeburn 358: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 359: header => [{col1 => 'Setting',
360: col2 => 'Value',},
1.131 raeburn 361: {col1 => 'Setting',
362: col2 => 'Affiliation'},
1.43 raeburn 363: {col1 => 'User population',
1.227 bisitz 364: col2 => 'Updatable user data'}],
1.230 raeburn 365: print => \&print_autoupdate,
366: modify => \&modify_autoupdate,
1.30 raeburn 367: },
1.125 raeburn 368: 'autocreate' =>
369: { text => 'Auto-course creation settings',
370: help => 'Domain_Configuration_Auto_Creation',
371: header => [{col1 => 'Configuration Setting',
372: col2 => 'Value',}],
1.230 raeburn 373: print => \&print_autocreate,
374: modify => \&modify_autocreate,
1.125 raeburn 375: },
1.30 raeburn 376: 'directorysrch' =>
1.277 raeburn 377: { text => 'Directory searches',
1.67 raeburn 378: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 379: header => [{col1 => 'Institutional Directory Setting',
380: col2 => 'Value',},
381: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 382: col2 => 'Value',}],
1.230 raeburn 383: print => \&print_directorysrch,
384: modify => \&modify_directorysrch,
1.30 raeburn 385: },
386: 'contacts' =>
1.286 raeburn 387: { text => 'E-mail addresses and helpform',
1.67 raeburn 388: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 389: header => [{col1 => 'Default e-mail addresses',
390: col2 => 'Value',},
391: {col1 => 'Recipient(s) for notifications',
392: col2 => 'Value',},
1.340 raeburn 393: {col1 => 'Nightly status check e-mail',
394: col2 => 'Settings',},
1.286 raeburn 395: {col1 => 'Ask helpdesk form settings',
396: col2 => 'Value',},],
1.230 raeburn 397: print => \&print_contacts,
398: modify => \&modify_contacts,
1.30 raeburn 399: },
400: 'usercreation' =>
401: { text => 'User creation',
1.67 raeburn 402: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 403: header => [{col1 => 'Format rule type',
404: col2 => 'Format rules in force'},
1.34 raeburn 405: {col1 => 'User account creation',
406: col2 => 'Usernames which may be created',},
1.30 raeburn 407: {col1 => 'Context',
1.43 raeburn 408: col2 => 'Assignable authentication types'}],
1.230 raeburn 409: print => \&print_usercreation,
410: modify => \&modify_usercreation,
1.30 raeburn 411: },
1.224 raeburn 412: 'selfcreation' =>
413: { text => 'Users self-creating accounts',
414: help => 'Domain_Configuration_Self_Creation',
415: header => [{col1 => 'Self-creation with institutional username',
416: col2 => 'Enabled?'},
417: {col1 => 'Institutional user type (login/SSO self-creation)',
418: col2 => 'Information user can enter'},
1.303 raeburn 419: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 420: col2 => 'Settings'}],
1.230 raeburn 421: print => \&print_selfcreation,
422: modify => \&modify_selfcreation,
1.224 raeburn 423: },
1.69 raeburn 424: 'usermodification' =>
1.33 raeburn 425: { text => 'User modification',
1.67 raeburn 426: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 427: header => [{col1 => 'Target user has role',
1.227 bisitz 428: col2 => 'User information updatable in author context'},
1.33 raeburn 429: {col1 => 'Target user has role',
1.227 bisitz 430: col2 => 'User information updatable in course context'}],
1.230 raeburn 431: print => \&print_usermodification,
432: modify => \&modify_usermodification,
1.33 raeburn 433: },
1.69 raeburn 434: 'scantron' =>
1.346 raeburn 435: { text => 'Bubblesheet format',
1.67 raeburn 436: help => 'Domain_Configuration_Scantron_Format',
1.346 raeburn 437: header => [ {col1 => 'Bubblesheet format file',
438: col2 => ''},
439: {col1 => 'Bubblesheet data upload formats',
440: col2 => 'Settings'}],
1.230 raeburn 441: print => \&print_scantron,
442: modify => \&modify_scantron,
1.46 raeburn 443: },
1.86 raeburn 444: 'requestcourses' =>
445: {text => 'Request creation of courses',
446: help => 'Domain_Configuration_Request_Courses',
447: header => [{col1 => 'User affiliation',
1.102 raeburn 448: col2 => 'Availability/Processing of requests',},
449: {col1 => 'Setting',
1.216 raeburn 450: col2 => 'Value'},
451: {col1 => 'Available textbooks',
1.235 raeburn 452: col2 => ''},
1.242 raeburn 453: {col1 => 'Available templates',
454: col2 => ''},
1.235 raeburn 455: {col1 => 'Validation (not official courses)',
456: col2 => 'Value'},],
1.230 raeburn 457: print => \&print_quotas,
458: modify => \&modify_quotas,
1.86 raeburn 459: },
1.163 raeburn 460: 'requestauthor' =>
1.223 bisitz 461: {text => 'Request Authoring Space',
1.163 raeburn 462: help => 'Domain_Configuration_Request_Author',
463: header => [{col1 => 'User affiliation',
464: col2 => 'Availability/Processing of requests',},
465: {col1 => 'Setting',
466: col2 => 'Value'}],
1.230 raeburn 467: print => \&print_quotas,
468: modify => \&modify_quotas,
1.163 raeburn 469: },
1.69 raeburn 470: 'coursecategories' =>
1.120 raeburn 471: { text => 'Cataloging of courses/communities',
1.67 raeburn 472: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 473: header => [{col1 => 'Catalog type/availability',
474: col2 => '',},
475: {col1 => 'Category settings for standard catalog',
1.57 raeburn 476: col2 => '',},
477: {col1 => 'Categories',
478: col2 => '',
479: }],
1.230 raeburn 480: print => \&print_coursecategories,
481: modify => \&modify_coursecategories,
1.69 raeburn 482: },
483: 'serverstatuses' =>
1.77 raeburn 484: {text => 'Access to server status pages',
1.69 raeburn 485: help => 'Domain_Configuration_Server_Status',
486: header => [{col1 => 'Status Page',
487: col2 => 'Other named users',
488: col3 => 'Specific IPs',
489: }],
1.230 raeburn 490: print => \&print_serverstatuses,
491: modify => \&modify_serverstatuses,
1.69 raeburn 492: },
1.118 jms 493: 'helpsettings' =>
1.282 raeburn 494: {text => 'Support settings',
1.118 jms 495: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 496: header => [{col1 => 'Help Page Settings (logged-in users)',
497: col2 => 'Value'},
498: {col1 => 'Helpdesk Roles',
499: col2 => 'Settings'},],
1.230 raeburn 500: print => \&print_helpsettings,
501: modify => \&modify_helpsettings,
1.118 jms 502: },
1.121 raeburn 503: 'coursedefaults' =>
504: {text => 'Course/Community defaults',
505: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 506: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
507: col2 => 'Value',},
508: {col1 => 'Defaults which can be overridden for each course by a DC',
509: col2 => 'Value',},],
1.230 raeburn 510: print => \&print_coursedefaults,
511: modify => \&modify_coursedefaults,
1.121 raeburn 512: },
1.231 raeburn 513: 'selfenrollment' =>
514: {text => 'Self-enrollment in Course/Community',
515: help => 'Domain_Configuration_Selfenrollment',
516: header => [{col1 => 'Configuration Rights',
517: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
518: {col1 => 'Defaults',
519: col2 => 'Value'},
520: {col1 => 'Self-enrollment validation (optional)',
521: col2 => 'Value'},],
522: print => \&print_selfenrollment,
523: modify => \&modify_selfenrollment,
524: },
1.120 raeburn 525: 'privacy' =>
1.357 raeburn 526: {text => 'Availability of User Information',
1.120 raeburn 527: help => 'Domain_Configuration_User_Privacy',
1.357 raeburn 528: header => [{col1 => 'Role assigned in different domain',
529: col2 => 'Approval options'},
530: {col1 => 'Role assigned in different domain to user of type',
531: col2 => 'User information available in that domain'},
532: {col1 => "Role assigned in user's domain",
533: col2 => 'Information viewable by privileged user'},
534: {col1 => "Role assigned in user's domain",
535: col2 => 'Information viewable by unprivileged user'}],
1.230 raeburn 536: print => \&print_privacy,
537: modify => \&modify_privacy,
1.120 raeburn 538: },
1.141 raeburn 539: 'usersessions' =>
1.145 raeburn 540: {text => 'User session hosting/offloading',
1.137 raeburn 541: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 542: header => [{col1 => 'Domain server',
543: col2 => 'Servers to offload sessions to when busy'},
544: {col1 => 'Hosting of users from other domains',
1.137 raeburn 545: col2 => 'Rules'},
546: {col1 => "Hosting domain's own users elsewhere",
547: col2 => 'Rules'}],
1.230 raeburn 548: print => \&print_usersessions,
549: modify => \&modify_usersessions,
1.137 raeburn 550: },
1.279 raeburn 551: 'loadbalancing' =>
1.185 raeburn 552: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 553: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 554: header => [{col1 => 'Balancers',
1.150 raeburn 555: col2 => 'Default destinations',
1.183 bisitz 556: col3 => 'User affiliation',
1.150 raeburn 557: col4 => 'Overrides'},
558: ],
1.230 raeburn 559: print => \&print_loadbalancing,
560: modify => \&modify_loadbalancing,
1.150 raeburn 561: },
1.279 raeburn 562: 'ltitools' =>
1.267 raeburn 563: {text => 'External Tools (LTI)',
1.296 raeburn 564: help => 'Domain_Configuration_LTI_Tools',
1.267 raeburn 565: header => [{col1 => 'Setting',
566: col2 => 'Value',}],
567: print => \&print_ltitools,
568: modify => \&modify_ltitools,
569: },
1.372 raeburn 570: 'proctoring' =>
571: {text => 'Remote Proctoring Integration',
572: help => 'Domain_Configuration_Proctoring',
573: header => [{col1 => 'Name',
574: col2 => 'Configuration'}],
575: print => \&print_proctoring,
576: modify => \&modify_proctoring,
577: },
1.279 raeburn 578: 'ssl' =>
1.275 raeburn 579: {text => 'LON-CAPA Network (SSL)',
580: help => 'Domain_Configuration_Network_SSL',
581: header => [{col1 => 'Server',
582: col2 => 'Certificate Status'},
583: {col1 => 'Connections to other servers',
584: col2 => 'Rules'},
1.293 raeburn 585: {col1 => 'Connections from other servers',
586: col2 => 'Rules'},
1.275 raeburn 587: {col1 => "Replicating domain's published content",
588: col2 => 'Rules'}],
589: print => \&print_ssl,
590: modify => \&modify_ssl,
591: },
1.279 raeburn 592: 'trust' =>
593: {text => 'Trust Settings',
594: help => 'Domain_Configuration_Trust',
595: header => [{col1 => "Access to this domain's content by others",
596: col2 => 'Rules'},
597: {col1 => "Access to other domain's content by this domain",
598: col2 => 'Rules'},
599: {col1 => "Enrollment in this domain's courses by others",
600: col2 => 'Rules',},
601: {col1 => "Co-author roles in this domain for others",
602: col2 => 'Rules',},
603: {col1 => "Co-author roles for this domain's users elsewhere",
604: col2 => 'Rules',},
605: {col1 => "Domain roles in this domain assignable to others",
606: col2 => 'Rules'},
607: {col1 => "Course catalog for this domain displayed elsewhere",
608: col2 => 'Rules'},
609: {col1 => "Requests for creation of courses in this domain by others",
610: col2 => 'Rules'},
611: {col1 => "Users in other domains can send messages to this domain",
612: col2 => 'Rules'},],
613: print => \&print_trust,
614: modify => \&modify_trust,
615: },
1.320 raeburn 616: 'lti' =>
617: {text => 'LTI Provider',
618: help => 'Domain_Configuration_LTI_Provider',
619: header => [{col1 => 'Setting',
620: col2 => 'Value',}],
621: print => \&print_lti,
622: modify => \&modify_lti,
623: },
1.3 raeburn 624: );
1.110 raeburn 625: if (keys(%servers) > 1) {
626: $prefs{'login'} = { text => 'Log-in page options',
627: help => 'Domain_Configuration_Login_Page',
628: header => [{col1 => 'Log-in Service',
629: col2 => 'Server Setting',},
630: {col1 => 'Log-in Page Items',
1.168 raeburn 631: col2 => ''},
632: {col1 => 'Log-in Help',
1.256 raeburn 633: col2 => 'Value'},
634: {col1 => 'Custom HTML in document head',
1.168 raeburn 635: col2 => 'Value'}],
1.230 raeburn 636: print => \&print_login,
637: modify => \&modify_login,
1.110 raeburn 638: };
639: }
1.174 foxr 640:
1.6 raeburn 641: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 642: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 643: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 644: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 645: text=>"Settings to display/modify"});
1.9 raeburn 646: my $confname = $dom.'-domainconfig';
1.174 foxr 647:
1.3 raeburn 648: if ($phase eq 'process') {
1.212 raeburn 649: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
650: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 651: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 652: $r->rflush();
1.212 raeburn 653: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 654: }
1.30 raeburn 655: } elsif ($phase eq 'display') {
1.192 raeburn 656: my $js = &recaptcha_js().
1.236 raeburn 657: &toggle_display_js();
1.171 raeburn 658: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 659: my ($othertitle,$usertypes,$types) =
660: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 661: $js .= &lonbalance_targets_js($dom,$types,\%servers,
662: $domconfig{'loadbalancing'}).
1.170 raeburn 663: &new_spares_js().
664: &common_domprefs_js().
665: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 666: }
1.216 raeburn 667: if (grep(/^requestcourses$/,@actions)) {
668: my $javascript_validations;
669: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
670: $js .= <<END;
671: <script type="text/javascript">
672: $javascript_validations
673: </script>
674: $coursebrowserjs
675: END
676: }
1.305 raeburn 677: if (grep(/^selfcreation$/,@actions)) {
678: $js .= &selfcreate_javascript();
679: }
1.286 raeburn 680: if (grep(/^contacts$/,@actions)) {
681: $js .= &contacts_javascript();
682: }
1.346 raeburn 683: if (grep(/^scantron$/,@actions)) {
684: $js .= &scantron_javascript();
685: }
1.150 raeburn 686: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 687: } else {
1.180 raeburn 688: # check if domconfig user exists for the domain.
689: my $servadm = $r->dir_config('lonAdmEMail');
690: my ($configuserok,$author_ok,$switchserver) =
691: &config_check($dom,$confname,$servadm);
692: unless ($configuserok eq 'ok') {
1.181 raeburn 693: &Apache::lonconfigsettings::print_header($r,$phase,$context);
694: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 695: $confname).
1.181 raeburn 696: '<br />'
697: );
1.180 raeburn 698: if ($switchserver) {
1.181 raeburn 699: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
700: '<br />'.
701: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
702: '<br />'.
703: &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).
704: '<br />'.
705: &mt('To do that now, use the following link: [_1]',$switchserver)
706: );
707: } else {
708: $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.').
709: '<br />'.
710: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
711: );
1.180 raeburn 712: }
713: $r->print(&Apache::loncommon::end_page());
714: return OK;
715: }
1.21 raeburn 716: if (keys(%domconfig) == 0) {
717: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 718: my @ids=&Apache::lonnet::current_machine_ids();
719: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 720: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 721: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 722: my $custom_img_count = 0;
723: foreach my $img (@loginimages) {
724: if ($designhash{$dom.'.login.'.$img} ne '') {
725: $custom_img_count ++;
726: }
727: }
728: foreach my $role (@roles) {
729: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
730: $custom_img_count ++;
731: }
732: }
733: if ($custom_img_count > 0) {
1.94 raeburn 734: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 735: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 736: $r->print(
737: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
738: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
739: &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 />'.
740: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
741: if ($switch_server) {
1.30 raeburn 742: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 743: }
1.91 raeburn 744: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 745: return OK;
746: }
747: }
748: }
1.91 raeburn 749: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 750: }
751: return OK;
752: }
753:
754: sub process_changes {
1.205 raeburn 755: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 756: my %domconfig;
757: if (ref($values) eq 'HASH') {
758: %domconfig = %{$values};
759: }
1.3 raeburn 760: my $output;
761: if ($action eq 'login') {
1.205 raeburn 762: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 763: } elsif ($action eq 'rolecolors') {
1.9 raeburn 764: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 765: $lastactref,%domconfig);
1.3 raeburn 766: } elsif ($action eq 'quotas') {
1.216 raeburn 767: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 768: } elsif ($action eq 'autoenroll') {
1.205 raeburn 769: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 770: } elsif ($action eq 'autoupdate') {
771: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 772: } elsif ($action eq 'autocreate') {
773: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 774: } elsif ($action eq 'directorysrch') {
1.295 raeburn 775: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 776: } elsif ($action eq 'usercreation') {
1.28 raeburn 777: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 778: } elsif ($action eq 'selfcreation') {
1.305 raeburn 779: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 780: } elsif ($action eq 'usermodification') {
781: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 782: } elsif ($action eq 'contacts') {
1.205 raeburn 783: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 784: } elsif ($action eq 'defaults') {
1.212 raeburn 785: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 786: } elsif ($action eq 'scantron') {
1.205 raeburn 787: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 788: } elsif ($action eq 'coursecategories') {
1.239 raeburn 789: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 790: } elsif ($action eq 'serverstatuses') {
791: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 792: } elsif ($action eq 'requestcourses') {
1.216 raeburn 793: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 794: } elsif ($action eq 'requestauthor') {
1.216 raeburn 795: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 796: } elsif ($action eq 'helpsettings') {
1.285 raeburn 797: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 798: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 799: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 800: } elsif ($action eq 'selfenrollment') {
801: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 802: } elsif ($action eq 'usersessions') {
1.212 raeburn 803: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 804: } elsif ($action eq 'loadbalancing') {
805: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 806: } elsif ($action eq 'ltitools') {
807: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.372 raeburn 808: } elsif ($action eq 'proctoring') {
809: $output = &modify_proctoring($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 810: } elsif ($action eq 'ssl') {
811: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 812: } elsif ($action eq 'trust') {
813: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 814: } elsif ($action eq 'lti') {
815: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.357 raeburn 816: } elsif ($action eq 'privacy') {
817: $output = &modify_privacy($dom,%domconfig);
1.354 raeburn 818: } elsif ($action eq 'passwords') {
819: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.373 raeburn 820: } elsif ($action eq 'wafproxy') {
821: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
1.3 raeburn 822: }
823: return $output;
824: }
825:
826: sub print_config_box {
1.9 raeburn 827: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 828: my $rowtotal = 0;
1.49 raeburn 829: my $output;
830: if ($action eq 'coursecategories') {
831: $output = &coursecategories_javascript($settings);
1.236 raeburn 832: } elsif ($action eq 'defaults') {
833: $output = &defaults_javascript($settings);
1.354 raeburn 834: } elsif ($action eq 'passwords') {
835: $output = &passwords_javascript();
1.282 raeburn 836: } elsif ($action eq 'helpsettings') {
837: my (%privs,%levelscurrent);
838: my %full=();
839: my %levels=(
840: course => {},
841: domain => {},
842: system => {},
843: );
844: my $context = 'domain';
845: my $crstype = 'Course';
846: my $formname = 'display';
847: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
848: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
849: $output =
850: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
851: \@templateroles);
1.334 raeburn 852: } elsif ($action eq 'ltitools') {
853: $output .= <itools_javascript($settings);
854: } elsif ($action eq 'lti') {
855: $output .= <i_javascript($settings);
1.372 raeburn 856: } elsif ($action eq 'proctoring') {
857: $output .= &proctoring_javascript($settings);
1.91 raeburn 858: }
1.236 raeburn 859: $output .=
1.30 raeburn 860: '<table class="LC_nested_outer">
1.3 raeburn 861: <tr>
1.306 raeburn 862: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 863: &mt($item->{text}).' '.
864: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
865: '</tr>';
1.30 raeburn 866: $rowtotal ++;
1.110 raeburn 867: my $numheaders = 1;
868: if (ref($item->{'header'}) eq 'ARRAY') {
869: $numheaders = scalar(@{$item->{'header'}});
870: }
871: if ($numheaders > 1) {
1.64 raeburn 872: my $colspan = '';
1.145 raeburn 873: my $rightcolspan = '';
1.369 raeburn 874: my $leftnobr = '';
1.238 raeburn 875: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 876: ($action eq 'directorysrch') ||
1.256 raeburn 877: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 878: $colspan = ' colspan="2"';
879: }
1.145 raeburn 880: if ($action eq 'usersessions') {
881: $rightcolspan = ' colspan="3"';
882: }
1.369 raeburn 883: if ($action eq 'passwords') {
884: $leftnobr = ' LC_nobreak';
885: }
1.30 raeburn 886: $output .= '
1.3 raeburn 887: <tr>
888: <td>
889: <table class="LC_nested">
890: <tr class="LC_info_row">
1.369 raeburn 891: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 892: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 893: </tr>';
1.69 raeburn 894: $rowtotal ++;
1.230 raeburn 895: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 896: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 897: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 898: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.373 raeburn 899: ($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'wafproxy')) {
1.230 raeburn 900: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354 raeburn 901: } elsif ($action eq 'passwords') {
902: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 903: } elsif ($action eq 'coursecategories') {
1.230 raeburn 904: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346 raeburn 905: } elsif ($action eq 'scantron') {
906: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 907: } elsif ($action eq 'login') {
1.256 raeburn 908: if ($numheaders == 4) {
1.168 raeburn 909: $colspan = ' colspan="2"';
910: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
911: } else {
912: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
913: }
1.230 raeburn 914: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 915: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 916: } elsif ($action eq 'rolecolors') {
1.30 raeburn 917: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 918: }
1.30 raeburn 919: $output .= '
1.6 raeburn 920: </table>
921: </td>
922: </tr>
923: <tr>
924: <td>
925: <table class="LC_nested">
926: <tr class="LC_info_row">
1.230 raeburn 927: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 928: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 929: </tr>';
930: $rowtotal ++;
1.230 raeburn 931: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
932: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 933: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.357 raeburn 934: ($action eq 'trust') || ($action eq 'contacts') ||
935: ($action eq 'privacy') || ($action eq 'passwords')) {
1.238 raeburn 936: if ($action eq 'coursecategories') {
937: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
938: $colspan = ' colspan="2"';
1.279 raeburn 939: } elsif ($action eq 'trust') {
940: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354 raeburn 941: } elsif ($action eq 'passwords') {
942: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.238 raeburn 943: } else {
944: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
945: }
1.279 raeburn 946: if ($action eq 'trust') {
947: $output .= '
948: </table>
949: </td>
950: </tr>';
951: my @trusthdrs = qw(2 3 4 5 6 7);
952: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
953: for (my $i=0; $i<@trusthdrs; $i++) {
954: $output .= '
955: <tr>
956: <td>
957: <table class="LC_nested">
958: <tr class="LC_info_row">
959: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
960: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
961: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
962: </table>
963: </td>
964: </tr>';
965: }
966: $output .= '
967: <tr>
968: <td>
969: <table class="LC_nested">
970: <tr class="LC_info_row">
971: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
972: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
973: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
974: } else {
975: $output .= '
1.63 raeburn 976: </table>
977: </td>
978: </tr>
979: <tr>
980: <td>
981: <table class="LC_nested">
982: <tr class="LC_info_row">
983: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 984: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 985: </tr>'."\n";
1.279 raeburn 986: if ($action eq 'coursecategories') {
987: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.357 raeburn 988: } elsif (($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'passwords')) {
1.354 raeburn 989: if ($action eq 'passwords') {
990: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
991: } else {
992: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
993: }
994: $output .= '
1.340 raeburn 995: </tr>
996: </table>
997: </td>
998: </tr>
999: <tr>
1000: <td>
1001: <table class="LC_nested">
1002: <tr class="LC_info_row">
1.369 raeburn 1003: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.354 raeburn 1004: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
1005: if ($action eq 'passwords') {
1006: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
1007: } else {
1008: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1009: }
1010: $output .= '
1.340 raeburn 1011: </table>
1012: </td>
1013: </tr>
1014: <tr>';
1.279 raeburn 1015: } else {
1016: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1017: }
1.238 raeburn 1018: }
1.63 raeburn 1019: $rowtotal ++;
1.236 raeburn 1020: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282 raeburn 1021: ($action eq 'defaults') || ($action eq 'directorysrch') ||
1.373 raeburn 1022: ($action eq 'helpsettings') || ($action eq 'wafproxy')) {
1.230 raeburn 1023: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346 raeburn 1024: } elsif ($action eq 'scantron') {
1025: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293 raeburn 1026: } elsif ($action eq 'ssl') {
1027: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
1028: </table>
1029: </td>
1030: </tr>
1031: <tr>
1032: <td>
1033: <table class="LC_nested">
1034: <tr class="LC_info_row">
1035: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1036: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1037: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
1038: </table>
1039: </td>
1040: </tr>
1041: <tr>
1042: <td>
1043: <table class="LC_nested">
1044: <tr class="LC_info_row">
1045: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1046: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
1047: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 1048: } elsif ($action eq 'login') {
1.256 raeburn 1049: if ($numheaders == 4) {
1.168 raeburn 1050: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
1051: </table>
1052: </td>
1053: </tr>
1054: <tr>
1055: <td>
1056: <table class="LC_nested">
1057: <tr class="LC_info_row">
1058: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 1059: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 1060: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1061: $rowtotal ++;
1062: } else {
1063: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1064: }
1.256 raeburn 1065: $output .= '
1066: </table>
1067: </td>
1068: </tr>
1069: <tr>
1070: <td>
1071: <table class="LC_nested">
1072: <tr class="LC_info_row">';
1073: if ($numheaders == 4) {
1074: $output .= '
1075: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1076: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1077: </tr>';
1078: } else {
1079: $output .= '
1080: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1081: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1082: </tr>';
1083: }
1084: $rowtotal ++;
1085: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1086: } elsif ($action eq 'requestcourses') {
1.247 raeburn 1087: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1088: $rowtotal ++;
1089: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 1090: </table>
1091: </td>
1092: </tr>
1093: <tr>
1094: <td>
1095: <table class="LC_nested">
1096: <tr class="LC_info_row">
1097: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1098: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 1099: &textbookcourses_javascript($settings).
1100: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1101: </table>
1102: </td>
1103: </tr>
1104: <tr>
1105: <td>
1106: <table class="LC_nested">
1107: <tr class="LC_info_row">
1108: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1109: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1110: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 1111: </table>
1112: </td>
1113: </tr>
1114: <tr>
1115: <td>
1116: <table class="LC_nested">
1117: <tr class="LC_info_row">
1.306 raeburn 1118: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1119: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1120: </tr>'.
1121: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1122: } elsif ($action eq 'requestauthor') {
1123: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1124: $rowtotal ++;
1.122 jms 1125: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1126: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1127: </table>
1128: </td>
1129: </tr>
1130: <tr>
1131: <td>
1132: <table class="LC_nested">
1133: <tr class="LC_info_row">
1.306 raeburn 1134: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1135: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1136: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1137: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1138: </tr>'.
1.30 raeburn 1139: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1140: </table>
1141: </td>
1142: </tr>
1143: <tr>
1144: <td>
1145: <table class="LC_nested">
1146: <tr class="LC_info_row">
1.59 bisitz 1147: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1148: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1149: </tr>'.
1.30 raeburn 1150: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1151: $rowtotal += 2;
1.6 raeburn 1152: }
1.3 raeburn 1153: } else {
1.30 raeburn 1154: $output .= '
1.3 raeburn 1155: <tr>
1156: <td>
1157: <table class="LC_nested">
1.30 raeburn 1158: <tr class="LC_info_row">';
1.277 raeburn 1159: if ($action eq 'login') {
1.30 raeburn 1160: $output .= '
1.59 bisitz 1161: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1162: } elsif ($action eq 'serverstatuses') {
1163: $output .= '
1.306 raeburn 1164: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1165: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1166:
1.6 raeburn 1167: } else {
1.30 raeburn 1168: $output .= '
1.306 raeburn 1169: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1170: }
1.72 raeburn 1171: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1172: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1173: &mt($item->{'header'}->[0]->{'col2'});
1174: if ($action eq 'serverstatuses') {
1175: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1176: }
1.69 raeburn 1177: } else {
1.306 raeburn 1178: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1179: &mt($item->{'header'}->[0]->{'col2'});
1180: }
1181: $output .= '</td>';
1182: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1183: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1184: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1185: &mt($item->{'header'}->[0]->{'col3'});
1186: } else {
1.306 raeburn 1187: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1188: &mt($item->{'header'}->[0]->{'col3'});
1189: }
1.69 raeburn 1190: if ($action eq 'serverstatuses') {
1191: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1192: }
1193: $output .= '</td>';
1.6 raeburn 1194: }
1.150 raeburn 1195: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1196: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1197: &mt($item->{'header'}->[0]->{'col4'});
1198: }
1.69 raeburn 1199: $output .= '</tr>';
1.48 raeburn 1200: $rowtotal ++;
1.168 raeburn 1201: if ($action eq 'quotas') {
1.86 raeburn 1202: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1203: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1204: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.372 raeburn 1205: ($action eq 'ltitools') || ($action eq 'lti') ||
1206: ($action eq 'proctoring')) {
1.230 raeburn 1207: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1208: }
1.3 raeburn 1209: }
1.30 raeburn 1210: $output .= '
1.3 raeburn 1211: </table>
1212: </td>
1213: </tr>
1.30 raeburn 1214: </table><br />';
1215: return ($output,$rowtotal);
1.1 raeburn 1216: }
1217:
1.3 raeburn 1218: sub print_login {
1.168 raeburn 1219: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 1220: my ($css_class,$datatable);
1.6 raeburn 1221: my %choices = &login_choices();
1.110 raeburn 1222:
1.168 raeburn 1223: if ($caller eq 'service') {
1.149 raeburn 1224: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1225: my $choice = $choices{'disallowlogin'};
1226: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1227: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1228: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1229: '<th>'.$choices{'server'}.'</th>'.
1230: '<th>'.$choices{'serverpath'}.'</th>'.
1231: '<th>'.$choices{'custompath'}.'</th>'.
1232: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1233: my %disallowed;
1234: if (ref($settings) eq 'HASH') {
1235: if (ref($settings->{'loginvia'}) eq 'HASH') {
1236: %disallowed = %{$settings->{'loginvia'}};
1237: }
1238: }
1239: foreach my $lonhost (sort(keys(%servers))) {
1240: my $direct = 'selected="selected"';
1.128 raeburn 1241: if (ref($disallowed{$lonhost}) eq 'HASH') {
1242: if ($disallowed{$lonhost}{'server'} ne '') {
1243: $direct = '';
1244: }
1.110 raeburn 1245: }
1.115 raeburn 1246: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1247: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1248: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1249: '</option>';
1.184 raeburn 1250: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1251: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1252: my $selected = '';
1.128 raeburn 1253: if (ref($disallowed{$lonhost}) eq 'HASH') {
1254: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1255: $selected = 'selected="selected"';
1256: }
1.110 raeburn 1257: }
1258: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1259: $servers{$hostid}.'</option>';
1260: }
1.128 raeburn 1261: $datatable .= '</select></td>'.
1262: '<td><select name="'.$lonhost.'_serverpath">';
1263: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1264: my $pathname = $path;
1265: if ($path eq 'custom') {
1266: $pathname = &mt('Custom Path').' ->';
1267: }
1268: my $selected = '';
1269: if (ref($disallowed{$lonhost}) eq 'HASH') {
1270: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1271: $selected = 'selected="selected"';
1272: }
1273: } elsif ($path eq '') {
1274: $selected = 'selected="selected"';
1275: }
1276: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1277: }
1278: $datatable .= '</select></td>';
1279: my ($custom,$exempt);
1280: if (ref($disallowed{$lonhost}) eq 'HASH') {
1281: $custom = $disallowed{$lonhost}{'custompath'};
1282: $exempt = $disallowed{$lonhost}{'exempt'};
1283: }
1284: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1285: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1286: '</tr>';
1.110 raeburn 1287: }
1288: $datatable .= '</table></td></tr>';
1289: return $datatable;
1.168 raeburn 1290: } elsif ($caller eq 'page') {
1291: my %defaultchecked = (
1292: 'coursecatalog' => 'on',
1.188 raeburn 1293: 'helpdesk' => 'on',
1.168 raeburn 1294: 'adminmail' => 'off',
1295: 'newuser' => 'off',
1296: );
1.188 raeburn 1297: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1298: my (%checkedon,%checkedoff);
1.42 raeburn 1299: foreach my $item (@toggles) {
1.168 raeburn 1300: if ($defaultchecked{$item} eq 'on') {
1301: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1302: $checkedoff{$item} = ' ';
1.168 raeburn 1303: } elsif ($defaultchecked{$item} eq 'off') {
1304: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1305: $checkedon{$item} = ' ';
1306: }
1.1 raeburn 1307: }
1.168 raeburn 1308: my @images = ('img','logo','domlogo','login');
1309: my @logintext = ('textcol','bgcol');
1310: my @bgs = ('pgbg','mainbg','sidebg');
1311: my @links = ('link','alink','vlink');
1312: my %designhash = &Apache::loncommon::get_domainconf($dom);
1313: my %defaultdesign = %Apache::loncommon::defaultdesign;
1314: my (%is_custom,%designs);
1315: my %defaults = (
1316: font => $defaultdesign{'login.font'},
1317: );
1.6 raeburn 1318: foreach my $item (@images) {
1.168 raeburn 1319: $defaults{$item} = $defaultdesign{'login.'.$item};
1320: $defaults{'showlogo'}{$item} = 1;
1321: }
1322: foreach my $item (@bgs) {
1323: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1324: }
1.41 raeburn 1325: foreach my $item (@logintext) {
1.168 raeburn 1326: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1327: }
1.168 raeburn 1328: foreach my $item (@links) {
1329: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1330: }
1.168 raeburn 1331: if (ref($settings) eq 'HASH') {
1332: foreach my $item (@toggles) {
1333: if ($settings->{$item} eq '1') {
1334: $checkedon{$item} = ' checked="checked" ';
1335: $checkedoff{$item} = ' ';
1336: } elsif ($settings->{$item} eq '0') {
1337: $checkedoff{$item} = ' checked="checked" ';
1338: $checkedon{$item} = ' ';
1339: }
1340: }
1341: foreach my $item (@images) {
1342: if (defined($settings->{$item})) {
1343: $designs{$item} = $settings->{$item};
1344: $is_custom{$item} = 1;
1345: }
1346: if (defined($settings->{'showlogo'}{$item})) {
1347: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1348: }
1349: }
1350: foreach my $item (@logintext) {
1351: if ($settings->{$item} ne '') {
1352: $designs{'logintext'}{$item} = $settings->{$item};
1353: $is_custom{$item} = 1;
1354: }
1355: }
1356: if ($settings->{'font'} ne '') {
1357: $designs{'font'} = $settings->{'font'};
1358: $is_custom{'font'} = 1;
1359: }
1360: foreach my $item (@bgs) {
1361: if ($settings->{$item} ne '') {
1362: $designs{'bgs'}{$item} = $settings->{$item};
1363: $is_custom{$item} = 1;
1364: }
1365: }
1366: foreach my $item (@links) {
1367: if ($settings->{$item} ne '') {
1368: $designs{'links'}{$item} = $settings->{$item};
1369: $is_custom{$item} = 1;
1370: }
1371: }
1372: } else {
1373: if ($designhash{$dom.'.login.font'} ne '') {
1374: $designs{'font'} = $designhash{$dom.'.login.font'};
1375: $is_custom{'font'} = 1;
1376: }
1377: foreach my $item (@images) {
1378: if ($designhash{$dom.'.login.'.$item} ne '') {
1379: $designs{$item} = $designhash{$dom.'.login.'.$item};
1380: $is_custom{$item} = 1;
1381: }
1382: }
1383: foreach my $item (@bgs) {
1384: if ($designhash{$dom.'.login.'.$item} ne '') {
1385: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1386: $is_custom{$item} = 1;
1387: }
1.6 raeburn 1388: }
1.168 raeburn 1389: foreach my $item (@links) {
1390: if ($designhash{$dom.'.login.'.$item} ne '') {
1391: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1392: $is_custom{$item} = 1;
1393: }
1.6 raeburn 1394: }
1395: }
1.168 raeburn 1396: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1397: logo => 'Institution Logo',
1398: domlogo => 'Domain Logo',
1399: login => 'Login box');
1400: my $itemcount = 1;
1401: foreach my $item (@toggles) {
1402: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1403: $datatable .=
1404: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1405: '</td><td>'.
1406: '<span class="LC_nobreak"><label><input type="radio" name="'.
1407: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1408: '</label> <label><input type="radio" name="'.$item.'"'.
1409: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1410: '</tr>';
1411: $itemcount ++;
1.6 raeburn 1412: }
1.168 raeburn 1413: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1414: $datatable .= '</tr></table></td></tr>';
1415: } elsif ($caller eq 'help') {
1416: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1417: my $switchserver = &check_switchserver($dom,$confname);
1418: my $itemcount = 1;
1419: $defaulturl = '/adm/loginproblems.html';
1420: $defaulttype = 'default';
1421: %lt = &Apache::lonlocal::texthash (
1422: del => 'Delete?',
1423: rep => 'Replace:',
1424: upl => 'Upload:',
1425: default => 'Default',
1426: custom => 'Custom',
1427: );
1428: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1429: my @currlangs;
1430: if (ref($settings) eq 'HASH') {
1431: if (ref($settings->{'helpurl'}) eq 'HASH') {
1432: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1433: next if ($settings->{'helpurl'}{$key} eq '');
1434: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1435: $type{$key} = 'custom';
1436: unless ($key eq 'nolang') {
1437: push(@currlangs,$key);
1438: }
1439: }
1440: } elsif ($settings->{'helpurl'} ne '') {
1441: $type{'nolang'} = 'custom';
1442: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1443: }
1444: }
1.168 raeburn 1445: foreach my $lang ('nolang',sort(@currlangs)) {
1446: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1447: $datatable .= '<tr'.$css_class.'>';
1448: if ($url{$lang} eq '') {
1449: $url{$lang} = $defaulturl;
1450: }
1451: if ($type{$lang} eq '') {
1452: $type{$lang} = $defaulttype;
1453: }
1454: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1455: if ($lang eq 'nolang') {
1456: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1457: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1458: } else {
1459: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1460: $langchoices{$lang},
1461: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1462: }
1463: $datatable .= '</span></td>'."\n".
1464: '<td class="LC_left_item">';
1465: if ($type{$lang} eq 'custom') {
1466: $datatable .= '<span class="LC_nobreak"><label>'.
1467: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1468: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1469: } else {
1470: $datatable .= $lt{'upl'};
1471: }
1472: $datatable .='<br />';
1473: if ($switchserver) {
1474: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1475: } else {
1476: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1477: }
1.168 raeburn 1478: $datatable .= '</td></tr>';
1479: $itemcount ++;
1.6 raeburn 1480: }
1.168 raeburn 1481: my @addlangs;
1482: foreach my $lang (sort(keys(%langchoices))) {
1483: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1484: push(@addlangs,$lang);
1485: }
1486: if (@addlangs > 0) {
1487: my %toadd;
1488: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1489: $toadd{''} = &mt('Select');
1490: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1491: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1492: &mt('Add log-in help page for a specific language:').' '.
1493: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1494: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1495: if ($switchserver) {
1496: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1497: } else {
1498: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1499: }
1.168 raeburn 1500: $datatable .= '</td></tr>';
1.169 raeburn 1501: $itemcount ++;
1.6 raeburn 1502: }
1.169 raeburn 1503: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1504: } elsif ($caller eq 'headtag') {
1505: my %domservers = &Apache::lonnet::get_servers($dom);
1506: my $choice = $choices{'headtag'};
1507: $css_class = ' class="LC_odd_row"';
1508: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1509: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1510: '<th>'.$choices{'current'}.'</th>'.
1511: '<th>'.$choices{'action'}.'</th>'.
1512: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1513: my (%currurls,%currexempt);
1514: if (ref($settings) eq 'HASH') {
1515: if (ref($settings->{'headtag'}) eq 'HASH') {
1516: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1517: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1518: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1519: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1520: }
1521: }
1522: }
1523: }
1524: my %lt = &Apache::lonlocal::texthash(
1525: del => 'Delete?',
1526: rep => 'Replace:',
1527: upl => 'Upload:',
1528: curr => 'View contents',
1529: none => 'None',
1530: );
1531: my $switchserver = &check_switchserver($dom,$confname);
1532: foreach my $lonhost (sort(keys(%domservers))) {
1533: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1534: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1535: if ($currurls{$lonhost}) {
1536: $datatable .= '<td class="LC_right_item"><a href="'.
1537: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1538: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1539: '">'.$lt{'curr'}.'</a></td>'.
1540: '<td><span class="LC_nobreak"><label>'.
1541: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1542: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1543: } else {
1544: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1545: }
1546: $datatable .='<br />';
1547: if ($switchserver) {
1548: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1549: } else {
1550: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1551: }
1.330 raeburn 1552: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1553: }
1554: $datatable .= '</table></td></tr>';
1.1 raeburn 1555: }
1.6 raeburn 1556: return $datatable;
1557: }
1558:
1559: sub login_choices {
1560: my %choices =
1561: &Apache::lonlocal::texthash (
1.116 bisitz 1562: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1563: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1564: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1565: disallowlogin => "Login page requests redirected",
1566: hostid => "Server",
1.128 raeburn 1567: server => "Redirect to:",
1568: serverpath => "Path",
1569: custompath => "Custom",
1570: exempt => "Exempt IP(s)",
1.110 raeburn 1571: directlogin => "No redirect",
1572: newuser => "Link to create a user account",
1573: img => "Header",
1574: logo => "Main Logo",
1575: domlogo => "Domain Logo",
1576: login => "Log-in Header",
1577: textcol => "Text color",
1578: bgcol => "Box color",
1579: bgs => "Background colors",
1580: links => "Link colors",
1581: font => "Font color",
1582: pgbg => "Header",
1583: mainbg => "Page",
1584: sidebg => "Login box",
1585: link => "Link",
1586: alink => "Active link",
1587: vlink => "Visited link",
1.256 raeburn 1588: headtag => "Custom markup",
1589: action => "Action",
1590: current => "Current",
1.6 raeburn 1591: );
1592: return %choices;
1593: }
1594:
1595: sub print_rolecolors {
1.30 raeburn 1596: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1597: my %choices = &color_font_choices();
1598: my @bgs = ('pgbg','tabbg','sidebg');
1599: my @links = ('link','alink','vlink');
1600: my @images = ('img');
1601: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1602: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1603: my %defaultdesign = %Apache::loncommon::defaultdesign;
1604: my (%is_custom,%designs);
1.200 raeburn 1605: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1606: if (ref($settings) eq 'HASH') {
1607: if (ref($settings->{$role}) eq 'HASH') {
1608: if ($settings->{$role}->{'img'} ne '') {
1609: $designs{'img'} = $settings->{$role}->{'img'};
1610: $is_custom{'img'} = 1;
1611: }
1612: if ($settings->{$role}->{'font'} ne '') {
1613: $designs{'font'} = $settings->{$role}->{'font'};
1614: $is_custom{'font'} = 1;
1615: }
1.97 tempelho 1616: if ($settings->{$role}->{'fontmenu'} ne '') {
1617: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1618: $is_custom{'fontmenu'} = 1;
1619: }
1.6 raeburn 1620: foreach my $item (@bgs) {
1621: if ($settings->{$role}->{$item} ne '') {
1622: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1623: $is_custom{$item} = 1;
1624: }
1625: }
1626: foreach my $item (@links) {
1627: if ($settings->{$role}->{$item} ne '') {
1628: $designs{'links'}{$item} = $settings->{$role}->{$item};
1629: $is_custom{$item} = 1;
1630: }
1631: }
1632: }
1633: } else {
1634: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1635: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1636: $is_custom{'img'} = 1;
1637: }
1.97 tempelho 1638: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1639: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1640: $is_custom{'fontmenu'} = 1;
1641: }
1.6 raeburn 1642: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1643: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1644: $is_custom{'font'} = 1;
1645: }
1646: foreach my $item (@bgs) {
1647: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1648: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1649: $is_custom{$item} = 1;
1650:
1651: }
1652: }
1653: foreach my $item (@links) {
1654: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1655: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1656: $is_custom{$item} = 1;
1657: }
1658: }
1659: }
1660: my $itemcount = 1;
1.30 raeburn 1661: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1662: $datatable .= '</tr></table></td></tr>';
1663: return $datatable;
1664: }
1665:
1.200 raeburn 1666: sub role_defaults {
1667: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1668: my %defaults;
1669: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1670: return %defaults;
1671: }
1672: my %defaultdesign = %Apache::loncommon::defaultdesign;
1673: if ($role eq 'login') {
1674: %defaults = (
1675: font => $defaultdesign{$role.'.font'},
1676: );
1677: if (ref($logintext) eq 'ARRAY') {
1678: foreach my $item (@{$logintext}) {
1679: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1680: }
1681: }
1682: foreach my $item (@{$images}) {
1683: $defaults{'showlogo'}{$item} = 1;
1684: }
1685: } else {
1686: %defaults = (
1687: img => $defaultdesign{$role.'.img'},
1688: font => $defaultdesign{$role.'.font'},
1689: fontmenu => $defaultdesign{$role.'.fontmenu'},
1690: );
1691: }
1692: foreach my $item (@{$bgs}) {
1693: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1694: }
1695: foreach my $item (@{$links}) {
1696: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1697: }
1698: foreach my $item (@{$images}) {
1699: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1700: }
1701: return %defaults;
1702: }
1703:
1.6 raeburn 1704: sub display_color_options {
1.9 raeburn 1705: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1706: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1707: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1708: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1709: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1710: '<td>'.$choices->{'font'}.'</td>';
1711: if (!$is_custom->{'font'}) {
1.329 raeburn 1712: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1713: } else {
1714: $datatable .= '<td> </td>';
1715: }
1.174 foxr 1716: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1717:
1.8 raeburn 1718: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1719: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1720: ' value="'.$current_color.'" /> '.
1.329 raeburn 1721: ' </span></td></tr>';
1.107 raeburn 1722: unless ($role eq 'login') {
1723: $datatable .= '<tr'.$css_class.'>'.
1724: '<td>'.$choices->{'fontmenu'}.'</td>';
1725: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 1726: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1727: } else {
1728: $datatable .= '<td> </td>';
1729: }
1.202 raeburn 1730: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1731: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1732: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1733: '<input class="colorchooser" type="text" size="10" name="'
1734: .$role.'_fontmenu"'.
1735: ' value="'.$current_color.'" /> '.
1.329 raeburn 1736: ' </span></td></tr>';
1.97 tempelho 1737: }
1.9 raeburn 1738: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1739: foreach my $img (@{$images}) {
1.18 albertel 1740: $itemcount ++;
1.6 raeburn 1741: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1742: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1743: '<td>'.$choices->{$img};
1.41 raeburn 1744: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1745: if ($role eq 'login') {
1746: if ($img eq 'login') {
1747: $login_hdr_pick =
1.135 bisitz 1748: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1749: $logincolors =
1750: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1751: $designs,$defaults);
1.70 raeburn 1752: } elsif ($img ne 'domlogo') {
1753: $datatable.= &logo_display_options($img,$defaults,$designs);
1754: }
1755: }
1756: $datatable .= '</td>';
1.6 raeburn 1757: if ($designs->{$img} ne '') {
1758: $imgfile = $designs->{$img};
1.18 albertel 1759: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1760: } else {
1761: $imgfile = $defaults->{$img};
1762: }
1763: if ($imgfile) {
1.9 raeburn 1764: my ($showfile,$fullsize);
1765: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1766: my $urldir = $1;
1767: my $filename = $2;
1768: my @info = &Apache::lonnet::stat_file($designs->{$img});
1769: if (@info) {
1770: my $thumbfile = 'tn-'.$filename;
1771: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1772: if (@thumb) {
1773: $showfile = $urldir.'/'.$thumbfile;
1774: } else {
1775: $showfile = $imgfile;
1776: }
1777: } else {
1778: $showfile = '';
1779: }
1780: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1781: $showfile = $imgfile;
1.6 raeburn 1782: my $imgdir = $1;
1783: my $filename = $2;
1.159 raeburn 1784: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1785: $showfile = "/$imgdir/tn-".$filename;
1786: } else {
1.159 raeburn 1787: my $input = $londocroot.$imgfile;
1788: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1789: if (!-e $output) {
1.9 raeburn 1790: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1791: my ($fullwidth,$fullheight) = &check_dimensions($input);
1792: if ($fullwidth ne '' && $fullheight ne '') {
1793: if ($fullwidth > $width && $fullheight > $height) {
1794: my $size = $width.'x'.$height;
1.316 raeburn 1795: my @args = ('convert','-sample',$size,$input,$output);
1796: system({$args[0]} @args);
1.159 raeburn 1797: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1798: }
1799: }
1.6 raeburn 1800: }
1801: }
1.16 raeburn 1802: }
1.6 raeburn 1803: if ($showfile) {
1.40 raeburn 1804: if ($showfile =~ m{^/(adm|res)/}) {
1805: if ($showfile =~ m{^/res/}) {
1806: my $local_showfile =
1807: &Apache::lonnet::filelocation('',$showfile);
1808: &Apache::lonnet::repcopy($local_showfile);
1809: }
1810: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1811: }
1812: if ($imgfile) {
1813: if ($imgfile =~ m{^/(adm|res)/}) {
1814: if ($imgfile =~ m{^/res/}) {
1815: my $local_imgfile =
1816: &Apache::lonnet::filelocation('',$imgfile);
1817: &Apache::lonnet::repcopy($local_imgfile);
1818: }
1819: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1820: } else {
1821: $fullsize = $imgfile;
1822: }
1823: }
1.41 raeburn 1824: $datatable .= '<td>';
1825: if ($img eq 'login') {
1.135 bisitz 1826: $datatable .= $login_hdr_pick;
1827: }
1.41 raeburn 1828: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1829: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1830: } else {
1.201 raeburn 1831: $datatable .= '<td> </td><td class="LC_left_item">'.
1832: &mt('Upload:').'<br />';
1.6 raeburn 1833: }
1834: } else {
1.201 raeburn 1835: $datatable .= '<td> </td><td class="LC_left_item">'.
1836: &mt('Upload:').'<br />';
1.6 raeburn 1837: }
1.9 raeburn 1838: if ($switchserver) {
1839: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1840: } else {
1.135 bisitz 1841: if ($img ne 'login') { # suppress file selection for Log-in header
1842: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1843: }
1.9 raeburn 1844: }
1845: $datatable .= '</td></tr>';
1.6 raeburn 1846: }
1847: $itemcount ++;
1848: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1849: $datatable .= '<tr'.$css_class.'>'.
1850: '<td>'.$choices->{'bgs'}.'</td>';
1851: my $bgs_def;
1852: foreach my $item (@{$bgs}) {
1853: if (!$is_custom->{$item}) {
1.329 raeburn 1854: $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 1855: }
1856: }
1857: if ($bgs_def) {
1.8 raeburn 1858: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1859: } else {
1860: $datatable .= '<td> </td>';
1861: }
1862: $datatable .= '<td class="LC_right_item">'.
1863: '<table border="0"><tr>';
1.174 foxr 1864:
1.6 raeburn 1865: foreach my $item (@{$bgs}) {
1.306 raeburn 1866: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 1867: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1868: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1869: $datatable .= ' ';
1.6 raeburn 1870: }
1.174 foxr 1871: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1872: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1873: }
1874: $datatable .= '</tr></table></td></tr>';
1875: $itemcount ++;
1876: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1877: $datatable .= '<tr'.$css_class.'>'.
1878: '<td>'.$choices->{'links'}.'</td>';
1879: my $links_def;
1880: foreach my $item (@{$links}) {
1881: if (!$is_custom->{$item}) {
1.329 raeburn 1882: $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 1883: }
1884: }
1885: if ($links_def) {
1.8 raeburn 1886: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1887: } else {
1888: $datatable .= '<td> </td>';
1889: }
1890: $datatable .= '<td class="LC_right_item">'.
1891: '<table border="0"><tr>';
1892: foreach my $item (@{$links}) {
1.234 raeburn 1893: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 1894: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 1895: if ($designs->{'links'}{$item}) {
1.174 foxr 1896: $datatable.=' ';
1.6 raeburn 1897: }
1.174 foxr 1898: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1899: '" /></td>';
1900: }
1.30 raeburn 1901: $$rowtotal += $itemcount;
1.3 raeburn 1902: return $datatable;
1903: }
1904:
1.70 raeburn 1905: sub logo_display_options {
1906: my ($img,$defaults,$designs) = @_;
1907: my $checkedon;
1908: if (ref($defaults) eq 'HASH') {
1909: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1910: if ($defaults->{'showlogo'}{$img}) {
1911: $checkedon = 'checked="checked" ';
1912: }
1913: }
1914: }
1915: if (ref($designs) eq 'HASH') {
1916: if (ref($designs->{'showlogo'}) eq 'HASH') {
1917: if (defined($designs->{'showlogo'}{$img})) {
1918: if ($designs->{'showlogo'}{$img} == 0) {
1919: $checkedon = '';
1920: } elsif ($designs->{'showlogo'}{$img} == 1) {
1921: $checkedon = 'checked="checked" ';
1922: }
1923: }
1924: }
1925: }
1926: return '<br /><label> <input type="checkbox" name="'.
1927: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1928: &mt('show').'</label>'."\n";
1929: }
1930:
1.41 raeburn 1931: sub login_header_options {
1.135 bisitz 1932: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1933: my $output = '';
1.41 raeburn 1934: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1935: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1936: if (!$is_custom->{'textcol'}) {
1937: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1938: ' ';
1939: }
1940: if (!$is_custom->{'bgcol'}) {
1941: $output .= $choices->{'bgcol'}.': '.
1942: '<span id="css_'.$role.'_font" style="background-color: '.
1943: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1944: }
1945: $output .= '<br />';
1946: }
1947: $output .='<br />';
1948: return $output;
1949: }
1950:
1951: sub login_text_colors {
1.201 raeburn 1952: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1953: my $color_menu = '<table border="0"><tr>';
1954: foreach my $item (@{$logintext}) {
1.306 raeburn 1955: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 1956: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1957: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1958: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1959: }
1960: $color_menu .= '</tr></table><br />';
1961: return $color_menu;
1962: }
1963:
1964: sub image_changes {
1965: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1966: my $output;
1.135 bisitz 1967: if ($img eq 'login') {
1.331 raeburn 1968: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 1969: } elsif (!$is_custom) {
1.70 raeburn 1970: if ($img ne 'domlogo') {
1.331 raeburn 1971: $output = &mt('Default image:').'<br />';
1.41 raeburn 1972: } else {
1.331 raeburn 1973: $output = &mt('Default in use:').'<br />';
1.41 raeburn 1974: }
1975: }
1.331 raeburn 1976: if ($img ne 'login') {
1.135 bisitz 1977: if ($img_import) {
1978: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1979: }
1980: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1981: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1982: if ($is_custom) {
1983: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1984: '<input type="checkbox" name="'.
1985: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1986: '</label> '.&mt('Replace:').'</span><br />';
1987: } else {
1.306 raeburn 1988: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1989: }
1.41 raeburn 1990: }
1991: return $output;
1992: }
1993:
1.3 raeburn 1994: sub print_quotas {
1.86 raeburn 1995: my ($dom,$settings,$rowtotal,$action) = @_;
1996: my $context;
1997: if ($action eq 'quotas') {
1998: $context = 'tools';
1999: } else {
2000: $context = $action;
2001: }
1.197 raeburn 2002: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 2003: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2004: my $typecount = 0;
1.101 raeburn 2005: my ($css_class,%titles);
1.86 raeburn 2006: if ($context eq 'requestcourses') {
1.325 raeburn 2007: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 2008: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2009: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2010: %titles = &courserequest_titles();
1.163 raeburn 2011: } elsif ($context eq 'requestauthor') {
2012: @usertools = ('author');
2013: @options = ('norequest','approval','automatic');
1.210 raeburn 2014: %titles = &authorrequest_titles();
1.86 raeburn 2015: } else {
1.162 raeburn 2016: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 2017: %titles = &tool_titles();
1.86 raeburn 2018: }
1.26 raeburn 2019: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2020: foreach my $type (@{$types}) {
1.197 raeburn 2021: my ($currdefquota,$currauthorquota);
1.163 raeburn 2022: unless (($context eq 'requestcourses') ||
2023: ($context eq 'requestauthor')) {
1.86 raeburn 2024: if (ref($settings) eq 'HASH') {
2025: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 2026: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2027: } else {
2028: $currdefquota = $settings->{$type};
2029: }
1.197 raeburn 2030: if (ref($settings->{authorquota}) eq 'HASH') {
2031: $currauthorquota = $settings->{authorquota}->{$type};
2032: }
1.78 raeburn 2033: }
1.72 raeburn 2034: }
1.3 raeburn 2035: if (defined($usertypes->{$type})) {
2036: $typecount ++;
2037: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2038: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2039: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2040: '<td class="LC_left_item">';
1.101 raeburn 2041: if ($context eq 'requestcourses') {
2042: $datatable .= '<table><tr>';
2043: }
2044: my %cell;
1.72 raeburn 2045: foreach my $item (@usertools) {
1.101 raeburn 2046: if ($context eq 'requestcourses') {
2047: my ($curroption,$currlimit);
2048: if (ref($settings) eq 'HASH') {
2049: if (ref($settings->{$item}) eq 'HASH') {
2050: $curroption = $settings->{$item}->{$type};
2051: if ($curroption =~ /^autolimit=(\d*)$/) {
2052: $currlimit = $1;
2053: }
2054: }
2055: }
2056: if (!$curroption) {
2057: $curroption = 'norequest';
2058: }
2059: $datatable .= '<th>'.$titles{$item}.'</th>';
2060: foreach my $option (@options) {
2061: my $val = $option;
2062: if ($option eq 'norequest') {
2063: $val = 0;
2064: }
2065: if ($option eq 'validate') {
2066: my $canvalidate = 0;
2067: if (ref($validations{$item}) eq 'HASH') {
2068: if ($validations{$item}{$type}) {
2069: $canvalidate = 1;
2070: }
2071: }
2072: next if (!$canvalidate);
2073: }
2074: my $checked = '';
2075: if ($option eq $curroption) {
2076: $checked = ' checked="checked"';
2077: } elsif ($option eq 'autolimit') {
2078: if ($curroption =~ /^autolimit/) {
2079: $checked = ' checked="checked"';
2080: }
2081: }
2082: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2083: '<input type="radio" name="crsreq_'.$item.
2084: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2085: $titles{$option}.'</label>';
1.101 raeburn 2086: if ($option eq 'autolimit') {
1.127 raeburn 2087: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2088: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2089: 'value="'.$currlimit.'" />';
1.101 raeburn 2090: }
1.127 raeburn 2091: $cell{$item} .= '</span> ';
1.103 raeburn 2092: if ($option eq 'autolimit') {
1.127 raeburn 2093: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2094: }
1.101 raeburn 2095: }
1.163 raeburn 2096: } elsif ($context eq 'requestauthor') {
2097: my $curroption;
2098: if (ref($settings) eq 'HASH') {
2099: $curroption = $settings->{$type};
2100: }
2101: if (!$curroption) {
2102: $curroption = 'norequest';
2103: }
2104: foreach my $option (@options) {
2105: my $val = $option;
2106: if ($option eq 'norequest') {
2107: $val = 0;
2108: }
2109: my $checked = '';
2110: if ($option eq $curroption) {
2111: $checked = ' checked="checked"';
2112: }
2113: $datatable .= '<span class="LC_nobreak"><label>'.
2114: '<input type="radio" name="authorreq_'.$type.
2115: '" value="'.$val.'"'.$checked.' />'.
2116: $titles{$option}.'</label></span> ';
2117: }
1.101 raeburn 2118: } else {
2119: my $checked = 'checked="checked" ';
2120: if (ref($settings) eq 'HASH') {
2121: if (ref($settings->{$item}) eq 'HASH') {
2122: if ($settings->{$item}->{$type} == 0) {
2123: $checked = '';
2124: } elsif ($settings->{$item}->{$type} == 1) {
2125: $checked = 'checked="checked" ';
2126: }
1.78 raeburn 2127: }
1.72 raeburn 2128: }
1.101 raeburn 2129: $datatable .= '<span class="LC_nobreak"><label>'.
2130: '<input type="checkbox" name="'.$context.'_'.$item.
2131: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2132: '</label></span> ';
1.72 raeburn 2133: }
1.101 raeburn 2134: }
2135: if ($context eq 'requestcourses') {
2136: $datatable .= '</tr><tr>';
2137: foreach my $item (@usertools) {
1.106 raeburn 2138: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2139: }
2140: $datatable .= '</tr></table>';
1.72 raeburn 2141: }
1.86 raeburn 2142: $datatable .= '</td>';
1.163 raeburn 2143: unless (($context eq 'requestcourses') ||
2144: ($context eq 'requestauthor')) {
1.86 raeburn 2145: $datatable .=
1.197 raeburn 2146: '<td class="LC_right_item">'.
2147: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2148: '<input type="text" name="quota_'.$type.
1.72 raeburn 2149: '" value="'.$currdefquota.
1.197 raeburn 2150: '" size="5" /></span>'.(' ' x 2).
2151: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2152: '<input type="text" name="authorquota_'.$type.
2153: '" value="'.$currauthorquota.
2154: '" size="5" /></span></td>';
1.86 raeburn 2155: }
2156: $datatable .= '</tr>';
1.3 raeburn 2157: }
2158: }
2159: }
1.163 raeburn 2160: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2161: $defaultquota = '20';
1.197 raeburn 2162: $authorquota = '500';
1.86 raeburn 2163: if (ref($settings) eq 'HASH') {
2164: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2165: $defaultquota = $settings->{'defaultquota'}->{'default'};
2166: } elsif (defined($settings->{'default'})) {
2167: $defaultquota = $settings->{'default'};
2168: }
1.197 raeburn 2169: if (ref($settings->{'authorquota'}) eq 'HASH') {
2170: $authorquota = $settings->{'authorquota'}->{'default'};
2171: }
1.3 raeburn 2172: }
2173: }
2174: $typecount ++;
2175: $css_class = $typecount%2?' class="LC_odd_row"':'';
2176: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2177: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2178: '<td class="LC_left_item">';
1.101 raeburn 2179: if ($context eq 'requestcourses') {
2180: $datatable .= '<table><tr>';
2181: }
2182: my %defcell;
1.72 raeburn 2183: foreach my $item (@usertools) {
1.101 raeburn 2184: if ($context eq 'requestcourses') {
2185: my ($curroption,$currlimit);
2186: if (ref($settings) eq 'HASH') {
2187: if (ref($settings->{$item}) eq 'HASH') {
2188: $curroption = $settings->{$item}->{'default'};
2189: if ($curroption =~ /^autolimit=(\d*)$/) {
2190: $currlimit = $1;
2191: }
2192: }
2193: }
2194: if (!$curroption) {
2195: $curroption = 'norequest';
2196: }
2197: $datatable .= '<th>'.$titles{$item}.'</th>';
2198: foreach my $option (@options) {
2199: my $val = $option;
2200: if ($option eq 'norequest') {
2201: $val = 0;
2202: }
2203: if ($option eq 'validate') {
2204: my $canvalidate = 0;
2205: if (ref($validations{$item}) eq 'HASH') {
2206: if ($validations{$item}{'default'}) {
2207: $canvalidate = 1;
2208: }
2209: }
2210: next if (!$canvalidate);
2211: }
2212: my $checked = '';
2213: if ($option eq $curroption) {
2214: $checked = ' checked="checked"';
2215: } elsif ($option eq 'autolimit') {
2216: if ($curroption =~ /^autolimit/) {
2217: $checked = ' checked="checked"';
2218: }
2219: }
2220: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2221: '<input type="radio" name="crsreq_'.$item.
2222: '_default" value="'.$val.'"'.$checked.' />'.
2223: $titles{$option}.'</label>';
2224: if ($option eq 'autolimit') {
1.127 raeburn 2225: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2226: $item.'_limit_default" size="1" '.
2227: 'value="'.$currlimit.'" />';
2228: }
1.127 raeburn 2229: $defcell{$item} .= '</span> ';
1.104 raeburn 2230: if ($option eq 'autolimit') {
1.127 raeburn 2231: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2232: }
1.101 raeburn 2233: }
1.163 raeburn 2234: } elsif ($context eq 'requestauthor') {
2235: my $curroption;
2236: if (ref($settings) eq 'HASH') {
1.172 raeburn 2237: $curroption = $settings->{'default'};
1.163 raeburn 2238: }
2239: if (!$curroption) {
2240: $curroption = 'norequest';
2241: }
2242: foreach my $option (@options) {
2243: my $val = $option;
2244: if ($option eq 'norequest') {
2245: $val = 0;
2246: }
2247: my $checked = '';
2248: if ($option eq $curroption) {
2249: $checked = ' checked="checked"';
2250: }
2251: $datatable .= '<span class="LC_nobreak"><label>'.
2252: '<input type="radio" name="authorreq_default"'.
2253: ' value="'.$val.'"'.$checked.' />'.
2254: $titles{$option}.'</label></span> ';
2255: }
1.101 raeburn 2256: } else {
2257: my $checked = 'checked="checked" ';
2258: if (ref($settings) eq 'HASH') {
2259: if (ref($settings->{$item}) eq 'HASH') {
2260: if ($settings->{$item}->{'default'} == 0) {
2261: $checked = '';
2262: } elsif ($settings->{$item}->{'default'} == 1) {
2263: $checked = 'checked="checked" ';
2264: }
1.78 raeburn 2265: }
1.72 raeburn 2266: }
1.101 raeburn 2267: $datatable .= '<span class="LC_nobreak"><label>'.
2268: '<input type="checkbox" name="'.$context.'_'.$item.
2269: '" value="default" '.$checked.'/>'.$titles{$item}.
2270: '</label></span> ';
2271: }
2272: }
2273: if ($context eq 'requestcourses') {
2274: $datatable .= '</tr><tr>';
2275: foreach my $item (@usertools) {
1.106 raeburn 2276: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2277: }
1.101 raeburn 2278: $datatable .= '</tr></table>';
1.72 raeburn 2279: }
1.86 raeburn 2280: $datatable .= '</td>';
1.163 raeburn 2281: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2282: $datatable .= '<td class="LC_right_item">'.
2283: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2284: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2285: $defaultquota.'" size="5" /></span>'.(' ' x2).
2286: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2287: '<input type="text" name="authorquota" value="'.
2288: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2289: }
2290: $datatable .= '</tr>';
1.72 raeburn 2291: $typecount ++;
2292: $css_class = $typecount%2?' class="LC_odd_row"':'';
2293: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2294: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2295: if ($context eq 'requestcourses') {
1.109 raeburn 2296: $datatable .= &mt('(overrides affiliation, if set)').
2297: '</td>'.
2298: '<td class="LC_left_item">'.
2299: '<table><tr>';
1.101 raeburn 2300: } else {
1.109 raeburn 2301: $datatable .= &mt('(overrides affiliation, if checked)').
2302: '</td>'.
2303: '<td class="LC_left_item" colspan="2">'.
2304: '<br />';
1.101 raeburn 2305: }
2306: my %advcell;
1.72 raeburn 2307: foreach my $item (@usertools) {
1.101 raeburn 2308: if ($context eq 'requestcourses') {
2309: my ($curroption,$currlimit);
2310: if (ref($settings) eq 'HASH') {
2311: if (ref($settings->{$item}) eq 'HASH') {
2312: $curroption = $settings->{$item}->{'_LC_adv'};
2313: if ($curroption =~ /^autolimit=(\d*)$/) {
2314: $currlimit = $1;
2315: }
2316: }
2317: }
2318: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2319: my $checked = '';
2320: if ($curroption eq '') {
2321: $checked = ' checked="checked"';
2322: }
2323: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2324: '<input type="radio" name="crsreq_'.$item.
2325: '__LC_adv" value=""'.$checked.' />'.
2326: &mt('No override set').'</label></span> ';
1.101 raeburn 2327: foreach my $option (@options) {
2328: my $val = $option;
2329: if ($option eq 'norequest') {
2330: $val = 0;
2331: }
2332: if ($option eq 'validate') {
2333: my $canvalidate = 0;
2334: if (ref($validations{$item}) eq 'HASH') {
2335: if ($validations{$item}{'_LC_adv'}) {
2336: $canvalidate = 1;
2337: }
2338: }
2339: next if (!$canvalidate);
2340: }
2341: my $checked = '';
1.104 raeburn 2342: if ($val eq $curroption) {
1.101 raeburn 2343: $checked = ' checked="checked"';
2344: } elsif ($option eq 'autolimit') {
2345: if ($curroption =~ /^autolimit/) {
2346: $checked = ' checked="checked"';
2347: }
2348: }
2349: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2350: '<input type="radio" name="crsreq_'.$item.
2351: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2352: $titles{$option}.'</label>';
2353: if ($option eq 'autolimit') {
1.127 raeburn 2354: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2355: $item.'_limit__LC_adv" size="1" '.
2356: 'value="'.$currlimit.'" />';
2357: }
1.127 raeburn 2358: $advcell{$item} .= '</span> ';
1.104 raeburn 2359: if ($option eq 'autolimit') {
1.127 raeburn 2360: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2361: }
1.101 raeburn 2362: }
1.163 raeburn 2363: } elsif ($context eq 'requestauthor') {
2364: my $curroption;
2365: if (ref($settings) eq 'HASH') {
2366: $curroption = $settings->{'_LC_adv'};
2367: }
2368: my $checked = '';
2369: if ($curroption eq '') {
2370: $checked = ' checked="checked"';
2371: }
2372: $datatable .= '<span class="LC_nobreak"><label>'.
2373: '<input type="radio" name="authorreq__LC_adv"'.
2374: ' value=""'.$checked.' />'.
2375: &mt('No override set').'</label></span> ';
2376: foreach my $option (@options) {
2377: my $val = $option;
2378: if ($option eq 'norequest') {
2379: $val = 0;
2380: }
2381: my $checked = '';
2382: if ($val eq $curroption) {
2383: $checked = ' checked="checked"';
2384: }
2385: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2386: '<input type="radio" name="authorreq__LC_adv"'.
2387: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2388: $titles{$option}.'</label></span> ';
2389: }
1.101 raeburn 2390: } else {
2391: my $checked = 'checked="checked" ';
2392: if (ref($settings) eq 'HASH') {
2393: if (ref($settings->{$item}) eq 'HASH') {
2394: if ($settings->{$item}->{'_LC_adv'} == 0) {
2395: $checked = '';
2396: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2397: $checked = 'checked="checked" ';
2398: }
1.79 raeburn 2399: }
1.72 raeburn 2400: }
1.101 raeburn 2401: $datatable .= '<span class="LC_nobreak"><label>'.
2402: '<input type="checkbox" name="'.$context.'_'.$item.
2403: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2404: '</label></span> ';
2405: }
2406: }
2407: if ($context eq 'requestcourses') {
2408: $datatable .= '</tr><tr>';
2409: foreach my $item (@usertools) {
1.106 raeburn 2410: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2411: }
1.101 raeburn 2412: $datatable .= '</tr></table>';
1.72 raeburn 2413: }
1.98 raeburn 2414: $datatable .= '</td></tr>';
1.30 raeburn 2415: $$rowtotal += $typecount;
1.3 raeburn 2416: return $datatable;
2417: }
2418:
1.163 raeburn 2419: sub print_requestmail {
1.305 raeburn 2420: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2421: my ($now,$datatable,%currapp);
1.102 raeburn 2422: $now = time;
2423: if (ref($settings) eq 'HASH') {
2424: if (ref($settings->{'notify'}) eq 'HASH') {
2425: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2426: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2427: }
2428: }
2429: }
1.191 raeburn 2430: my $numinrow = 2;
1.224 raeburn 2431: my $css_class;
1.305 raeburn 2432: if ($$rowtotal%2) {
2433: $css_class = 'LC_odd_row';
2434: }
2435: if ($customcss) {
2436: $css_class .= " $customcss";
2437: }
2438: $css_class =~ s/^\s+//;
2439: if ($css_class) {
2440: $css_class = ' class="'.$css_class.'"';
2441: }
2442: if ($rowstyle) {
2443: $css_class .= ' style="'.$rowstyle.'"';
2444: }
1.163 raeburn 2445: my $text;
2446: if ($action eq 'requestcourses') {
2447: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2448: } elsif ($action eq 'requestauthor') {
2449: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2450: } else {
1.224 raeburn 2451: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2452: }
1.224 raeburn 2453: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2454: ' <td>'.$text.'</td>'.
1.102 raeburn 2455: ' <td class="LC_left_item">';
1.191 raeburn 2456: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2457: $action.'notifyapproval',%currapp);
1.191 raeburn 2458: if ($numdc > 0) {
2459: $datatable .= $table;
1.102 raeburn 2460: } else {
2461: $datatable .= &mt('There are no active Domain Coordinators');
2462: }
2463: $datatable .='</td></tr>';
2464: return $datatable;
2465: }
2466:
1.216 raeburn 2467: sub print_studentcode {
2468: my ($settings,$rowtotal) = @_;
2469: my $rownum = 0;
1.218 raeburn 2470: my ($output,%current);
1.325 raeburn 2471: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2472: if (ref($settings) eq 'HASH') {
2473: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2474: foreach my $type (@crstypes) {
2475: $current{$type} = $settings->{'uniquecode'}{$type};
2476: }
1.218 raeburn 2477: }
2478: }
2479: $output .= '<tr>'.
2480: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2481: '<td class="LC_left_item">';
2482: foreach my $type (@crstypes) {
2483: my $check = ' ';
2484: if ($current{$type}) {
2485: $check = ' checked="checked" ';
2486: }
2487: $output .= '<span class="LC_nobreak"><label>'.
2488: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2489: &mt($type).'</label></span>'.(' 'x2).' ';
2490: }
2491: $output .= '</td></tr>';
2492: $$rowtotal ++;
2493: return $output;
1.216 raeburn 2494: }
2495:
2496: sub print_textbookcourses {
1.242 raeburn 2497: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2498: my $rownum = 0;
2499: my $css_class;
2500: my $itemcount = 1;
2501: my $maxnum = 0;
2502: my $bookshash;
2503: if (ref($settings) eq 'HASH') {
1.242 raeburn 2504: $bookshash = $settings->{$type};
1.216 raeburn 2505: }
2506: my %ordered;
2507: if (ref($bookshash) eq 'HASH') {
2508: foreach my $item (keys(%{$bookshash})) {
2509: if (ref($bookshash->{$item}) eq 'HASH') {
2510: my $num = $bookshash->{$item}{'order'};
2511: $ordered{$num} = $item;
2512: }
2513: }
2514: }
2515: my $confname = $dom.'-domainconfig';
2516: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2517: my $maxnum = scalar(keys(%ordered));
2518: my $datatable;
1.216 raeburn 2519: if (keys(%ordered)) {
2520: my @items = sort { $a <=> $b } keys(%ordered);
2521: for (my $i=0; $i<@items; $i++) {
2522: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2523: my $key = $ordered{$items[$i]};
2524: my %coursehash=&Apache::lonnet::coursedescription($key);
2525: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2526: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2527: if (ref($bookshash->{$key}) eq 'HASH') {
2528: $subject = $bookshash->{$key}->{'subject'};
2529: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2530: if ($type eq 'textbooks') {
1.243 raeburn 2531: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2532: $author = $bookshash->{$key}->{'author'};
2533: $image = $bookshash->{$key}->{'image'};
2534: if ($image ne '') {
2535: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2536: my $imagethumb = "$path/tn-".$imagefile;
2537: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2538: }
1.216 raeburn 2539: }
2540: }
1.242 raeburn 2541: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2542: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2543: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2544: for (my $k=0; $k<=$maxnum; $k++) {
2545: my $vpos = $k+1;
2546: my $selstr;
2547: if ($k == $i) {
2548: $selstr = ' selected="selected" ';
2549: }
2550: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2551: }
2552: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2553: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2554: &mt('Delete?').'</label></span></td>'.
2555: '<td colspan="2">'.
1.242 raeburn 2556: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2557: (' 'x2).
1.242 raeburn 2558: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2559: if ($type eq 'textbooks') {
2560: $datatable .= (' 'x2).
1.243 raeburn 2561: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2562: (' 'x2).
1.242 raeburn 2563: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2564: (' 'x2).
2565: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2566: if ($image) {
1.267 raeburn 2567: $datatable .= $imgsrc.
1.242 raeburn 2568: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2569: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2570: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2571: }
2572: if ($switchserver) {
2573: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2574: } else {
2575: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2576: }
1.216 raeburn 2577: }
1.242 raeburn 2578: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2579: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2580: $coursetitle.'</span></td></tr>'."\n";
2581: $itemcount ++;
2582: }
2583: }
2584: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2585: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2586: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2587: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2588: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2589: for (my $k=0; $k<$maxnum+1; $k++) {
2590: my $vpos = $k+1;
2591: my $selstr;
2592: if ($k == $maxnum) {
2593: $selstr = ' selected="selected" ';
2594: }
2595: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2596: }
2597: $datatable .= '</select> '."\n".
1.334 raeburn 2598: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 2599: '<td colspan="2">'.
1.242 raeburn 2600: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2601: (' 'x2).
1.242 raeburn 2602: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2603: (' 'x2);
2604: if ($type eq 'textbooks') {
1.243 raeburn 2605: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2606: (' 'x2).
2607: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2608: (' 'x2).
2609: '<span class="LC_nobreak">'.&mt('Image:').' ';
2610: if ($switchserver) {
2611: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2612: } else {
2613: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2614: }
1.334 raeburn 2615: $datatable .= '</span>'."\n";
1.216 raeburn 2616: }
1.334 raeburn 2617: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2618: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2619: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2620: &Apache::loncommon::selectcourse_link
1.334 raeburn 2621: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 2622: '</span></td>'."\n".
2623: '</tr>'."\n";
2624: $itemcount ++;
2625: return $datatable;
2626: }
2627:
1.217 raeburn 2628: sub textbookcourses_javascript {
1.242 raeburn 2629: my ($settings) = @_;
2630: return unless(ref($settings) eq 'HASH');
2631: my (%ordered,%total,%jstext);
2632: foreach my $type ('textbooks','templates') {
2633: $total{$type} = 0;
2634: if (ref($settings->{$type}) eq 'HASH') {
2635: foreach my $item (keys(%{$settings->{$type}})) {
2636: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2637: my $num = $settings->{$type}->{$item}{'order'};
2638: $ordered{$type}{$num} = $item;
2639: }
2640: }
2641: $total{$type} = scalar(keys(%{$settings->{$type}}));
2642: }
2643: my @jsarray = ();
2644: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2645: push(@jsarray,$ordered{$type}{$item});
2646: }
2647: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2648: }
2649: return <<"ENDSCRIPT";
2650: <script type="text/javascript">
2651: // <![CDATA[
1.242 raeburn 2652: function reorderBooks(form,item,caller) {
1.217 raeburn 2653: var changedVal;
1.242 raeburn 2654: $jstext{'textbooks'};
2655: $jstext{'templates'};
2656: var newpos;
2657: var maxh;
2658: if (caller == 'textbooks') {
2659: newpos = 'textbooks_addbook_pos';
2660: maxh = 1 + $total{'textbooks'};
2661: } else {
2662: newpos = 'templates_addbook_pos';
2663: maxh = 1 + $total{'templates'};
2664: }
1.217 raeburn 2665: var current = new Array;
2666: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2667: if (item == newpos) {
2668: changedVal = newitemVal;
2669: } else {
2670: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2671: current[newitemVal] = newpos;
2672: }
1.242 raeburn 2673: if (caller == 'textbooks') {
2674: for (var i=0; i<textbooks.length; i++) {
2675: var elementName = 'textbooks_'+textbooks[i];
2676: if (elementName != item) {
2677: if (form.elements[elementName]) {
2678: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2679: current[currVal] = elementName;
2680: }
2681: }
2682: }
2683: }
2684: if (caller == 'templates') {
2685: for (var i=0; i<templates.length; i++) {
2686: var elementName = 'templates_'+templates[i];
2687: if (elementName != item) {
2688: if (form.elements[elementName]) {
2689: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2690: current[currVal] = elementName;
2691: }
1.217 raeburn 2692: }
2693: }
2694: }
2695: var oldVal;
2696: for (var j=0; j<maxh; j++) {
2697: if (current[j] == undefined) {
2698: oldVal = j;
2699: }
2700: }
2701: if (oldVal < changedVal) {
2702: for (var k=oldVal+1; k<=changedVal ; k++) {
2703: var elementName = current[k];
2704: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2705: }
2706: } else {
2707: for (var k=changedVal; k<oldVal; k++) {
2708: var elementName = current[k];
2709: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2710: }
2711: }
2712: return;
2713: }
2714:
2715: // ]]>
2716: </script>
2717:
2718: ENDSCRIPT
2719: }
2720:
1.267 raeburn 2721: sub ltitools_javascript {
2722: my ($settings) = @_;
1.319 raeburn 2723: my $togglejs = <itools_toggle_js();
2724: unless (ref($settings) eq 'HASH') {
2725: return $togglejs;
2726: }
1.267 raeburn 2727: my (%ordered,$total,%jstext);
2728: $total = 0;
2729: foreach my $item (keys(%{$settings})) {
2730: if (ref($settings->{$item}) eq 'HASH') {
2731: my $num = $settings->{$item}{'order'};
2732: $ordered{$num} = $item;
2733: }
2734: }
2735: $total = scalar(keys(%{$settings}));
2736: my @jsarray = ();
2737: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2738: push(@jsarray,$ordered{$item});
2739: }
2740: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2741: return <<"ENDSCRIPT";
2742: <script type="text/javascript">
2743: // <![CDATA[
1.319 raeburn 2744: function reorderLTITools(form,item) {
1.267 raeburn 2745: var changedVal;
2746: $jstext
2747: var newpos = 'ltitools_add_pos';
2748: var maxh = 1 + $total;
2749: var current = new Array;
2750: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2751: if (item == newpos) {
2752: changedVal = newitemVal;
2753: } else {
2754: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2755: current[newitemVal] = newpos;
2756: }
2757: for (var i=0; i<ltitools.length; i++) {
2758: var elementName = 'ltitools_'+ltitools[i];
2759: if (elementName != item) {
2760: if (form.elements[elementName]) {
2761: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2762: current[currVal] = elementName;
2763: }
2764: }
2765: }
2766: var oldVal;
2767: for (var j=0; j<maxh; j++) {
2768: if (current[j] == undefined) {
2769: oldVal = j;
2770: }
2771: }
2772: if (oldVal < changedVal) {
2773: for (var k=oldVal+1; k<=changedVal ; k++) {
2774: var elementName = current[k];
2775: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2776: }
2777: } else {
2778: for (var k=changedVal; k<oldVal; k++) {
2779: var elementName = current[k];
2780: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2781: }
2782: }
2783: return;
2784: }
2785:
2786: // ]]>
2787: </script>
2788:
1.319 raeburn 2789: $togglejs
2790:
2791: ENDSCRIPT
2792: }
2793:
2794: sub ltitools_toggle_js {
2795: return <<"ENDSCRIPT";
2796: <script type="text/javascript">
2797: // <![CDATA[
2798:
2799: function toggleLTITools(form,setting,item) {
2800: var radioname = '';
2801: var divid = '';
2802: if ((setting == 'passback') || (setting == 'roster')) {
2803: radioname = 'ltitools_'+setting+'_'+item;
2804: divid = 'ltitools_'+setting+'time_'+item;
2805: var num = form.elements[radioname].length;
2806: if (num) {
2807: var setvis = '';
2808: for (var i=0; i<num; i++) {
2809: if (form.elements[radioname][i].checked) {
2810: if (form.elements[radioname][i].value == '1') {
2811: if (document.getElementById(divid)) {
2812: document.getElementById(divid).style.display = 'inline-block';
2813: }
2814: setvis = 1;
2815: }
2816: break;
2817: }
2818: }
2819: }
2820: if (!setvis) {
2821: if (document.getElementById(divid)) {
2822: document.getElementById(divid).style.display = 'none';
2823: }
2824: }
2825: }
1.324 raeburn 2826: if (setting == 'user') {
2827: divid = 'ltitools_'+setting+'_div_'+item;
2828: var checkid = 'ltitools_'+setting+'_field_'+item;
2829: if (document.getElementById(divid)) {
2830: if (document.getElementById(checkid)) {
2831: if (document.getElementById(checkid).checked) {
2832: document.getElementById(divid).style.display = 'inline-block';
2833: } else {
2834: document.getElementById(divid).style.display = 'none';
2835: }
2836: }
2837: }
2838: }
1.319 raeburn 2839: return;
2840: }
2841: // ]]>
2842: </script>
2843:
1.267 raeburn 2844: ENDSCRIPT
2845: }
2846:
1.372 raeburn 2847: sub proctoring_javascript {
2848: my ($settings) = @_;
2849: my (%ordered,$total,%jstext);
2850: $total = 0;
2851: if (ref($settings) eq 'HASH') {
2852: foreach my $item (keys(%{$settings})) {
2853: if (ref($settings->{$item}) eq 'HASH') {
2854: my $num = $settings->{$item}{'order'};
2855: $ordered{$num} = $item;
2856: }
2857: }
2858: $total = scalar(keys(%{$settings}));
2859: } else {
2860: %ordered = (
2861: 0 => 'proctorio',
2862: 1 => 'examity',
2863: );
2864: $total = 2;
2865: }
2866: my @jsarray = ();
2867: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2868: push(@jsarray,$ordered{$item});
2869: }
2870: my $jstext = ' var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
2871: return <<"ENDSCRIPT";
2872: <script type="text/javascript">
2873: // <![CDATA[
2874: function reorderProctoring(form,item) {
2875: var changedVal;
2876: $jstext
2877: var maxh = $total;
2878: var current = new Array;
2879: var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2880: for (var i=0; i<proctors.length; i++) {
2881: var elementName = 'proctoring_pos_'+proctors[i];
2882: if (elementName != item) {
2883: if (form.elements[elementName]) {
2884: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2885: current[currVal] = elementName;
2886: }
2887: }
2888: }
2889: var oldVal;
2890: for (var j=0; j<maxh; j++) {
2891: if (current[j] == undefined) {
2892: oldVal = j;
2893: }
2894: }
2895: if (oldVal < changedVal) {
2896: for (var k=oldVal+1; k<=changedVal ; k++) {
2897: var elementName = current[k];
2898: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2899: }
2900: } else {
2901: for (var k=changedVal; k<oldVal; k++) {
2902: var elementName = current[k];
2903: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2904: }
2905: }
2906: return;
2907: }
2908:
2909: function toggleProctoring(form,item) {
2910: var fieldsets = document.getElementsByClassName('proctoring_'+item);
2911: if (fieldsets.length) {
2912: var radioname = 'proctoring_available_'+item;
2913: var num = form.elements[radioname].length;
2914: if (num) {
2915: var setvis = '';
2916: for (var i=0; i<num; i++) {
2917: if (form.elements[radioname][i].checked) {
2918: if (form.elements[radioname][i].value == '1') {
2919: setvis = 1;
2920: break;
2921: }
2922: }
2923: }
2924: for (var j=0; j<fieldsets.length; j++) {
2925: if (setvis) {
2926: fieldsets[j].style.display = 'block';
2927: } else {
2928: fieldsets[j].style.display = 'none';
2929: }
2930: }
2931: }
2932: }
2933: return;
2934: }
2935:
2936: // ]]>
2937: </script>
2938:
2939: ENDSCRIPT
2940: }
2941:
2942:
1.320 raeburn 2943: sub lti_javascript {
2944: my ($settings) = @_;
2945: my $togglejs = <i_toggle_js();
2946: unless (ref($settings) eq 'HASH') {
2947: return $togglejs;
2948: }
2949: my (%ordered,$total,%jstext);
2950: $total = 0;
2951: foreach my $item (keys(%{$settings})) {
2952: if (ref($settings->{$item}) eq 'HASH') {
2953: my $num = $settings->{$item}{'order'};
2954: $ordered{$num} = $item;
2955: }
2956: }
2957: $total = scalar(keys(%{$settings}));
2958: my @jsarray = ();
2959: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2960: push(@jsarray,$ordered{$item});
2961: }
2962: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
2963: return <<"ENDSCRIPT";
2964: <script type="text/javascript">
2965: // <![CDATA[
2966: function reorderLTI(form,item) {
2967: var changedVal;
2968: $jstext
2969: var newpos = 'lti_pos_add';
2970: var maxh = 1 + $total;
2971: var current = new Array;
2972: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2973: if (item == newpos) {
2974: changedVal = newitemVal;
2975: } else {
2976: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2977: current[newitemVal] = newpos;
2978: }
2979: for (var i=0; i<lti.length; i++) {
2980: var elementName = 'lti_pos_'+lti[i];
2981: if (elementName != item) {
2982: if (form.elements[elementName]) {
2983: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2984: current[currVal] = elementName;
2985: }
2986: }
2987: }
2988: var oldVal;
2989: for (var j=0; j<maxh; j++) {
2990: if (current[j] == undefined) {
2991: oldVal = j;
2992: }
2993: }
2994: if (oldVal < changedVal) {
2995: for (var k=oldVal+1; k<=changedVal ; k++) {
2996: var elementName = current[k];
2997: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2998: }
2999: } else {
3000: for (var k=changedVal; k<oldVal; k++) {
3001: var elementName = current[k];
3002: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3003: }
3004: }
3005: return;
3006: }
3007: // ]]>
3008: </script>
3009:
3010: $togglejs
3011:
3012: ENDSCRIPT
3013: }
3014:
3015: sub lti_toggle_js {
1.325 raeburn 3016: my %lcauthparmtext = &Apache::lonlocal::texthash (
3017: localauth => 'Local auth argument',
3018: krb => 'Kerberos domain',
3019: );
1.320 raeburn 3020: return <<"ENDSCRIPT";
3021: <script type="text/javascript">
3022: // <![CDATA[
3023:
3024: function toggleLTI(form,setting,item) {
1.345 raeburn 3025: if (setting == 'requser') {
3026: var fieldsets = document.getElementsByClassName('ltioption_'+item);
3027: if (fieldsets.length) {
3028: var radioname = 'lti_'+setting+'_'+item;
3029: var num = form.elements[radioname].length;
3030: if (num) {
3031: var setvis = '';
3032: for (var i=0; i<num; i++) {
3033: if (form.elements[radioname][i].checked) {
3034: if (form.elements[radioname][i].value == '1') {
3035: setvis = 1;
3036: break;
3037: }
3038: }
3039: }
1.352 raeburn 3040: for (var j=0; j<fieldsets.length; j++) {
1.345 raeburn 3041: if (setvis) {
3042: fieldsets[j].style.display = 'block';
3043: } else {
3044: fieldsets[j].style.display = 'none';
3045: }
3046: }
3047: }
3048: }
1.363 raeburn 3049: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320 raeburn 3050: var radioname = '';
3051: var divid = '';
3052: if (setting == 'user') {
3053: radioname = 'lti_mapuser_'+item;
3054: divid = 'lti_userfield_'+item;
1.343 raeburn 3055: } else if (setting == 'crs') {
1.320 raeburn 3056: radioname = 'lti_mapcrs_'+item;
3057: divid = 'lti_crsfield_'+item;
1.363 raeburn 3058: } else if (setting == 'callback') {
3059: radioname = 'lti_callback_'+item;
3060: divid = 'lti_callbackfield_'+item;
1.337 raeburn 3061: } else {
1.351 raeburn 3062: radioname = 'lti_passback_'+item;
1.337 raeburn 3063: divid = 'lti_passback_'+item;
1.320 raeburn 3064: }
3065: var num = form.elements[radioname].length;
3066: if (num) {
3067: var setvis = '';
3068: for (var i=0; i<num; i++) {
3069: if (form.elements[radioname][i].checked) {
1.363 raeburn 3070: if ((setting == 'passback') || (setting == 'callback')) {
1.337 raeburn 3071: if (form.elements[radioname][i].value == '1') {
3072: if (document.getElementById(divid)) {
3073: document.getElementById(divid).style.display = 'inline-block';
3074: }
3075: setvis = 1;
3076: break;
3077: }
3078: } else {
3079: if (form.elements[radioname][i].value == 'other') {
3080: if (document.getElementById(divid)) {
3081: document.getElementById(divid).style.display = 'inline-block';
3082: }
3083: setvis = 1;
3084: break;
1.320 raeburn 3085: }
3086: }
3087: }
3088: }
3089: if (!setvis) {
3090: if (document.getElementById(divid)) {
3091: document.getElementById(divid).style.display = 'none';
3092: }
3093: }
3094: }
3095: } else if ((setting == 'sec') || (setting == 'secsrc')) {
3096: var numsec = form.elements['lti_crssec_'+item].length;
3097: if (numsec) {
3098: var setvis = '';
3099: for (var i=0; i<numsec; i++) {
3100: if (form.elements['lti_crssec_'+item][i].checked) {
3101: if (form.elements['lti_crssec_'+item][i].value == '1') {
3102: if (document.getElementById('lti_crssecfield_'+item)) {
3103: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3104: setvis = 1;
3105: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3106: if (numsrcsec) {
3107: var setsrcvis = '';
3108: for (var j=0; j<numsrcsec; j++) {
3109: if (form.elements['lti_crssecsrc_'+item][j].checked) {
3110: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3111: if (document.getElementById('lti_secsrcfield_'+item)) {
3112: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3113: setsrcvis = 1;
3114: }
3115: }
3116: }
3117: }
3118: if (!setsrcvis) {
3119: if (document.getElementById('lti_secsrcfield_'+item)) {
3120: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3121: }
3122: }
3123: }
3124: }
3125: }
3126: }
3127: }
3128: if (!setvis) {
3129: if (document.getElementById('lti_crssecfield_'+item)) {
3130: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3131: }
3132: if (document.getElementById('lti_secsrcfield_'+item)) {
3133: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3134: }
3135: }
3136: }
1.325 raeburn 3137: } else if (setting == 'lcauth') {
3138: var numauth = form.elements['lti_lcauth_'+item].length;
3139: if (numauth) {
3140: for (var i=0; i<numauth; i++) {
3141: if (form.elements['lti_lcauth_'+item][i].checked) {
3142: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3143: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3144: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3145: } else {
3146: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3147: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3148: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3149: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3150: } else {
3151: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3152: }
3153: }
3154: }
3155: }
3156: }
3157: }
3158: }
1.326 raeburn 3159: } else if (setting == 'lcmenu') {
3160: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3161: var divid = 'lti_menufield_'+item;
3162: var setvis = '';
3163: for (var i=0; i<menus.length; i++) {
3164: var radioname = menus[i];
3165: var num = form.elements[radioname].length;
3166: if (num) {
3167: for (var j=0; j<num; j++) {
3168: if (form.elements[radioname][j].checked) {
3169: if (form.elements[radioname][j].value == '1') {
3170: if (document.getElementById(divid)) {
3171: document.getElementById(divid).style.display = 'inline-block';
3172: }
3173: setvis = 1;
3174: break;
3175: }
3176: }
3177: }
3178: }
3179: if (setvis == 1) {
3180: break;
3181: }
3182: }
3183: if (!setvis) {
3184: if (document.getElementById(divid)) {
3185: document.getElementById(divid).style.display = 'none';
3186: }
3187: }
1.320 raeburn 3188: }
3189: return;
3190: }
3191: // ]]>
3192: </script>
3193:
3194: ENDSCRIPT
3195: }
3196:
1.3 raeburn 3197: sub print_autoenroll {
1.30 raeburn 3198: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3199: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 3200: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 3201: if (ref($settings) eq 'HASH') {
3202: if (exists($settings->{'run'})) {
3203: if ($settings->{'run'} eq '0') {
3204: $runoff = ' checked="checked" ';
3205: $runon = ' ';
3206: } else {
3207: $runon = ' checked="checked" ';
3208: $runoff = ' ';
3209: }
3210: } else {
3211: if ($autorun) {
3212: $runon = ' checked="checked" ';
3213: $runoff = ' ';
3214: } else {
3215: $runoff = ' checked="checked" ';
3216: $runon = ' ';
3217: }
3218: }
1.129 raeburn 3219: if (exists($settings->{'co-owners'})) {
3220: if ($settings->{'co-owners'} eq '0') {
3221: $coownersoff = ' checked="checked" ';
3222: $coownerson = ' ';
3223: } else {
3224: $coownerson = ' checked="checked" ';
3225: $coownersoff = ' ';
3226: }
3227: } else {
3228: $coownersoff = ' checked="checked" ';
3229: $coownerson = ' ';
3230: }
1.3 raeburn 3231: if (exists($settings->{'sender_domain'})) {
3232: $defdom = $settings->{'sender_domain'};
3233: }
1.274 raeburn 3234: if (exists($settings->{'autofailsafe'})) {
3235: $failsafe = $settings->{'autofailsafe'};
3236: }
1.14 raeburn 3237: } else {
3238: if ($autorun) {
3239: $runon = ' checked="checked" ';
3240: $runoff = ' ';
3241: } else {
3242: $runoff = ' checked="checked" ';
3243: $runon = ' ';
3244: }
1.3 raeburn 3245: }
3246: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3247: my $notif_sender;
3248: if (ref($settings) eq 'HASH') {
3249: $notif_sender = $settings->{'sender_uname'};
3250: }
1.3 raeburn 3251: my $datatable='<tr class="LC_odd_row">'.
3252: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3253: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3254: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3255: $runon.' value="1" />'.&mt('Yes').'</label> '.
3256: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3257: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3258: '</tr><tr>'.
3259: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3260: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3261: &mt('username').': '.
3262: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3263: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3264: ': '.$domform.'</span></td></tr>'.
3265: '<tr class="LC_odd_row">'.
3266: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3267: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3268: '<input type="radio" name="autoassign_coowners"'.
3269: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3270: '<label><input type="radio" name="autoassign_coowners"'.
3271: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 3272: '</tr><tr>'.
3273: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
3274: '<td class="LC_right_item"><span class="LC_nobreak">'.
3275: '<input type="text" name="autoenroll_failsafe"'.
1.333 raeburn 3276: ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.274 raeburn 3277: $$rowtotal += 4;
1.3 raeburn 3278: return $datatable;
3279: }
3280:
3281: sub print_autoupdate {
1.30 raeburn 3282: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 3283: my $datatable;
3284: if ($position eq 'top') {
3285: my $updateon = ' ';
3286: my $updateoff = ' checked="checked" ';
3287: my $classlistson = ' ';
3288: my $classlistsoff = ' checked="checked" ';
3289: if (ref($settings) eq 'HASH') {
3290: if ($settings->{'run'} eq '1') {
3291: $updateon = $updateoff;
3292: $updateoff = ' ';
3293: }
3294: if ($settings->{'classlists'} eq '1') {
3295: $classlistson = $classlistsoff;
3296: $classlistsoff = ' ';
3297: }
3298: }
3299: my %title = (
3300: run => 'Auto-update active?',
3301: classlists => 'Update information in classlists?',
3302: );
3303: $datatable = '<tr class="LC_odd_row">'.
3304: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 3305: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3306: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 3307: $updateon.' value="1" />'.&mt('Yes').'</label> '.
3308: '<label><input type="radio" name="autoupdate_run"'.
3309: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3310: '</tr><tr>'.
3311: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 3312: '<td class="LC_right_item"><span class="LC_nobreak">'.
3313: '<label><input type="radio" name="classlists"'.
3314: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
3315: '<label><input type="radio" name="classlists"'.
3316: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3317: '</tr>';
1.30 raeburn 3318: $$rowtotal += 2;
1.131 raeburn 3319: } elsif ($position eq 'middle') {
3320: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3321: my $numinrow = 3;
3322: my $locknamesettings;
3323: $datatable .= &insttypes_row($settings,$types,$usertypes,
3324: $dom,$numinrow,$othertitle,
1.305 raeburn 3325: 'lockablenames',$rowtotal);
1.131 raeburn 3326: $$rowtotal ++;
1.3 raeburn 3327: } else {
1.44 raeburn 3328: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3329: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3330: 'permanentemail','id');
1.33 raeburn 3331: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3332: my $numrows = 0;
1.26 raeburn 3333: if (ref($types) eq 'ARRAY') {
3334: if (@{$types} > 0) {
3335: $datatable =
3336: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3337: \@fields,$types,\$numrows);
1.30 raeburn 3338: $$rowtotal += @{$types};
1.26 raeburn 3339: }
1.3 raeburn 3340: }
3341: $datatable .=
3342: &usertype_update_row($settings,{'default' => $othertitle},
3343: \%fieldtitles,\@fields,['default'],
3344: \$numrows);
1.30 raeburn 3345: $$rowtotal ++;
1.3 raeburn 3346: }
3347: return $datatable;
3348: }
3349:
1.125 raeburn 3350: sub print_autocreate {
3351: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 3352: my (%createon,%createoff,%currhash);
1.125 raeburn 3353: my @types = ('xml','req');
3354: if (ref($settings) eq 'HASH') {
3355: foreach my $item (@types) {
3356: $createoff{$item} = ' checked="checked" ';
3357: $createon{$item} = ' ';
3358: if (exists($settings->{$item})) {
3359: if ($settings->{$item}) {
3360: $createon{$item} = ' checked="checked" ';
3361: $createoff{$item} = ' ';
3362: }
3363: }
3364: }
1.210 raeburn 3365: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 3366: $currhash{$settings->{'xmldc'}} = 1;
3367: }
1.125 raeburn 3368: } else {
3369: foreach my $item (@types) {
3370: $createoff{$item} = ' checked="checked" ';
3371: $createon{$item} = ' ';
3372: }
3373: }
3374: $$rowtotal += 2;
1.191 raeburn 3375: my $numinrow = 2;
1.125 raeburn 3376: my $datatable='<tr class="LC_odd_row">'.
3377: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3378: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3379: '<input type="radio" name="autocreate_xml"'.
3380: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3381: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3382: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3383: '</td></tr><tr>'.
3384: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3385: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3386: '<input type="radio" name="autocreate_req"'.
3387: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3388: '<label><input type="radio" name="autocreate_req"'.
3389: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 3390: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3391: 'autocreate_xmldc',%currhash);
1.247 raeburn 3392: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3393: if ($numdc > 1) {
1.247 raeburn 3394: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3395: '</td><td class="LC_left_item">';
1.125 raeburn 3396: } else {
1.247 raeburn 3397: $datatable .= &mt('Course creation processed as:').
3398: '</td><td class="LC_right_item">';
1.125 raeburn 3399: }
1.247 raeburn 3400: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 3401: $$rowtotal += $rows;
1.125 raeburn 3402: return $datatable;
3403: }
3404:
1.23 raeburn 3405: sub print_directorysrch {
1.277 raeburn 3406: my ($position,$dom,$settings,$rowtotal) = @_;
3407: my $datatable;
3408: if ($position eq 'top') {
3409: my $instsrchon = ' ';
3410: my $instsrchoff = ' checked="checked" ';
3411: my ($exacton,$containson,$beginson);
3412: my $instlocalon = ' ';
3413: my $instlocaloff = ' checked="checked" ';
3414: if (ref($settings) eq 'HASH') {
3415: if ($settings->{'available'} eq '1') {
3416: $instsrchon = $instsrchoff;
3417: $instsrchoff = ' ';
3418: }
3419: if ($settings->{'localonly'} eq '1') {
3420: $instlocalon = $instlocaloff;
3421: $instlocaloff = ' ';
3422: }
3423: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3424: foreach my $type (@{$settings->{'searchtypes'}}) {
3425: if ($type eq 'exact') {
3426: $exacton = ' checked="checked" ';
3427: } elsif ($type eq 'contains') {
3428: $containson = ' checked="checked" ';
3429: } elsif ($type eq 'begins') {
3430: $beginson = ' checked="checked" ';
3431: }
3432: }
3433: } else {
3434: if ($settings->{'searchtypes'} eq 'exact') {
3435: $exacton = ' checked="checked" ';
3436: } elsif ($settings->{'searchtypes'} eq 'contains') {
3437: $containson = ' checked="checked" ';
3438: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 3439: $exacton = ' checked="checked" ';
3440: $containson = ' checked="checked" ';
3441: }
3442: }
1.277 raeburn 3443: }
3444: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3445: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3446:
3447: my $numinrow = 4;
3448: my $cansrchrow = 0;
3449: $datatable='<tr class="LC_odd_row">'.
3450: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3451: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3452: '<input type="radio" name="dirsrch_available"'.
3453: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3454: '<label><input type="radio" name="dirsrch_available"'.
3455: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3456: '</tr><tr>'.
3457: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3458: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3459: '<input type="radio" name="dirsrch_instlocalonly"'.
3460: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3461: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3462: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3463: '</tr>';
3464: $$rowtotal += 2;
3465: if (ref($usertypes) eq 'HASH') {
3466: if (keys(%{$usertypes}) > 0) {
3467: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 3468: $numinrow,$othertitle,'cansearch',
3469: $rowtotal);
1.277 raeburn 3470: $cansrchrow = 1;
1.25 raeburn 3471: }
1.23 raeburn 3472: }
1.277 raeburn 3473: if ($cansrchrow) {
3474: $$rowtotal ++;
3475: $datatable .= '<tr>';
3476: } else {
3477: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 3478: }
1.277 raeburn 3479: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3480: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3481: foreach my $title (@{$titleorder}) {
3482: if (defined($searchtitles->{$title})) {
3483: my $check = ' ';
3484: if (ref($settings) eq 'HASH') {
3485: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3486: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3487: $check = ' checked="checked" ';
3488: }
1.39 raeburn 3489: }
1.25 raeburn 3490: }
1.277 raeburn 3491: $datatable .= '<td class="LC_left_item">'.
3492: '<span class="LC_nobreak"><label>'.
3493: '<input type="checkbox" name="searchby" '.
3494: 'value="'.$title.'"'.$check.'/>'.
3495: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 3496: }
3497: }
1.277 raeburn 3498: $datatable .= '</tr></table></td></tr>';
3499: $$rowtotal ++;
3500: if ($cansrchrow) {
3501: $datatable .= '<tr class="LC_odd_row">';
3502: } else {
3503: $datatable .= '<tr>';
3504: }
3505: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3506: '<td class="LC_left_item" colspan="2">'.
3507: '<span class="LC_nobreak"><label>'.
3508: '<input type="checkbox" name="searchtypes" '.
3509: $exacton.' value="exact" />'.&mt('Exact match').
3510: '</label> '.
3511: '<label><input type="checkbox" name="searchtypes" '.
3512: $beginson.' value="begins" />'.&mt('Begins with').
3513: '</label> '.
3514: '<label><input type="checkbox" name="searchtypes" '.
3515: $containson.' value="contains" />'.&mt('Contains').
3516: '</label></span></td></tr>';
3517: $$rowtotal ++;
1.26 raeburn 3518: } else {
1.277 raeburn 3519: my $domsrchon = ' checked="checked" ';
3520: my $domsrchoff = ' ';
3521: my $domlocalon = ' ';
3522: my $domlocaloff = ' checked="checked" ';
3523: if (ref($settings) eq 'HASH') {
3524: if ($settings->{'lclocalonly'} eq '1') {
3525: $domlocalon = $domlocaloff;
3526: $domlocaloff = ' ';
3527: }
3528: if ($settings->{'lcavailable'} eq '0') {
3529: $domsrchoff = $domsrchon;
3530: $domsrchon = ' ';
3531: }
3532: }
3533: $datatable='<tr class="LC_odd_row">'.
3534: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3535: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3536: '<input type="radio" name="dirsrch_domavailable"'.
3537: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3538: '<label><input type="radio" name="dirsrch_domavailable"'.
3539: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3540: '</tr><tr>'.
3541: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3542: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3543: '<input type="radio" name="dirsrch_domlocalonly"'.
3544: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3545: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3546: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3547: '</tr>';
3548: $$rowtotal += 2;
1.26 raeburn 3549: }
1.25 raeburn 3550: return $datatable;
3551: }
3552:
1.28 raeburn 3553: sub print_contacts {
1.286 raeburn 3554: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3555: my $datatable;
3556: my @contacts = ('adminemail','supportemail');
1.286 raeburn 3557: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 3558: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 3559: if ($position eq 'top') {
3560: if (ref($settings) eq 'HASH') {
3561: foreach my $item (@contacts) {
3562: if (exists($settings->{$item})) {
3563: $to{$item} = $settings->{$item};
3564: }
3565: }
3566: }
3567: } elsif ($position eq 'middle') {
3568: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 3569: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 3570: foreach my $type (@mailings) {
3571: $otheremails{$type} = '';
3572: }
1.340 raeburn 3573: } elsif ($position eq 'lower') {
3574: if (ref($settings) eq 'HASH') {
3575: if (ref($settings->{'lonstatus'}) eq 'HASH') {
3576: %lonstatus = %{$settings->{'lonstatus'}};
3577: }
3578: }
1.286 raeburn 3579: } else {
3580: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 3581: foreach my $type (@mailings) {
3582: $otheremails{$type} = '';
3583: }
1.286 raeburn 3584: $bccemails{'helpdeskmail'} = '';
3585: $bccemails{'otherdomsmail'} = '';
3586: $includestr{'helpdeskmail'} = '';
3587: $includestr{'otherdomsmail'} = '';
3588: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3589: }
1.28 raeburn 3590: if (ref($settings) eq 'HASH') {
1.340 raeburn 3591: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 3592: foreach my $type (@mailings) {
3593: if (exists($settings->{$type})) {
3594: if (ref($settings->{$type}) eq 'HASH') {
3595: foreach my $item (@contacts) {
3596: if ($settings->{$type}{$item}) {
3597: $checked{$type}{$item} = ' checked="checked" ';
3598: }
3599: }
3600: $otheremails{$type} = $settings->{$type}{'others'};
3601: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3602: $bccemails{$type} = $settings->{$type}{'bcc'};
3603: if ($settings->{$type}{'include'} ne '') {
3604: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3605: $includestr{$type} = &unescape($includestr{$type});
3606: }
3607: }
3608: }
3609: } elsif ($type eq 'lonstatusmail') {
3610: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3611: }
1.28 raeburn 3612: }
3613: }
1.286 raeburn 3614: if ($position eq 'bottom') {
3615: foreach my $type (@mailings) {
3616: $bccemails{$type} = $settings->{$type}{'bcc'};
3617: if ($settings->{$type}{'include'} ne '') {
3618: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3619: $includestr{$type} = &unescape($includestr{$type});
3620: }
3621: }
3622: if (ref($settings->{'helpform'}) eq 'HASH') {
3623: if (ref($fields) eq 'ARRAY') {
3624: foreach my $field (@{$fields}) {
3625: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3626: }
1.286 raeburn 3627: }
3628: if (exists($settings->{'helpform'}{'maxsize'})) {
3629: $maxsize = $settings->{'helpform'}{'maxsize'};
3630: } else {
1.289 raeburn 3631: $maxsize = '1.0';
1.286 raeburn 3632: }
3633: } else {
3634: if (ref($fields) eq 'ARRAY') {
3635: foreach my $field (@{$fields}) {
3636: $currfield{$field} = 'yes';
1.134 raeburn 3637: }
1.28 raeburn 3638: }
1.286 raeburn 3639: $maxsize = '1.0';
1.28 raeburn 3640: }
3641: }
3642: } else {
1.286 raeburn 3643: if ($position eq 'top') {
3644: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3645: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3646: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3647: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 3648: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3649: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3650: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3651: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 3652: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3653: } elsif ($position eq 'bottom') {
3654: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3655: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3656: if (ref($fields) eq 'ARRAY') {
3657: foreach my $field (@{$fields}) {
3658: $currfield{$field} = 'yes';
3659: }
3660: }
3661: $maxsize = '1.0';
3662: }
1.28 raeburn 3663: }
3664: my ($titles,$short_titles) = &contact_titles();
3665: my $rownum = 0;
3666: my $css_class;
1.286 raeburn 3667: if ($position eq 'top') {
3668: foreach my $item (@contacts) {
3669: $css_class = $rownum%2?' class="LC_odd_row"':'';
3670: $datatable .= '<tr'.$css_class.'>'.
3671: '<td><span class="LC_nobreak">'.$titles->{$item}.
3672: '</span></td><td class="LC_right_item">'.
3673: '<input type="text" name="'.$item.'" value="'.
3674: $to{$item}.'" /></td></tr>';
3675: $rownum ++;
3676: }
1.315 raeburn 3677: } elsif ($position eq 'bottom') {
3678: $css_class = $rownum%2?' class="LC_odd_row"':'';
3679: $datatable .= '<tr'.$css_class.'>'.
3680: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3681: &mt('(e-mail, subject, and description always shown)').
3682: '</td><td class="LC_left_item">';
3683: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3684: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3685: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3686: foreach my $field (@{$fields}) {
3687: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3688: if (($field eq 'screenshot') || ($field eq 'cc')) {
3689: $datatable .= ' '.&mt('(logged-in users)');
3690: }
3691: $datatable .='</td><td>';
3692: my $clickaction;
3693: if ($field eq 'screenshot') {
3694: $clickaction = ' onclick="screenshotSize(this);"';
3695: }
3696: if (ref($possoptions->{$field}) eq 'ARRAY') {
3697: foreach my $option (@{$possoptions->{$field}}) {
3698: my $checked;
3699: if ($currfield{$field} eq $option) {
3700: $checked = ' checked="checked"';
3701: }
3702: $datatable .= '<span class="LC_nobreak"><label>'.
3703: '<input type="radio" name="helpform_'.$field.'" '.
3704: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3705: '</label></span>'.(' 'x2);
3706: }
3707: }
3708: if ($field eq 'screenshot') {
3709: my $display;
3710: if ($currfield{$field} eq 'no') {
3711: $display = ' style="display:none"';
3712: }
1.334 raeburn 3713: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 3714: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3715: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3716: }
3717: $datatable .= '</td></tr>';
3718: }
3719: $datatable .= '</table>';
3720: }
3721: $datatable .= '</td></tr>'."\n";
3722: $rownum ++;
3723: }
1.340 raeburn 3724: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 3725: foreach my $type (@mailings) {
3726: $css_class = $rownum%2?' class="LC_odd_row"':'';
3727: $datatable .= '<tr'.$css_class.'>'.
3728: '<td><span class="LC_nobreak">'.
3729: $titles->{$type}.': </span></td>'.
3730: '<td class="LC_left_item">';
3731: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3732: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3733: }
3734: $datatable .= '<span class="LC_nobreak">';
3735: foreach my $item (@contacts) {
3736: $datatable .= '<label>'.
3737: '<input type="checkbox" name="'.$type.'"'.
3738: $checked{$type}{$item}.
3739: ' value="'.$item.'" />'.$short_titles->{$item}.
3740: '</label> ';
3741: }
3742: $datatable .= '</span><br />'.&mt('Others').': '.
3743: '<input type="text" name="'.$type.'_others" '.
3744: 'value="'.$otheremails{$type}.'" />';
3745: my %locchecked;
3746: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3747: foreach my $loc ('s','b') {
3748: if ($includeloc{$type} eq $loc) {
3749: $locchecked{$loc} = ' checked="checked"';
3750: last;
3751: }
3752: }
3753: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3754: '<input type="text" name="'.$type.'_bcc" '.
3755: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3756: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3757: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 3758: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 3759: '<span class="LC_nobreak">'.&mt('Location:').' '.
3760: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3761: (' 'x2).
3762: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3763: '</span></fieldset>';
3764: }
3765: $datatable .= '</td></tr>'."\n";
3766: $rownum ++;
3767: }
1.28 raeburn 3768: }
1.286 raeburn 3769: if ($position eq 'middle') {
3770: my %choices;
1.340 raeburn 3771: my $corelink = &core_link_msu();
3772: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 3773: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 3774: $corelink);
3775: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
3776: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 3777: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 3778: 'reportupdates' => 'on',
3779: 'reportstatus' => 'on');
1.286 raeburn 3780: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3781: \%choices,$rownum);
3782: $datatable .= $reports;
1.340 raeburn 3783: } elsif ($position eq 'lower') {
3784: $css_class = $rownum%2?' class="LC_odd_row"':'';
3785: my ($threshold,$sysmail,%excluded,%weights);
3786: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
3787: if ($lonstatus{'threshold'} =~ /^\d+$/) {
3788: $threshold = $lonstatus{'threshold'};
3789: } else {
3790: $threshold = $defaults->{'threshold'};
3791: }
3792: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
3793: $sysmail = $lonstatus{'sysmail'};
3794: } else {
3795: $sysmail = $defaults->{'sysmail'};
3796: }
3797: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 3798: foreach my $type ('E','W','N','U') {
1.340 raeburn 3799: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
3800: $weights{$type} = $lonstatus{'weights'}{$type};
3801: } else {
3802: $weights{$type} = $defaults->{$type};
3803: }
3804: }
3805: } else {
1.341 raeburn 3806: foreach my $type ('E','W','N','U') {
1.340 raeburn 3807: $weights{$type} = $defaults->{$type};
3808: }
3809: }
3810: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
3811: if (@{$lonstatus{'excluded'}} > 0) {
3812: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
3813: }
3814: }
3815: $datatable .= '<tr'.$css_class.'>'.
3816: '<td class="LC_left_item"><span class="LC_nobreak">'.
3817: $titles->{'errorthreshold'}.
3818: '</span></td><td class="LC_left_item">'.
3819: '<input type="text" name="errorthreshold" value="'.
3820: $threshold.'" size="5" /></td></tr>';
3821: $rownum ++;
3822: $css_class = $rownum%2?' class="LC_odd_row"':'';
3823: $datatable .= '<tr'.$css_class.'>'.
3824: '<td class="LC_left_item">'.
3825: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
3826: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 3827: foreach my $type ('E','W','N','U') {
1.340 raeburn 3828: $datatable .= '<td>'.$names->{$type}.'<br />'.
3829: '<input type="text" name="errorweights_'.$type.'" value="'.
3830: $weights{$type}.'" size="5" /></td>';
3831: }
3832: $datatable .= '</tr></table></tr>';
3833: $rownum ++;
3834: $css_class = $rownum%2?' class="LC_odd_row"':'';
3835: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
3836: $titles->{'errorexcluded'}.'</td>'.
3837: '<td class="LC_left_item"><table>';
3838: my $numinrow = 4;
3839: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
3840: for (my $i=0; $i<@ids; $i++) {
3841: my $rem = $i%($numinrow);
3842: if ($rem == 0) {
3843: if ($i > 0) {
3844: $datatable .= '</tr>';
3845: }
3846: $datatable .= '<tr>';
3847: }
3848: my $check;
3849: if ($excluded{$ids[$i]}) {
3850: $check = ' checked="checked" ';
3851: }
3852: $datatable .= '<td class="LC_left_item">'.
3853: '<span class="LC_nobreak"><label>'.
3854: '<input type="checkbox" name="errorexcluded" '.
3855: 'value="'.$ids[$i].'"'.$check.' />'.
3856: $ids[$i].'</label></span></td>';
3857: }
3858: my $colsleft = $numinrow - @ids%($numinrow);
3859: if ($colsleft > 1 ) {
3860: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3861: ' </td>';
3862: } elsif ($colsleft == 1) {
3863: $datatable .= '<td class="LC_left_item"> </td>';
3864: }
3865: $datatable .= '</tr></table></td></tr>';
3866: $rownum ++;
3867: $css_class = $rownum%2?' class="LC_odd_row"':'';
3868: $datatable .= '<tr'.$css_class.'>'.
3869: '<td class="LC_left_item"><span class="LC_nobreak">'.
3870: $titles->{'errorsysmail'}.
3871: '</span></td><td class="LC_left_item">'.
3872: '<input type="text" name="errorsysmail" value="'.
3873: $sysmail.'" size="5" /></td></tr>';
3874: $rownum ++;
1.286 raeburn 3875: } elsif ($position eq 'bottom') {
1.315 raeburn 3876: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3877: my (@posstypes,%usertypeshash);
3878: if (ref($types) eq 'ARRAY') {
3879: @posstypes = @{$types};
3880: }
3881: if (@posstypes) {
3882: if (ref($usertypes) eq 'HASH') {
3883: %usertypeshash = %{$usertypes};
3884: }
3885: my @overridden;
3886: my $numinrow = 4;
3887: if (ref($settings) eq 'HASH') {
3888: if (ref($settings->{'overrides'}) eq 'HASH') {
3889: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3890: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3891: push(@overridden,$key);
3892: foreach my $item (@contacts) {
3893: if ($settings->{'overrides'}{$key}{$item}) {
3894: $checked{'override_'.$key}{$item} = ' checked="checked" ';
3895: }
3896: }
3897: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3898: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3899: $includeloc{'override_'.$key} = '';
3900: $includestr{'override_'.$key} = '';
3901: if ($settings->{'overrides'}{$key}{'include'} ne '') {
3902: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3903: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3904: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3905: }
1.286 raeburn 3906: }
3907: }
3908: }
1.315 raeburn 3909: }
3910: my $customclass = 'LC_helpdesk_override';
3911: my $optionsprefix = 'LC_options_helpdesk_';
3912:
3913: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3914:
3915: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3916: $numinrow,$othertitle,'overrides',
3917: \$rownum,$onclicktypes,$customclass);
3918: $rownum ++;
3919: $usertypeshash{'default'} = $othertitle;
3920: foreach my $status (@posstypes) {
3921: my $css_class;
3922: if ($rownum%2) {
3923: $css_class = 'LC_odd_row ';
3924: }
3925: $css_class .= $customclass;
3926: my $rowid = $optionsprefix.$status;
3927: my $hidden = 1;
3928: my $currstyle = 'display:none';
3929: if (grep(/^\Q$status\E$/,@overridden)) {
3930: $currstyle = 'display:table-row';
3931: $hidden = 0;
3932: }
3933: my $key = 'override_'.$status;
3934: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3935: $includeloc{$key},$includestr{$key},$status,$rowid,
3936: $usertypeshash{$status},$css_class,$currstyle,
3937: \@contacts,$short_titles);
3938: unless ($hidden) {
3939: $rownum ++;
1.286 raeburn 3940: }
3941: }
1.134 raeburn 3942: }
1.28 raeburn 3943: }
1.30 raeburn 3944: $$rowtotal += $rownum;
1.28 raeburn 3945: return $datatable;
3946: }
3947:
1.340 raeburn 3948: sub core_link_msu {
3949: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3950: &mt('LON-CAPA core group - MSU'),600,500);
3951: }
3952:
1.315 raeburn 3953: sub overridden_helpdesk {
3954: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3955: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3956: my $class = 'LC_left_item';
3957: if ($css_class) {
3958: $css_class = ' class="'.$css_class.'"';
3959: }
3960: if ($rowid) {
3961: $rowid = ' id="'.$rowid.'"';
3962: }
3963: if ($rowstyle) {
3964: $rowstyle = ' style="'.$rowstyle.'"';
3965: }
3966: my ($output,$description);
3967: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3968: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3969: "<td>$description</td>\n".
3970: '<td class="'.$class.'" colspan="2">'.
3971: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3972: '<span class="LC_nobreak">';
3973: if (ref($contacts) eq 'ARRAY') {
3974: foreach my $item (@{$contacts}) {
3975: my $check;
3976: if (ref($checked) eq 'HASH') {
3977: $check = $checked->{$item};
3978: }
3979: my $title;
3980: if (ref($short_titles) eq 'HASH') {
3981: $title = $short_titles->{$item};
3982: }
3983: $output .= '<label>'.
3984: '<input type="checkbox" name="override_'.$type.'"'.$check.
3985: ' value="'.$item.'" />'.$title.'</label> ';
3986: }
3987: }
3988: $output .= '</span><br />'.&mt('Others').': '.
3989: '<input type="text" name="override_'.$type.'_others" '.
3990: 'value="'.$otheremails.'" />';
3991: my %locchecked;
3992: foreach my $loc ('s','b') {
3993: if ($includeloc eq $loc) {
3994: $locchecked{$loc} = ' checked="checked"';
3995: last;
3996: }
3997: }
3998: $output .= '<br />'.&mt('Bcc:').(' 'x6).
3999: '<input type="text" name="override_'.$type.'_bcc" '.
4000: 'value="'.$bccemails.'" /></fieldset>'.
4001: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4002: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4003: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 4004: '<span class="LC_nobreak">'.&mt('Location:').' '.
4005: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4006: (' 'x2).
4007: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4008: '</span></fieldset>'.
4009: '</td></tr>'."\n";
4010: return $output;
4011: }
4012:
1.286 raeburn 4013: sub contacts_javascript {
4014: return <<"ENDSCRIPT";
4015:
4016: <script type="text/javascript">
4017: // <![CDATA[
4018:
4019: function screenshotSize(field) {
4020: if (document.getElementById('help_screenshotsize')) {
4021: if (field.value == 'no') {
1.289 raeburn 4022: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 4023: } else {
4024: document.getElementById('help_screenshotsize').style.display="";
4025: }
4026: }
4027: return;
4028: }
4029:
1.315 raeburn 4030: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4031: if (form.elements[checkbox].length != undefined) {
4032: var count = 0;
4033: if (docount) {
4034: for (var i=0; i<form.elements[checkbox].length; i++) {
4035: if (form.elements[checkbox][i].checked) {
4036: count ++;
4037: }
4038: }
4039: }
4040: for (var i=0; i<form.elements[checkbox].length; i++) {
4041: var type = form.elements[checkbox][i].value;
4042: if (document.getElementById(prefix+type)) {
4043: if (form.elements[checkbox][i].checked) {
4044: document.getElementById(prefix+type).style.display = 'table-row';
4045: if (count % 2 == 1) {
4046: document.getElementById(prefix+type).className = target+' LC_odd_row';
4047: } else {
4048: document.getElementById(prefix+type).className = target;
4049: }
4050: count ++;
4051: } else {
4052: document.getElementById(prefix+type).style.display = 'none';
4053: }
4054: }
4055: }
4056: }
4057: return;
4058: }
4059:
4060:
1.286 raeburn 4061: // ]]>
4062: </script>
4063:
4064: ENDSCRIPT
4065: }
4066:
1.118 jms 4067: sub print_helpsettings {
1.282 raeburn 4068: my ($position,$dom,$settings,$rowtotal) = @_;
4069: my $confname = $dom.'-domainconfig';
1.285 raeburn 4070: my $formname = 'display';
1.168 raeburn 4071: my ($datatable,$itemcount);
1.282 raeburn 4072: if ($position eq 'top') {
4073: $itemcount = 1;
4074: my (%choices,%defaultchecked,@toggles);
4075: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4076: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4077: &mt('LON-CAPA bug tracker'),600,500));
4078: %defaultchecked = ('submitbugs' => 'on');
4079: @toggles = ('submitbugs');
4080: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4081: \%choices,$itemcount);
4082: $$rowtotal ++;
4083: } else {
4084: my $css_class;
4085: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 4086: my (%customroles,%ordered,%current);
1.301 raeburn 4087: if (ref($settings) eq 'HASH') {
4088: if (ref($settings->{'adhoc'}) eq 'HASH') {
4089: %current = %{$settings->{'adhoc'}};
4090: }
1.285 raeburn 4091: }
4092: my $count = 0;
4093: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 4094: if ($key=~/^rolesdef\_(\w+)$/) {
4095: my $rolename = $1;
1.285 raeburn 4096: my (%privs,$order);
1.282 raeburn 4097: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4098: $customroles{$rolename} = \%privs;
1.285 raeburn 4099: if (ref($current{$rolename}) eq 'HASH') {
4100: $order = $current{$rolename}{'order'};
4101: }
4102: if ($order eq '') {
4103: $order = $count;
4104: }
4105: $ordered{$order} = $rolename;
4106: $count++;
4107: }
4108: }
4109: my $maxnum = scalar(keys(%ordered));
4110: my @roles_by_num = ();
4111: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4112: push(@roles_by_num,$item);
4113: }
4114: my $context = 'domprefs';
4115: my $crstype = 'Course';
4116: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 4117: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 4118: my ($numstatustypes,@jsarray);
4119: if (ref($types) eq 'ARRAY') {
4120: if (@{$types} > 0) {
4121: $numstatustypes = scalar(@{$types});
4122: push(@accesstypes,'status');
4123: @jsarray = ('bystatus');
1.282 raeburn 4124: }
4125: }
1.290 raeburn 4126: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 4127: if (keys(%domhelpdesk)) {
4128: push(@accesstypes,('inc','exc'));
4129: push(@jsarray,('notinc','notexc'));
4130: }
4131: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 4132: my $context = 'domprefs';
4133: my $crstype = 'Course';
1.285 raeburn 4134: my $prefix = 'helproles_';
4135: my $add_class = 'LC_hidden';
4136: foreach my $num (@roles_by_num) {
4137: my $role = $ordered{$num};
4138: my ($desc,$access,@statuses);
4139: if (ref($current{$role}) eq 'HASH') {
4140: $desc = $current{$role}{'desc'};
4141: $access = $current{$role}{'access'};
4142: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4143: @statuses = @{$current{$role}{'insttypes'}};
4144: }
4145: }
4146: if ($desc eq '') {
4147: $desc = $role;
4148: }
4149: my $identifier = 'custhelp'.$num;
1.282 raeburn 4150: my %full=();
4151: my %levels= (
4152: course => {},
4153: domain => {},
4154: system => {},
4155: );
4156: my %levelscurrent=(
4157: course => {},
4158: domain => {},
4159: system => {},
4160: );
4161: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4162: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4163: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 4164: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 4165: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 4166: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4167: for (my $k=0; $k<=$maxnum; $k++) {
4168: my $vpos = $k+1;
4169: my $selstr;
4170: if ($k == $num) {
4171: $selstr = ' selected="selected" ';
4172: }
4173: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4174: }
4175: $datatable .= '</select>'.(' 'x2).
4176: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4177: '</td>'.
4178: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4179: &mt('Name shown to users:').
4180: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4181: '</fieldset>'.
4182: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4183: $othertitle,$usertypes,$types,\%domhelpdesk).
4184: '<fieldset>'.
4185: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 4186: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 4187: \%levelscurrent,$identifier,
4188: 'LC_hidden',$prefix.$num.'_privs').
4189: '</fieldset></td>';
1.282 raeburn 4190: $itemcount ++;
4191: }
4192: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4193: my $newcust = 'custhelp'.$count;
4194: my (%privs,%levelscurrent);
4195: my %full=();
4196: my %levels= (
4197: course => {},
4198: domain => {},
4199: system => {},
4200: );
4201: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4202: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 4203: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 4204: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 4205: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4206: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4207: for (my $k=0; $k<$maxnum+1; $k++) {
4208: my $vpos = $k+1;
4209: my $selstr;
4210: if ($k == $maxnum) {
4211: $selstr = ' selected="selected" ';
4212: }
4213: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4214: }
4215: $datatable .= '</select> '."\n".
1.282 raeburn 4216: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4217: '</label></span></td>'.
1.285 raeburn 4218: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4219: '<span class="LC_nobreak">'.
4220: &mt('Internal name:').
4221: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4222: '</span>'.(' 'x4).
4223: '<span class="LC_nobreak">'.
4224: &mt('Name shown to users:').
4225: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4226: '</span></fieldset>'.
4227: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4228: $usertypes,$types,\%domhelpdesk).
4229: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 4230: &Apache::lonuserutils::custom_role_header($context,$crstype,
4231: \@templateroles,$newcust).
4232: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4233: \%levelscurrent,$newcust).
1.334 raeburn 4234: '</fieldset>'.
4235: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4236: '</td></tr>';
1.282 raeburn 4237: $count ++;
4238: $$rowtotal += $count;
4239: }
1.166 raeburn 4240: return $datatable;
1.121 raeburn 4241: }
4242:
1.285 raeburn 4243: sub adhocbutton {
4244: my ($prefix,$num,$field,$visibility) = @_;
4245: my %lt = &Apache::lonlocal::texthash(
4246: show => 'Show details',
4247: hide => 'Hide details',
4248: );
4249: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4250: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4251: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4252: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4253: }
4254:
4255: sub helpsettings_javascript {
4256: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4257: return unless(ref($roles_by_num) eq 'ARRAY');
4258: my %html_js_lt = &Apache::lonlocal::texthash(
4259: show => 'Show details',
4260: hide => 'Hide details',
4261: );
4262: &html_escape(\%html_js_lt);
4263: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4264: return <<"ENDSCRIPT";
4265: <script type="text/javascript">
4266: // <![CDATA[
4267:
4268: function reorderHelpRoles(form,item) {
4269: var changedVal;
4270: $jstext
4271: var newpos = 'helproles_${total}_pos';
4272: var maxh = 1 + $total;
4273: var current = new Array();
4274: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4275: if (item == newpos) {
4276: changedVal = newitemVal;
4277: } else {
4278: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4279: current[newitemVal] = newpos;
4280: }
4281: for (var i=0; i<helproles.length; i++) {
4282: var elementName = 'helproles_'+helproles[i]+'_pos';
4283: if (elementName != item) {
4284: if (form.elements[elementName]) {
4285: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4286: current[currVal] = elementName;
4287: }
4288: }
4289: }
4290: var oldVal;
4291: for (var j=0; j<maxh; j++) {
4292: if (current[j] == undefined) {
4293: oldVal = j;
4294: }
4295: }
4296: if (oldVal < changedVal) {
4297: for (var k=oldVal+1; k<=changedVal ; k++) {
4298: var elementName = current[k];
4299: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4300: }
4301: } else {
4302: for (var k=changedVal; k<oldVal; k++) {
4303: var elementName = current[k];
4304: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4305: }
4306: }
4307: return;
4308: }
4309:
4310: function helpdeskAccess(num) {
4311: var curraccess = null;
4312: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4313: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4314: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4315: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4316: }
4317: }
4318: }
4319: var shown = Array();
4320: var hidden = Array();
4321: if (curraccess == 'none') {
4322: hidden = Array('$hiddenstr');
4323: } else {
4324: if (curraccess == 'status') {
4325: shown = Array('bystatus');
4326: hidden = Array('notinc','notexc');
4327: } else {
4328: if (curraccess == 'exc') {
4329: shown = Array('notexc');
4330: hidden = Array('notinc','bystatus');
4331: }
4332: if (curraccess == 'inc') {
4333: shown = Array('notinc');
4334: hidden = Array('notexc','bystatus');
4335: }
1.293 raeburn 4336: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 4337: hidden = Array('notinc','notexc','bystatus');
4338: }
4339: }
4340: }
4341: if (hidden.length > 0) {
4342: for (var i=0; i<hidden.length; i++) {
4343: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4344: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4345: }
4346: }
4347: }
4348: if (shown.length > 0) {
4349: for (var i=0; i<shown.length; i++) {
4350: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4351: if (shown[i] == 'privs') {
4352: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4353: } else {
4354: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4355: }
4356: }
4357: }
4358: }
4359: return;
4360: }
4361:
4362: function toggleHelpdeskItem(num,field) {
4363: if (document.getElementById('helproles_'+num+'_'+field)) {
4364: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 4365: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 4366: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4367: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4368: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4369: }
4370: } else {
4371: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4372: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4373: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4374: }
4375: }
4376: }
4377: return;
4378: }
4379:
4380: // ]]>
4381: </script>
4382:
4383: ENDSCRIPT
4384: }
4385:
4386: sub helpdeskroles_access {
4387: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4388: $usertypes,$types,$domhelpdesk) = @_;
4389: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4390: my %lt = &Apache::lonlocal::texthash(
4391: 'rou' => 'Role usage',
4392: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 4393: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4394: 'dh' => 'All with domain helpdesk role',
4395: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 4396: 'none' => 'None',
4397: 'status' => 'Determined based on institutional status',
4398: 'inc' => 'Include all, but exclude specific personnel',
4399: 'exc' => 'Exclude all, but include specific personnel',
4400: );
4401: my %usecheck = (
4402: all => ' checked="checked"',
4403: );
4404: my %displaydiv = (
4405: status => 'none',
4406: inc => 'none',
4407: exc => 'none',
4408: priv => 'block',
4409: );
4410: my $output;
4411: if (ref($current) eq 'HASH') {
4412: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4413: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4414: $usecheck{$current->{access}} = $usecheck{'all'};
4415: delete($usecheck{'all'});
4416: if ($current->{access} =~ /^(status|inc|exc)$/) {
4417: my $access = $1;
4418: $displaydiv{$access} = 'inline';
4419: } elsif ($current->{access} eq 'none') {
4420: $displaydiv{'priv'} = 'none';
4421: }
4422: }
4423: }
4424: }
4425: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4426: '<p>'.$lt{'whi'}.'</p>';
4427: foreach my $access (@{$accesstypes}) {
4428: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4429: ' onclick="helpdeskAccess('."'$num'".');" />'.
4430: $lt{$access}.'</label>';
4431: if ($access eq 'status') {
4432: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4433: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4434: $othertitle,$usertypes,$types).
4435: '</div>';
4436: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4437: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4438: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4439: '</div>';
4440: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4441: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4442: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4443: '</div>';
4444: }
4445: $output .= '</p>';
4446: }
4447: $output .= '</fieldset>';
4448: return $output;
4449: }
4450:
1.121 raeburn 4451: sub radiobutton_prefs {
1.192 raeburn 4452: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 4453: $additional,$align) = @_;
1.121 raeburn 4454: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4455: (ref($choices) eq 'HASH'));
4456:
1.170 raeburn 4457: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 4458:
4459: foreach my $item (@{$toggles}) {
4460: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4461: $checkedon{$item} = ' checked="checked" ';
4462: $checkedoff{$item} = ' ';
1.121 raeburn 4463: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4464: $checkedoff{$item} = ' checked="checked" ';
4465: $checkedon{$item} = ' ';
4466: }
4467: }
4468: if (ref($settings) eq 'HASH') {
1.121 raeburn 4469: foreach my $item (@{$toggles}) {
1.118 jms 4470: if ($settings->{$item} eq '1') {
4471: $checkedon{$item} = ' checked="checked" ';
4472: $checkedoff{$item} = ' ';
4473: } elsif ($settings->{$item} eq '0') {
4474: $checkedoff{$item} = ' checked="checked" ';
4475: $checkedon{$item} = ' ';
4476: }
4477: }
1.121 raeburn 4478: }
1.192 raeburn 4479: if ($onclick) {
4480: $onclick = ' onclick="'.$onclick.'"';
4481: }
1.121 raeburn 4482: foreach my $item (@{$toggles}) {
1.118 jms 4483: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4484: $datatable .=
1.306 raeburn 4485: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 4486: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 4487: '</span></td>';
4488: if ($align eq 'left') {
4489: $datatable .= '<td class="LC_left_item">';
4490: } else {
4491: $datatable .= '<td class="LC_right_item">';
4492: }
1.289 raeburn 4493: $datatable .=
1.257 raeburn 4494: '<span class="LC_nobreak">'.
1.118 jms 4495: '<label><input type="radio" name="'.
1.192 raeburn 4496: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 4497: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 4498: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
4499: '</span>'.$additional.
4500: '</td>'.
1.118 jms 4501: '</tr>';
4502: $itemcount ++;
1.121 raeburn 4503: }
4504: return ($datatable,$itemcount);
4505: }
4506:
1.267 raeburn 4507: sub print_ltitools {
4508: my ($dom,$settings,$rowtotal) = @_;
4509: my $rownum = 0;
4510: my $css_class;
4511: my $itemcount = 1;
4512: my $maxnum = 0;
4513: my %ordered;
4514: if (ref($settings) eq 'HASH') {
4515: foreach my $item (keys(%{$settings})) {
4516: if (ref($settings->{$item}) eq 'HASH') {
4517: my $num = $settings->{$item}{'order'};
4518: $ordered{$num} = $item;
4519: }
4520: }
4521: }
4522: my $confname = $dom.'-domainconfig';
4523: my $switchserver = &check_switchserver($dom,$confname);
4524: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 4525: my $datatable;
1.267 raeburn 4526: my %lt = <itools_names();
4527: my @courseroles = ('cc','in','ta','ep','st');
4528: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.324 raeburn 4529: my @fields = ('fullname','firstname','lastname','email','roles','user');
1.267 raeburn 4530: if (keys(%ordered)) {
4531: my @items = sort { $a <=> $b } keys(%ordered);
4532: for (my $i=0; $i<@items; $i++) {
4533: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4534: my $item = $ordered{$items[$i]};
1.323 raeburn 4535: my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267 raeburn 4536: if (ref($settings->{$item}) eq 'HASH') {
4537: $title = $settings->{$item}->{'title'};
4538: $url = $settings->{$item}->{'url'};
4539: $key = $settings->{$item}->{'key'};
4540: $secret = $settings->{$item}->{'secret'};
1.322 raeburn 4541: $lifetime = $settings->{$item}->{'lifetime'};
1.267 raeburn 4542: my $image = $settings->{$item}->{'image'};
4543: if ($image ne '') {
4544: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
4545: }
1.323 raeburn 4546: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
4547: $sigsel{'HMAC-256'} = ' selected="selected"';
4548: } else {
4549: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
4550: }
1.267 raeburn 4551: }
1.319 raeburn 4552: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267 raeburn 4553: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4554: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
4555: for (my $k=0; $k<=$maxnum; $k++) {
4556: my $vpos = $k+1;
4557: my $selstr;
4558: if ($k == $i) {
4559: $selstr = ' selected="selected" ';
4560: }
4561: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4562: }
4563: $datatable .= '</select>'.(' 'x2).
4564: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4565: &mt('Delete?').'</label></span></td>'.
4566: '<td colspan="2">'.
4567: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4568: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267 raeburn 4569: (' 'x2).
4570: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4571: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4572: (' 'x2).
4573: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4574: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4575: (' 'x2).
4576: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
4577: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
4578: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267 raeburn 4579: '<br /><br />'.
1.323 raeburn 4580: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267 raeburn 4581: ' value="'.$url.'" /></span>'.
4582: (' 'x2).
1.319 raeburn 4583: '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267 raeburn 4584: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4585: (' 'x2).
1.322 raeburn 4586: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
4587: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
4588: (' 'x2).
1.267 raeburn 4589: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4590: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4591: '<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>'.
4592: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4593: '</fieldset>'.
4594: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4595: '<span class="LC_nobreak">'.&mt('Display target:');
4596: my %currdisp;
4597: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4598: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4599: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 4600: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4601: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 4602: } else {
4603: $currdisp{'iframe'} = ' checked="checked"';
4604: }
4605: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4606: $currdisp{'width'} = $1;
4607: }
4608: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4609: $currdisp{'height'} = $1;
4610: }
1.296 raeburn 4611: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4612: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 4613: } else {
4614: $currdisp{'iframe'} = ' checked="checked"';
4615: }
1.298 raeburn 4616: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4617: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4618: $lt{$disp}.'</label>'.(' 'x2);
4619: }
4620: $datatable .= (' 'x4);
4621: foreach my $dimen ('width','height') {
4622: $datatable .= '<label>'.$lt{$dimen}.' '.
4623: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4624: (' 'x2);
4625: }
1.334 raeburn 4626: $datatable .= '</span><br />'.
1.296 raeburn 4627: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 4628: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
1.296 raeburn 4629: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4630: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
4631: '</textarea></div><div style=""></div><br />';
1.319 raeburn 4632: my %units = (
4633: 'passback' => 'days',
4634: 'roster' => 'seconds',
4635: );
1.267 raeburn 4636: foreach my $extra ('passback','roster') {
1.319 raeburn 4637: my $validsty = 'none';
4638: my $currvalid;
1.267 raeburn 4639: my $checkedon = '';
4640: my $checkedoff = ' checked="checked"';
4641: if ($settings->{$item}->{$extra}) {
4642: $checkedon = $checkedoff;
4643: $checkedoff = '';
1.319 raeburn 4644: $validsty = 'inline-block';
4645: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
4646: $currvalid = $settings->{$item}->{$extra.'valid'};
4647: }
4648: }
4649: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
4650: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4651: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
4652: &mt('No').'</label>'.(' 'x2).
4653: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
4654: &mt('Yes').'</label></span></div>'.
4655: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
4656: '<span class="LC_nobreak">'.
4657: &mt("at least [_1] $units{$extra} after launch",
4658: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
4659: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4660: }
1.319 raeburn 4661: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
1.267 raeburn 4662: if ($imgsrc) {
4663: $datatable .= $imgsrc.
4664: '<label><input type="checkbox" name="ltitools_image_del"'.
4665: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
4666: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
4667: } else {
4668: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4669: }
4670: if ($switchserver) {
4671: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4672: } else {
4673: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
4674: }
4675: $datatable .= '</span></fieldset>';
1.324 raeburn 4676: my (%checkedfields,%rolemaps,$userincdom);
1.267 raeburn 4677: if (ref($settings->{$item}) eq 'HASH') {
4678: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
4679: %checkedfields = %{$settings->{$item}->{'fields'}};
4680: }
1.324 raeburn 4681: $userincdom = $settings->{$item}->{'incdom'};
1.267 raeburn 4682: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
4683: %rolemaps = %{$settings->{$item}->{'roles'}};
4684: $checkedfields{'roles'} = 1;
4685: }
4686: }
4687: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4688: '<span class="LC_nobreak">';
1.324 raeburn 4689: my $userfieldstyle = 'display:none;';
4690: my $seluserdom = '';
4691: my $unseluserdom = ' selected="selected"';
1.267 raeburn 4692: foreach my $field (@fields) {
1.324 raeburn 4693: my ($checked,$onclick,$id,$spacer);
1.267 raeburn 4694: if ($checkedfields{$field}) {
4695: $checked = ' checked="checked"';
4696: }
1.324 raeburn 4697: if ($field eq 'user') {
4698: $id = ' id="ltitools_user_field_'.$i.'"';
4699: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
4700: if ($checked) {
4701: $userfieldstyle = 'display:inline-block';
4702: if ($userincdom) {
4703: $seluserdom = $unseluserdom;
4704: $unseluserdom = '';
4705: }
4706: }
4707: } else {
4708: $spacer = (' ' x2);
4709: }
1.267 raeburn 4710: $datatable .= '<label>'.
1.324 raeburn 4711: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
4712: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4713: }
1.324 raeburn 4714: $datatable .= '</span>';
4715: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
4716: '<span class="LC_nobreak"> : '.
4717: '<select name="ltitools_userincdom_'.$i.'">'.
4718: '<option value="">'.&mt('Select').'</option>'.
4719: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
4720: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
4721: '</select></span></div>';
4722: $datatable .= '</fieldset>'.
1.267 raeburn 4723: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4724: foreach my $role (@courseroles) {
4725: my ($selected,$selectnone);
4726: if (!$rolemaps{$role}) {
4727: $selectnone = ' selected="selected"';
4728: }
1.306 raeburn 4729: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4730: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4731: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
4732: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4733: foreach my $ltirole (@ltiroles) {
4734: unless ($selectnone) {
4735: if ($rolemaps{$role} eq $ltirole) {
4736: $selected = ' selected="selected"';
4737: } else {
4738: $selected = '';
4739: }
4740: }
4741: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
4742: }
4743: $datatable .= '</select></td>';
4744: }
1.273 raeburn 4745: $datatable .= '</tr></table></fieldset>';
4746: my %courseconfig;
4747: if (ref($settings->{$item}) eq 'HASH') {
4748: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
4749: %courseconfig = %{$settings->{$item}->{'crsconf'}};
4750: }
4751: }
4752: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4753: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 4754: my $checked;
4755: if ($courseconfig{$item}) {
4756: $checked = ' checked="checked"';
4757: }
4758: $datatable .= '<label>'.
4759: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
1.372 raeburn 4760: $lt{'crs'.$item}.'</label> '."\n";
1.273 raeburn 4761: }
4762: $datatable .= '</span></fieldset>'.
1.267 raeburn 4763: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4764: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
4765: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
4766: my %custom = %{$settings->{$item}->{'custom'}};
4767: if (keys(%custom) > 0) {
4768: foreach my $key (sort(keys(%custom))) {
4769: $datatable .= '<tr><td><span class="LC_nobreak">'.
4770: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
4771: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
4772: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
4773: ' value="'.$custom{$key}.'" /></td></tr>';
4774: }
4775: }
4776: }
4777: $datatable .= '<tr><td><span class="LC_nobreak">'.
4778: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
4779: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
4780: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
4781: $datatable .= '</table></fieldset></td></tr>'."\n";
4782: $itemcount ++;
4783: }
4784: }
4785: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319 raeburn 4786: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267 raeburn 4787: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4788: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
4789: '<select name="ltitools_add_pos"'.$chgstr.'>';
4790: for (my $k=0; $k<$maxnum+1; $k++) {
4791: my $vpos = $k+1;
4792: my $selstr;
4793: if ($k == $maxnum) {
4794: $selstr = ' selected="selected" ';
4795: }
4796: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4797: }
4798: $datatable .= '</select> '."\n".
1.334 raeburn 4799: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.267 raeburn 4800: '<td colspan="2">'.
4801: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4802: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267 raeburn 4803: (' 'x2).
4804: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
4805: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4806: (' 'x2).
4807: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
4808: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4809: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
4810: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
4811: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267 raeburn 4812: '<br />'.
1.323 raeburn 4813: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267 raeburn 4814: (' 'x2).
4815: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
4816: (' 'x2).
1.322 raeburn 4817: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
4818: (' 'x2).
1.267 raeburn 4819: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
4820: '<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".
4821: '</fieldset>'.
4822: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4823: '<span class="LC_nobreak">'.&mt('Display target:');
4824: my %defaultdisp;
4825: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 4826: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4827: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
4828: $lt{$disp}.'</label>'.(' 'x2);
4829: }
4830: $datatable .= (' 'x4);
4831: foreach my $dimen ('width','height') {
4832: $datatable .= '<label>'.$lt{$dimen}.' '.
4833: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
4834: (' 'x2);
4835: }
1.334 raeburn 4836: $datatable .= '</span><br />'.
1.296 raeburn 4837: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 4838: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
1.296 raeburn 4839: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
1.334 raeburn 4840: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
1.296 raeburn 4841: '</div><div style=""></div><br />';
1.319 raeburn 4842: my %units = (
4843: 'passback' => 'days',
4844: 'roster' => 'seconds',
4845: );
4846: my %defaulttimes = (
4847: 'passback' => '7',
1.322 raeburn 4848: 'roster' => '300',
1.319 raeburn 4849: );
1.267 raeburn 4850: foreach my $extra ('passback','roster') {
1.319 raeburn 4851: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
4852: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4853: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
4854: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
4855: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
4856: &mt('Yes').'</label></span></div>'.
4857: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
4858: '<span class="LC_nobreak">'.
4859: &mt("at least [_1] $units{$extra} after launch",
4860: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
4861: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4862: }
1.319 raeburn 4863: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
1.267 raeburn 4864: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4865: if ($switchserver) {
4866: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4867: } else {
4868: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
4869: }
4870: $datatable .= '</span></fieldset>'.
4871: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4872: '<span class="LC_nobreak">';
4873: foreach my $field (@fields) {
1.324 raeburn 4874: my ($id,$onclick,$spacer);
4875: if ($field eq 'user') {
4876: $id = ' id="ltitools_user_field_add"';
4877: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
4878: } else {
4879: $spacer = (' ' x2);
4880: }
1.267 raeburn 4881: $datatable .= '<label>'.
1.324 raeburn 4882: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
4883: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4884: }
1.324 raeburn 4885: $datatable .= '</span>'.
4886: '<div style="display:none;" id="ltitools_user_div_add">'.
4887: '<span class="LC_nobreak"> : '.
4888: '<select name="ltitools_userincdom_add">'.
4889: '<option value="" selected="selected">'.&mt('Select').'</option>'.
4890: '<option value="0">'.&mt('username').'</option>'.
4891: '<option value="1">'.&mt('username:domain').'</option>'.
4892: '</select></span></div></fieldset>';
4893: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1.267 raeburn 4894: foreach my $role (@courseroles) {
4895: my ($checked,$checkednone);
1.306 raeburn 4896: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4897: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4898: '<select name="ltitools_add_roles_'.$role.'">'.
4899: '<option value="" selected="selected">'.&mt('Select').'</option>';
4900: foreach my $ltirole (@ltiroles) {
4901: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
4902: }
4903: $datatable .= '</select></td>';
4904: }
4905: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 4906: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4907: foreach my $item ('label','title','target','linktext','explanation','append') {
1.296 raeburn 4908: $datatable .= '<label>'.
4909: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4910: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 4911: }
4912: $datatable .= '</span></fieldset>'.
1.267 raeburn 4913: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4914: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4915: '<tr><td><span class="LC_nobreak">'.
4916: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4917: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4918: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
1.334 raeburn 4919: '</table></fieldset>'."\n".
1.267 raeburn 4920: '</td>'."\n".
4921: '</tr>'."\n";
4922: $itemcount ++;
4923: return $datatable;
4924: }
4925:
4926: sub ltitools_names {
4927: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 4928: 'title' => 'Title',
4929: 'version' => 'Version',
4930: 'msgtype' => 'Message Type',
1.323 raeburn 4931: 'sigmethod' => 'Signature Method',
1.296 raeburn 4932: 'url' => 'URL',
4933: 'key' => 'Key',
1.322 raeburn 4934: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 4935: 'secret' => 'Secret',
4936: 'icon' => 'Icon',
1.324 raeburn 4937: 'user' => 'User',
1.296 raeburn 4938: 'fullname' => 'Full Name',
4939: 'firstname' => 'First Name',
4940: 'lastname' => 'Last Name',
4941: 'email' => 'E-mail',
4942: 'roles' => 'Role',
1.298 raeburn 4943: 'window' => 'Window',
4944: 'tab' => 'Tab',
1.296 raeburn 4945: 'iframe' => 'iFrame',
4946: 'height' => 'Height',
4947: 'width' => 'Width',
4948: 'linktext' => 'Default Link Text',
4949: 'explanation' => 'Default Explanation',
4950: 'passback' => 'Tool can return grades:',
4951: 'roster' => 'Tool can retrieve roster:',
4952: 'crstarget' => 'Display target',
4953: 'crslabel' => 'Course label',
4954: 'crstitle' => 'Course title',
4955: 'crslinktext' => 'Link Text',
4956: 'crsexplanation' => 'Explanation',
1.318 raeburn 4957: 'crsappend' => 'Provider URL',
1.267 raeburn 4958: );
4959: return %lt;
4960: }
4961:
1.372 raeburn 4962: sub print_proctoring {
4963: my ($dom,$settings,$rowtotal) = @_;
4964: my $itemcount = 1;
4965: my (%ordered,%providernames,%current,%currentdef);
4966: my $confname = $dom.'-domainconfig';
4967: my $switchserver = &check_switchserver($dom,$confname);
4968: if (ref($settings) eq 'HASH') {
4969: foreach my $item (keys(%{$settings})) {
4970: if (ref($settings->{$item}) eq 'HASH') {
4971: my $num = $settings->{$item}{'order'};
4972: $ordered{$num} = $item;
4973: }
4974: }
4975: } else {
4976: %ordered = (
4977: 1 => 'proctorio',
4978: 2 => 'examity',
4979: );
4980: }
4981: %providernames = &proctoring_providernames();
4982: my $maxnum = scalar(keys(%ordered));
4983: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
4984: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
4985: if (ref($requref) eq 'HASH') {
4986: %requserfields = %{$requref};
4987: }
4988: if (ref($opturef) eq 'HASH') {
4989: %optuserfields = %{$opturef};
4990: }
4991: if (ref($defref) eq 'HASH') {
4992: %defaults = %{$defref};
4993: }
4994: if (ref($extref) eq 'HASH') {
4995: %extended = %{$extref};
4996: }
4997: if (ref($crsref) eq 'HASH') {
4998: %crsconf = %{$crsref};
4999: }
5000: if (ref($rolesref) eq 'ARRAY') {
5001: @courseroles = @{$rolesref};
5002: }
5003: if (ref($ltiref) eq 'ARRAY') {
5004: @ltiroles = @{$ltiref};
5005: }
5006: my $datatable;
5007: my $css_class;
5008: if (keys(%ordered)) {
5009: my @items = sort { $a <=> $b } keys(%ordered);
5010: for (my $i=0; $i<@items; $i++) {
5011: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5012: my $provider = $ordered{$items[$i]};
5013: my $optionsty = 'none';
5014: my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
5015: %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
5016: if (ref($settings) eq 'HASH') {
5017: if (ref($settings->{$provider}) eq 'HASH') {
5018: %current = %{$settings->{$provider}};
5019: if ($current{'available'}) {
5020: $optionsty = 'block';
5021: $available = 1;
5022: }
5023: if ($current{'lifetime'} =~ /^\d+$/) {
5024: $lifetime = $current{'lifetime'};
5025: }
5026: if ($current{'version'} =~ /^\d+\.\d+$/) {
5027: $version = $current{'version'};
5028: }
5029: if ($current{'image'} ne '') {
5030: $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
5031: }
5032: if (ref($current{'fields'}) eq 'ARRAY') {
5033: map { $checkedfields{$_} = 1; } @{$current{'fields'}};
5034: }
5035: $userincdom = $current{'incdom'};
5036: if (ref($current{'roles'}) eq 'HASH') {
5037: %rolemaps = %{$current{'roles'}};
5038: $checkedfields{'roles'} = 1;
5039: }
5040: if (ref($current{'defaults'}) eq 'ARRAY') {
5041: foreach my $val (@{$current{'defaults'}}) {
5042: if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
5043: $inuse{$val} = 1;
5044: } else {
5045: foreach my $poss (keys(%{$extended{$provider}})) {
5046: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5047: if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
5048: $inuse{$poss} = $val;
5049: last;
5050: }
5051: }
5052: }
5053: }
5054: }
5055: } elsif (ref($current{'defaults'}) eq 'HASH') {
5056: foreach my $key (keys(%{$current{'defaults'}})) {
5057: my $currval = $current{'defaults'}{$key};
5058: if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
5059: $inuse{$key} = 1;
5060: } else {
5061: my $match;
5062: foreach my $poss (keys(%{$extended{$provider}})) {
5063: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5064: if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
5065: $inuse{$poss} = $key;
5066: last;
5067: }
5068: } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
5069: foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
5070: if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
5071: if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
5072: $currentdef{$inner} = $currval;
5073: $match = 1;
5074: last;
5075: }
5076: } elsif ($inner eq $key) {
5077: $currentdef{$key} = $currval;
5078: $match = 1;
5079: last;
5080: }
5081: }
5082: }
5083: last if ($match);
5084: }
5085: }
5086: }
5087: }
5088: if (ref($current{'crsconf'}) eq 'ARRAY') {
5089: map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
5090: }
5091: }
5092: }
5093: my %lt = &proctoring_titles($provider);
5094: my %fieldtitles = &proctoring_fieldtitles($provider);
5095: my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
5096: my %checkedavailable = (
5097: yes => '',
5098: no => ' checked="checked"',
5099: );
5100: if ($available) {
5101: $checkedavailable{'yes'} = $checkedavailable{'no'};
5102: $checkedavailable{'no'} = '';
5103: }
5104: my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
5105: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5106: .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
5107: for (my $k=0; $k<$maxnum; $k++) {
5108: my $vpos = $k+1;
5109: my $selstr;
5110: if ($k == $i) {
5111: $selstr = ' selected="selected" ';
5112: }
5113: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5114: }
5115: if ($version eq '') {
5116: if ($provider eq 'proctorio') {
5117: $version = '1.0';
5118: } elsif ($provider eq 'examity') {
5119: $version = '1.1';
5120: }
5121: }
5122: if ($lifetime eq '') {
5123: $lifetime = '300';
5124: }
5125: $datatable .=
5126: '</select>'.(' 'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
5127: '<span class="LC_nobreak">'.$lt{'avai'}.' '.
5128: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label> '."\n".
5129: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
5130: '</td>'.
5131: '<td colspan="2">'.
5132: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
5133: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
5134: '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
5135: (' 'x2).
5136: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
5137: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5138: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5139: (' 'x2).
5140: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
5141: '<br />'.
5142: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
5143: '<br />'.
5144: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
5145: (' 'x2).
5146: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
5147: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.proctoring_'.$provider.'_secret.type='."'text'".' } else { this.form.proctoring_'.$provider.'_secret.type='."'password'".' }" />'.$lt{'visible'}.'</label></span><br />'."\n";
5148: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
5149: if ($imgsrc) {
5150: $datatable .= $imgsrc.
5151: '<label><input type="checkbox" name="proctoring_image_del"'.
5152: ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
5153: '<span class="LC_nobreak"> '.&mt('Replace:');
5154: }
5155: $datatable .= ' ';
5156: if ($switchserver) {
5157: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5158: } else {
5159: $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
5160: }
5161: unless ($imgsrc) {
5162: $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
5163: }
5164: $datatable .= '</fieldset>'."\n";
5165: if (ref($requserfields{$provider}) eq 'ARRAY') {
5166: if (@{$requserfields{$provider}} > 0) {
5167: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
5168: foreach my $field (@{$requserfields{$provider}}) {
5169: $datatable .= '<span class="LC_nobreak">'.
5170: '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
5171: $lt{$field}.'</label>';
5172: if ($field eq 'user') {
5173: my $seluserdom = '';
5174: my $unseluserdom = ' selected="selected"';
5175: if ($userincdom) {
5176: $seluserdom = $unseluserdom;
5177: $unseluserdom = '';
5178: }
5179: $datatable .= ': '.
5180: '<select name="proctoring_userincdom_'.$provider.'">'.
5181: '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
5182: '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
5183: '</select> ';
5184: } else {
5185: $datatable .= ' ';
5186: if ($field eq 'roles') {
5187: $showroles = 1;
5188: }
5189: }
5190: $datatable .= '</span> ';
5191: }
5192: }
5193: $datatable .= '</fieldset>'."\n";
5194: }
5195: if (ref($optuserfields{$provider}) eq 'ARRAY') {
5196: if (@{$optuserfields{$provider}} > 0) {
5197: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>';
5198: foreach my $field (@{$optuserfields{$provider}}) {
5199: my $checked;
5200: if ($checkedfields{$field}) {
5201: $checked = ' checked="checked"';
5202: }
5203: $datatable .= '<span class="LC_nobreak">'.
5204: '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span> ';
5205: }
5206: $datatable .= '</fieldset>'."\n";
5207: }
5208: }
5209: if (ref($defaults{$provider}) eq 'ARRAY') {
5210: if (@{$defaults{$provider}}) {
5211: my (%options,@selectboxes);
5212: if (ref($extended{$provider}) eq 'HASH') {
5213: %options = %{$extended{$provider}};
5214: }
5215: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
5216: my ($rem,$numinrow,$dropdowns);
5217: if ($provider eq 'proctorio') {
5218: $datatable .= '<table>';
5219: $numinrow = 4;
5220: }
5221: my $i = 0;
5222: foreach my $field (@{$defaults{$provider}}) {
5223: my $checked;
5224: if ($inuse{$field}) {
5225: $checked = ' checked="checked"';
5226: }
5227: if ($provider eq 'examity') {
5228: if ($field eq 'display') {
5229: $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
5230: foreach my $option ('iframe','tab','window') {
5231: my $checkdisp;
5232: if ($currentdef{'target'} eq $option) {
5233: $checkdisp = ' checked="checked"';
5234: }
5235: $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
5236: $fieldtitles{$option}.'</label>'.(' 'x2);
5237: }
5238: $datatable .= (' 'x4);
5239: foreach my $dimen ('width','height') {
5240: $datatable .= '<label>'.$fieldtitles{$dimen}.' '.
5241: '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
5242: 'value="'.$currentdef{$dimen}.'" /></label>'.
5243: (' 'x2);
5244: }
5245: $datatable .= '</span><br />'.
5246: '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
5247: '<input type="text" name="proctoring_linktext_'.$provider.'" '.
5248: 'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
5249: '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
5250: '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
5251: $currentdef{'explanation'}.
5252: '</textarea></div><div style=""></div><br />';
5253: }
5254: } else {
5255: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
5256: my ($output,$selnone);
5257: unless ($checked) {
5258: $selnone = ' selected="selected"';
5259: }
5260: $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
5261: '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
5262: '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>';
5263: foreach my $option (@{$options{$field}}) {
5264: my $sel;
5265: if ($inuse{$field} eq $option) {
5266: $sel = ' selected="selected"';
5267: }
5268: $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
5269: }
5270: $output .= '</select></span>';
5271: push(@selectboxes,$output);
5272: } else {
5273: $rem = $i%($numinrow);
5274: if ($rem == 0) {
5275: if ($i > 0) {
5276: $datatable .= '</tr>';
5277: }
5278: $datatable .= '<tr>';
5279: }
5280: $datatable .= '<td class="LC_left_item">'.
5281: '<span class="LC_nobreak">'.
5282: '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
5283: $fieldtitles{$field}.'</label></span></td>';
5284: $i++;
5285: }
5286: }
5287: }
5288: if ($provider eq 'proctorio') {
5289: if ($numinrow) {
5290: $rem = $i%$numinrow;
5291: }
5292: my $colsleft = $numinrow - $rem;
5293: if ($colsleft > 1) {
5294: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5295: } else {
5296: $datatable .= '<td class="LC_left_item">';
5297: }
5298: $datatable .= ' '.
5299: '</td></tr></table>';
5300: if (@selectboxes) {
5301: $datatable .= '<hr /><table>';
5302: $numinrow = 2;
5303: for (my $i=0; $i<@selectboxes; $i++) {
5304: $rem = $i%($numinrow);
5305: if ($rem == 0) {
5306: if ($i > 0) {
5307: $datatable .= '</tr>';
5308: }
5309: $datatable .= '<tr>';
5310: }
5311: $datatable .= '<td class="LC_left_item">'.
5312: $selectboxes[$i].'</td>';
5313: }
5314: if ($numinrow) {
5315: $rem = $i%$numinrow;
5316: }
5317: $colsleft = $numinrow - $rem;
5318: if ($colsleft > 1) {
5319: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5320: } else {
5321: $datatable .= '<td class="LC_left_item">';
5322: }
5323: $datatable .= ' '.
5324: '</td></tr></table>';
5325: }
5326: }
5327: $datatable .= '</fieldset>';
5328: }
5329: if (ref($crsconf{$provider}) eq 'ARRAY') {
5330: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5331: '<legend>'.&mt('Configurable in course').'</legend>';
5332: my ($rem,$numinrow);
5333: if ($provider eq 'proctorio') {
5334: $datatable .= '<table>';
5335: $numinrow = 4;
5336: }
5337: my $i = 0;
5338: foreach my $item (@{$crsconf{$provider}}) {
5339: my $name;
5340: if ($provider eq 'examity') {
5341: $name = $lt{'crs'.$item};
5342: } elsif ($provider eq 'proctorio') {
5343: $name = $fieldtitles{$item};
5344: $rem = $i%($numinrow);
5345: if ($rem == 0) {
5346: if ($i > 0) {
5347: $datatable .= '</tr>';
5348: }
5349: $datatable .= '<tr>';
5350: }
5351: $datatable .= '<td class="LC_left_item>';
5352: }
5353: my $checked;
5354: if ($crsconfig{$item}) {
5355: $checked = ' checked="checked"';
5356: }
5357: $datatable .= '<span class="LC_nobreak"><label>'.
5358: '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
5359: $name.'</label></span>';
5360: if ($provider eq 'examity') {
5361: $datatable .= ' ';
5362: }
5363: $datatable .= "\n";
5364: $i++;
5365: }
5366: if ($provider eq 'proctorio') {
5367: if ($numinrow) {
5368: $rem = $i%$numinrow;
5369: }
5370: my $colsleft = $numinrow - $rem;
5371: if ($colsleft > 1) {
5372: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5373: } else {
5374: $datatable .= '<td class="LC_left_item">';
5375: }
5376: $datatable .= ' '.
5377: '</td></tr></table>';
5378: }
5379: $datatable .= '</fieldset>';
5380: }
5381: if ($showroles) {
5382: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5383: '<legend>'.&mt('Role mapping').'</legend><table><tr>';
5384: foreach my $role (@courseroles) {
5385: my ($selected,$selectnone);
5386: if (!$rolemaps{$role}) {
5387: $selectnone = ' selected="selected"';
5388: }
5389: $datatable .= '<td style="text-align: center">'.
5390: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5391: '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
5392: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5393: foreach my $ltirole (@ltiroles) {
5394: unless ($selectnone) {
5395: if ($rolemaps{$role} eq $ltirole) {
5396: $selected = ' selected="selected"';
5397: } else {
5398: $selected = '';
5399: }
5400: }
5401: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5402: }
5403: $datatable .= '</select></td>';
5404: }
5405: $datatable .= '</tr></table></fieldset>'.
5406: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5407: '<legend>'.&mt('Custom items sent on launch').'</legend>'.
5408: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5409: '<tr><td></td><td>lms</td>'.
5410: '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
5411: ' value="Loncapa" disabled="disabled"/></td></tr>';
5412: if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
5413: (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
5414: my %custom = %{$settings->{$provider}->{'custom'}};
5415: if (keys(%custom) > 0) {
5416: foreach my $key (sort(keys(%custom))) {
5417: next if ($key eq 'lms');
5418: $datatable .= '<tr><td><span class="LC_nobreak">'.
5419: '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
5420: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
5421: '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
5422: ' value="'.$custom{$key}.'" /></td></tr>';
5423: }
5424: }
5425: }
5426: $datatable .= '<tr><td><span class="LC_nobreak">'.
5427: '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
5428: &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
5429: '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
5430: '</table></fieldset></td></tr>'."\n";
5431: }
5432: $datatable .= '</td></tr>';
5433: }
5434: $itemcount ++;
5435: }
5436: }
5437: return $datatable;
5438: }
5439:
5440: sub proctoring_data {
5441: my $requserfields = {
5442: proctorio => ['user'],
5443: examity => ['roles','user'],
5444: };
5445: my $optuserfields = {
5446: proctorio => ['fullname'],
5447: examity => ['fullname','firstname','lastname','email'],
5448: };
5449: my $defaults = {
5450: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
5451: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
5452: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
5453: 'closetabs','onescreen','print','downloads','cache','rightclick',
5454: 'reentry','calculator','whiteboard'],
5455: examity => ['display'],
5456: };
5457: my $extended = {
5458: proctorio => {
5459: verifyid => ['verifyidauto','verifyidlive'],
5460: fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
5461: tabslinks => ['notabs','linksonly'],
5462: reentry => ['noreentry','agentreentry'],
5463: calculator => ['calculatorbasic','calculatorsci'],
5464: },
5465: examity => {
5466: display => {
5467: target => ['iframe','tab','window'],
5468: width => '',
5469: height => '',
5470: linktext => '',
5471: explanation => '',
5472: },
5473: },
5474: };
5475: my $crsconf = {
5476: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
5477: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
5478: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
5479: 'closetabs','onescreen','print','downloads','cache','rightclick',
5480: 'reentry','calculator','whiteboard'],
5481: examity => ['label','title','target','linktext','explanation','append'],
5482: };
5483: my $courseroles = ['cc','in','ta','ep','st'];
5484: my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
5485: return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
5486: }
5487:
5488: sub proctoring_titles {
5489: my ($item) = @_;
5490: my (%common_lt,%custom_lt);
5491: %common_lt = &Apache::lonlocal::texthash (
5492: 'avai' => 'Available?',
5493: 'base' => 'Basic Settings',
5494: 'requ' => 'User data required to be sent on launch',
5495: 'optu' => 'User data optionally sent on launch',
5496: 'udsl' => 'User data sent on launch',
5497: 'defa' => 'Defaults for items configurable in course',
5498: 'sigmethod' => 'Signature Method',
5499: 'key' => 'Key',
5500: 'lifetime' => 'Nonce lifetime (s)',
5501: 'secret' => 'Secret',
5502: 'icon' => 'Icon',
5503: 'fullname' => 'Full Name',
5504: 'visible' => 'Visible input',
5505: 'username' => 'username',
5506: 'user' => 'User',
5507: );
5508: if ($item eq 'proctorio') {
5509: %custom_lt = &Apache::lonlocal::texthash (
5510: 'version' => 'OAuth version',
5511: 'url' => 'API URL',
5512: 'uname:dom' => 'username-domain',
5513: );
5514: } elsif ($item eq 'examity') {
5515: %custom_lt = &Apache::lonlocal::texthash (
5516: 'version' => 'LTI Version',
5517: 'url' => 'URL',
5518: 'uname:dom' => 'username:domain',
5519: 'msgtype' => 'Message Type',
5520: 'firstname' => 'First Name',
5521: 'lastname' => 'Last Name',
5522: 'email' => 'E-mail',
5523: 'roles' => 'Role',
5524: 'crstarget' => 'Display target',
5525: 'crslabel' => 'Course label',
5526: 'crstitle' => 'Course title',
5527: 'crslinktext' => 'Link Text',
5528: 'crsexplanation' => 'Explanation',
5529: 'crsappend' => 'Provider URL',
5530: );
5531: }
5532: my %lt = (%common_lt,%custom_lt);
5533: return %lt;
5534: }
5535:
5536: sub proctoring_fieldtitles {
5537: my ($item) = @_;
5538: if ($item eq 'proctorio') {
5539: return &Apache::lonlocal::texthash (
5540: 'recordvideo' => 'Record video',
5541: 'recordaudio' => 'Record audio',
5542: 'recordscreen' => 'Record screen',
5543: 'recordwebtraffic' => 'Record web traffic',
5544: 'recordroomstart' => 'Record room scan',
5545: 'verifyvideo' => 'Verify webcam',
5546: 'verifyaudio' => 'Verify microphone',
5547: 'verifydesktop' => 'Verify desktop recording',
5548: 'verifyid' => 'Photo ID verification',
5549: 'verifysignature' => 'Require signature',
5550: 'fullscreen' => 'Fullscreen',
5551: 'clipboard' => 'Disable copy/paste',
5552: 'tabslinks' => 'New tabs/windows',
5553: 'closetabs' => 'Close other tabs',
5554: 'onescreen' => 'Limit to single screen',
5555: 'print' => 'Disable Printing',
5556: 'downloads' => 'Disable Downloads',
5557: 'cache' => 'Empty cache after exam',
5558: 'rightclick' => 'Disable right click',
5559: 'reentry' => 'Re-entry to exam',
5560: 'calculator' => 'Onscreen calculator',
5561: 'whiteboard' => 'Onscreen whiteboard',
5562: 'verifyidauto' => 'Automated verification',
5563: 'verifyidlive' => 'Live agent verification',
5564: 'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
5565: 'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
5566: 'fullscreensever' => 'Forced, navigation away ends exam',
5567: 'notabs' => 'Disaallowed',
5568: 'linksonly' => 'Allowed from links in exam',
5569: 'noreentry' => 'Disallowed',
5570: 'agentreentry' => 'Agent required for re-entry',
5571: 'calculatorbasic' => 'Basic',
5572: 'calculatorsci' => 'Scientific',
5573: );
5574: } elsif ($item eq 'examity') {
5575: return &Apache::lonlocal::texthash (
5576: 'target' => 'Display target',
5577: 'window' => 'Window',
5578: 'tab' => 'Tab',
5579: 'iframe' => 'iFrame',
5580: 'height' => 'Height (pixels)',
5581: 'width' => 'Width (pixels)',
5582: 'linktext' => 'Default Link Text',
5583: 'explanation' => 'Default Explanation',
5584: 'append' => 'Provider URL',
5585: );
5586: }
5587: }
5588:
5589: sub proctoring_providernames {
5590: return (
5591: proctorio => 'Proctorio',
5592: examity => 'Examity',
5593: );
5594: }
5595:
1.320 raeburn 5596: sub print_lti {
5597: my ($dom,$settings,$rowtotal) = @_;
5598: my $itemcount = 1;
5599: my $maxnum = 0;
5600: my $css_class;
5601: my %ordered;
5602: if (ref($settings) eq 'HASH') {
5603: foreach my $item (keys(%{$settings})) {
5604: if (ref($settings->{$item}) eq 'HASH') {
5605: my $num = $settings->{$item}{'order'};
5606: $ordered{$num} = $item;
5607: }
5608: }
5609: }
5610: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 5611: my $datatable;
1.320 raeburn 5612: my %lt = <i_names();
5613: if (keys(%ordered)) {
5614: my @items = sort { $a <=> $b } keys(%ordered);
5615: for (my $i=0; $i<@items; $i++) {
5616: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5617: my $item = $ordered{$items[$i]};
1.345 raeburn 5618: my ($key,$secret,$lifetime,$consumer,$requser,$current);
1.320 raeburn 5619: if (ref($settings->{$item}) eq 'HASH') {
5620: $key = $settings->{$item}->{'key'};
5621: $secret = $settings->{$item}->{'secret'};
5622: $lifetime = $settings->{$item}->{'lifetime'};
5623: $consumer = $settings->{$item}->{'consumer'};
1.345 raeburn 5624: $requser = $settings->{$item}->{'requser'};
1.320 raeburn 5625: $current = $settings->{$item};
5626: }
1.345 raeburn 5627: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
5628: my %checkedrequser = (
5629: yes => ' checked="checked"',
5630: no => '',
5631: );
5632: if (!$requser) {
5633: $checkedrequser{'no'} = $checkedrequser{'yes'};
5634: $checkedrequser{'yes'} = '';
1.352 raeburn 5635: }
1.320 raeburn 5636: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
5637: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5638: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
5639: for (my $k=0; $k<=$maxnum; $k++) {
5640: my $vpos = $k+1;
5641: my $selstr;
5642: if ($k == $i) {
5643: $selstr = ' selected="selected" ';
5644: }
5645: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5646: }
5647: $datatable .= '</select>'.(' 'x2).
5648: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
5649: &mt('Delete?').'</label></span></td>'.
5650: '<td colspan="2">'.
5651: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5652: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 5653: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
1.320 raeburn 5654: (' 'x2).
5655: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
5656: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
5657: (' 'x2).
5658: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.345 raeburn 5659: 'value="'.$lifetime.'" size="3" /></span>'.
5660: (' 'x2).
5661: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
5662: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
5663: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 5664: '<br /><br />'.
5665: '<span class="LC_nobreak">'.$lt{'key'}.
5666: ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
5667: (' 'x2).
5668: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
5669: '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
5670: '<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>'.
5671: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
1.325 raeburn 5672: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
1.320 raeburn 5673: $itemcount ++;
5674: }
5675: }
5676: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5677: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
5678: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
5679: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
5680: '<select name="lti_pos_add"'.$chgstr.'>';
5681: for (my $k=0; $k<$maxnum+1; $k++) {
5682: my $vpos = $k+1;
5683: my $selstr;
5684: if ($k == $maxnum) {
5685: $selstr = ' selected="selected" ';
5686: }
5687: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5688: }
5689: $datatable .= '</select> '."\n".
1.334 raeburn 5690: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.320 raeburn 5691: '<td colspan="2">'.
5692: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5693: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 5694: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
1.320 raeburn 5695: (' 'x2).
5696: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
5697: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
5698: (' 'x2).
1.345 raeburn 5699: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span> '."\n".
5700: (' 'x2).
5701: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
5702: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
5703: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 5704: '<br /><br />'.
5705: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
5706: (' 'x2).
5707: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
5708: '<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 5709: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
1.320 raeburn 5710: '</td>'."\n".
5711: '</tr>'."\n";
5712: $$rowtotal ++;
5713: return $datatable;;
5714: }
5715:
5716: sub lti_names {
5717: my %lt = &Apache::lonlocal::texthash(
5718: 'version' => 'LTI Version',
5719: 'url' => 'URL',
5720: 'key' => 'Key',
1.322 raeburn 5721: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 5722: 'consumer' => 'Consumer',
1.320 raeburn 5723: 'secret' => 'Secret',
1.345 raeburn 5724: 'requser' => "User's identity sent",
1.320 raeburn 5725: 'email' => 'Email address',
5726: 'sourcedid' => 'User ID',
5727: 'other' => 'Other',
5728: 'passback' => 'Can return grades to Consumer:',
5729: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 5730: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 5731: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 5732: );
5733: return %lt;
5734: }
5735:
5736: sub lti_options {
1.325 raeburn 5737: my ($num,$current,$itemcount,%lt) = @_;
1.363 raeburn 5738: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320 raeburn 5739: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
5740: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
5741: $checked{'makecrs'}{'N'} = ' checked="checked"';
5742: $checked{'mapcrstype'} = {};
5743: $checked{'makeuser'} = {};
5744: $checked{'selfenroll'} = {};
5745: $checked{'crssec'} = {};
5746: $checked{'crssecsrc'} = {};
1.325 raeburn 5747: $checked{'lcauth'} = {};
1.326 raeburn 5748: $checked{'menuitem'} = {};
1.325 raeburn 5749: if ($num eq 'add') {
5750: $checked{'lcauth'}{'lti'} = ' checked="checked"';
5751: }
1.320 raeburn 5752: my $userfieldsty = 'none';
5753: my $crsfieldsty = 'none';
5754: my $crssecfieldsty = 'none';
5755: my $secsrcfieldsty = 'none';
1.363 raeburn 5756: my $callbacksty = 'none';
1.337 raeburn 5757: my $passbacksty = 'none';
1.345 raeburn 5758: my $optionsty = 'block';
1.325 raeburn 5759: my $lcauthparm;
5760: my $lcauthparmstyle = 'display:none';
5761: my $lcauthparmtext;
1.326 raeburn 5762: my $menusty;
1.325 raeburn 5763: my $numinrow = 4;
1.326 raeburn 5764: my %menutitles = <imenu_titles();
1.320 raeburn 5765:
5766: if (ref($current) eq 'HASH') {
1.345 raeburn 5767: if (!$current->{'requser'}) {
5768: $optionsty = 'none';
5769: }
1.320 raeburn 5770: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
5771: $checked{'mapuser'}{'sourcedid'} = '';
5772: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
5773: $checked{'mapuser'}{'email'} = ' checked="checked"';
5774: } else {
5775: $checked{'mapuser'}{'other'} = ' checked="checked"';
5776: $userfield = $current->{'mapuser'};
5777: $userfieldsty = 'inline-block';
5778: }
5779: }
5780: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
5781: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
5782: if ($current->{'mapcrs'} eq 'context_id') {
5783: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
5784: } else {
5785: $checked{'mapcrs'}{'other'} = ' checked="checked"';
5786: $cidfield = $current->{'mapcrs'};
5787: $crsfieldsty = 'inline-block';
5788: }
5789: }
5790: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
5791: foreach my $type (@{$current->{'mapcrstype'}}) {
5792: $checked{'mapcrstype'}{$type} = ' checked="checked"';
5793: }
5794: }
1.345 raeburn 5795: if ($current->{'makecrs'}) {
1.320 raeburn 5796: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 5797: }
1.320 raeburn 5798: if (ref($current->{'makeuser'}) eq 'ARRAY') {
5799: foreach my $role (@{$current->{'makeuser'}}) {
5800: $checked{'makeuser'}{$role} = ' checked="checked"';
5801: }
5802: }
1.325 raeburn 5803: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
5804: $checked{'lcauth'}{$1} = ' checked="checked"';
5805: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
5806: $lcauthparm = $current->{'lcauthparm'};
5807: $lcauthparmstyle = 'display:table-row';
5808: if ($current->{'lcauth'} eq 'localauth') {
5809: $lcauthparmtext = &mt('Local auth argument');
5810: } else {
5811: $lcauthparmtext = &mt('Kerberos domain');
5812: }
5813: }
5814: }
1.320 raeburn 5815: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
5816: foreach my $role (@{$current->{'selfenroll'}}) {
5817: $checked{'selfenroll'}{$role} = ' checked="checked"';
5818: }
5819: }
5820: if (ref($current->{'maproles'}) eq 'HASH') {
5821: %rolemaps = %{$current->{'maproles'}};
5822: }
5823: if ($current->{'section'} ne '') {
5824: $checked{'crssec'}{'Y'} = ' checked="checked"';
5825: $crssecfieldsty = 'inline-block';
5826: if ($current->{'section'} eq 'course_section_sourcedid') {
5827: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
5828: } else {
5829: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
5830: $crssecsrc = $current->{'section'};
5831: $secsrcfieldsty = 'inline-block';
5832: }
5833: } else {
5834: $checked{'crssec'}{'N'} = ' checked="checked"';
5835: }
1.363 raeburn 5836: if ($current->{'callback'} ne '') {
5837: $callback = $current->{'callback'};
5838: $checked{'callback'}{'Y'} = ' checked="checked"';
5839: $callbacksty = 'inline-block';
5840: } else {
5841: $checked{'callback'}{'N'} = ' checked="checked"';
5842: }
1.326 raeburn 5843: if ($current->{'topmenu'}) {
5844: $checked{'topmenu'}{'Y'} = ' checked="checked"';
5845: } else {
5846: $checked{'topmenu'}{'N'} = ' checked="checked"';
5847: }
5848: if ($current->{'inlinemenu'}) {
5849: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5850: } else {
5851: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
5852: }
5853: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
5854: $menusty = 'inline-block';
5855: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
5856: foreach my $item (@{$current->{'lcmenu'}}) {
5857: if (exists($menutitles{$item})) {
5858: $checked{'menuitem'}{$item} = ' checked="checked"';
5859: }
5860: }
5861: }
5862: } else {
5863: $menusty = 'none';
5864: }
1.320 raeburn 5865: } else {
5866: $checked{'makecrs'}{'N'} = ' checked="checked"';
5867: $checked{'crssec'}{'N'} = ' checked="checked"';
1.363 raeburn 5868: $checked{'callback'}{'N'} = ' checked="checked"';
1.326 raeburn 5869: $checked{'topmenu'}{'N'} = ' checked="checked"';
5870: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5871: $checked{'menuitem'}{'grades'} = ' checked="checked"';
5872: $menusty = 'inline-block';
1.320 raeburn 5873: }
1.325 raeburn 5874: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 5875: my %coursetypetitles = &Apache::lonlocal::texthash (
5876: official => 'Official',
5877: unofficial => 'Unofficial',
5878: community => 'Community',
5879: textbook => 'Textbook',
5880: placement => 'Placement Test',
1.325 raeburn 5881: lti => 'LTI Provider',
1.320 raeburn 5882: );
1.325 raeburn 5883: my @authtypes = ('internal','krb4','krb5','localauth');
5884: my %shortauth = (
5885: internal => 'int',
5886: krb4 => 'krb4',
5887: krb5 => 'krb5',
5888: localauth => 'loc'
5889: );
5890: my %authnames = &authtype_names();
1.320 raeburn 5891: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
5892: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
5893: my @courseroles = ('cc','in','ta','ep','st');
5894: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
5895: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
5896: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363 raeburn 5897: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320 raeburn 5898: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 5899: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 5900: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.345 raeburn 5901: my $output = '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 5902: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
5903: foreach my $option ('sourcedid','email','other') {
5904: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
5905: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
5906: ($option eq 'other' ? '' : (' 'x2) );
5907: }
5908: $output .= '</span></div>'.
5909: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
5910: '<input type="text" name="lti_customuser_'.$num.'" '.
1.372 raeburn 5911: 'value="'.$userfield.'" /></div></fieldset>'.
1.345 raeburn 5912: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
1.320 raeburn 5913: foreach my $ltirole (@lticourseroles) {
5914: my ($selected,$selectnone);
5915: if ($rolemaps{$ltirole} eq '') {
5916: $selectnone = ' selected="selected"';
5917: }
5918: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
5919: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
5920: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5921: foreach my $role (@courseroles) {
5922: unless ($selectnone) {
5923: if ($rolemaps{$ltirole} eq $role) {
5924: $selected = ' selected="selected"';
5925: } else {
5926: $selected = '';
5927: }
5928: }
5929: $output .= '<option value="'.$role.'"'.$selected.'>'.
5930: &Apache::lonnet::plaintext($role,'Course').
5931: '</option>';
5932: }
5933: $output .= '</select></td>';
5934: }
5935: $output .= '</tr></table></fieldset>'.
1.345 raeburn 5936: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 5937: foreach my $ltirole (@ltiroles) {
5938: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
5939: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
5940: }
5941: $output .= '</fieldset>'.
1.345 raeburn 5942: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 5943: '<table>'.
5944: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
5945: '</table>'.
5946: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
5947: '<td class="LC_left_item">';
5948: foreach my $auth ('lti',@authtypes) {
5949: my $authtext;
5950: if ($auth eq 'lti') {
5951: $authtext = &mt('None');
5952: } else {
5953: $authtext = $authnames{$shortauth{$auth}};
5954: }
5955: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
5956: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
5957: $authtext.'</label></span> ';
5958: }
5959: $output .= '</td></tr>'.
5960: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
5961: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
5962: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
5963: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
5964: '</table></fieldset>'.
1.345 raeburn 5965: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 5966: '<div class="LC_floatleft"><span class="LC_nobreak">'.
5967: &mt('Unique course identifier').': ';
5968: foreach my $option ('course_offering_sourcedid','context_id','other') {
5969: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
5970: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
5971: ($option eq 'other' ? '' : (' 'x2) );
5972: }
1.334 raeburn 5973: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 5974: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
5975: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
5976: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
5977: foreach my $type (@coursetypes) {
5978: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
5979: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
5980: (' 'x2);
5981: }
5982: $output .= '</span></fieldset>'.
1.345 raeburn 5983: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 5984: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
5985: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
5986: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
5987: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
5988: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
5989: '</fieldset>'.
1.345 raeburn 5990: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 5991: foreach my $lticrsrole (@lticourseroles) {
5992: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
5993: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
5994: }
5995: $output .= '</fieldset>'.
1.345 raeburn 5996: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 5997: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
5998: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
5999: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
6000: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 6001: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 6002: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
6003: '<span class="LC_nobreak">'.&mt('From').':<label>'.
6004: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
6005: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
6006: &mt('Standard field').'</label>'.(' 'x2).
6007: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
6008: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 6009: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 6010: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 6011: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6012: my ($pb1p1chk,$pb1p0chk,$onclickpb);
6013: foreach my $extra ('roster','passback') {
1.320 raeburn 6014: my $checkedon = '';
6015: my $checkedoff = ' checked="checked"';
1.337 raeburn 6016: if ($extra eq 'passback') {
6017: $pb1p1chk = ' checked="checked"';
6018: $pb1p0chk = '';
6019: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
6020: } else {
6021: $onclickpb = '';
6022: }
1.320 raeburn 6023: if (ref($current) eq 'HASH') {
6024: if (($current->{$extra})) {
6025: $checkedon = $checkedoff;
6026: $checkedoff = '';
1.337 raeburn 6027: if ($extra eq 'passback') {
6028: $passbacksty = 'inline-block';
6029: }
6030: if ($current->{'passbackformat'} eq '1.0') {
6031: $pb1p0chk = ' checked="checked"';
6032: $pb1p1chk = '';
6033: }
1.320 raeburn 6034: }
6035: }
6036: $output .= $lt{$extra}.' '.
1.337 raeburn 6037: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 6038: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 6039: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 6040: &mt('Yes').'</label><br />';
6041: }
1.337 raeburn 6042: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
6043: '<span class="LC_nobreak">'.&mt('Grade format').
6044: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
6045: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
6046: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363 raeburn 6047: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
6048: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6049: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback on logout').': '.
6050: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
6051: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
6052: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
6053: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
6054: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
6055: '<span class="LC_nobreak">'.&mt('Parameter').': '.
6056: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
6057: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
1.345 raeburn 6058: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Course defaults (Course Coordinator can override)').'</legend>'.
1.326 raeburn 6059: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
6060: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
6061: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6062: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
1.334 raeburn 6063: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
1.326 raeburn 6064: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6065: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
6066: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
6067: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6068: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
1.334 raeburn 6069: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
1.326 raeburn 6070: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6071: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
6072: '<span class="LC_nobreak">'.&mt('Menu items').': ';
6073: foreach my $type ('fullname','coursetitle','role','logout','grades') {
6074: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
6075: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
6076: (' 'x2);
6077: }
1.334 raeburn 6078: $output .= '</span></div></fieldset>';
1.320 raeburn 6079: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
6080: #
6081: # $output .= '</fieldset>'.
6082: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
6083: return $output;
6084: }
6085:
1.326 raeburn 6086: sub ltimenu_titles {
6087: return &Apache::lonlocal::texthash(
6088: fullname => 'Full name',
6089: coursetitle => 'Course title',
6090: role => 'Role',
6091: logout => 'Logout',
6092: grades => 'Grades',
6093: );
6094: }
6095:
1.121 raeburn 6096: sub print_coursedefaults {
1.139 raeburn 6097: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 6098: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 6099: my $itemcount = 1;
1.192 raeburn 6100: my %choices = &Apache::lonlocal::texthash (
6101: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 6102: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 6103: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6104: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 6105: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6106: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.314 raeburn 6107: texengine => 'Default method to display mathematics',
1.257 raeburn 6108: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 6109: canclone => "People who may clone a course (besides course's owner and coordinators)",
6110: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 6111: );
1.198 raeburn 6112: my %staticdefaults = (
6113: anonsurvey_threshold => 10,
6114: uploadquota => 500,
1.257 raeburn 6115: postsubmit => 60,
1.276 raeburn 6116: mysqltables => 172800,
1.198 raeburn 6117: );
1.139 raeburn 6118: if ($position eq 'top') {
1.257 raeburn 6119: %defaultchecked = (
6120: 'canuse_pdfforms' => 'off',
6121: 'uselcmath' => 'on',
6122: 'usejsme' => 'on',
1.289 raeburn 6123: 'canclone' => 'none',
1.257 raeburn 6124: );
6125: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.349 raeburn 6126: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 6127: if (ref($settings) eq 'HASH') {
6128: if ($settings->{'texengine'}) {
6129: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6130: $deftex = $settings->{'texengine'};
6131: }
6132: }
6133: }
6134: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6135: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6136: '<span class="LC_nobreak">'.$choices{'texengine'}.
6137: '</span></td><td class="LC_right_item">'.
6138: '<select name="texengine">'."\n";
6139: my %texoptions = (
6140: MathJax => 'MathJax',
6141: mimetex => &mt('Convert to Images'),
6142: tth => &mt('TeX to HTML'),
6143: );
6144: foreach my $renderer ('MathJax','mimetex','tth') {
6145: my $selected = '';
6146: if ($renderer eq $deftex) {
6147: $selected = ' selected="selected"';
6148: }
6149: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6150: }
6151: $mathdisp .= '</select></td></tr>'."\n";
6152: $itemcount ++;
1.139 raeburn 6153: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 6154: \%choices,$itemcount);
1.314 raeburn 6155: $datatable = $mathdisp.$datatable;
1.264 raeburn 6156: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6157: $datatable .=
1.306 raeburn 6158: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 6159: '<span class="LC_nobreak">'.$choices{'canclone'}.
6160: '</span></td><td class="LC_left_item">';
6161: my $currcanclone = 'none';
6162: my $onclick;
6163: my @cloneoptions = ('none','domain');
6164: my %clonetitles = (
6165: none => 'No additional course requesters',
6166: domain => "Any course requester in course's domain",
6167: instcode => 'Course requests for official courses ...',
6168: );
6169: my (%codedefaults,@code_order,@posscodes);
6170: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6171: \@code_order) eq 'ok') {
6172: if (@code_order > 0) {
6173: push(@cloneoptions,'instcode');
6174: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6175: }
6176: }
6177: if (ref($settings) eq 'HASH') {
6178: if ($settings->{'canclone'}) {
6179: if (ref($settings->{'canclone'}) eq 'HASH') {
6180: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6181: if (@code_order > 0) {
6182: $currcanclone = 'instcode';
6183: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6184: }
6185: }
6186: } elsif ($settings->{'canclone'} eq 'domain') {
6187: $currcanclone = $settings->{'canclone'};
6188: }
6189: }
1.289 raeburn 6190: }
1.264 raeburn 6191: foreach my $option (@cloneoptions) {
6192: my ($checked,$additional);
6193: if ($currcanclone eq $option) {
6194: $checked = ' checked="checked"';
6195: }
6196: if ($option eq 'instcode') {
6197: if (@code_order) {
6198: my $show = 'none';
6199: if ($checked) {
6200: $show = 'block';
6201: }
1.317 raeburn 6202: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 6203: &mt('Institutional codes for new and cloned course have identical:').
6204: '<br />';
6205: foreach my $item (@code_order) {
6206: my $codechk;
6207: if ($checked) {
6208: if (grep(/^\Q$item\E$/,@posscodes)) {
6209: $codechk = ' checked="checked"';
6210: }
6211: }
6212: $additional .= '<label>'.
6213: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
6214: $item.'</label>';
6215: }
6216: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
6217: }
6218: }
6219: $datatable .=
6220: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
6221: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
6222: '</label> '.$additional.'</span><br />';
6223: }
6224: $datatable .= '</td>'.
6225: '</tr>';
6226: $itemcount ++;
1.139 raeburn 6227: } else {
6228: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 6229: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 6230: my $currusecredits = 0;
1.257 raeburn 6231: my $postsubmitclient = 1;
1.271 raeburn 6232: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 6233: if (ref($settings) eq 'HASH') {
6234: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 6235: if (ref($settings->{'uploadquota'}) eq 'HASH') {
6236: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
6237: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
6238: }
6239: }
1.192 raeburn 6240: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 6241: foreach my $type (@types) {
6242: next if ($type eq 'community');
6243: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
6244: if ($defcredits{$type} ne '') {
6245: $currusecredits = 1;
6246: }
6247: }
6248: }
6249: if (ref($settings->{'postsubmit'}) eq 'HASH') {
6250: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
6251: $postsubmitclient = 0;
6252: foreach my $type (@types) {
6253: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6254: }
6255: } else {
6256: foreach my $type (@types) {
6257: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
6258: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 6259: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 6260: } else {
6261: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6262: }
6263: } else {
6264: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6265: }
6266: }
6267: }
6268: } else {
6269: foreach my $type (@types) {
6270: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 6271: }
6272: }
1.276 raeburn 6273: if (ref($settings->{'mysqltables'}) eq 'HASH') {
6274: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
6275: $currmysql{$type} = $settings->{'mysqltables'}{$type};
6276: }
6277: } else {
6278: foreach my $type (@types) {
6279: $currmysql{$type} = $staticdefaults{'mysqltables'};
6280: }
6281: }
1.258 raeburn 6282: } else {
6283: foreach my $type (@types) {
6284: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6285: }
1.139 raeburn 6286: }
6287: if (!$currdefresponder) {
1.198 raeburn 6288: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 6289: } elsif ($currdefresponder < 1) {
6290: $currdefresponder = 1;
6291: }
1.198 raeburn 6292: foreach my $type (@types) {
6293: if ($curruploadquota{$type} eq '') {
6294: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
6295: }
6296: }
1.139 raeburn 6297: $datatable .=
1.192 raeburn 6298: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6299: $choices{'anonsurvey_threshold'}.
1.139 raeburn 6300: '</span></td>'.
6301: '<td class="LC_right_item"><span class="LC_nobreak">'.
6302: '<input type="text" name="anonsurvey_threshold"'.
6303: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 6304: '</td></tr>'."\n";
6305: $itemcount ++;
6306: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6307: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6308: $choices{'uploadquota'}.
6309: '</span></td>'.
1.306 raeburn 6310: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 6311: '<table><tr>';
1.198 raeburn 6312: foreach my $type (@types) {
1.306 raeburn 6313: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 6314: '<input type="text" name="uploadquota_'.$type.'"'.
6315: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
6316: }
6317: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 6318: $itemcount ++;
1.236 raeburn 6319: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 6320: my $display = 'none';
1.192 raeburn 6321: if ($currusecredits) {
6322: $display = 'block';
6323: }
6324: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 6325: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
6326: foreach my $type (@types) {
6327: next if ($type eq 'community');
1.306 raeburn 6328: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 6329: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 6330: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 6331: }
6332: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 6333: %defaultchecked = ('coursecredits' => 'off');
6334: @toggles = ('coursecredits');
6335: my $current = {
6336: 'coursecredits' => $currusecredits,
6337: };
6338: (my $table,$itemcount) =
6339: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 6340: \%choices,$itemcount,$onclick,$additional,'left');
6341: $datatable .= $table;
6342: $onclick = "toggleDisplay(this.form,'studentsubmission');";
6343: my $display = 'none';
6344: if ($postsubmitclient) {
6345: $display = 'block';
6346: }
6347: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 6348: &mt('Number of seconds submit is disabled').'<br />'.
6349: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
6350: '<table><tr>';
1.257 raeburn 6351: foreach my $type (@types) {
1.306 raeburn 6352: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 6353: '<input type="text" name="'.$type.'_timeout" value="'.
6354: $deftimeout{$type}.'" size="5" /></td>';
6355: }
6356: $additional .= '</tr></table></div>'."\n";
6357: %defaultchecked = ('postsubmit' => 'on');
6358: @toggles = ('postsubmit');
1.280 raeburn 6359: $current = {
6360: 'postsubmit' => $postsubmitclient,
6361: };
1.257 raeburn 6362: ($table,$itemcount) =
6363: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
6364: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 6365: $datatable .= $table;
1.276 raeburn 6366: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6367: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6368: $choices{'mysqltables'}.
6369: '</span></td>'.
1.306 raeburn 6370: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 6371: '<table><tr>';
6372: foreach my $type (@types) {
1.306 raeburn 6373: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 6374: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 6375: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 6376: }
6377: $datatable .= '</tr></table></td></tr>'."\n";
6378: $itemcount ++;
6379:
1.139 raeburn 6380: }
1.192 raeburn 6381: $$rowtotal += $itemcount;
1.121 raeburn 6382: return $datatable;
1.118 jms 6383: }
6384:
1.231 raeburn 6385: sub print_selfenrollment {
6386: my ($position,$dom,$settings,$rowtotal) = @_;
6387: my ($css_class,$datatable);
6388: my $itemcount = 1;
1.271 raeburn 6389: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 6390: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 6391: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
6392: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 6393: my @rows;
6394: my $key;
6395: if ($position eq 'top') {
6396: $key = 'admin';
6397: if (ref($rowsref) eq 'ARRAY') {
6398: @rows = @{$rowsref};
6399: }
6400: } elsif ($position eq 'middle') {
6401: $key = 'default';
6402: @rows = ('types','registered','approval','limit');
6403: }
6404: foreach my $row (@rows) {
6405: if (defined($titlesref->{$row})) {
6406: $itemcount ++;
6407: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6408: $datatable .= '<tr'.$css_class.'>'.
6409: '<td>'.$titlesref->{$row}.'</td>'.
6410: '<td class="LC_left_item">'.
6411: '<table><tr>';
6412: my (%current,%currentcap);
6413: if (ref($settings) eq 'HASH') {
6414: if (ref($settings->{$key}) eq 'HASH') {
6415: foreach my $type (@types) {
6416: if (ref($settings->{$key}->{$type}) eq 'HASH') {
6417: $current{$type} = $settings->{$key}->{$type}->{$row};
6418: }
6419: if (($row eq 'limit') && ($key eq 'default')) {
6420: if (ref($settings->{$key}->{$type}) eq 'HASH') {
6421: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
6422: }
6423: }
6424: }
6425: }
6426: }
6427: my %roles = (
6428: '0' => &Apache::lonnet::plaintext('dc'),
6429: );
6430:
6431: foreach my $type (@types) {
6432: unless (($row eq 'registered') && ($key eq 'default')) {
6433: $datatable .= '<th>'.&mt($type).'</th>';
6434: }
6435: }
6436: unless (($row eq 'registered') && ($key eq 'default')) {
6437: $datatable .= '</tr><tr>';
6438: }
6439: foreach my $type (@types) {
6440: if ($type eq 'community') {
6441: $roles{'1'} = &mt('Community personnel');
6442: } else {
6443: $roles{'1'} = &mt('Course personnel');
6444: }
6445: $datatable .= '<td style="vertical-align: top">';
6446: if ($position eq 'top') {
6447: my %checked;
6448: if ($current{$type} eq '0') {
6449: $checked{'0'} = ' checked="checked"';
6450: } else {
6451: $checked{'1'} = ' checked="checked"';
6452: }
6453: foreach my $role ('1','0') {
6454: $datatable .= '<span class="LC_nobreak"><label>'.
6455: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
6456: 'value="'.$role.'"'.$checked{$role}.' />'.
6457: $roles{$role}.'</label></span> ';
6458: }
6459: } else {
6460: if ($row eq 'types') {
6461: my %checked;
6462: if ($current{$type} =~ /^(all|dom)$/) {
6463: $checked{$1} = ' checked="checked"';
6464: } else {
6465: $checked{''} = ' checked="checked"';
6466: }
6467: foreach my $val ('','dom','all') {
6468: $datatable .= '<span class="LC_nobreak"><label>'.
6469: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6470: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6471: }
6472: } elsif ($row eq 'registered') {
6473: my %checked;
6474: if ($current{$type} eq '1') {
6475: $checked{'1'} = ' checked="checked"';
6476: } else {
6477: $checked{'0'} = ' checked="checked"';
6478: }
6479: foreach my $val ('0','1') {
6480: $datatable .= '<span class="LC_nobreak"><label>'.
6481: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6482: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6483: }
6484: } elsif ($row eq 'approval') {
6485: my %checked;
6486: if ($current{$type} =~ /^([12])$/) {
6487: $checked{$1} = ' checked="checked"';
6488: } else {
6489: $checked{'0'} = ' checked="checked"';
6490: }
6491: for my $val (0..2) {
6492: $datatable .= '<span class="LC_nobreak"><label>'.
6493: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6494: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6495: }
6496: } elsif ($row eq 'limit') {
6497: my %checked;
6498: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
6499: $checked{$1} = ' checked="checked"';
6500: } else {
6501: $checked{'none'} = ' checked="checked"';
6502: }
6503: my $cap;
6504: if ($currentcap{$type} =~ /^\d+$/) {
6505: $cap = $currentcap{$type};
6506: }
6507: foreach my $val ('none','allstudents','selfenrolled') {
6508: $datatable .= '<span class="LC_nobreak"><label>'.
6509: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6510: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6511: }
6512: $datatable .= '<br />'.
6513: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
6514: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
6515: '</span>';
6516: }
6517: }
6518: $datatable .= '</td>';
6519: }
6520: $datatable .= '</tr>';
6521: }
6522: $datatable .= '</table></td></tr>';
6523: }
6524: } elsif ($position eq 'bottom') {
1.235 raeburn 6525: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
6526: }
6527: $$rowtotal += $itemcount;
6528: return $datatable;
6529: }
6530:
6531: sub print_validation_rows {
6532: my ($caller,$dom,$settings,$rowtotal) = @_;
6533: my ($itemsref,$namesref,$fieldsref);
6534: if ($caller eq 'selfenroll') {
6535: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
6536: } elsif ($caller eq 'requestcourses') {
6537: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
6538: }
6539: my %currvalidation;
6540: if (ref($settings) eq 'HASH') {
6541: if (ref($settings->{'validation'}) eq 'HASH') {
6542: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 6543: }
1.235 raeburn 6544: }
6545: my $datatable;
6546: my $itemcount = 0;
6547: foreach my $item (@{$itemsref}) {
6548: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6549: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6550: $namesref->{$item}.
6551: '</span></td>'.
6552: '<td class="LC_left_item">';
6553: if (($item eq 'url') || ($item eq 'button')) {
6554: $datatable .= '<span class="LC_nobreak">'.
6555: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
6556: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
6557: } elsif ($item eq 'fields') {
6558: my @currfields;
6559: if (ref($currvalidation{$item}) eq 'ARRAY') {
6560: @currfields = @{$currvalidation{$item}};
6561: }
6562: foreach my $field (@{$fieldsref}) {
6563: my $check = '';
6564: if (grep(/^\Q$field\E$/,@currfields)) {
6565: $check = ' checked="checked"';
6566: }
6567: $datatable .= '<span class="LC_nobreak"><label>'.
6568: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
6569: ' value="'.$field.'"'.$check.' />'.$field.
6570: '</label></span> ';
6571: }
6572: } elsif ($item eq 'markup') {
1.334 raeburn 6573: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 6574: $currvalidation{$item}.
1.231 raeburn 6575: '</textarea>';
1.235 raeburn 6576: }
6577: $datatable .= '</td></tr>'."\n";
6578: if (ref($rowtotal)) {
1.231 raeburn 6579: $itemcount ++;
6580: }
6581: }
1.235 raeburn 6582: if ($caller eq 'requestcourses') {
6583: my %currhash;
1.248 raeburn 6584: if (ref($settings) eq 'HASH') {
6585: if (ref($settings->{'validation'}) eq 'HASH') {
6586: if ($settings->{'validation'}{'dc'} ne '') {
6587: $currhash{$settings->{'validation'}{'dc'}} = 1;
6588: }
1.235 raeburn 6589: }
6590: }
6591: my $numinrow = 2;
6592: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
6593: 'validationdc',%currhash);
1.247 raeburn 6594: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 6595: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 6596: if ($numdc > 1) {
1.247 raeburn 6597: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 6598: } else {
1.247 raeburn 6599: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 6600: }
1.247 raeburn 6601: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 6602: $itemcount ++;
6603: }
6604: if (ref($rowtotal)) {
6605: $$rowtotal += $itemcount;
6606: }
1.231 raeburn 6607: return $datatable;
6608: }
6609:
1.357 raeburn 6610: sub print_privacy {
6611: my ($position,$dom,$settings,$rowtotal) = @_;
6612: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
6613: my $itemcount = 0;
6614: unless ($position eq 'top') {
6615: @items = ('domain','author','course','community');
6616: %names = &Apache::lonlocal::texthash (
6617: domain => 'Assigned domain role(s)',
6618: author => 'Assigned co-author role(s)',
6619: course => 'Assigned course role(s)',
6620: community => 'Assigned community role',
6621: );
6622: $numinrow = 4;
6623: ($othertitle,$usertypes,$types) =
6624: &Apache::loncommon::sorted_inst_types($dom);
6625: }
6626: if (($position eq 'top') || ($position eq 'middle')) {
6627: my (%by_ip,%by_location,@intdoms,@instdoms);
6628: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
6629: if ($position eq 'top') {
6630: my %curr;
6631: my @options = ('none','user','domain','auto');
6632: my %titles = &Apache::lonlocal::texthash (
6633: none => 'Not allowed',
6634: user => 'User authorizes',
6635: domain => 'DC authorizes',
6636: auto => 'Unrestricted',
6637: instdom => 'Other domain shares institution/provider',
6638: extdom => 'Other domain has different institution/provider',
6639: );
6640: my %names = &Apache::lonlocal::texthash (
6641: domain => 'Domain role',
6642: author => 'Co-author role',
6643: course => 'Course role',
6644: community => 'Community role',
6645: );
6646: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6647: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6648: foreach my $domtype ('instdom','extdom') {
6649: my (%checked,$skip);
6650: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6651: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
6652: '<td class="LC_left_item">';
6653: if ($domtype eq 'instdom') {
6654: unless (@instdoms > 1) {
6655: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
6656: $skip = 1;
6657: }
6658: } elsif ($domtype eq 'extdom') {
6659: if (keys(%by_location) == 0) {
6660: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
6661: $skip = 1;
6662: }
6663: }
6664: unless ($skip) {
6665: foreach my $roletype ('domain','author','course','community') {
6666: $checked{'auto'} = ' checked="checked"';
6667: if (ref($settings) eq 'HASH') {
6668: if (ref($settings->{approval}) eq 'HASH') {
6669: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
6670: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
6671: $checked{$1} = ' checked="checked"';
6672: $checked{'auto'} = '';
6673: }
6674: }
6675: }
6676: }
6677: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
6678: foreach my $option (@options) {
6679: $datatable .= '<span class="LC_nobreak"><label>'.
6680: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
6681: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
6682: '</label></span> ';
6683: }
6684: $datatable .= '</fieldset>';
6685: }
6686: }
6687: $datatable .= '</td></tr>';
6688: $itemcount ++;
6689: }
6690: } elsif ($position eq 'middle') {
6691: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
6692: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6693: foreach my $item (@{$types}) {
6694: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
6695: $numinrow,$itemcount,'','','','','',
6696: '',$usertypes->{$item});
6697: $itemcount ++;
6698: }
6699: }
6700: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
6701: $numinrow,$itemcount,'','','','','',
6702: '',$othertitle);
6703: $itemcount ++;
6704: } else {
1.360 raeburn 6705: my (@insttypes,%insttitles);
6706: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6707: @insttypes = @{$types};
6708: %insttitles = %{$usertypes};
6709: }
6710: foreach my $item (@insttypes,'default') {
6711: my $title;
6712: if ($item eq 'default') {
6713: $title = $othertitle;
6714: } else {
6715: $title = $insttitles{$item};
6716: }
6717: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6718: $datatable .= '<tr'.$css_class.'>'.
6719: '<td class="LC_left_item">'.$title.'</td>'.
6720: '<td class="LC_left_item">'.
6721: &mt('Nothing to set here, as there are no other domains').
6722: '</td></tr>';
6723: $itemcount ++;
6724: }
1.357 raeburn 6725: }
6726: }
6727: } else {
6728: my $prefix;
6729: if ($position eq 'lower') {
6730: $prefix = 'priv';
6731: } else {
6732: $prefix = 'unpriv';
6733: }
6734: foreach my $item (@items) {
6735: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
6736: $numinrow,$itemcount,'','','','','',
6737: '',$names{$item});
6738: $itemcount ++;
6739: }
6740: }
6741: if (ref($rowtotal)) {
6742: $$rowtotal += $itemcount;
6743: }
6744: return $datatable;
6745: }
6746:
1.354 raeburn 6747: sub print_passwords {
6748: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
6749: my ($datatable,$css_class);
6750: my $itemcount = 0;
6751: my %titles = &Apache::lonlocal::texthash (
6752: captcha => '"Forgot Password" CAPTCHA validation',
6753: link => 'Reset link expiration (hours)',
6754: case => 'Case-sensitive usernames/e-mail',
6755: prelink => 'Information required (form 1)',
6756: postlink => 'Information required (form 2)',
6757: emailsrc => 'LON-CAPA e-mail address type(s)',
6758: customtext => 'Domain specific text (HTML)',
6759: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
6760: intauth_check => 'Check bcrypt cost if authenticated',
6761: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
6762: permanent => 'Permanent e-mail address',
6763: critical => 'Critical notification address',
6764: notify => 'Notification address',
6765: min => 'Minimum password length',
6766: max => 'Maximum password length',
6767: chars => 'Required characters',
6768: expire => 'Password expiration (days)',
1.356 raeburn 6769: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 6770: );
6771: if ($position eq 'top') {
6772: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6773: my $shownlinklife = 2;
6774: my $prelink = 'both';
6775: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
6776: if (ref($settings) eq 'HASH') {
6777: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
6778: $shownlinklife = $settings->{resetlink};
6779: }
6780: if (ref($settings->{resetcase}) eq 'ARRAY') {
6781: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
6782: }
6783: if ($settings->{resetprelink} =~ /^(both|either)$/) {
6784: $prelink = $settings->{resetprelink};
6785: }
6786: if (ref($settings->{resetpostlink}) eq 'HASH') {
6787: %postlink = %{$settings->{resetpostlink}};
6788: }
6789: if (ref($settings->{resetemail}) eq 'ARRAY') {
6790: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
6791: }
6792: if ($settings->{resetremove}) {
6793: $nostdtext = 1;
6794: }
6795: if ($settings->{resetcustom}) {
6796: $customurl = $settings->{resetcustom};
6797: }
6798: } else {
6799: if (ref($types) eq 'ARRAY') {
6800: foreach my $item (@{$types}) {
6801: $casesens{$item} = 1;
6802: $postlink{$item} = ['username','email'];
6803: }
6804: }
6805: $casesens{'default'} = 1;
6806: $postlink{'default'} = ['username','email'];
6807: $prelink = 'both';
6808: %emailsrc = (
6809: permanent => 1,
6810: critical => 1,
6811: notify => 1,
6812: );
6813: }
6814: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
6815: $itemcount ++;
6816: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6817: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
6818: '<td class="LC_left_item">'.
6819: '<input type="textbox" value="'.$shownlinklife.'" '.
6820: 'name="passwords_link" size="3" /></td></tr>';
6821: $itemcount ++;
6822: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6823: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
6824: '<td class="LC_left_item">';
6825: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6826: foreach my $item (@{$types}) {
6827: my $checkedcase;
6828: if ($casesens{$item}) {
6829: $checkedcase = ' checked="checked"';
6830: }
6831: $datatable .= '<span class="LC_nobreak"><label>'.
6832: '<input type="checkbox" name="passwords_case_sensitive" value="'.
6833: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 6834: '</span> ';
1.354 raeburn 6835: }
6836: }
6837: my $checkedcase;
6838: if ($casesens{'default'}) {
6839: $checkedcase = ' checked="checked"';
6840: }
6841: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
6842: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
6843: $othertitle.'</label></span></td>';
6844: $itemcount ++;
6845: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6846: my %checkedpre = (
6847: both => ' checked="checked"',
6848: either => '',
6849: );
6850: if ($prelink eq 'either') {
6851: $checkedpre{either} = ' checked="checked"';
6852: $checkedpre{both} = '';
6853: }
6854: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
6855: '<td class="LC_left_item"><span class="LC_nobreak">'.
6856: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
6857: &mt('Both username and e-mail address').'</label></span> '.
6858: '<span class="LC_nobreak"><label>'.
6859: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
6860: &mt('Either username or e-mail address').'</label></span></td></tr>';
6861: $itemcount ++;
6862: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6863: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
6864: '<td class="LC_left_item">';
6865: my %postlinked;
6866: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6867: foreach my $item (@{$types}) {
6868: undef(%postlinked);
6869: $datatable .= '<fieldset style="display: inline-block;">'.
6870: '<legend>'.$usertypes->{$item}.'</legend>';
6871: if (ref($postlink{$item}) eq 'ARRAY') {
6872: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
6873: }
6874: foreach my $field ('email','username') {
6875: my $checked;
6876: if ($postlinked{$field}) {
6877: $checked = ' checked="checked"';
6878: }
6879: $datatable .= '<span class="LC_nobreak"><label>'.
6880: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
6881: $field.'"'.$checked.' />'.$field.'</label>'.
6882: '<span> ';
6883: }
6884: $datatable .= '</fieldset>';
6885: }
6886: }
6887: if (ref($postlink{'default'}) eq 'ARRAY') {
6888: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
6889: }
6890: $datatable .= '<fieldset style="display: inline-block;">'.
6891: '<legend>'.$othertitle.'</legend>';
6892: foreach my $field ('email','username') {
6893: my $checked;
6894: if ($postlinked{$field}) {
6895: $checked = ' checked="checked"';
6896: }
6897: $datatable .= '<span class="LC_nobreak"><label>'.
6898: '<input type="checkbox" name="passwords_postlink_default" value="'.
6899: $field.'"'.$checked.' />'.$field.'</label>'.
6900: '<span> ';
6901: }
6902: $datatable .= '</fieldset></td></tr>';
6903: $itemcount ++;
6904: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6905: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
6906: '<td class="LC_left_item">';
6907: foreach my $type ('permanent','critical','notify') {
6908: my $checkedemail;
6909: if ($emailsrc{$type}) {
6910: $checkedemail = ' checked="checked"';
6911: }
6912: $datatable .= '<span class="LC_nobreak"><label>'.
6913: '<input type="checkbox" name="passwords_emailsrc" value="'.
6914: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
6915: '<span> ';
6916: }
6917: $datatable .= '</td></tr>';
6918: $itemcount ++;
6919: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6920: my $switchserver = &check_switchserver($dom,$confname);
6921: my ($showstd,$noshowstd);
6922: if ($nostdtext) {
6923: $noshowstd = ' checked="checked"';
6924: } else {
6925: $showstd = ' checked="checked"';
6926: }
6927: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
6928: '<td class="LC_left_item"><span class="LC_nobreak">'.
6929: &mt('Retain standard text:').
6930: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
6931: &mt('Yes').'</label>'.' '.
6932: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
6933: &mt('No').'</label></span><br />'.
6934: '<span class="LC_fontsize_small">'.
6935: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
6936: &mt('Include custom text:');
6937: if ($customurl) {
1.369 raeburn 6938: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 6939: undef,undef,undef,undef,'background-color:#ffffff');
6940: $datatable .= '<span class="LC_nobreak"> '.$link.
6941: '<label><input type="checkbox" name="passwords_custom_del"'.
6942: ' value="1" />'.&mt('Delete?').'</label></span>'.
6943: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
6944: }
6945: if ($switchserver) {
6946: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
6947: } else {
6948: $datatable .='<span class="LC_nobreak"> '.
6949: '<input type="file" name="passwords_customfile" /></span>';
6950: }
6951: $datatable .= '</td></tr>';
6952: } elsif ($position eq 'middle') {
6953: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
6954: my @items = ('intauth_cost','intauth_check','intauth_switch');
6955: my %defaults;
6956: if (ref($domconf{'defaults'}) eq 'HASH') {
6957: %defaults = %{$domconf{'defaults'}};
6958: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
6959: $defaults{'intauth_cost'} = 10;
6960: }
6961: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
6962: $defaults{'intauth_check'} = 0;
6963: }
6964: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
6965: $defaults{'intauth_switch'} = 0;
6966: }
6967: } else {
6968: %defaults = (
6969: 'intauth_cost' => 10,
6970: 'intauth_check' => 0,
6971: 'intauth_switch' => 0,
6972: );
6973: }
6974: foreach my $item (@items) {
6975: if ($itemcount%2) {
6976: $css_class = '';
6977: } else {
6978: $css_class = ' class="LC_odd_row" ';
6979: }
6980: $datatable .= '<tr'.$css_class.'>'.
6981: '<td><span class="LC_nobreak">'.$titles{$item}.
6982: '</span></td><td class="LC_left_item" colspan="3">';
6983: if ($item eq 'intauth_switch') {
6984: my @options = (0,1,2);
6985: my %optiondesc = &Apache::lonlocal::texthash (
6986: 0 => 'No',
6987: 1 => 'Yes',
6988: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
6989: );
6990: $datatable .= '<table width="100%">';
6991: foreach my $option (@options) {
6992: my $checked = ' ';
6993: if ($defaults{$item} eq $option) {
6994: $checked = ' checked="checked"';
6995: }
6996: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6997: '<label><input type="radio" name="'.$item.
6998: '" value="'.$option.'"'.$checked.' />'.
6999: $optiondesc{$option}.'</label></span></td></tr>';
7000: }
7001: $datatable .= '</table>';
7002: } elsif ($item eq 'intauth_check') {
7003: my @options = (0,1,2);
7004: my %optiondesc = &Apache::lonlocal::texthash (
7005: 0 => 'No',
7006: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
7007: 2 => 'Yes, disallow login if stored cost is less than domain default',
7008: );
7009: $datatable .= '<table width="100%">';
7010: foreach my $option (@options) {
7011: my $checked = ' ';
7012: my $onclick;
7013: if ($defaults{$item} eq $option) {
7014: $checked = ' checked="checked"';
7015: }
7016: if ($option == 2) {
7017: $onclick = ' onclick="javascript:warnIntAuth(this);"';
7018: }
7019: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7020: '<label><input type="radio" name="'.$item.
7021: '" value="'.$option.'"'.$checked.$onclick.' />'.
7022: $optiondesc{$option}.'</label></span></td></tr>';
7023: }
7024: $datatable .= '</table>';
7025: } else {
7026: $datatable .= '<input type="text" name="'.$item.'" value="'.
7027: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
7028: }
7029: $datatable .= '</td></tr>';
7030: $itemcount ++;
7031: }
7032: } elsif ($position eq 'lower') {
1.356 raeburn 7033: my ($min,$max,%chars,$expire,$numsaved);
1.365 raeburn 7034: $min = $Apache::lonnet::passwdmin;
1.354 raeburn 7035: if (ref($settings) eq 'HASH') {
7036: if ($settings->{min}) {
7037: $min = $settings->{min};
7038: }
7039: if ($settings->{max}) {
7040: $max = $settings->{max};
7041: }
7042: if (ref($settings->{chars}) eq 'ARRAY') {
7043: map { $chars{$_} = 1; } (@{$settings->{chars}});
7044: }
7045: if ($settings->{expire}) {
7046: $expire = $settings->{expire};
7047: }
1.358 raeburn 7048: if ($settings->{numsaved}) {
7049: $numsaved = $settings->{numsaved};
1.356 raeburn 7050: }
1.354 raeburn 7051: }
7052: my %rulenames = &Apache::lonlocal::texthash(
7053: uc => 'At least one upper case letter',
7054: lc => 'At least one lower case letter',
7055: num => 'At least one number',
7056: spec => 'At least one non-alphanumeric',
7057: );
7058: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7059: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
7060: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 7061: '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
7062: 'onblur="javascript:warnIntPass(this);" />'.
7063: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
1.354 raeburn 7064: '</span></td></tr>';
7065: $itemcount ++;
7066: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7067: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
7068: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 7069: '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
7070: 'onblur="javascript:warnIntPass(this);" />'.
1.354 raeburn 7071: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
7072: '</span></td></tr>';
7073: $itemcount ++;
7074: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7075: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
7076: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
7077: '</span></td>';
7078: my $numinrow = 2;
7079: my @possrules = ('uc','lc','num','spec');
7080: $datatable .= '<td class="LC_left_item"><table>';
7081: for (my $i=0; $i<@possrules; $i++) {
7082: my ($rem,$checked);
7083: if ($chars{$possrules[$i]}) {
7084: $checked = ' checked="checked"';
7085: }
7086: $rem = $i%($numinrow);
7087: if ($rem == 0) {
7088: if ($i > 0) {
7089: $datatable .= '</tr>';
7090: }
7091: $datatable .= '<tr>';
7092: }
7093: $datatable .= '<td><span class="LC_nobreak"><label>'.
7094: '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
7095: $rulenames{$possrules[$i]}.'</label></span></td>';
7096: }
7097: my $rem = @possrules%($numinrow);
7098: my $colsleft = $numinrow - $rem;
7099: if ($colsleft > 1 ) {
7100: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7101: ' </td>';
7102: } elsif ($colsleft == 1) {
7103: $datatable .= '<td class="LC_left_item"> </td>';
7104: }
7105: $datatable .='</table></td></tr>';
7106: $itemcount ++;
7107: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7108: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
7109: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 7110: '<input type="text" name="passwords_expire" value="'.$expire.'" size="4" '.
7111: 'onblur="javascript:warnIntPass(this);" />'.
1.354 raeburn 7112: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
7113: '</span></td></tr>';
1.356 raeburn 7114: $itemcount ++;
7115: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7116: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
7117: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.367 raeburn 7118: '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
7119: 'onblur="javascript:warnIntPass(this);" />'.
1.356 raeburn 7120: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
7121: '</span></td></tr>';
1.354 raeburn 7122: } else {
1.359 raeburn 7123: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7124: my %ownerchg = (
7125: by => {},
7126: for => {},
7127: );
7128: my %ownertitles = &Apache::lonlocal::texthash (
7129: by => 'Course owner status(es) allowed',
7130: for => 'Student status(es) allowed',
7131: );
1.354 raeburn 7132: if (ref($settings) eq 'HASH') {
1.359 raeburn 7133: if (ref($settings->{crsownerchg}) eq 'HASH') {
7134: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
7135: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
7136: }
7137: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
7138: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
7139: }
1.354 raeburn 7140: }
7141: }
7142: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7143: $datatable .= '<tr '.$css_class.'>'.
7144: '<td>'.
7145: &mt('Requirements').'<ul>'.
1.359 raeburn 7146: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 7147: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
7148: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 7149: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 7150: '</ul>'.
7151: '</td>'.
1.359 raeburn 7152: '<td class="LC_left_item">';
7153: foreach my $item ('by','for') {
7154: $datatable .= '<fieldset style="display: inline-block;">'.
7155: '<legend>'.$ownertitles{$item}.'</legend>';
7156: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7157: foreach my $type (@{$types}) {
7158: my $checked;
7159: if ($ownerchg{$item}{$type}) {
7160: $checked = ' checked="checked"';
7161: }
7162: $datatable .= '<span class="LC_nobreak"><label>'.
7163: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
7164: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 7165: '</span> ';
1.359 raeburn 7166: }
7167: }
7168: my $checked;
7169: if ($ownerchg{$item}{'default'}) {
7170: $checked = ' checked="checked"';
7171: }
7172: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7173: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
7174: $othertitle.'</label></span></fieldset>';
7175: }
7176: $datatable .= '</td></tr>';
1.354 raeburn 7177: }
7178: return $datatable;
7179: }
7180:
1.373 raeburn 7181: sub print_wafproxy {
7182: my ($position,$dom,$settings,$rowtotal) = @_;
7183: my $css_class;
7184: my $itemcount = 0;
7185: my $datatable;
7186: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7187: my (%othercontrol,%otherdoms,%aliases,%values,$setdom);
1.374 raeburn 7188: my %lt = &wafproxy_titles();
1.373 raeburn 7189: foreach my $server (sort(keys(%servers))) {
7190: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
7191: my $serverdom;
7192: if ($serverhome ne $server) {
7193: $serverdom = &Apache::lonnet::host_domain($serverhome);
7194: $othercontrol{$server} = $serverdom;
7195: } else {
7196: $serverdom = &Apache::lonnet::host_domain($server);
7197: if ($serverdom ne $dom) {
7198: $othercontrol{$server} = $serverdom;
7199: } else {
7200: $setdom = 1;
7201: if (ref($settings) eq 'HASH') {
7202: %{$values{$dom}} = ();
7203: if (ref($settings->{'alias'}) eq 'HASH') {
7204: $aliases{$dom} = $settings->{'alias'};
7205: }
1.376 ! raeburn 7206: foreach my $item ('ipheader','trusted','vpnint','vpnext') {
1.373 raeburn 7207: $values{$dom}{$item} = $settings->{$item};
7208: }
7209: }
7210: }
7211: }
7212: }
7213: if (keys(%othercontrol)) {
7214: %otherdoms = reverse(%othercontrol);
7215: foreach my $domain (keys(%otherdoms)) {
7216: %{$values{$domain}} = ();
7217: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
7218: if (ref($config{$domain}) eq 'HASH') {
7219: if (ref($config{$domain}{'wafproxy'}) eq 'HASH') {
7220: $aliases{$domain} = $config{$domain}{'wafproxy'}{'alias'};
1.376 ! raeburn 7221: foreach my $item ('ipheader','trusted','vpnint','vpnext') {
1.373 raeburn 7222: $values{$domain}{$item} = $config{$domain}{'wafproxy'}{$item};
7223: }
7224: }
7225: }
7226: }
7227: }
7228: if ($position eq 'top') {
7229: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7230: foreach my $server (sort(keys(%servers))) {
7231: $itemcount ++;
7232: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7233: $datatable .= '<tr'.$css_class.'>'.
7234: '<td>'.&mt('Hostname').': '.
7235: &Apache::lonnet::hostname($server).'</td>'.
1.374 raeburn 7236: '<td class="LC_right_item">';
1.373 raeburn 7237: if ($othercontrol{$server}) {
7238: my $current;
7239: if (ref($aliases{$othercontrol{$server}}) eq 'HASH') {
7240: $current = $aliases{$othercontrol{$server}{$server}};
7241: }
7242: if ($current) {
7243: $datatable .= $current;
7244: } else {
7245: $datatable .= &mt('None in effect');
7246: }
7247: $datatable .= '<br /><span class="LC_small">('.
7248: &mt('WAF/Reverse Proxy controlled by domain: [_1]',
7249: '<b>'.$othercontrol{$server}.'</b>').'</span>';
7250: } else {
7251: my $current;
7252: if (ref($aliases{$dom}) eq 'HASH') {
7253: if ($aliases{$dom}{$server}) {
7254: $current = $aliases{$dom}{$server};
7255: }
7256: }
7257: $datatable .= '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.374 raeburn 7258: 'value="'.$current.'" size="30" />';
1.373 raeburn 7259: }
7260: $datatable .= '</td></tr>';
7261: }
7262: } else {
7263: if ($setdom) {
7264: $itemcount ++;
7265: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7266: $datatable .= '<tr'.$css_class.'>'.
1.374 raeburn 7267: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.373 raeburn 7268: &mt('Format for comma separated IP blocks').':<br />'.
7269: &mt('A.B.C.D/N or A.B.C.D - E.F.G.H').'</td>'.
7270: '<td class="LC_left_item"><table>';
1.376 ! raeburn 7271: foreach my $item ('ipheader','trusted','vpnint','vpnext') {
1.373 raeburn 7272: $datatable .= '<tr>'.
1.374 raeburn 7273: '<td valign="top">'.$lt{$item}.': ';
7274: if ($item eq 'ipheader') {
7275: $datatable .= '<input type="text" value="'.$values{$dom}{$item}.'" '.
7276: 'name="wafproxy_'.$item.'" />';
7277:
7278: } else {
7279: $datatable .= '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
7280: $values{$dom}{$item}.'</textarea>';
7281: }
7282: $datatable .= '</td></tr>';
1.373 raeburn 7283: }
7284: $datatable .= '</table></td></tr>';
7285: }
7286: if (keys(%otherdoms)) {
7287: foreach my $domain (sort(keys(%otherdoms))) {
7288: $itemcount ++;
7289: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7290: $datatable .= '<tr'.$css_class.'>'.
1.374 raeburn 7291: '<td class="LC_left_item">'.&mt('Domain: [_1]',$domain).'</td>'.
7292: '<td class="LC_left_item"><table>';
1.376 ! raeburn 7293: foreach my $item ('ipheader','trusted','vpnint','vpnext') {
1.373 raeburn 7294: my $showval = &mt('None');
7295: if ($values{$domain}{$item}) {
7296: $showval = $values{$domain}{$item};
7297: }
7298: $datatable .= '<tr>'.
7299: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
7300: }
7301: $datatable .= '</table></td></tr>';
7302: }
7303: }
7304: }
7305: $$rowtotal += $itemcount;
7306: return $datatable;
7307: }
7308:
7309: sub wafproxy_titles {
7310: return &Apache::lonlocal::texthash(
1.376 ! raeburn 7311: vpnint => 'Internal IP Range(s) for VPN sessions',
! 7312: vpnext => 'IP Range for backend WAF connections',
1.373 raeburn 7313: trusted => 'Trusted IP range(s)',
7314: ipheader => 'Custom request header',
7315: );
7316: }
7317:
1.137 raeburn 7318: sub print_usersessions {
7319: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 7320: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 7321: my (%by_ip,%by_location,@intdoms,@instdoms);
7322: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 7323:
7324: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 7325: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 7326: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 7327: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 7328: if ($position eq 'top') {
1.152 raeburn 7329: if (keys(%serverhomes) > 1) {
1.145 raeburn 7330: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 7331: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 7332: if (ref($settings) eq 'HASH') {
7333: if (ref($settings->{'offloadnow'}) eq 'HASH') {
7334: $curroffloadnow = $settings->{'offloadnow'};
7335: }
1.371 raeburn 7336: if (ref($settings->{'offloadoth'}) eq 'HASH') {
7337: $curroffloadoth = $settings->{'offloadoth'};
7338: }
1.261 raeburn 7339: }
1.371 raeburn 7340: my $other_insts = scalar(keys(%by_location));
7341: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
7342: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 7343: } else {
1.140 raeburn 7344: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 7345: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
7346: '</td></tr>';
1.140 raeburn 7347: }
1.137 raeburn 7348: } else {
1.279 raeburn 7349: my %titles = &usersession_titles();
7350: my ($prefix,@types);
7351: if ($position eq 'bottom') {
7352: $prefix = 'remote';
7353: @types = ('version','excludedomain','includedomain');
1.145 raeburn 7354: } else {
1.279 raeburn 7355: $prefix = 'hosted';
7356: @types = ('excludedomain','includedomain');
7357: }
7358: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
7359: }
7360: $$rowtotal += $itemcount;
7361: return $datatable;
7362: }
7363:
7364: sub rules_by_location {
7365: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
7366: my ($datatable,$itemcount,$css_class);
7367: if (keys(%{$by_location}) == 0) {
7368: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7369: $datatable = '<tr'.$css_class.'><td colspan="2">'.
7370: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
7371: '</td></tr>';
7372: $itemcount = 1;
7373: } else {
7374: $itemcount = 0;
7375: my $numinrow = 5;
7376: my (%current,%checkedon,%checkedoff);
7377: my @locations = sort(keys(%{$by_location}));
7378: foreach my $type (@{$types}) {
7379: $checkedon{$type} = '';
7380: $checkedoff{$type} = ' checked="checked"';
7381: }
7382: if (ref($settings) eq 'HASH') {
7383: if (ref($settings->{$prefix}) eq 'HASH') {
7384: foreach my $key (keys(%{$settings->{$prefix}})) {
7385: $current{$key} = $settings->{$prefix}{$key};
7386: if ($key eq 'version') {
7387: if ($current{$key} ne '') {
1.145 raeburn 7388: $checkedon{$key} = ' checked="checked"';
7389: $checkedoff{$key} = '';
7390: }
1.279 raeburn 7391: } elsif (ref($current{$key}) eq 'ARRAY') {
7392: $checkedon{$key} = ' checked="checked"';
7393: $checkedoff{$key} = '';
1.137 raeburn 7394: }
7395: }
7396: }
1.279 raeburn 7397: }
7398: foreach my $type (@{$types}) {
7399: next if ($type ne 'version' && !@locations);
7400: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7401: $datatable .= '<tr'.$css_class.'>
7402: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
7403: <span class="LC_nobreak">
7404: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
7405: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
7406: if ($type eq 'version') {
7407: my @lcversions = &Apache::lonnet::all_loncaparevs();
7408: my $selector = '<select name="'.$prefix.'_version">';
7409: foreach my $version (@lcversions) {
7410: my $selected = '';
7411: if ($current{'version'} eq $version) {
7412: $selected = ' selected="selected"';
1.145 raeburn 7413: }
1.279 raeburn 7414: $selector .= ' <option value="'.$version.'"'.
7415: $selected.'>'.$version.'</option>';
7416: }
7417: $selector .= '</select> ';
7418: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
7419: } else {
7420: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
7421: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
7422: ' />'.(' 'x2).
7423: '<input type="button" value="'.&mt('uncheck all').'" '.
7424: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
7425: "\n".
7426: '</div><div><table>';
7427: my $rem;
7428: for (my $i=0; $i<@locations; $i++) {
7429: my ($showloc,$value,$checkedtype);
7430: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
7431: my $ip = $by_location->{$locations[$i]}->[0];
7432: if (ref($by_ip->{$ip}) eq 'ARRAY') {
7433: $value = join(':',@{$by_ip->{$ip}});
7434: $showloc = join(', ',@{$by_ip->{$ip}});
7435: if (ref($current{$type}) eq 'ARRAY') {
7436: foreach my $loc (@{$by_ip->{$ip}}) {
7437: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
7438: $checkedtype = ' checked="checked"';
7439: last;
1.145 raeburn 7440: }
1.138 raeburn 7441: }
7442: }
7443: }
1.137 raeburn 7444: }
1.279 raeburn 7445: $rem = $i%($numinrow);
7446: if ($rem == 0) {
7447: if ($i > 0) {
7448: $datatable .= '</tr>';
7449: }
7450: $datatable .= '<tr>';
7451: }
7452: $datatable .= '<td class="LC_left_item">'.
7453: '<span class="LC_nobreak"><label>'.
7454: '<input type="checkbox" name="'.$prefix.'_'.$type.
7455: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
7456: '</label></span></td>';
7457: }
7458: $rem = @locations%($numinrow);
7459: my $colsleft = $numinrow - $rem;
7460: if ($colsleft > 1 ) {
7461: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7462: ' </td>';
7463: } elsif ($colsleft == 1) {
7464: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 7465: }
1.279 raeburn 7466: $datatable .= '</tr></table>';
1.137 raeburn 7467: }
1.279 raeburn 7468: $datatable .= '</td></tr>';
7469: $itemcount ++;
1.137 raeburn 7470: }
7471: }
1.279 raeburn 7472: return ($datatable,$itemcount);
1.137 raeburn 7473: }
7474:
1.275 raeburn 7475: sub print_ssl {
7476: my ($position,$dom,$settings,$rowtotal) = @_;
7477: my ($css_class,$datatable);
7478: my $itemcount = 1;
7479: if ($position eq 'top') {
1.281 raeburn 7480: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7481: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7482: my $same_institution;
7483: if ($intdom ne '') {
7484: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
7485: if (ref($internet_names) eq 'ARRAY') {
7486: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
7487: $same_institution = 1;
7488: }
7489: }
7490: }
1.275 raeburn 7491: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 7492: $datatable = '<tr'.$css_class.'><td colspan="2">';
7493: if ($same_institution) {
7494: my %domservers = &Apache::lonnet::get_servers($dom);
7495: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
7496: } else {
7497: $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.");
7498: }
7499: $datatable .= '</td></tr>';
1.275 raeburn 7500: $itemcount ++;
7501: } else {
7502: my %titles = &ssl_titles();
7503: my (%by_ip,%by_location,@intdoms,@instdoms);
7504: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7505: my @alldoms = &Apache::lonnet::all_domains();
7506: my %serverhomes = %Apache::lonnet::serverhomeIDs;
7507: my @domservers = &Apache::lonnet::get_servers($dom);
7508: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7509: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 7510: if (($position eq 'connto') || ($position eq 'connfrom')) {
7511: my $legacy;
7512: unless (ref($settings) eq 'HASH') {
7513: my $name;
7514: if ($position eq 'connto') {
7515: $name = 'loncAllowInsecure';
7516: } else {
7517: $name = 'londAllowInsecure';
7518: }
7519: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
7520: my @ids=&Apache::lonnet::current_machine_ids();
7521: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
7522: my %what = (
7523: $name => 1,
7524: );
7525: my ($result,$returnhash) =
7526: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
7527: if ($result eq 'ok') {
7528: if (ref($returnhash) eq 'HASH') {
7529: $legacy = $returnhash->{$name};
7530: }
7531: }
7532: } else {
7533: $legacy = $Apache::lonnet::perlvar{$name};
7534: }
7535: }
1.275 raeburn 7536: foreach my $type ('dom','intdom','other') {
7537: my %checked;
7538: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7539: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
7540: '<td class="LC_right_item">';
7541: my $skip;
7542: if ($type eq 'dom') {
7543: unless (keys(%servers) > 1) {
7544: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
7545: $skip = 1;
7546: }
7547: }
7548: if ($type eq 'intdom') {
7549: unless (@instdoms > 1) {
7550: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
7551: $skip = 1;
7552: }
7553: } elsif ($type eq 'other') {
7554: if (keys(%by_location) == 0) {
7555: $datatable .= &mt('Nothing to set here, as there are no other institutions');
7556: $skip = 1;
7557: }
7558: }
7559: unless ($skip) {
7560: $checked{'yes'} = ' checked="checked"';
7561: if (ref($settings) eq 'HASH') {
1.293 raeburn 7562: if (ref($settings->{$position}) eq 'HASH') {
7563: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 7564: $checked{$1} = $checked{'yes'};
7565: delete($checked{'yes'});
7566: }
7567: }
1.293 raeburn 7568: } else {
7569: if ($legacy == 0) {
7570: $checked{'req'} = $checked{'yes'};
7571: delete($checked{'yes'});
7572: }
1.275 raeburn 7573: }
7574: foreach my $option ('no','yes','req') {
7575: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 7576: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 7577: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7578: '</label></span>'.(' 'x2);
7579: }
7580: }
7581: $datatable .= '</td></tr>';
7582: $itemcount ++;
7583: }
7584: } else {
7585: my $prefix = 'replication';
7586: my @types = ('certreq','nocertreq');
1.279 raeburn 7587: if (keys(%by_location) == 0) {
7588: $datatable .= '<tr'.$css_class.'><td>'.
7589: &mt('Nothing to set here, as there are no other institutions').
7590: '</td></tr>';
7591: $itemcount ++;
1.275 raeburn 7592: } else {
1.279 raeburn 7593: ($datatable,$itemcount) =
7594: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 7595: }
7596: }
7597: }
7598: $$rowtotal += $itemcount;
7599: return $datatable;
7600: }
7601:
7602: sub ssl_titles {
7603: return &Apache::lonlocal::texthash (
7604: dom => 'LON-CAPA servers/VMs from same domain',
7605: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
7606: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 7607: connto => 'Connections to other servers',
7608: connfrom => 'Connections from other servers',
1.275 raeburn 7609: replication => 'Replicating content to other institutions',
7610: certreq => 'Client certificate required, but specific domains exempt',
7611: nocertreq => 'No client certificate required, except for specific domains',
7612: no => 'SSL not used',
7613: yes => 'SSL Optional (used if available)',
7614: req => 'SSL Required',
7615: );
1.279 raeburn 7616: }
7617:
7618: sub print_trust {
7619: my ($prefix,$dom,$settings,$rowtotal) = @_;
7620: my ($css_class,$datatable,%checked,%choices);
7621: my (%by_ip,%by_location,@intdoms,@instdoms);
7622: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7623: my $itemcount = 1;
7624: my %titles = &trust_titles();
7625: my @types = ('exc','inc');
7626: if ($prefix eq 'top') {
7627: $prefix = 'content';
7628: } elsif ($prefix eq 'bottom') {
7629: $prefix = 'msg';
7630: }
7631: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
7632: $$rowtotal += $itemcount;
7633: return $datatable;
7634: }
7635:
7636: sub trust_titles {
7637: return &Apache::lonlocal::texthash(
7638: content => "Access to this domain's content by others",
7639: shared => "Access to other domain's content by this domain",
7640: enroll => "Enrollment in this domain's courses by others",
7641: othcoau => "Co-author roles in this domain for others",
7642: coaurem => "Co-author roles for this domain's users elsewhere",
7643: domroles => "Domain roles in this domain assignable to others",
7644: catalog => "Course Catalog for this domain displayed elsewhere",
7645: reqcrs => "Requests for creation of courses in this domain by others",
7646: msg => "Users in other domains can send messages to this domain",
7647: exc => "Allow all, but exclude specific domains",
7648: inc => "Deny all, but include specific domains",
7649: );
1.275 raeburn 7650: }
7651:
1.138 raeburn 7652: sub build_location_hashes {
1.275 raeburn 7653: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 7654: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 7655: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 7656: my %iphost = &Apache::lonnet::get_iphost();
7657: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
7658: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
7659: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
7660: foreach my $id (@{$iphost{$primary_ip}}) {
7661: my $intdom = &Apache::lonnet::internet_dom($id);
7662: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
7663: push(@{$intdoms},$intdom);
7664: }
7665: }
7666: }
7667: foreach my $ip (keys(%iphost)) {
7668: if (ref($iphost{$ip}) eq 'ARRAY') {
7669: foreach my $id (@{$iphost{$ip}}) {
7670: my $location = &Apache::lonnet::internet_dom($id);
7671: if ($location) {
1.275 raeburn 7672: if (grep(/^\Q$location\E$/,@{$intdoms})) {
7673: my $dom = &Apache::lonnet::host_domain($id);
7674: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
7675: push(@{$instdoms},$dom);
7676: }
7677: next;
7678: }
1.138 raeburn 7679: if (ref($by_ip->{$ip}) eq 'ARRAY') {
7680: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
7681: push(@{$by_ip->{$ip}},$location);
7682: }
7683: } else {
7684: $by_ip->{$ip} = [$location];
7685: }
7686: }
7687: }
7688: }
7689: }
7690: foreach my $ip (sort(keys(%{$by_ip}))) {
7691: if (ref($by_ip->{$ip}) eq 'ARRAY') {
7692: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
7693: my $first = $by_ip->{$ip}->[0];
7694: if (ref($by_location->{$first}) eq 'ARRAY') {
7695: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
7696: push(@{$by_location->{$first}},$ip);
7697: }
7698: } else {
7699: $by_location->{$first} = [$ip];
7700: }
7701: }
7702: }
7703: return;
7704: }
7705:
1.145 raeburn 7706: sub current_offloads_to {
7707: my ($dom,$settings,$servers) = @_;
7708: my (%spareid,%otherdomconfigs);
1.152 raeburn 7709: if (ref($servers) eq 'HASH') {
1.145 raeburn 7710: foreach my $lonhost (sort(keys(%{$servers}))) {
7711: my $gotspares;
1.152 raeburn 7712: if (ref($settings) eq 'HASH') {
7713: if (ref($settings->{'spares'}) eq 'HASH') {
7714: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
7715: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
7716: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
7717: $gotspares = 1;
7718: }
1.145 raeburn 7719: }
7720: }
7721: unless ($gotspares) {
7722: my $gotspares;
7723: my $serverhomeID =
7724: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
7725: my $serverhomedom =
7726: &Apache::lonnet::host_domain($serverhomeID);
7727: if ($serverhomedom ne $dom) {
7728: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
7729: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
7730: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
7731: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
7732: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
7733: $gotspares = 1;
7734: }
7735: }
7736: } else {
7737: $otherdomconfigs{$serverhomedom} =
7738: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
7739: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
7740: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
7741: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
7742: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
7743: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
7744: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
7745: $gotspares = 1;
7746: }
7747: }
7748: }
7749: }
7750: }
7751: }
7752: }
7753: unless ($gotspares) {
7754: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
7755: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
7756: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
7757: } else {
7758: my $server_hostname = &Apache::lonnet::hostname($lonhost);
7759: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
7760: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
7761: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
7762: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
7763: } else {
1.150 raeburn 7764: my %what = (
7765: spareid => 1,
7766: );
7767: my ($result,$returnhash) =
7768: &Apache::lonnet::get_remote_globals($lonhost,\%what);
7769: if ($result eq 'ok') {
7770: if (ref($returnhash) eq 'HASH') {
7771: if (ref($returnhash->{'spareid'}) eq 'HASH') {
7772: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
7773: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
7774: }
7775: }
1.145 raeburn 7776: }
7777: }
7778: }
7779: }
7780: }
7781: }
7782: return %spareid;
7783: }
7784:
7785: sub spares_row {
1.371 raeburn 7786: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
7787: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 7788: my $css_class;
7789: my $numinrow = 4;
7790: my $itemcount = 1;
7791: my $datatable;
1.152 raeburn 7792: my %typetitles = &sparestype_titles();
7793: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 7794: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 7795: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
7796: my ($othercontrol,$serverdom);
7797: if ($serverhome ne $server) {
7798: $serverdom = &Apache::lonnet::host_domain($serverhome);
7799: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
7800: } else {
7801: $serverdom = &Apache::lonnet::host_domain($server);
7802: if ($serverdom ne $dom) {
7803: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
7804: }
7805: }
7806: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 7807: my ($checkednow,$checkedoth);
1.261 raeburn 7808: if (ref($curroffloadnow) eq 'HASH') {
7809: if ($curroffloadnow->{$server}) {
7810: $checkednow = ' checked="checked"';
7811: }
7812: }
1.371 raeburn 7813: if (ref($curroffloadoth) eq 'HASH') {
7814: if ($curroffloadoth->{$server}) {
7815: $checkedoth = ' checked="checked"';
7816: }
7817: }
1.145 raeburn 7818: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7819: $datatable .= '<tr'.$css_class.'>
7820: <td rowspan="2">
1.183 bisitz 7821: <span class="LC_nobreak">'.
7822: &mt('[_1] when busy, offloads to:'
1.261 raeburn 7823: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 7824: '<span class="LC_nobreak">'."\n".
1.261 raeburn 7825: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 7826: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 7827: "\n";
1.371 raeburn 7828: if ($other_insts) {
7829: $datatable .= '<br />'.
7830: '<span class="LC_nobreak">'."\n".
7831: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
7832: ' '.&mt('Switch other institutions on next access').'</label></span>'.
7833: "\n";
7834: }
1.145 raeburn 7835: my (%current,%canselect);
1.152 raeburn 7836: my @choices =
7837: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
7838: foreach my $type ('primary','default') {
7839: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 7840: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
7841: my @spares = @{$spareid->{$server}{$type}};
7842: if (@spares > 0) {
1.152 raeburn 7843: if ($othercontrol) {
7844: $current{$type} = join(', ',@spares);
7845: } else {
7846: $current{$type} .= '<table>';
7847: my $numspares = scalar(@spares);
7848: for (my $i=0; $i<@spares; $i++) {
7849: my $rem = $i%($numinrow);
7850: if ($rem == 0) {
7851: if ($i > 0) {
7852: $current{$type} .= '</tr>';
7853: }
7854: $current{$type} .= '<tr>';
1.145 raeburn 7855: }
1.152 raeburn 7856: $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'".');" /> '.
7857: $spareid->{$server}{$type}[$i].
7858: '</label></td>'."\n";
7859: }
7860: my $rem = @spares%($numinrow);
7861: my $colsleft = $numinrow - $rem;
7862: if ($colsleft > 1 ) {
7863: $current{$type} .= '<td colspan="'.$colsleft.
7864: '" class="LC_left_item">'.
7865: ' </td>';
7866: } elsif ($colsleft == 1) {
7867: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 7868: }
1.152 raeburn 7869: $current{$type} .= '</tr></table>';
1.150 raeburn 7870: }
1.145 raeburn 7871: }
7872: }
7873: if ($current{$type} eq '') {
7874: $current{$type} = &mt('None specified');
7875: }
1.152 raeburn 7876: if ($othercontrol) {
7877: if ($type eq 'primary') {
7878: $canselect{$type} = $othercontrol;
7879: }
7880: } else {
7881: $canselect{$type} =
7882: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
7883: '<select name="newspare_'.$type.'_'.$server.'" '.
7884: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
7885: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
7886: if (@choices > 0) {
7887: foreach my $lonhost (@choices) {
7888: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
7889: }
7890: }
7891: $canselect{$type} .= '</select>'."\n";
7892: }
7893: } else {
7894: $current{$type} = &mt('Could not be determined');
7895: if ($type eq 'primary') {
7896: $canselect{$type} = $othercontrol;
7897: }
1.145 raeburn 7898: }
1.152 raeburn 7899: if ($type eq 'default') {
7900: $datatable .= '<tr'.$css_class.'>';
7901: }
7902: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
7903: '<td>'.$current{$type}.'</td>'."\n".
7904: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 7905: }
7906: $itemcount ++;
7907: }
7908: }
7909: $$rowtotal += $itemcount;
7910: return $datatable;
7911: }
7912:
1.152 raeburn 7913: sub possible_newspares {
7914: my ($server,$currspares,$serverhomes,$altids) = @_;
7915: my $serverhostname = &Apache::lonnet::hostname($server);
7916: my %excluded;
7917: if ($serverhostname ne '') {
7918: %excluded = (
7919: $serverhostname => 1,
7920: );
7921: }
7922: if (ref($currspares) eq 'HASH') {
7923: foreach my $type (keys(%{$currspares})) {
7924: if (ref($currspares->{$type}) eq 'ARRAY') {
7925: if (@{$currspares->{$type}} > 0) {
7926: foreach my $curr (@{$currspares->{$type}}) {
7927: my $hostname = &Apache::lonnet::hostname($curr);
7928: $excluded{$hostname} = 1;
7929: }
7930: }
7931: }
7932: }
7933: }
7934: my @choices;
7935: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
7936: if (keys(%{$serverhomes}) > 1) {
7937: foreach my $name (sort(keys(%{$serverhomes}))) {
7938: unless ($excluded{$name}) {
7939: if (exists($altids->{$serverhomes->{$name}})) {
7940: push(@choices,$altids->{$serverhomes->{$name}});
7941: } else {
7942: push(@choices,$serverhomes->{$name});
1.145 raeburn 7943: }
7944: }
7945: }
7946: }
7947: }
1.152 raeburn 7948: return sort(@choices);
1.145 raeburn 7949: }
7950:
1.150 raeburn 7951: sub print_loadbalancing {
7952: my ($dom,$settings,$rowtotal) = @_;
7953: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7954: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7955: my $numinrow = 1;
7956: my $datatable;
7957: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 7958: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 7959: if (ref($settings) eq 'HASH') {
7960: %existing = %{$settings};
7961: }
7962: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
7963: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 7964: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 7965: } else {
7966: return;
7967: }
7968: my ($othertitle,$usertypes,$types) =
7969: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 7970: my $rownum = 8;
1.150 raeburn 7971: if (ref($types) eq 'ARRAY') {
7972: $rownum += scalar(@{$types});
7973: }
1.171 raeburn 7974: my @css_class = ('LC_odd_row','LC_even_row');
7975: my $balnum = 0;
7976: my $islast;
7977: my (@toshow,$disabledtext);
7978: if (keys(%currbalancer) > 0) {
7979: @toshow = sort(keys(%currbalancer));
7980: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
7981: push(@toshow,'');
7982: }
7983: } else {
7984: @toshow = ('');
7985: $disabledtext = &mt('No existing load balancer');
7986: }
7987: foreach my $lonhost (@toshow) {
7988: if ($balnum == scalar(@toshow)-1) {
7989: $islast = 1;
7990: } else {
7991: $islast = 0;
7992: }
7993: my $cssidx = $balnum%2;
7994: my $targets_div_style = 'display: none';
7995: my $disabled_div_style = 'display: block';
7996: my $homedom_div_style = 'display: none';
7997: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 7998: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 7999: '<p>';
8000: if ($lonhost eq '') {
1.210 raeburn 8001: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 8002: if (keys(%currbalancer) > 0) {
8003: $datatable .= &mt('Add balancer:');
8004: } else {
8005: $datatable .= &mt('Enable balancer:');
8006: }
8007: $datatable .= ' '.
8008: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
8009: ' id="loadbalancing_lonhost_'.$balnum.'"'.
8010: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
8011: '<option value="" selected="selected">'.&mt('None').
8012: '</option>'."\n";
8013: foreach my $server (sort(keys(%servers))) {
8014: next if ($currbalancer{$server});
8015: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
8016: }
1.210 raeburn 8017: $datatable .=
1.171 raeburn 8018: '</select>'."\n".
8019: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
8020: } else {
8021: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
8022: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
8023: &mt('Stop balancing').'</label>'.
8024: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
8025: $targets_div_style = 'display: block';
8026: $disabled_div_style = 'display: none';
8027: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
8028: $homedom_div_style = 'display: block';
8029: }
8030: }
1.306 raeburn 8031: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 8032: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
8033: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
8034: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
8035: my ($numspares,@spares) = &count_servers($lonhost,%servers);
8036: my @sparestypes = ('primary','default');
8037: my %typetitles = &sparestype_titles();
1.284 raeburn 8038: my %hostherechecked = (
8039: no => ' checked="checked"',
8040: );
1.342 raeburn 8041: my %balcookiechecked = (
8042: no => ' checked="checked"',
8043: );
1.171 raeburn 8044: foreach my $sparetype (@sparestypes) {
8045: my $targettable;
8046: for (my $i=0; $i<$numspares; $i++) {
8047: my $checked;
8048: if (ref($currtargets{$lonhost}) eq 'HASH') {
8049: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
8050: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
8051: $checked = ' checked="checked"';
8052: }
8053: }
8054: }
8055: my ($chkboxval,$disabled);
8056: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
8057: $chkboxval = $spares[$i];
8058: }
8059: if (exists($currbalancer{$spares[$i]})) {
8060: $disabled = ' disabled="disabled"';
8061: }
1.210 raeburn 8062: $targettable .=
1.253 raeburn 8063: '<td><span class="LC_nobreak"><label>'.
8064: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 8065: $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 8066: '</span></label></span></td>';
1.171 raeburn 8067: my $rem = $i%($numinrow);
8068: if ($rem == 0) {
8069: if (($i > 0) && ($i < $numspares-1)) {
8070: $targettable .= '</tr>';
8071: }
8072: if ($i < $numspares-1) {
8073: $targettable .= '<tr>';
1.150 raeburn 8074: }
8075: }
8076: }
1.171 raeburn 8077: if ($targettable ne '') {
8078: my $rem = $numspares%($numinrow);
8079: my $colsleft = $numinrow - $rem;
8080: if ($colsleft > 1 ) {
8081: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8082: ' </td>';
8083: } elsif ($colsleft == 1) {
8084: $targettable .= '<td class="LC_left_item"> </td>';
8085: }
8086: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
8087: '<table><tr>'.$targettable.'</tr></table><br />';
8088: }
1.284 raeburn 8089: $hostherechecked{$sparetype} = '';
8090: if (ref($currtargets{$lonhost}) eq 'HASH') {
8091: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
8092: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
8093: $hostherechecked{$sparetype} = ' checked="checked"';
8094: $hostherechecked{'no'} = '';
8095: }
8096: }
8097: }
8098: }
1.342 raeburn 8099: if ($currcookies{$lonhost}) {
8100: %balcookiechecked = (
8101: yes => ' checked="checked"',
8102: );
8103: }
1.284 raeburn 8104: $datatable .= &mt('Hosting on balancer itself').'<br />'.
8105: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
8106: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
8107: foreach my $sparetype (@sparestypes) {
8108: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
8109: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
8110: '</i></label><br />';
1.171 raeburn 8111: }
1.342 raeburn 8112: $datatable .= &mt('Use balancer cookie').'<br />'.
8113: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
8114: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
8115: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
8116: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
8117: '</div></td></tr>'.
1.171 raeburn 8118: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
8119: $othertitle,$usertypes,$types,\%servers,
8120: \%currbalancer,$lonhost,
8121: $targets_div_style,$homedom_div_style,
8122: $css_class[$cssidx],$balnum,$islast);
8123: $$rowtotal += $rownum;
8124: $balnum ++;
8125: }
8126: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
8127: return $datatable;
8128: }
8129:
8130: sub get_loadbalancers_config {
1.342 raeburn 8131: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 8132: return unless ((ref($servers) eq 'HASH') &&
8133: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 8134: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
8135: (ref($currcookies) eq 'HASH'));
1.171 raeburn 8136: if (keys(%{$existing}) > 0) {
8137: my $oldlonhost;
8138: foreach my $key (sort(keys(%{$existing}))) {
8139: if ($key eq 'lonhost') {
8140: $oldlonhost = $existing->{'lonhost'};
8141: $currbalancer->{$oldlonhost} = 1;
8142: } elsif ($key eq 'targets') {
8143: if ($oldlonhost) {
8144: $currtargets->{$oldlonhost} = $existing->{'targets'};
8145: }
8146: } elsif ($key eq 'rules') {
8147: if ($oldlonhost) {
8148: $currrules->{$oldlonhost} = $existing->{'rules'};
8149: }
8150: } elsif (ref($existing->{$key}) eq 'HASH') {
8151: $currbalancer->{$key} = 1;
8152: $currtargets->{$key} = $existing->{$key}{'targets'};
8153: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 8154: if ($existing->{$key}{'cookie'}) {
8155: $currcookies->{$key} = 1;
8156: }
1.150 raeburn 8157: }
8158: }
1.171 raeburn 8159: } else {
8160: my ($balancerref,$targetsref) =
8161: &Apache::lonnet::get_lonbalancer_config($servers);
8162: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
8163: foreach my $server (sort(keys(%{$balancerref}))) {
8164: $currbalancer->{$server} = 1;
8165: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 8166: }
8167: }
8168: }
1.171 raeburn 8169: return;
1.150 raeburn 8170: }
8171:
8172: sub loadbalancing_rules {
8173: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 8174: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
8175: $css_class,$balnum,$islast) = @_;
1.150 raeburn 8176: my $output;
1.171 raeburn 8177: my $num = 0;
1.210 raeburn 8178: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 8179: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8180: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8181: foreach my $type (@{$alltypes}) {
1.171 raeburn 8182: $num ++;
1.150 raeburn 8183: my $current;
8184: if (ref($currrules) eq 'HASH') {
8185: $current = $currrules->{$type};
8186: }
1.253 raeburn 8187: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 8188: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 8189: $current = '';
8190: }
8191: }
8192: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 8193: $servers,$currbalancer,$lonhost,$dom,
8194: $targets_div_style,$homedom_div_style,
8195: $css_class,$balnum,$num,$islast);
1.150 raeburn 8196: }
8197: }
8198: return $output;
8199: }
8200:
8201: sub loadbalancing_titles {
8202: my ($dom,$intdom,$usertypes,$types) = @_;
8203: my %othertypes = (
8204: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
8205: '_LC_author' => &mt('Users from [_1] with author role',$dom),
8206: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
8207: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 8208: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
8209: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 8210: );
1.209 raeburn 8211: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 8212: my @available;
1.150 raeburn 8213: if (ref($types) eq 'ARRAY') {
1.302 raeburn 8214: @available = @{$types};
1.150 raeburn 8215: }
1.302 raeburn 8216: unless (grep(/^default$/,@available)) {
8217: push(@available,'default');
8218: }
8219: unshift(@alltypes,@available);
1.150 raeburn 8220: my %titles;
8221: foreach my $type (@alltypes) {
8222: if ($type =~ /^_LC_/) {
8223: $titles{$type} = $othertypes{$type};
8224: } elsif ($type eq 'default') {
8225: $titles{$type} = &mt('All users from [_1]',$dom);
8226: if (ref($types) eq 'ARRAY') {
8227: if (@{$types} > 0) {
8228: $titles{$type} = &mt('Other users from [_1]',$dom);
8229: }
8230: }
8231: } elsif (ref($usertypes) eq 'HASH') {
8232: $titles{$type} = $usertypes->{$type};
8233: }
8234: }
8235: return (\@alltypes,\%othertypes,\%titles);
8236: }
8237:
8238: sub loadbalance_rule_row {
1.171 raeburn 8239: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
8240: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 8241: my @rulenames;
1.150 raeburn 8242: my %ruletitles = &offloadtype_text();
1.209 raeburn 8243: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 8244: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 8245: } else {
1.209 raeburn 8246: @rulenames = ('default','homeserver');
8247: if ($type eq '_LC_external') {
8248: push(@rulenames,'externalbalancer');
8249: } else {
8250: push(@rulenames,'specific');
8251: }
8252: push(@rulenames,'none');
1.150 raeburn 8253: }
8254: my $style = $targets_div_style;
1.253 raeburn 8255: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 8256: $style = $homedom_div_style;
8257: }
1.171 raeburn 8258: my $space;
8259: if ($islast && $num == 1) {
1.317 raeburn 8260: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 8261: }
1.210 raeburn 8262: my $output =
1.306 raeburn 8263: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 8264: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
8265: '<td valaign="top">'.$space.
8266: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 8267: for (my $i=0; $i<@rulenames; $i++) {
8268: my $rule = $rulenames[$i];
8269: my ($checked,$extra);
8270: if ($rulenames[$i] eq 'default') {
8271: $rule = '';
8272: }
8273: if ($rulenames[$i] eq 'specific') {
8274: if (ref($servers) eq 'HASH') {
8275: my $default;
8276: if (($current ne '') && (exists($servers->{$current}))) {
8277: $checked = ' checked="checked"';
8278: }
8279: unless ($checked) {
8280: $default = ' selected="selected"';
8281: }
1.210 raeburn 8282: $extra =
1.171 raeburn 8283: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
8284: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
8285: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
8286: '<option value=""'.$default.'></option>'."\n";
8287: foreach my $server (sort(keys(%{$servers}))) {
8288: if (ref($currbalancer) eq 'HASH') {
8289: next if (exists($currbalancer->{$server}));
8290: }
1.150 raeburn 8291: my $selected;
1.171 raeburn 8292: if ($server eq $current) {
1.150 raeburn 8293: $selected = ' selected="selected"';
8294: }
1.171 raeburn 8295: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 8296: }
8297: $extra .= '</select>';
8298: }
8299: } elsif ($rule eq $current) {
8300: $checked = ' checked="checked"';
8301: }
8302: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 8303: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
8304: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
8305: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 8306: ')"'.$checked.' /> ';
8307: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
8308: $output .= $ruletitles{'particular'};
8309: } else {
8310: $output .= $ruletitles{$rulenames[$i]};
8311: }
8312: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 8313: }
8314: $output .= '</div></td></tr>'."\n";
8315: return $output;
8316: }
8317:
8318: sub offloadtype_text {
8319: my %ruletitles = &Apache::lonlocal::texthash (
8320: 'default' => 'Offloads to default destinations',
8321: 'homeserver' => "Offloads to user's home server",
8322: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
8323: 'specific' => 'Offloads to specific server',
1.161 raeburn 8324: 'none' => 'No offload',
1.209 raeburn 8325: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
8326: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 8327: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 8328: );
8329: return %ruletitles;
8330: }
8331:
8332: sub sparestype_titles {
8333: my %typestitles = &Apache::lonlocal::texthash (
8334: 'primary' => 'primary',
8335: 'default' => 'default',
8336: );
8337: return %typestitles;
8338: }
8339:
1.28 raeburn 8340: sub contact_titles {
8341: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 8342: 'supportemail' => 'Support E-mail address',
8343: 'adminemail' => 'Default Server Admin E-mail address',
8344: 'errormail' => 'Error reports to be e-mailed to',
8345: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 8346: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
8347: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 8348: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
8349: 'requestsmail' => 'E-mail from course requests requiring approval',
8350: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 8351: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 8352: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.340 raeburn 8353: 'errorthreshold' => 'Error/warning threshold for status e-mail',
8354: 'errorsysmail' => 'Error threshold for e-mail to core group',
8355: 'errorweights' => 'Weights used to compute error count',
8356: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 8357: );
8358: my %short_titles = &Apache::lonlocal::texthash (
8359: adminemail => 'Admin E-mail address',
8360: supportemail => 'Support E-mail',
8361: );
8362: return (\%titles,\%short_titles);
8363: }
8364:
1.286 raeburn 8365: sub helpform_fields {
8366: my %titles = &Apache::lonlocal::texthash (
8367: 'username' => 'Name',
8368: 'user' => 'Username/domain',
8369: 'phone' => 'Phone',
8370: 'cc' => 'Cc e-mail',
8371: 'course' => 'Course Details',
8372: 'section' => 'Sections',
1.289 raeburn 8373: 'screenshot' => 'File upload',
1.286 raeburn 8374: );
8375: my @fields = ('username','phone','user','course','section','cc','screenshot');
8376: my %possoptions = (
8377: username => ['yes','no','req'],
1.289 raeburn 8378: phone => ['yes','no','req'],
1.286 raeburn 8379: user => ['yes','no'],
1.289 raeburn 8380: cc => ['yes','no'],
1.286 raeburn 8381: course => ['yes','no'],
8382: section => ['yes','no'],
8383: screenshot => ['yes','no'],
8384: );
8385: my %fieldoptions = &Apache::lonlocal::texthash (
8386: 'yes' => 'Optional',
8387: 'req' => 'Required',
8388: 'no' => "Not shown",
8389: );
8390: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
8391: }
8392:
1.72 raeburn 8393: sub tool_titles {
8394: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 8395: aboutme => 'Personal web page',
1.86 raeburn 8396: blog => 'Blog',
1.162 raeburn 8397: webdav => 'WebDAV',
1.86 raeburn 8398: portfolio => 'Portfolio',
1.88 bisitz 8399: official => 'Official courses (with institutional codes)',
8400: unofficial => 'Unofficial courses',
1.98 raeburn 8401: community => 'Communities',
1.216 raeburn 8402: textbook => 'Textbook courses',
1.271 raeburn 8403: placement => 'Placement tests',
1.86 raeburn 8404: );
1.72 raeburn 8405: return %titles;
8406: }
8407:
1.101 raeburn 8408: sub courserequest_titles {
8409: my %titles = &Apache::lonlocal::texthash (
8410: official => 'Official',
8411: unofficial => 'Unofficial',
8412: community => 'Communities',
1.216 raeburn 8413: textbook => 'Textbook',
1.271 raeburn 8414: placement => 'Placement tests',
1.325 raeburn 8415: lti => 'LTI Provider',
1.101 raeburn 8416: norequest => 'Not allowed',
1.325 raeburn 8417: approval => 'Approval by DC',
1.101 raeburn 8418: validate => 'With validation',
8419: autolimit => 'Numerical limit',
1.103 raeburn 8420: unlimited => '(blank for unlimited)',
1.101 raeburn 8421: );
8422: return %titles;
8423: }
8424:
1.163 raeburn 8425: sub authorrequest_titles {
8426: my %titles = &Apache::lonlocal::texthash (
8427: norequest => 'Not allowed',
8428: approval => 'Approval by Dom. Coord.',
8429: automatic => 'Automatic approval',
8430: );
8431: return %titles;
1.210 raeburn 8432: }
1.163 raeburn 8433:
1.101 raeburn 8434: sub courserequest_conditions {
8435: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 8436: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 8437: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 8438: );
8439: return %conditions;
8440: }
8441:
8442:
1.27 raeburn 8443: sub print_usercreation {
1.30 raeburn 8444: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 8445: my $numinrow = 4;
1.28 raeburn 8446: my $datatable;
8447: if ($position eq 'top') {
1.30 raeburn 8448: $$rowtotal ++;
1.34 raeburn 8449: my $rowcount = 0;
1.32 raeburn 8450: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 8451: if (ref($rules) eq 'HASH') {
8452: if (keys(%{$rules}) > 0) {
1.32 raeburn 8453: $datatable .= &user_formats_row('username',$settings,$rules,
8454: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 8455: $$rowtotal ++;
1.32 raeburn 8456: $rowcount ++;
8457: }
8458: }
8459: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
8460: if (ref($idrules) eq 'HASH') {
8461: if (keys(%{$idrules}) > 0) {
8462: $datatable .= &user_formats_row('id',$settings,$idrules,
8463: $idruleorder,$numinrow,$rowcount);
8464: $$rowtotal ++;
8465: $rowcount ++;
1.28 raeburn 8466: }
8467: }
1.39 raeburn 8468: if ($rowcount == 0) {
8469: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
8470: $$rowtotal ++;
8471: $rowcount ++;
8472: }
1.34 raeburn 8473: } elsif ($position eq 'middle') {
1.224 raeburn 8474: my @creators = ('author','course','requestcrs');
1.37 raeburn 8475: my ($rules,$ruleorder) =
8476: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 8477: my %lt = &usercreation_types();
8478: my %checked;
8479: if (ref($settings) eq 'HASH') {
8480: if (ref($settings->{'cancreate'}) eq 'HASH') {
8481: foreach my $item (@creators) {
8482: $checked{$item} = $settings->{'cancreate'}{$item};
8483: }
8484: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
8485: foreach my $item (@creators) {
8486: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
8487: $checked{$item} = 'none';
8488: }
8489: }
8490: }
8491: }
8492: my $rownum = 0;
8493: foreach my $item (@creators) {
8494: $rownum ++;
1.224 raeburn 8495: if ($checked{$item} eq '') {
8496: $checked{$item} = 'any';
1.34 raeburn 8497: }
8498: my $css_class;
8499: if ($rownum%2) {
8500: $css_class = '';
8501: } else {
8502: $css_class = ' class="LC_odd_row" ';
8503: }
8504: $datatable .= '<tr'.$css_class.'>'.
8505: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 8506: '</span></td><td style="text-align: right">';
1.224 raeburn 8507: my @options = ('any');
8508: if (ref($rules) eq 'HASH') {
8509: if (keys(%{$rules}) > 0) {
8510: push(@options,('official','unofficial'));
1.37 raeburn 8511: }
8512: }
1.224 raeburn 8513: push(@options,'none');
1.37 raeburn 8514: foreach my $option (@options) {
1.50 raeburn 8515: my $type = 'radio';
1.34 raeburn 8516: my $check = ' ';
1.224 raeburn 8517: if ($checked{$item} eq $option) {
8518: $check = ' checked="checked" ';
1.34 raeburn 8519: }
8520: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 8521: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 8522: $item.'" value="'.$option.'"'.$check.'/> '.
8523: $lt{$option}.'</label> </span>';
8524: }
8525: $datatable .= '</td></tr>';
8526: }
1.28 raeburn 8527: } else {
8528: my @contexts = ('author','course','domain');
1.325 raeburn 8529: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 8530: my %checked;
8531: if (ref($settings) eq 'HASH') {
8532: if (ref($settings->{'authtypes'}) eq 'HASH') {
8533: foreach my $item (@contexts) {
8534: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
8535: foreach my $auth (@authtypes) {
8536: if ($settings->{'authtypes'}{$item}{$auth}) {
8537: $checked{$item}{$auth} = ' checked="checked" ';
8538: }
8539: }
8540: }
8541: }
1.27 raeburn 8542: }
1.35 raeburn 8543: } else {
8544: foreach my $item (@contexts) {
1.36 raeburn 8545: foreach my $auth (@authtypes) {
1.35 raeburn 8546: $checked{$item}{$auth} = ' checked="checked" ';
8547: }
8548: }
1.27 raeburn 8549: }
1.28 raeburn 8550: my %title = &context_names();
8551: my %authname = &authtype_names();
8552: my $rownum = 0;
8553: my $css_class;
8554: foreach my $item (@contexts) {
8555: if ($rownum%2) {
8556: $css_class = '';
8557: } else {
8558: $css_class = ' class="LC_odd_row" ';
8559: }
1.30 raeburn 8560: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 8561: '<td>'.$title{$item}.
8562: '</td><td class="LC_left_item">'.
8563: '<span class="LC_nobreak">';
8564: foreach my $auth (@authtypes) {
8565: $datatable .= '<label>'.
8566: '<input type="checkbox" name="'.$item.'_auth" '.
8567: $checked{$item}{$auth}.' value="'.$auth.'" />'.
8568: $authname{$auth}.'</label> ';
8569: }
8570: $datatable .= '</span></td></tr>';
8571: $rownum ++;
1.27 raeburn 8572: }
1.30 raeburn 8573: $$rowtotal += $rownum;
1.27 raeburn 8574: }
8575: return $datatable;
8576: }
8577:
1.224 raeburn 8578: sub print_selfcreation {
8579: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 8580: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
8581: $emaildomain,$datatable);
1.224 raeburn 8582: if (ref($settings) eq 'HASH') {
8583: if (ref($settings->{'cancreate'}) eq 'HASH') {
8584: $createsettings = $settings->{'cancreate'};
1.236 raeburn 8585: if (ref($createsettings) eq 'HASH') {
8586: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
8587: @selfcreate = @{$createsettings->{'selfcreate'}};
8588: } elsif ($createsettings->{'selfcreate'} ne '') {
8589: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
8590: @selfcreate = ('email','login','sso');
8591: } elsif ($createsettings->{'selfcreate'} ne 'none') {
8592: @selfcreate = ($createsettings->{'selfcreate'});
8593: }
8594: }
8595: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
8596: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 8597: }
1.305 raeburn 8598: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
8599: $emailoptions = $createsettings->{'emailoptions'};
8600: }
1.303 raeburn 8601: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
8602: $emailverified = $createsettings->{'emailverified'};
8603: }
8604: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
8605: $emaildomain = $createsettings->{'emaildomain'};
8606: }
1.224 raeburn 8607: }
8608: }
8609: }
8610: my %radiohash;
8611: my $numinrow = 4;
8612: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 8613: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 8614: if ($position eq 'top') {
8615: my %choices = &Apache::lonlocal::texthash (
8616: cancreate_login => 'Institutional Login',
8617: cancreate_sso => 'Institutional Single Sign On',
8618: );
8619: my @toggles = sort(keys(%choices));
8620: my %defaultchecked = (
8621: 'cancreate_login' => 'off',
8622: 'cancreate_sso' => 'off',
8623: );
1.228 raeburn 8624: my ($onclick,$itemcount);
1.224 raeburn 8625: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
8626: \%choices,$itemcount,$onclick);
1.228 raeburn 8627: $$rowtotal += $itemcount;
8628:
1.224 raeburn 8629: if (ref($usertypes) eq 'HASH') {
8630: if (keys(%{$usertypes}) > 0) {
8631: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
8632: $dom,$numinrow,$othertitle,
1.305 raeburn 8633: 'statustocreate',$rowtotal);
1.224 raeburn 8634: $$rowtotal ++;
8635: }
8636: }
1.240 raeburn 8637: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
8638: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8639: $fieldtitles{'inststatus'} = &mt('Institutional status');
8640: my $rem;
8641: my $numperrow = 2;
8642: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
8643: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 8644: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 8645: '<td class="LC_left_item">'."\n".
1.334 raeburn 8646: '<table>'."\n";
1.240 raeburn 8647: for (my $i=0; $i<@fields; $i++) {
8648: $rem = $i%($numperrow);
8649: if ($rem == 0) {
8650: if ($i > 0) {
8651: $datatable .= '</tr>';
8652: }
8653: $datatable .= '<tr>';
8654: }
8655: my $currval;
1.248 raeburn 8656: if (ref($createsettings) eq 'HASH') {
8657: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
8658: $currval = $createsettings->{'shibenv'}{$fields[$i]};
8659: }
1.240 raeburn 8660: }
8661: $datatable .= '<td class="LC_left_item">'.
8662: '<span class="LC_nobreak">'.
8663: '<input type="text" name="shibenv_'.$fields[$i].'" '.
8664: 'value="'.$currval.'" size="10" /> '.
8665: $fieldtitles{$fields[$i]}.'</span></td>';
8666: }
8667: my $colsleft = $numperrow - $rem;
8668: if ($colsleft > 1 ) {
8669: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8670: ' </td>';
8671: } elsif ($colsleft == 1) {
8672: $datatable .= '<td class="LC_left_item"> </td>';
8673: }
8674: $datatable .= '</tr></table></td></tr>';
8675: $$rowtotal ++;
1.224 raeburn 8676: } elsif ($position eq 'middle') {
8677: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 8678: my @posstypes;
1.224 raeburn 8679: if (ref($types) eq 'ARRAY') {
1.302 raeburn 8680: @posstypes = @{$types};
8681: }
8682: unless (grep(/^default$/,@posstypes)) {
8683: push(@posstypes,'default');
8684: }
8685: my %usertypeshash;
8686: if (ref($usertypes) eq 'HASH') {
8687: %usertypeshash = %{$usertypes};
8688: }
8689: $usertypeshash{'default'} = $othertitle;
8690: foreach my $status (@posstypes) {
8691: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
8692: $numinrow,$$rowtotal,\%usertypeshash);
8693: $$rowtotal ++;
1.224 raeburn 8694: }
8695: } else {
1.236 raeburn 8696: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 8697: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 8698: );
8699: my @toggles = sort(keys(%choices));
8700: my %defaultchecked = (
8701: 'cancreate_email' => 'off',
8702: );
1.305 raeburn 8703: my $customclass = 'LC_selfcreate_email';
8704: my $classprefix = 'LC_canmodify_emailusername_';
8705: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 8706: my $display = 'none';
1.305 raeburn 8707: my $rowstyle = 'display:none';
1.236 raeburn 8708: if (grep(/^\Qemail\E$/,@selfcreate)) {
8709: $display = 'block';
1.305 raeburn 8710: $rowstyle = 'display:table-row';
1.236 raeburn 8711: }
1.305 raeburn 8712: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
8713: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
8714: \%choices,$$rowtotal,$onclick);
8715: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
8716: $rowstyle);
8717: $$rowtotal ++;
8718: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
8719: $rowstyle);
8720: $$rowtotal ++;
8721: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 8722: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 8723: my ($emailrules,$emailruleorder) =
8724: &Apache::lonnet::inst_userrules($dom,'email');
8725: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8726: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8727: if (ref($types) eq 'ARRAY') {
8728: @posstypes = @{$types};
8729: }
8730: if (@posstypes) {
8731: unless (grep(/^default$/,@posstypes)) {
8732: push(@posstypes,'default');
1.302 raeburn 8733: }
8734: if (ref($usertypes) eq 'HASH') {
8735: %usertypeshash = %{$usertypes};
8736: }
1.305 raeburn 8737: my $currassign;
8738: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
8739: $currassign = {
8740: selfassign => $domdefaults{'inststatusguest'},
8741: };
8742: @ordered = @{$domdefaults{'inststatusguest'}};
8743: } else {
8744: $currassign = { selfassign => [] };
8745: }
8746: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
8747: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
8748: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
8749: $numinrow,$othertitle,'selfassign',
8750: $rowtotal,$onclicktypes,$customclass,
8751: $rowstyle);
8752: $$rowtotal ++;
1.302 raeburn 8753: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 8754: foreach my $status (@posstypes) {
8755: my $css_class;
8756: if ($$rowtotal%2) {
8757: $css_class = 'LC_odd_row ';
8758: }
8759: $css_class .= $customclass;
8760: my $rowid = $optionsprefix.$status;
8761: my $hidden = 1;
8762: my $currstyle = 'display:none';
8763: if (grep(/^\Q$status\E$/,@ordered)) {
8764: $currstyle = $rowstyle;
8765: $hidden = 0;
8766: }
8767: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
8768: $emailrules,$emailruleorder,$settings,$status,$rowid,
8769: $usertypeshash{$status},$css_class,$currstyle,$intdom);
8770: unless ($hidden) {
8771: $$rowtotal ++;
8772: }
1.224 raeburn 8773: }
1.302 raeburn 8774: } else {
1.305 raeburn 8775: my $css_class;
8776: if ($$rowtotal%2) {
8777: $css_class = 'LC_odd_row ';
8778: }
8779: $css_class .= $customclass;
1.302 raeburn 8780: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 8781: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
8782: $emailrules,$emailruleorder,$settings,'default','',
8783: $othertitle,$css_class,$rowstyle,$intdom);
8784: $$rowtotal ++;
1.224 raeburn 8785: }
8786: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 8787: $numinrow = 1;
1.305 raeburn 8788: if (@posstypes) {
8789: foreach my $status (@posstypes) {
8790: my $rowid = $classprefix.$status;
8791: my $datarowstyle = 'display:none';
8792: if (grep(/^\Q$status\E$/,@ordered)) {
8793: $datarowstyle = $rowstyle;
8794: }
8795: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
8796: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
8797: $infotitles,$rowid,$customclass,$datarowstyle);
8798: unless ($datarowstyle eq 'display:none') {
8799: $$rowtotal ++;
8800: }
1.224 raeburn 8801: }
1.305 raeburn 8802: } else {
8803: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
8804: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
8805: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 8806: }
8807: }
8808: return $datatable;
8809: }
8810:
1.305 raeburn 8811: sub selfcreate_javascript {
8812: return <<"ENDSCRIPT";
8813:
8814: <script type="text/javascript">
8815: // <![CDATA[
8816:
8817: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
8818: var x = document.getElementsByClassName(target);
8819: var insttypes = 0;
8820: var insttypeRegExp = new RegExp(prefix);
8821: if ((x.length != undefined) && (x.length > 0)) {
8822: if (form.elements[radio].length != undefined) {
8823: for (var i=0; i<form.elements[radio].length; i++) {
8824: if (form.elements[radio][i].checked) {
8825: if (form.elements[radio][i].value == 1) {
8826: for (var j=0; j<x.length; j++) {
8827: if (x[j].id == 'undefined') {
8828: x[j].style.display = 'table-row';
8829: } else if (insttypeRegExp.test(x[j].id)) {
8830: insttypes ++;
8831: } else {
8832: x[j].style.display = 'table-row';
8833: }
8834: }
8835: } else {
8836: for (var j=0; j<x.length; j++) {
8837: x[j].style.display = 'none';
8838: }
1.236 raeburn 8839: }
1.305 raeburn 8840: break;
8841: }
8842: }
8843: if (insttypes > 0) {
8844: toggleDataRow(form,checkbox,target,altprefix);
8845: toggleDataRow(form,checkbox,target,prefix,1);
8846: }
8847: }
8848: }
8849: return;
8850: }
8851:
8852: function toggleDataRow(form,checkbox,target,prefix,docount) {
8853: if (form.elements[checkbox].length != undefined) {
8854: var count = 0;
8855: if (docount) {
8856: for (var i=0; i<form.elements[checkbox].length; i++) {
8857: if (form.elements[checkbox][i].checked) {
8858: count ++;
1.236 raeburn 8859: }
1.305 raeburn 8860: }
8861: }
8862: for (var i=0; i<form.elements[checkbox].length; i++) {
8863: var type = form.elements[checkbox][i].value;
8864: if (document.getElementById(prefix+type)) {
8865: if (form.elements[checkbox][i].checked) {
8866: document.getElementById(prefix+type).style.display = 'table-row';
8867: if (count % 2 == 1) {
8868: document.getElementById(prefix+type).className = target+' LC_odd_row';
8869: } else {
8870: document.getElementById(prefix+type).className = target;
1.236 raeburn 8871: }
1.305 raeburn 8872: count ++;
1.236 raeburn 8873: } else {
1.305 raeburn 8874: document.getElementById(prefix+type).style.display = 'none';
8875: }
8876: }
8877: }
8878: }
8879: return;
8880: }
8881:
8882: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
8883: var caller = radio+'_'+status;
8884: if (form.elements[caller].length != undefined) {
8885: for (var i=0; i<form.elements[caller].length; i++) {
8886: if (form.elements[caller][i].checked) {
8887: if (document.getElementById(altprefix+'_inst_'+status)) {
8888: var curr = form.elements[caller][i].value;
8889: if (prefix) {
8890: document.getElementById(prefix+'_'+status).style.display = 'none';
8891: }
8892: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
8893: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
8894: if (curr == 'custom') {
8895: if (prefix) {
8896: document.getElementById(prefix+'_'+status).style.display = 'inline';
8897: }
8898: } else if (curr == 'inst') {
8899: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
8900: } else if (curr == 'noninst') {
8901: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 8902: }
1.305 raeburn 8903: break;
1.236 raeburn 8904: }
8905: }
8906: }
8907: }
8908: }
8909:
1.305 raeburn 8910: // ]]>
8911: </script>
8912:
8913: ENDSCRIPT
8914: }
8915:
8916: sub noninst_users {
8917: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
8918: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
8919: my $class = 'LC_left_item';
8920: if ($css_class) {
8921: $css_class = ' class="'.$css_class.'"';
8922: }
8923: if ($rowid) {
8924: $rowid = ' id="'.$rowid.'"';
8925: }
8926: if ($rowstyle) {
8927: $rowstyle = ' style="'.$rowstyle.'"';
8928: }
8929: my ($output,$description);
8930: if ($type eq 'default') {
8931: $description = &mt('Requests for: [_1]',$typetitle);
8932: } else {
8933: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
8934: }
8935: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
8936: "<td>$description</td>\n".
8937: '<td class="'.$class.'" colspan="2">'.
8938: '<table><tr>';
8939: my %headers = &Apache::lonlocal::texthash(
8940: approve => 'Processing',
8941: email => 'E-mail',
8942: username => 'Username',
8943: );
8944: foreach my $item ('approve','email','username') {
8945: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 8946: }
1.305 raeburn 8947: $output .= '</tr><tr>';
8948: foreach my $item ('approve','email','username') {
1.306 raeburn 8949: $output .= '<td style="vertical-align: top">';
1.305 raeburn 8950: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
8951: if ($item eq 'approve') {
8952: %choices = &Apache::lonlocal::texthash (
8953: automatic => 'Automatically approved',
8954: approval => 'Queued for approval',
8955: );
8956: @options = ('automatic','approval');
8957: $hashref = $processing;
8958: $defoption = 'automatic';
8959: $name = 'cancreate_emailprocess_'.$type;
8960: } elsif ($item eq 'email') {
8961: %choices = &Apache::lonlocal::texthash (
8962: any => 'Any e-mail',
8963: inst => 'Institutional only',
8964: noninst => 'Non-institutional only',
8965: custom => 'Custom restrictions',
8966: );
8967: @options = ('any','inst','noninst');
8968: my $showcustom;
8969: if (ref($emailrules) eq 'HASH') {
8970: if (keys(%{$emailrules}) > 0) {
8971: push(@options,'custom');
8972: $showcustom = 'cancreate_emailrule';
8973: if (ref($settings) eq 'HASH') {
8974: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
8975: foreach my $rule (@{$settings->{'email_rule'}}) {
8976: if (exists($emailrules->{$rule})) {
8977: $hascustom ++;
8978: }
8979: }
8980: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
8981: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
8982: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
8983: if (exists($emailrules->{$rule})) {
8984: $hascustom ++;
8985: }
8986: }
8987: }
8988: }
8989: }
8990: }
8991: }
8992: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
8993: "'cancreate_emaildomain','$type'".');"';
8994: $hashref = $emailoptions;
8995: $defoption = 'any';
8996: $name = 'cancreate_emailoptions_'.$type;
8997: } elsif ($item eq 'username') {
8998: %choices = &Apache::lonlocal::texthash (
8999: all => 'Same as e-mail',
9000: first => 'Omit @domain',
9001: free => 'Free to choose',
9002: );
9003: @options = ('all','first','free');
9004: $hashref = $emailverified;
9005: $defoption = 'all';
9006: $name = 'cancreate_usernameoptions_'.$type;
9007: }
9008: foreach my $option (@options) {
9009: my $checked;
9010: if (ref($hashref) eq 'HASH') {
9011: if ($type eq '') {
9012: if (!exists($hashref->{'default'})) {
9013: if ($option eq $defoption) {
9014: $checked = ' checked="checked"';
9015: }
9016: } else {
9017: if ($hashref->{'default'} eq $option) {
9018: $checked = ' checked="checked"';
9019: }
1.303 raeburn 9020: }
9021: } else {
1.305 raeburn 9022: if (!exists($hashref->{$type})) {
9023: if ($option eq $defoption) {
9024: $checked = ' checked="checked"';
9025: }
9026: } else {
9027: if ($hashref->{$type} eq $option) {
9028: $checked = ' checked="checked"';
9029: }
1.303 raeburn 9030: }
9031: }
1.305 raeburn 9032: } elsif (($item eq 'email') && ($hascustom)) {
9033: if ($option eq 'custom') {
9034: $checked = ' checked="checked"';
9035: }
9036: } elsif ($option eq $defoption) {
9037: $checked = ' checked="checked"';
9038: }
9039: $output .= '<span class="LC_nobreak"><label>'.
9040: '<input type="radio" name="'.$name.'"'.
9041: $checked.' value="'.$option.'"'.$onclick.' />'.
9042: $choices{$option}.'</label></span><br />';
9043: if ($item eq 'email') {
9044: if ($option eq 'custom') {
9045: my $id = 'cancreate_emailrule_'.$type;
9046: my $display = 'none';
9047: if ($checked) {
9048: $display = 'inline';
1.303 raeburn 9049: }
1.305 raeburn 9050: my $numinrow = 2;
9051: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
9052: '<legend>'.&mt('Disallow').'</legend><table>'.
9053: &user_formats_row('email',$settings,$emailrules,
9054: $emailruleorder,$numinrow,'',$type);
9055: '</table></fieldset>';
9056: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
9057: my %text = &Apache::lonlocal::texthash (
9058: inst => 'must end:',
9059: noninst => 'cannot end:',
9060: );
9061: my $value;
9062: if (ref($emaildomain) eq 'HASH') {
9063: if (ref($emaildomain->{$type}) eq 'HASH') {
9064: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 9065: }
9066: }
1.305 raeburn 9067: if ($value eq '') {
9068: $value = '@'.$intdom;
9069: }
9070: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
9071: my $display = 'none';
9072: if ($checked) {
9073: $display = 'inline';
9074: }
9075: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
9076: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
9077: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
9078: '</div>';
1.303 raeburn 9079: }
9080: }
9081: }
1.305 raeburn 9082: $output .= '</td>'."\n";
1.303 raeburn 9083: }
1.305 raeburn 9084: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 9085: return $output;
9086: }
9087:
1.165 raeburn 9088: sub captcha_choice {
1.305 raeburn 9089: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 9090: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
9091: $vertext,$currver);
1.165 raeburn 9092: my %lt = &captcha_phrases();
9093: $keyentry = 'hidden';
1.354 raeburn 9094: my $colspan=2;
1.165 raeburn 9095: if ($context eq 'cancreate') {
1.224 raeburn 9096: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 9097: } elsif ($context eq 'login') {
9098: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 9099: } elsif ($context eq 'passwords') {
9100: $rowname = &mt('"Forgot Password" CAPTCHA validation');
9101: $colspan=1;
1.165 raeburn 9102: }
9103: if (ref($settings) eq 'HASH') {
9104: if ($settings->{'captcha'}) {
9105: $checked{$settings->{'captcha'}} = ' checked="checked"';
9106: } else {
9107: $checked{'original'} = ' checked="checked"';
9108: }
9109: if ($settings->{'captcha'} eq 'recaptcha') {
9110: $pubtext = $lt{'pub'};
9111: $privtext = $lt{'priv'};
9112: $keyentry = 'text';
1.269 raeburn 9113: $vertext = $lt{'ver'};
9114: $currver = $settings->{'recaptchaversion'};
9115: if ($currver ne '2') {
9116: $currver = 1;
9117: }
1.165 raeburn 9118: }
9119: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
9120: $currpub = $settings->{'recaptchakeys'}{'public'};
9121: $currpriv = $settings->{'recaptchakeys'}{'private'};
9122: }
9123: } else {
9124: $checked{'original'} = ' checked="checked"';
9125: }
1.305 raeburn 9126: my $css_class;
9127: if ($itemcount%2) {
9128: $css_class = 'LC_odd_row';
9129: }
9130: if ($customcss) {
9131: $css_class .= " $customcss";
9132: }
9133: $css_class =~ s/^\s+//;
9134: if ($css_class) {
9135: $css_class = ' class="'.$css_class.'"';
9136: }
9137: if ($rowstyle) {
9138: $css_class .= ' style="'.$rowstyle.'"';
9139: }
1.169 raeburn 9140: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 9141: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 9142: '<table><tr><td>'."\n";
9143: foreach my $option ('original','recaptcha','notused') {
9144: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
9145: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
9146: $lt{$option}.'</label></span>';
9147: unless ($option eq 'notused') {
9148: $output .= (' 'x2)."\n";
9149: }
9150: }
9151: #
9152: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
9153: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 9154: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 9155: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 9156: #
1.165 raeburn 9157: $output .= '</td></tr>'."\n".
1.305 raeburn 9158: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 9159: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
9160: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
9161: $currpub.'" size="40" /></span><br />'."\n".
9162: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
9163: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 9164: $currpriv.'" size="40" /></span><br />'.
9165: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
9166: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
9167: $currver.'" size="3" /></span><br />'.
9168: '</td></tr></table>'."\n".
1.165 raeburn 9169: '</td></tr>';
9170: return $output;
9171: }
9172:
1.32 raeburn 9173: sub user_formats_row {
1.305 raeburn 9174: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 9175: my $output;
9176: my %text = (
9177: 'username' => 'new usernames',
9178: 'id' => 'IDs',
9179: );
1.305 raeburn 9180: unless ($type eq 'email') {
9181: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
9182: $output = '<tr '.$css_class.'>'.
9183: '<td><span class="LC_nobreak">'.
9184: &mt("Format rules to check for $text{$type}: ").
9185: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 9186: }
1.27 raeburn 9187: my $rem;
9188: if (ref($ruleorder) eq 'ARRAY') {
9189: for (my $i=0; $i<@{$ruleorder}; $i++) {
9190: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
9191: my $rem = $i%($numinrow);
9192: if ($rem == 0) {
9193: if ($i > 0) {
9194: $output .= '</tr>';
9195: }
9196: $output .= '<tr>';
9197: }
9198: my $check = ' ';
1.39 raeburn 9199: if (ref($settings) eq 'HASH') {
9200: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
9201: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
9202: $check = ' checked="checked" ';
9203: }
1.305 raeburn 9204: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
9205: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
9206: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
9207: $check = ' checked="checked" ';
9208: }
9209: }
1.27 raeburn 9210: }
9211: }
1.305 raeburn 9212: my $name = $type.'_rule';
9213: if ($type eq 'email') {
9214: $name .= '_'.$status;
9215: }
1.27 raeburn 9216: $output .= '<td class="LC_left_item">'.
9217: '<span class="LC_nobreak"><label>'.
1.311 raeburn 9218: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 9219: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
9220: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
9221: }
9222: }
9223: $rem = @{$ruleorder}%($numinrow);
9224: }
1.305 raeburn 9225: my $colsleft;
9226: if ($rem) {
9227: $colsleft = $numinrow - $rem;
9228: }
1.27 raeburn 9229: if ($colsleft > 1 ) {
9230: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9231: ' </td>';
9232: } elsif ($colsleft == 1) {
9233: $output .= '<td class="LC_left_item"> </td>';
9234: }
1.305 raeburn 9235: $output .= '</tr></table>';
9236: unless ($type eq 'email') {
9237: $output .= '</td></tr>';
9238: }
1.27 raeburn 9239: return $output;
9240: }
9241:
1.34 raeburn 9242: sub usercreation_types {
9243: my %lt = &Apache::lonlocal::texthash (
9244: author => 'When adding a co-author',
9245: course => 'When adding a user to a course',
1.100 raeburn 9246: requestcrs => 'When requesting a course',
1.34 raeburn 9247: any => 'Any',
9248: official => 'Institutional only ',
9249: unofficial => 'Non-institutional only',
9250: none => 'None',
9251: );
9252: return %lt;
1.48 raeburn 9253: }
1.34 raeburn 9254:
1.224 raeburn 9255: sub selfcreation_types {
9256: my %lt = &Apache::lonlocal::texthash (
9257: selfcreate => 'User creates own account',
9258: any => 'Any',
9259: official => 'Institutional only ',
9260: unofficial => 'Non-institutional only',
9261: email => 'E-mail address',
9262: login => 'Institutional Login',
9263: sso => 'SSO',
9264: );
9265: }
9266:
1.28 raeburn 9267: sub authtype_names {
9268: my %lt = &Apache::lonlocal::texthash(
9269: int => 'Internal',
9270: krb4 => 'Kerberos 4',
9271: krb5 => 'Kerberos 5',
9272: loc => 'Local',
1.325 raeburn 9273: lti => 'LTI',
1.28 raeburn 9274: );
9275: return %lt;
9276: }
9277:
9278: sub context_names {
9279: my %context_title = &Apache::lonlocal::texthash(
9280: author => 'Creating users when an Author',
9281: course => 'Creating users when in a course',
9282: domain => 'Creating users when a Domain Coordinator',
9283: );
9284: return %context_title;
9285: }
9286:
1.33 raeburn 9287: sub print_usermodification {
9288: my ($position,$dom,$settings,$rowtotal) = @_;
9289: my $numinrow = 4;
9290: my ($context,$datatable,$rowcount);
9291: if ($position eq 'top') {
9292: $rowcount = 0;
9293: $context = 'author';
9294: foreach my $role ('ca','aa') {
9295: $datatable .= &modifiable_userdata_row($context,$role,$settings,
9296: $numinrow,$rowcount);
9297: $$rowtotal ++;
9298: $rowcount ++;
9299: }
1.230 raeburn 9300: } elsif ($position eq 'bottom') {
1.33 raeburn 9301: $context = 'course';
9302: $rowcount = 0;
9303: foreach my $role ('st','ep','ta','in','cr') {
9304: $datatable .= &modifiable_userdata_row($context,$role,$settings,
9305: $numinrow,$rowcount);
9306: $$rowtotal ++;
9307: $rowcount ++;
9308: }
9309: }
9310: return $datatable;
9311: }
9312:
1.43 raeburn 9313: sub print_defaults {
1.236 raeburn 9314: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 9315: my $rownum = 0;
1.294 raeburn 9316: my ($datatable,$css_class,$titles);
9317: unless ($position eq 'bottom') {
9318: $titles = &defaults_titles($dom);
9319: }
1.236 raeburn 9320: if ($position eq 'top') {
9321: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
9322: 'datelocale_def','portal_def');
9323: my %defaults;
9324: if (ref($settings) eq 'HASH') {
9325: %defaults = %{$settings};
1.43 raeburn 9326: } else {
1.236 raeburn 9327: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9328: foreach my $item (@items) {
9329: $defaults{$item} = $domdefaults{$item};
9330: }
1.43 raeburn 9331: }
1.236 raeburn 9332: foreach my $item (@items) {
9333: if ($rownum%2) {
9334: $css_class = '';
9335: } else {
9336: $css_class = ' class="LC_odd_row" ';
9337: }
9338: $datatable .= '<tr'.$css_class.'>'.
9339: '<td><span class="LC_nobreak">'.$titles->{$item}.
9340: '</span></td><td class="LC_right_item" colspan="3">';
9341: if ($item eq 'auth_def') {
1.325 raeburn 9342: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 9343: my %shortauth = (
9344: internal => 'int',
9345: krb4 => 'krb4',
9346: krb5 => 'krb5',
1.325 raeburn 9347: localauth => 'loc',
9348: lti => 'lti',
1.236 raeburn 9349: );
9350: my %authnames = &authtype_names();
9351: foreach my $auth (@authtypes) {
9352: my $checked = ' ';
9353: if ($defaults{$item} eq $auth) {
9354: $checked = ' checked="checked" ';
9355: }
9356: $datatable .= '<label><input type="radio" name="'.$item.
9357: '" value="'.$auth.'"'.$checked.'/>'.
9358: $authnames{$shortauth{$auth}}.'</label> ';
9359: }
9360: } elsif ($item eq 'timezone_def') {
9361: my $includeempty = 1;
9362: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
9363: } elsif ($item eq 'datelocale_def') {
9364: my $includeempty = 1;
9365: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
9366: } elsif ($item eq 'lang_def') {
1.263 raeburn 9367: my $includeempty = 1;
9368: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 9369: } else {
9370: my $size;
9371: if ($item eq 'portal_def') {
9372: $size = ' size="25"';
9373: }
9374: $datatable .= '<input type="text" name="'.$item.'" value="'.
9375: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 9376: }
1.236 raeburn 9377: $datatable .= '</td></tr>';
9378: $rownum ++;
9379: }
1.354 raeburn 9380: } else {
1.294 raeburn 9381: my %defaults;
9382: if (ref($settings) eq 'HASH') {
1.354 raeburn 9383: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
9384: my $maxnum = @{$settings->{'inststatusorder'}};
9385: for (my $i=0; $i<$maxnum; $i++) {
9386: $css_class = $rownum%2?' class="LC_odd_row"':'';
9387: my $item = $settings->{'inststatusorder'}->[$i];
9388: my $title = $settings->{'inststatustypes'}->{$item};
9389: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
9390: $datatable .= '<tr'.$css_class.'>'.
9391: '<td><span class="LC_nobreak">'.
9392: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
9393: for (my $k=0; $k<=$maxnum; $k++) {
9394: my $vpos = $k+1;
9395: my $selstr;
9396: if ($k == $i) {
9397: $selstr = ' selected="selected" ';
9398: }
9399: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9400: }
9401: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
9402: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
9403: &mt('delete').'</span></td>'.
9404: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed:').
9405: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
9406: '</span></td></tr>';
9407: }
9408: $css_class = $rownum%2?' class="LC_odd_row"':'';
9409: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
9410: $datatable .= '<tr '.$css_class.'>'.
9411: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
9412: for (my $k=0; $k<=$maxnum; $k++) {
9413: my $vpos = $k+1;
9414: my $selstr;
9415: if ($k == $maxnum) {
9416: $selstr = ' selected="selected" ';
9417: }
9418: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9419: }
9420: $datatable .= '</select> '.&mt('Internal ID:').
9421: '<input type="text" size="10" name="addinststatus" value="" />'.
9422: ' '.&mt('(new)').
9423: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
9424: &mt('Name displayed:').
9425: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
9426: '</tr>'."\n";
9427: $rownum ++;
1.294 raeburn 9428: }
1.354 raeburn 9429: }
9430: }
9431: $$rowtotal += $rownum;
1.43 raeburn 9432: return $datatable;
9433: }
9434:
1.168 raeburn 9435: sub get_languages_hash {
9436: my %langchoices;
9437: foreach my $id (&Apache::loncommon::languageids()) {
9438: my $code = &Apache::loncommon::supportedlanguagecode($id);
9439: if ($code ne '') {
9440: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
9441: }
9442: }
9443: return %langchoices;
9444: }
9445:
1.43 raeburn 9446: sub defaults_titles {
1.141 raeburn 9447: my ($dom) = @_;
1.43 raeburn 9448: my %titles = &Apache::lonlocal::texthash (
9449: 'auth_def' => 'Default authentication type',
9450: 'auth_arg_def' => 'Default authentication argument',
9451: 'lang_def' => 'Default language',
1.54 raeburn 9452: 'timezone_def' => 'Default timezone',
1.68 raeburn 9453: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 9454: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 9455: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
9456: 'intauth_check' => 'Check bcrypt cost if authenticated',
9457: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 9458: );
1.141 raeburn 9459: if ($dom) {
9460: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
9461: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
9462: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
9463: $protocol = 'http' if ($protocol ne 'https');
9464: if ($uint_dom) {
9465: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
9466: $uint_dom);
9467: }
9468: }
1.43 raeburn 9469: return (\%titles);
9470: }
9471:
1.346 raeburn 9472: sub print_scantron {
9473: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
9474: if ($position eq 'top') {
9475: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
9476: } else {
9477: return &print_scantronconfig($dom,$settings,\$rowtotal);
9478: }
9479: }
9480:
9481: sub scantron_javascript {
9482: return <<"ENDSCRIPT";
9483:
9484: <script type="text/javascript">
9485: // <![CDATA[
9486:
9487: function toggleScantron(form) {
1.347 raeburn 9488: var csvfieldset = new Array();
1.346 raeburn 9489: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 9490: csvfieldset.push(document.getElementById('scantroncsv_cols'));
9491: }
9492: if (document.getElementById('scantroncsv_options')) {
9493: csvfieldset.push(document.getElementById('scantroncsv_options'));
9494: }
9495: if (csvfieldset.length) {
1.346 raeburn 9496: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 9497: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 9498: if (scantroncsv.checked) {
1.347 raeburn 9499: for (var i=0; i<csvfieldset.length; i++) {
9500: csvfieldset[i].style.display = 'block';
9501: }
1.346 raeburn 9502: } else {
1.347 raeburn 9503: for (var i=0; i<csvfieldset.length; i++) {
9504: csvfieldset[i].style.display = 'none';
9505: }
1.346 raeburn 9506: var csvselects = document.getElementsByClassName('scantronconfig_csv');
9507: if (csvselects.length) {
9508: for (var j=0; j<csvselects.length; j++) {
9509: csvselects[j].selectedIndex = 0;
9510: }
9511: }
9512: }
9513: }
9514: }
9515: return;
9516: }
9517: // ]]>
9518: </script>
9519:
9520: ENDSCRIPT
9521:
9522: }
9523:
1.46 raeburn 9524: sub print_scantronformat {
9525: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
9526: my $itemcount = 1;
1.60 raeburn 9527: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
9528: %confhash);
1.46 raeburn 9529: my $switchserver = &check_switchserver($dom,$confname);
9530: my %lt = &Apache::lonlocal::texthash (
1.95 www 9531: default => 'Default bubblesheet format file error',
9532: custom => 'Custom bubblesheet format file error',
1.46 raeburn 9533: );
9534: my %scantronfiles = (
9535: default => 'default.tab',
9536: custom => 'custom.tab',
9537: );
9538: foreach my $key (keys(%scantronfiles)) {
9539: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
9540: .$scantronfiles{$key};
9541: }
9542: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
9543: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
9544: if (!$switchserver) {
9545: my $servadm = $r->dir_config('lonAdmEMail');
9546: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
9547: if ($configuserok eq 'ok') {
9548: if ($author_ok eq 'ok') {
9549: my %legacyfile = (
1.346 raeburn 9550: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
9551: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 9552: );
9553: my %md5chk;
9554: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 9555: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
9556: chomp($md5chk{$type});
1.46 raeburn 9557: }
9558: if ($md5chk{'default'} ne $md5chk{'custom'}) {
9559: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 9560: ($scantronurls{$type},my $error) =
1.46 raeburn 9561: &legacy_scantronformat($r,$dom,$confname,
9562: $type,$legacyfile{$type},
9563: $scantronurls{$type},
9564: $scantronfiles{$type});
1.60 raeburn 9565: if ($error ne '') {
9566: $error{$type} = $error;
9567: }
9568: }
9569: if (keys(%error) == 0) {
9570: $is_custom = 1;
1.346 raeburn 9571: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 9572: $scantronurls{'custom'};
1.346 raeburn 9573: my $putresult =
1.60 raeburn 9574: &Apache::lonnet::put_dom('configuration',
9575: \%confhash,$dom);
9576: if ($putresult ne 'ok') {
1.346 raeburn 9577: $error{'custom'} =
1.60 raeburn 9578: '<span class="LC_error">'.
9579: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
9580: }
1.46 raeburn 9581: }
9582: } else {
1.60 raeburn 9583: ($scantronurls{'default'},my $error) =
1.46 raeburn 9584: &legacy_scantronformat($r,$dom,$confname,
9585: 'default',$legacyfile{'default'},
9586: $scantronurls{'default'},
9587: $scantronfiles{'default'});
1.60 raeburn 9588: if ($error eq '') {
9589: $confhash{'scantron'}{'scantronformat'} = '';
9590: my $putresult =
9591: &Apache::lonnet::put_dom('configuration',
9592: \%confhash,$dom);
9593: if ($putresult ne 'ok') {
9594: $error{'default'} =
9595: '<span class="LC_error">'.
9596: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
9597: }
9598: } else {
9599: $error{'default'} = $error;
9600: }
1.46 raeburn 9601: }
9602: }
9603: }
9604: } else {
1.95 www 9605: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 9606: }
9607: }
9608: if (ref($settings) eq 'HASH') {
9609: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
9610: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
9611: if ((!@info) || ($info[0] eq 'no_such_dir')) {
9612: $scantronurl = '';
9613: } else {
9614: $scantronurl = $settings->{'scantronformat'};
9615: }
9616: $is_custom = 1;
9617: } else {
9618: $scantronurl = $scantronurls{'default'};
9619: }
9620: } else {
1.60 raeburn 9621: if ($is_custom) {
9622: $scantronurl = $scantronurls{'custom'};
9623: } else {
9624: $scantronurl = $scantronurls{'default'};
9625: }
1.46 raeburn 9626: }
9627: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9628: $datatable .= '<tr'.$css_class.'>';
9629: if (!$is_custom) {
1.65 raeburn 9630: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
9631: '<span class="LC_nobreak">';
1.46 raeburn 9632: if ($scantronurl) {
1.199 raeburn 9633: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
9634: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 9635: } else {
9636: $datatable = &mt('File unavailable for display');
9637: }
1.65 raeburn 9638: $datatable .= '</span></td>';
1.60 raeburn 9639: if (keys(%error) == 0) {
1.306 raeburn 9640: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 9641: if (!$switchserver) {
9642: $datatable .= &mt('Upload:').'<br />';
9643: }
9644: } else {
9645: my $errorstr;
9646: foreach my $key (sort(keys(%error))) {
9647: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
9648: }
9649: $datatable .= '<td>'.$errorstr;
9650: }
1.46 raeburn 9651: } else {
9652: if (keys(%error) > 0) {
9653: my $errorstr;
9654: foreach my $key (sort(keys(%error))) {
9655: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
9656: }
1.60 raeburn 9657: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 9658: } elsif ($scantronurl) {
1.199 raeburn 9659: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
9660: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 9661: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 9662: $link.
9663: '<label><input type="checkbox" name="scantronformat_del"'.
9664: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 9665: '<td><span class="LC_nobreak"> '.
9666: &mt('Replace:').'</span><br />';
1.46 raeburn 9667: }
9668: }
9669: if (keys(%error) == 0) {
9670: if ($switchserver) {
9671: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
9672: } else {
1.65 raeburn 9673: $datatable .='<span class="LC_nobreak"> '.
9674: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 9675: }
9676: }
9677: $datatable .= '</td></tr>';
9678: $$rowtotal ++;
9679: return $datatable;
9680: }
9681:
9682: sub legacy_scantronformat {
9683: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
9684: my ($url,$error);
9685: my @statinfo = &Apache::lonnet::stat_file($newurl);
9686: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
9687: (my $result,$url) =
9688: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
9689: '','',$newfile);
9690: if ($result ne 'ok') {
1.130 raeburn 9691: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 9692: }
9693: }
9694: return ($url,$error);
9695: }
1.43 raeburn 9696:
1.346 raeburn 9697: sub print_scantronconfig {
9698: my ($dom,$settings,$rowtotal) = @_;
9699: my $itemcount = 2;
9700: my $is_checked = ' checked="checked"';
1.347 raeburn 9701: my %optionson = (
9702: hdr => ' checked="checked"',
9703: pad => ' checked="checked"',
9704: rem => ' checked="checked"',
9705: );
9706: my %optionsoff = (
9707: hdr => '',
9708: pad => '',
9709: rem => '',
9710: );
1.346 raeburn 9711: my $currcsvsty = 'none';
1.347 raeburn 9712: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 9713: my @fields = &scantroncsv_fields();
9714: my %titles = &scantronconfig_titles();
9715: if (ref($settings) eq 'HASH') {
9716: if (ref($settings->{config}) eq 'HASH') {
9717: if ($settings->{config}->{dat}) {
9718: $checked{'dat'} = $is_checked;
9719: }
9720: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 9721: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
9722: %csvfields = %{$settings->{config}->{csv}->{fields}};
9723: if (keys(%csvfields) > 0) {
9724: $checked{'csv'} = $is_checked;
9725: $currcsvsty = 'block';
9726: }
9727: }
9728: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
9729: %csvoptions = %{$settings->{config}->{csv}->{options}};
9730: foreach my $option (keys(%optionson)) {
9731: unless ($csvoptions{$option}) {
9732: $optionsoff{$option} = $optionson{$option};
9733: $optionson{$option} = '';
9734: }
9735: }
1.346 raeburn 9736: }
9737: }
9738: } else {
9739: $checked{'dat'} = $is_checked;
9740: }
9741: } else {
9742: $checked{'dat'} = $is_checked;
9743: }
9744: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
9745: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
9746: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
9747: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
9748: foreach my $item ('dat','csv') {
9749: my $id;
9750: if ($item eq 'csv') {
9751: $id = 'id="scantronconfcsv" ';
1.347 raeburn 9752: }
1.346 raeburn 9753: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
9754: $titles{$item}.'</label>'.(' 'x3);
9755: if ($item eq 'csv') {
9756: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
9757: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
9758: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
9759: foreach my $col (@fields) {
9760: my $selnone;
9761: if ($csvfields{$col} eq '') {
9762: $selnone = ' selected="selected"';
9763: }
9764: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
9765: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
9766: '<option value=""'.$selnone.'></option>';
9767: for (my $i=0; $i<20; $i++) {
9768: my $shown = $i+1;
9769: my $sel;
9770: unless ($selnone) {
9771: if (exists($csvfields{$col})) {
9772: if ($csvfields{$col} == $i) {
9773: $sel = ' selected="selected"';
9774: }
9775: }
9776: }
9777: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
9778: }
9779: $datatable .= '</select></td></tr>';
9780: }
1.347 raeburn 9781: $datatable .= '</table></fieldset>'.
9782: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
9783: '<legend>'.&mt('CSV Options').'</legend>';
9784: foreach my $option ('hdr','pad','rem') {
9785: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
9786: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
9787: &mt('Yes').'</label>'.(' 'x2)."\n".
9788: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
9789: }
9790: $datatable .= '</fieldset>';
1.346 raeburn 9791: $itemcount ++;
9792: }
9793: }
9794: $datatable .= '</td></tr>';
9795: $$rowtotal ++;
9796: return $datatable;
9797: }
9798:
9799: sub scantronconfig_titles {
9800: return &Apache::lonlocal::texthash(
9801: dat => 'Standard format (.dat)',
9802: csv => 'Comma separated values (.csv)',
1.347 raeburn 9803: hdr => 'Remove first line in file (contains column titles)',
9804: pad => 'Prepend 0s to PaperID',
1.348 raeburn 9805: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 9806: CODE => 'CODE',
9807: ID => 'Student ID',
9808: PaperID => 'Paper ID',
9809: FirstName => 'First Name',
9810: LastName => 'Last Name',
9811: FirstQuestion => 'First Question Response',
9812: Section => 'Section',
9813: );
9814: }
9815:
9816: sub scantroncsv_fields {
9817: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
9818: }
9819:
1.49 raeburn 9820: sub print_coursecategories {
1.57 raeburn 9821: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
9822: my $datatable;
9823: if ($position eq 'top') {
1.238 raeburn 9824: my (%checked);
9825: my @catitems = ('unauth','auth');
9826: my @cattypes = ('std','domonly','codesrch','none');
9827: $checked{'unauth'} = 'std';
9828: $checked{'auth'} = 'std';
9829: if (ref($settings) eq 'HASH') {
9830: foreach my $type (@cattypes) {
9831: if ($type eq $settings->{'unauth'}) {
9832: $checked{'unauth'} = $type;
9833: }
9834: if ($type eq $settings->{'auth'}) {
9835: $checked{'auth'} = $type;
9836: }
9837: }
9838: }
9839: my %lt = &Apache::lonlocal::texthash (
9840: unauth => 'Catalog type for unauthenticated users',
9841: auth => 'Catalog type for authenticated users',
9842: none => 'No catalog',
9843: std => 'Standard catalog',
9844: domonly => 'Domain-only catalog',
9845: codesrch => "Code search form",
9846: );
9847: my $itemcount = 0;
9848: foreach my $item (@catitems) {
9849: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
9850: $datatable .= '<tr '.$css_class.'>'.
9851: '<td>'.$lt{$item}.'</td>'.
9852: '<td class="LC_right_item"><span class="LC_nobreak">';
9853: foreach my $type (@cattypes) {
9854: my $ischecked;
9855: if ($checked{$item} eq $type) {
9856: $ischecked=' checked="checked"';
9857: }
9858: $datatable .= '<label>'.
9859: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
9860: ' />'.$lt{$type}.'</label> ';
9861: }
1.327 raeburn 9862: $datatable .= '</span></td></tr>';
1.238 raeburn 9863: $itemcount ++;
9864: }
9865: $$rowtotal += $itemcount;
9866: } elsif ($position eq 'middle') {
1.57 raeburn 9867: my $toggle_cats_crs = ' ';
9868: my $toggle_cats_dom = ' checked="checked" ';
9869: my $can_cat_crs = ' ';
9870: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 9871: my $toggle_catscomm_comm = ' ';
9872: my $toggle_catscomm_dom = ' checked="checked" ';
9873: my $can_catcomm_comm = ' ';
9874: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 9875: my $toggle_catsplace_place = ' ';
9876: my $toggle_catsplace_dom = ' checked="checked" ';
9877: my $can_catplace_place = ' ';
9878: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 9879:
1.57 raeburn 9880: if (ref($settings) eq 'HASH') {
9881: if ($settings->{'togglecats'} eq 'crs') {
9882: $toggle_cats_crs = $toggle_cats_dom;
9883: $toggle_cats_dom = ' ';
9884: }
9885: if ($settings->{'categorize'} eq 'crs') {
9886: $can_cat_crs = $can_cat_dom;
9887: $can_cat_dom = ' ';
9888: }
1.120 raeburn 9889: if ($settings->{'togglecatscomm'} eq 'comm') {
9890: $toggle_catscomm_comm = $toggle_catscomm_dom;
9891: $toggle_catscomm_dom = ' ';
9892: }
9893: if ($settings->{'categorizecomm'} eq 'comm') {
9894: $can_catcomm_comm = $can_catcomm_dom;
9895: $can_catcomm_dom = ' ';
9896: }
1.272 raeburn 9897: if ($settings->{'togglecatsplace'} eq 'place') {
9898: $toggle_catsplace_place = $toggle_catsplace_dom;
9899: $toggle_catsplace_dom = ' ';
9900: }
9901: if ($settings->{'categorizeplace'} eq 'place') {
9902: $can_catplace_place = $can_catplace_dom;
9903: $can_catplace_dom = ' ';
9904: }
1.57 raeburn 9905: }
9906: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 9907: togglecats => 'Show/Hide a course in catalog',
9908: togglecatscomm => 'Show/Hide a community in catalog',
9909: togglecatsplace => 'Show/Hide a placement test in catalog',
9910: categorize => 'Assign a category to a course',
9911: categorizecomm => 'Assign a category to a community',
9912: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 9913: );
9914: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 9915: dom => 'Set in Domain',
9916: crs => 'Set in Course',
9917: comm => 'Set in Community',
9918: place => 'Set in Placement Test',
1.57 raeburn 9919: );
9920: $datatable = '<tr class="LC_odd_row">'.
9921: '<td>'.$title{'togglecats'}.'</td>'.
9922: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
9923: '<input type="radio" name="togglecats"'.
9924: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9925: '<label><input type="radio" name="togglecats"'.
9926: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
9927: '</tr><tr>'.
9928: '<td>'.$title{'categorize'}.'</td>'.
9929: '<td class="LC_right_item"><span class="LC_nobreak">'.
9930: '<label><input type="radio" name="categorize"'.
9931: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9932: '<label><input type="radio" name="categorize"'.
9933: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 9934: '</tr><tr class="LC_odd_row">'.
9935: '<td>'.$title{'togglecatscomm'}.'</td>'.
9936: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
9937: '<input type="radio" name="togglecatscomm"'.
9938: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9939: '<label><input type="radio" name="togglecatscomm"'.
9940: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
9941: '</tr><tr>'.
9942: '<td>'.$title{'categorizecomm'}.'</td>'.
9943: '<td class="LC_right_item"><span class="LC_nobreak">'.
9944: '<label><input type="radio" name="categorizecomm"'.
9945: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9946: '<label><input type="radio" name="categorizecomm"'.
9947: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 9948: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 9949: '<td>'.$title{'togglecatsplace'}.'</td>'.
9950: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
9951: '<input type="radio" name="togglecatsplace"'.
9952: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9953: '<label><input type="radio" name="togglecatscomm"'.
9954: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
9955: '</tr><tr>'.
9956: '<td>'.$title{'categorizeplace'}.'</td>'.
9957: '<td class="LC_right_item"><span class="LC_nobreak">'.
9958: '<label><input type="radio" name="categorizeplace"'.
9959: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9960: '<label><input type="radio" name="categorizeplace"'.
9961: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 9962: '</tr>';
1.272 raeburn 9963: $$rowtotal += 6;
1.57 raeburn 9964: } else {
9965: my $css_class;
9966: my $itemcount = 1;
9967: my $cathash;
9968: if (ref($settings) eq 'HASH') {
9969: $cathash = $settings->{'cats'};
9970: }
9971: if (ref($cathash) eq 'HASH') {
9972: my (@cats,@trails,%allitems,%idx,@jsarray);
9973: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
9974: \%allitems,\%idx,\@jsarray);
9975: my $maxdepth = scalar(@cats);
9976: my $colattrib = '';
9977: if ($maxdepth > 2) {
9978: $colattrib = ' colspan="2" ';
9979: }
9980: my @path;
9981: if (@cats > 0) {
9982: if (ref($cats[0]) eq 'ARRAY') {
9983: my $numtop = @{$cats[0]};
9984: my $maxnum = $numtop;
1.120 raeburn 9985: my %default_names = (
9986: instcode => &mt('Official courses'),
9987: communities => &mt('Communities'),
1.272 raeburn 9988: placement => &mt('Placement Tests'),
1.120 raeburn 9989: );
9990:
9991: if ((!grep(/^instcode$/,@{$cats[0]})) ||
9992: ($cathash->{'instcode::0'} eq '') ||
9993: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 9994: ($cathash->{'communities::0'} eq '') ||
9995: (!grep(/^placement$/,@{$cats[0]})) ||
9996: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 9997: $maxnum ++;
9998: }
9999: my $lastidx;
10000: for (my $i=0; $i<$numtop; $i++) {
10001: my $parent = $cats[0][$i];
10002: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10003: my $item = &escape($parent).'::0';
10004: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
10005: $lastidx = $idx{$item};
10006: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
10007: .'<select name="'.$item.'"'.$chgstr.'>';
10008: for (my $k=0; $k<=$maxnum; $k++) {
10009: my $vpos = $k+1;
10010: my $selstr;
10011: if ($k == $i) {
10012: $selstr = ' selected="selected" ';
10013: }
10014: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10015: }
1.214 raeburn 10016: $datatable .= '</select></span></td><td>';
1.272 raeburn 10017: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 10018: $datatable .= '<span class="LC_nobreak">'
10019: .$default_names{$parent}.'</span>';
10020: if ($parent eq 'instcode') {
10021: $datatable .= '<br /><span class="LC_nobreak">('
10022: .&mt('with institutional codes')
10023: .')</span></td><td'.$colattrib.'>';
10024: } else {
10025: $datatable .= '<table><tr><td>';
10026: }
10027: $datatable .= '<span class="LC_nobreak">'
10028: .'<label><input type="radio" name="'
10029: .$parent.'" value="1" checked="checked" />'
10030: .&mt('Display').'</label>';
10031: if ($parent eq 'instcode') {
10032: $datatable .= ' ';
10033: } else {
10034: $datatable .= '</span></td></tr><tr><td>'
10035: .'<span class="LC_nobreak">';
10036: }
10037: $datatable .= '<label><input type="radio" name="'
10038: .$parent.'" value="0" />'
10039: .&mt('Do not display').'</label></span>';
1.272 raeburn 10040: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 10041: $datatable .= '</td></tr></table>';
10042: }
10043: $datatable .= '</td>';
1.57 raeburn 10044: } else {
10045: $datatable .= $parent
1.214 raeburn 10046: .' <span class="LC_nobreak"><label>'
10047: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 10048: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
10049: }
10050: my $depth = 1;
10051: push(@path,$parent);
10052: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
10053: pop(@path);
10054: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
10055: $itemcount ++;
10056: }
1.48 raeburn 10057: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 10058: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
10059: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 10060: for (my $k=0; $k<=$maxnum; $k++) {
10061: my $vpos = $k+1;
10062: my $selstr;
1.57 raeburn 10063: if ($k == $numtop) {
1.48 raeburn 10064: $selstr = ' selected="selected" ';
10065: }
10066: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10067: }
1.59 bisitz 10068: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 10069: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
10070: .'</tr>'."\n";
1.48 raeburn 10071: $itemcount ++;
1.272 raeburn 10072: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 10073: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
10074: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10075: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
10076: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
10077: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
10078: for (my $k=0; $k<=$maxnum; $k++) {
10079: my $vpos = $k+1;
10080: my $selstr;
10081: if ($k == $maxnum) {
10082: $selstr = ' selected="selected" ';
10083: }
10084: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 10085: }
1.120 raeburn 10086: $datatable .= '</select></span></td>'.
10087: '<td><span class="LC_nobreak">'.
10088: $default_names{$default}.'</span>';
10089: if ($default eq 'instcode') {
10090: $datatable .= '<br /><span class="LC_nobreak">('
10091: .&mt('with institutional codes').')</span>';
10092: }
10093: $datatable .= '</td>'
10094: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
10095: .&mt('Display').'</label> '
10096: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
10097: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 10098: }
10099: }
10100: }
1.57 raeburn 10101: } else {
10102: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 10103: }
10104: } else {
1.327 raeburn 10105: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 10106: .&initialize_categories($itemcount);
1.48 raeburn 10107: }
1.57 raeburn 10108: $$rowtotal += $itemcount;
1.48 raeburn 10109: }
10110: return $datatable;
10111: }
10112:
1.69 raeburn 10113: sub print_serverstatuses {
10114: my ($dom,$settings,$rowtotal) = @_;
10115: my $datatable;
10116: my @pages = &serverstatus_pages();
10117: my (%namedaccess,%machineaccess);
10118: foreach my $type (@pages) {
10119: $namedaccess{$type} = '';
10120: $machineaccess{$type}= '';
10121: }
10122: if (ref($settings) eq 'HASH') {
10123: foreach my $type (@pages) {
10124: if (exists($settings->{$type})) {
10125: if (ref($settings->{$type}) eq 'HASH') {
10126: foreach my $key (keys(%{$settings->{$type}})) {
10127: if ($key eq 'namedusers') {
10128: $namedaccess{$type} = $settings->{$type}->{$key};
10129: } elsif ($key eq 'machines') {
10130: $machineaccess{$type} = $settings->{$type}->{$key};
10131: }
10132: }
10133: }
10134: }
10135: }
10136: }
1.81 raeburn 10137: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 10138: my $rownum = 0;
10139: my $css_class;
10140: foreach my $type (@pages) {
10141: $rownum ++;
10142: $css_class = $rownum%2?' class="LC_odd_row"':'';
10143: $datatable .= '<tr'.$css_class.'>'.
10144: '<td><span class="LC_nobreak">'.
10145: $titles->{$type}.'</span></td>'.
10146: '<td class="LC_left_item">'.
10147: '<input type="text" name="'.$type.'_namedusers" '.
10148: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
10149: '<td class="LC_right_item">'.
10150: '<span class="LC_nobreak">'.
10151: '<input type="text" name="'.$type.'_machines" '.
10152: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 10153: '</span></td></tr>'."\n";
1.69 raeburn 10154: }
10155: $$rowtotal += $rownum;
10156: return $datatable;
10157: }
10158:
10159: sub serverstatus_pages {
10160: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 10161: 'checksums','clusterstatus','certstatus','metadata_keywords',
10162: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
10163: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 10164: }
10165:
1.236 raeburn 10166: sub defaults_javascript {
10167: my ($settings) = @_;
1.354 raeburn 10168: return unless (ref($settings) eq 'HASH');
1.236 raeburn 10169: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10170: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
10171: if ($maxnum eq '') {
10172: $maxnum = 0;
10173: }
10174: $maxnum ++;
1.249 raeburn 10175: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 10176: return <<"ENDSCRIPT";
10177: <script type="text/javascript">
10178: // <![CDATA[
10179: function reorderTypes(form,caller) {
10180: var changedVal;
10181: $jstext
10182: var newpos = 'addinststatus_pos';
10183: var current = new Array;
10184: var maxh = $maxnum;
10185: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
10186: var oldVal;
10187: if (caller == newpos) {
10188: changedVal = newitemVal;
10189: } else {
10190: var curritem = 'inststatus_pos_'+caller;
10191: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
10192: current[newitemVal] = newpos;
10193: }
10194: for (var i=0; i<inststatuses.length; i++) {
10195: if (inststatuses[i] != caller) {
10196: var elementName = 'inststatus_pos_'+inststatuses[i];
10197: if (form.elements[elementName]) {
10198: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
10199: current[currVal] = elementName;
10200: }
10201: }
10202: }
10203: for (var j=0; j<maxh; j++) {
10204: if (current[j] == undefined) {
10205: oldVal = j;
10206: }
10207: }
10208: if (oldVal < changedVal) {
10209: for (var k=oldVal+1; k<=changedVal ; k++) {
10210: var elementName = current[k];
10211: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
10212: }
10213: } else {
10214: for (var k=changedVal; k<oldVal; k++) {
10215: var elementName = current[k];
10216: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
10217: }
10218: }
10219: return;
10220: }
10221:
10222: // ]]>
10223: </script>
10224:
10225: ENDSCRIPT
10226: }
1.354 raeburn 10227: return;
10228: }
10229:
10230: sub passwords_javascript {
1.365 raeburn 10231: my %intalert = &Apache::lonlocal::texthash (
10232: authcheck => 'Warning: disallowing login for an authenticated user if the stored cost is less than the default will require a password reset by/for the user.',
10233: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
10234: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
10235: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
10236: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
10237: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
10238: );
10239: &js_escape(\%intalert);
10240: my $defmin = $Apache::lonnet::passwdmin;
1.354 raeburn 10241: my $intauthjs = <<"ENDSCRIPT";
10242:
10243: function warnIntAuth(field) {
10244: if (field.name == 'intauth_check') {
10245: if (field.value == '2') {
1.365 raeburn 10246: alert('$intalert{authcheck}');
1.354 raeburn 10247: }
10248: }
10249: if (field.name == 'intauth_cost') {
10250: field.value.replace(/\s/g,'');
10251: if (field.value != '') {
10252: var regexdigit=/^\\d+\$/;
10253: if (!regexdigit.test(field.value)) {
1.365 raeburn 10254: alert('$intalert{authcost}');
10255: }
10256: }
10257: }
10258: return;
10259: }
10260:
10261: function warnIntPass(field) {
10262: field.value.replace(/^\s+/,'');
10263: field.value.replace(/\s+\$/,'');
10264: var regexdigit=/^\\d+\$/;
10265: if (field.name == 'passwords_min') {
10266: if (field.value == '') {
10267: alert('$intalert{passmin}');
10268: field.value = '$defmin';
10269: } else {
10270: if (!regexdigit.test(field.value)) {
10271: alert('$intalert{passmin}');
10272: field.value = '$defmin';
10273: }
1.366 raeburn 10274: var minval = parseInt(field.value,10);
1.365 raeburn 10275: if (minval < $defmin) {
10276: alert('$intalert{passmin}');
10277: field.value = '$defmin';
10278: }
10279: }
10280: } else {
10281: if (field.value == '0') {
10282: field.value = '';
10283: }
10284: if (field.value != '') {
10285: if (field.name == 'passwords_expire') {
10286: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
10287: if (!regexpposnum.test(field.value)) {
10288: alert('$intalert{passexp}');
10289: field.value = '';
10290: } else {
10291: var expval = parseFloat(field.value);
10292: if (expval == 0) {
10293: alert('$intalert{passexp}');
10294: field.value = '';
10295: }
10296: }
10297: } else {
10298: if (!regexdigit.test(field.value)) {
10299: if (field.name == 'passwords_max') {
10300: alert('$intalert{passmax}');
10301: } else {
10302: if (field.name == 'passwords_numsaved') {
10303: alert('$intalert{passnum}');
10304: }
10305: }
1.370 raeburn 10306: field.value = '';
1.365 raeburn 10307: }
1.354 raeburn 10308: }
10309: }
10310: }
10311: return;
10312: }
10313:
10314: ENDSCRIPT
10315: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 10316: }
10317:
1.49 raeburn 10318: sub coursecategories_javascript {
10319: my ($settings) = @_;
1.57 raeburn 10320: my ($output,$jstext,$cathash);
1.49 raeburn 10321: if (ref($settings) eq 'HASH') {
1.57 raeburn 10322: $cathash = $settings->{'cats'};
10323: }
10324: if (ref($cathash) eq 'HASH') {
1.49 raeburn 10325: my (@cats,@jsarray,%idx);
1.57 raeburn 10326: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 10327: if (@jsarray > 0) {
10328: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
10329: for (my $i=0; $i<@jsarray; $i++) {
10330: if (ref($jsarray[$i]) eq 'ARRAY') {
10331: my $catstr = join('","',@{$jsarray[$i]});
10332: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
10333: }
10334: }
10335: }
10336: } else {
10337: $jstext = ' var categories = Array(1);'."\n".
10338: ' categories[0] = Array("instcode_pos");'."\n";
10339: }
1.237 bisitz 10340: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
10341: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 10342: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 10343: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
10344: &js_escape(\$instcode_reserved);
10345: &js_escape(\$communities_reserved);
1.272 raeburn 10346: &js_escape(\$placement_reserved);
1.265 damieng 10347: &js_escape(\$choose_again);
1.49 raeburn 10348: $output = <<"ENDSCRIPT";
10349: <script type="text/javascript">
1.109 raeburn 10350: // <![CDATA[
1.49 raeburn 10351: function reorderCats(form,parent,item,idx) {
10352: var changedVal;
10353: $jstext
10354: var newpos = 'addcategory_pos';
10355: if (parent == '') {
10356: var has_instcode = 0;
10357: var maxtop = categories[idx].length;
10358: for (var j=0; j<maxtop; j++) {
10359: if (categories[idx][j] == 'instcode::0') {
10360: has_instcode == 1;
10361: }
10362: }
10363: if (has_instcode == 0) {
10364: categories[idx][maxtop] = 'instcode_pos';
10365: }
10366: } else {
10367: newpos += '_'+parent;
10368: }
10369: var maxh = 1 + categories[idx].length;
10370: var current = new Array;
10371: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
10372: if (item == newpos) {
10373: changedVal = newitemVal;
10374: } else {
10375: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
10376: current[newitemVal] = newpos;
10377: }
10378: for (var i=0; i<categories[idx].length; i++) {
10379: var elementName = categories[idx][i];
10380: if (elementName != item) {
10381: if (form.elements[elementName]) {
10382: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
10383: current[currVal] = elementName;
10384: }
10385: }
10386: }
10387: var oldVal;
10388: for (var j=0; j<maxh; j++) {
10389: if (current[j] == undefined) {
10390: oldVal = j;
10391: }
10392: }
10393: if (oldVal < changedVal) {
10394: for (var k=oldVal+1; k<=changedVal ; k++) {
10395: var elementName = current[k];
10396: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
10397: }
10398: } else {
10399: for (var k=changedVal; k<oldVal; k++) {
10400: var elementName = current[k];
10401: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
10402: }
10403: }
10404: return;
10405: }
1.120 raeburn 10406:
10407: function categoryCheck(form) {
10408: if (form.elements['addcategory_name'].value == 'instcode') {
10409: alert('$instcode_reserved\\n$choose_again');
10410: return false;
10411: }
10412: if (form.elements['addcategory_name'].value == 'communities') {
10413: alert('$communities_reserved\\n$choose_again');
10414: return false;
10415: }
1.272 raeburn 10416: if (form.elements['addcategory_name'].value == 'placement') {
10417: alert('$placement_reserved\\n$choose_again');
10418: return false;
10419: }
1.120 raeburn 10420: return true;
10421: }
10422:
1.109 raeburn 10423: // ]]>
1.49 raeburn 10424: </script>
10425:
10426: ENDSCRIPT
10427: return $output;
10428: }
10429:
1.48 raeburn 10430: sub initialize_categories {
10431: my ($itemcount) = @_;
1.120 raeburn 10432: my ($datatable,$css_class,$chgstr);
10433: my %default_names = (
10434: instcode => 'Official courses (with institutional codes)',
10435: communities => 'Communities',
1.272 raeburn 10436: placement => 'Placement Tests',
1.120 raeburn 10437: );
1.328 raeburn 10438: my %selnum = (
10439: instcode => '0',
10440: communities => '1',
10441: placement => '2',
10442: );
10443: my %selected;
1.272 raeburn 10444: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 10445: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 10446: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 10447: map { $selected{$selnum{$_}} = '' } keys(%selnum);
10448: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 10449: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 10450: .'<select name="'.$default.'_pos"'.$chgstr.'>'
10451: .'<option value="0"'.$selected{'0'}.'>1</option>'
10452: .'<option value="1"'.$selected{'1'}.'>2</option>'
10453: .'<option value="2"'.$selected{'2'}.'>3</option>'
10454: .'<option value="3">4</option></select> '
1.120 raeburn 10455: .$default_names{$default}
10456: .'</span></td><td><span class="LC_nobreak">'
10457: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
10458: .&mt('Display').'</label> <label>'
10459: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 10460: .'</label></span></td></tr>';
1.120 raeburn 10461: $itemcount ++;
10462: }
1.48 raeburn 10463: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 10464: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 10465: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 10466: .'<select name="addcategory_pos"'.$chgstr.'>'
10467: .'<option value="0">1</option>'
10468: .'<option value="1">2</option>'
1.328 raeburn 10469: .'<option value="2">3</option>'
10470: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 10471: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
10472: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
10473: .'</td></tr>';
1.48 raeburn 10474: return $datatable;
10475: }
10476:
10477: sub build_category_rows {
1.49 raeburn 10478: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
10479: my ($text,$name,$item,$chgstr);
1.48 raeburn 10480: if (ref($cats) eq 'ARRAY') {
10481: my $maxdepth = scalar(@{$cats});
10482: if (ref($cats->[$depth]) eq 'HASH') {
10483: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
10484: my $numchildren = @{$cats->[$depth]{$parent}};
10485: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 10486: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 10487: my ($idxnum,$parent_name,$parent_item);
10488: my $higher = $depth - 1;
10489: if ($higher == 0) {
10490: $parent_name = &escape($parent).'::'.$higher;
10491: } else {
10492: if (ref($path) eq 'ARRAY') {
10493: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
10494: }
10495: }
10496: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 10497: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 10498: if ($j < $numchildren) {
1.48 raeburn 10499: $name = $cats->[$depth]{$parent}[$j];
10500: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 10501: $idxnum = $idx->{$item};
10502: } else {
10503: $name = $parent_name;
10504: $item = $parent_item;
1.48 raeburn 10505: }
1.49 raeburn 10506: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
10507: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 10508: for (my $i=0; $i<=$numchildren; $i++) {
10509: my $vpos = $i+1;
10510: my $selstr;
10511: if ($j == $i) {
10512: $selstr = ' selected="selected" ';
10513: }
10514: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
10515: }
10516: $text .= '</select> ';
10517: if ($j < $numchildren) {
10518: my $deeper = $depth+1;
10519: $text .= $name.' '
10520: .'<label><input type="checkbox" name="deletecategory" value="'
10521: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
10522: if(ref($path) eq 'ARRAY') {
10523: push(@{$path},$name);
1.49 raeburn 10524: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 10525: pop(@{$path});
10526: }
10527: } else {
1.330 raeburn 10528: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 10529: if ($j == $numchildren) {
10530: $text .= $name;
10531: } else {
10532: $text .= $item;
10533: }
10534: $text .= '" value="" />';
10535: }
10536: $text .= '</td></tr>';
10537: }
10538: $text .= '</table></td>';
10539: } else {
10540: my $higher = $depth-1;
10541: if ($higher == 0) {
10542: $name = &escape($parent).'::'.$higher;
10543: } else {
10544: if (ref($path) eq 'ARRAY') {
10545: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
10546: }
10547: }
10548: my $colspan;
10549: if ($parent ne 'instcode') {
10550: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 10551: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 10552: }
10553: }
10554: }
10555: }
10556: return $text;
10557: }
10558:
1.33 raeburn 10559: sub modifiable_userdata_row {
1.305 raeburn 10560: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 10561: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 10562: my ($role,$rolename,$statustype);
10563: $role = $item;
1.224 raeburn 10564: if ($context eq 'cancreate') {
1.305 raeburn 10565: if ($item =~ /^(emailusername)_(.+)$/) {
10566: $role = $1;
10567: $statustype = $2;
1.228 raeburn 10568: if (ref($usertypes) eq 'HASH') {
10569: if ($usertypes->{$statustype}) {
10570: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
10571: } else {
10572: $rolename = &mt('Data provided by user');
10573: }
10574: }
1.224 raeburn 10575: }
10576: } elsif ($context eq 'selfcreate') {
1.63 raeburn 10577: if (ref($usertypes) eq 'HASH') {
10578: $rolename = $usertypes->{$role};
10579: } else {
10580: $rolename = $role;
10581: }
1.325 raeburn 10582: } elsif ($context eq 'lti') {
10583: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 10584: } elsif ($context eq 'privacy') {
10585: $rolename = $itemdesc;
1.33 raeburn 10586: } else {
1.63 raeburn 10587: if ($role eq 'cr') {
10588: $rolename = &mt('Custom role');
10589: } else {
10590: $rolename = &Apache::lonnet::plaintext($role);
10591: }
1.33 raeburn 10592: }
1.224 raeburn 10593: my (@fields,%fieldtitles);
10594: if (ref($fieldsref) eq 'ARRAY') {
10595: @fields = @{$fieldsref};
10596: } else {
10597: @fields = ('lastname','firstname','middlename','generation',
10598: 'permanentemail','id');
10599: }
10600: if ((ref($titlesref) eq 'HASH')) {
10601: %fieldtitles = %{$titlesref};
10602: } else {
10603: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10604: }
1.33 raeburn 10605: my $output;
1.305 raeburn 10606: my $css_class;
10607: if ($rowcount%2) {
10608: $css_class = 'LC_odd_row';
10609: }
10610: if ($customcss) {
10611: $css_class .= " $customcss";
10612: }
10613: $css_class =~ s/^\s+//;
10614: if ($css_class) {
10615: $css_class = ' class="'.$css_class.'"';
10616: }
10617: if ($rowstyle) {
10618: $css_class .= ' style="'.$rowstyle.'"';
10619: }
10620: if ($rowid) {
10621: $rowid = ' id="'.$rowid.'"';
10622: }
10623: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 10624: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
10625: '<td class="LC_left_item" colspan="2"><table>';
10626: my $rem;
10627: my %checks;
1.325 raeburn 10628: my %current;
1.33 raeburn 10629: if (ref($settings) eq 'HASH') {
1.325 raeburn 10630: my $hashref;
10631: if ($context eq 'lti') {
10632: if (ref($settings) eq 'HASH') {
10633: $hashref = $settings->{'instdata'};
10634: }
1.357 raeburn 10635: } elsif ($context eq 'privacy') {
10636: my ($key,$inner) = split(/_/,$role);
10637: if (ref($settings) eq 'HASH') {
10638: if (ref($settings->{$key}) eq 'HASH') {
10639: $hashref = $settings->{$key}->{$inner};
10640: }
10641: }
1.325 raeburn 10642: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 10643: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 10644: $hashref = $settings->{'lti_instdata'};
10645: }
10646: if ($role eq 'emailusername') {
10647: if ($statustype) {
10648: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
10649: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 10650: }
1.325 raeburn 10651: }
10652: }
10653: }
10654: if (ref($hashref) eq 'HASH') {
10655: foreach my $field (@fields) {
10656: if ($hashref->{$field}) {
10657: if ($role eq 'emailusername') {
10658: $checks{$field} = $hashref->{$field};
10659: } else {
10660: $checks{$field} = ' checked="checked" ';
1.33 raeburn 10661: }
10662: }
10663: }
10664: }
10665: }
1.305 raeburn 10666:
10667: my $total = scalar(@fields);
10668: for (my $i=0; $i<$total; $i++) {
10669: $rem = $i%($numinrow);
1.33 raeburn 10670: if ($rem == 0) {
10671: if ($i > 0) {
10672: $output .= '</tr>';
10673: }
10674: $output .= '<tr>';
10675: }
10676: my $check = ' ';
1.228 raeburn 10677: unless ($role eq 'emailusername') {
10678: if (exists($checks{$fields[$i]})) {
1.354 raeburn 10679: $check = $checks{$fields[$i]};
1.357 raeburn 10680: } elsif ($context eq 'privacy') {
10681: if ($role =~ /^priv_(domain|course)$/) {
10682: if (ref($settings) ne 'HASH') {
10683: $check = ' checked="checked" ';
10684: }
10685: } elsif ($role =~ /^priv_(author|community)$/) {
10686: if (ref($settings) ne 'HASH') {
10687: unless ($fields[$i] eq 'id') {
10688: $check = ' checked="checked" ';
10689: }
10690: }
10691: } elsif ($role =~ /^(unpriv|othdom)_/) {
10692: if (ref($settings) ne 'HASH') {
10693: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
10694: $check = ' checked="checked" ';
10695: }
10696: }
10697: }
1.325 raeburn 10698: } elsif ($context ne 'lti') {
1.228 raeburn 10699: if ($role eq 'st') {
10700: if (ref($settings) ne 'HASH') {
10701: $check = ' checked="checked" ';
10702: }
1.33 raeburn 10703: }
10704: }
10705: }
10706: $output .= '<td class="LC_left_item">'.
1.228 raeburn 10707: '<span class="LC_nobreak">';
1.325 raeburn 10708: my $prefix = 'canmodify';
1.228 raeburn 10709: if ($role eq 'emailusername') {
10710: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
10711: $checks{$fields[$i]} = 'omit';
10712: }
10713: foreach my $option ('required','optional','omit') {
10714: my $checked='';
10715: if ($checks{$fields[$i]} eq $option) {
10716: $checked='checked="checked" ';
10717: }
10718: $output .= '<label>'.
1.325 raeburn 10719: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 10720: &mt($option).'</label>'.(' ' x2);
10721: }
10722: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
10723: } else {
1.325 raeburn 10724: if ($context eq 'lti') {
10725: $prefix = 'lti';
1.357 raeburn 10726: } elsif ($context eq 'privacy') {
10727: $prefix = 'privacy';
1.325 raeburn 10728: }
1.228 raeburn 10729: $output .= '<label>'.
1.325 raeburn 10730: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 10731: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
10732: '</label>';
10733: }
10734: $output .= '</span></td>';
1.33 raeburn 10735: }
1.305 raeburn 10736: $rem = $total%$numinrow;
10737: my $colsleft;
10738: if ($rem) {
10739: $colsleft = $numinrow - $rem;
10740: }
10741: if ($colsleft > 1) {
1.33 raeburn 10742: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10743: ' </td>';
10744: } elsif ($colsleft == 1) {
10745: $output .= '<td class="LC_left_item"> </td>';
10746: }
10747: $output .= '</tr></table></td></tr>';
10748: return $output;
10749: }
1.28 raeburn 10750:
1.93 raeburn 10751: sub insttypes_row {
1.305 raeburn 10752: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
10753: $customcss,$rowstyle) = @_;
1.93 raeburn 10754: my %lt = &Apache::lonlocal::texthash (
10755: cansearch => 'Users allowed to search',
10756: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 10757: lockablenames => 'User preference to lock name',
1.305 raeburn 10758: selfassign => 'Self-reportable affiliations',
1.315 raeburn 10759: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 10760: );
10761: my $showdom;
10762: if ($context eq 'cansearch') {
10763: $showdom = ' ('.$dom.')';
10764: }
1.165 raeburn 10765: my $class = 'LC_left_item';
10766: if ($context eq 'statustocreate') {
10767: $class = 'LC_right_item';
10768: }
1.305 raeburn 10769: my $css_class;
10770: if ($$rowtotal%2) {
10771: $css_class = 'LC_odd_row';
10772: }
10773: if ($customcss) {
10774: $css_class .= ' '.$customcss;
10775: }
10776: $css_class =~ s/^\s+//;
10777: if ($css_class) {
10778: $css_class = ' class="'.$css_class.'"';
10779: }
10780: if ($rowstyle) {
10781: $css_class .= ' style="'.$rowstyle.'"';
10782: }
10783: if ($onclick) {
10784: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 10785: }
10786: my $output = '<tr'.$css_class.'>'.
10787: '<td>'.$lt{$context}.$showdom.
10788: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 10789: my $rem;
10790: if (ref($types) eq 'ARRAY') {
10791: for (my $i=0; $i<@{$types}; $i++) {
10792: if (defined($usertypes->{$types->[$i]})) {
10793: my $rem = $i%($numinrow);
10794: if ($rem == 0) {
10795: if ($i > 0) {
10796: $output .= '</tr>';
10797: }
10798: $output .= '<tr>';
1.23 raeburn 10799: }
1.26 raeburn 10800: my $check = ' ';
1.99 raeburn 10801: if (ref($settings) eq 'HASH') {
10802: if (ref($settings->{$context}) eq 'ARRAY') {
10803: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
10804: $check = ' checked="checked" ';
10805: }
1.315 raeburn 10806: } elsif (ref($settings->{$context}) eq 'HASH') {
10807: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
10808: $check = ' checked="checked" ';
10809: }
1.99 raeburn 10810: } elsif ($context eq 'statustocreate') {
1.26 raeburn 10811: $check = ' checked="checked" ';
10812: }
1.23 raeburn 10813: }
1.26 raeburn 10814: $output .= '<td class="LC_left_item">'.
10815: '<span class="LC_nobreak"><label>'.
1.93 raeburn 10816: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 10817: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 10818: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 10819: }
10820: }
1.26 raeburn 10821: $rem = @{$types}%($numinrow);
1.23 raeburn 10822: }
10823: my $colsleft = $numinrow - $rem;
1.315 raeburn 10824: if ($context eq 'overrides') {
10825: if ($colsleft > 1) {
10826: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
10827: } else {
10828: $output .= '<td class="LC_left_item">';
10829: }
10830: $output .= ' ';
1.23 raeburn 10831: } else {
1.334 raeburn 10832: if ($rem == 0) {
1.315 raeburn 10833: $output .= '<tr>';
10834: }
10835: if ($colsleft > 1) {
10836: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
10837: } else {
10838: $output .= '<td class="LC_left_item">';
10839: }
10840: my $defcheck = ' ';
10841: if (ref($settings) eq 'HASH') {
10842: if (ref($settings->{$context}) eq 'ARRAY') {
10843: if (grep(/^default$/,@{$settings->{$context}})) {
10844: $defcheck = ' checked="checked" ';
10845: }
10846: } elsif ($context eq 'statustocreate') {
1.99 raeburn 10847: $defcheck = ' checked="checked" ';
10848: }
1.26 raeburn 10849: }
1.315 raeburn 10850: $output .= '<span class="LC_nobreak"><label>'.
10851: '<input type="checkbox" name="'.$context.'" '.
10852: 'value="default"'.$defcheck.$onclick.' />'.
10853: $othertitle.'</label></span>';
1.23 raeburn 10854: }
1.315 raeburn 10855: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 10856: return $output;
1.23 raeburn 10857: }
10858:
10859: sub sorted_searchtitles {
10860: my %searchtitles = &Apache::lonlocal::texthash(
10861: 'uname' => 'username',
10862: 'lastname' => 'last name',
10863: 'lastfirst' => 'last name, first name',
10864: );
10865: my @titleorder = ('uname','lastname','lastfirst');
10866: return (\%searchtitles,\@titleorder);
10867: }
10868:
1.25 raeburn 10869: sub sorted_searchtypes {
10870: my %srchtypes_desc = (
10871: exact => 'is exact match',
10872: contains => 'contains ..',
10873: begins => 'begins with ..',
10874: );
10875: my @srchtypeorder = ('exact','begins','contains');
10876: return (\%srchtypes_desc,\@srchtypeorder);
10877: }
10878:
1.3 raeburn 10879: sub usertype_update_row {
10880: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
10881: my $datatable;
10882: my $numinrow = 4;
10883: foreach my $type (@{$types}) {
10884: if (defined($usertypes->{$type})) {
10885: $$rownums ++;
10886: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
10887: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
10888: '</td><td class="LC_left_item"><table>';
10889: for (my $i=0; $i<@{$fields}; $i++) {
10890: my $rem = $i%($numinrow);
10891: if ($rem == 0) {
10892: if ($i > 0) {
10893: $datatable .= '</tr>';
10894: }
10895: $datatable .= '<tr>';
10896: }
10897: my $check = ' ';
1.39 raeburn 10898: if (ref($settings) eq 'HASH') {
10899: if (ref($settings->{'fields'}) eq 'HASH') {
10900: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
10901: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
10902: $check = ' checked="checked" ';
10903: }
1.3 raeburn 10904: }
10905: }
10906: }
10907:
10908: if ($i == @{$fields}-1) {
10909: my $colsleft = $numinrow - $rem;
10910: if ($colsleft > 1) {
10911: $datatable .= '<td colspan="'.$colsleft.'">';
10912: } else {
10913: $datatable .= '<td>';
10914: }
10915: } else {
10916: $datatable .= '<td>';
10917: }
1.8 raeburn 10918: $datatable .= '<span class="LC_nobreak"><label>'.
10919: '<input type="checkbox" name="updateable_'.$type.
10920: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
10921: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 10922: }
10923: $datatable .= '</tr></table></td></tr>';
10924: }
10925: }
10926: return $datatable;
1.1 raeburn 10927: }
10928:
10929: sub modify_login {
1.205 raeburn 10930: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 10931: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
10932: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
10933: %title = ( coursecatalog => 'Display course catalog',
10934: adminmail => 'Display administrator E-mail address',
1.188 raeburn 10935: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 10936: newuser => 'Link for visitors to create a user account',
10937: loginheader => 'Log-in box header');
10938: @offon = ('off','on');
1.112 raeburn 10939: if (ref($domconfig{login}) eq 'HASH') {
10940: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
10941: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
10942: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
10943: }
10944: }
10945: }
1.9 raeburn 10946: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
10947: \%domconfig,\%loginhash);
1.188 raeburn 10948: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 10949: foreach my $item (@toggles) {
10950: $loginhash{login}{$item} = $env{'form.'.$item};
10951: }
1.41 raeburn 10952: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 10953: if (ref($colchanges{'login'}) eq 'HASH') {
10954: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
10955: \%loginhash);
10956: }
1.110 raeburn 10957:
1.149 raeburn 10958: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 10959: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 10960: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 10961: if (keys(%servers) > 1) {
10962: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 10963: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
10964: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
10965: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
10966: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
10967: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
10968: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
10969: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
10970: $changes{'loginvia'}{$lonhost} = 1;
10971: } else {
10972: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
10973: $changes{'loginvia'}{$lonhost} = 1;
10974: }
10975: } else {
10976: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
10977: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
10978: $changes{'loginvia'}{$lonhost} = 1;
10979: }
10980: }
10981: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
10982: foreach my $item (@loginvia_attribs) {
10983: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
10984: }
10985: } else {
10986: foreach my $item (@loginvia_attribs) {
10987: my $new = $env{'form.'.$lonhost.'_'.$item};
10988: if (($item eq 'serverpath') && ($new eq 'custom')) {
10989: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
10990: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
10991: $new = '/';
10992: }
10993: }
10994: if (($item eq 'custompath') &&
10995: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
10996: $new = '';
10997: }
10998: if ($new ne $curr_loginvia{$lonhost}{$item}) {
10999: $changes{'loginvia'}{$lonhost} = 1;
11000: }
11001: if ($item eq 'exempt') {
1.256 raeburn 11002: $new = &check_exempt_addresses($new);
1.128 raeburn 11003: }
11004: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
11005: }
11006: }
1.112 raeburn 11007: } else {
1.128 raeburn 11008: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11009: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 11010: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 11011: foreach my $item (@loginvia_attribs) {
11012: my $new = $env{'form.'.$lonhost.'_'.$item};
11013: if (($item eq 'serverpath') && ($new eq 'custom')) {
11014: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
11015: $new = '/';
11016: }
11017: }
11018: if (($item eq 'custompath') &&
11019: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
11020: $new = '';
11021: }
11022: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
11023: }
1.110 raeburn 11024: }
11025: }
11026: }
11027: }
1.119 raeburn 11028:
1.168 raeburn 11029: my $servadm = $r->dir_config('lonAdmEMail');
11030: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
11031: if (ref($domconfig{'login'}) eq 'HASH') {
11032: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
11033: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
11034: if ($lang eq 'nolang') {
11035: push(@currlangs,$lang);
11036: } elsif (defined($langchoices{$lang})) {
11037: push(@currlangs,$lang);
11038: } else {
11039: next;
11040: }
11041: }
11042: }
11043: }
11044: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
11045: if (@currlangs > 0) {
11046: foreach my $lang (@currlangs) {
11047: if (grep(/^\Q$lang\E$/,@delurls)) {
11048: $changes{'helpurl'}{$lang} = 1;
11049: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
11050: $changes{'helpurl'}{$lang} = 1;
11051: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
11052: push(@newlangs,$lang);
11053: } else {
11054: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
11055: }
11056: }
11057: }
11058: unless (grep(/^nolang$/,@currlangs)) {
11059: if ($env{'form.loginhelpurl_nolang.filename'}) {
11060: $changes{'helpurl'}{'nolang'} = 1;
11061: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
11062: push(@newlangs,'nolang');
11063: }
11064: }
11065: if ($env{'form.loginhelpurl_add_lang'}) {
11066: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
11067: ($env{'form.loginhelpurl_add_file.filename'})) {
11068: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
11069: $addedfile = $env{'form.loginhelpurl_add_lang'};
11070: }
11071: }
11072: if ((@newlangs > 0) || ($addedfile)) {
11073: my $error;
11074: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11075: if ($configuserok eq 'ok') {
11076: if ($switchserver) {
11077: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
11078: } elsif ($author_ok eq 'ok') {
11079: my @allnew = @newlangs;
11080: if ($addedfile ne '') {
11081: push(@allnew,$addedfile);
11082: }
11083: foreach my $lang (@allnew) {
11084: my $formelem = 'loginhelpurl_'.$lang;
11085: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
11086: $formelem = 'loginhelpurl_add_file';
11087: }
11088: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
11089: "help/$lang",'','',$newfile{$lang});
11090: if ($result eq 'ok') {
11091: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
11092: $changes{'helpurl'}{$lang} = 1;
11093: } else {
11094: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
11095: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 11096: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 11097: (!grep(/^\Q$lang\E$/,@delurls))) {
11098: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
11099: }
11100: }
11101: }
11102: } else {
11103: $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);
11104: }
11105: } else {
11106: $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);
11107: }
11108: if ($error) {
11109: &Apache::lonnet::logthis($error);
11110: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11111: }
11112: }
1.256 raeburn 11113:
11114: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
11115: if (ref($domconfig{'login'}) eq 'HASH') {
11116: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
11117: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
11118: if ($domservers{$lonhost}) {
11119: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
11120: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 11121: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 11122: }
11123: }
11124: }
11125: }
11126: }
11127: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
11128: foreach my $lonhost (sort(keys(%domservers))) {
11129: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
11130: $changes{'headtag'}{$lonhost} = 1;
11131: } else {
11132: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
11133: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
11134: }
11135: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
11136: push(@newhosts,$lonhost);
11137: } elsif ($currheadtagurls{$lonhost}) {
11138: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
11139: if ($currexempt{$lonhost}) {
1.289 raeburn 11140: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 11141: $changes{'headtag'}{$lonhost} = 1;
11142: }
11143: } elsif ($possexempt{$lonhost}) {
11144: $changes{'headtag'}{$lonhost} = 1;
11145: }
11146: if ($possexempt{$lonhost}) {
11147: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
11148: }
11149: }
11150: }
11151: }
11152: if (@newhosts) {
11153: my $error;
11154: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11155: if ($configuserok eq 'ok') {
11156: if ($switchserver) {
11157: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
11158: } elsif ($author_ok eq 'ok') {
11159: foreach my $lonhost (@newhosts) {
11160: my $formelem = 'loginheadtag_'.$lonhost;
11161: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
11162: "login/headtag/$lonhost",'','',
11163: $env{'form.loginheadtag_'.$lonhost.'.filename'});
11164: if ($result eq 'ok') {
11165: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
11166: $changes{'headtag'}{$lonhost} = 1;
11167: if ($possexempt{$lonhost}) {
11168: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
11169: }
11170: } else {
11171: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
11172: $newheadtagurls{$lonhost},$result);
11173: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
11174: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
11175: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
11176: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
11177: }
11178: }
11179: }
11180: } else {
11181: $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);
11182: }
11183: } else {
11184: $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);
11185: }
11186: if ($error) {
11187: &Apache::lonnet::logthis($error);
11188: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11189: }
11190: }
1.169 raeburn 11191: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 11192:
11193: my $defaulthelpfile = '/adm/loginproblems.html';
11194: my $defaulttext = &mt('Default in use');
11195:
1.1 raeburn 11196: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
11197: $dom);
11198: if ($putresult eq 'ok') {
1.188 raeburn 11199: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 11200: my %defaultchecked = (
11201: 'coursecatalog' => 'on',
1.188 raeburn 11202: 'helpdesk' => 'on',
1.42 raeburn 11203: 'adminmail' => 'off',
1.43 raeburn 11204: 'newuser' => 'off',
1.42 raeburn 11205: );
1.55 raeburn 11206: if (ref($domconfig{'login'}) eq 'HASH') {
11207: foreach my $item (@toggles) {
11208: if ($defaultchecked{$item} eq 'on') {
11209: if (($domconfig{'login'}{$item} eq '0') &&
11210: ($env{'form.'.$item} eq '1')) {
11211: $changes{$item} = 1;
11212: } elsif (($domconfig{'login'}{$item} eq '' ||
11213: $domconfig{'login'}{$item} eq '1') &&
11214: ($env{'form.'.$item} eq '0')) {
11215: $changes{$item} = 1;
11216: }
11217: } elsif ($defaultchecked{$item} eq 'off') {
11218: if (($domconfig{'login'}{$item} eq '1') &&
11219: ($env{'form.'.$item} eq '0')) {
11220: $changes{$item} = 1;
11221: } elsif (($domconfig{'login'}{$item} eq '' ||
11222: $domconfig{'login'}{$item} eq '0') &&
11223: ($env{'form.'.$item} eq '1')) {
11224: $changes{$item} = 1;
11225: }
1.42 raeburn 11226: }
11227: }
1.41 raeburn 11228: }
1.6 raeburn 11229: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 11230: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 11231: if (ref($lastactref) eq 'HASH') {
11232: $lastactref->{'domainconfig'} = 1;
11233: }
1.1 raeburn 11234: $resulttext = &mt('Changes made:').'<ul>';
11235: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 11236: if ($item eq 'loginvia') {
1.112 raeburn 11237: if (ref($changes{$item}) eq 'HASH') {
11238: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
11239: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 11240: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
11241: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
11242: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
11243: $protocol = 'http' if ($protocol ne 'https');
11244: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
11245:
11246: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
11247: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
11248: } else {
11249: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
11250: }
11251: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
11252: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
11253: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
11254: }
11255: $resulttext .= '</li>';
11256: } else {
11257: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
11258: }
1.112 raeburn 11259: } else {
1.128 raeburn 11260: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 11261: }
11262: }
1.128 raeburn 11263: $resulttext .= '</ul></li>';
1.112 raeburn 11264: }
1.168 raeburn 11265: } elsif ($item eq 'helpurl') {
11266: if (ref($changes{$item}) eq 'HASH') {
11267: foreach my $lang (sort(keys(%{$changes{$item}}))) {
11268: if (grep(/^\Q$lang\E$/,@delurls)) {
11269: my ($chg,$link);
11270: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
11271: if ($lang eq 'nolang') {
11272: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
11273: } else {
11274: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
11275: }
11276: $resulttext .= '<li>'.$chg.'</li>';
11277: } else {
11278: my $chg;
11279: if ($lang eq 'nolang') {
11280: $chg = &mt('custom log-in help file for no preferred language');
11281: } else {
11282: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
11283: }
11284: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
11285: $loginhash{'login'}{'helpurl'}{$lang}.
11286: '?inhibitmenu=yes',$chg,600,500).
11287: '</li>';
11288: }
11289: }
11290: }
1.256 raeburn 11291: } elsif ($item eq 'headtag') {
11292: if (ref($changes{$item}) eq 'HASH') {
11293: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
11294: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
11295: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
11296: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
11297: $resulttext .= '<li><a href="'.
11298: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
11299: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
11300: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
11301: if ($possexempt{$lonhost}) {
11302: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
11303: } else {
11304: $resulttext .= &mt('included for any client IP');
11305: }
11306: $resulttext .= '</li>';
11307: }
11308: }
11309: }
1.169 raeburn 11310: } elsif ($item eq 'captcha') {
11311: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 11312: my $chgtxt;
1.169 raeburn 11313: if ($loginhash{'login'}{$item} eq 'notused') {
11314: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
11315: } else {
11316: my %captchas = &captcha_phrases();
11317: if ($captchas{$loginhash{'login'}{$item}}) {
11318: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
11319: } else {
11320: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
11321: }
11322: }
11323: $resulttext .= '<li>'.$chgtxt.'</li>';
11324: }
11325: } elsif ($item eq 'recaptchakeys') {
11326: if (ref($loginhash{'login'}) eq 'HASH') {
11327: my ($privkey,$pubkey);
11328: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
11329: $pubkey = $loginhash{'login'}{$item}{'public'};
11330: $privkey = $loginhash{'login'}{$item}{'private'};
11331: }
11332: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
11333: if (!$pubkey) {
11334: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
11335: } else {
11336: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
11337: }
11338: if (!$privkey) {
11339: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
11340: } else {
1.251 raeburn 11341: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 11342: }
11343: $chgtxt .= '</ul>';
11344: $resulttext .= '<li>'.$chgtxt.'</li>';
11345: }
1.269 raeburn 11346: } elsif ($item eq 'recaptchaversion') {
11347: if (ref($loginhash{'login'}) eq 'HASH') {
11348: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 11349: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 11350: '</li>';
11351: }
11352: }
1.41 raeburn 11353: } else {
11354: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
11355: }
1.1 raeburn 11356: }
1.6 raeburn 11357: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 11358: } else {
11359: $resulttext = &mt('No changes made to log-in page settings');
11360: }
11361: } else {
1.11 albertel 11362: $resulttext = '<span class="LC_error">'.
11363: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11364: }
1.6 raeburn 11365: if ($errors) {
1.9 raeburn 11366: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 11367: $errors.'</ul>';
11368: }
11369: return $resulttext;
11370: }
11371:
1.256 raeburn 11372: sub check_exempt_addresses {
11373: my ($iplist) = @_;
11374: $iplist =~ s/^\s+//;
11375: $iplist =~ s/\s+$//;
11376: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
11377: my (@okips,$new);
11378: foreach my $ip (@poss_ips) {
11379: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
11380: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
11381: push(@okips,$ip);
11382: }
11383: }
11384: }
11385: if (@okips > 0) {
11386: $new = join(',',@okips);
11387: } else {
11388: $new = '';
11389: }
11390: return $new;
11391: }
11392:
1.6 raeburn 11393: sub color_font_choices {
11394: my %choices =
11395: &Apache::lonlocal::texthash (
11396: img => "Header",
11397: bgs => "Background colors",
11398: links => "Link colors",
1.55 raeburn 11399: images => "Images",
1.6 raeburn 11400: font => "Font color",
1.201 raeburn 11401: fontmenu => "Font menu",
1.76 raeburn 11402: pgbg => "Page",
1.6 raeburn 11403: tabbg => "Header",
11404: sidebg => "Border",
11405: link => "Link",
11406: alink => "Active link",
11407: vlink => "Visited link",
11408: );
11409: return %choices;
11410: }
11411:
11412: sub modify_rolecolors {
1.205 raeburn 11413: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 11414: my ($resulttext,%rolehash);
11415: $rolehash{'rolecolors'} = {};
1.55 raeburn 11416: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
11417: if ($domconfig{'rolecolors'} eq '') {
11418: $domconfig{'rolecolors'} = {};
11419: }
11420: }
1.9 raeburn 11421: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 11422: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
11423: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
11424: $dom);
11425: if ($putresult eq 'ok') {
11426: if (keys(%changes) > 0) {
1.41 raeburn 11427: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 11428: if (ref($lastactref) eq 'HASH') {
11429: $lastactref->{'domainconfig'} = 1;
11430: }
1.6 raeburn 11431: $resulttext = &display_colorchgs($dom,\%changes,$roles,
11432: $rolehash{'rolecolors'});
11433: } else {
11434: $resulttext = &mt('No changes made to default color schemes');
11435: }
11436: } else {
1.11 albertel 11437: $resulttext = '<span class="LC_error">'.
11438: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 11439: }
11440: if ($errors) {
11441: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11442: $errors.'</ul>';
11443: }
11444: return $resulttext;
11445: }
11446:
11447: sub modify_colors {
1.9 raeburn 11448: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 11449: my (%changes,%choices);
1.51 raeburn 11450: my @bgs;
1.6 raeburn 11451: my @links = ('link','alink','vlink');
1.41 raeburn 11452: my @logintext;
1.6 raeburn 11453: my @images;
11454: my $servadm = $r->dir_config('lonAdmEMail');
11455: my $errors;
1.200 raeburn 11456: my %defaults;
1.6 raeburn 11457: foreach my $role (@{$roles}) {
11458: if ($role eq 'login') {
1.12 raeburn 11459: %choices = &login_choices();
1.41 raeburn 11460: @logintext = ('textcol','bgcol');
1.12 raeburn 11461: } else {
11462: %choices = &color_font_choices();
11463: }
11464: if ($role eq 'login') {
1.41 raeburn 11465: @images = ('img','logo','domlogo','login');
1.51 raeburn 11466: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 11467: } else {
11468: @images = ('img');
1.200 raeburn 11469: @bgs = ('pgbg','tabbg','sidebg');
11470: }
11471: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
11472: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
11473: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
11474: }
11475: if ($role eq 'login') {
11476: foreach my $item (@logintext) {
1.234 raeburn 11477: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
11478: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
11479: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
11480: }
11481: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 11482: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
11483: }
11484: }
11485: } else {
1.234 raeburn 11486: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
11487: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
11488: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
11489: }
11490: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 11491: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
11492: }
1.6 raeburn 11493: }
1.200 raeburn 11494: foreach my $item (@bgs) {
1.234 raeburn 11495: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
11496: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
11497: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
11498: }
11499: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 11500: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
11501: }
11502: }
11503: foreach my $item (@links) {
1.234 raeburn 11504: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
11505: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
11506: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
11507: }
11508: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 11509: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
11510: }
1.6 raeburn 11511: }
1.46 raeburn 11512: my ($configuserok,$author_ok,$switchserver) =
11513: &config_check($dom,$confname,$servadm);
1.9 raeburn 11514: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 11515: if (ref($domconfig->{$role}) ne 'HASH') {
11516: $domconfig->{$role} = {};
11517: }
1.8 raeburn 11518: foreach my $img (@images) {
1.70 raeburn 11519: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
11520: if (defined($env{'form.login_showlogo_'.$img})) {
11521: $confhash->{$role}{'showlogo'}{$img} = 1;
11522: } else {
11523: $confhash->{$role}{'showlogo'}{$img} = 0;
11524: }
11525: }
1.18 albertel 11526: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
11527: && !defined($domconfig->{$role}{$img})
11528: && !$env{'form.'.$role.'_del_'.$img}
11529: && $env{'form.'.$role.'_import_'.$img}) {
11530: # import the old configured image from the .tab setting
11531: # if they haven't provided a new one
11532: $domconfig->{$role}{$img} =
11533: $env{'form.'.$role.'_import_'.$img};
11534: }
1.6 raeburn 11535: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 11536: my $error;
1.6 raeburn 11537: if ($configuserok eq 'ok') {
1.9 raeburn 11538: if ($switchserver) {
1.12 raeburn 11539: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 11540: } else {
11541: if ($author_ok eq 'ok') {
11542: my ($result,$logourl) =
11543: &publishlogo($r,'upload',$role.'_'.$img,
11544: $dom,$confname,$img,$width,$height);
11545: if ($result eq 'ok') {
11546: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 11547: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 11548: } else {
1.12 raeburn 11549: $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 11550: }
11551: } else {
1.46 raeburn 11552: $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 11553: }
11554: }
11555: } else {
1.46 raeburn 11556: $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 11557: }
11558: if ($error) {
1.8 raeburn 11559: &Apache::lonnet::logthis($error);
1.11 albertel 11560: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 11561: }
11562: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 11563: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
11564: my $error;
11565: if ($configuserok eq 'ok') {
11566: # is confname an author?
11567: if ($switchserver eq '') {
11568: if ($author_ok eq 'ok') {
11569: my ($result,$logourl) =
11570: &publishlogo($r,'copy',$domconfig->{$role}{$img},
11571: $dom,$confname,$img,$width,$height);
11572: if ($result eq 'ok') {
11573: $confhash->{$role}{$img} = $logourl;
1.18 albertel 11574: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 11575: }
11576: }
11577: }
11578: }
1.6 raeburn 11579: }
11580: }
11581: }
11582: if (ref($domconfig) eq 'HASH') {
11583: if (ref($domconfig->{$role}) eq 'HASH') {
11584: foreach my $img (@images) {
11585: if ($domconfig->{$role}{$img} ne '') {
11586: if ($env{'form.'.$role.'_del_'.$img}) {
11587: $confhash->{$role}{$img} = '';
1.12 raeburn 11588: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 11589: } else {
1.9 raeburn 11590: if ($confhash->{$role}{$img} eq '') {
11591: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
11592: }
1.6 raeburn 11593: }
11594: } else {
11595: if ($env{'form.'.$role.'_del_'.$img}) {
11596: $confhash->{$role}{$img} = '';
1.12 raeburn 11597: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 11598: }
11599: }
1.70 raeburn 11600: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
11601: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
11602: if ($confhash->{$role}{'showlogo'}{$img} ne
11603: $domconfig->{$role}{'showlogo'}{$img}) {
11604: $changes{$role}{'showlogo'}{$img} = 1;
11605: }
11606: } else {
11607: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
11608: $changes{$role}{'showlogo'}{$img} = 1;
11609: }
11610: }
11611: }
11612: }
1.6 raeburn 11613: if ($domconfig->{$role}{'font'} ne '') {
11614: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
11615: $changes{$role}{'font'} = 1;
11616: }
11617: } else {
11618: if ($confhash->{$role}{'font'}) {
11619: $changes{$role}{'font'} = 1;
11620: }
11621: }
1.107 raeburn 11622: if ($role ne 'login') {
11623: if ($domconfig->{$role}{'fontmenu'} ne '') {
11624: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
11625: $changes{$role}{'fontmenu'} = 1;
11626: }
11627: } else {
11628: if ($confhash->{$role}{'fontmenu'}) {
11629: $changes{$role}{'fontmenu'} = 1;
11630: }
1.97 tempelho 11631: }
11632: }
1.6 raeburn 11633: foreach my $item (@bgs) {
11634: if ($domconfig->{$role}{$item} ne '') {
11635: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11636: $changes{$role}{'bgs'}{$item} = 1;
11637: }
11638: } else {
11639: if ($confhash->{$role}{$item}) {
11640: $changes{$role}{'bgs'}{$item} = 1;
11641: }
11642: }
11643: }
11644: foreach my $item (@links) {
11645: if ($domconfig->{$role}{$item} ne '') {
11646: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11647: $changes{$role}{'links'}{$item} = 1;
11648: }
11649: } else {
11650: if ($confhash->{$role}{$item}) {
11651: $changes{$role}{'links'}{$item} = 1;
11652: }
11653: }
11654: }
1.41 raeburn 11655: foreach my $item (@logintext) {
11656: if ($domconfig->{$role}{$item} ne '') {
11657: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11658: $changes{$role}{'logintext'}{$item} = 1;
11659: }
11660: } else {
11661: if ($confhash->{$role}{$item}) {
11662: $changes{$role}{'logintext'}{$item} = 1;
11663: }
11664: }
11665: }
1.6 raeburn 11666: } else {
11667: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 11668: \@logintext,$confhash,\%changes);
1.6 raeburn 11669: }
11670: } else {
11671: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 11672: \@logintext,$confhash,\%changes);
1.6 raeburn 11673: }
11674: }
11675: return ($errors,%changes);
11676: }
11677:
1.46 raeburn 11678: sub config_check {
11679: my ($dom,$confname,$servadm) = @_;
11680: my ($configuserok,$author_ok,$switchserver,%currroles);
11681: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
11682: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
11683: $confname,$servadm);
11684: if ($configuserok eq 'ok') {
11685: $switchserver = &check_switchserver($dom,$confname);
11686: if ($switchserver eq '') {
11687: $author_ok = &check_authorstatus($dom,$confname,%currroles);
11688: }
11689: }
11690: return ($configuserok,$author_ok,$switchserver);
11691: }
11692:
1.6 raeburn 11693: sub default_change_checker {
1.41 raeburn 11694: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 11695: foreach my $item (@{$links}) {
11696: if ($confhash->{$role}{$item}) {
11697: $changes->{$role}{'links'}{$item} = 1;
11698: }
11699: }
11700: foreach my $item (@{$bgs}) {
11701: if ($confhash->{$role}{$item}) {
11702: $changes->{$role}{'bgs'}{$item} = 1;
11703: }
11704: }
1.41 raeburn 11705: foreach my $item (@{$logintext}) {
11706: if ($confhash->{$role}{$item}) {
11707: $changes->{$role}{'logintext'}{$item} = 1;
11708: }
11709: }
1.6 raeburn 11710: foreach my $img (@{$images}) {
11711: if ($env{'form.'.$role.'_del_'.$img}) {
11712: $confhash->{$role}{$img} = '';
1.12 raeburn 11713: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 11714: }
1.70 raeburn 11715: if ($role eq 'login') {
11716: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
11717: $changes->{$role}{'showlogo'}{$img} = 1;
11718: }
11719: }
1.6 raeburn 11720: }
11721: if ($confhash->{$role}{'font'}) {
11722: $changes->{$role}{'font'} = 1;
11723: }
1.48 raeburn 11724: }
1.6 raeburn 11725:
11726: sub display_colorchgs {
11727: my ($dom,$changes,$roles,$confhash) = @_;
11728: my (%choices,$resulttext);
11729: if (!grep(/^login$/,@{$roles})) {
11730: $resulttext = &mt('Changes made:').'<br />';
11731: }
11732: foreach my $role (@{$roles}) {
11733: if ($role eq 'login') {
11734: %choices = &login_choices();
11735: } else {
11736: %choices = &color_font_choices();
11737: }
11738: if (ref($changes->{$role}) eq 'HASH') {
11739: if ($role ne 'login') {
11740: $resulttext .= '<h4>'.&mt($role).'</h4>';
11741: }
11742: foreach my $key (sort(keys(%{$changes->{$role}}))) {
11743: if ($role ne 'login') {
11744: $resulttext .= '<ul>';
11745: }
11746: if (ref($changes->{$role}{$key}) eq 'HASH') {
11747: if ($role ne 'login') {
11748: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
11749: }
11750: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 11751: if (($role eq 'login') && ($key eq 'showlogo')) {
11752: if ($confhash->{$role}{$key}{$item}) {
11753: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
11754: } else {
11755: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
11756: }
11757: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 11758: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
11759: } else {
1.12 raeburn 11760: my $newitem = $confhash->{$role}{$item};
11761: if ($key eq 'images') {
1.306 raeburn 11762: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 11763: }
11764: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 11765: }
11766: }
11767: if ($role ne 'login') {
11768: $resulttext .= '</ul></li>';
11769: }
11770: } else {
11771: if ($confhash->{$role}{$key} eq '') {
11772: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
11773: } else {
11774: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
11775: }
11776: }
11777: if ($role ne 'login') {
11778: $resulttext .= '</ul>';
11779: }
11780: }
11781: }
11782: }
1.3 raeburn 11783: return $resulttext;
1.1 raeburn 11784: }
11785:
1.9 raeburn 11786: sub thumb_dimensions {
11787: return ('200','50');
11788: }
11789:
1.16 raeburn 11790: sub check_dimensions {
11791: my ($inputfile) = @_;
11792: my ($fullwidth,$fullheight);
11793: if ($inputfile =~ m|^[/\w.\-]+$|) {
11794: if (open(PIPE,"identify $inputfile 2>&1 |")) {
11795: my $imageinfo = <PIPE>;
11796: if (!close(PIPE)) {
11797: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
11798: }
11799: chomp($imageinfo);
11800: my ($fullsize) =
1.21 raeburn 11801: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 11802: if ($fullsize) {
11803: ($fullwidth,$fullheight) = split(/x/,$fullsize);
11804: }
11805: }
11806: }
11807: return ($fullwidth,$fullheight);
11808: }
11809:
1.9 raeburn 11810: sub check_configuser {
11811: my ($uhome,$dom,$confname,$servadm) = @_;
11812: my ($configuserok,%currroles);
11813: if ($uhome eq 'no_host') {
11814: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 11815: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 11816: $configuserok =
11817: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
11818: $configpass,'','','','','',undef,$servadm);
11819: } else {
11820: $configuserok = 'ok';
11821: %currroles =
11822: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
11823: }
11824: return ($configuserok,%currroles);
11825: }
11826:
11827: sub check_authorstatus {
11828: my ($dom,$confname,%currroles) = @_;
11829: my $author_ok;
1.40 raeburn 11830: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 11831: my $start = time;
11832: my $end = 0;
11833: $author_ok =
11834: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 11835: 'au',$end,$start,'','','domconfig');
1.9 raeburn 11836: } else {
11837: $author_ok = 'ok';
11838: }
11839: return $author_ok;
11840: }
11841:
11842: sub publishlogo {
1.46 raeburn 11843: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 11844: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 11845: if ($action eq 'upload') {
11846: $fname=$env{'form.'.$formname.'.filename'};
11847: chop($env{'form.'.$formname});
11848: } else {
11849: ($fname) = ($formname =~ /([^\/]+)$/);
11850: }
1.46 raeburn 11851: if ($savefileas ne '') {
11852: $fname = $savefileas;
11853: }
1.9 raeburn 11854: $fname=&Apache::lonnet::clean_filename($fname);
11855: # See if there is anything left
11856: unless ($fname) { return ('error: no uploaded file'); }
11857: $fname="$subdir/$fname";
1.210 raeburn 11858: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 11859: my $filepath="$docroot/priv";
11860: my $relpath = "$dom/$confname";
1.9 raeburn 11861: my ($fnamepath,$file,$fetchthumb);
11862: $file=$fname;
11863: if ($fname=~m|/|) {
11864: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
11865: }
1.164 raeburn 11866: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 11867: my $count;
1.164 raeburn 11868: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 11869: $filepath.="/$parts[$count]";
11870: if ((-e $filepath)!=1) {
11871: mkdir($filepath,02770);
11872: }
11873: }
11874: # Check for bad extension and disallow upload
11875: if ($file=~/\.(\w+)$/ &&
11876: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
11877: $output =
1.207 bisitz 11878: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 11879: } elsif ($file=~/\.(\w+)$/ &&
11880: !defined(&Apache::loncommon::fileembstyle($1))) {
11881: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
11882: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 11883: $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 11884: } elsif (-d "$filepath/$file") {
1.195 bisitz 11885: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 11886: } else {
11887: my $source = $filepath.'/'.$file;
11888: my $logfile;
1.316 raeburn 11889: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 11890: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 11891: }
11892: print $logfile
11893: "\n================= Publish ".localtime()." ================\n".
11894: $env{'user.name'}.':'.$env{'user.domain'}."\n";
11895: # Save the file
1.316 raeburn 11896: if (!open(FH,">",$source)) {
1.9 raeburn 11897: &Apache::lonnet::logthis('Failed to create '.$source);
11898: return (&mt('Failed to create file'));
11899: }
11900: if ($action eq 'upload') {
11901: if (!print FH ($env{'form.'.$formname})) {
11902: &Apache::lonnet::logthis('Failed to write to '.$source);
11903: return (&mt('Failed to write file'));
11904: }
11905: } else {
11906: my $original = &Apache::lonnet::filelocation('',$formname);
11907: if(!copy($original,$source)) {
11908: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
11909: return (&mt('Failed to write file'));
11910: }
11911: }
11912: close(FH);
11913: chmod(0660, $source); # Permissions to rw-rw---.
11914:
11915: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
11916: my $copyfile=$targetdir.'/'.$file;
11917:
11918: my @parts=split(/\//,$targetdir);
11919: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
11920: for (my $count=5;$count<=$#parts;$count++) {
11921: $path.="/$parts[$count]";
11922: if (!-e $path) {
11923: print $logfile "\nCreating directory ".$path;
11924: mkdir($path,02770);
11925: }
11926: }
11927: my $versionresult;
11928: if (-e $copyfile) {
11929: $versionresult = &logo_versioning($targetdir,$file,$logfile);
11930: } else {
11931: $versionresult = 'ok';
11932: }
11933: if ($versionresult eq 'ok') {
11934: if (copy($source,$copyfile)) {
11935: print $logfile "\nCopied original source to ".$copyfile."\n";
11936: $output = 'ok';
11937: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 11938: push(@{$modified_urls},[$copyfile,$source]);
11939: my $metaoutput =
11940: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
11941: unless ($registered_cleanup) {
11942: my $handlers = $r->get_handlers('PerlCleanupHandler');
11943: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
11944: $registered_cleanup=1;
11945: }
1.9 raeburn 11946: } else {
11947: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
11948: $output = &mt('Failed to copy file to RES space').", $!";
11949: }
11950: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
11951: my $inputfile = $filepath.'/'.$file;
11952: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 11953: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
11954: if ($fullwidth ne '' && $fullheight ne '') {
11955: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
11956: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 11957: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
11958: system({$args[0]} @args);
1.16 raeburn 11959: chmod(0660, $filepath.'/tn-'.$file);
11960: if (-e $outfile) {
11961: my $copyfile=$targetdir.'/tn-'.$file;
11962: if (copy($outfile,$copyfile)) {
11963: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 11964: my $thumb_metaoutput =
11965: &write_metadata($dom,$confname,$formname,
11966: $targetdir,'tn-'.$file,$logfile);
11967: push(@{$modified_urls},[$copyfile,$outfile]);
11968: unless ($registered_cleanup) {
11969: my $handlers = $r->get_handlers('PerlCleanupHandler');
11970: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
11971: $registered_cleanup=1;
11972: }
1.267 raeburn 11973: $madethumb = 1;
1.16 raeburn 11974: } else {
11975: print $logfile "\nUnable to write ".$copyfile.
11976: ':'.$!."\n";
11977: }
11978: }
1.9 raeburn 11979: }
11980: }
11981: }
11982: } else {
11983: $output = $versionresult;
11984: }
11985: }
1.267 raeburn 11986: return ($output,$logourl,$madethumb);
1.9 raeburn 11987: }
11988:
11989: sub logo_versioning {
11990: my ($targetdir,$file,$logfile) = @_;
11991: my $target = $targetdir.'/'.$file;
11992: my ($maxversion,$fn,$extn,$output);
11993: $maxversion = 0;
11994: if ($file =~ /^(.+)\.(\w+)$/) {
11995: $fn=$1;
11996: $extn=$2;
11997: }
11998: opendir(DIR,$targetdir);
11999: while (my $filename=readdir(DIR)) {
12000: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
12001: $maxversion=($1>$maxversion)?$1:$maxversion;
12002: }
12003: }
12004: $maxversion++;
12005: print $logfile "\nCreating old version ".$maxversion."\n";
12006: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
12007: if (copy($target,$copyfile)) {
12008: print $logfile "Copied old target to ".$copyfile."\n";
12009: $copyfile=$copyfile.'.meta';
12010: if (copy($target.'.meta',$copyfile)) {
12011: print $logfile "Copied old target metadata to ".$copyfile."\n";
12012: $output = 'ok';
12013: } else {
12014: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
12015: $output = &mt('Failed to copy old meta').", $!, ";
12016: }
12017: } else {
12018: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
12019: $output = &mt('Failed to copy old target').", $!, ";
12020: }
12021: return $output;
12022: }
12023:
12024: sub write_metadata {
12025: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
12026: my (%metadatafields,%metadatakeys,$output);
12027: $metadatafields{'title'}=$formname;
12028: $metadatafields{'creationdate'}=time;
12029: $metadatafields{'lastrevisiondate'}=time;
12030: $metadatafields{'copyright'}='public';
12031: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
12032: $env{'user.domain'};
12033: $metadatafields{'authorspace'}=$confname.':'.$dom;
12034: $metadatafields{'domain'}=$dom;
12035: {
12036: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
12037: my $mfh;
1.316 raeburn 12038: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 12039: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 12040: unless ($_=~/\./) {
12041: my $unikey=$_;
12042: $unikey=~/^([A-Za-z]+)/;
12043: my $tag=$1;
12044: $tag=~tr/A-Z/a-z/;
12045: print $mfh "\n\<$tag";
12046: foreach (split(/\,/,$metadatakeys{$unikey})) {
12047: my $value=$metadatafields{$unikey.'.'.$_};
12048: $value=~s/\"/\'\'/g;
12049: print $mfh ' '.$_.'="'.$value.'"';
12050: }
12051: print $mfh '>'.
12052: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
12053: .'</'.$tag.'>';
12054: }
12055: }
12056: $output = 'ok';
12057: print $logfile "\nWrote metadata";
12058: close($mfh);
12059: } else {
12060: print $logfile "\nFailed to open metadata file";
1.9 raeburn 12061: $output = &mt('Could not write metadata');
12062: }
12063: }
1.155 raeburn 12064: return $output;
12065: }
12066:
12067: sub notifysubscribed {
12068: foreach my $targetsource (@{$modified_urls}){
12069: next unless (ref($targetsource) eq 'ARRAY');
12070: my ($target,$source)=@{$targetsource};
12071: if ($source ne '') {
1.316 raeburn 12072: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 12073: print $logfh "\nCleanup phase: Notifications\n";
12074: my @subscribed=&subscribed_hosts($target);
12075: foreach my $subhost (@subscribed) {
12076: print $logfh "\nNotifying host ".$subhost.':';
12077: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
12078: print $logfh $reply;
12079: }
12080: my @subscribedmeta=&subscribed_hosts("$target.meta");
12081: foreach my $subhost (@subscribedmeta) {
12082: print $logfh "\nNotifying host for metadata only ".$subhost.':';
12083: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
12084: $subhost);
12085: print $logfh $reply;
12086: }
12087: print $logfh "\n============ Done ============\n";
1.160 raeburn 12088: close($logfh);
1.155 raeburn 12089: }
12090: }
12091: }
12092: return OK;
12093: }
12094:
12095: sub subscribed_hosts {
12096: my ($target) = @_;
12097: my @subscribed;
1.316 raeburn 12098: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 12099: while (my $subline=<$fh>) {
12100: if ($subline =~ /^($match_lonid):/) {
12101: my $host = $1;
12102: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
12103: unless (grep(/^\Q$host\E$/,@subscribed)) {
12104: push(@subscribed,$host);
12105: }
12106: }
12107: }
12108: }
12109: }
12110: return @subscribed;
1.9 raeburn 12111: }
12112:
12113: sub check_switchserver {
12114: my ($dom,$confname) = @_;
12115: my ($allowed,$switchserver);
12116: my $home = &Apache::lonnet::homeserver($confname,$dom);
12117: if ($home eq 'no_host') {
12118: $home = &Apache::lonnet::domain($dom,'primary');
12119: }
12120: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 12121: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
12122: if (!$allowed) {
1.180 raeburn 12123: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 12124: }
12125: return $switchserver;
12126: }
12127:
1.1 raeburn 12128: sub modify_quotas {
1.216 raeburn 12129: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 12130: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 12131: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 12132: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
12133: $validationfieldsref);
1.86 raeburn 12134: if ($action eq 'quotas') {
12135: $context = 'tools';
1.163 raeburn 12136: } else {
1.86 raeburn 12137: $context = $action;
12138: }
12139: if ($context eq 'requestcourses') {
1.325 raeburn 12140: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 12141: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 12142: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
12143: %titles = &courserequest_titles();
12144: $toolregexp = join('|',@usertools);
12145: %conditions = &courserequest_conditions();
1.216 raeburn 12146: $confname = $dom.'-domainconfig';
12147: my $servadm = $r->dir_config('lonAdmEMail');
12148: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 12149: ($validationitemsref,$validationnamesref,$validationfieldsref) =
12150: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 12151: } elsif ($context eq 'requestauthor') {
12152: @usertools = ('author');
12153: %titles = &authorrequest_titles();
1.86 raeburn 12154: } else {
1.162 raeburn 12155: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 12156: %titles = &tool_titles();
1.86 raeburn 12157: }
1.212 raeburn 12158: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 12159: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 12160: foreach my $key (keys(%env)) {
1.101 raeburn 12161: if ($context eq 'requestcourses') {
12162: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
12163: my $item = $1;
12164: my $type = $2;
12165: if ($type =~ /^limit_(.+)/) {
12166: $limithash{$item}{$1} = $env{$key};
12167: } else {
12168: $confhash{$item}{$type} = $env{$key};
12169: }
12170: }
1.163 raeburn 12171: } elsif ($context eq 'requestauthor') {
12172: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
12173: $confhash{$1} = $env{$key};
12174: }
1.101 raeburn 12175: } else {
1.86 raeburn 12176: if ($key =~ /^form\.quota_(.+)$/) {
12177: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 12178: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
12179: $confhash{'authorquota'}{$1} = $env{$key};
12180: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 12181: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
12182: }
1.72 raeburn 12183: }
12184: }
1.163 raeburn 12185: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 12186: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 12187: @approvalnotify = sort(@approvalnotify);
12188: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 12189: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 12190: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
12191: foreach my $type (@hasuniquecode) {
12192: if (grep(/^\Q$type\E$/,@crstypes)) {
12193: $confhash{'uniquecode'}{$type} = 1;
12194: }
1.216 raeburn 12195: }
1.242 raeburn 12196: my (%newbook,%allpos);
1.216 raeburn 12197: if ($context eq 'requestcourses') {
1.242 raeburn 12198: foreach my $type ('textbooks','templates') {
12199: @{$allpos{$type}} = ();
12200: my $invalid;
12201: if ($type eq 'textbooks') {
12202: $invalid = &mt('Invalid LON-CAPA course for textbook');
12203: } else {
12204: $invalid = &mt('Invalid LON-CAPA course for template');
12205: }
12206: if ($env{'form.'.$type.'_addbook'}) {
12207: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
12208: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
12209: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
12210: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
12211: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
12212: } else {
12213: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
12214: my $position = $env{'form.'.$type.'_addbook_pos'};
12215: $position =~ s/\D+//g;
12216: if ($position ne '') {
12217: $allpos{$type}[$position] = $newbook{$type};
12218: }
1.216 raeburn 12219: }
1.242 raeburn 12220: } else {
12221: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 12222: }
12223: }
1.242 raeburn 12224: }
1.216 raeburn 12225: }
1.102 raeburn 12226: if (ref($domconfig{$action}) eq 'HASH') {
12227: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
12228: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
12229: $changes{'notify'}{'approval'} = 1;
12230: }
12231: } else {
1.144 raeburn 12232: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 12233: $changes{'notify'}{'approval'} = 1;
12234: }
12235: }
1.218 raeburn 12236: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
12237: if (ref($confhash{'uniquecode'}) eq 'HASH') {
12238: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
12239: unless ($confhash{'uniquecode'}{$crstype}) {
12240: $changes{'uniquecode'} = 1;
12241: }
12242: }
12243: unless ($changes{'uniquecode'}) {
12244: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
12245: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
12246: $changes{'uniquecode'} = 1;
12247: }
12248: }
12249: }
12250: } else {
12251: $changes{'uniquecode'} = 1;
12252: }
12253: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
12254: $changes{'uniquecode'} = 1;
1.216 raeburn 12255: }
12256: if ($context eq 'requestcourses') {
1.242 raeburn 12257: foreach my $type ('textbooks','templates') {
12258: if (ref($domconfig{$action}{$type}) eq 'HASH') {
12259: my %deletions;
12260: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
12261: if (@todelete) {
12262: map { $deletions{$_} = 1; } @todelete;
12263: }
12264: my %imgdeletions;
12265: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
12266: if (@todeleteimages) {
12267: map { $imgdeletions{$_} = 1; } @todeleteimages;
12268: }
12269: my $maxnum = $env{'form.'.$type.'_maxnum'};
12270: for (my $i=0; $i<=$maxnum; $i++) {
12271: my $itemid = $env{'form.'.$type.'_id_'.$i};
12272: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
12273: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
12274: if ($deletions{$key}) {
12275: if ($domconfig{$action}{$type}{$key}{'image'}) {
12276: #FIXME need to obsolete item in RES space
12277: }
12278: next;
12279: } else {
12280: my $newpos = $env{'form.'.$itemid};
12281: $newpos =~ s/\D+//g;
1.243 raeburn 12282: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 12283: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 12284: ($type eq 'templates'));
1.242 raeburn 12285: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
12286: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
12287: $changes{$type}{$key} = 1;
12288: }
12289: }
12290: $allpos{$type}[$newpos] = $key;
12291: }
12292: if ($imgdeletions{$key}) {
12293: $changes{$type}{$key} = 1;
1.216 raeburn 12294: #FIXME need to obsolete item in RES space
1.242 raeburn 12295: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
12296: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 12297: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
12298: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
12299: } else {
12300: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
12301: $cdom,$cnum,$type,$configuserok,
12302: $switchserver,$author_ok);
12303: if ($imgurl) {
12304: $confhash{$type}{$key}{'image'} = $imgurl;
12305: $changes{$type}{$key} = 1;
12306: }
12307: if ($error) {
12308: &Apache::lonnet::logthis($error);
12309: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12310: }
12311: }
1.242 raeburn 12312: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
12313: $confhash{$type}{$key}{'image'} =
12314: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 12315: }
12316: }
12317: }
12318: }
12319: }
12320: }
1.102 raeburn 12321: } else {
1.144 raeburn 12322: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 12323: $changes{'notify'}{'approval'} = 1;
12324: }
1.218 raeburn 12325: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 12326: $changes{'uniquecode'} = 1;
12327: }
12328: }
12329: if ($context eq 'requestcourses') {
1.242 raeburn 12330: foreach my $type ('textbooks','templates') {
12331: if ($newbook{$type}) {
12332: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 12333: foreach my $item ('subject','title','publisher','author') {
12334: next if ((($item eq 'author') || ($item eq 'publisher')) &&
12335: ($type eq 'template'));
1.242 raeburn 12336: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
12337: if ($env{'form.'.$type.'_addbook_'.$item}) {
12338: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
12339: }
12340: }
12341: if ($type eq 'textbooks') {
12342: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
12343: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 12344: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
12345: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
12346: } else {
12347: my ($imageurl,$error) =
12348: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
12349: $configuserok,$switchserver,$author_ok);
12350: if ($imageurl) {
12351: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
12352: }
12353: if ($error) {
12354: &Apache::lonnet::logthis($error);
12355: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12356: }
1.242 raeburn 12357: }
12358: }
1.216 raeburn 12359: }
12360: }
1.242 raeburn 12361: if (@{$allpos{$type}} > 0) {
12362: my $idx = 0;
12363: foreach my $item (@{$allpos{$type}}) {
12364: if ($item ne '') {
12365: $confhash{$type}{$item}{'order'} = $idx;
12366: if (ref($domconfig{$action}) eq 'HASH') {
12367: if (ref($domconfig{$action}{$type}) eq 'HASH') {
12368: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
12369: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
12370: $changes{$type}{$item} = 1;
12371: }
1.216 raeburn 12372: }
12373: }
12374: }
1.242 raeburn 12375: $idx ++;
1.216 raeburn 12376: }
12377: }
12378: }
12379: }
1.235 raeburn 12380: if (ref($validationitemsref) eq 'ARRAY') {
12381: foreach my $item (@{$validationitemsref}) {
12382: if ($item eq 'fields') {
12383: my @changed;
12384: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
12385: if (@{$confhash{'validation'}{$item}} > 0) {
12386: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
12387: }
1.266 raeburn 12388: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12389: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12390: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
12391: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
12392: $domconfig{'requestcourses'}{'validation'}{$item});
12393: } else {
12394: @changed = @{$confhash{'validation'}{$item}};
12395: }
1.235 raeburn 12396: } else {
12397: @changed = @{$confhash{'validation'}{$item}};
12398: }
12399: } else {
12400: @changed = @{$confhash{'validation'}{$item}};
12401: }
12402: if (@changed) {
12403: if ($confhash{'validation'}{$item}) {
12404: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
12405: } else {
12406: $changes{'validation'}{$item} = &mt('None');
12407: }
12408: }
12409: } else {
12410: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
12411: if ($item eq 'markup') {
12412: if ($env{'form.requestcourses_validation_'.$item}) {
12413: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
12414: }
12415: }
1.266 raeburn 12416: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12417: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12418: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
12419: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
12420: }
12421: } else {
12422: if ($confhash{'validation'}{$item} ne '') {
12423: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
12424: }
1.235 raeburn 12425: }
12426: } else {
12427: if ($confhash{'validation'}{$item} ne '') {
12428: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
12429: }
12430: }
12431: }
12432: }
12433: }
12434: if ($env{'form.validationdc'}) {
12435: my $newval = $env{'form.validationdc'};
1.285 raeburn 12436: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 12437: if (exists($domcoords{$newval})) {
12438: $confhash{'validation'}{'dc'} = $newval;
12439: }
12440: }
12441: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 12442: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12443: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12444: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
12445: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
12446: if ($confhash{'validation'}{'dc'} eq '') {
12447: $changes{'validation'}{'dc'} = &mt('None');
12448: } else {
12449: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
12450: }
1.235 raeburn 12451: }
1.266 raeburn 12452: } elsif ($confhash{'validation'}{'dc'} ne '') {
12453: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 12454: }
12455: } elsif ($confhash{'validation'}{'dc'} ne '') {
12456: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
12457: }
12458: } elsif ($confhash{'validation'}{'dc'} ne '') {
12459: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 12460: }
1.266 raeburn 12461: } else {
12462: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12463: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12464: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
12465: $changes{'validation'}{'dc'} = &mt('None');
12466: }
12467: }
1.235 raeburn 12468: }
12469: }
1.102 raeburn 12470: }
12471: } else {
1.86 raeburn 12472: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 12473: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 12474: }
1.72 raeburn 12475: foreach my $item (@usertools) {
12476: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 12477: my $unset;
1.101 raeburn 12478: if ($context eq 'requestcourses') {
1.104 raeburn 12479: $unset = '0';
12480: if ($type eq '_LC_adv') {
12481: $unset = '';
12482: }
1.101 raeburn 12483: if ($confhash{$item}{$type} eq 'autolimit') {
12484: $confhash{$item}{$type} .= '=';
12485: unless ($limithash{$item}{$type} =~ /\D/) {
12486: $confhash{$item}{$type} .= $limithash{$item}{$type};
12487: }
12488: }
1.163 raeburn 12489: } elsif ($context eq 'requestauthor') {
12490: $unset = '0';
12491: if ($type eq '_LC_adv') {
12492: $unset = '';
12493: }
1.72 raeburn 12494: } else {
1.101 raeburn 12495: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
12496: $confhash{$item}{$type} = 1;
12497: } else {
12498: $confhash{$item}{$type} = 0;
12499: }
1.72 raeburn 12500: }
1.86 raeburn 12501: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 12502: if ($action eq 'requestauthor') {
12503: if ($domconfig{$action}{$type} ne $confhash{$type}) {
12504: $changes{$type} = 1;
12505: }
12506: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 12507: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
12508: $changes{$item}{$type} = 1;
12509: }
12510: } else {
12511: if ($context eq 'requestcourses') {
1.104 raeburn 12512: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 12513: $changes{$item}{$type} = 1;
12514: }
12515: } else {
12516: if (!$confhash{$item}{$type}) {
12517: $changes{$item}{$type} = 1;
12518: }
12519: }
12520: }
12521: } else {
12522: if ($context eq 'requestcourses') {
1.104 raeburn 12523: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 12524: $changes{$item}{$type} = 1;
12525: }
1.163 raeburn 12526: } elsif ($context eq 'requestauthor') {
12527: if ($confhash{$type} ne $unset) {
12528: $changes{$type} = 1;
12529: }
1.72 raeburn 12530: } else {
12531: if (!$confhash{$item}{$type}) {
12532: $changes{$item}{$type} = 1;
12533: }
12534: }
12535: }
1.1 raeburn 12536: }
12537: }
1.163 raeburn 12538: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 12539: if (ref($domconfig{'quotas'}) eq 'HASH') {
12540: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
12541: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
12542: if (exists($confhash{'defaultquota'}{$key})) {
12543: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
12544: $changes{'defaultquota'}{$key} = 1;
12545: }
12546: } else {
12547: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 12548: }
12549: }
1.86 raeburn 12550: } else {
12551: foreach my $key (keys(%{$domconfig{'quotas'}})) {
12552: if (exists($confhash{'defaultquota'}{$key})) {
12553: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
12554: $changes{'defaultquota'}{$key} = 1;
12555: }
12556: } else {
12557: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 12558: }
1.1 raeburn 12559: }
12560: }
1.197 raeburn 12561: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
12562: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
12563: if (exists($confhash{'authorquota'}{$key})) {
12564: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
12565: $changes{'authorquota'}{$key} = 1;
12566: }
12567: } else {
12568: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
12569: }
12570: }
12571: }
1.1 raeburn 12572: }
1.86 raeburn 12573: if (ref($confhash{'defaultquota'}) eq 'HASH') {
12574: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
12575: if (ref($domconfig{'quotas'}) eq 'HASH') {
12576: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
12577: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
12578: $changes{'defaultquota'}{$key} = 1;
12579: }
12580: } else {
12581: if (!exists($domconfig{'quotas'}{$key})) {
12582: $changes{'defaultquota'}{$key} = 1;
12583: }
1.72 raeburn 12584: }
12585: } else {
1.86 raeburn 12586: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 12587: }
1.1 raeburn 12588: }
12589: }
1.197 raeburn 12590: if (ref($confhash{'authorquota'}) eq 'HASH') {
12591: foreach my $key (keys(%{$confhash{'authorquota'}})) {
12592: if (ref($domconfig{'quotas'}) eq 'HASH') {
12593: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
12594: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
12595: $changes{'authorquota'}{$key} = 1;
12596: }
12597: } else {
12598: $changes{'authorquota'}{$key} = 1;
12599: }
12600: } else {
12601: $changes{'authorquota'}{$key} = 1;
12602: }
12603: }
12604: }
1.1 raeburn 12605: }
1.72 raeburn 12606:
1.163 raeburn 12607: if ($context eq 'requestauthor') {
12608: $domdefaults{'requestauthor'} = \%confhash;
12609: } else {
12610: foreach my $key (keys(%confhash)) {
1.242 raeburn 12611: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 12612: $domdefaults{$key} = $confhash{$key};
12613: }
1.163 raeburn 12614: }
1.72 raeburn 12615: }
1.163 raeburn 12616:
1.1 raeburn 12617: my %quotahash = (
1.86 raeburn 12618: $action => { %confhash }
1.1 raeburn 12619: );
12620: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
12621: $dom);
12622: if ($putresult eq 'ok') {
12623: if (keys(%changes) > 0) {
1.72 raeburn 12624: my $cachetime = 24*60*60;
12625: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 12626: if (ref($lastactref) eq 'HASH') {
12627: $lastactref->{'domdefaults'} = 1;
12628: }
1.1 raeburn 12629: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 12630: unless (($context eq 'requestcourses') ||
1.163 raeburn 12631: ($context eq 'requestauthor')) {
1.86 raeburn 12632: if (ref($changes{'defaultquota'}) eq 'HASH') {
12633: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
12634: foreach my $type (@{$types},'default') {
12635: if (defined($changes{'defaultquota'}{$type})) {
12636: my $typetitle = $usertypes->{$type};
12637: if ($type eq 'default') {
12638: $typetitle = $othertitle;
12639: }
1.213 raeburn 12640: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 12641: }
12642: }
1.86 raeburn 12643: $resulttext .= '</ul></li>';
1.72 raeburn 12644: }
1.197 raeburn 12645: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 12646: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 12647: foreach my $type (@{$types},'default') {
12648: if (defined($changes{'authorquota'}{$type})) {
12649: my $typetitle = $usertypes->{$type};
12650: if ($type eq 'default') {
12651: $typetitle = $othertitle;
12652: }
1.213 raeburn 12653: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 12654: }
12655: }
12656: $resulttext .= '</ul></li>';
12657: }
1.72 raeburn 12658: }
1.80 raeburn 12659: my %newenv;
1.72 raeburn 12660: foreach my $item (@usertools) {
1.163 raeburn 12661: my (%haschgs,%inconf);
12662: if ($context eq 'requestauthor') {
12663: %haschgs = %changes;
1.210 raeburn 12664: %inconf = %confhash;
1.163 raeburn 12665: } else {
12666: if (ref($changes{$item}) eq 'HASH') {
12667: %haschgs = %{$changes{$item}};
12668: }
12669: if (ref($confhash{$item}) eq 'HASH') {
12670: %inconf = %{$confhash{$item}};
12671: }
12672: }
12673: if (keys(%haschgs) > 0) {
1.80 raeburn 12674: my $newacc =
12675: &Apache::lonnet::usertools_access($env{'user.name'},
12676: $env{'user.domain'},
1.86 raeburn 12677: $item,'reload',$context);
1.210 raeburn 12678: if (($context eq 'requestcourses') ||
1.163 raeburn 12679: ($context eq 'requestauthor')) {
1.108 raeburn 12680: if ($env{'environment.canrequest.'.$item} ne $newacc) {
12681: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 12682: }
12683: } else {
12684: if ($env{'environment.availabletools.'.$item} ne $newacc) {
12685: $newenv{'environment.availabletools.'.$item} = $newacc;
12686: }
1.80 raeburn 12687: }
1.163 raeburn 12688: unless ($context eq 'requestauthor') {
12689: $resulttext .= '<li>'.$titles{$item}.'<ul>';
12690: }
1.72 raeburn 12691: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 12692: if ($haschgs{$type}) {
1.72 raeburn 12693: my $typetitle = $usertypes->{$type};
12694: if ($type eq 'default') {
12695: $typetitle = $othertitle;
12696: } elsif ($type eq '_LC_adv') {
12697: $typetitle = 'LON-CAPA Advanced Users';
12698: }
1.163 raeburn 12699: if ($inconf{$type}) {
1.101 raeburn 12700: if ($context eq 'requestcourses') {
12701: my $cond;
1.163 raeburn 12702: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 12703: if ($1 eq '') {
12704: $cond = &mt('(Automatic processing of any request).');
12705: } else {
12706: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
12707: }
12708: } else {
1.163 raeburn 12709: $cond = $conditions{$inconf{$type}};
1.101 raeburn 12710: }
12711: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 12712: } elsif ($context eq 'requestauthor') {
12713: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
12714: $titles{$inconf{$type}},$typetitle);
12715:
1.101 raeburn 12716: } else {
12717: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
12718: }
1.72 raeburn 12719: } else {
1.104 raeburn 12720: if ($type eq '_LC_adv') {
1.163 raeburn 12721: if ($inconf{$type} eq '0') {
1.104 raeburn 12722: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
12723: } else {
12724: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
12725: }
12726: } else {
12727: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
12728: }
1.72 raeburn 12729: }
12730: }
1.26 raeburn 12731: }
1.163 raeburn 12732: unless ($context eq 'requestauthor') {
12733: $resulttext .= '</ul></li>';
12734: }
1.26 raeburn 12735: }
1.1 raeburn 12736: }
1.163 raeburn 12737: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 12738: if (ref($changes{'notify'}) eq 'HASH') {
12739: if ($changes{'notify'}{'approval'}) {
12740: if (ref($confhash{'notify'}) eq 'HASH') {
12741: if ($confhash{'notify'}{'approval'}) {
12742: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
12743: } else {
1.163 raeburn 12744: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 12745: }
12746: }
12747: }
12748: }
12749: }
1.216 raeburn 12750: if ($action eq 'requestcourses') {
12751: my @offon = ('off','on');
12752: if ($changes{'uniquecode'}) {
1.218 raeburn 12753: if (ref($confhash{'uniquecode'}) eq 'HASH') {
12754: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
12755: $resulttext .= '<li>'.
12756: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
12757: '</li>';
12758: } else {
12759: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
12760: '</li>';
12761: }
1.216 raeburn 12762: }
1.242 raeburn 12763: foreach my $type ('textbooks','templates') {
12764: if (ref($changes{$type}) eq 'HASH') {
12765: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
12766: foreach my $key (sort(keys(%{$changes{$type}}))) {
12767: my %coursehash = &Apache::lonnet::coursedescription($key);
12768: my $coursetitle = $coursehash{'description'};
12769: my $position = $confhash{$type}{$key}{'order'} + 1;
12770: $resulttext .= '<li>';
1.243 raeburn 12771: foreach my $item ('subject','title','publisher','author') {
12772: next if ((($item eq 'author') || ($item eq 'publisher')) &&
12773: ($type eq 'templates'));
1.242 raeburn 12774: my $name = $item.':';
12775: $name =~ s/^(\w)/\U$1/;
12776: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
12777: }
12778: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
12779: if ($type eq 'textbooks') {
12780: if ($confhash{$type}{$key}{'image'}) {
12781: $resulttext .= ' '.&mt('Image: [_1]',
12782: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
12783: ' alt="Textbook cover" />').'<br />';
12784: }
12785: }
12786: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 12787: }
1.242 raeburn 12788: $resulttext .= '</ul></li>';
1.216 raeburn 12789: }
12790: }
1.235 raeburn 12791: if (ref($changes{'validation'}) eq 'HASH') {
12792: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
12793: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
12794: foreach my $item (@{$validationitemsref}) {
12795: if (exists($changes{'validation'}{$item})) {
12796: if ($item eq 'markup') {
12797: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
12798: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
12799: } else {
12800: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
12801: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
12802: }
12803: }
12804: }
12805: if (exists($changes{'validation'}{'dc'})) {
12806: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
12807: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
12808: }
12809: }
12810: }
1.216 raeburn 12811: }
1.1 raeburn 12812: $resulttext .= '</ul>';
1.80 raeburn 12813: if (keys(%newenv)) {
12814: &Apache::lonnet::appenv(\%newenv);
12815: }
1.1 raeburn 12816: } else {
1.86 raeburn 12817: if ($context eq 'requestcourses') {
12818: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 12819: } elsif ($context eq 'requestauthor') {
12820: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 12821: } else {
1.90 weissno 12822: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 12823: }
1.1 raeburn 12824: }
12825: } else {
1.11 albertel 12826: $resulttext = '<span class="LC_error">'.
12827: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12828: }
1.216 raeburn 12829: if ($errors) {
12830: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
12831: '<ul>'.$errors.'</ul></p>';
12832: }
1.3 raeburn 12833: return $resulttext;
1.1 raeburn 12834: }
12835:
1.216 raeburn 12836: sub process_textbook_image {
1.242 raeburn 12837: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 12838: my $filename = $env{'form.'.$caller.'.filename'};
12839: my ($error,$url);
12840: my ($width,$height) = (50,50);
12841: if ($configuserok eq 'ok') {
12842: if ($switchserver) {
12843: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
12844: $switchserver);
12845: } elsif ($author_ok eq 'ok') {
12846: my ($result,$imageurl) =
12847: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 12848: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 12849: if ($result eq 'ok') {
12850: $url = $imageurl;
12851: } else {
12852: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
12853: }
12854: } else {
12855: $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);
12856: }
12857: } else {
12858: $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);
12859: }
12860: return ($url,$error);
12861: }
12862:
1.267 raeburn 12863: sub modify_ltitools {
12864: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
12865: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 12866: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 12867: my $confname = $dom.'-domainconfig';
12868: my $servadm = $r->dir_config('lonAdmEMail');
12869: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12870: my (%posslti,%possfield);
12871: my @courseroles = ('cc','in','ta','ep','st');
12872: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
12873: map { $posslti{$_} = 1; } @ltiroles;
12874: my @allfields = ('fullname','firstname','lastname','email','user','roles');
12875: map { $possfield{$_} = 1; } @allfields;
12876: my %lt = <itools_names();
12877: if ($env{'form.ltitools_add'}) {
12878: my $title = $env{'form.ltitools_add_title'};
12879: $title =~ s/(`)/'/g;
12880: ($newid,my $error) = &get_ltitools_id($dom,$title);
12881: if ($newid) {
12882: my $position = $env{'form.ltitools_add_pos'};
12883: $position =~ s/\D+//g;
12884: if ($position ne '') {
12885: $allpos[$position] = $newid;
12886: }
12887: $changes{$newid} = 1;
1.322 raeburn 12888: foreach my $item ('title','url','key','secret','lifetime') {
1.267 raeburn 12889: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322 raeburn 12890: if ($item eq 'lifetime') {
12891: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
12892: }
1.267 raeburn 12893: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 12894: if (($item eq 'key') || ($item eq 'secret')) {
12895: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
12896: } else {
12897: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
12898: }
1.267 raeburn 12899: }
12900: }
12901: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
12902: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
12903: }
12904: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
12905: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
12906: }
1.323 raeburn 12907: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
12908: $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
12909: } else {
12910: $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
12911: }
1.296 raeburn 12912: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 12913: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
12914: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 12915: if (($item eq 'width') || ($item eq 'height')) {
12916: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
12917: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
12918: }
12919: } else {
12920: if ($env{'form.ltitools_add_'.$item} ne '') {
12921: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
12922: }
1.267 raeburn 12923: }
12924: }
12925: if ($env{'form.ltitools_add_target'} eq 'window') {
12926: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 12927: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
12928: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 12929: } else {
12930: $confhash{$newid}{'display'}{'target'} = 'iframe';
12931: }
12932: foreach my $item ('passback','roster') {
1.319 raeburn 12933: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 12934: $confhash{$newid}{$item} = 1;
1.319 raeburn 12935: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
12936: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
12937: $lifetime =~ s/^\s+|\s+$//g;
12938: if ($lifetime =~ /^\d+\.?\d*$/) {
12939: $confhash{$newid}{$item.'valid'} = $lifetime;
12940: }
12941: }
1.267 raeburn 12942: }
12943: }
12944: if ($env{'form.ltitools_add_image.filename'} ne '') {
12945: my ($imageurl,$error) =
1.307 raeburn 12946: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 12947: $configuserok,$switchserver,$author_ok);
12948: if ($imageurl) {
12949: $confhash{$newid}{'image'} = $imageurl;
12950: }
12951: if ($error) {
12952: &Apache::lonnet::logthis($error);
12953: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12954: }
12955: }
12956: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
12957: foreach my $field (@fields) {
12958: if ($possfield{$field}) {
12959: if ($field eq 'roles') {
12960: foreach my $role (@courseroles) {
12961: my $choice = $env{'form.ltitools_add_roles_'.$role};
12962: if (($choice ne '') && ($posslti{$choice})) {
12963: $confhash{$newid}{'roles'}{$role} = $choice;
12964: if ($role eq 'cc') {
12965: $confhash{$newid}{'roles'}{'co'} = $choice;
12966: }
12967: }
12968: }
12969: } else {
12970: $confhash{$newid}{'fields'}{$field} = 1;
12971: }
12972: }
12973: }
1.324 raeburn 12974: if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
12975: if ($confhash{$newid}{'fields'}{'user'}) {
12976: if ($env{'form.ltitools_userincdom_add'}) {
12977: $confhash{$newid}{'incdom'} = 1;
12978: }
12979: }
12980: }
1.273 raeburn 12981: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
12982: foreach my $item (@courseconfig) {
12983: $confhash{$newid}{'crsconf'}{$item} = 1;
12984: }
1.267 raeburn 12985: if ($env{'form.ltitools_add_custom'}) {
12986: my $name = $env{'form.ltitools_add_custom_name'};
12987: my $value = $env{'form.ltitools_add_custom_value'};
12988: $value =~ s/(`)/'/g;
12989: $name =~ s/(`)/'/g;
12990: $confhash{$newid}{'custom'}{$name} = $value;
12991: }
12992: } else {
12993: my $error = &mt('Failed to acquire unique ID for new external tool');
12994: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12995: }
12996: }
12997: if (ref($domconfig{$action}) eq 'HASH') {
12998: my %deletions;
12999: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
13000: if (@todelete) {
13001: map { $deletions{$_} = 1; } @todelete;
13002: }
13003: my %customadds;
13004: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
13005: if (@newcustom) {
13006: map { $customadds{$_} = 1; } @newcustom;
13007: }
13008: my %imgdeletions;
13009: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
13010: if (@todeleteimages) {
13011: map { $imgdeletions{$_} = 1; } @todeleteimages;
13012: }
13013: my $maxnum = $env{'form.ltitools_maxnum'};
13014: for (my $i=0; $i<=$maxnum; $i++) {
13015: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 13016: $itemid =~ s/\D+//g;
1.267 raeburn 13017: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
13018: if ($deletions{$itemid}) {
13019: if ($domconfig{$action}{$itemid}{'image'}) {
13020: #FIXME need to obsolete item in RES space
13021: }
13022: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
13023: next;
13024: } else {
13025: my $newpos = $env{'form.ltitools_'.$itemid};
13026: $newpos =~ s/\D+//g;
1.322 raeburn 13027: foreach my $item ('title','url','lifetime') {
1.267 raeburn 13028: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
13029: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
13030: $changes{$itemid} = 1;
13031: }
13032: }
1.297 raeburn 13033: foreach my $item ('key','secret') {
13034: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
13035: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
13036: $changes{$itemid} = 1;
13037: }
13038: }
1.267 raeburn 13039: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
13040: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
13041: }
13042: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
13043: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
13044: }
1.323 raeburn 13045: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
13046: $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
13047: } else {
13048: $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
13049: }
13050: if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
13051: if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
13052: $changes{$itemid} = 1;
13053: }
13054: } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
13055: $changes{$itemid} = 1;
13056: }
1.267 raeburn 13057: foreach my $size ('width','height') {
13058: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
13059: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
13060: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
13061: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
13062: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13063: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
13064: $changes{$itemid} = 1;
13065: }
13066: } else {
13067: $changes{$itemid} = 1;
13068: }
1.296 raeburn 13069: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13070: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
13071: $changes{$itemid} = 1;
13072: }
13073: }
13074: }
13075: foreach my $item ('linktext','explanation') {
13076: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
13077: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
13078: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
13079: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
13080: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13081: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
13082: $changes{$itemid} = 1;
13083: }
13084: } else {
13085: $changes{$itemid} = 1;
13086: }
13087: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13088: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
13089: $changes{$itemid} = 1;
13090: }
1.267 raeburn 13091: }
13092: }
13093: if ($env{'form.ltitools_target_'.$i} eq 'window') {
13094: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 13095: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
13096: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 13097: } else {
13098: $confhash{$itemid}{'display'}{'target'} = 'iframe';
13099: }
13100: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13101: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
13102: $changes{$itemid} = 1;
13103: }
13104: } else {
13105: $changes{$itemid} = 1;
13106: }
13107: foreach my $extra ('passback','roster') {
13108: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
13109: $confhash{$itemid}{$extra} = 1;
1.319 raeburn 13110: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
1.338 raeburn 13111: my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
1.319 raeburn 13112: $lifetime =~ s/^\s+|\s+$//g;
13113: if ($lifetime =~ /^\d+\.?\d*$/) {
13114: $confhash{$itemid}{$extra.'valid'} = $lifetime;
13115: }
13116: }
1.267 raeburn 13117: }
13118: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
13119: $changes{$itemid} = 1;
13120: }
1.319 raeburn 13121: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
13122: $changes{$itemid} = 1;
13123: }
1.267 raeburn 13124: }
1.273 raeburn 13125: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 13126: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 13127: if (grep(/^\Q$item\E$/,@courseconfig)) {
13128: $confhash{$itemid}{'crsconf'}{$item} = 1;
13129: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
13130: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
13131: $changes{$itemid} = 1;
13132: }
13133: } else {
13134: $changes{$itemid} = 1;
13135: }
13136: }
13137: }
1.267 raeburn 13138: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
13139: foreach my $field (@fields) {
13140: if ($possfield{$field}) {
13141: if ($field eq 'roles') {
13142: foreach my $role (@courseroles) {
13143: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
13144: if (($choice ne '') && ($posslti{$choice})) {
13145: $confhash{$itemid}{'roles'}{$role} = $choice;
13146: if ($role eq 'cc') {
13147: $confhash{$itemid}{'roles'}{'co'} = $choice;
13148: }
13149: }
13150: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
13151: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
13152: $changes{$itemid} = 1;
13153: }
13154: } elsif ($confhash{$itemid}{'roles'}{$role}) {
13155: $changes{$itemid} = 1;
13156: }
13157: }
13158: } else {
13159: $confhash{$itemid}{'fields'}{$field} = 1;
13160: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
13161: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
13162: $changes{$itemid} = 1;
13163: }
13164: } else {
13165: $changes{$itemid} = 1;
13166: }
13167: }
13168: }
13169: }
1.324 raeburn 13170: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
13171: if ($confhash{$itemid}{'fields'}{'user'}) {
13172: if ($env{'form.ltitools_userincdom_'.$i}) {
13173: $confhash{$itemid}{'incdom'} = 1;
13174: }
13175: if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
13176: $changes{$itemid} = 1;
13177: }
13178: }
13179: }
1.267 raeburn 13180: $allpos[$newpos] = $itemid;
13181: }
13182: if ($imgdeletions{$itemid}) {
13183: $changes{$itemid} = 1;
13184: #FIXME need to obsolete item in RES space
13185: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
13186: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
13187: $itemid,$configuserok,$switchserver,
13188: $author_ok);
13189: if ($imgurl) {
13190: $confhash{$itemid}{'image'} = $imgurl;
13191: $changes{$itemid} = 1;
13192: }
13193: if ($error) {
13194: &Apache::lonnet::logthis($error);
13195: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13196: }
13197: } elsif ($domconfig{$action}{$itemid}{'image'}) {
13198: $confhash{$itemid}{'image'} =
13199: $domconfig{$action}{$itemid}{'image'};
13200: }
13201: if ($customadds{$i}) {
13202: my $name = $env{'form.ltitools_custom_name_'.$i};
13203: $name =~ s/(`)/'/g;
13204: $name =~ s/^\s+//;
13205: $name =~ s/\s+$//;
13206: my $value = $env{'form.ltitools_custom_value_'.$i};
13207: $value =~ s/(`)/'/g;
13208: $value =~ s/^\s+//;
13209: $value =~ s/\s+$//;
13210: if ($name ne '') {
13211: $confhash{$itemid}{'custom'}{$name} = $value;
13212: $changes{$itemid} = 1;
13213: }
13214: }
13215: my %customdels;
13216: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
13217: if (@customdeletions) {
13218: $changes{$itemid} = 1;
13219: }
13220: map { $customdels{$_} = 1; } @customdeletions;
13221: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
13222: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
13223: unless ($customdels{$key}) {
13224: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
13225: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
13226: }
13227: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
13228: $changes{$itemid} = 1;
13229: }
13230: }
13231: }
13232: }
13233: unless ($changes{$itemid}) {
13234: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
13235: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
13236: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
13237: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
13238: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
13239: $changes{$itemid} = 1;
13240: last;
13241: }
13242: }
13243: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
13244: $changes{$itemid} = 1;
13245: }
13246: }
13247: last if ($changes{$itemid});
13248: }
13249: }
13250: }
13251: }
13252: }
13253: if (@allpos > 0) {
13254: my $idx = 0;
13255: foreach my $itemid (@allpos) {
13256: if ($itemid ne '') {
13257: $confhash{$itemid}{'order'} = $idx;
13258: if (ref($domconfig{$action}) eq 'HASH') {
13259: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
13260: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
13261: $changes{$itemid} = 1;
13262: }
13263: }
13264: }
13265: $idx ++;
13266: }
13267: }
13268: }
13269: my %ltitoolshash = (
13270: $action => { %confhash }
13271: );
13272: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
13273: $dom);
13274: if ($putresult eq 'ok') {
1.297 raeburn 13275: my %ltienchash = (
13276: $action => { %encconfig }
13277: );
13278: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267 raeburn 13279: if (keys(%changes) > 0) {
13280: my $cachetime = 24*60*60;
1.297 raeburn 13281: my %ltiall = %confhash;
13282: foreach my $id (keys(%ltiall)) {
13283: if (ref($encconfig{$id}) eq 'HASH') {
13284: foreach my $item ('key','secret') {
13285: $ltiall{$id}{$item} = $encconfig{$id}{$item};
13286: }
13287: }
13288: }
13289: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 13290: if (ref($lastactref) eq 'HASH') {
13291: $lastactref->{'ltitools'} = 1;
13292: }
13293: $resulttext = &mt('Changes made:').'<ul>';
13294: my %bynum;
13295: foreach my $itemid (sort(keys(%changes))) {
13296: my $position = $confhash{$itemid}{'order'};
13297: $bynum{$position} = $itemid;
13298: }
13299: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13300: my $itemid = $bynum{$pos};
13301: if (ref($confhash{$itemid}) ne 'HASH') {
13302: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
13303: } else {
13304: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
13305: if ($confhash{$itemid}{'image'}) {
13306: $resulttext .= ' '.
13307: '<img src="'.$confhash{$itemid}{'image'}.'"'.
13308: ' alt="'.&mt('Tool Provider icon').'" />';
13309: }
13310: $resulttext .= '</li><ul>';
13311: my $position = $pos + 1;
13312: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323 raeburn 13313: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267 raeburn 13314: if ($confhash{$itemid}{$item} ne '') {
13315: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
13316: }
13317: }
1.297 raeburn 13318: if ($encconfig{$itemid}{'key'} ne '') {
13319: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
13320: }
13321: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 13322: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 13323: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 13324: $resulttext .= ('*'x$num).'</li>';
13325: }
1.273 raeburn 13326: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 13327: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 13328: my $numconfig = 0;
13329: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
13330: foreach my $item (@possconfig) {
13331: if ($confhash{$itemid}{'crsconf'}{$item}) {
13332: $numconfig ++;
1.296 raeburn 13333: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 13334: }
13335: }
13336: }
13337: if (!$numconfig) {
1.372 raeburn 13338: $resulttext .= ' '.&mt('None');
1.273 raeburn 13339: }
13340: $resulttext .= '</li>';
1.267 raeburn 13341: foreach my $item ('passback','roster') {
13342: $resulttext .= '<li>'.$lt{$item}.' ';
13343: if ($confhash{$itemid}{$item}) {
13344: $resulttext .= &mt('Yes');
1.319 raeburn 13345: if ($confhash{$itemid}{$item.'valid'}) {
13346: if ($item eq 'passback') {
13347: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
13348: $confhash{$itemid}{$item.'valid'});
13349: } else {
13350: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
13351: $confhash{$itemid}{$item.'valid'});
13352: }
13353: }
1.267 raeburn 13354: } else {
13355: $resulttext .= &mt('No');
13356: }
13357: $resulttext .= '</li>';
13358: }
13359: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
13360: my $displaylist;
13361: if ($confhash{$itemid}{'display'}{'target'}) {
13362: $displaylist = &mt('Display target').': '.
13363: $confhash{$itemid}{'display'}{'target'}.',';
13364: }
13365: foreach my $size ('width','height') {
13366: if ($confhash{$itemid}{'display'}{$size}) {
13367: $displaylist .= (' 'x2).$lt{$size}.': '.
13368: $confhash{$itemid}{'display'}{$size}.',';
13369: }
13370: }
13371: if ($displaylist) {
13372: $displaylist =~ s/,$//;
13373: $resulttext .= '<li>'.$displaylist.'</li>';
13374: }
1.296 raeburn 13375: foreach my $item ('linktext','explanation') {
13376: if ($confhash{$itemid}{'display'}{$item}) {
13377: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
13378: }
13379: }
13380: }
1.267 raeburn 13381: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
13382: my $fieldlist;
13383: foreach my $field (@allfields) {
13384: if ($confhash{$itemid}{'fields'}{$field}) {
13385: $fieldlist .= (' 'x2).$lt{$field}.',';
13386: }
13387: }
13388: if ($fieldlist) {
13389: $fieldlist =~ s/,$//;
1.324 raeburn 13390: if ($confhash{$itemid}{'fields'}{'user'}) {
13391: if ($confhash{$itemid}{'incdom'}) {
13392: $fieldlist .= ' ('.&mt('username:domain').')';
13393: } else {
13394: $fieldlist .= ' ('.&mt('username').')';
13395: }
13396: }
1.267 raeburn 13397: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
13398: }
13399: }
13400: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
13401: my $rolemaps;
13402: foreach my $role (@courseroles) {
13403: if ($confhash{$itemid}{'roles'}{$role}) {
13404: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
13405: $confhash{$itemid}{'roles'}{$role}.',';
13406: }
13407: }
13408: if ($rolemaps) {
13409: $rolemaps =~ s/,$//;
13410: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
13411: }
13412: }
13413: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
13414: my $customlist;
13415: if (keys(%{$confhash{$itemid}{'custom'}})) {
13416: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
13417: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
13418: }
13419: }
13420: if ($customlist) {
1.317 raeburn 13421: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 13422: }
13423: }
13424: $resulttext .= '</ul></li>';
13425: }
13426: }
13427: $resulttext .= '</ul>';
13428: } else {
13429: $resulttext = &mt('No changes made.');
13430: }
13431: } else {
13432: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13433: }
13434: if ($errors) {
13435: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13436: $errors.'</ul>';
13437: }
13438: return $resulttext;
13439: }
13440:
13441: sub process_ltitools_image {
13442: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
13443: my $filename = $env{'form.'.$caller.'.filename'};
13444: my ($error,$url);
13445: my ($width,$height) = (21,21);
13446: if ($configuserok eq 'ok') {
13447: if ($switchserver) {
13448: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
13449: $switchserver);
13450: } elsif ($author_ok eq 'ok') {
13451: my ($result,$imageurl,$madethumb) =
13452: &publishlogo($r,'upload',$caller,$dom,$confname,
13453: "ltitools/$itemid/icon",$width,$height);
13454: if ($result eq 'ok') {
13455: if ($madethumb) {
13456: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
13457: my $imagethumb = "$path/tn-".$imagefile;
13458: $url = $imagethumb;
13459: } else {
13460: $url = $imageurl;
13461: }
13462: } else {
13463: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
13464: }
13465: } else {
13466: $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);
13467: }
13468: } else {
13469: $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);
13470: }
13471: return ($url,$error);
13472: }
13473:
13474: sub get_ltitools_id {
13475: my ($cdom,$title) = @_;
13476: # get lock on ltitools db
13477: my $lockhash = {
13478: lock => $env{'user.name'}.
13479: ':'.$env{'user.domain'},
13480: };
13481: my $tries = 0;
13482: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
13483: my ($id,$error);
13484:
13485: while (($gotlock ne 'ok') && ($tries<10)) {
13486: $tries ++;
13487: sleep (0.1);
13488: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
13489: }
13490: if ($gotlock eq 'ok') {
13491: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
13492: if ($currids{'lock'}) {
13493: delete($currids{'lock'});
13494: if (keys(%currids)) {
13495: my @curr = sort { $a <=> $b } keys(%currids);
13496: if ($curr[-1] =~ /^\d+$/) {
13497: $id = 1 + $curr[-1];
13498: }
13499: } else {
13500: $id = 1;
13501: }
13502: if ($id) {
13503: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
13504: $error = 'nostore';
13505: }
13506: } else {
13507: $error = 'nonumber';
13508: }
13509: }
13510: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
13511: } else {
13512: $error = 'nolock';
13513: }
13514: return ($id,$error);
13515: }
13516:
1.372 raeburn 13517: sub modify_proctoring {
13518: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
13519: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13520: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
13521: my $confname = $dom.'-domainconfig';
13522: my $servadm = $r->dir_config('lonAdmEMail');
13523: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
13524: my %providernames = &proctoring_providernames();
13525: my $maxnum = scalar(keys(%providernames));
13526:
13527: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
13528: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
13529: if (ref($requref) eq 'HASH') {
13530: %requserfields = %{$requref};
13531: }
13532: if (ref($opturef) eq 'HASH') {
13533: %optuserfields = %{$opturef};
13534: }
13535: if (ref($defref) eq 'HASH') {
13536: %defaults = %{$defref};
13537: }
13538: if (ref($extref) eq 'HASH') {
13539: %extended = %{$extref};
13540: }
13541: if (ref($crsref) eq 'HASH') {
13542: %crsconf = %{$crsref};
13543: }
13544: if (ref($rolesref) eq 'ARRAY') {
13545: @courseroles = @{$rolesref};
13546: }
13547: if (ref($ltiref) eq 'ARRAY') {
13548: @ltiroles = @{$ltiref};
13549: }
13550:
13551: if (ref($domconfig{$action}) eq 'HASH') {
13552: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
13553: if (@todeleteimages) {
13554: map { $imgdeletions{$_} = 1; } @todeleteimages;
13555: }
13556: }
13557: my %customadds;
13558: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
13559: if (@newcustom) {
13560: map { $customadds{$_} = 1; } @newcustom;
13561: }
13562: foreach my $provider (sort(keys(%providernames))) {
13563: $confhash{$provider} = {};
13564: my $pos = $env{'form.proctoring_pos_'.$provider};
13565: $pos =~ s/\D+//g;
13566: $allpos[$pos] = $provider;
13567: my (%current,%currentenc);
13568: my $showroles = 0;
13569: if (ref($domconfig{$action}) eq 'HASH') {
13570: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
13571: %current = %{$domconfig{$action}{$provider}};
13572: foreach my $item ('key','secret') {
13573: $currentenc{$item} = $current{$item};
13574: delete($current{$item});
13575: }
13576: }
13577: }
13578: if ($env{'form.proctoring_available_'.$provider}) {
13579: $confhash{$provider}{'available'} = 1;
13580: unless ($current{'available'}) {
13581: $changes{$provider} = 1;
13582: }
13583: } else {
13584: %{$confhash{$provider}} = %current;
13585: %{$encconfhash{$provider}} = %currentenc;
13586: $confhash{$provider}{'available'} = 0;
13587: if ($current{'available'}) {
13588: $changes{$provider} = 1;
13589: }
13590: }
13591: if ($confhash{$provider}{'available'}) {
13592: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
13593: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
13594: if ($field eq 'lifetime') {
13595: if ($possval =~ /^\d+$/) {
13596: $confhash{$provider}{$field} = $possval;
13597: }
13598: } elsif ($field eq 'version') {
13599: if ($possval =~ /^\d+\.\d+$/) {
13600: $confhash{$provider}{$field} = $possval;
13601: }
13602: } elsif ($field eq 'sigmethod') {
13603: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
13604: $confhash{$provider}{$field} = $possval;
13605: }
13606: } elsif ($field eq 'url') {
13607: $confhash{$provider}{$field} = $possval;
13608: } elsif (($field eq 'key') || ($field eq 'secret')) {
13609: $encconfhash{$provider}{$field} = $possval;
13610: unless ($currentenc{$field} eq $possval) {
13611: $changes{$provider} = 1;
13612: }
13613: }
13614: unless (($field eq 'key') || ($field eq 'secret')) {
13615: unless ($current{$field} eq $confhash{$provider}{$field}) {
13616: $changes{$provider} = 1;
13617: }
13618: }
13619: }
13620: if ($imgdeletions{$provider}) {
13621: $changes{$provider} = 1;
13622: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
13623: my ($imageurl,$error) =
13624: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
13625: $configuserok,$switchserver,$author_ok);
13626: if ($imageurl) {
13627: $confhash{$provider}{'image'} = $imageurl;
13628: $changes{$provider} = 1;
13629: }
13630: if ($error) {
13631: &Apache::lonnet::logthis($error);
13632: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13633: }
13634: } elsif (exists($current{'image'})) {
13635: $confhash{$provider}{'image'} = $current{'image'};
13636: }
13637: if (ref($requserfields{$provider}) eq 'ARRAY') {
13638: if (@{$requserfields{$provider}} > 0) {
13639: if (grep(/^user$/,@{$requserfields{$provider}})) {
13640: if ($env{'form.proctoring_userincdom_'.$provider}) {
13641: $confhash{$provider}{'incdom'} = 1;
13642: }
13643: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
13644: $changes{$provider} = 1;
13645: }
13646: }
13647: if (grep(/^roles$/,@{$requserfields{$provider}})) {
13648: $showroles = 1;
13649: }
13650: }
13651: }
13652: $confhash{$provider}{'fields'} = [];
13653: if (ref($optuserfields{$provider}) eq 'ARRAY') {
13654: if (@{$optuserfields{$provider}} > 0) {
13655: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
13656: foreach my $field (@{$optuserfields{$provider}}) {
13657: if (grep(/^\Q$field\E$/,@optfields)) {
13658: push(@{$confhash{$provider}{'fields'}},$field);
13659: }
13660: }
13661: }
13662: if (ref($current{'fields'}) eq 'ARRAY') {
13663: unless ($changes{$provider}) {
13664: my @new = sort(@{$confhash{$provider}{'fields'}});
13665: my @old = sort(@{$current{'fields'}});
13666: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
13667: if (@diffs) {
13668: $changes{$provider} = 1;
13669: }
13670: }
13671: } elsif (@{$confhash{$provider}{'fields'}}) {
13672: $changes{$provider} = 1;
13673: }
13674: }
13675: if (ref($defaults{$provider}) eq 'ARRAY') {
13676: if (@{$defaults{$provider}} > 0) {
13677: my %options;
13678: if (ref($extended{$provider}) eq 'HASH') {
13679: %options = %{$extended{$provider}};
13680: }
13681: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
13682: foreach my $field (@{$defaults{$provider}}) {
13683: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
13684: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
13685: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
13686: push(@{$confhash{$provider}{'defaults'}},$poss);
13687: }
13688: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
13689: foreach my $inner (keys(%{$options{$field}})) {
13690: if (ref($options{$field}{$inner}) eq 'ARRAY') {
13691: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
13692: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
13693: $confhash{$provider}{'defaults'}{$inner} = $poss;
13694: }
13695: } else {
13696: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
13697: }
13698: }
13699: } else {
13700: if (grep(/^\Q$field\E$/,@checked)) {
13701: push(@{$confhash{$provider}{'defaults'}},$field);
13702: }
13703: }
13704: }
13705: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
13706: if (ref($current{'defaults'}) eq 'ARRAY') {
13707: unless ($changes{$provider}) {
13708: my @new = sort(@{$confhash{$provider}{'defaults'}});
13709: my @old = sort(@{$current{'defaults'}});
13710: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
13711: if (@diffs) {
13712: $changes{$provider} = 1;
13713: }
13714: }
13715: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
13716: if (@{$current{'defaults'}}) {
13717: $changes{$provider} = 1;
13718: }
13719: }
13720: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
13721: if (ref($current{'defaults'}) eq 'HASH') {
13722: unless ($changes{$provider}) {
13723: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
13724: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
13725: $changes{$provider} = 1;
13726: last;
13727: }
13728: }
13729: }
13730: unless ($changes{$provider}) {
13731: foreach my $key (keys(%{$current{'defaults'}})) {
13732: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
13733: $changes{$provider} = 1;
13734: last;
13735: }
13736: }
13737: }
13738: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
13739: $changes{$provider} = 1;
13740: }
13741: }
13742: }
13743: }
13744: if (ref($crsconf{$provider}) eq 'ARRAY') {
13745: if (@{$crsconf{$provider}} > 0) {
13746: $confhash{$provider}{'crsconf'} = [];
13747: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
13748: foreach my $crsfield (@{$crsconf{$provider}}) {
13749: if (grep(/^\Q$crsfield\E$/,@checked)) {
13750: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
13751: }
13752: }
13753: if (ref($current{'crsconf'}) eq 'ARRAY') {
13754: unless ($changes{$provider}) {
13755: my @new = sort(@{$confhash{$provider}{'crsconf'}});
13756: my @old = sort(@{$current{'crsconf'}});
13757: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
13758: if (@diffs) {
13759: $changes{$provider} = 1;
13760: }
13761: }
13762: } elsif (@{$confhash{$provider}{'crsconf'}}) {
13763: $changes{$provider} = 1;
13764: }
13765: }
13766: }
13767: if ($showroles) {
13768: $confhash{$provider}{'roles'} = {};
13769: foreach my $role (@courseroles) {
13770: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
13771: if (grep(/^\Q$poss\E$/,@ltiroles)) {
13772: $confhash{$provider}{'roles'}{$role} = $poss;
13773: }
13774: }
13775: unless ($changes{$provider}) {
13776: if (ref($current{'roles'}) eq 'HASH') {
13777: foreach my $role (keys(%{$current{'roles'}})) {
13778: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
13779: $changes{$provider} = 1;
13780: last
13781: }
13782: }
13783: unless ($changes{$provider}) {
13784: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
13785: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
13786: $changes{$provider} = 1;
13787: last;
13788: }
13789: }
13790: }
13791: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
13792: $changes{$provider} = 1;
13793: }
13794: }
13795: }
13796: if (ref($current{'custom'}) eq 'HASH') {
13797: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
13798: foreach my $key (keys(%{$current{'custom'}})) {
13799: if (grep(/^\Q$key\E$/,@customdels)) {
13800: $changes{$provider} = 1;
13801: } else {
13802: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
13803: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
13804: $changes{$provider} = 1;
13805: }
13806: }
13807: }
13808: }
13809: if ($customadds{$provider}) {
13810: my $name = $env{'form.proctoring_custom_name_'.$provider};
13811: $name =~ s/(`)/'/g;
13812: $name =~ s/^\s+//;
13813: $name =~ s/\s+$//;
13814: my $value = $env{'form.proctoring_custom_value_'.$provider};
13815: $value =~ s/(`)/'/g;
13816: $value =~ s/^\s+//;
13817: $value =~ s/\s+$//;
13818: if ($name ne '') {
13819: $confhash{$provider}{'custom'}{$name} = $value;
13820: $changes{$provider} = 1;
13821: }
13822: }
13823: }
13824: }
13825: if (@allpos > 0) {
13826: my $idx = 0;
13827: foreach my $provider (@allpos) {
13828: if ($provider ne '') {
13829: $confhash{$provider}{'order'} = $idx;
13830: unless ($changes{$provider}) {
13831: if (ref($domconfig{$action}) eq 'HASH') {
13832: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
13833: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
13834: $changes{$provider} = 1;
13835: }
13836: }
13837: }
13838: }
13839: $idx ++;
13840: }
13841: }
13842: }
13843: my %proc_hash = (
13844: $action => { %confhash }
13845: );
13846: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
13847: $dom);
13848: if ($putresult eq 'ok') {
13849: my %proc_enchash = (
13850: $action => { %encconfhash }
13851: );
13852: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom);
13853: if (keys(%changes) > 0) {
13854: my $cachetime = 24*60*60;
13855: my %procall = %confhash;
13856: foreach my $provider (keys(%procall)) {
13857: if (ref($encconfhash{$provider}) eq 'HASH') {
13858: foreach my $key ('key','secret') {
13859: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
13860: }
13861: }
13862: }
13863: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
13864: if (ref($lastactref) eq 'HASH') {
13865: $lastactref->{'proctoring'} = 1;
13866: }
13867: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
13868: my %bynum;
13869: foreach my $provider (sort(keys(%changes))) {
13870: my $position = $confhash{$provider}{'order'};
13871: $bynum{$position} = $provider;
13872: }
13873: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13874: my $provider = $bynum{$pos};
13875: my %lt = &proctoring_titles($provider);
13876: my %fieldtitles = &proctoring_fieldtitles($provider);
13877: if (!$confhash{$provider}{'available'}) {
13878: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
13879: } else {
13880: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
13881: if ($confhash{$provider}{'image'}) {
13882: $resulttext .= ' '.
13883: '<img src="'.$confhash{$provider}{'image'}.'"'.
13884: ' alt="'.&mt('Proctoring icon').'" />';
13885: }
13886: $resulttext .= '<ul>';
13887: my $position = $pos + 1;
13888: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
13889: foreach my $key ('version','sigmethod','url','lifetime') {
13890: if ($confhash{$provider}{$key} ne '') {
13891: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
13892: }
13893: }
13894: if ($encconfhash{$provider}{'key'} ne '') {
13895: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
13896: }
13897: if ($encconfhash{$provider}{'secret'} ne '') {
13898: $resulttext .= '<li>'.$lt{'secret'}.': ';
13899: my $num = length($encconfhash{$provider}{'secret'});
13900: $resulttext .= ('*'x$num).'</li>';
13901: }
13902: my (@fields,$showroles);
13903: if (ref($requserfields{$provider}) eq 'ARRAY') {
13904: push(@fields,@{$requserfields{$provider}});
13905: }
13906: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
13907: push(@fields,@{$confhash{$provider}{'fields'}});
13908: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
13909: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
13910: }
13911: if (@fields) {
13912: if (grep(/^roles$/,@fields)) {
13913: $showroles = 1;
13914: }
13915: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
13916: join('", "', map { $lt{$_}; } @fields).'"</li>';
13917: }
13918: if (ref($requserfields{$provider}) eq 'ARRAY') {
13919: if (grep(/^user$/,@{$requserfields{$provider}})) {
13920: if ($confhash{$provider}{'incdom'}) {
13921: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
13922: } else {
13923: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
13924: }
13925: }
13926: }
13927: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
13928: if (@{$confhash{$provider}{'defaults'}} > 0) {
13929: $resulttext .= '<li>'.$lt{'defa'};
13930: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
13931: $resulttext .= ' "'.$fieldtitles{$field}.'",';
13932: }
13933: $resulttext =~ s/,$//;
13934: $resulttext .= '</li>';
13935: }
13936: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
13937: if (keys(%{$confhash{$provider}{'defaults'}})) {
13938: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
13939: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
13940: if ($confhash{$provider}{'defaults'}{$key} ne '') {
13941: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
13942: }
13943: }
13944: $resulttext .= '</ul></li>';
13945: }
13946: }
13947: if (ref($crsconf{$provider}) eq 'ARRAY') {
13948: if (@{$crsconf{$provider}} > 0) {
13949: $resulttext .= '<li>'.&mt('Configurable in course:');
13950: my $numconfig = 0;
13951: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
13952: if (@{$confhash{$provider}{'crsconf'}} > 0) {
13953: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
13954: $numconfig ++;
13955: if ($provider eq 'examity') {
13956: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
13957: } else {
13958: $resulttext .= ' "'.$fieldtitles{$field}.'",';
13959: }
13960: }
13961: $resulttext =~ s/,$//;
13962: }
13963: }
13964: if (!$numconfig) {
13965: $resulttext .= ' '.&mt('None');
13966: }
13967: $resulttext .= '</li>';
13968: }
13969: }
13970: if ($showroles) {
13971: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
13972: my $rolemaps;
13973: foreach my $role (@courseroles) {
13974: if ($confhash{$provider}{'roles'}{$role}) {
13975: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
13976: $confhash{$provider}{'roles'}{$role}.',';
13977: }
13978: }
13979: if ($rolemaps) {
13980: $rolemaps =~ s/,$//;
13981: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
13982: }
13983: }
13984: }
13985: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
13986: my $customlist;
13987: if (keys(%{$confhash{$provider}{'custom'}})) {
13988: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
13989: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
13990: }
13991: $customlist =~ s/,$//;
13992: }
13993: if ($customlist) {
13994: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
13995: }
13996: }
13997: $resulttext .= '</ul></li>';
13998: }
13999: }
14000: $resulttext .= '</ul>';
14001: } else {
14002: $resulttext = &mt('No changes made.');
14003: }
14004: } else {
14005: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14006: }
14007: if ($errors) {
14008: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14009: $errors.'</ul>';
14010: }
14011: return $resulttext;
14012: }
14013:
14014: sub process_proctoring_image {
14015: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
14016: my $filename = $env{'form.'.$caller.'.filename'};
14017: my ($error,$url);
14018: my ($width,$height) = (21,21);
14019: if ($configuserok eq 'ok') {
14020: if ($switchserver) {
14021: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
14022: $switchserver);
14023: } elsif ($author_ok eq 'ok') {
14024: my ($result,$imageurl,$madethumb) =
14025: &publishlogo($r,'upload',$caller,$dom,$confname,
14026: "proctoring/$provider/icon",$width,$height);
14027: if ($result eq 'ok') {
14028: if ($madethumb) {
14029: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
14030: my $imagethumb = "$path/tn-".$imagefile;
14031: $url = $imagethumb;
14032: } else {
14033: $url = $imageurl;
14034: }
14035: } else {
14036: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14037: }
14038: } else {
14039: $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);
14040: }
14041: } else {
14042: $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);
14043: }
14044: return ($url,$error);
14045: }
14046:
1.320 raeburn 14047: sub modify_lti {
14048: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
14049: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14050: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
14051: my (%posslti,%posslticrs,%posscrstype);
14052: my @courseroles = ('cc','in','ta','ep','st');
14053: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
14054: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
14055: my @coursetypes = ('official','unofficial','community','textbook','placement');
14056: my %coursetypetitles = &Apache::lonlocal::texthash (
14057: official => 'Official',
14058: unofficial => 'Unofficial',
14059: community => 'Community',
14060: textbook => 'Textbook',
14061: placement => 'Placement Test',
14062: );
1.325 raeburn 14063: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 14064: my %lt = <i_names();
14065: map { $posslti{$_} = 1; } @ltiroles;
14066: map { $posslticrs{$_} = 1; } @lticourseroles;
14067: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 14068:
1.326 raeburn 14069: my %menutitles = <imenu_titles();
14070:
1.320 raeburn 14071: my (@items,%deletions,%itemids);
14072: if ($env{'form.lti_add'}) {
14073: my $consumer = $env{'form.lti_consumer_add'};
14074: $consumer =~ s/(`)/'/g;
14075: ($newid,my $error) = &get_lti_id($dom,$consumer);
14076: if ($newid) {
14077: $itemids{'add'} = $newid;
14078: push(@items,'add');
14079: $changes{$newid} = 1;
14080: } else {
14081: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
14082: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14083: }
14084: }
14085: if (ref($domconfig{$action}) eq 'HASH') {
14086: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
14087: if (@todelete) {
14088: map { $deletions{$_} = 1; } @todelete;
14089: }
14090: my $maxnum = $env{'form.lti_maxnum'};
14091: for (my $i=0; $i<=$maxnum; $i++) {
14092: my $itemid = $env{'form.lti_id_'.$i};
14093: $itemid =~ s/\D+//g;
14094: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14095: if ($deletions{$itemid}) {
14096: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
14097: } else {
14098: push(@items,$i);
14099: $itemids{$i} = $itemid;
14100: }
14101: }
14102: }
14103: }
14104: foreach my $idx (@items) {
14105: my $itemid = $itemids{$idx};
14106: next unless ($itemid);
14107: my $position = $env{'form.lti_pos_'.$idx};
14108: $position =~ s/\D+//g;
14109: if ($position ne '') {
14110: $allpos[$position] = $itemid;
14111: }
1.345 raeburn 14112: foreach my $item ('consumer','key','secret','lifetime','requser') {
1.320 raeburn 14113: my $formitem = 'form.lti_'.$item.'_'.$idx;
14114: $env{$formitem} =~ s/(`)/'/g;
14115: if ($item eq 'lifetime') {
14116: $env{$formitem} =~ s/[^\d.]//g;
14117: }
14118: if ($env{$formitem} ne '') {
14119: if (($item eq 'key') || ($item eq 'secret')) {
14120: $encconfig{$itemid}{$item} = $env{$formitem};
14121: } else {
14122: $confhash{$itemid}{$item} = $env{$formitem};
14123: unless (($idx eq 'add') || ($changes{$itemid})) {
14124: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
14125: $changes{$itemid} = 1;
14126: }
14127: }
14128: }
14129: }
14130: }
14131: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
14132: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
14133: }
1.345 raeburn 14134: if ($confhash{$itemid}{'requser'}) {
14135: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
14136: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
14137: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
14138: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
14139: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
14140: my $mapuser = $env{'form.lti_customuser_'.$idx};
14141: $mapuser =~ s/(`)/'/g;
14142: $mapuser =~ s/^\s+|\s+$//g;
14143: $confhash{$itemid}{'mapuser'} = $mapuser;
14144: }
14145: foreach my $ltirole (@lticourseroles) {
14146: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
14147: if (grep(/^\Q$possrole\E$/,@courseroles)) {
14148: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
14149: }
14150: }
14151: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
14152: my @makeuser;
14153: foreach my $ltirole (sort(@possmakeuser)) {
14154: if ($posslti{$ltirole}) {
14155: push(@makeuser,$ltirole);
14156: }
14157: }
14158: $confhash{$itemid}{'makeuser'} = \@makeuser;
14159: if (@makeuser) {
14160: my $lcauth = $env{'form.lti_lcauth_'.$idx};
14161: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
14162: $confhash{$itemid}{'lcauth'} = $lcauth;
14163: if ($lcauth ne 'internal') {
14164: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
14165: $lcauthparm =~ s/^(\s+|\s+)$//g;
14166: $lcauthparm =~ s/`//g;
14167: if ($lcauthparm ne '') {
14168: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
14169: }
14170: }
14171: } else {
14172: $confhash{$itemid}{'lcauth'} = 'lti';
14173: }
1.320 raeburn 14174: }
1.345 raeburn 14175: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
14176: if (@possinstdata) {
14177: foreach my $field (@possinstdata) {
14178: if (exists($fieldtitles{$field})) {
14179: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 14180: }
14181: }
14182: }
1.345 raeburn 14183: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
14184: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
14185: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
14186: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
14187: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
14188: $mapcrs =~ s/(`)/'/g;
14189: $mapcrs =~ s/^\s+|\s+$//g;
14190: $confhash{$itemid}{'mapcrs'} = $mapcrs;
14191: }
14192: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
14193: my @crstypes;
14194: foreach my $type (sort(@posstypes)) {
14195: if ($posscrstype{$type}) {
14196: push(@crstypes,$type);
1.325 raeburn 14197: }
14198: }
1.345 raeburn 14199: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
14200: if ($env{'form.lti_makecrs_'.$idx}) {
14201: $confhash{$itemid}{'makecrs'} = 1;
1.320 raeburn 14202: }
1.345 raeburn 14203: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
14204: my @selfenroll;
14205: foreach my $type (sort(@possenroll)) {
14206: if ($posslticrs{$type}) {
14207: push(@selfenroll,$type);
14208: }
1.320 raeburn 14209: }
1.345 raeburn 14210: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
14211: if ($env{'form.lti_crssec_'.$idx}) {
14212: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
14213: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
14214: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
14215: my $section = $env{'form.lti_customsection_'.$idx};
14216: $section =~ s/(`)/'/g;
14217: $section =~ s/^\s+|\s+$//g;
14218: if ($section ne '') {
14219: $confhash{$itemid}{'section'} = $section;
14220: }
1.320 raeburn 14221: }
14222: }
1.363 raeburn 14223: if ($env{'form.lti_callback_'.$idx}) {
14224: if ($env{'form.lti_callbackparam_'.$idx}) {
14225: my $callback = $env{'form.lti_callbackparam_'.$idx};
14226: $callback =~ s/^\s+|\s+$//g;
14227: $confhash{$itemid}{'callback'} = $callback;
14228: }
14229: }
1.345 raeburn 14230: foreach my $field ('passback','roster','topmenu','inlinemenu') {
14231: if ($env{'form.lti_'.$field.'_'.$idx}) {
14232: $confhash{$itemid}{$field} = 1;
14233: }
1.320 raeburn 14234: }
1.345 raeburn 14235: if ($env{'form.lti_passback_'.$idx}) {
14236: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
14237: $confhash{$itemid}{'passbackformat'} = '1.0';
14238: } else {
14239: $confhash{$itemid}{'passbackformat'} = '1.1';
14240: }
1.337 raeburn 14241: }
1.345 raeburn 14242: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
14243: $confhash{$itemid}{lcmenu} = [];
14244: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
14245: foreach my $field (@possmenu) {
14246: if (exists($menutitles{$field})) {
14247: if ($field eq 'grades') {
14248: next unless ($env{'form.lti_inlinemenu_'.$idx});
14249: }
14250: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 14251: }
14252: }
14253: }
1.345 raeburn 14254: unless (($idx eq 'add') || ($changes{$itemid})) {
1.363 raeburn 14255: foreach my $field ('mapuser','mapcrs','makecrs','section','passback','roster','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
1.345 raeburn 14256: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.337 raeburn 14257: $changes{$itemid} = 1;
14258: }
14259: }
1.320 raeburn 14260: unless ($changes{$itemid}) {
1.345 raeburn 14261: if ($domconfig{$action}{$itemid}{'passback'} eq $confhash{$itemid}{'passback'}) {
14262: if ($domconfig{$action}{$itemid}{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 14263: $changes{$itemid} = 1;
14264: }
1.345 raeburn 14265: }
1.320 raeburn 14266: }
1.345 raeburn 14267: foreach my $field ('makeuser','mapcrstype','selfenroll','instdata','lcmenu') {
14268: unless ($changes{$itemid}) {
14269: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
14270: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
14271: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
14272: $confhash{$itemid}{$field});
14273: if (@diffs) {
14274: $changes{$itemid} = 1;
14275: }
14276: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
14277: $changes{$itemid} = 1;
14278: }
14279: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
14280: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 14281: $changes{$itemid} = 1;
14282: }
14283: }
1.345 raeburn 14284: }
14285: }
14286: unless ($changes{$itemid}) {
14287: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
14288: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
14289: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
14290: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
14291: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.320 raeburn 14292: $changes{$itemid} = 1;
14293: last;
14294: }
14295: }
1.345 raeburn 14296: unless ($changes{$itemid}) {
14297: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
14298: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
14299: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
14300: $changes{$itemid} = 1;
14301: last;
14302: }
14303: }
14304: }
14305: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
14306: $changes{$itemid} = 1;
1.320 raeburn 14307: }
1.345 raeburn 14308: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
14309: unless ($changes{$itemid}) {
14310: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
14311: $changes{$itemid} = 1;
14312: }
1.320 raeburn 14313: }
14314: }
14315: }
14316: }
14317: }
14318: }
14319: if (@allpos > 0) {
14320: my $idx = 0;
14321: foreach my $itemid (@allpos) {
14322: if ($itemid ne '') {
14323: $confhash{$itemid}{'order'} = $idx;
14324: if (ref($domconfig{$action}) eq 'HASH') {
14325: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14326: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
14327: $changes{$itemid} = 1;
14328: }
14329: }
14330: }
14331: $idx ++;
14332: }
14333: }
14334: }
14335: my %ltihash = (
14336: $action => { %confhash }
14337: );
14338: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
14339: $dom);
14340: if ($putresult eq 'ok') {
14341: my %ltienchash = (
14342: $action => { %encconfig }
14343: );
14344: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
14345: if (keys(%changes) > 0) {
14346: my $cachetime = 24*60*60;
14347: my %ltiall = %confhash;
14348: foreach my $id (keys(%ltiall)) {
14349: if (ref($encconfig{$id}) eq 'HASH') {
14350: foreach my $item ('key','secret') {
14351: $ltiall{$id}{$item} = $encconfig{$id}{$item};
14352: }
14353: }
14354: }
14355: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
14356: if (ref($lastactref) eq 'HASH') {
14357: $lastactref->{'lti'} = 1;
14358: }
14359: $resulttext = &mt('Changes made:').'<ul>';
14360: my %bynum;
14361: foreach my $itemid (sort(keys(%changes))) {
14362: my $position = $confhash{$itemid}{'order'};
14363: $bynum{$position} = $itemid;
14364: }
14365: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
14366: my $itemid = $bynum{$pos};
14367: if (ref($confhash{$itemid}) ne 'HASH') {
14368: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
14369: } else {
14370: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b></li><ul>';
14371: my $position = $pos + 1;
14372: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
14373: foreach my $item ('version','lifetime') {
14374: if ($confhash{$itemid}{$item} ne '') {
14375: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
14376: }
14377: }
14378: if ($encconfig{$itemid}{'key'} ne '') {
14379: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
14380: }
14381: if ($encconfig{$itemid}{'secret'} ne '') {
14382: $resulttext .= '<li>'.$lt{'secret'}.': ';
14383: my $num = length($encconfig{$itemid}{'secret'});
14384: $resulttext .= ('*'x$num).'</li>';
14385: }
1.345 raeburn 14386: if ($confhash{$itemid}{'requser'}) {
14387: if ($confhash{$itemid}{'mapuser'}) {
14388: my $shownmapuser;
14389: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
14390: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
14391: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
14392: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
14393: } else {
14394: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 14395: }
1.345 raeburn 14396: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 14397: }
1.345 raeburn 14398: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
14399: my $rolemaps;
14400: foreach my $role (@ltiroles) {
14401: if ($confhash{$itemid}{'maproles'}{$role}) {
14402: $rolemaps .= (' 'x2).$role.'='.
14403: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
14404: 'Course').',';
14405: }
14406: }
14407: if ($rolemaps) {
14408: $rolemaps =~ s/,$//;
14409: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
14410: }
14411: }
14412: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
14413: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
14414: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
14415: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
14416: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
14417: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
14418: } else {
14419: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
14420: $confhash{$itemid}{'lcauth'});
14421: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
14422: $resulttext .= '; '.&mt('a randomly generated password will be created');
14423: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
14424: if ($confhash{$itemid}{'lcauthparm'} ne '') {
14425: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
14426: }
14427: } else {
14428: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
14429: }
14430: }
14431: $resulttext .= '</li>';
14432: } else {
14433: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
14434: }
1.320 raeburn 14435: }
1.345 raeburn 14436: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
14437: if (@{$confhash{$itemid}{'instdata'}} > 0) {
14438: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
14439: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 14440: } else {
1.345 raeburn 14441: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 14442: }
1.320 raeburn 14443: }
1.345 raeburn 14444: if ($confhash{$itemid}{'mapcrs'}) {
14445: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
14446: }
14447: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
14448: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
14449: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
14450: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
14451: '</li>';
14452: } else {
14453: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
14454: }
1.325 raeburn 14455: }
1.345 raeburn 14456: if ($confhash{$itemid}{'makecrs'}) {
14457: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
1.320 raeburn 14458: } else {
1.345 raeburn 14459: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
1.320 raeburn 14460: }
1.345 raeburn 14461: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
14462: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
14463: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
14464: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
14465: '</li>';
14466: } else {
14467: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
14468: }
1.320 raeburn 14469: }
1.345 raeburn 14470: if ($confhash{$itemid}{'section'}) {
14471: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
14472: $resulttext .= '<li>'.&mt('User section from standard field:').
14473: ' (course_section_sourcedid)'.'</li>';
14474: } else {
14475: $resulttext .= '<li>'.&mt('User section from:').' '.
14476: $confhash{$itemid}{'section'}.'</li>';
14477: }
1.320 raeburn 14478: } else {
1.345 raeburn 14479: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
1.320 raeburn 14480: }
1.363 raeburn 14481: if ($confhash{$itemid}{'callback'}) {
14482: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
14483: } else {
14484: $resulttext .= '<li>'.&mt('No callback to logout LON-CAPA session when user logs out of Comsumer');
14485: }
1.345 raeburn 14486: foreach my $item ('passback','roster','topmenu','inlinemenu') {
14487: $resulttext .= '<li>'.$lt{$item}.': ';
14488: if ($confhash{$itemid}{$item}) {
14489: $resulttext .= &mt('Yes');
14490: if ($item eq 'passback') {
14491: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
14492: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
14493: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
14494: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
14495: }
1.337 raeburn 14496: }
1.345 raeburn 14497: } else {
14498: $resulttext .= &mt('No');
1.337 raeburn 14499: }
1.345 raeburn 14500: $resulttext .= '</li>';
1.320 raeburn 14501: }
1.345 raeburn 14502: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
14503: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
14504: $resulttext .= '<li>'.&mt('Menu items:').' '.
14505: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
14506: } else {
14507: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
14508: }
1.326 raeburn 14509: }
14510: }
1.320 raeburn 14511: $resulttext .= '</ul></li>';
14512: }
14513: }
14514: $resulttext .= '</ul>';
14515: } else {
14516: $resulttext = &mt('No changes made.');
14517: }
14518: } else {
14519: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14520: }
14521: if ($errors) {
14522: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14523: $errors.'</ul>';
14524: }
14525: return $resulttext;
14526: }
14527:
14528: sub get_lti_id {
14529: my ($domain,$consumer) = @_;
14530: # get lock on lti db
14531: my $lockhash = {
14532: lock => $env{'user.name'}.
14533: ':'.$env{'user.domain'},
14534: };
14535: my $tries = 0;
14536: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
14537: my ($id,$error);
14538:
14539: while (($gotlock ne 'ok') && ($tries<10)) {
14540: $tries ++;
14541: sleep (0.1);
14542: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
14543: }
14544: if ($gotlock eq 'ok') {
14545: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
14546: if ($currids{'lock'}) {
14547: delete($currids{'lock'});
14548: if (keys(%currids)) {
14549: my @curr = sort { $a <=> $b } keys(%currids);
14550: if ($curr[-1] =~ /^\d+$/) {
14551: $id = 1 + $curr[-1];
14552: }
14553: } else {
14554: $id = 1;
14555: }
14556: if ($id) {
14557: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
14558: $error = 'nostore';
14559: }
14560: } else {
14561: $error = 'nonumber';
14562: }
14563: }
14564: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
14565: } else {
14566: $error = 'nolock';
14567: }
14568: return ($id,$error);
14569: }
14570:
1.3 raeburn 14571: sub modify_autoenroll {
1.205 raeburn 14572: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 14573: my ($resulttext,%changes);
14574: my %currautoenroll;
14575: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
14576: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
14577: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
14578: }
14579: }
14580: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
14581: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 14582: sender => 'Sender for notification messages',
1.274 raeburn 14583: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
14584: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 14585: my @offon = ('off','on');
1.17 raeburn 14586: my $sender_uname = $env{'form.sender_uname'};
14587: my $sender_domain = $env{'form.sender_domain'};
14588: if ($sender_domain eq '') {
14589: $sender_uname = '';
14590: } elsif ($sender_uname eq '') {
14591: $sender_domain = '';
14592: }
1.129 raeburn 14593: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 14594: my $failsafe = $env{'form.autoenroll_failsafe'};
14595: $failsafe =~ s{^\s+|\s+$}{}g;
14596: if ($failsafe =~ /\D/) {
14597: undef($failsafe);
14598: }
1.1 raeburn 14599: my %autoenrollhash = (
1.129 raeburn 14600: autoenroll => { 'run' => $env{'form.autoenroll_run'},
14601: 'sender_uname' => $sender_uname,
14602: 'sender_domain' => $sender_domain,
14603: 'co-owners' => $coowners,
1.274 raeburn 14604: 'autofailsafe' => $failsafe,
1.1 raeburn 14605: }
14606: );
1.4 raeburn 14607: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
14608: $dom);
1.1 raeburn 14609: if ($putresult eq 'ok') {
14610: if (exists($currautoenroll{'run'})) {
14611: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
14612: $changes{'run'} = 1;
14613: }
14614: } elsif ($autorun) {
14615: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 14616: $changes{'run'} = 1;
1.1 raeburn 14617: }
14618: }
1.17 raeburn 14619: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 14620: $changes{'sender'} = 1;
14621: }
1.17 raeburn 14622: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 14623: $changes{'sender'} = 1;
14624: }
1.129 raeburn 14625: if ($currautoenroll{'co-owners'} ne '') {
14626: if ($currautoenroll{'co-owners'} ne $coowners) {
14627: $changes{'coowners'} = 1;
14628: }
14629: } elsif ($coowners) {
14630: $changes{'coowners'} = 1;
1.274 raeburn 14631: }
14632: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
14633: $changes{'autofailsafe'} = 1;
14634: }
1.1 raeburn 14635: if (keys(%changes) > 0) {
14636: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 14637: if ($changes{'run'}) {
1.1 raeburn 14638: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
14639: }
14640: if ($changes{'sender'}) {
1.17 raeburn 14641: if ($sender_uname eq '' || $sender_domain eq '') {
14642: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
14643: } else {
14644: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
14645: }
1.1 raeburn 14646: }
1.129 raeburn 14647: if ($changes{'coowners'}) {
14648: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
14649: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 14650: if (ref($lastactref) eq 'HASH') {
14651: $lastactref->{'domainconfig'} = 1;
14652: }
1.129 raeburn 14653: }
1.274 raeburn 14654: if ($changes{'autofailsafe'}) {
14655: if ($failsafe ne '') {
1.299 raeburn 14656: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 14657: } else {
1.299 raeburn 14658: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 14659: }
14660: &Apache::lonnet::get_domain_defaults($dom,1);
14661: if (ref($lastactref) eq 'HASH') {
14662: $lastactref->{'domdefaults'} = 1;
14663: }
14664: }
1.1 raeburn 14665: $resulttext .= '</ul>';
14666: } else {
14667: $resulttext = &mt('No changes made to auto-enrollment settings');
14668: }
14669: } else {
1.11 albertel 14670: $resulttext = '<span class="LC_error">'.
14671: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14672: }
1.3 raeburn 14673: return $resulttext;
1.1 raeburn 14674: }
14675:
14676: sub modify_autoupdate {
1.3 raeburn 14677: my ($dom,%domconfig) = @_;
1.1 raeburn 14678: my ($resulttext,%currautoupdate,%fields,%changes);
14679: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
14680: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
14681: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
14682: }
14683: }
14684: my @offon = ('off','on');
14685: my %title = &Apache::lonlocal::texthash (
14686: run => 'Auto-update:',
14687: classlists => 'Updates to user information in classlists?'
14688: );
1.44 raeburn 14689: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 14690: my %fieldtitles = &Apache::lonlocal::texthash (
14691: id => 'Student/Employee ID',
1.20 raeburn 14692: permanentemail => 'E-mail address',
1.1 raeburn 14693: lastname => 'Last Name',
14694: firstname => 'First Name',
14695: middlename => 'Middle Name',
1.132 raeburn 14696: generation => 'Generation',
1.1 raeburn 14697: );
1.142 raeburn 14698: $othertitle = &mt('All users');
1.1 raeburn 14699: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 14700: $othertitle = &mt('Other users');
1.1 raeburn 14701: }
14702: foreach my $key (keys(%env)) {
14703: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 14704: my ($usertype,$item) = ($1,$2);
14705: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
14706: if ($usertype eq 'default') {
14707: push(@{$fields{$1}},$2);
14708: } elsif (ref($types) eq 'ARRAY') {
14709: if (grep(/^\Q$usertype\E$/,@{$types})) {
14710: push(@{$fields{$1}},$2);
14711: }
14712: }
14713: }
1.1 raeburn 14714: }
14715: }
1.131 raeburn 14716: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
14717: @lockablenames = sort(@lockablenames);
14718: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
14719: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
14720: if (@changed) {
14721: $changes{'lockablenames'} = 1;
14722: }
14723: } else {
14724: if (@lockablenames) {
14725: $changes{'lockablenames'} = 1;
14726: }
14727: }
1.1 raeburn 14728: my %updatehash = (
14729: autoupdate => { run => $env{'form.autoupdate_run'},
14730: classlists => $env{'form.classlists'},
14731: fields => {%fields},
1.131 raeburn 14732: lockablenames => \@lockablenames,
1.1 raeburn 14733: }
14734: );
14735: foreach my $key (keys(%currautoupdate)) {
14736: if (($key eq 'run') || ($key eq 'classlists')) {
14737: if (exists($updatehash{autoupdate}{$key})) {
14738: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
14739: $changes{$key} = 1;
14740: }
14741: }
14742: } elsif ($key eq 'fields') {
14743: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 14744: foreach my $item (@{$types},'default') {
1.1 raeburn 14745: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
14746: my $change = 0;
14747: foreach my $type (@{$currautoupdate{$key}{$item}}) {
14748: if (!exists($fields{$item})) {
14749: $change = 1;
1.132 raeburn 14750: last;
1.1 raeburn 14751: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 14752: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 14753: $change = 1;
1.132 raeburn 14754: last;
1.1 raeburn 14755: }
14756: }
14757: }
14758: if ($change) {
14759: push(@{$changes{$key}},$item);
14760: }
1.26 raeburn 14761: }
1.1 raeburn 14762: }
14763: }
1.131 raeburn 14764: } elsif ($key eq 'lockablenames') {
14765: if (ref($currautoupdate{$key}) eq 'ARRAY') {
14766: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
14767: if (@changed) {
14768: $changes{'lockablenames'} = 1;
14769: }
14770: } else {
14771: if (@lockablenames) {
14772: $changes{'lockablenames'} = 1;
14773: }
14774: }
14775: }
14776: }
14777: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
14778: if (@lockablenames) {
14779: $changes{'lockablenames'} = 1;
1.1 raeburn 14780: }
14781: }
1.26 raeburn 14782: foreach my $item (@{$types},'default') {
14783: if (defined($fields{$item})) {
14784: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 14785: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
14786: my $change = 0;
14787: if (ref($fields{$item}) eq 'ARRAY') {
14788: foreach my $type (@{$fields{$item}}) {
14789: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
14790: $change = 1;
14791: last;
14792: }
14793: }
14794: }
14795: if ($change) {
14796: push(@{$changes{'fields'}},$item);
14797: }
14798: } else {
1.26 raeburn 14799: push(@{$changes{'fields'}},$item);
14800: }
14801: } else {
14802: push(@{$changes{'fields'}},$item);
1.1 raeburn 14803: }
14804: }
14805: }
14806: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
14807: $dom);
14808: if ($putresult eq 'ok') {
14809: if (keys(%changes) > 0) {
14810: $resulttext = &mt('Changes made:').'<ul>';
14811: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 14812: if ($key eq 'lockablenames') {
14813: $resulttext .= '<li>';
14814: if (@lockablenames) {
14815: $usertypes->{'default'} = $othertitle;
14816: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
14817: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
14818: } else {
14819: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
14820: }
14821: $resulttext .= '</li>';
14822: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 14823: foreach my $item (@{$changes{$key}}) {
14824: my @newvalues;
14825: foreach my $type (@{$fields{$item}}) {
14826: push(@newvalues,$fieldtitles{$type});
14827: }
1.3 raeburn 14828: my $newvaluestr;
14829: if (@newvalues > 0) {
14830: $newvaluestr = join(', ',@newvalues);
14831: } else {
14832: $newvaluestr = &mt('none');
1.6 raeburn 14833: }
1.1 raeburn 14834: if ($item eq 'default') {
1.26 raeburn 14835: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 14836: } else {
1.26 raeburn 14837: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 14838: }
14839: }
14840: } else {
14841: my $newvalue;
14842: if ($key eq 'run') {
14843: $newvalue = $offon[$env{'form.autoupdate_run'}];
14844: } else {
14845: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 14846: }
1.1 raeburn 14847: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
14848: }
14849: }
14850: $resulttext .= '</ul>';
14851: } else {
1.3 raeburn 14852: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 14853: }
14854: } else {
1.11 albertel 14855: $resulttext = '<span class="LC_error">'.
14856: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14857: }
1.3 raeburn 14858: return $resulttext;
1.1 raeburn 14859: }
14860:
1.125 raeburn 14861: sub modify_autocreate {
14862: my ($dom,%domconfig) = @_;
14863: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
14864: if (ref($domconfig{'autocreate'}) eq 'HASH') {
14865: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
14866: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
14867: }
14868: }
14869: my %title= ( xml => 'Auto-creation of courses in XML course description files',
14870: req => 'Auto-creation of validated requests for official courses',
14871: xmldc => 'Identity of course creator of courses from XML files',
14872: );
14873: my @types = ('xml','req');
14874: foreach my $item (@types) {
14875: $newvals{$item} = $env{'form.autocreate_'.$item};
14876: $newvals{$item} =~ s/\D//g;
14877: $newvals{$item} = 0 if ($newvals{$item} eq '');
14878: }
14879: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 14880: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 14881: unless (exists($domcoords{$newvals{'xmldc'}})) {
14882: $newvals{'xmldc'} = '';
14883: }
14884: %autocreatehash = (
14885: autocreate => { xml => $newvals{'xml'},
14886: req => $newvals{'req'},
14887: }
14888: );
14889: if ($newvals{'xmldc'} ne '') {
14890: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
14891: }
14892: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
14893: $dom);
14894: if ($putresult eq 'ok') {
14895: my @items = @types;
14896: if ($newvals{'xml'}) {
14897: push(@items,'xmldc');
14898: }
14899: foreach my $item (@items) {
14900: if (exists($currautocreate{$item})) {
14901: if ($currautocreate{$item} ne $newvals{$item}) {
14902: $changes{$item} = 1;
14903: }
14904: } elsif ($newvals{$item}) {
14905: $changes{$item} = 1;
14906: }
14907: }
14908: if (keys(%changes) > 0) {
14909: my @offon = ('off','on');
14910: $resulttext = &mt('Changes made:').'<ul>';
14911: foreach my $item (@types) {
14912: if ($changes{$item}) {
14913: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 14914: $resulttext .= '<li>'.
14915: &mt("$title{$item} set to [_1]$newtxt [_2]",
14916: '<b>','</b>').
14917: '</li>';
1.125 raeburn 14918: }
14919: }
14920: if ($changes{'xmldc'}) {
14921: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
14922: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 14923: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 14924: }
14925: $resulttext .= '</ul>';
14926: } else {
14927: $resulttext = &mt('No changes made to auto-creation settings');
14928: }
14929: } else {
14930: $resulttext = '<span class="LC_error">'.
14931: &mt('An error occurred: [_1]',$putresult).'</span>';
14932: }
14933: return $resulttext;
14934: }
14935:
1.23 raeburn 14936: sub modify_directorysrch {
1.295 raeburn 14937: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 14938: my ($resulttext,%changes);
14939: my %currdirsrch;
14940: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
14941: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
14942: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
14943: }
14944: }
1.277 raeburn 14945: my %title = ( available => 'Institutional directory search available',
14946: localonly => 'Other domains can search institution',
14947: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 14948: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 14949: searchby => 'Search types',
14950: searchtypes => 'Search latitude');
14951: my @offon = ('off','on');
1.24 raeburn 14952: my @otherdoms = ('Yes','No');
1.23 raeburn 14953:
1.25 raeburn 14954: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 14955: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
14956: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
14957:
1.44 raeburn 14958: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 14959: if (keys(%{$usertypes}) == 0) {
14960: @cansearch = ('default');
14961: } else {
14962: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
14963: foreach my $type (@{$currdirsrch{'cansearch'}}) {
14964: if (!grep(/^\Q$type\E$/,@cansearch)) {
14965: push(@{$changes{'cansearch'}},$type);
14966: }
1.23 raeburn 14967: }
1.26 raeburn 14968: foreach my $type (@cansearch) {
14969: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
14970: push(@{$changes{'cansearch'}},$type);
14971: }
1.23 raeburn 14972: }
1.26 raeburn 14973: } else {
14974: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 14975: }
14976: }
14977:
14978: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
14979: foreach my $by (@{$currdirsrch{'searchby'}}) {
14980: if (!grep(/^\Q$by\E$/,@searchby)) {
14981: push(@{$changes{'searchby'}},$by);
14982: }
14983: }
14984: foreach my $by (@searchby) {
14985: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
14986: push(@{$changes{'searchby'}},$by);
14987: }
14988: }
14989: } else {
14990: push(@{$changes{'searchby'}},@searchby);
14991: }
1.25 raeburn 14992:
14993: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
14994: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
14995: if (!grep(/^\Q$type\E$/,@searchtypes)) {
14996: push(@{$changes{'searchtypes'}},$type);
14997: }
14998: }
14999: foreach my $type (@searchtypes) {
15000: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
15001: push(@{$changes{'searchtypes'}},$type);
15002: }
15003: }
15004: } else {
15005: if (exists($currdirsrch{'searchtypes'})) {
15006: foreach my $type (@searchtypes) {
15007: if ($type ne $currdirsrch{'searchtypes'}) {
15008: push(@{$changes{'searchtypes'}},$type);
15009: }
15010: }
15011: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
15012: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
15013: }
15014: } else {
15015: push(@{$changes{'searchtypes'}},@searchtypes);
15016: }
15017: }
15018:
1.23 raeburn 15019: my %dirsrch_hash = (
15020: directorysrch => { available => $env{'form.dirsrch_available'},
15021: cansearch => \@cansearch,
1.277 raeburn 15022: localonly => $env{'form.dirsrch_instlocalonly'},
15023: lclocalonly => $env{'form.dirsrch_domlocalonly'},
15024: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 15025: searchby => \@searchby,
1.25 raeburn 15026: searchtypes => \@searchtypes,
1.23 raeburn 15027: }
15028: );
15029: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
15030: $dom);
15031: if ($putresult eq 'ok') {
15032: if (exists($currdirsrch{'available'})) {
15033: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
15034: $changes{'available'} = 1;
15035: }
15036: } else {
15037: if ($env{'form.dirsrch_available'} eq '1') {
15038: $changes{'available'} = 1;
15039: }
15040: }
1.277 raeburn 15041: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 15042: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
15043: $changes{'lcavailable'} = 1;
15044: }
1.277 raeburn 15045: } else {
15046: if ($env{'form.dirsrch_lcavailable'} eq '1') {
15047: $changes{'lcavailable'} = 1;
15048: }
15049: }
1.24 raeburn 15050: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 15051: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
15052: $changes{'localonly'} = 1;
15053: }
1.24 raeburn 15054: } else {
1.277 raeburn 15055: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 15056: $changes{'localonly'} = 1;
15057: }
15058: }
1.277 raeburn 15059: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 15060: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
15061: $changes{'lclocalonly'} = 1;
15062: }
1.277 raeburn 15063: } else {
15064: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
15065: $changes{'lclocalonly'} = 1;
15066: }
15067: }
1.23 raeburn 15068: if (keys(%changes) > 0) {
15069: $resulttext = &mt('Changes made:').'<ul>';
15070: if ($changes{'available'}) {
15071: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
15072: }
1.277 raeburn 15073: if ($changes{'lcavailable'}) {
15074: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
15075: }
1.24 raeburn 15076: if ($changes{'localonly'}) {
1.277 raeburn 15077: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 15078: }
1.277 raeburn 15079: if ($changes{'lclocalonly'}) {
15080: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 15081: }
1.23 raeburn 15082: if (ref($changes{'cansearch'}) eq 'ARRAY') {
15083: my $chgtext;
1.26 raeburn 15084: if (ref($usertypes) eq 'HASH') {
15085: if (keys(%{$usertypes}) > 0) {
15086: foreach my $type (@{$types}) {
15087: if (grep(/^\Q$type\E$/,@cansearch)) {
15088: $chgtext .= $usertypes->{$type}.'; ';
15089: }
15090: }
15091: if (grep(/^default$/,@cansearch)) {
15092: $chgtext .= $othertitle;
15093: } else {
15094: $chgtext =~ s/\; $//;
15095: }
1.210 raeburn 15096: $resulttext .=
1.178 raeburn 15097: '<li>'.
15098: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
15099: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
15100: '</li>';
1.23 raeburn 15101: }
15102: }
15103: }
15104: if (ref($changes{'searchby'}) eq 'ARRAY') {
15105: my ($searchtitles,$titleorder) = &sorted_searchtitles();
15106: my $chgtext;
15107: foreach my $type (@{$titleorder}) {
15108: if (grep(/^\Q$type\E$/,@searchby)) {
15109: if (defined($searchtitles->{$type})) {
15110: $chgtext .= $searchtitles->{$type}.'; ';
15111: }
15112: }
15113: }
15114: $chgtext =~ s/\; $//;
15115: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
15116: }
1.25 raeburn 15117: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
15118: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
15119: my $chgtext;
15120: foreach my $type (@{$srchtypeorder}) {
15121: if (grep(/^\Q$type\E$/,@searchtypes)) {
15122: if (defined($srchtypes_desc->{$type})) {
15123: $chgtext .= $srchtypes_desc->{$type}.'; ';
15124: }
15125: }
15126: }
15127: $chgtext =~ s/\; $//;
1.178 raeburn 15128: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 15129: }
15130: $resulttext .= '</ul>';
1.295 raeburn 15131: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
15132: if (ref($lastactref) eq 'HASH') {
15133: $lastactref->{'directorysrch'} = 1;
15134: }
1.23 raeburn 15135: } else {
1.277 raeburn 15136: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 15137: }
15138: } else {
15139: $resulttext = '<span class="LC_error">'.
1.27 raeburn 15140: &mt('An error occurred: [_1]',$putresult).'</span>';
15141: }
15142: return $resulttext;
15143: }
15144:
1.28 raeburn 15145: sub modify_contacts {
1.205 raeburn 15146: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 15147: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
15148: if (ref($domconfig{'contacts'}) eq 'HASH') {
15149: foreach my $key (keys(%{$domconfig{'contacts'}})) {
15150: $currsetting{$key} = $domconfig{'contacts'}{$key};
15151: }
15152: }
1.286 raeburn 15153: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 15154: my @contacts = ('supportemail','adminemail');
1.286 raeburn 15155: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 15156: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 15157: my @toggles = ('reporterrors','reportupdates','reportstatus');
15158: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 15159: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 15160: foreach my $type (@mailings) {
15161: @{$newsetting{$type}} =
15162: &Apache::loncommon::get_env_multiple('form.'.$type);
15163: foreach my $item (@contacts) {
15164: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
15165: $contacts_hash{contacts}{$type}{$item} = 1;
15166: } else {
15167: $contacts_hash{contacts}{$type}{$item} = 0;
15168: }
1.289 raeburn 15169: }
1.28 raeburn 15170: $others{$type} = $env{'form.'.$type.'_others'};
15171: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 15172: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15173: $bcc{$type} = $env{'form.'.$type.'_bcc'};
15174: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 15175: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
15176: $includestr{$type} = $env{'form.'.$type.'_includestr'};
15177: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
15178: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
15179: }
1.134 raeburn 15180: }
1.28 raeburn 15181: }
15182: foreach my $item (@contacts) {
15183: $to{$item} = $env{'form.'.$item};
15184: $contacts_hash{'contacts'}{$item} = $to{$item};
15185: }
1.203 raeburn 15186: foreach my $item (@toggles) {
15187: if ($env{'form.'.$item} =~ /^(0|1)$/) {
15188: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
15189: }
15190: }
1.340 raeburn 15191: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
15192: foreach my $item (@lonstatus) {
15193: if ($item eq 'excluded') {
15194: my (%serverhomes,@excluded);
15195: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
15196: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
15197: if (@possexcluded) {
15198: foreach my $id (sort(@possexcluded)) {
15199: if ($serverhomes{$id}) {
15200: push(@excluded,$id);
15201: }
15202: }
15203: }
15204: if (@excluded) {
15205: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
15206: }
15207: } elsif ($item eq 'weights') {
15208: foreach my $type ('E','W','N') {
15209: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
15210: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
15211: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
15212: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
15213: $env{'form.error'.$item.'_'.$type};
15214: }
15215: }
15216: }
15217: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
15218: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
15219: if ($env{'form.error'.$item} =~ /^\d+$/) {
15220: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
15221: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
15222: }
15223: }
15224: }
15225: }
1.286 raeburn 15226: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
15227: foreach my $field (@{$fields}) {
15228: if (ref($possoptions->{$field}) eq 'ARRAY') {
15229: my $value = $env{'form.helpform_'.$field};
15230: $value =~ s/^\s+|\s+$//g;
15231: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 15232: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 15233: if ($field eq 'screenshot') {
15234: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
15235: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 15236: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 15237: }
15238: }
15239: }
15240: }
15241: }
15242: }
1.315 raeburn 15243: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
15244: my (@statuses,%usertypeshash,@overrides);
15245: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
15246: @statuses = @{$types};
15247: if (ref($usertypes) eq 'HASH') {
15248: %usertypeshash = %{$usertypes};
15249: }
15250: }
15251: if (@statuses) {
15252: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
15253: foreach my $type (@possoverrides) {
15254: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
15255: push(@overrides,$type);
15256: }
15257: }
15258: if (@overrides) {
15259: foreach my $type (@overrides) {
15260: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
15261: foreach my $item (@contacts) {
15262: if (grep(/^\Q$item\E$/,@standard)) {
15263: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
15264: $newsetting{'override_'.$type}{$item} = 1;
15265: } else {
15266: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
15267: $newsetting{'override_'.$type}{$item} = 0;
15268: }
15269: }
15270: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
15271: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
15272: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
15273: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
15274: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
15275: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
15276: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
15277: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
15278: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
15279: }
15280: }
15281: }
15282: }
1.28 raeburn 15283: if (keys(%currsetting) > 0) {
15284: foreach my $item (@contacts) {
15285: if ($to{$item} ne $currsetting{$item}) {
15286: $changes{$item} = 1;
15287: }
15288: }
15289: foreach my $type (@mailings) {
15290: foreach my $item (@contacts) {
15291: if (ref($currsetting{$type}) eq 'HASH') {
15292: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
15293: push(@{$changes{$type}},$item);
15294: }
15295: } else {
15296: push(@{$changes{$type}},@{$newsetting{$type}});
15297: }
15298: }
15299: if ($others{$type} ne $currsetting{$type}{'others'}) {
15300: push(@{$changes{$type}},'others');
15301: }
1.289 raeburn 15302: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15303: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
15304: push(@{$changes{$type}},'bcc');
15305: }
1.286 raeburn 15306: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
15307: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
15308: push(@{$changes{$type}},'include');
15309: }
15310: }
15311: }
15312: if (ref($fields) eq 'ARRAY') {
15313: if (ref($currsetting{'helpform'}) eq 'HASH') {
15314: foreach my $field (@{$fields}) {
15315: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
15316: push(@{$changes{'helpform'}},$field);
15317: }
15318: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
15319: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
15320: push(@{$changes{'helpform'}},'maxsize');
15321: }
15322: }
15323: }
15324: } else {
15325: foreach my $field (@{$fields}) {
15326: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
15327: push(@{$changes{'helpform'}},$field);
15328: }
15329: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
15330: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
15331: push(@{$changes{'helpform'}},'maxsize');
15332: }
15333: }
15334: }
1.134 raeburn 15335: }
1.28 raeburn 15336: }
1.315 raeburn 15337: if (@statuses) {
15338: if (ref($currsetting{'overrides'}) eq 'HASH') {
15339: foreach my $key (keys(%{$currsetting{'overrides'}})) {
15340: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
15341: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
15342: foreach my $item (@contacts,'bcc','others','include') {
15343: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
15344: push(@{$changes{'overrides'}},$key);
15345: last;
15346: }
15347: }
15348: } else {
15349: push(@{$changes{'overrides'}},$key);
15350: }
15351: }
15352: }
15353: foreach my $key (@overrides) {
15354: unless (exists($currsetting{'overrides'}{$key})) {
15355: push(@{$changes{'overrides'}},$key);
15356: }
15357: }
15358: } else {
15359: foreach my $key (@overrides) {
15360: push(@{$changes{'overrides'}},$key);
15361: }
15362: }
15363: }
1.340 raeburn 15364: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
15365: foreach my $key ('excluded','weights','threshold','sysmail') {
15366: if ($key eq 'excluded') {
15367: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
15368: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
15369: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
15370: (@{$currsetting{'lonstatus'}{$key}})) {
15371: my @diffs =
15372: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
15373: $currsetting{'lonstatus'}{$key});
15374: if (@diffs) {
15375: push(@{$changes{'lonstatus'}},$key);
15376: }
15377: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
15378: push(@{$changes{'lonstatus'}},$key);
15379: }
15380: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
15381: (@{$currsetting{'lonstatus'}{$key}})) {
15382: push(@{$changes{'lonstatus'}},$key);
15383: }
15384: } elsif ($key eq 'weights') {
15385: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
15386: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
15387: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 15388: foreach my $type ('E','W','N','U') {
1.340 raeburn 15389: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
15390: $currsetting{'lonstatus'}{$key}{$type}) {
15391: push(@{$changes{'lonstatus'}},$key);
15392: last;
15393: }
15394: }
15395: } else {
1.341 raeburn 15396: foreach my $type ('E','W','N','U') {
1.340 raeburn 15397: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
15398: push(@{$changes{'lonstatus'}},$key);
15399: last;
15400: }
15401: }
15402: }
15403: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 15404: foreach my $type ('E','W','N','U') {
1.340 raeburn 15405: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
15406: push(@{$changes{'lonstatus'}},$key);
15407: last;
15408: }
15409: }
15410: }
15411: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
15412: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
15413: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
15414: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
15415: push(@{$changes{'lonstatus'}},$key);
15416: }
15417: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
15418: push(@{$changes{'lonstatus'}},$key);
15419: }
15420: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
15421: push(@{$changes{'lonstatus'}},$key);
15422: }
15423: }
15424: }
15425: } else {
15426: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
15427: foreach my $key ('excluded','weights','threshold','sysmail') {
15428: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
15429: push(@{$changes{'lonstatus'}},$key);
15430: }
15431: }
15432: }
15433: }
1.28 raeburn 15434: } else {
15435: my %default;
15436: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
15437: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
15438: $default{'errormail'} = 'adminemail';
15439: $default{'packagesmail'} = 'adminemail';
15440: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 15441: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 15442: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 15443: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 15444: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 15445: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 15446: foreach my $item (@contacts) {
15447: if ($to{$item} ne $default{$item}) {
1.286 raeburn 15448: $changes{$item} = 1;
1.203 raeburn 15449: }
1.28 raeburn 15450: }
15451: foreach my $type (@mailings) {
15452: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
15453: push(@{$changes{$type}},@{$newsetting{$type}});
15454: }
15455: if ($others{$type} ne '') {
15456: push(@{$changes{$type}},'others');
1.134 raeburn 15457: }
1.286 raeburn 15458: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15459: if ($bcc{$type} ne '') {
15460: push(@{$changes{$type}},'bcc');
15461: }
1.286 raeburn 15462: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
15463: push(@{$changes{$type}},'include');
15464: }
1.134 raeburn 15465: }
1.28 raeburn 15466: }
1.286 raeburn 15467: if (ref($fields) eq 'ARRAY') {
15468: foreach my $field (@{$fields}) {
15469: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
15470: push(@{$changes{'helpform'}},$field);
15471: }
15472: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
15473: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
15474: push(@{$changes{'helpform'}},'maxsize');
15475: }
15476: }
15477: }
1.289 raeburn 15478: }
1.340 raeburn 15479: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
15480: foreach my $key ('excluded','weights','threshold','sysmail') {
15481: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
15482: push(@{$changes{'lonstatus'}},$key);
15483: }
15484: }
15485: }
1.28 raeburn 15486: }
1.203 raeburn 15487: foreach my $item (@toggles) {
15488: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
15489: $changes{$item} = 1;
15490: } elsif ((!$env{'form.'.$item}) &&
15491: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
15492: $changes{$item} = 1;
15493: }
15494: }
1.28 raeburn 15495: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
15496: $dom);
15497: if ($putresult eq 'ok') {
15498: if (keys(%changes) > 0) {
1.205 raeburn 15499: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 15500: if (ref($lastactref) eq 'HASH') {
15501: $lastactref->{'domainconfig'} = 1;
15502: }
1.28 raeburn 15503: my ($titles,$short_titles) = &contact_titles();
15504: $resulttext = &mt('Changes made:').'<ul>';
15505: foreach my $item (@contacts) {
15506: if ($changes{$item}) {
15507: $resulttext .= '<li>'.$titles->{$item}.
15508: &mt(' set to: ').
15509: '<span class="LC_cusr_emph">'.
15510: $to{$item}.'</span></li>';
15511: }
15512: }
15513: foreach my $type (@mailings) {
15514: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 15515: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 15516: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 15517: } else {
15518: $resulttext .= '<li>'.$titles->{$type}.': ';
15519: }
1.28 raeburn 15520: my @text;
15521: foreach my $item (@{$newsetting{$type}}) {
15522: push(@text,$short_titles->{$item});
15523: }
15524: if ($others{$type} ne '') {
15525: push(@text,$others{$type});
15526: }
1.286 raeburn 15527: if (@text) {
15528: $resulttext .= '<span class="LC_cusr_emph">'.
15529: join(', ',@text).'</span>';
15530: }
15531: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15532: if ($bcc{$type} ne '') {
1.286 raeburn 15533: my $bcctext;
15534: if (@text) {
1.289 raeburn 15535: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 15536: } else {
15537: $bcctext = '(Bcc)';
15538: }
15539: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
15540: } elsif (!@text) {
15541: $resulttext .= &mt('No one');
15542: }
1.289 raeburn 15543: if ($includestr{$type} ne '') {
1.286 raeburn 15544: if ($includeloc{$type} eq 'b') {
15545: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
15546: } elsif ($includeloc{$type} eq 's') {
15547: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
15548: }
1.134 raeburn 15549: }
1.286 raeburn 15550: } elsif (!@text) {
15551: $resulttext .= &mt('No recipients');
1.134 raeburn 15552: }
15553: $resulttext .= '</li>';
1.28 raeburn 15554: }
15555: }
1.315 raeburn 15556: if (ref($changes{'overrides'}) eq 'ARRAY') {
15557: my @deletions;
15558: foreach my $type (@{$changes{'overrides'}}) {
15559: if ($usertypeshash{$type}) {
15560: if (grep(/^\Q$type\E/,@overrides)) {
15561: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
15562: $usertypeshash{$type}).'<ul><li>';
15563: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
15564: my @text;
15565: foreach my $item (@contacts) {
15566: if ($newsetting{'override_'.$type}{$item}) {
15567: push(@text,$short_titles->{$item});
15568: }
15569: }
15570: if ($newsetting{'override_'.$type}{'others'} ne '') {
15571: push(@text,$newsetting{'override_'.$type}{'others'});
15572: }
15573:
15574: if (@text) {
15575: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
15576: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
15577: }
15578: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
15579: my $bcctext;
15580: if (@text) {
15581: $bcctext = ' '.&mt('with Bcc to');
15582: } else {
15583: $bcctext = '(Bcc)';
15584: }
15585: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
15586: } elsif (!@text) {
15587: $resulttext .= &mt('Helpdesk e-mail sent to no one');
15588: }
15589: $resulttext .= '</li>';
15590: if ($newsetting{'override_'.$type}{'include'} ne '') {
15591: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
15592: if ($loc eq 'b') {
15593: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
15594: } elsif ($loc eq 's') {
15595: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
15596: }
15597: }
15598: }
15599: $resulttext .= '</li></ul></li>';
15600: } else {
15601: push(@deletions,$usertypeshash{$type});
15602: }
15603: }
15604: }
15605: if (@deletions) {
15606: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
15607: join(', ',@deletions)).'</li>';
15608: }
15609: }
1.203 raeburn 15610: my @offon = ('off','on');
1.340 raeburn 15611: my $corelink = &core_link_msu();
1.203 raeburn 15612: if ($changes{'reporterrors'}) {
15613: $resulttext .= '<li>'.
15614: &mt('E-mail error reports to [_1] set to "'.
15615: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 15616: $corelink).
1.203 raeburn 15617: '</li>';
15618: }
15619: if ($changes{'reportupdates'}) {
15620: $resulttext .= '<li>'.
15621: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
15622: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 15623: $corelink).
1.203 raeburn 15624: '</li>';
15625: }
1.340 raeburn 15626: if ($changes{'reportstatus'}) {
15627: $resulttext .= '<li>'.
15628: &mt('E-mail status if errors above threshold to [_1] set to "'.
15629: $offon[$env{'form.reportstatus'}].'".',
15630: $corelink).
15631: '</li>';
15632: }
15633: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
15634: $resulttext .= '<li>'.
15635: &mt('Nightly status check e-mail settings').':<ul>';
15636: my (%defval,%use_def,%shown);
15637: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
15638: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
15639: $defval{'weights'} =
1.341 raeburn 15640: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 15641: $defval{'excluded'} = &mt('None');
15642: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
15643: foreach my $item ('threshold','sysmail','weights','excluded') {
15644: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
15645: if (($item eq 'threshold') || ($item eq 'sysmail')) {
15646: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
15647: } elsif ($item eq 'weights') {
15648: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 15649: foreach my $type ('E','W','N','U') {
1.340 raeburn 15650: $shown{$item} .= $lonstatus_names->{$type}.'=';
15651: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
15652: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
15653: } else {
15654: $shown{$item} .= $lonstatus_defs->{$type};
15655: }
15656: $shown{$item} .= ', ';
15657: }
15658: $shown{$item} =~ s/, $//;
15659: } else {
15660: $shown{$item} = $defval{$item};
15661: }
15662: } elsif ($item eq 'excluded') {
15663: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
15664: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
15665: } else {
15666: $shown{$item} = $defval{$item};
15667: }
15668: }
15669: } else {
15670: $shown{$item} = $defval{$item};
15671: }
15672: }
15673: } else {
15674: foreach my $item ('threshold','weights','excluded','sysmail') {
15675: $shown{$item} = $defval{$item};
15676: }
15677: }
15678: foreach my $item ('threshold','weights','excluded','sysmail') {
15679: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
15680: $shown{$item}).'</li>';
15681: }
15682: $resulttext .= '</ul></li>';
15683: }
1.286 raeburn 15684: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
15685: my (@optional,@required,@unused,$maxsizechg);
15686: foreach my $field (@{$changes{'helpform'}}) {
15687: if ($field eq 'maxsize') {
15688: $maxsizechg = 1;
15689: next;
15690: }
15691: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 15692: push(@optional,$field);
1.286 raeburn 15693: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
15694: push(@unused,$field);
15695: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 15696: push(@required,$field);
1.286 raeburn 15697: }
15698: }
15699: if (@optional) {
15700: $resulttext .= '<li>'.
15701: &mt('Help form fields changed to "Optional": [_1].',
15702: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
15703: '</li>';
15704: }
15705: if (@required) {
15706: $resulttext .= '<li>'.
15707: &mt('Help form fields changed to "Required": [_1].',
15708: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
15709: '</li>';
15710: }
15711: if (@unused) {
15712: $resulttext .= '<li>'.
15713: &mt('Help form fields changed to "Not shown": [_1].',
15714: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
15715: '</li>';
15716: }
15717: if ($maxsizechg) {
15718: $resulttext .= '<li>'.
15719: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
15720: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
15721: '</li>';
15722: }
15723: }
1.28 raeburn 15724: $resulttext .= '</ul>';
15725: } else {
1.288 raeburn 15726: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 15727: }
15728: } else {
15729: $resulttext = '<span class="LC_error">'.
15730: &mt('An error occurred: [_1].',$putresult).'</span>';
15731: }
15732: return $resulttext;
15733: }
15734:
1.357 raeburn 15735: sub modify_privacy {
15736: my ($dom,%domconfig) = @_;
15737: my ($resulttext,%current,%changes);
15738: if (ref($domconfig{'privacy'}) eq 'HASH') {
15739: %current = %{$domconfig{'privacy'}};
15740: }
15741: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
15742: my @items = ('domain','author','course','community');
15743: my %names = &Apache::lonlocal::texthash (
15744: domain => 'Assigned domain role(s)',
15745: author => 'Assigned co-author role(s)',
15746: course => 'Assigned course role(s)',
15747: community => 'Assigned community role',
15748: );
15749: my %roles = &Apache::lonlocal::texthash (
15750: domain => 'Domain role',
15751: author => 'Co-author role',
15752: course => 'Course role',
15753: community => 'Community role',
15754: );
15755: my %titles = &Apache::lonlocal::texthash (
15756: approval => 'Approval for role in different domain',
15757: othdom => 'User information available in other domain',
15758: priv => 'Information viewable by privileged user in same domain',
15759: unpriv => 'Information viewable by unprivileged user in same domain',
15760: instdom => 'Other domain shares institution/provider',
15761: extdom => 'Other domain has different institution/provider',
15762: none => 'Not allowed',
15763: user => 'User authorizes',
15764: domain => 'Domain Coordinator authorizes',
15765: auto => 'Unrestricted',
15766: );
15767: my %fieldnames = &Apache::lonlocal::texthash (
15768: id => 'Student/Employee ID',
15769: permanentemail => 'E-mail address',
15770: lastname => 'Last Name',
15771: firstname => 'First Name',
15772: middlename => 'Middle Name',
15773: generation => 'Generation',
15774: );
15775: my ($othertitle,$usertypes,$types) =
15776: &Apache::loncommon::sorted_inst_types($dom);
15777: my (%by_ip,%by_location,@intdoms,@instdoms);
15778: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
15779:
15780: my %privacyhash = (
15781: 'approval' => {
15782: instdom => {},
15783: extdom => {},
15784: },
15785: 'othdom' => {},
15786: 'priv' => {},
15787: 'unpriv' => {},
15788: );
15789: foreach my $item (@items) {
15790: if (@instdoms > 1) {
15791: if ($env{'form.privacy_approval_instdom'.$item} =~ /^(none|user|domain|auto)$/) {
15792: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
15793: }
15794: if (ref($current{'approval'}) eq 'HASH') {
15795: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
15796: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
15797: $changes{'approval'} = 1;
15798: }
15799: }
15800: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
15801: $changes{'approval'} = 1;
15802: }
15803: }
15804: if (keys(%by_location) > 0) {
15805: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
15806: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
15807: }
15808: if (ref($current{'approval'}) eq 'HASH') {
15809: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
15810: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
15811: $changes{'approval'} = 1;
15812: }
15813: }
15814: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
15815: $changes{'approval'} = 1;
15816: }
15817: }
15818: foreach my $status ('priv','unpriv') {
15819: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
15820: my @newvalues;
15821: foreach my $field (@possibles) {
15822: if (grep(/^\Q$field\E$/,@fields)) {
15823: $privacyhash{$status}{$item}{$field} = 1;
15824: push(@newvalues,$field);
15825: }
15826: }
15827: @newvalues = sort(@newvalues);
15828: if (ref($current{$status}) eq 'HASH') {
15829: if (ref($current{$status}{$item}) eq 'HASH') {
15830: my @currvalues = sort(keys(%{$current{$status}{$item}}));
15831: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
15832: if (@diffs > 0) {
15833: $changes{$status} = 1;
15834: }
15835: }
15836: } else {
15837: my @stdfields;
15838: foreach my $field (@fields) {
15839: if ($field eq 'id') {
15840: next if ($status eq 'unpriv');
15841: next if (($status eq 'priv') && ($item eq 'community'));
15842: }
15843: push(@stdfields,$field);
15844: }
15845: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
15846: if (@diffs > 0) {
15847: $changes{$status} = 1;
15848: }
15849: }
15850: }
15851: }
15852: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
15853: my @statuses;
15854: if (ref($types) eq 'ARRAY') {
15855: @statuses = @{$types};
15856: }
15857: foreach my $type (@statuses,'default') {
15858: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
15859: my @newvalues;
15860: foreach my $field (sort(@possfields)) {
15861: if (grep(/^\Q$field\E$/,@fields)) {
15862: $privacyhash{'othdom'}{$type}{$field} = 1;
15863: push(@newvalues,$field);
15864: }
15865: }
15866: @newvalues = sort(@newvalues);
15867: if (ref($current{'othdom'}) eq 'HASH') {
15868: if (ref($current{'othdom'}{$type}) eq 'HASH') {
15869: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
15870: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
15871: if (@diffs > 0) {
15872: $changes{'othdom'} = 1;
15873: }
15874: }
15875: } else {
15876: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
15877: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
15878: if (@diffs > 0) {
15879: $changes{'othdom'} = 1;
15880: }
15881: }
15882: }
15883: }
15884: my %confighash = (
15885: privacy => \%privacyhash,
15886: );
15887: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
15888: if ($putresult eq 'ok') {
15889: if (keys(%changes) > 0) {
15890: $resulttext = &mt('Changes made: ').'<ul>';
15891: foreach my $key ('approval','othdom','priv','unpriv') {
15892: if ($changes{$key}) {
15893: $resulttext .= '<li>'.$titles{$key}.':<ul>';
15894: if ($key eq 'approval') {
15895: if (keys(%{$privacyhash{$key}{instdom}})) {
15896: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
15897: foreach my $item (@items) {
15898: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
15899: }
15900: $resulttext .= '</ul></li>';
15901: }
15902: if (keys(%{$privacyhash{$key}{extdom}})) {
15903: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
15904: foreach my $item (@items) {
15905: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
15906: }
15907: $resulttext .= '</ul></li>';
15908: }
15909: } elsif ($key eq 'othdom') {
15910: my @statuses;
15911: if (ref($types) eq 'ARRAY') {
15912: @statuses = @{$types};
15913: }
15914: if (ref($privacyhash{$key}) eq 'HASH') {
15915: foreach my $status (@statuses,'default') {
15916: if ($status eq 'default') {
15917: $resulttext .= '<li>'.$othertitle.': ';
15918: } elsif (ref($usertypes) eq 'HASH') {
15919: $resulttext .= '<li>'.$usertypes->{$status}.': ';
15920: } else {
15921: next;
15922: }
15923: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
15924: if (keys(%{$privacyhash{$key}{$status}})) {
15925: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
15926: } else {
15927: $resulttext .= &mt('none');
15928: }
15929: }
15930: $resulttext .= '</li>';
15931: }
15932: }
15933: } else {
15934: foreach my $item (@items) {
15935: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
15936: $resulttext .= '<li>'.$names{$item}.': ';
15937: if (keys(%{$privacyhash{$key}{$item}})) {
15938: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
15939: } else {
15940: $resulttext .= &mt('none');
15941: }
15942: $resulttext .= '</li>';
15943: }
15944: }
15945: }
15946: $resulttext .= '</ul></li>';
15947: }
15948: }
15949: } else {
15950: $resulttext = &mt('No changes made to user information settings');
15951: }
15952: } else {
15953: $resulttext = '<span class="LC_error">'.
15954: &mt('An error occurred: [_1]',$putresult).'</span>';
15955: }
15956: return $resulttext;
15957: }
15958:
1.354 raeburn 15959: sub modify_passwords {
15960: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 15961: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
15962: $updatedefaults,$updateconf);
1.354 raeburn 15963: my $customfn = 'resetpw.html';
15964: if (ref($domconfig{'passwords'}) eq 'HASH') {
15965: %current = %{$domconfig{'passwords'}};
15966: }
15967: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15968: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
15969: if (ref($types) eq 'ARRAY') {
15970: @oktypes = @{$types};
15971: }
15972: push(@oktypes,'default');
15973:
15974: my %titles = &Apache::lonlocal::texthash (
15975: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
15976: intauth_check => 'Check bcrypt cost if authenticated',
15977: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
15978: permanent => 'Permanent e-mail address',
15979: critical => 'Critical notification address',
15980: notify => 'Notification address',
15981: min => 'Minimum password length',
15982: max => 'Maximum password length',
15983: chars => 'Required characters',
15984: expire => 'Password expiration (days)',
1.356 raeburn 15985: numsaved => 'Number of previous passwords to save',
1.354 raeburn 15986: reset => 'Resetting Forgotten Password',
15987: intauth => 'Encryption of Stored Passwords (Internal Auth)',
15988: rules => 'Rules for LON-CAPA Passwords',
15989: crsownerchg => 'Course Owner Changing Student Passwords',
15990: username => 'Username',
15991: email => 'E-mail address',
15992: );
15993:
15994: #
15995: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
15996: #
15997: my (%curr_defaults,%save_defaults);
15998: if (ref($domconfig{'defaults'}) eq 'HASH') {
15999: foreach my $key (keys(%{$domconfig{'defaults'}})) {
16000: if ($key =~ /^intauth_(cost|check|switch)$/) {
16001: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
16002: } else {
16003: $save_defaults{$key} = $domconfig{'defaults'}{$key};
16004: }
16005: }
16006: }
16007: my %staticdefaults = (
16008: 'resetlink' => 2,
16009: 'resetcase' => \@oktypes,
16010: 'resetprelink' => 'both',
16011: 'resetemail' => ['critical','notify','permanent'],
16012: 'intauth_cost' => 10,
16013: 'intauth_check' => 0,
16014: 'intauth_switch' => 0,
16015: );
1.365 raeburn 16016: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 16017: foreach my $type (@oktypes) {
16018: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
16019: }
16020: my $linklife = $env{'form.passwords_link'};
16021: $linklife =~ s/^\s+|\s+$//g;
16022: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
16023: $newvalues{'resetlink'} = $linklife;
16024: if ($current{'resetlink'}) {
16025: if ($current{'resetlink'} ne $linklife) {
16026: $changes{'reset'} = 1;
16027: }
1.368 raeburn 16028: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16029: if ($staticdefaults{'resetlink'} ne $linklife) {
16030: $changes{'reset'} = 1;
16031: }
16032: }
16033: } elsif ($current{'resetlink'}) {
16034: $changes{'reset'} = 1;
16035: }
16036: my @casesens;
16037: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
16038: foreach my $case (sort(@posscase)) {
16039: if (grep(/^\Q$case\E$/,@oktypes)) {
16040: push(@casesens,$case);
16041: }
16042: }
16043: $newvalues{'resetcase'} = \@casesens;
16044: if (ref($current{'resetcase'}) eq 'ARRAY') {
16045: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
16046: if (@diffs > 0) {
16047: $changes{'reset'} = 1;
16048: }
1.368 raeburn 16049: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16050: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
16051: if (@diffs > 0) {
16052: $changes{'reset'} = 1;
16053: }
16054: }
16055: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
16056: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
16057: if (exists($current{'resetprelink'})) {
16058: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
16059: $changes{'reset'} = 1;
16060: }
1.368 raeburn 16061: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16062: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
16063: $changes{'reset'} = 1;
16064: }
16065: }
16066: } elsif ($current{'resetprelink'}) {
16067: $changes{'reset'} = 1;
16068: }
16069: foreach my $type (@oktypes) {
16070: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
16071: my @postlink;
16072: foreach my $item (sort(@possplink)) {
16073: if ($item =~ /^(email|username)$/) {
16074: push(@postlink,$item);
16075: }
16076: }
16077: $newvalues{'resetpostlink'}{$type} = \@postlink;
16078: unless ($changes{'reset'}) {
16079: if (ref($current{'resetpostlink'}) eq 'HASH') {
16080: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
16081: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
16082: if (@diffs > 0) {
16083: $changes{'reset'} = 1;
16084: }
16085: } else {
16086: $changes{'reset'} = 1;
16087: }
1.368 raeburn 16088: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16089: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
16090: if (@diffs > 0) {
16091: $changes{'reset'} = 1;
16092: }
16093: }
16094: }
16095: }
16096: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
16097: my @resetemail;
16098: foreach my $item (sort(@possemailsrc)) {
16099: if ($item =~ /^(permanent|critical|notify)$/) {
16100: push(@resetemail,$item);
16101: }
16102: }
16103: $newvalues{'resetemail'} = \@resetemail;
16104: unless ($changes{'reset'}) {
16105: if (ref($current{'resetemail'}) eq 'ARRAY') {
16106: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
16107: if (@diffs > 0) {
16108: $changes{'reset'} = 1;
16109: }
1.368 raeburn 16110: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16111: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
16112: if (@diffs > 0) {
16113: $changes{'reset'} = 1;
16114: }
16115: }
16116: }
16117: if ($env{'form.passwords_stdtext'} == 0) {
16118: $newvalues{'resetremove'} = 1;
16119: unless ($current{'resetremove'}) {
16120: $changes{'reset'} = 1;
16121: }
16122: } elsif ($current{'resetremove'}) {
16123: $changes{'reset'} = 1;
16124: }
16125: if ($env{'form.passwords_customfile.filename'} ne '') {
16126: my $servadm = $r->dir_config('lonAdmEMail');
16127: my ($configuserok,$author_ok,$switchserver) =
16128: &config_check($dom,$confname,$servadm);
16129: my $error;
16130: if ($configuserok eq 'ok') {
16131: if ($switchserver) {
16132: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
16133: } else {
16134: if ($author_ok eq 'ok') {
16135: my ($result,$customurl) =
16136: &publishlogo($r,'upload','passwords_customfile',$dom,
16137: $confname,'customtext/resetpw','','',$customfn);
16138: if ($result eq 'ok') {
16139: $newvalues{'resetcustom'} = $customurl;
16140: $changes{'reset'} = 1;
16141: } else {
16142: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
16143: }
16144: } else {
16145: $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);
16146: }
16147: }
16148: } else {
16149: $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);
16150: }
16151: if ($error) {
16152: &Apache::lonnet::logthis($error);
16153: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
16154: }
16155: } elsif ($current{'resetcustom'}) {
16156: if ($env{'form.passwords_custom_del'}) {
16157: $changes{'reset'} = 1;
16158: } else {
16159: $newvalues{'resetcustom'} = $current{'resetcustom'};
16160: }
16161: }
16162: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
16163: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
16164: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
16165: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
16166: $changes{'intauth'} = 1;
16167: }
16168: } else {
16169: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
16170: }
16171: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
16172: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
16173: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
16174: $changes{'intauth'} = 1;
16175: }
16176: } else {
16177: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
16178: }
16179: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
16180: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
16181: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
16182: $changes{'intauth'} = 1;
16183: }
16184: } else {
16185: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
16186: }
16187: foreach my $item ('cost','check','switch') {
16188: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
16189: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
16190: $updatedefaults = 1;
16191: }
16192: }
1.356 raeburn 16193: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 16194: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.356 raeburn 16195: my $ruleok;
16196: if ($rule eq 'expire') {
1.365 raeburn 16197: if (($env{'form.passwords_'.$rule} =~ /^\d+(|\.\d*)$/) &&
16198: ($env{'form.passwords_'.$rule} ne '0')) {
1.359 raeburn 16199: $ruleok = 1;
1.356 raeburn 16200: }
1.365 raeburn 16201: } elsif ($rule eq 'min') {
16202: if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
16203: if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
16204: $ruleok = 1;
16205: }
16206: }
16207: } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
16208: ($env{'form.passwords_'.$rule} ne '0')) {
1.356 raeburn 16209: $ruleok = 1;
16210: }
16211: if ($ruleok) {
1.354 raeburn 16212: $newvalues{$rule} = $env{'form.passwords_'.$rule};
16213: if (exists($current{$rule})) {
16214: if ($newvalues{$rule} ne $current{$rule}) {
16215: $changes{'rules'} = 1;
16216: }
16217: } elsif ($rule eq 'min') {
16218: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
16219: $changes{'rules'} = 1;
16220: }
1.370 raeburn 16221: } else {
16222: $changes{'rules'} = 1;
1.354 raeburn 16223: }
16224: } elsif (exists($current{$rule})) {
16225: $changes{'rules'} = 1;
16226: }
16227: }
16228: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
16229: my @chars;
16230: foreach my $item (sort(@posschars)) {
16231: if ($item =~ /^(uc|lc|num|spec)$/) {
16232: push(@chars,$item);
16233: }
16234: }
16235: $newvalues{'chars'} = \@chars;
16236: unless ($changes{'rules'}) {
16237: if (ref($current{'chars'}) eq 'ARRAY') {
16238: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
16239: if (@diffs > 0) {
16240: $changes{'rules'} = 1;
16241: }
16242: } else {
16243: if (@chars > 0) {
16244: $changes{'rules'} = 1;
16245: }
16246: }
16247: }
1.359 raeburn 16248: my %crsownerchg = (
16249: by => [],
16250: for => [],
16251: );
16252: foreach my $item ('by','for') {
16253: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
16254: foreach my $type (sort(@posstypes)) {
16255: if (grep(/^\Q$type\E$/,@oktypes)) {
16256: push(@{$crsownerchg{$item}},$type);
16257: }
16258: }
16259: }
16260: $newvalues{'crsownerchg'} = \%crsownerchg;
16261: if (ref($current{'crsownerchg'}) eq 'HASH') {
16262: foreach my $item ('by','for') {
16263: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
16264: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
16265: if (@diffs > 0) {
16266: $changes{'crsownerchg'} = 1;
16267: last;
16268: }
16269: }
16270: }
1.368 raeburn 16271: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 16272: foreach my $item ('by','for') {
16273: if (@{$crsownerchg{$item}} > 0) {
16274: $changes{'crsownerchg'} = 1;
16275: last;
16276: }
1.354 raeburn 16277: }
16278: }
16279:
16280: my %confighash = (
16281: defaults => \%save_defaults,
16282: passwords => \%newvalues,
16283: );
16284: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
16285:
16286: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
16287: if ($putresult eq 'ok') {
16288: if (keys(%changes) > 0) {
16289: $resulttext = &mt('Changes made: ').'<ul>';
16290: foreach my $key ('reset','intauth','rules','crsownerchg') {
16291: if ($changes{$key}) {
1.355 raeburn 16292: unless ($key eq 'intauth') {
16293: $updateconf = 1;
16294: }
1.354 raeburn 16295: $resulttext .= '<li>'.$titles{$key}.':<ul>';
16296: if ($key eq 'reset') {
16297: if ($confighash{'passwords'}{'captcha'} eq 'original') {
16298: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
16299: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
16300: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 16301: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
16302: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
16303: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
16304: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
16305: }
1.354 raeburn 16306: } else {
16307: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
16308: }
16309: if ($confighash{'passwords'}{'resetlink'}) {
16310: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
16311: } else {
16312: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
16313: &mt('Will default to 2 hours').'</li>';
16314: }
16315: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
16316: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
16317: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
16318: } else {
16319: my $casesens;
16320: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
16321: if ($type eq 'default') {
16322: $casesens .= $othertitle.', ';
16323: } elsif ($usertypes->{$type} ne '') {
16324: $casesens .= $usertypes->{$type}.', ';
16325: }
16326: }
16327: $casesens =~ s/\Q, \E$//;
16328: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
16329: }
16330: } else {
16331: $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>';
16332: }
16333: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
16334: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
16335: } else {
16336: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
16337: }
16338: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
16339: my $output;
16340: if (ref($types) eq 'ARRAY') {
16341: foreach my $type (@{$types}) {
16342: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
16343: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
16344: $output .= $usertypes->{$type}.' -- '.&mt('none');
16345: } else {
16346: $output .= $usertypes->{$type}.' -- '.
16347: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
16348: }
16349: }
16350: }
16351: }
16352: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
16353: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
16354: $output .= $othertitle.' -- '.&mt('none');
16355: } else {
16356: $output .= $othertitle.' -- '.
16357: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
16358: }
16359: }
16360: if ($output) {
16361: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
16362: } else {
16363: $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>';
16364: }
16365: } else {
16366: $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>';
16367: }
16368: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
16369: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
16370: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
16371: } else {
16372: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
16373: }
16374: } else {
16375: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA usedfor verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
16376: }
16377: if ($confighash{'passwords'}{'resetremove'}) {
16378: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
16379: } else {
16380: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
16381: }
16382: if ($confighash{'passwords'}{'resetcustom'}) {
16383: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 16384: &mt('custom text'),600,500,undef,undef,
16385: undef,undef,'background-color:#ffffff');
16386: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 16387: } else {
16388: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
16389: }
16390: } elsif ($key eq 'intauth') {
16391: foreach my $item ('cost','switch','check') {
16392: my $value = $save_defaults{$key.'_'.$item};
16393: if ($item eq 'switch') {
16394: my %optiondesc = &Apache::lonlocal::texthash (
16395: 0 => 'No',
16396: 1 => 'Yes',
16397: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
16398: );
16399: if ($value =~ /^(0|1|2)$/) {
16400: $value = $optiondesc{$value};
16401: } else {
16402: $value = &mt('none -- defaults to No');
16403: }
16404: } elsif ($item eq 'check') {
16405: my %optiondesc = &Apache::lonlocal::texthash (
16406: 0 => 'No',
16407: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
16408: 2 => 'Yes, disallow login if stored cost is less than domain default',
16409: );
16410: if ($value =~ /^(0|1|2)$/) {
16411: $value = $optiondesc{$value};
16412: } else {
16413: $value = &mt('none -- defaults to No');
16414: }
16415: }
16416: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
16417: }
16418: } elsif ($key eq 'rules') {
1.356 raeburn 16419: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 16420: if ($confighash{'passwords'}{$rule} eq '') {
16421: if ($rule eq 'min') {
1.356 raeburn 16422: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 16423: ' '.&mt('Default of [_1] will be used',
16424: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 16425: } else {
16426: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 16427: }
16428: } else {
16429: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
16430: }
16431: }
1.370 raeburn 16432: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
16433: if (@{$confighash{'passwords'}{'chars'}} > 0) {
16434: my %rulenames = &Apache::lonlocal::texthash(
16435: uc => 'At least one upper case letter',
16436: lc => 'At least one lower case letter',
16437: num => 'At least one number',
16438: spec => 'At least one non-alphanumeric',
16439: );
16440: my $needed = '<ul><li>'.
16441: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
16442: '</li></ul>';
16443: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
16444: } else {
16445: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
16446: }
16447: } else {
16448: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
16449: }
1.354 raeburn 16450: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 16451: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
16452: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
16453: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
16454: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
16455: } else {
16456: my %crsownerstr;
16457: foreach my $item ('by','for') {
16458: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
16459: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
16460: if ($type eq 'default') {
16461: $crsownerstr{$item} .= $othertitle.', ';
16462: } elsif ($usertypes->{$type} ne '') {
16463: $crsownerstr{$item} .= $usertypes->{$type}.', ';
16464: }
16465: }
16466: $crsownerstr{$item} =~ s/\Q, \E$//;
16467: }
16468: }
16469: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
16470: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
16471: }
1.354 raeburn 16472: } else {
1.359 raeburn 16473: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 16474: }
16475: }
16476: $resulttext .= '</ul></li>';
16477: }
16478: }
16479: $resulttext .= '</ul>';
16480: } else {
16481: $resulttext = &mt('No changes made to password settings');
16482: }
1.355 raeburn 16483: my $cachetime = 24*60*60;
1.354 raeburn 16484: if ($updatedefaults) {
16485: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16486: if (ref($lastactref) eq 'HASH') {
16487: $lastactref->{'domdefaults'} = 1;
16488: }
16489: }
1.355 raeburn 16490: if ($updateconf) {
16491: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
16492: if (ref($lastactref) eq 'HASH') {
16493: $lastactref->{'passwdconf'} = 1;
16494: }
16495: }
1.354 raeburn 16496: } else {
16497: $resulttext = '<span class="LC_error">'.
16498: &mt('An error occurred: [_1]',$putresult).'</span>';
16499: }
16500: if ($errors) {
16501: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
16502: $errors.'</ul></p>';
16503: }
16504: return $resulttext;
16505: }
16506:
1.28 raeburn 16507: sub modify_usercreation {
1.27 raeburn 16508: my ($dom,%domconfig) = @_;
1.224 raeburn 16509: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 16510: my $warningmsg;
1.27 raeburn 16511: if (ref($domconfig{'usercreation'}) eq 'HASH') {
16512: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 16513: if ($key eq 'cancreate') {
16514: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
16515: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 16516: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
16517: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
16518: } else {
1.224 raeburn 16519: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
16520: }
16521: }
16522: }
16523: } elsif ($key eq 'email_rule') {
16524: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
16525: } else {
16526: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
16527: }
1.27 raeburn 16528: }
16529: }
16530: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 16531: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 16532: my @contexts = ('author','course','requestcrs');
1.34 raeburn 16533: foreach my $item(@contexts) {
1.224 raeburn 16534: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 16535: }
1.34 raeburn 16536: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
16537: foreach my $item (@contexts) {
1.224 raeburn 16538: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
16539: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 16540: }
1.27 raeburn 16541: }
1.34 raeburn 16542: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
16543: foreach my $item (@contexts) {
1.43 raeburn 16544: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 16545: if ($cancreate{$item} ne 'any') {
16546: push(@{$changes{'cancreate'}},$item);
16547: }
16548: } else {
16549: if ($cancreate{$item} ne 'none') {
16550: push(@{$changes{'cancreate'}},$item);
16551: }
1.27 raeburn 16552: }
16553: }
16554: } else {
1.43 raeburn 16555: foreach my $item (@contexts) {
1.34 raeburn 16556: push(@{$changes{'cancreate'}},$item);
16557: }
1.27 raeburn 16558: }
1.34 raeburn 16559:
1.27 raeburn 16560: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
16561: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
16562: if (!grep(/^\Q$type\E$/,@username_rule)) {
16563: push(@{$changes{'username_rule'}},$type);
16564: }
16565: }
16566: foreach my $type (@username_rule) {
16567: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
16568: push(@{$changes{'username_rule'}},$type);
16569: }
16570: }
16571: } else {
16572: push(@{$changes{'username_rule'}},@username_rule);
16573: }
16574:
1.32 raeburn 16575: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
16576: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
16577: if (!grep(/^\Q$type\E$/,@id_rule)) {
16578: push(@{$changes{'id_rule'}},$type);
16579: }
16580: }
16581: foreach my $type (@id_rule) {
16582: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
16583: push(@{$changes{'id_rule'}},$type);
16584: }
16585: }
16586: } else {
16587: push(@{$changes{'id_rule'}},@id_rule);
16588: }
16589:
1.43 raeburn 16590: my @authen_contexts = ('author','course','domain');
1.325 raeburn 16591: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 16592: my %authhash;
1.43 raeburn 16593: foreach my $item (@authen_contexts) {
1.28 raeburn 16594: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
16595: foreach my $auth (@authtypes) {
16596: if (grep(/^\Q$auth\E$/,@authallowed)) {
16597: $authhash{$item}{$auth} = 1;
16598: } else {
16599: $authhash{$item}{$auth} = 0;
16600: }
16601: }
16602: }
16603: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 16604: foreach my $item (@authen_contexts) {
1.28 raeburn 16605: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
16606: foreach my $auth (@authtypes) {
16607: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
16608: push(@{$changes{'authtypes'}},$item);
16609: last;
16610: }
16611: }
16612: }
16613: }
16614: } else {
1.43 raeburn 16615: foreach my $item (@authen_contexts) {
1.28 raeburn 16616: push(@{$changes{'authtypes'}},$item);
16617: }
16618: }
16619:
1.224 raeburn 16620: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
16621: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
16622: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
16623: $save_usercreate{'id_rule'} = \@id_rule;
16624: $save_usercreate{'username_rule'} = \@username_rule,
16625: $save_usercreate{'authtypes'} = \%authhash;
16626:
1.27 raeburn 16627: my %usercreation_hash = (
1.224 raeburn 16628: usercreation => \%save_usercreate,
16629: );
1.27 raeburn 16630:
16631: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
16632: $dom);
1.50 raeburn 16633:
1.224 raeburn 16634: if ($putresult eq 'ok') {
16635: if (keys(%changes) > 0) {
16636: $resulttext = &mt('Changes made:').'<ul>';
16637: if (ref($changes{'cancreate'}) eq 'ARRAY') {
16638: my %lt = &usercreation_types();
16639: foreach my $type (@{$changes{'cancreate'}}) {
16640: my $chgtext = $lt{$type}.', ';
16641: if ($cancreate{$type} eq 'none') {
16642: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
16643: } elsif ($cancreate{$type} eq 'any') {
16644: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
16645: } elsif ($cancreate{$type} eq 'official') {
16646: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
16647: } elsif ($cancreate{$type} eq 'unofficial') {
16648: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
16649: }
16650: $resulttext .= '<li>'.$chgtext.'</li>';
16651: }
16652: }
16653: if (ref($changes{'username_rule'}) eq 'ARRAY') {
16654: my ($rules,$ruleorder) =
16655: &Apache::lonnet::inst_userrules($dom,'username');
16656: my $chgtext = '<ul>';
16657: foreach my $type (@username_rule) {
16658: if (ref($rules->{$type}) eq 'HASH') {
16659: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
16660: }
16661: }
16662: $chgtext .= '</ul>';
16663: if (@username_rule > 0) {
16664: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
16665: } else {
16666: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
16667: }
16668: }
16669: if (ref($changes{'id_rule'}) eq 'ARRAY') {
16670: my ($idrules,$idruleorder) =
16671: &Apache::lonnet::inst_userrules($dom,'id');
16672: my $chgtext = '<ul>';
16673: foreach my $type (@id_rule) {
16674: if (ref($idrules->{$type}) eq 'HASH') {
16675: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
16676: }
16677: }
16678: $chgtext .= '</ul>';
16679: if (@id_rule > 0) {
16680: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
16681: } else {
16682: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
16683: }
16684: }
16685: my %authname = &authtype_names();
16686: my %context_title = &context_names();
16687: if (ref($changes{'authtypes'}) eq 'ARRAY') {
16688: my $chgtext = '<ul>';
16689: foreach my $type (@{$changes{'authtypes'}}) {
16690: my @allowed;
16691: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
16692: foreach my $auth (@authtypes) {
16693: if ($authhash{$type}{$auth}) {
16694: push(@allowed,$authname{$auth});
16695: }
16696: }
16697: if (@allowed > 0) {
16698: $chgtext .= join(', ',@allowed).'</li>';
16699: } else {
16700: $chgtext .= &mt('none').'</li>';
16701: }
16702: }
16703: $chgtext .= '</ul>';
16704: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
16705: $resulttext .= '</li>';
16706: }
16707: $resulttext .= '</ul>';
16708: } else {
16709: $resulttext = &mt('No changes made to user creation settings');
16710: }
16711: } else {
16712: $resulttext = '<span class="LC_error">'.
16713: &mt('An error occurred: [_1]',$putresult).'</span>';
16714: }
16715: if ($warningmsg ne '') {
16716: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
16717: }
16718: return $resulttext;
16719: }
16720:
16721: sub modify_selfcreation {
1.305 raeburn 16722: my ($dom,$lastactref,%domconfig) = @_;
16723: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
16724: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
16725: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 16726: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
16727: if (ref($typesref) eq 'ARRAY') {
16728: @types = @{$typesref};
16729: }
16730: if (ref($usertypesref) eq 'HASH') {
16731: %usertypes = %{$usertypesref};
1.228 raeburn 16732: }
1.303 raeburn 16733: $usertypes{'default'} = $othertitle;
1.224 raeburn 16734: #
16735: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
16736: #
16737: if (ref($domconfig{'usercreation'}) eq 'HASH') {
16738: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
16739: if ($key eq 'cancreate') {
16740: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
16741: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
16742: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 16743: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
16744: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
16745: ($item eq 'emailusername') || ($item eq 'shibenv') ||
16746: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 16747: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 16748: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
16749: } else {
16750: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
16751: }
16752: }
16753: }
16754: } elsif ($key eq 'email_rule') {
16755: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
16756: } else {
16757: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
16758: }
16759: }
16760: }
16761: #
16762: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
16763: #
16764: if (ref($domconfig{'usermodification'}) eq 'HASH') {
16765: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
16766: if ($key eq 'selfcreate') {
16767: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
16768: } else {
16769: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
16770: }
16771: }
16772: }
1.305 raeburn 16773: #
16774: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
16775: #
16776: if (ref($domconfig{'inststatus'}) eq 'HASH') {
16777: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
16778: if ($key eq 'inststatusguest') {
16779: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
16780: } else {
16781: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
16782: }
16783: }
16784: }
1.224 raeburn 16785:
16786: my @contexts = ('selfcreate');
16787: @{$cancreate{'selfcreate'}} = ();
16788: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 16789: if (@types) {
16790: @{$cancreate{'statustocreate'}} = ();
16791: }
1.236 raeburn 16792: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 16793: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 16794: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 16795: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 16796: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 16797: my %selfcreatetypes = (
16798: sso => 'users authenticated by institutional single sign on',
16799: login => 'users authenticated by institutional log-in',
1.303 raeburn 16800: email => 'users verified by e-mail',
1.50 raeburn 16801: );
1.224 raeburn 16802: #
16803: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
16804: # is permitted.
16805: #
1.305 raeburn 16806: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 16807:
1.305 raeburn 16808: my (@statuses,%email_rule);
1.228 raeburn 16809: foreach my $item ('login','sso','email') {
1.224 raeburn 16810: if ($item eq 'email') {
1.236 raeburn 16811: if ($env{'form.cancreate_email'}) {
1.305 raeburn 16812: if (@types) {
16813: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
16814: foreach my $status (@poss_statuses) {
16815: if (grep(/^\Q$status\E$/,(@types,'default'))) {
16816: push(@statuses,$status);
16817: }
16818: }
16819: $save_inststatus{'inststatusguest'} = \@statuses;
16820: } else {
16821: push(@statuses,'default');
16822: }
16823: if (@statuses) {
16824: my %curr_rule;
16825: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
16826: foreach my $type (@statuses) {
16827: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 16828: }
1.305 raeburn 16829: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
16830: foreach my $type (@statuses) {
16831: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
16832: }
16833: }
16834: push(@{$cancreate{'selfcreate'}},'email');
16835: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
16836: my %curremaildom;
16837: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
16838: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
16839: }
16840: foreach my $type (@statuses) {
16841: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
16842: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
16843: }
16844: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
16845: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
16846: }
16847: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
16848: #
16849: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
16850: #
16851: my $chosen = $1;
16852: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
16853: my $emaildom;
16854: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
16855: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
16856: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
16857: if (ref($curremaildom{$type}) eq 'HASH') {
16858: if (exists($curremaildom{$type}{$chosen})) {
16859: if ($curremaildom{$type}{$chosen} ne $emaildom) {
16860: push(@{$changes{'cancreate'}},'emaildomain');
16861: }
16862: } elsif ($emaildom ne '') {
16863: push(@{$changes{'cancreate'}},'emaildomain');
16864: }
16865: } elsif ($emaildom ne '') {
16866: push(@{$changes{'cancreate'}},'emaildomain');
16867: }
16868: }
16869: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
16870: } elsif ($chosen eq 'custom') {
16871: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
16872: $email_rule{$type} = [];
16873: if (ref($emailrules) eq 'HASH') {
16874: foreach my $rule (@possemail_rules) {
16875: if (exists($emailrules->{$rule})) {
16876: push(@{$email_rule{$type}},$rule);
16877: }
16878: }
16879: }
16880: if (@{$email_rule{$type}}) {
16881: $cancreate{'emailoptions'}{$type} = 'custom';
16882: if (ref($curr_rule{$type}) eq 'ARRAY') {
16883: if (@{$curr_rule{$type}} > 0) {
16884: foreach my $rule (@{$curr_rule{$type}}) {
16885: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
16886: push(@{$changes{'email_rule'}},$type);
16887: }
16888: }
16889: }
16890: foreach my $type (@{$email_rule{$type}}) {
16891: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
16892: push(@{$changes{'email_rule'}},$type);
16893: }
16894: }
16895: } else {
16896: push(@{$changes{'email_rule'}},$type);
16897: }
16898: }
16899: } else {
16900: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
16901: }
16902: }
16903: }
16904: if (@types) {
16905: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
16906: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
16907: if (@changed) {
16908: push(@{$changes{'inststatus'}},'inststatusguest');
16909: }
16910: } else {
16911: push(@{$changes{'inststatus'}},'inststatusguest');
16912: }
16913: }
16914: } else {
16915: delete($env{'form.cancreate_email'});
16916: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
16917: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
16918: push(@{$changes{'inststatus'}},'inststatusguest');
16919: }
16920: }
16921: }
16922: } else {
16923: $save_inststatus{'inststatusguest'} = [];
16924: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
16925: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
16926: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 16927: }
16928: }
1.224 raeburn 16929: }
16930: } else {
16931: if ($env{'form.cancreate_'.$item}) {
16932: push(@{$cancreate{'selfcreate'}},$item);
16933: }
16934: }
16935: }
1.305 raeburn 16936: my (%userinfo,%savecaptcha);
1.224 raeburn 16937: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
16938: #
1.228 raeburn 16939: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
16940: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 16941: #
1.236 raeburn 16942:
1.244 raeburn 16943: if ($env{'form.cancreate_email'}) {
1.228 raeburn 16944: push(@contexts,'emailusername');
1.305 raeburn 16945: if (@statuses) {
16946: foreach my $type (@statuses) {
1.228 raeburn 16947: if (ref($infofields) eq 'ARRAY') {
16948: foreach my $field (@{$infofields}) {
16949: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
16950: $cancreate{'emailusername'}{$type}{$field} = $1;
16951: }
16952: }
1.224 raeburn 16953: }
16954: }
16955: }
16956: #
16957: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 16958: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 16959: #
16960:
16961: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
16962: @approvalnotify = sort(@approvalnotify);
16963: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
16964: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
16965: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
16966: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
16967: push(@{$changes{'cancreate'}},'notify');
16968: }
16969: } else {
16970: if ($cancreate{'notify'}{'approval'}) {
16971: push(@{$changes{'cancreate'}},'notify');
16972: }
16973: }
16974: } elsif ($cancreate{'notify'}{'approval'}) {
16975: push(@{$changes{'cancreate'}},'notify');
16976: }
16977:
16978: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
16979: }
16980: #
1.236 raeburn 16981: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 16982: # institutional log-in.
16983: #
16984: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
16985: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
16986: ($domdefaults{'auth_def'} eq 'localauth'))) {
16987: $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.').' '.
16988: &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.');
16989: }
16990: }
16991: my @fields = ('lastname','firstname','middlename','generation',
16992: 'permanentemail','id');
1.240 raeburn 16993: my @shibfields = (@fields,'inststatus');
1.224 raeburn 16994: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
16995: #
16996: # Where usernames may created for institutional log-in and/or institutional single sign on:
16997: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
16998: # may self-create accounts
16999: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
17000: # which the user may supply, if institutional data is unavailable.
17001: #
17002: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 17003: if (@types) {
1.305 raeburn 17004: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
17005: push(@contexts,'statustocreate');
1.303 raeburn 17006: foreach my $type (@types) {
1.224 raeburn 17007: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
17008: foreach my $field (@fields) {
17009: if (grep(/^\Q$field\E$/,@modifiable)) {
17010: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
17011: } else {
17012: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
17013: }
17014: }
17015: }
17016: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 17017: foreach my $type (@types) {
1.224 raeburn 17018: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
17019: foreach my $field (@fields) {
17020: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
17021: $curr_usermodify{'selfcreate'}{$type}{$field}) {
17022: push(@{$changes{'selfcreate'}},$type);
17023: last;
17024: }
17025: }
17026: }
17027: }
17028: } else {
1.303 raeburn 17029: foreach my $type (@types) {
1.224 raeburn 17030: push(@{$changes{'selfcreate'}},$type);
17031: }
17032: }
17033: }
1.240 raeburn 17034: foreach my $field (@shibfields) {
17035: if ($env{'form.shibenv_'.$field} ne '') {
17036: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
17037: }
17038: }
17039: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
17040: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
17041: foreach my $field (@shibfields) {
17042: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
17043: push(@{$changes{'cancreate'}},'shibenv');
17044: }
17045: }
17046: } else {
17047: foreach my $field (@shibfields) {
17048: if ($env{'form.shibenv_'.$field}) {
17049: push(@{$changes{'cancreate'}},'shibenv');
17050: last;
17051: }
17052: }
17053: }
17054: }
1.224 raeburn 17055: }
17056: foreach my $item (@contexts) {
17057: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
17058: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
17059: if (ref($cancreate{$item}) eq 'ARRAY') {
17060: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
17061: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17062: push(@{$changes{'cancreate'}},$item);
17063: }
17064: }
17065: }
17066: }
17067: if (ref($cancreate{$item}) eq 'ARRAY') {
17068: foreach my $type (@{$cancreate{$item}}) {
17069: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
17070: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17071: push(@{$changes{'cancreate'}},$item);
17072: }
17073: }
17074: }
17075: }
17076: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
17077: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 17078: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
17079: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
17080: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
17081: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 17082: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17083: push(@{$changes{'cancreate'}},$item);
17084: }
17085: }
17086: }
1.305 raeburn 17087: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17088: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 17089: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17090: push(@{$changes{'cancreate'}},$item);
17091: }
1.224 raeburn 17092: }
17093: }
17094: }
1.305 raeburn 17095: foreach my $type (keys(%{$cancreate{$item}})) {
17096: if (ref($cancreate{$item}{$type}) eq 'HASH') {
17097: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
17098: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
17099: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 17100: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17101: push(@{$changes{'cancreate'}},$item);
17102: }
17103: }
17104: } else {
17105: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17106: push(@{$changes{'cancreate'}},$item);
17107: }
17108: }
17109: }
1.305 raeburn 17110: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17111: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 17112: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17113: push(@{$changes{'cancreate'}},$item);
17114: }
1.224 raeburn 17115: }
17116: }
17117: }
17118: }
17119: } elsif ($curr_usercreation{'cancreate'}{$item}) {
17120: if (ref($cancreate{$item}) eq 'ARRAY') {
17121: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
17122: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17123: push(@{$changes{'cancreate'}},$item);
17124: }
17125: }
1.305 raeburn 17126: }
17127: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17128: if (ref($cancreate{$item}) eq 'HASH') {
17129: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17130: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 17131: }
17132: }
17133: } elsif ($item eq 'emailusername') {
1.228 raeburn 17134: if (ref($cancreate{$item}) eq 'HASH') {
17135: foreach my $type (keys(%{$cancreate{$item}})) {
17136: if (ref($cancreate{$item}{$type}) eq 'HASH') {
17137: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
17138: if ($cancreate{$item}{$type}{$field}) {
17139: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17140: push(@{$changes{'cancreate'}},$item);
17141: }
17142: last;
17143: }
17144: }
17145: }
17146: }
1.224 raeburn 17147: }
17148: }
17149: }
17150: #
17151: # Populate %save_usercreate hash with updates to self-creation configuration.
17152: #
17153: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
17154: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 17155: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 17156: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
17157: if (ref($cancreate{'notify'}) eq 'HASH') {
17158: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
17159: }
1.236 raeburn 17160: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
17161: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
17162: }
1.303 raeburn 17163: if (ref($cancreate{'emailverified'}) eq 'HASH') {
17164: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
17165: }
1.305 raeburn 17166: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
17167: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
17168: }
1.303 raeburn 17169: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
17170: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
17171: }
1.224 raeburn 17172: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
17173: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
17174: }
1.240 raeburn 17175: if (ref($cancreate{'shibenv'}) eq 'HASH') {
17176: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
17177: }
1.224 raeburn 17178: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 17179: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 17180:
17181: my %userconfig_hash = (
17182: usercreation => \%save_usercreate,
17183: usermodification => \%save_usermodify,
1.305 raeburn 17184: inststatus => \%save_inststatus,
1.224 raeburn 17185: );
1.305 raeburn 17186:
1.224 raeburn 17187: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
17188: $dom);
17189: #
1.305 raeburn 17190: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 17191: #
1.27 raeburn 17192: if ($putresult eq 'ok') {
17193: if (keys(%changes) > 0) {
17194: $resulttext = &mt('Changes made:').'<ul>';
17195: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 17196: my %lt = &selfcreation_types();
1.34 raeburn 17197: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 17198: my $chgtext = '';
1.45 raeburn 17199: if ($type eq 'selfcreate') {
1.50 raeburn 17200: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 17201: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 17202: } else {
1.224 raeburn 17203: $chgtext .= &mt('Self-creation of a new account is permitted for:').
17204: '<ul>';
1.50 raeburn 17205: foreach my $case (@{$cancreate{$type}}) {
17206: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
17207: }
17208: $chgtext .= '</ul>';
1.100 raeburn 17209: if (ref($cancreate{$type}) eq 'ARRAY') {
17210: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
17211: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
17212: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 17213: $chgtext .= '<span class="LC_warning">'.
17214: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
17215: '</span><br />';
17216: }
17217: }
17218: }
17219: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 17220: if (!@statuses) {
17221: $chgtext .= '<span class="LC_warning">'.
17222: &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.").
17223: '</span><br />';
1.303 raeburn 17224:
1.100 raeburn 17225: }
17226: }
17227: }
1.43 raeburn 17228: }
1.240 raeburn 17229: } elsif ($type eq 'shibenv') {
17230: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 17231: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 17232: } else {
17233: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
17234: '<ul>';
17235: foreach my $field (@shibfields) {
17236: next if ($cancreate{$type}{$field} eq '');
17237: if ($field eq 'inststatus') {
17238: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
17239: } else {
17240: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
17241: }
17242: }
17243: $chgtext .= '</ul>';
1.303 raeburn 17244: }
1.93 raeburn 17245: } elsif ($type eq 'statustocreate') {
1.96 raeburn 17246: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
17247: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
17248: if (@{$cancreate{'selfcreate'}} > 0) {
17249: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 17250: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 17251: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 17252: $chgtext .= '<br />'.
17253: '<span class="LC_warning">'.
17254: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
17255: '</span>';
17256: }
1.303 raeburn 17257: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 17258: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 17259: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
17260: } else {
17261: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
17262: }
17263: $chgtext .= '<ul>';
17264: foreach my $case (@{$cancreate{$type}}) {
17265: if ($case eq 'default') {
17266: $chgtext .= '<li>'.$othertitle.'</li>';
17267: } else {
1.303 raeburn 17268: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 17269: }
17270: }
1.100 raeburn 17271: $chgtext .= '</ul>';
17272: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 17273: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 17274: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
17275: '</span>';
1.100 raeburn 17276: }
17277: }
17278: } else {
17279: if (@{$cancreate{$type}} == 0) {
17280: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
17281: } else {
17282: $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 17283: }
17284: }
1.303 raeburn 17285: $chgtext .= '<br />';
1.93 raeburn 17286: }
1.236 raeburn 17287: } elsif ($type eq 'selfcreateprocessing') {
17288: my %choices = &Apache::lonlocal::texthash (
17289: automatic => 'Automatic approval',
17290: approval => 'Queued for approval',
17291: );
1.305 raeburn 17292: if (@types) {
17293: if (@statuses) {
1.303 raeburn 17294: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 17295: '<ul>';
1.305 raeburn 17296: foreach my $status (@statuses) {
17297: if ($status eq 'default') {
17298: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 17299: } else {
1.305 raeburn 17300: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 17301: }
17302: }
17303: $chgtext .= '</ul>';
17304: }
17305: } else {
17306: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
17307: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
17308: }
17309: } elsif ($type eq 'emailverified') {
17310: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 17311: all => 'Same as e-mail',
17312: first => 'Omit @domain',
17313: free => 'Free to choose',
1.303 raeburn 17314: );
1.305 raeburn 17315: if (@types) {
17316: if (@statuses) {
1.303 raeburn 17317: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
17318: '<ul>';
1.305 raeburn 17319: foreach my $status (@statuses) {
1.362 raeburn 17320: if ($status eq 'default') {
1.305 raeburn 17321: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 17322: } else {
1.305 raeburn 17323: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 17324: }
17325: }
17326: $chgtext .= '</ul>';
17327: }
17328: } else {
1.305 raeburn 17329: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 17330: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 17331: }
1.305 raeburn 17332: } elsif ($type eq 'emailoptions') {
17333: my %options = &Apache::lonlocal::texthash (
17334: any => 'Any e-mail',
17335: inst => 'Institutional only',
17336: noninst => 'Non-institutional only',
17337: custom => 'Custom restrictions',
17338: );
17339: if (@types) {
17340: if (@statuses) {
17341: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
17342: '<ul>';
17343: foreach my $status (@statuses) {
17344: if ($type eq 'default') {
17345: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
17346: } else {
17347: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 17348: }
17349: }
1.305 raeburn 17350: $chgtext .= '</ul>';
17351: }
17352: } else {
17353: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
17354: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
17355: } else {
17356: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
17357: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 17358: }
1.305 raeburn 17359: }
17360: } elsif ($type eq 'emaildomain') {
17361: my $output;
17362: if (@statuses) {
17363: foreach my $type (@statuses) {
17364: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
17365: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
17366: if ($type eq 'default') {
17367: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17368: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
17369: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
17370: } else {
17371: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
17372: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
17373: }
1.303 raeburn 17374: } else {
1.305 raeburn 17375: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17376: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
17377: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
17378: } else {
17379: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
17380: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
17381: }
1.303 raeburn 17382: }
1.305 raeburn 17383: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
17384: if ($type eq 'default') {
17385: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17386: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
17387: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
17388: } else {
17389: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
17390: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
17391: }
1.303 raeburn 17392: } else {
1.305 raeburn 17393: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17394: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
17395: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
17396: } else {
17397: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
17398: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
17399: }
1.303 raeburn 17400: }
17401: }
17402: }
17403: }
1.305 raeburn 17404: }
17405: if ($output ne '') {
17406: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
17407: '<ul>'.$output.'</ul>';
1.236 raeburn 17408: }
1.165 raeburn 17409: } elsif ($type eq 'captcha') {
1.224 raeburn 17410: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 17411: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
17412: } else {
17413: my %captchas = &captcha_phrases();
1.224 raeburn 17414: if ($captchas{$savecaptcha{$type}}) {
17415: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 17416: } else {
1.210 raeburn 17417: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 17418: }
17419: }
17420: } elsif ($type eq 'recaptchakeys') {
17421: my ($privkey,$pubkey);
1.224 raeburn 17422: if (ref($savecaptcha{$type}) eq 'HASH') {
17423: $pubkey = $savecaptcha{$type}{'public'};
17424: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 17425: }
17426: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
17427: if (!$pubkey) {
17428: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
17429: } else {
17430: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
17431: }
17432: if (!$privkey) {
17433: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
17434: } else {
17435: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
17436: }
17437: $chgtext .= '</ul>';
1.269 raeburn 17438: } elsif ($type eq 'recaptchaversion') {
17439: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 17440: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 17441: }
1.224 raeburn 17442: } elsif ($type eq 'emailusername') {
17443: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 17444: if (@statuses) {
17445: foreach my $type (@statuses) {
1.228 raeburn 17446: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
17447: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 17448: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 17449: '<ul>';
17450: foreach my $field (@{$infofields}) {
17451: if ($cancreate{'emailusername'}{$type}{$field}) {
17452: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
17453: }
17454: }
1.245 raeburn 17455: $chgtext .= '</ul>';
17456: } else {
1.303 raeburn 17457: $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 17458: }
17459: } else {
1.303 raeburn 17460: $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 17461: }
17462: }
17463: }
17464: }
17465: } elsif ($type eq 'notify') {
1.303 raeburn 17466: my $numapprove = 0;
1.224 raeburn 17467: if (ref($changes{'cancreate'}) eq 'ARRAY') {
17468: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
17469: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 17470: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
17471: $numapprove ++;
1.224 raeburn 17472: }
17473: }
1.43 raeburn 17474: }
1.303 raeburn 17475: unless ($numapprove) {
17476: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
17477: }
1.34 raeburn 17478: }
1.224 raeburn 17479: if ($chgtext) {
17480: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 17481: }
17482: }
17483: }
1.305 raeburn 17484: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 17485: my ($emailrules,$emailruleorder) =
17486: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 17487: foreach my $type (@{$changes{'email_rule'}}) {
17488: if (ref($email_rule{$type}) eq 'ARRAY') {
17489: my $chgtext = '<ul>';
17490: foreach my $rule (@{$email_rule{$type}}) {
17491: if (ref($emailrules->{$rule}) eq 'HASH') {
17492: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
17493: }
17494: }
17495: $chgtext .= '</ul>';
1.310 raeburn 17496: my $typename;
1.305 raeburn 17497: if (@types) {
17498: if ($type eq 'default') {
17499: $typename = $othertitle;
17500: } else {
17501: $typename = $usertypes{$type};
17502: }
17503: $chgtext .= &mt('(Affiliation: [_1])',$typename);
17504: }
17505: if (@{$email_rule{$type}} > 0) {
17506: $resulttext .= '<li>'.
17507: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
17508: $usertypes{$type}).
17509: $chgtext.
17510: '</li>';
17511: } else {
17512: $resulttext .= '<li>'.
1.310 raeburn 17513: &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 17514: '</li>'.
1.310 raeburn 17515: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 17516: }
1.43 raeburn 17517: }
17518: }
1.305 raeburn 17519: }
17520: if (ref($changes{'inststatus'}) eq 'ARRAY') {
17521: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
17522: if (@{$save_inststatus{'inststatusguest'}} > 0) {
17523: my $chgtext = '<ul>';
17524: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
17525: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
17526: }
17527: $chgtext .= '</ul>';
17528: $resulttext .= '<li>'.
17529: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
17530: $chgtext.
17531: '</li>';
17532: } else {
17533: $resulttext .= '<li>'.
17534: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
17535: '</li>';
17536: }
1.43 raeburn 17537: }
17538: }
1.224 raeburn 17539: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
17540: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
17541: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
17542: foreach my $type (@{$changes{'selfcreate'}}) {
17543: my $typename = $type;
1.303 raeburn 17544: if (keys(%usertypes) > 0) {
17545: if ($usertypes{$type} ne '') {
17546: $typename = $usertypes{$type};
1.224 raeburn 17547: }
17548: }
17549: my @modifiable;
17550: $resulttext .= '<li>'.
17551: &mt('Self-creation of account by users with status: [_1]',
17552: '<span class="LC_cusr_emph">'.$typename.'</span>').
17553: ' - '.&mt('modifiable fields (if institutional data blank): ');
17554: foreach my $field (@fields) {
17555: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
17556: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 17557: }
17558: }
1.224 raeburn 17559: if (@modifiable > 0) {
17560: $resulttext .= join(', ',@modifiable);
1.43 raeburn 17561: } else {
1.224 raeburn 17562: $resulttext .= &mt('none');
1.43 raeburn 17563: }
1.224 raeburn 17564: $resulttext .= '</li>';
1.28 raeburn 17565: }
1.224 raeburn 17566: $resulttext .= '</ul></li>';
1.28 raeburn 17567: }
1.27 raeburn 17568: $resulttext .= '</ul>';
1.305 raeburn 17569: my $cachetime = 24*60*60;
17570: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
17571: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17572: if (ref($lastactref) eq 'HASH') {
17573: $lastactref->{'domdefaults'} = 1;
17574: }
1.27 raeburn 17575: } else {
1.224 raeburn 17576: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 17577: }
17578: } else {
17579: $resulttext = '<span class="LC_error">'.
1.23 raeburn 17580: &mt('An error occurred: [_1]',$putresult).'</span>';
17581: }
1.43 raeburn 17582: if ($warningmsg ne '') {
17583: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
17584: }
1.23 raeburn 17585: return $resulttext;
17586: }
17587:
1.165 raeburn 17588: sub process_captcha {
1.369 raeburn 17589: my ($container,$changes,$newsettings,$currsettings) = @_;
17590: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 17591: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
17592: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
17593: $newsettings->{'captcha'} = 'original';
17594: }
1.369 raeburn 17595: my %current;
17596: if (ref($currsettings) eq 'HASH') {
17597: %current = %{$currsettings};
17598: }
17599: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 17600: if ($container eq 'cancreate') {
1.169 raeburn 17601: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
17602: push(@{$changes->{'cancreate'}},'captcha');
17603: } elsif (!defined($changes->{'cancreate'})) {
17604: $changes->{'cancreate'} = ['captcha'];
17605: }
1.368 raeburn 17606: } elsif ($container eq 'passwords') {
17607: $changes->{'reset'} = 1;
1.169 raeburn 17608: } else {
17609: $changes->{'captcha'} = 1;
1.165 raeburn 17610: }
17611: }
1.269 raeburn 17612: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 17613: if ($newsettings->{'captcha'} eq 'recaptcha') {
17614: $newpub = $env{'form.'.$container.'_recaptchapub'};
17615: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 17616: $newpub =~ s/[^\w\-]//g;
17617: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 17618: $newsettings->{'recaptchakeys'} = {
17619: public => $newpub,
17620: private => $newpriv,
17621: };
1.269 raeburn 17622: $newversion = $env{'form.'.$container.'_recaptchaversion'};
17623: $newversion =~ s/\D//g;
17624: if ($newversion ne '2') {
17625: $newversion = 1;
17626: }
17627: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 17628: }
1.369 raeburn 17629: if (ref($current{'recaptchakeys'}) eq 'HASH') {
17630: $currpub = $current{'recaptchakeys'}{'public'};
17631: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 17632: unless ($newsettings->{'captcha'} eq 'recaptcha') {
17633: $newsettings->{'recaptchakeys'} = {
17634: public => '',
17635: private => '',
17636: }
17637: }
1.165 raeburn 17638: }
1.369 raeburn 17639: if ($current{'captcha'} eq 'recaptcha') {
17640: $currversion = $current{'recaptchaversion'};
1.269 raeburn 17641: if ($currversion ne '2') {
17642: $currversion = 1;
17643: }
17644: }
17645: if ($currversion ne $newversion) {
17646: if ($container eq 'cancreate') {
17647: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
17648: push(@{$changes->{'cancreate'}},'recaptchaversion');
17649: } elsif (!defined($changes->{'cancreate'})) {
17650: $changes->{'cancreate'} = ['recaptchaversion'];
17651: }
1.368 raeburn 17652: } elsif ($container eq 'passwords') {
17653: $changes->{'reset'} = 1;
1.269 raeburn 17654: } else {
17655: $changes->{'recaptchaversion'} = 1;
17656: }
17657: }
1.165 raeburn 17658: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 17659: if ($container eq 'cancreate') {
17660: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
17661: push(@{$changes->{'cancreate'}},'recaptchakeys');
17662: } elsif (!defined($changes->{'cancreate'})) {
17663: $changes->{'cancreate'} = ['recaptchakeys'];
17664: }
1.368 raeburn 17665: } elsif ($container eq 'passwords') {
17666: $changes->{'reset'} = 1;
1.169 raeburn 17667: } else {
1.210 raeburn 17668: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 17669: }
17670: }
17671: return;
17672: }
17673:
1.33 raeburn 17674: sub modify_usermodification {
17675: my ($dom,%domconfig) = @_;
1.224 raeburn 17676: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 17677: if (ref($domconfig{'usermodification'}) eq 'HASH') {
17678: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 17679: if ($key eq 'selfcreate') {
17680: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
17681: } else {
17682: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
17683: }
1.33 raeburn 17684: }
17685: }
1.224 raeburn 17686: my @contexts = ('author','course');
1.33 raeburn 17687: my %context_title = (
17688: author => 'In author context',
17689: course => 'In course context',
17690: );
17691: my @fields = ('lastname','firstname','middlename','generation',
17692: 'permanentemail','id');
17693: my %roles = (
17694: author => ['ca','aa'],
17695: course => ['st','ep','ta','in','cr'],
17696: );
17697: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
17698: foreach my $context (@contexts) {
17699: foreach my $role (@{$roles{$context}}) {
17700: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
17701: foreach my $item (@fields) {
17702: if (grep(/^\Q$item\E$/,@modifiable)) {
17703: $modifyhash{$context}{$role}{$item} = 1;
17704: } else {
17705: $modifyhash{$context}{$role}{$item} = 0;
17706: }
17707: }
17708: }
17709: if (ref($curr_usermodification{$context}) eq 'HASH') {
17710: foreach my $role (@{$roles{$context}}) {
17711: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
17712: foreach my $field (@fields) {
17713: if ($modifyhash{$context}{$role}{$field} ne
17714: $curr_usermodification{$context}{$role}{$field}) {
17715: push(@{$changes{$context}},$role);
17716: last;
17717: }
17718: }
17719: }
17720: }
17721: } else {
17722: foreach my $context (@contexts) {
17723: foreach my $role (@{$roles{$context}}) {
17724: push(@{$changes{$context}},$role);
17725: }
17726: }
17727: }
17728: }
17729: my %usermodification_hash = (
17730: usermodification => \%modifyhash,
17731: );
17732: my $putresult = &Apache::lonnet::put_dom('configuration',
17733: \%usermodification_hash,$dom);
17734: if ($putresult eq 'ok') {
17735: if (keys(%changes) > 0) {
17736: $resulttext = &mt('Changes made: ').'<ul>';
17737: foreach my $context (@contexts) {
17738: if (ref($changes{$context}) eq 'ARRAY') {
17739: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
17740: if (ref($changes{$context}) eq 'ARRAY') {
17741: foreach my $role (@{$changes{$context}}) {
17742: my $rolename;
1.224 raeburn 17743: if ($role eq 'cr') {
17744: $rolename = &mt('Custom');
1.33 raeburn 17745: } else {
1.224 raeburn 17746: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 17747: }
17748: my @modifiable;
1.224 raeburn 17749: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 17750: foreach my $field (@fields) {
17751: if ($modifyhash{$context}{$role}{$field}) {
17752: push(@modifiable,$fieldtitles{$field});
17753: }
17754: }
17755: if (@modifiable > 0) {
17756: $resulttext .= join(', ',@modifiable);
17757: } else {
17758: $resulttext .= &mt('none');
17759: }
17760: $resulttext .= '</li>';
17761: }
17762: $resulttext .= '</ul></li>';
17763: }
17764: }
17765: }
17766: $resulttext .= '</ul>';
17767: } else {
17768: $resulttext = &mt('No changes made to user modification settings');
17769: }
17770: } else {
17771: $resulttext = '<span class="LC_error">'.
17772: &mt('An error occurred: [_1]',$putresult).'</span>';
17773: }
17774: return $resulttext;
17775: }
17776:
1.43 raeburn 17777: sub modify_defaults {
1.212 raeburn 17778: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 17779: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 17780: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 17781: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 17782: 'portal_def');
1.325 raeburn 17783: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 17784: foreach my $item (@items) {
17785: $newvalues{$item} = $env{'form.'.$item};
17786: if ($item eq 'auth_def') {
17787: if ($newvalues{$item} ne '') {
17788: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
17789: push(@errors,$item);
17790: }
17791: }
17792: } elsif ($item eq 'lang_def') {
17793: if ($newvalues{$item} ne '') {
17794: if ($newvalues{$item} =~ /^(\w+)/) {
17795: my $langcode = $1;
1.103 raeburn 17796: if ($langcode ne 'x_chef') {
17797: if (code2language($langcode) eq '') {
17798: push(@errors,$item);
17799: }
1.43 raeburn 17800: }
17801: } else {
17802: push(@errors,$item);
17803: }
17804: }
1.54 raeburn 17805: } elsif ($item eq 'timezone_def') {
17806: if ($newvalues{$item} ne '') {
1.62 raeburn 17807: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 17808: push(@errors,$item);
17809: }
17810: }
1.68 raeburn 17811: } elsif ($item eq 'datelocale_def') {
17812: if ($newvalues{$item} ne '') {
17813: my @datelocale_ids = DateTime::Locale->ids();
17814: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
17815: push(@errors,$item);
17816: }
17817: }
1.141 raeburn 17818: } elsif ($item eq 'portal_def') {
17819: if ($newvalues{$item} ne '') {
17820: 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])\/?$/) {
17821: push(@errors,$item);
17822: }
17823: }
1.43 raeburn 17824: }
17825: if (grep(/^\Q$item\E$/,@errors)) {
17826: $newvalues{$item} = $domdefaults{$item};
17827: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
17828: $changes{$item} = 1;
17829: }
1.72 raeburn 17830: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 17831: }
1.354 raeburn 17832: my %staticdefaults = (
17833: 'intauth_cost' => 10,
17834: 'intauth_check' => 0,
17835: 'intauth_switch' => 0,
17836: );
17837: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
17838: if (exists($domdefaults{$item})) {
17839: $newvalues{$item} = $domdefaults{$item};
17840: } else {
17841: $newvalues{$item} = $staticdefaults{$item};
17842: }
17843: }
1.43 raeburn 17844: my %defaults_hash = (
1.72 raeburn 17845: defaults => \%newvalues,
17846: );
1.43 raeburn 17847: my $title = &defaults_titles();
1.236 raeburn 17848:
17849: my $currinststatus;
17850: if (ref($domconfig{'inststatus'}) eq 'HASH') {
17851: $currinststatus = $domconfig{'inststatus'};
17852: } else {
17853: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17854: $currinststatus = {
17855: inststatustypes => $usertypes,
17856: inststatusorder => $types,
17857: inststatusguest => [],
17858: };
17859: }
17860: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
17861: my @allpos;
17862: my %alltypes;
1.305 raeburn 17863: my @inststatusguest;
17864: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
17865: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
17866: unless (grep(/^\Q$type\E$/,@todelete)) {
17867: push(@inststatusguest,$type);
17868: }
17869: }
17870: }
17871: my ($currtitles,$currorder);
1.236 raeburn 17872: if (ref($currinststatus) eq 'HASH') {
17873: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
17874: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
17875: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
17876: if ($currinststatus->{inststatustypes}->{$type} ne '') {
17877: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
17878: }
17879: }
17880: unless (grep(/^\Q$type\E$/,@todelete)) {
17881: my $position = $env{'form.inststatus_pos_'.$type};
17882: $position =~ s/\D+//g;
17883: $allpos[$position] = $type;
17884: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
17885: $alltypes{$type} =~ s/`//g;
17886: }
17887: }
17888: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
17889: $currtitles =~ s/,$//;
17890: }
17891: }
17892: if ($env{'form.addinststatus'}) {
17893: my $newtype = $env{'form.addinststatus'};
17894: $newtype =~ s/\W//g;
17895: unless (exists($alltypes{$newtype})) {
17896: $alltypes{$newtype} = $env{'form.addinststatus_title'};
17897: $alltypes{$newtype} =~ s/`//g;
17898: my $position = $env{'form.addinststatus_pos'};
17899: $position =~ s/\D+//g;
17900: if ($position ne '') {
17901: $allpos[$position] = $newtype;
17902: }
17903: }
17904: }
1.305 raeburn 17905: my @orderedstatus;
1.236 raeburn 17906: foreach my $type (@allpos) {
17907: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
17908: push(@orderedstatus,$type);
17909: }
17910: }
17911: foreach my $type (keys(%alltypes)) {
17912: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
17913: delete($alltypes{$type});
17914: }
17915: }
17916: $defaults_hash{'inststatus'} = {
17917: inststatustypes => \%alltypes,
17918: inststatusorder => \@orderedstatus,
1.305 raeburn 17919: inststatusguest => \@inststatusguest,
1.236 raeburn 17920: };
17921: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
17922: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
17923: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
17924: }
17925: }
17926: if ($currorder ne join(',',@orderedstatus)) {
17927: $changes{'inststatus'}{'inststatusorder'} = 1;
17928: }
17929: my $newtitles;
17930: foreach my $item (@orderedstatus) {
17931: $newtitles .= $alltypes{$item}.',';
17932: }
17933: $newtitles =~ s/,$//;
17934: if ($currtitles ne $newtitles) {
17935: $changes{'inststatus'}{'inststatustypes'} = 1;
17936: }
1.43 raeburn 17937: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
17938: $dom);
17939: if ($putresult eq 'ok') {
17940: if (keys(%changes) > 0) {
17941: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 17942: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 17943: 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";
17944: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 17945: if ($item eq 'inststatus') {
17946: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 17947: if (@orderedstatus) {
1.236 raeburn 17948: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
17949: foreach my $type (@orderedstatus) {
17950: $resulttext .= $alltypes{$type}.', ';
17951: }
17952: $resulttext =~ s/, $//;
17953: $resulttext .= '</li>';
1.305 raeburn 17954: } else {
17955: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 17956: }
17957: }
17958: } else {
17959: my $value = $env{'form.'.$item};
17960: if ($value eq '') {
17961: $value = &mt('none');
17962: } elsif ($item eq 'auth_def') {
17963: my %authnames = &authtype_names();
17964: my %shortauth = (
17965: internal => 'int',
17966: krb4 => 'krb4',
17967: krb5 => 'krb5',
17968: localauth => 'loc',
1.325 raeburn 17969: lti => 'lti',
1.236 raeburn 17970: );
17971: $value = $authnames{$shortauth{$value}};
17972: }
17973: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
17974: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 17975: }
17976: }
17977: $resulttext .= '</ul>';
17978: $mailmsgtext .= "\n";
17979: my $cachetime = 24*60*60;
1.72 raeburn 17980: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 17981: if (ref($lastactref) eq 'HASH') {
17982: $lastactref->{'domdefaults'} = 1;
17983: }
1.68 raeburn 17984: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 17985: my $notify = 1;
17986: if (ref($domconfig{'contacts'}) eq 'HASH') {
17987: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
17988: $notify = 0;
17989: }
17990: }
17991: if ($notify) {
17992: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
17993: "LON-CAPA Domain Settings Change - $dom",
17994: $mailmsgtext);
17995: }
1.54 raeburn 17996: }
1.43 raeburn 17997: } else {
1.54 raeburn 17998: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 17999: }
18000: } else {
18001: $resulttext = '<span class="LC_error">'.
18002: &mt('An error occurred: [_1]',$putresult).'</span>';
18003: }
18004: if (@errors > 0) {
18005: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
18006: foreach my $item (@errors) {
18007: $resulttext .= ' "'.$title->{$item}.'",';
18008: }
18009: $resulttext =~ s/,$//;
18010: }
18011: return $resulttext;
18012: }
18013:
1.46 raeburn 18014: sub modify_scantron {
1.205 raeburn 18015: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 18016: my ($resulttext,%confhash,%changes,$errors);
18017: my $custom = 'custom.tab';
18018: my $default = 'default.tab';
18019: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 18020: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 18021: &config_check($dom,$confname,$servadm);
18022: if ($env{'form.scantronformat.filename'} ne '') {
18023: my $error;
18024: if ($configuserok eq 'ok') {
18025: if ($switchserver) {
1.130 raeburn 18026: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 18027: } else {
18028: if ($author_ok eq 'ok') {
18029: my ($result,$scantronurl) =
18030: &publishlogo($r,'upload','scantronformat',$dom,
18031: $confname,'scantron','','',$custom);
18032: if ($result eq 'ok') {
18033: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 18034: $changes{'scantronformat'} = 1;
1.46 raeburn 18035: } else {
18036: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
18037: }
18038: } else {
18039: $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);
18040: }
18041: }
18042: } else {
18043: $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);
18044: }
18045: if ($error) {
18046: &Apache::lonnet::logthis($error);
18047: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18048: }
18049: }
1.48 raeburn 18050: if (ref($domconfig{'scantron'}) eq 'HASH') {
18051: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
18052: if ($env{'form.scantronformat_del'}) {
18053: $confhash{'scantron'}{'scantronformat'} = '';
18054: $changes{'scantronformat'} = 1;
1.347 raeburn 18055: } else {
18056: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 18057: }
18058: }
18059: }
1.347 raeburn 18060: my @options = ('hdr','pad','rem');
1.346 raeburn 18061: my @fields = &scantroncsv_fields();
18062: my %titles = &scantronconfig_titles();
1.347 raeburn 18063: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 18064: my ($newdat,$currdat,%newcol,%currcol);
18065: if (grep(/^dat$/,@formats)) {
18066: $confhash{'scantron'}{config}{dat} = 1;
18067: $newdat = 1;
18068: } else {
18069: $newdat = 0;
18070: }
18071: if (grep(/^csv$/,@formats)) {
18072: my %bynum;
18073: foreach my $field (@fields) {
18074: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
18075: my $posscol = $1;
18076: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 18077: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 18078: $bynum{$posscol} = $field;
18079: $newcol{$field} = $posscol;
18080: }
18081: }
18082: }
1.347 raeburn 18083: if (keys(%newcol)) {
18084: foreach my $option (@options) {
18085: if ($env{'form.scantroncsv_'.$option}) {
18086: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
18087: }
18088: }
18089: }
1.346 raeburn 18090: }
18091: $currdat = 1;
18092: if (ref($domconfig{'scantron'}) eq 'HASH') {
18093: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 18094: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 18095: $currdat = 0;
18096: }
18097: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 18098: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
18099: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
18100: }
1.346 raeburn 18101: }
18102: }
18103: }
18104: if ($currdat != $newdat) {
18105: $changes{'config'} = 1;
18106: } else {
18107: foreach my $field (@fields) {
18108: if ($currcol{$field} ne '') {
18109: if ($currcol{$field} ne $newcol{$field}) {
18110: $changes{'config'} = 1;
18111: last;
1.347 raeburn 18112: }
1.346 raeburn 18113: } elsif ($newcol{$field} ne '') {
18114: $changes{'config'} = 1;
18115: last;
18116: }
18117: }
18118: }
1.46 raeburn 18119: if (keys(%confhash) > 0) {
18120: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
18121: $dom);
18122: if ($putresult eq 'ok') {
18123: if (keys(%changes) > 0) {
1.48 raeburn 18124: if (ref($confhash{'scantron'}) eq 'HASH') {
18125: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 18126: if ($changes{'scantronformat'}) {
18127: if ($confhash{'scantron'}{'scantronformat'} eq '') {
18128: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
18129: } else {
18130: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
18131: }
18132: }
1.347 raeburn 18133: if ($changes{'config'}) {
1.346 raeburn 18134: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
18135: if ($confhash{'scantron'}{'config'}{'dat'}) {
18136: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
18137: }
18138: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 18139: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
18140: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
18141: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
18142: foreach my $field (@fields) {
18143: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
18144: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
18145: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
18146: }
18147: }
18148: $resulttext .= '</ul></li>';
18149: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
18150: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
18151: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
18152: foreach my $option (@options) {
18153: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
18154: $resulttext .= '<li>'.$titles{$option}.'</li>';
18155: }
18156: }
18157: $resulttext .= '</ul></li>';
18158: }
1.346 raeburn 18159: }
18160: }
18161: }
18162: }
18163: } else {
18164: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
18165: }
1.46 raeburn 18166: }
1.48 raeburn 18167: $resulttext .= '</ul>';
18168: } else {
1.130 raeburn 18169: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 18170: }
18171: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 18172: if (ref($lastactref) eq 'HASH') {
18173: $lastactref->{'domainconfig'} = 1;
18174: }
1.46 raeburn 18175: } else {
1.346 raeburn 18176: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 18177: }
18178: } else {
18179: $resulttext = '<span class="LC_error">'.
18180: &mt('An error occurred: [_1]',$putresult).'</span>';
18181: }
18182: } else {
1.130 raeburn 18183: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 18184: }
18185: if ($errors) {
1.353 raeburn 18186: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18187: $errors.'</ul></p>';
1.46 raeburn 18188: }
18189: return $resulttext;
18190: }
18191:
1.48 raeburn 18192: sub modify_coursecategories {
1.239 raeburn 18193: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 18194: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
18195: $cathash);
1.48 raeburn 18196: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 18197: my @catitems = ('unauth','auth');
18198: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 18199: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 18200: $cathash = $domconfig{'coursecategories'}{'cats'};
18201: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
18202: $changes{'togglecats'} = 1;
18203: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
18204: }
18205: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
18206: $changes{'categorize'} = 1;
18207: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
18208: }
1.120 raeburn 18209: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
18210: $changes{'togglecatscomm'} = 1;
18211: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
18212: }
18213: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
18214: $changes{'categorizecomm'} = 1;
18215: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 18216:
18217: }
18218: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
18219: $changes{'togglecatsplace'} = 1;
18220: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
18221: }
18222: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
18223: $changes{'categorizeplace'} = 1;
18224: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 18225: }
1.238 raeburn 18226: foreach my $item (@catitems) {
18227: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
18228: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
18229: $changes{$item} = 1;
18230: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
18231: }
18232: }
18233: }
1.57 raeburn 18234: } else {
18235: $changes{'togglecats'} = 1;
18236: $changes{'categorize'} = 1;
1.124 raeburn 18237: $changes{'togglecatscomm'} = 1;
18238: $changes{'categorizecomm'} = 1;
1.272 raeburn 18239: $changes{'togglecatsplace'} = 1;
18240: $changes{'categorizeplace'} = 1;
1.87 raeburn 18241: $domconfig{'coursecategories'} = {
18242: togglecats => $env{'form.togglecats'},
18243: categorize => $env{'form.categorize'},
1.124 raeburn 18244: togglecatscomm => $env{'form.togglecatscomm'},
18245: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 18246: togglecatsplace => $env{'form.togglecatsplace'},
18247: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 18248: };
1.238 raeburn 18249: foreach my $item (@catitems) {
18250: if ($env{'form.coursecat_'.$item} ne 'std') {
18251: $changes{$item} = 1;
18252: }
18253: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
18254: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
18255: }
18256: }
1.57 raeburn 18257: }
18258: if (ref($cathash) eq 'HASH') {
18259: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 18260: push (@deletecategory,'instcode::0');
18261: }
1.120 raeburn 18262: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
18263: push(@deletecategory,'communities::0');
18264: }
1.272 raeburn 18265: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
18266: push(@deletecategory,'placement::0');
18267: }
1.48 raeburn 18268: }
1.57 raeburn 18269: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
18270: if (ref($cathash) eq 'HASH') {
1.48 raeburn 18271: if (@deletecategory > 0) {
18272: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 18273: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 18274: foreach my $item (@deletecategory) {
1.57 raeburn 18275: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
18276: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 18277: $deletions{$item} = 1;
1.57 raeburn 18278: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 18279: }
18280: }
18281: }
1.57 raeburn 18282: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 18283: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 18284: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 18285: $reorderings{$item} = 1;
1.57 raeburn 18286: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 18287: }
18288: if ($env{'form.addcategory_name_'.$item} ne '') {
18289: my $newcat = $env{'form.addcategory_name_'.$item};
18290: my $newdepth = $depth+1;
18291: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 18292: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 18293: $adds{$newitem} = 1;
18294: }
18295: if ($env{'form.subcat_'.$item} ne '') {
18296: my $newcat = $env{'form.subcat_'.$item};
18297: my $newdepth = $depth+1;
18298: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 18299: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 18300: $adds{$newitem} = 1;
18301: }
18302: }
18303: }
18304: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 18305: if (ref($cathash) eq 'HASH') {
1.48 raeburn 18306: my $newitem = 'instcode::0';
1.57 raeburn 18307: if ($cathash->{$newitem} eq '') {
18308: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 18309: $adds{$newitem} = 1;
18310: }
18311: } else {
18312: my $newitem = 'instcode::0';
1.57 raeburn 18313: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 18314: $adds{$newitem} = 1;
18315: }
18316: }
1.120 raeburn 18317: if ($env{'form.communities'} eq '1') {
18318: if (ref($cathash) eq 'HASH') {
18319: my $newitem = 'communities::0';
18320: if ($cathash->{$newitem} eq '') {
18321: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
18322: $adds{$newitem} = 1;
18323: }
18324: } else {
18325: my $newitem = 'communities::0';
18326: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
18327: $adds{$newitem} = 1;
18328: }
18329: }
1.272 raeburn 18330: if ($env{'form.placement'} eq '1') {
18331: if (ref($cathash) eq 'HASH') {
18332: my $newitem = 'placement::0';
18333: if ($cathash->{$newitem} eq '') {
18334: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
18335: $adds{$newitem} = 1;
18336: }
18337: } else {
18338: my $newitem = 'placement::0';
18339: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
18340: $adds{$newitem} = 1;
18341: }
18342: }
1.48 raeburn 18343: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 18344: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 18345: ($env{'form.addcategory_name'} ne 'communities') &&
18346: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 18347: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
18348: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
18349: $adds{$newitem} = 1;
18350: }
1.48 raeburn 18351: }
1.57 raeburn 18352: my $putresult;
1.48 raeburn 18353: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
18354: if (keys(%deletions) > 0) {
18355: foreach my $key (keys(%deletions)) {
18356: if ($predelallitems{$key} ne '') {
18357: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
18358: }
18359: }
18360: }
18361: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 18362: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 18363: if (ref($chkcats[0]) eq 'ARRAY') {
18364: my $depth = 0;
18365: my $chg = 0;
18366: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
18367: my $name = $chkcats[0][$i];
18368: my $item;
18369: if ($name eq '') {
18370: $chg ++;
18371: } else {
18372: $item = &escape($name).'::0';
18373: if ($chg) {
1.57 raeburn 18374: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 18375: }
18376: $depth ++;
1.57 raeburn 18377: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 18378: $depth --;
18379: }
18380: }
18381: }
1.57 raeburn 18382: }
18383: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
18384: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 18385: if ($putresult eq 'ok') {
1.57 raeburn 18386: my %title = (
1.120 raeburn 18387: togglecats => 'Show/Hide a course in catalog',
18388: categorize => 'Assign a category to a course',
18389: togglecatscomm => 'Show/Hide a community in catalog',
18390: categorizecomm => 'Assign a category to a community',
1.57 raeburn 18391: );
18392: my %level = (
1.120 raeburn 18393: dom => 'set in Domain ("Modify Course/Community")',
18394: crs => 'set in Course ("Course Configuration")',
18395: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 18396: none => 'No catalog',
18397: std => 'Standard catalog',
18398: domonly => 'Domain-only catalog',
18399: codesrch => 'Code search form',
1.57 raeburn 18400: );
1.48 raeburn 18401: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 18402: if ($changes{'togglecats'}) {
18403: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
18404: }
18405: if ($changes{'categorize'}) {
18406: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 18407: }
1.120 raeburn 18408: if ($changes{'togglecatscomm'}) {
18409: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
18410: }
18411: if ($changes{'categorizecomm'}) {
18412: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
18413: }
1.238 raeburn 18414: if ($changes{'unauth'}) {
18415: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
18416: }
18417: if ($changes{'auth'}) {
18418: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
18419: }
1.57 raeburn 18420: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
18421: my $cathash;
18422: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
18423: $cathash = $domconfig{'coursecategories'}{'cats'};
18424: } else {
18425: $cathash = {};
18426: }
18427: my (@cats,@trails,%allitems);
18428: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
18429: if (keys(%deletions) > 0) {
18430: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
18431: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
18432: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
18433: }
18434: $resulttext .= '</ul></li>';
18435: }
18436: if (keys(%reorderings) > 0) {
18437: my %sort_by_trail;
18438: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
18439: foreach my $key (keys(%reorderings)) {
18440: if ($allitems{$key} ne '') {
18441: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
18442: }
1.48 raeburn 18443: }
1.57 raeburn 18444: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
18445: $resulttext .= '<li>'.$trails[$trail].'</li>';
18446: }
18447: $resulttext .= '</ul></li>';
1.48 raeburn 18448: }
1.57 raeburn 18449: if (keys(%adds) > 0) {
18450: my %sort_by_trail;
18451: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
18452: foreach my $key (keys(%adds)) {
18453: if ($allitems{$key} ne '') {
18454: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
18455: }
18456: }
18457: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
18458: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 18459: }
1.57 raeburn 18460: $resulttext .= '</ul></li>';
1.48 raeburn 18461: }
1.364 raeburn 18462: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
18463: if (ref($lastactref) eq 'HASH') {
18464: $lastactref->{'cats'} = 1;
18465: }
1.48 raeburn 18466: }
18467: $resulttext .= '</ul>';
1.239 raeburn 18468: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 18469: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
18470: if ($changes{'auth'}) {
18471: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
18472: }
18473: if ($changes{'unauth'}) {
18474: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
18475: }
18476: my $cachetime = 24*60*60;
18477: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 18478: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 18479: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 18480: }
18481: }
1.48 raeburn 18482: } else {
18483: $resulttext = '<span class="LC_error">'.
1.57 raeburn 18484: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 18485: }
18486: } else {
1.120 raeburn 18487: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 18488: }
18489: return $resulttext;
18490: }
18491:
1.69 raeburn 18492: sub modify_serverstatuses {
18493: my ($dom,%domconfig) = @_;
18494: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
18495: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
18496: %currserverstatus = %{$domconfig{'serverstatuses'}};
18497: }
18498: my @pages = &serverstatus_pages();
18499: foreach my $type (@pages) {
18500: $newserverstatus{$type}{'namedusers'} = '';
18501: $newserverstatus{$type}{'machines'} = '';
18502: if (defined($env{'form.'.$type.'_namedusers'})) {
18503: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
18504: my @okusers;
18505: foreach my $user (@users) {
18506: my ($uname,$udom) = split(/:/,$user);
18507: if (($udom =~ /^$match_domain$/) &&
18508: (&Apache::lonnet::domain($udom)) &&
18509: ($uname =~ /^$match_username$/)) {
18510: if (!grep(/^\Q$user\E/,@okusers)) {
18511: push(@okusers,$user);
18512: }
18513: }
18514: }
18515: if (@okusers > 0) {
18516: @okusers = sort(@okusers);
18517: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
18518: }
18519: }
18520: if (defined($env{'form.'.$type.'_machines'})) {
18521: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
18522: my @okmachines;
18523: foreach my $ip (@machines) {
18524: my @parts = split(/\./,$ip);
18525: next if (@parts < 4);
18526: my $badip = 0;
18527: for (my $i=0; $i<4; $i++) {
18528: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
18529: $badip = 1;
18530: last;
18531: }
18532: }
18533: if (!$badip) {
18534: push(@okmachines,$ip);
18535: }
18536: }
18537: @okmachines = sort(@okmachines);
18538: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
18539: }
18540: }
18541: my %serverstatushash = (
18542: serverstatuses => \%newserverstatus,
18543: );
18544: foreach my $type (@pages) {
1.83 raeburn 18545: foreach my $setting ('namedusers','machines') {
1.84 raeburn 18546: my (@current,@new);
1.83 raeburn 18547: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 18548: if ($currserverstatus{$type}{$setting} ne '') {
18549: @current = split(/,/,$currserverstatus{$type}{$setting});
18550: }
18551: }
18552: if ($newserverstatus{$type}{$setting} ne '') {
18553: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 18554: }
18555: if (@current > 0) {
18556: if (@new > 0) {
18557: foreach my $item (@current) {
18558: if (!grep(/^\Q$item\E$/,@new)) {
18559: $changes{$type}{$setting} = 1;
1.82 raeburn 18560: last;
18561: }
18562: }
1.84 raeburn 18563: foreach my $item (@new) {
18564: if (!grep(/^\Q$item\E$/,@current)) {
18565: $changes{$type}{$setting} = 1;
18566: last;
1.82 raeburn 18567: }
18568: }
18569: } else {
1.83 raeburn 18570: $changes{$type}{$setting} = 1;
1.69 raeburn 18571: }
1.83 raeburn 18572: } elsif (@new > 0) {
18573: $changes{$type}{$setting} = 1;
1.69 raeburn 18574: }
18575: }
18576: }
18577: if (keys(%changes) > 0) {
1.81 raeburn 18578: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 18579: my $putresult = &Apache::lonnet::put_dom('configuration',
18580: \%serverstatushash,$dom);
18581: if ($putresult eq 'ok') {
18582: $resulttext .= &mt('Changes made:').'<ul>';
18583: foreach my $type (@pages) {
1.84 raeburn 18584: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 18585: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 18586: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 18587: if ($newserverstatus{$type}{'namedusers'} eq '') {
18588: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
18589: } else {
18590: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
18591: }
1.84 raeburn 18592: }
18593: if ($changes{$type}{'machines'}) {
1.69 raeburn 18594: if ($newserverstatus{$type}{'machines'} eq '') {
18595: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
18596: } else {
18597: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
18598: }
18599:
18600: }
18601: $resulttext .= '</ul></li>';
18602: }
18603: }
18604: $resulttext .= '</ul>';
18605: } else {
18606: $resulttext = '<span class="LC_error">'.
18607: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
18608:
18609: }
18610: } else {
18611: $resulttext = &mt('No changes made to access to server status pages');
18612: }
18613: return $resulttext;
18614: }
18615:
1.118 jms 18616: sub modify_helpsettings {
1.285 raeburn 18617: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 18618: my ($resulttext,$errors,%changes,%helphash);
18619: my %defaultchecked = ('submitbugs' => 'on');
18620: my @offon = ('off','on');
1.118 jms 18621: my @toggles = ('submitbugs');
1.285 raeburn 18622: my %current = ('submitbugs' => '',
18623: 'adhoc' => {},
18624: );
1.118 jms 18625: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 18626: %current = %{$domconfig{'helpsettings'}};
18627: }
1.285 raeburn 18628: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 18629: foreach my $item (@toggles) {
18630: if ($defaultchecked{$item} eq 'on') {
18631: if ($current{$item} eq '') {
18632: if ($env{'form.'.$item} eq '0') {
18633: $changes{$item} = 1;
18634: }
18635: } elsif ($current{$item} ne $env{'form.'.$item}) {
18636: $changes{$item} = 1;
18637: }
18638: } elsif ($defaultchecked{$item} eq 'off') {
18639: if ($current{$item} eq '') {
18640: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 18641: $changes{$item} = 1;
18642: }
1.282 raeburn 18643: } elsif ($current{$item} ne $env{'form.'.$item}) {
18644: $changes{$item} = 1;
18645: }
18646: }
18647: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
18648: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
18649: }
18650: }
1.285 raeburn 18651: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 18652: my $confname = $dom.'-domainconfig';
18653: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 18654: my (@allpos,%newsettings,%changedprivs,$newrole);
18655: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 18656: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 18657: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 18658: my %lt = &Apache::lonlocal::texthash(
18659: s => 'system',
18660: d => 'domain',
18661: order => 'Display order',
18662: access => 'Role usage',
1.291 raeburn 18663: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 18664: dh => 'All with domain helpdesk role',
18665: da => 'All with domain helpdesk assistant role',
1.285 raeburn 18666: none => 'None',
18667: status => 'Determined based on institutional status',
18668: inc => 'Include all, but exclude specific personnel',
18669: exc => 'Exclude all, but include specific personnel',
18670: );
18671: for (my $num=0; $num<=$maxnum; $num++) {
18672: my ($prefix,$identifier,$rolename,%curr);
18673: if ($num == $maxnum) {
18674: next unless ($env{'form.newcusthelp'} == $maxnum);
18675: $identifier = 'custhelp'.$num;
18676: $prefix = 'helproles_'.$num;
18677: $rolename = $env{'form.custhelpname'.$num};
18678: $rolename=~s/[^A-Za-z0-9]//gs;
18679: next if ($rolename eq '');
18680: next if (exists($existing{'rolesdef_'.$rolename}));
18681: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
18682: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
18683: $newprivs{'c'},$confname,$dom);
18684: if ($result ne 'ok') {
18685: $errors .= '<li><span class="LC_error">'.
18686: &mt('An error occurred storing the new custom role: [_1]',
18687: $result).'</span></li>';
18688: next;
18689: } else {
18690: $changedprivs{$rolename} = \%newprivs;
18691: $newrole = $rolename;
18692: }
18693: } else {
18694: $prefix = 'helproles_'.$num;
18695: $rolename = $env{'form.'.$prefix};
18696: next if ($rolename eq '');
18697: next unless (exists($existing{'rolesdef_'.$rolename}));
18698: $identifier = 'custhelp'.$num;
18699: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
18700: my %currprivs;
1.289 raeburn 18701: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 18702: split(/\_/,$existing{'rolesdef_'.$rolename});
18703: foreach my $level ('c','d','s') {
18704: if ($newprivs{$level} ne $currprivs{$level}) {
18705: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
18706: $newprivs{'c'},$confname,$dom);
18707: if ($result ne 'ok') {
18708: $errors .= '<li><span class="LC_error">'.
18709: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
18710: $rolename,$result).'</span></li>';
18711: } else {
18712: $changedprivs{$rolename} = \%newprivs;
18713: }
18714: last;
18715: }
18716: }
18717: if (ref($current{'adhoc'}) eq 'HASH') {
18718: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
18719: %curr = %{$current{'adhoc'}{$rolename}};
18720: }
18721: }
18722: }
18723: my $newpos = $env{'form.'.$prefix.'_pos'};
18724: $newpos =~ s/\D+//g;
18725: $allpos[$newpos] = $rolename;
18726: my $newdesc = $env{'form.'.$prefix.'_desc'};
18727: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
18728: if ($curr{'desc'}) {
18729: if ($curr{'desc'} ne $newdesc) {
18730: $changes{'customrole'}{$rolename}{'desc'} = 1;
18731: $newsettings{$rolename}{'desc'} = $newdesc;
18732: }
18733: } elsif ($newdesc ne '') {
18734: $changes{'customrole'}{$rolename}{'desc'} = 1;
18735: $newsettings{$rolename}{'desc'} = $newdesc;
18736: }
18737: my $access = $env{'form.'.$prefix.'_access'};
18738: if (grep(/^\Q$access\E$/,@accesstypes)) {
18739: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
18740: if ($access eq 'status') {
18741: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
18742: if (scalar(@statuses) == 0) {
1.289 raeburn 18743: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 18744: } else {
18745: my (@shownstatus,$numtypes);
18746: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
18747: if (ref($types) eq 'ARRAY') {
18748: $numtypes = scalar(@{$types});
18749: foreach my $type (sort(@statuses)) {
18750: if ($type eq 'default') {
18751: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
18752: } elsif (grep(/^\Q$type\E$/,@{$types})) {
18753: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
18754: push(@shownstatus,$usertypes->{$type});
18755: }
18756: }
18757: }
18758: if (grep(/^default$/,@statuses)) {
18759: push(@shownstatus,$othertitle);
18760: }
18761: if (scalar(@shownstatus) == 1+$numtypes) {
18762: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
18763: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
18764: } else {
18765: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
18766: if (ref($curr{'status'}) eq 'ARRAY') {
18767: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
18768: if (@diffs) {
18769: $changes{'customrole'}{$rolename}{$access} = 1;
18770: }
18771: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
18772: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 18773: }
1.166 raeburn 18774: }
18775: }
1.285 raeburn 18776: } elsif (($access eq 'inc') || ($access eq 'exc')) {
18777: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
18778: my @newspecstaff;
18779: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
18780: foreach my $person (sort(@personnel)) {
18781: if ($domhelpdesk{$person}) {
18782: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
18783: }
18784: }
18785: if (ref($curr{$access}) eq 'ARRAY') {
18786: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
18787: if (@diffs) {
18788: $changes{'customrole'}{$rolename}{$access} = 1;
18789: }
18790: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
18791: $changes{'customrole'}{$rolename}{$access} = 1;
18792: }
18793: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
18794: my ($uname,$udom) = split(/:/,$person);
18795: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
18796: }
18797: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 18798: }
1.285 raeburn 18799: } else {
18800: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
18801: }
18802: unless ($curr{'access'} eq $access) {
18803: $changes{'customrole'}{$rolename}{'access'} = 1;
18804: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 18805: }
18806: }
1.285 raeburn 18807: if (@allpos > 0) {
18808: my $idx = 0;
18809: foreach my $rolename (@allpos) {
18810: if ($rolename ne '') {
18811: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
18812: if (ref($current{'adhoc'}) eq 'HASH') {
18813: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
18814: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
18815: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 18816: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 18817: }
18818: }
1.282 raeburn 18819: }
1.285 raeburn 18820: $idx ++;
1.166 raeburn 18821: }
18822: }
1.118 jms 18823: }
1.123 jms 18824: my $putresult;
18825: if (keys(%changes) > 0) {
1.166 raeburn 18826: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 18827: if ($putresult eq 'ok') {
1.285 raeburn 18828: if (ref($helphash{'helpsettings'}) eq 'HASH') {
18829: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
18830: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
18831: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
18832: }
18833: }
18834: my $cachetime = 24*60*60;
18835: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18836: if (ref($lastactref) eq 'HASH') {
18837: $lastactref->{'domdefaults'} = 1;
18838: }
18839: } else {
18840: $errors .= '<li><span class="LC_error">'.
18841: &mt('An error occurred storing the settings: [_1]',
18842: $putresult).'</span></li>';
18843: }
18844: }
18845: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
18846: $resulttext = &mt('Changes made:').'<ul>';
18847: my (%shownprivs,@levelorder);
18848: @levelorder = ('c','d','s');
18849: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 18850: foreach my $item (sort(keys(%changes))) {
18851: if ($item eq 'submitbugs') {
18852: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
18853: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
18854: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 18855: } elsif ($item eq 'customrole') {
18856: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 18857: my @keyorder = ('order','desc','access','status','exc','inc');
18858: my %keytext = &Apache::lonlocal::texthash(
18859: order => 'Order',
18860: desc => 'Role description',
18861: access => 'Role usage',
1.300 droeschl 18862: status => 'Allowed institutional types',
1.285 raeburn 18863: exc => 'Allowed personnel',
18864: inc => 'Disallowed personnel',
18865: );
1.282 raeburn 18866: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 18867: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
18868: if ($role eq $newrole) {
18869: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
18870: $role).'<ul>';
18871: } else {
18872: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
18873: $role).'<ul>';
18874: }
18875: foreach my $key (@keyorder) {
18876: if ($changes{'customrole'}{$role}{$key}) {
18877: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
18878: $keytext{$key},$newsettings{$role}{$key}).
18879: '</li>';
18880: }
18881: }
18882: if (ref($changedprivs{$role}) eq 'HASH') {
18883: $shownprivs{$role} = 1;
18884: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
18885: foreach my $level (@levelorder) {
18886: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
18887: next if ($item eq '');
18888: my ($priv) = split(/\&/,$item,2);
18889: if (&Apache::lonnet::plaintext($priv)) {
18890: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
18891: unless ($level eq 'c') {
18892: $resulttext .= ' ('.$lt{$level}.')';
18893: }
18894: $resulttext .= '</li>';
18895: }
18896: }
18897: }
18898: $resulttext .= '</ul>';
18899: }
18900: $resulttext .= '</ul></li>';
18901: }
18902: }
18903: }
18904: }
18905: }
18906: }
18907: if (keys(%changedprivs)) {
18908: foreach my $role (sort(keys(%changedprivs))) {
18909: unless ($shownprivs{$role}) {
18910: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
18911: $role).'<ul>'.
18912: '<li>'.&mt('Privileges set to :').'<ul>';
18913: foreach my $level (@levelorder) {
18914: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
18915: next if ($item eq '');
18916: my ($priv) = split(/\&/,$item,2);
18917: if (&Apache::lonnet::plaintext($priv)) {
18918: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
18919: unless ($level eq 'c') {
18920: $resulttext .= ' ('.$lt{$level}.')';
18921: }
18922: $resulttext .= '</li>';
18923: }
1.282 raeburn 18924: }
18925: }
1.285 raeburn 18926: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 18927: }
18928: }
18929: }
1.285 raeburn 18930: $resulttext .= '</ul>';
18931: } else {
18932: $resulttext = &mt('No changes made to help settings');
1.118 jms 18933: }
18934: if ($errors) {
1.168 raeburn 18935: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 18936: $errors.'</ul>';
1.118 jms 18937: }
18938: return $resulttext;
18939: }
18940:
1.121 raeburn 18941: sub modify_coursedefaults {
1.212 raeburn 18942: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 18943: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 18944: my %defaultchecked = (
18945: 'canuse_pdfforms' => 'off',
18946: 'uselcmath' => 'on',
18947: 'usejsme' => 'on'
18948: );
18949: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 18950: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 18951: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
18952: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
18953: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 18954: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 18955: my %staticdefaults = (
18956: anonsurvey_threshold => 10,
18957: uploadquota => 500,
1.257 raeburn 18958: postsubmit => 60,
1.276 raeburn 18959: mysqltables => 172800,
1.198 raeburn 18960: );
1.314 raeburn 18961: my %texoptions = (
18962: MathJax => 'MathJax',
18963: mimetex => &mt('Convert to Images'),
18964: tth => &mt('TeX to HTML'),
18965: );
1.121 raeburn 18966: $defaultshash{'coursedefaults'} = {};
18967:
18968: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
18969: if ($domconfig{'coursedefaults'} eq '') {
18970: $domconfig{'coursedefaults'} = {};
18971: }
18972: }
18973:
18974: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
18975: foreach my $item (@toggles) {
18976: if ($defaultchecked{$item} eq 'on') {
18977: if (($domconfig{'coursedefaults'}{$item} eq '') &&
18978: ($env{'form.'.$item} eq '0')) {
18979: $changes{$item} = 1;
1.192 raeburn 18980: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 18981: $changes{$item} = 1;
18982: }
18983: } elsif ($defaultchecked{$item} eq 'off') {
18984: if (($domconfig{'coursedefaults'}{$item} eq '') &&
18985: ($env{'form.'.$item} eq '1')) {
18986: $changes{$item} = 1;
18987: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
18988: $changes{$item} = 1;
18989: }
18990: }
18991: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
18992: }
1.198 raeburn 18993: foreach my $item (@numbers) {
18994: my ($currdef,$newdef);
1.208 raeburn 18995: $newdef = $env{'form.'.$item};
1.198 raeburn 18996: if ($item eq 'anonsurvey_threshold') {
18997: $currdef = $domconfig{'coursedefaults'}{$item};
18998: $newdef =~ s/\D//g;
18999: if ($newdef eq '' || $newdef < 1) {
19000: $newdef = 1;
19001: }
19002: $defaultshash{'coursedefaults'}{$item} = $newdef;
19003: } else {
1.276 raeburn 19004: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
19005: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
19006: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 19007: }
19008: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 19009: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 19010: }
19011: if ($currdef ne $newdef) {
19012: if ($item eq 'anonsurvey_threshold') {
19013: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
19014: $changes{$item} = 1;
19015: }
1.276 raeburn 19016: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 19017: my $setting = $1;
1.276 raeburn 19018: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
19019: $changes{$setting} = 1;
1.198 raeburn 19020: }
19021: }
1.139 raeburn 19022: }
19023: }
1.314 raeburn 19024: my $texengine;
19025: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
19026: $texengine = $env{'form.texengine'};
1.349 raeburn 19027: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
19028: if ($currdef eq '') {
19029: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 19030: $changes{'texengine'} = 1;
19031: }
1.349 raeburn 19032: } elsif ($currdef ne $texengine) {
1.314 raeburn 19033: $changes{'texengine'} = 1;
19034: }
19035: }
19036: if ($texengine ne '') {
19037: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
19038: }
1.264 raeburn 19039: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
19040: my @currclonecode;
19041: if (ref($currclone) eq 'HASH') {
19042: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
19043: @currclonecode = @{$currclone->{'instcode'}};
19044: }
19045: }
19046: my $newclone;
1.289 raeburn 19047: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 19048: $newclone = $env{'form.canclone'};
19049: }
19050: if ($newclone eq 'instcode') {
19051: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
19052: my (%codedefaults,@code_order,@clonecode);
19053: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
19054: \@code_order);
19055: foreach my $item (@code_order) {
19056: if (grep(/^\Q$item\E$/,@newcodes)) {
19057: push(@clonecode,$item);
19058: }
19059: }
19060: if (@clonecode) {
19061: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
19062: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
19063: if (@diffs) {
19064: $changes{'canclone'} = 1;
19065: }
19066: } else {
19067: $newclone eq '';
19068: }
19069: } elsif ($newclone ne '') {
1.289 raeburn 19070: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
19071: }
1.264 raeburn 19072: if ($newclone ne $currclone) {
19073: $changes{'canclone'} = 1;
19074: }
1.257 raeburn 19075: my %credits;
19076: foreach my $type (@types) {
19077: unless ($type eq 'community') {
19078: $credits{$type} = $env{'form.'.$type.'_credits'};
19079: $credits{$type} =~ s/[^\d.]+//g;
19080: }
19081: }
19082: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
19083: ($env{'form.coursecredits'} eq '1')) {
19084: $changes{'coursecredits'} = 1;
19085: foreach my $type (keys(%credits)) {
19086: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
19087: }
19088: } else {
1.289 raeburn 19089: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 19090: foreach my $type (@types) {
19091: unless ($type eq 'community') {
1.289 raeburn 19092: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 19093: $changes{'coursecredits'} = 1;
19094: }
19095: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
19096: }
19097: }
19098: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
19099: foreach my $type (@types) {
19100: unless ($type eq 'community') {
19101: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
19102: $changes{'coursecredits'} = 1;
19103: last;
19104: }
19105: }
19106: }
19107: }
19108: }
19109: if ($env{'form.postsubmit'} eq '1') {
19110: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
19111: my %currtimeout;
19112: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19113: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
19114: $changes{'postsubmit'} = 1;
19115: }
19116: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19117: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
19118: }
19119: } else {
19120: $changes{'postsubmit'} = 1;
19121: }
19122: foreach my $type (@types) {
19123: my $timeout = $env{'form.'.$type.'_timeout'};
19124: $timeout =~ s/\D//g;
19125: if ($timeout == $staticdefaults{'postsubmit'}) {
19126: $timeout = '';
19127: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
19128: $timeout = '0';
19129: }
19130: unless ($timeout eq '') {
19131: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
19132: }
19133: if (exists($currtimeout{$type})) {
19134: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 19135: $changes{'postsubmit'} = 1;
1.257 raeburn 19136: }
19137: } elsif ($timeout ne '') {
19138: $changes{'postsubmit'} = 1;
19139: }
19140: }
19141: } else {
19142: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
19143: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19144: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
19145: $changes{'postsubmit'} = 1;
19146: }
19147: } else {
19148: $changes{'postsubmit'} = 1;
19149: }
1.192 raeburn 19150: }
1.121 raeburn 19151: }
19152: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
19153: $dom);
19154: if ($putresult eq 'ok') {
19155: if (keys(%changes) > 0) {
1.213 raeburn 19156: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 19157: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 19158: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314 raeburn 19159: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
19160: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257 raeburn 19161: if ($changes{$item}) {
19162: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
19163: }
1.289 raeburn 19164: }
1.192 raeburn 19165: if ($changes{'coursecredits'}) {
19166: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 19167: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
19168: $domdefaults{$type.'credits'} =
19169: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
19170: }
19171: }
19172: }
19173: if ($changes{'postsubmit'}) {
19174: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19175: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
19176: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19177: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
19178: $domdefaults{$type.'postsubtimeout'} =
19179: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
19180: }
19181: }
1.192 raeburn 19182: }
19183: }
1.198 raeburn 19184: if ($changes{'uploadquota'}) {
19185: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
19186: foreach my $type (@types) {
19187: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
19188: }
19189: }
19190: }
1.264 raeburn 19191: if ($changes{'canclone'}) {
19192: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
19193: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
19194: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
19195: if (@clonecodes) {
19196: $domdefaults{'canclone'} = join('+',@clonecodes);
19197: }
19198: }
19199: } else {
19200: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
19201: }
19202: }
1.121 raeburn 19203: my $cachetime = 24*60*60;
19204: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 19205: if (ref($lastactref) eq 'HASH') {
19206: $lastactref->{'domdefaults'} = 1;
19207: }
1.121 raeburn 19208: }
19209: $resulttext = &mt('Changes made:').'<ul>';
19210: foreach my $item (sort(keys(%changes))) {
19211: if ($item eq 'canuse_pdfforms') {
19212: if ($env{'form.'.$item} eq '1') {
19213: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
19214: } else {
19215: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
19216: }
1.257 raeburn 19217: } elsif ($item eq 'uselcmath') {
19218: if ($env{'form.'.$item} eq '1') {
19219: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
19220: } else {
19221: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
19222: }
19223: } elsif ($item eq 'usejsme') {
19224: if ($env{'form.'.$item} eq '1') {
19225: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
19226: } else {
1.289 raeburn 19227: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 19228: }
1.314 raeburn 19229: } elsif ($item eq 'texengine') {
19230: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
19231: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
19232: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
19233: }
1.139 raeburn 19234: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 19235: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 19236: } elsif ($item eq 'uploadquota') {
19237: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
19238: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
19239: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
19240: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 19241: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 19242: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 19243: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
19244: '</ul>'.
19245: '</li>';
19246: } else {
19247: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
19248: }
1.276 raeburn 19249: } elsif ($item eq 'mysqltables') {
19250: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
19251: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
19252: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
19253: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
19254: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
19255: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
19256: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
19257: '</ul>'.
19258: '</li>';
19259: } else {
19260: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
19261: }
1.257 raeburn 19262: } elsif ($item eq 'postsubmit') {
19263: if ($domdefaults{'postsubmit'} eq 'off') {
19264: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
19265: } else {
19266: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 19267: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 19268: $resulttext .= &mt('durations:').'<ul>';
19269: foreach my $type (@types) {
19270: $resulttext .= '<li>';
19271: my $timeout;
19272: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19273: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
19274: }
19275: my $display;
19276: if ($timeout eq '0') {
19277: $display = &mt('unlimited');
19278: } elsif ($timeout eq '') {
19279: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
19280: } else {
19281: $display = &mt('[quant,_1,second]',$timeout);
19282: }
19283: if ($type eq 'community') {
19284: $resulttext .= &mt('Communities');
19285: } elsif ($type eq 'official') {
19286: $resulttext .= &mt('Official courses');
19287: } elsif ($type eq 'unofficial') {
19288: $resulttext .= &mt('Unofficial courses');
19289: } elsif ($type eq 'textbook') {
19290: $resulttext .= &mt('Textbook courses');
1.271 raeburn 19291: } elsif ($type eq 'placement') {
19292: $resulttext .= &mt('Placement tests');
1.257 raeburn 19293: }
19294: $resulttext .= ' -- '.$display.'</li>';
19295: }
19296: $resulttext .= '</ul>';
19297: }
1.289 raeburn 19298: $resulttext .= '</li>';
1.257 raeburn 19299: }
1.192 raeburn 19300: } elsif ($item eq 'coursecredits') {
19301: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
19302: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 19303: ($domdefaults{'unofficialcredits'} eq '') &&
19304: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 19305: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
19306: } else {
19307: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
19308: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
19309: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 19310: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 19311: '</ul>'.
19312: '</li>';
19313: }
19314: } else {
19315: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
19316: }
1.264 raeburn 19317: } elsif ($item eq 'canclone') {
19318: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
19319: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
19320: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
19321: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
19322: }
19323: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
19324: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
19325: } else {
1.289 raeburn 19326: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 19327: }
1.140 raeburn 19328: }
1.121 raeburn 19329: }
19330: $resulttext .= '</ul>';
19331: } else {
19332: $resulttext = &mt('No changes made to course defaults');
19333: }
19334: } else {
19335: $resulttext = '<span class="LC_error">'.
19336: &mt('An error occurred: [_1]',$putresult).'</span>';
19337: }
19338: return $resulttext;
19339: }
19340:
1.231 raeburn 19341: sub modify_selfenrollment {
19342: my ($dom,$lastactref,%domconfig) = @_;
19343: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 19344: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 19345: my %titles = &tool_titles();
1.232 raeburn 19346: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
19347: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 19348: $ordered{'default'} = ['types','registered','approval','limit'];
19349:
19350: my (%roles,%shown,%toplevel);
19351: $roles{'0'} = &Apache::lonnet::plaintext('dc');
19352:
19353: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
19354: if ($domconfig{'selfenrollment'} eq '') {
19355: $domconfig{'selfenrollment'} = {};
19356: }
19357: }
19358: %toplevel = (
19359: admin => 'Configuration Rights',
19360: default => 'Default settings',
19361: validation => 'Validation of self-enrollment requests',
19362: );
1.233 raeburn 19363: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 19364:
19365: if (ref($ordered{'admin'}) eq 'ARRAY') {
19366: foreach my $item (@{$ordered{'admin'}}) {
19367: foreach my $type (@types) {
19368: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
19369: $selfenrollhash{'admin'}{$type}{$item} = 1;
19370: } else {
19371: $selfenrollhash{'admin'}{$type}{$item} = 0;
19372: }
19373: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
19374: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
19375: if ($selfenrollhash{'admin'}{$type}{$item} ne
19376: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
19377: push(@{$changes{'admin'}{$type}},$item);
19378: }
19379: } else {
19380: if (!$selfenrollhash{'admin'}{$type}{$item}) {
19381: push(@{$changes{'admin'}{$type}},$item);
19382: }
19383: }
19384: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
19385: push(@{$changes{'admin'}{$type}},$item);
19386: }
19387: }
19388: }
19389: }
19390:
19391: foreach my $item (@{$ordered{'default'}}) {
19392: foreach my $type (@types) {
19393: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
19394: if ($item eq 'types') {
19395: unless (($value eq 'all') || ($value eq 'dom')) {
19396: $value = '';
19397: }
19398: } elsif ($item eq 'registered') {
19399: unless ($value eq '1') {
19400: $value = 0;
19401: }
19402: } elsif ($item eq 'approval') {
19403: unless ($value =~ /^[012]$/) {
19404: $value = 0;
19405: }
19406: } else {
19407: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
19408: $value = 'none';
19409: }
19410: }
19411: $selfenrollhash{'default'}{$type}{$item} = $value;
19412: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
19413: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
19414: if ($selfenrollhash{'default'}{$type}{$item} ne
19415: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
19416: push(@{$changes{'default'}{$type}},$item);
19417: }
19418: } else {
19419: push(@{$changes{'default'}{$type}},$item);
19420: }
19421: } else {
19422: push(@{$changes{'default'}{$type}},$item);
19423: }
19424: if ($item eq 'limit') {
19425: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
19426: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
19427: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
19428: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
19429: }
19430: } else {
19431: $selfenrollhash{'default'}{$type}{'cap'} = '';
19432: }
19433: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
19434: if ($selfenrollhash{'default'}{$type}{'cap'} ne
19435: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
19436: push(@{$changes{'default'}{$type}},'cap');
19437: }
19438: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
19439: push(@{$changes{'default'}{$type}},'cap');
19440: }
19441: }
19442: }
19443: }
19444:
19445: foreach my $item (@{$itemsref}) {
19446: if ($item eq 'fields') {
19447: my @changed;
19448: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
19449: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
19450: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
19451: }
19452: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
19453: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
19454: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
19455: $domconfig{'selfenrollment'}{'validation'}{$item});
19456: } else {
19457: @changed = @{$selfenrollhash{'validation'}{$item}};
19458: }
19459: } else {
19460: @changed = @{$selfenrollhash{'validation'}{$item}};
19461: }
19462: if (@changed) {
19463: if ($selfenrollhash{'validation'}{$item}) {
19464: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
19465: } else {
19466: $changes{'validation'}{$item} = &mt('None');
19467: }
19468: }
19469: } else {
19470: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
19471: if ($item eq 'markup') {
19472: if ($env{'form.selfenroll_validation_'.$item}) {
19473: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
19474: }
19475: }
19476: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
19477: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
19478: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
19479: }
19480: }
19481: }
19482: }
19483:
19484: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
19485: $dom);
19486: if ($putresult eq 'ok') {
19487: if (keys(%changes) > 0) {
19488: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
19489: $resulttext = &mt('Changes made:').'<ul>';
19490: foreach my $key ('admin','default','validation') {
19491: if (ref($changes{$key}) eq 'HASH') {
19492: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
19493: if ($key eq 'validation') {
19494: foreach my $item (@{$itemsref}) {
19495: if (exists($changes{$key}{$item})) {
19496: if ($item eq 'markup') {
19497: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
19498: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
19499: } else {
19500: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
19501: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
19502: }
19503: }
19504: }
19505: } else {
19506: foreach my $type (@types) {
19507: if ($type eq 'community') {
19508: $roles{'1'} = &mt('Community personnel');
19509: } else {
19510: $roles{'1'} = &mt('Course personnel');
19511: }
19512: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 19513: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
19514: if ($key eq 'admin') {
19515: my @mgrdc = ();
19516: if (ref($ordered{$key}) eq 'ARRAY') {
19517: foreach my $item (@{$ordered{'admin'}}) {
19518: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
19519: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
19520: push(@mgrdc,$item);
19521: }
19522: }
19523: }
19524: if (@mgrdc) {
19525: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
19526: } else {
19527: delete($domdefaults{$type.'selfenrolladmdc'});
19528: }
19529: }
19530: } else {
19531: if (ref($ordered{$key}) eq 'ARRAY') {
19532: foreach my $item (@{$ordered{$key}}) {
19533: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
19534: $domdefaults{$type.'selfenroll'.$item} =
19535: $selfenrollhash{$key}{$type}{$item};
19536: }
19537: }
19538: }
19539: }
19540: }
1.231 raeburn 19541: $resulttext .= '<li>'.$titles{$type}.'<ul>';
19542: foreach my $item (@{$ordered{$key}}) {
19543: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
19544: $resulttext .= '<li>';
19545: if ($key eq 'admin') {
19546: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
19547: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
19548: } else {
19549: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
19550: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
19551: }
19552: $resulttext .= '</li>';
19553: }
19554: }
19555: $resulttext .= '</ul></li>';
19556: }
19557: }
19558: $resulttext .= '</ul></li>';
19559: }
19560: }
1.305 raeburn 19561: }
19562: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
19563: my $cachetime = 24*60*60;
19564: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19565: if (ref($lastactref) eq 'HASH') {
19566: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 19567: }
1.231 raeburn 19568: }
19569: $resulttext .= '</ul>';
19570: } else {
19571: $resulttext = &mt('No changes made to self-enrollment settings');
19572: }
19573: } else {
19574: $resulttext = '<span class="LC_error">'.
19575: &mt('An error occurred: [_1]',$putresult).'</span>';
19576: }
19577: return $resulttext;
19578: }
19579:
1.373 raeburn 19580: sub modify_wafproxy {
19581: my ($dom,$action,$lastactref,%domconfig) = @_;
19582: my %servers = &Apache::lonnet::internet_dom_servers($dom);
19583: my (%othercontrol,%canset,%values,%curralias,%currvalue,@warnings,%wafproxy,
19584: %changes,%expirecache);
19585: foreach my $server (sort(keys(%servers))) {
19586: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
19587: if ($serverhome eq $server) {
19588: my $serverdom = &Apache::lonnet::host_domain($server);
19589: if ($serverdom eq $dom) {
19590: $canset{$server} = 1;
19591: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
19592: %{$values{$dom}} = ();
19593: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
19594: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
19595: }
19596: foreach my $item ('ipheader','trusted','exempt') {
19597: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
19598: }
19599: }
19600: }
19601: }
19602: }
19603: my $output;
19604: if (keys(%canset)) {
19605: %{$wafproxy{'alias'}} = ();
19606: foreach my $key (sort(keys(%canset))) {
19607: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
19608: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
19609: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
19610: $changes{'alias'} = 1;
19611: }
19612: if ($wafproxy{'alias'}{$key} eq '') {
19613: if ($curralias{$key}) {
19614: $expirecache{$key} = 1;
19615: }
19616: delete($wafproxy{'alias'}{$key});
19617: }
19618: }
19619: unless (keys(%{$wafproxy{'alias'}})) {
19620: delete($wafproxy{'alias'});
19621: }
19622: # Localization for values in %warn occus in &mt() calls separately.
19623: my %warn = (
19624: trusted => 'trusted IP range(s)',
19625: exempt => 'exempt IP range(s)',
19626: );
19627: foreach my $item ('ipheader','trusted','exempt') {
19628: my $possible = $env{'form.wafproxy_'.$item};
19629: $possible =~ s/^\s+|\s+$//g;
19630: if ($possible ne '') {
19631: if ($item eq 'ipheader') {
19632: $wafproxy{$item} = $possible;
19633: } else {
19634: my (@ok,$count);
19635: $possible =~ s/[\r\n]+/\s/g;
19636: $possible =~ s/\s*-\s*/-/g;
19637: $possible =~ s/\s+/,/g;
19638: $count = 0;
19639: if ($possible) {
19640: foreach my $poss (split(/\,/,$possible)) {
19641: $count ++;
19642: if (&validate_ip_pattern($poss)) {
19643: push(@ok,$poss);
19644: }
19645: }
19646: if (@ok) {
19647: $wafproxy{$item} = join(',',@ok);
19648: }
19649: my $diff = $count - scalar(@ok);
19650: if ($diff) {
19651: push(@warnings,'<li>'.
19652: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
19653: $diff,$warn{$item}).
19654: '</li>');
19655: }
19656: if ($wafproxy{$item} ne $currvalue{$item}) {
19657: $changes{$item} = 1;
19658: }
19659: }
19660: }
19661: } else {
19662: if ($currvalue{$item}) {
19663: $changes{$item} = 1;
19664: }
19665: }
19666: }
19667: }
19668: if (keys(%changes)) {
19669: my %defaultshash = (
19670: wafproxy => \%wafproxy,
19671: );
19672: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
19673: $dom);
19674: if ($putresult eq 'ok') {
19675: my $cachetime = 24*60*60;
19676: my (%domdefaults,$updatedomdefs);
19677: foreach my $item ('ipheader','trusted','exempt') {
19678: if ($changes{$item}) {
19679: unless ($updatedomdefs) {
19680: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
19681: $updatedomdefs = 1;
19682: }
19683: if ($wafproxy{$item}) {
19684: $domdefaults{'waf_'.$item} = $wafproxy{$item};
19685: } elsif (exists($domdefaults{'waf_'.$item})) {
19686: delete($domdefaults{'waf_'.$item});
19687: }
19688: }
19689: }
19690: if ($updatedomdefs) {
19691: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19692: if (ref($lastactref) eq 'HASH') {
19693: $lastactref->{'domdefaults'} = 1;
19694: }
19695: }
19696: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
19697: my %updates = %expirecache;
19698: foreach my $key (keys(%expirecache)) {
19699: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
19700: }
19701: if (ref($wafproxy{'alias'}) eq 'HASH') {
19702: my $cachetime = 24*60*60;
19703: foreach my $key (keys(%{$wafproxy{'alias'}})) {
19704: $updates{$key} = 1;
19705: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
19706: $cachetime);
19707: }
19708: }
19709: if (ref($lastactref) eq 'HASH') {
19710: $lastactref->{'proxyalias'} = \%updates;
19711: }
19712: }
19713: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
19714: foreach my $item ('alias','ipheader','trusted','exempt') {
19715: if ($changes{$item}) {
19716: if ($item eq 'alias') {
19717: my $numaliased = 0;
19718: if (ref($wafproxy{'alias'}) eq 'HASH') {
19719: my $shown;
19720: if (keys(%{$wafproxy{'alias'}})) {
19721: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
19722: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
19723: &Apache::lonnet::hostname($server),
19724: $wafproxy{'alias'}{$server}).'</li>';
19725: $numaliased ++;
19726: }
19727: if ($numaliased) {
19728: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
19729: '<ul>'.$shown.'</ul>').'</li>';
19730: }
19731: }
19732: }
19733: unless ($numaliased) {
19734: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
19735: }
19736: } else {
19737: if ($item eq 'ipheader') {
19738: if ($wafproxy{$item}) {
19739: $output .= '<li>'.&mt('Custom request header set to [_1]',
19740: $wafproxy{$item}).'</li>';
19741: } else {
19742: $output .= '<li>'.&mt('Custom request header deleted').'</li>';
19743: }
19744: } elsif ($item eq 'trusted') {
19745: if ($wafproxy{$item}) {
19746: $output .= '<li>'.&mt('Trusted IP range(s) set to [_1]',
19747: $wafproxy{$item}).'</li>';
19748: } else {
19749: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
19750: }
19751: } elsif ($item eq 'exempt') {
19752: if ($wafproxy{$item}) {
19753: $output .= '<li>'.&mt('Exempt IP range(s) set to [_1]',
19754: $wafproxy{$item}).'</li>';
19755: } else {
19756: $output .= '<li>'.&mt('Exempt IP range(s) deleted').'</li>';
19757: }
19758: }
19759: }
19760: }
19761: }
19762: } else {
19763: $output = '<span class="LC_error">'.
19764: &mt('An error occurred: [_1]',$putresult).'</span>';
19765: }
19766: } elsif (keys(%canset)) {
19767: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
19768: }
19769: if (@warnings) {
19770: $output .= '<br />'.&mt('Warnings:').'<ul>'.
19771: join("\n",@warnings).'</ul>';
19772: }
19773: return $output;
19774: }
19775:
19776: sub validate_ip_pattern {
19777: my ($pattern) = @_;
19778: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
19779: my ($start,$end) = ($1,$2);
19780: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
19781: return 1;
19782: }
19783: } elsif (&Net::CIDR::cidrvalidate($pattern)) {
19784: return 1;
19785: }
19786: return
19787: }
19788:
1.137 raeburn 19789: sub modify_usersessions {
1.212 raeburn 19790: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 19791: my @hostingtypes = ('version','excludedomain','includedomain');
19792: my @offloadtypes = ('primary','default');
19793: my %types = (
19794: remote => \@hostingtypes,
19795: hosted => \@hostingtypes,
19796: spares => \@offloadtypes,
19797: );
19798: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 19799: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 19800: my (%by_ip,%by_location,@intdoms,@instdoms);
19801: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 19802: my @locations = sort(keys(%by_location));
1.137 raeburn 19803: my (%defaultshash,%changes);
19804: foreach my $prefix (@prefixes) {
19805: $defaultshash{'usersessions'}{$prefix} = {};
19806: }
1.212 raeburn 19807: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 19808: my $resulttext;
1.138 raeburn 19809: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 19810: foreach my $prefix (@prefixes) {
1.145 raeburn 19811: next if ($prefix eq 'spares');
19812: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 19813: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
19814: if ($type eq 'version') {
19815: my $value = $env{'form.'.$prefix.'_'.$type};
19816: my $okvalue;
19817: if ($value ne '') {
19818: if (grep(/^\Q$value\E$/,@lcversions)) {
19819: $okvalue = $value;
19820: }
19821: }
19822: if (ref($domconfig{'usersessions'}) eq 'HASH') {
19823: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
19824: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
19825: if ($inuse == 0) {
19826: $changes{$prefix}{$type} = 1;
19827: } else {
19828: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
19829: $changes{$prefix}{$type} = 1;
19830: }
19831: if ($okvalue ne '') {
19832: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
19833: }
19834: }
19835: } else {
19836: if (($inuse == 1) && ($okvalue ne '')) {
19837: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
19838: $changes{$prefix}{$type} = 1;
19839: }
19840: }
19841: } else {
19842: if (($inuse == 1) && ($okvalue ne '')) {
19843: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
19844: $changes{$prefix}{$type} = 1;
19845: }
19846: }
19847: } else {
19848: if (($inuse == 1) && ($okvalue ne '')) {
19849: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
19850: $changes{$prefix}{$type} = 1;
19851: }
19852: }
19853: } else {
19854: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
19855: my @okvals;
19856: foreach my $val (@vals) {
1.138 raeburn 19857: if ($val =~ /:/) {
19858: my @items = split(/:/,$val);
19859: foreach my $item (@items) {
19860: if (ref($by_location{$item}) eq 'ARRAY') {
19861: push(@okvals,$item);
19862: }
19863: }
19864: } else {
19865: if (ref($by_location{$val}) eq 'ARRAY') {
19866: push(@okvals,$val);
19867: }
1.137 raeburn 19868: }
19869: }
19870: @okvals = sort(@okvals);
19871: if (ref($domconfig{'usersessions'}) eq 'HASH') {
19872: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
19873: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
19874: if ($inuse == 0) {
19875: $changes{$prefix}{$type} = 1;
19876: } else {
19877: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
19878: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
19879: if (@changed > 0) {
19880: $changes{$prefix}{$type} = 1;
19881: }
19882: }
19883: } else {
19884: if ($inuse == 1) {
19885: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
19886: $changes{$prefix}{$type} = 1;
19887: }
19888: }
19889: } else {
19890: if ($inuse == 1) {
19891: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
19892: $changes{$prefix}{$type} = 1;
19893: }
19894: }
19895: } else {
19896: if ($inuse == 1) {
19897: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
19898: $changes{$prefix}{$type} = 1;
19899: }
19900: }
19901: }
19902: }
19903: }
1.145 raeburn 19904:
19905: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 19906: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 19907: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
19908: my $savespares;
19909:
19910: foreach my $lonhost (sort(keys(%servers))) {
19911: my $serverhomeID =
19912: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 19913: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 19914: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
19915: my %spareschg;
19916: foreach my $type (@{$types{'spares'}}) {
19917: my @okspares;
19918: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
19919: foreach my $server (@checked) {
1.152 raeburn 19920: if (&Apache::lonnet::hostname($server) ne '') {
19921: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
19922: unless (grep(/^\Q$server\E$/,@okspares)) {
19923: push(@okspares,$server);
19924: }
1.145 raeburn 19925: }
19926: }
19927: }
19928: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
19929: my $newspare;
1.152 raeburn 19930: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
19931: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 19932: $newspare = $new;
19933: }
19934: }
1.152 raeburn 19935: my @spares;
19936: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
19937: @spares = sort(@okspares,$newspare);
19938: } else {
19939: @spares = sort(@okspares);
19940: }
19941: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 19942: if (ref($spareid{$lonhost}) eq 'HASH') {
19943: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 19944: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 19945: if (@diffs > 0) {
19946: $spareschg{$type} = 1;
19947: }
19948: }
19949: }
19950: }
19951: if (keys(%spareschg) > 0) {
19952: $changes{'spares'}{$lonhost} = \%spareschg;
19953: }
19954: }
1.261 raeburn 19955: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 19956: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 19957: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
19958: my @okoffload;
19959: if (@offloadnow) {
19960: foreach my $server (@offloadnow) {
19961: if (&Apache::lonnet::hostname($server) ne '') {
19962: unless (grep(/^\Q$server\E$/,@okoffload)) {
19963: push(@okoffload,$server);
19964: }
19965: }
19966: }
19967: if (@okoffload) {
19968: foreach my $lonhost (@okoffload) {
19969: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
19970: }
19971: }
19972: }
1.371 raeburn 19973: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
19974: my @okoffloadoth;
19975: if (@offloadoth) {
19976: foreach my $server (@offloadoth) {
19977: if (&Apache::lonnet::hostname($server) ne '') {
19978: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
19979: push(@okoffloadoth,$server);
19980: }
19981: }
19982: }
19983: if (@okoffloadoth) {
19984: foreach my $lonhost (@okoffloadoth) {
19985: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
19986: }
19987: }
19988: }
1.145 raeburn 19989: if (ref($domconfig{'usersessions'}) eq 'HASH') {
19990: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
19991: if (ref($changes{'spares'}) eq 'HASH') {
19992: if (keys(%{$changes{'spares'}}) > 0) {
19993: $savespares = 1;
19994: }
19995: }
19996: } else {
19997: $savespares = 1;
19998: }
1.371 raeburn 19999: foreach my $offload ('offloadnow','offloadoth') {
20000: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
20001: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
20002: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
20003: $changes{$offload} = 1;
20004: last;
20005: }
1.261 raeburn 20006: }
1.371 raeburn 20007: unless ($changes{$offload}) {
20008: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
20009: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
20010: $changes{$offload} = 1;
20011: last;
20012: }
1.261 raeburn 20013: }
20014: }
1.371 raeburn 20015: } else {
20016: if (($offload eq 'offloadnow') && (@okoffload)) {
20017: $changes{'offloadnow'} = 1;
20018: }
20019: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
20020: $changes{'offloadoth'} = 1;
20021: }
20022: }
20023: }
20024: } else {
20025: if (@okoffload) {
1.261 raeburn 20026: $changes{'offloadnow'} = 1;
20027: }
1.371 raeburn 20028: if (@okoffloadoth) {
20029: $changes{'offloadoth'} = 1;
20030: }
1.145 raeburn 20031: }
1.147 raeburn 20032: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
20033: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 20034: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20035: $dom);
20036: if ($putresult eq 'ok') {
20037: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
20038: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
20039: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
20040: }
20041: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
20042: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
20043: }
1.261 raeburn 20044: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
20045: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
20046: }
1.371 raeburn 20047: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
20048: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
20049: }
1.137 raeburn 20050: }
20051: my $cachetime = 24*60*60;
20052: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 20053: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 20054: if (ref($lastactref) eq 'HASH') {
20055: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 20056: $lastactref->{'usersessions'} = 1;
1.212 raeburn 20057: }
1.147 raeburn 20058: if (keys(%changes) > 0) {
20059: my %lt = &usersession_titles();
20060: $resulttext = &mt('Changes made:').'<ul>';
20061: foreach my $prefix (@prefixes) {
20062: if (ref($changes{$prefix}) eq 'HASH') {
20063: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
20064: if ($prefix eq 'spares') {
20065: if (ref($changes{$prefix}) eq 'HASH') {
20066: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
20067: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 20068: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 20069: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
20070: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 20071: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
20072: foreach my $type (@{$types{$prefix}}) {
20073: if ($changes{$prefix}{$lonhost}{$type}) {
20074: my $offloadto = &mt('None');
20075: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
20076: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
20077: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
20078: }
1.145 raeburn 20079: }
1.147 raeburn 20080: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 20081: }
1.137 raeburn 20082: }
20083: }
1.147 raeburn 20084: $resulttext .= '</li>';
1.137 raeburn 20085: }
20086: }
1.147 raeburn 20087: } else {
20088: foreach my $type (@{$types{$prefix}}) {
20089: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 20090: my ($newvalue,$notinuse);
1.147 raeburn 20091: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
20092: if (ref($defaultshash{'usersessions'}{$prefix})) {
20093: if ($type eq 'version') {
20094: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 20095: } else {
20096: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
20097: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
20098: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
20099: }
20100: } else {
20101: $notinuse = 1;
1.147 raeburn 20102: }
1.145 raeburn 20103: }
20104: }
20105: }
1.147 raeburn 20106: if ($newvalue eq '') {
20107: if ($type eq 'version') {
20108: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 20109: } elsif ($notinuse) {
20110: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 20111: } else {
20112: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
20113: }
1.145 raeburn 20114: } else {
1.147 raeburn 20115: if ($type eq 'version') {
1.344 raeburn 20116: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 20117: }
20118: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 20119: }
1.137 raeburn 20120: }
20121: }
20122: }
1.147 raeburn 20123: $resulttext .= '</ul>';
1.137 raeburn 20124: }
20125: }
1.261 raeburn 20126: if ($changes{'offloadnow'}) {
20127: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
20128: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 20129: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 20130: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
20131: $resulttext .= '<li>'.$lonhost.'</li>';
20132: }
20133: $resulttext .= '</ul>';
20134: } else {
1.371 raeburn 20135: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
20136: }
20137: } else {
20138: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
20139: }
20140: }
20141: if ($changes{'offloadoth'}) {
20142: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
20143: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
20144: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
20145: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
20146: $resulttext .= '<li>'.$lonhost.'</li>';
20147: }
20148: $resulttext .= '</ul>';
20149: } else {
20150: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 20151: }
20152: } else {
1.371 raeburn 20153: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 20154: }
20155: }
1.147 raeburn 20156: $resulttext .= '</ul>';
20157: } else {
20158: $resulttext = $nochgmsg;
1.137 raeburn 20159: }
20160: } else {
20161: $resulttext = '<span class="LC_error">'.
20162: &mt('An error occurred: [_1]',$putresult).'</span>';
20163: }
20164: } else {
1.147 raeburn 20165: $resulttext = $nochgmsg;
1.137 raeburn 20166: }
20167: return $resulttext;
20168: }
20169:
1.275 raeburn 20170: sub modify_ssl {
20171: my ($dom,$lastactref,%domconfig) = @_;
20172: my (%by_ip,%by_location,@intdoms,@instdoms);
20173: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
20174: my @locations = sort(keys(%by_location));
20175: my %servers = &Apache::lonnet::internet_dom_servers($dom);
20176: my (%defaultshash,%changes);
20177: my $action = 'ssl';
1.293 raeburn 20178: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 20179: foreach my $prefix (@prefixes) {
20180: $defaultshash{$action}{$prefix} = {};
20181: }
20182: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
20183: my $resulttext;
20184: my %iphost = &Apache::lonnet::get_iphost();
20185: my @reptypes = ('certreq','nocertreq');
20186: my @connecttypes = ('dom','intdom','other');
20187: my %types = (
1.293 raeburn 20188: connto => \@connecttypes,
20189: connfrom => \@connecttypes,
20190: replication => \@reptypes,
1.275 raeburn 20191: );
20192: foreach my $prefix (sort(keys(%types))) {
20193: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 20194: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 20195: my $value = 'yes';
20196: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
20197: $value = $env{'form.'.$prefix.'_'.$type};
20198: }
1.335 raeburn 20199: if (ref($domconfig{$action}) eq 'HASH') {
20200: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
20201: if ($domconfig{$action}{$prefix}{$type} ne '') {
20202: if ($value ne $domconfig{$action}{$prefix}{$type}) {
20203: $changes{$prefix}{$type} = 1;
20204: }
20205: $defaultshash{$action}{$prefix}{$type} = $value;
20206: } else {
20207: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 20208: $changes{$prefix}{$type} = 1;
20209: }
20210: } else {
20211: $defaultshash{$action}{$prefix}{$type} = $value;
20212: $changes{$prefix}{$type} = 1;
20213: }
20214: } else {
20215: $defaultshash{$action}{$prefix}{$type} = $value;
20216: $changes{$prefix}{$type} = 1;
20217: }
20218: if (($type eq 'dom') && (keys(%servers) == 1)) {
20219: delete($changes{$prefix}{$type});
20220: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
20221: delete($changes{$prefix}{$type});
20222: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
20223: delete($changes{$prefix}{$type});
20224: }
20225: } elsif ($prefix eq 'replication') {
20226: if (@locations > 0) {
20227: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
20228: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
20229: my @okvals;
20230: foreach my $val (@vals) {
20231: if ($val =~ /:/) {
20232: my @items = split(/:/,$val);
20233: foreach my $item (@items) {
20234: if (ref($by_location{$item}) eq 'ARRAY') {
20235: push(@okvals,$item);
20236: }
20237: }
20238: } else {
20239: if (ref($by_location{$val}) eq 'ARRAY') {
20240: push(@okvals,$val);
20241: }
20242: }
20243: }
20244: @okvals = sort(@okvals);
20245: if (ref($domconfig{$action}) eq 'HASH') {
20246: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
20247: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
20248: if ($inuse == 0) {
20249: $changes{$prefix}{$type} = 1;
20250: } else {
20251: $defaultshash{$action}{$prefix}{$type} = \@okvals;
20252: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
20253: if (@changed > 0) {
20254: $changes{$prefix}{$type} = 1;
20255: }
20256: }
20257: } else {
20258: if ($inuse == 1) {
20259: $defaultshash{$action}{$prefix}{$type} = \@okvals;
20260: $changes{$prefix}{$type} = 1;
20261: }
20262: }
20263: } else {
20264: if ($inuse == 1) {
20265: $defaultshash{$action}{$prefix}{$type} = \@okvals;
20266: $changes{$prefix}{$type} = 1;
20267: }
20268: }
20269: } else {
20270: if ($inuse == 1) {
20271: $defaultshash{$action}{$prefix}{$type} = \@okvals;
20272: $changes{$prefix}{$type} = 1;
20273: }
20274: }
20275: }
20276: }
20277: }
20278: }
1.336 raeburn 20279: if (keys(%changes)) {
20280: foreach my $prefix (keys(%changes)) {
20281: if (ref($changes{$prefix}) eq 'HASH') {
20282: if (scalar(keys(%{$changes{$prefix}})) == 0) {
20283: delete($changes{$prefix});
20284: }
20285: } else {
20286: delete($changes{$prefix});
20287: }
20288: }
20289: }
1.275 raeburn 20290: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
20291: if (keys(%changes) > 0) {
20292: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20293: $dom);
20294: if ($putresult eq 'ok') {
20295: if (ref($defaultshash{$action}) eq 'HASH') {
20296: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
20297: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
20298: }
1.293 raeburn 20299: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 20300: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 20301: }
20302: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 20303: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 20304: }
20305: }
20306: my $cachetime = 24*60*60;
20307: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20308: if (ref($lastactref) eq 'HASH') {
20309: $lastactref->{'domdefaults'} = 1;
20310: }
20311: if (keys(%changes) > 0) {
20312: my %titles = &ssl_titles();
20313: $resulttext = &mt('Changes made:').'<ul>';
20314: foreach my $prefix (@prefixes) {
20315: if (ref($changes{$prefix}) eq 'HASH') {
20316: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
20317: foreach my $type (@{$types{$prefix}}) {
20318: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 20319: my ($newvalue,$notinuse);
1.275 raeburn 20320: if (ref($defaultshash{$action}) eq 'HASH') {
20321: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 20322: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 20323: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 20324: } else {
20325: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
20326: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
20327: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
20328: }
20329: } else {
20330: $notinuse = 1;
1.275 raeburn 20331: }
20332: }
20333: }
1.344 raeburn 20334: if ($notinuse) {
20335: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
20336: } elsif ($newvalue eq '') {
1.275 raeburn 20337: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
20338: } else {
20339: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
20340: }
20341: }
20342: }
20343: }
20344: $resulttext .= '</ul>';
20345: }
20346: }
20347: } else {
20348: $resulttext = $nochgmsg;
20349: }
20350: } else {
20351: $resulttext = '<span class="LC_error">'.
20352: &mt('An error occurred: [_1]',$putresult).'</span>';
20353: }
20354: } else {
20355: $resulttext = $nochgmsg;
20356: }
20357: return $resulttext;
20358: }
20359:
1.279 raeburn 20360: sub modify_trust {
20361: my ($dom,$lastactref,%domconfig) = @_;
20362: my (%by_ip,%by_location,@intdoms,@instdoms);
20363: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
20364: my @locations = sort(keys(%by_location));
20365: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
20366: my @types = ('exc','inc');
20367: my (%defaultshash,%changes);
20368: foreach my $prefix (@prefixes) {
20369: $defaultshash{'trust'}{$prefix} = {};
20370: }
20371: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
20372: my $resulttext;
20373: foreach my $prefix (@prefixes) {
20374: foreach my $type (@types) {
20375: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
20376: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
20377: my @okvals;
20378: foreach my $val (@vals) {
20379: if ($val =~ /:/) {
20380: my @items = split(/:/,$val);
20381: foreach my $item (@items) {
20382: if (ref($by_location{$item}) eq 'ARRAY') {
20383: push(@okvals,$item);
20384: }
20385: }
20386: } else {
20387: if (ref($by_location{$val}) eq 'ARRAY') {
20388: push(@okvals,$val);
20389: }
20390: }
20391: }
20392: @okvals = sort(@okvals);
20393: if (ref($domconfig{'trust'}) eq 'HASH') {
20394: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
20395: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
20396: if ($inuse == 0) {
20397: $changes{$prefix}{$type} = 1;
20398: } else {
20399: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
20400: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
20401: if (@changed > 0) {
20402: $changes{$prefix}{$type} = 1;
20403: }
20404: }
20405: } else {
20406: if ($inuse == 1) {
20407: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
20408: $changes{$prefix}{$type} = 1;
20409: }
20410: }
20411: } else {
20412: if ($inuse == 1) {
20413: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
20414: $changes{$prefix}{$type} = 1;
20415: }
20416: }
20417: } else {
20418: if ($inuse == 1) {
20419: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
20420: $changes{$prefix}{$type} = 1;
20421: }
20422: }
20423: }
20424: }
20425: my $nochgmsg = &mt('No changes made to trust settings.');
20426: if (keys(%changes) > 0) {
20427: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20428: $dom);
20429: if ($putresult eq 'ok') {
20430: if (ref($defaultshash{'trust'}) eq 'HASH') {
20431: foreach my $prefix (@prefixes) {
20432: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
20433: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
20434: }
20435: }
20436: }
20437: my $cachetime = 24*60*60;
20438: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20439: if (ref($lastactref) eq 'HASH') {
20440: $lastactref->{'domdefaults'} = 1;
20441: }
20442: if (keys(%changes) > 0) {
20443: my %lt = &trust_titles();
20444: $resulttext = &mt('Changes made:').'<ul>';
20445: foreach my $prefix (@prefixes) {
20446: if (ref($changes{$prefix}) eq 'HASH') {
20447: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
20448: foreach my $type (@types) {
20449: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 20450: my ($newvalue,$notinuse);
1.279 raeburn 20451: if (ref($defaultshash{'trust'}) eq 'HASH') {
20452: if (ref($defaultshash{'trust'}{$prefix})) {
20453: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
20454: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
20455: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
20456: }
1.344 raeburn 20457: } else {
20458: $notinuse = 1;
1.279 raeburn 20459: }
20460: }
20461: }
1.344 raeburn 20462: if ($notinuse) {
20463: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
20464: } elsif ($newvalue eq '') {
1.279 raeburn 20465: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
20466: } else {
20467: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
20468: }
20469: }
20470: }
20471: $resulttext .= '</ul>';
20472: }
20473: }
20474: $resulttext .= '</ul>';
20475: } else {
20476: $resulttext = $nochgmsg;
20477: }
20478: } else {
20479: $resulttext = '<span class="LC_error">'.
20480: &mt('An error occurred: [_1]',$putresult).'</span>';
20481: }
20482: } else {
20483: $resulttext = $nochgmsg;
20484: }
20485: return $resulttext;
20486: }
20487:
1.150 raeburn 20488: sub modify_loadbalancing {
20489: my ($dom,%domconfig) = @_;
20490: my $primary_id = &Apache::lonnet::domain($dom,'primary');
20491: my $intdom = &Apache::lonnet::internet_dom($primary_id);
20492: my ($othertitle,$usertypes,$types) =
20493: &Apache::loncommon::sorted_inst_types($dom);
20494: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 20495: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 20496: my @sparestypes = ('primary','default');
20497: my %typetitles = &sparestype_titles();
20498: my $resulttext;
1.342 raeburn 20499: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 20500: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
20501: %existing = %{$domconfig{'loadbalancing'}};
20502: }
20503: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 20504: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 20505: my ($saveloadbalancing,%defaultshash,%changes);
20506: my ($alltypes,$othertypes,$titles) =
20507: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
20508: my %ruletitles = &offloadtype_text();
20509: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
20510: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
20511: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
20512: if ($balancer eq '') {
20513: next;
20514: }
1.210 raeburn 20515: if (!exists($servers{$balancer})) {
1.171 raeburn 20516: if (exists($currbalancer{$balancer})) {
20517: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 20518: }
1.171 raeburn 20519: next;
20520: }
20521: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
20522: push(@{$changes{'delete'}},$balancer);
20523: next;
20524: }
20525: if (!exists($currbalancer{$balancer})) {
20526: push(@{$changes{'add'}},$balancer);
20527: }
20528: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
20529: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
20530: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
20531: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
20532: $saveloadbalancing = 1;
20533: }
20534: foreach my $sparetype (@sparestypes) {
20535: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
20536: my @offloadto;
20537: foreach my $target (@targets) {
20538: if (($servers{$target}) && ($target ne $balancer)) {
20539: if ($sparetype eq 'default') {
20540: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
20541: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 20542: }
20543: }
1.171 raeburn 20544: unless(grep(/^\Q$target\E$/,@offloadto)) {
20545: push(@offloadto,$target);
20546: }
1.150 raeburn 20547: }
20548: }
1.284 raeburn 20549: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
20550: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
20551: push(@offloadto,$balancer);
20552: }
20553: }
20554: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 20555: }
1.342 raeburn 20556: if ($env{'form.loadbalancing_cookie_'.$i}) {
20557: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
20558: if (exists($currbalancer{$balancer})) {
20559: unless ($currcookies{$balancer}) {
20560: $changes{'curr'}{$balancer}{'cookie'} = 1;
20561: }
20562: }
20563: } elsif (exists($currbalancer{$balancer})) {
20564: if ($currcookies{$balancer}) {
20565: $changes{'curr'}{$balancer}{'cookie'} = 1;
20566: }
20567: }
1.171 raeburn 20568: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 20569: foreach my $sparetype (@sparestypes) {
1.171 raeburn 20570: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
20571: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 20572: if (@targetdiffs > 0) {
1.171 raeburn 20573: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 20574: }
1.171 raeburn 20575: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20576: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
20577: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 20578: }
20579: }
20580: }
20581: } else {
1.171 raeburn 20582: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 20583: foreach my $sparetype (@sparestypes) {
1.171 raeburn 20584: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20585: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
20586: $changes{'curr'}{$balancer}{'targets'} = 1;
20587: }
1.150 raeburn 20588: }
20589: }
1.210 raeburn 20590: }
1.150 raeburn 20591: }
20592: my $ishomedom;
1.171 raeburn 20593: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
20594: $ishomedom = 1;
1.150 raeburn 20595: }
20596: if (ref($alltypes) eq 'ARRAY') {
20597: foreach my $type (@{$alltypes}) {
20598: my $rule;
1.210 raeburn 20599: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 20600: (!$ishomedom)) {
1.171 raeburn 20601: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
20602: }
20603: if ($rule eq 'specific') {
1.255 raeburn 20604: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 20605: if (exists($servers{$specifiedhost})) {
1.255 raeburn 20606: $rule = $specifiedhost;
20607: }
1.150 raeburn 20608: }
1.171 raeburn 20609: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
20610: if (ref($currrules{$balancer}) eq 'HASH') {
20611: if ($rule ne $currrules{$balancer}{$type}) {
20612: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 20613: }
20614: } elsif ($rule ne '') {
1.171 raeburn 20615: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 20616: }
20617: }
20618: }
1.171 raeburn 20619: }
20620: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
20621: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
20622: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
20623: $defaultshash{'loadbalancing'} = {};
20624: }
20625: my $putresult = &Apache::lonnet::put_dom('configuration',
20626: \%defaultshash,$dom);
20627: if ($putresult eq 'ok') {
20628: if (keys(%changes) > 0) {
1.252 raeburn 20629: my %toupdate;
1.171 raeburn 20630: if (ref($changes{'delete'}) eq 'ARRAY') {
20631: foreach my $balancer (sort(@{$changes{'delete'}})) {
20632: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 20633: $toupdate{$balancer} = 1;
1.150 raeburn 20634: }
1.171 raeburn 20635: }
20636: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 20637: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 20638: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 20639: $toupdate{$balancer} = 1;
1.171 raeburn 20640: }
20641: }
20642: if (ref($changes{'curr'}) eq 'HASH') {
20643: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 20644: $toupdate{$balancer} = 1;
1.171 raeburn 20645: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
20646: if ($changes{'curr'}{$balancer}{'targets'}) {
20647: my %offloadstr;
20648: foreach my $sparetype (@sparestypes) {
20649: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20650: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
20651: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
20652: }
20653: }
1.150 raeburn 20654: }
1.171 raeburn 20655: if (keys(%offloadstr) == 0) {
20656: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 20657: } else {
1.171 raeburn 20658: my $showoffload;
20659: foreach my $sparetype (@sparestypes) {
20660: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
20661: if (defined($offloadstr{$sparetype})) {
20662: $showoffload .= $offloadstr{$sparetype};
20663: } else {
20664: $showoffload .= &mt('None');
20665: }
20666: $showoffload .= (' 'x3);
20667: }
20668: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 20669: }
20670: }
20671: }
1.171 raeburn 20672: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
20673: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
20674: foreach my $type (@{$alltypes}) {
20675: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
20676: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
20677: my $balancetext;
20678: if ($rule eq '') {
20679: $balancetext = $ruletitles{'default'};
1.209 raeburn 20680: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 20681: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 20682: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 20683: foreach my $sparetype (@sparestypes) {
20684: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20685: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
20686: }
20687: }
1.253 raeburn 20688: foreach my $item (@{$alltypes}) {
20689: next if ($item =~ /^_LC_ipchange/);
20690: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
20691: if ($hasrule eq 'homeserver') {
20692: map { $toupdate{$_} = 1; } (keys(%libraryservers));
20693: } else {
20694: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
20695: if ($servers{$hasrule}) {
20696: $toupdate{$hasrule} = 1;
20697: }
20698: }
20699: }
20700: }
1.254 raeburn 20701: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
20702: $balancetext = $ruletitles{$rule};
20703: } else {
20704: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
20705: $balancetext = $ruletitles{'particular'}.' '.$receiver;
20706: if ($receiver) {
20707: $toupdate{$receiver};
20708: }
20709: }
20710: } else {
20711: $balancetext = $ruletitles{$rule};
1.252 raeburn 20712: }
1.171 raeburn 20713: } else {
20714: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
20715: }
1.210 raeburn 20716: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 20717: }
20718: }
20719: }
20720: }
1.342 raeburn 20721: if ($changes{'curr'}{$balancer}{'cookie'}) {
20722: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
20723: $balancer).'</li>';
20724: }
1.375 raeburn 20725: }
20726: }
20727: if (keys(%toupdate)) {
20728: my %thismachine;
20729: my $updatedhere;
20730: my $cachetime = 60*60*24;
20731: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
20732: foreach my $lonhost (keys(%toupdate)) {
20733: if ($thismachine{$lonhost}) {
20734: unless ($updatedhere) {
20735: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
20736: $defaultshash{'loadbalancing'},
20737: $cachetime);
20738: $updatedhere = 1;
1.252 raeburn 20739: }
1.375 raeburn 20740: } else {
20741: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
20742: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 20743: }
1.150 raeburn 20744: }
1.171 raeburn 20745: }
20746: if ($resulttext ne '') {
20747: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 20748: } else {
20749: $resulttext = $nochgmsg;
20750: }
20751: } else {
1.171 raeburn 20752: $resulttext = $nochgmsg;
1.150 raeburn 20753: }
20754: } else {
1.171 raeburn 20755: $resulttext = '<span class="LC_error">'.
20756: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 20757: }
20758: } else {
1.171 raeburn 20759: $resulttext = $nochgmsg;
1.150 raeburn 20760: }
20761: return $resulttext;
20762: }
20763:
1.48 raeburn 20764: sub recurse_check {
20765: my ($chkcats,$categories,$depth,$name) = @_;
20766: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
20767: my $chg = 0;
20768: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
20769: my $category = $chkcats->[$depth]{$name}[$j];
20770: my $item;
20771: if ($category eq '') {
20772: $chg ++;
20773: } else {
20774: my $deeper = $depth + 1;
20775: $item = &escape($category).':'.&escape($name).':'.$depth;
20776: if ($chg) {
20777: $categories->{$item} -= $chg;
20778: }
20779: &recurse_check($chkcats,$categories,$deeper,$category);
20780: $deeper --;
20781: }
20782: }
20783: }
20784: return;
20785: }
20786:
20787: sub recurse_cat_deletes {
20788: my ($item,$coursecategories,$deletions) = @_;
20789: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
20790: my $subdepth = $depth + 1;
20791: if (ref($coursecategories) eq 'HASH') {
20792: foreach my $subitem (keys(%{$coursecategories})) {
20793: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
20794: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
20795: delete($coursecategories->{$subitem});
20796: $deletions->{$subitem} = 1;
20797: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 20798: }
1.48 raeburn 20799: }
20800: }
20801: return;
20802: }
20803:
1.125 raeburn 20804: sub active_dc_picker {
1.191 raeburn 20805: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 20806: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 20807: my @domcoord = keys(%domcoords);
20808: if (keys(%currhash)) {
20809: foreach my $dc (keys(%currhash)) {
20810: unless (exists($domcoords{$dc})) {
20811: push(@domcoord,$dc);
20812: }
20813: }
20814: }
20815: @domcoord = sort(@domcoord);
1.210 raeburn 20816: my $numdcs = scalar(@domcoord);
1.191 raeburn 20817: my $rows = 0;
20818: my $table;
1.125 raeburn 20819: if ($numdcs > 1) {
1.191 raeburn 20820: $table = '<table>';
20821: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 20822: my $rem = $i%($numinrow);
20823: if ($rem == 0) {
20824: if ($i > 0) {
1.191 raeburn 20825: $table .= '</tr>';
1.125 raeburn 20826: }
1.191 raeburn 20827: $table .= '<tr>';
20828: $rows ++;
1.125 raeburn 20829: }
1.191 raeburn 20830: my $check = '';
20831: if ($inputtype eq 'radio') {
20832: if (keys(%currhash) == 0) {
20833: if (!$i) {
20834: $check = ' checked="checked"';
20835: }
20836: } elsif (exists($currhash{$domcoord[$i]})) {
20837: $check = ' checked="checked"';
20838: }
20839: } else {
20840: if (exists($currhash{$domcoord[$i]})) {
20841: $check = ' checked="checked"';
1.125 raeburn 20842: }
20843: }
1.191 raeburn 20844: if ($i == @domcoord - 1) {
1.125 raeburn 20845: my $colsleft = $numinrow - $rem;
20846: if ($colsleft > 1) {
1.191 raeburn 20847: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 20848: } else {
1.191 raeburn 20849: $table .= '<td class="LC_left_item">';
1.125 raeburn 20850: }
20851: } else {
1.191 raeburn 20852: $table .= '<td class="LC_left_item">';
20853: }
20854: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
20855: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
20856: $table .= '<span class="LC_nobreak"><label>'.
20857: '<input type="'.$inputtype.'" name="'.$name.'"'.
20858: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
20859: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 20860: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 20861: }
1.219 raeburn 20862: $table .= '</label></span></td>';
1.191 raeburn 20863: }
20864: $table .= '</tr></table>';
20865: } elsif ($numdcs == 1) {
1.219 raeburn 20866: my ($dcname,$dcdom) = split(':',$domcoord[0]);
20867: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 20868: if ($inputtype eq 'radio') {
1.247 raeburn 20869: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 20870: if ($user ne $dcname.':'.$dcdom) {
20871: $table .= ' ('.$dcname.':'.$dcdom.')';
20872: }
1.191 raeburn 20873: } else {
20874: my $check;
20875: if (exists($currhash{$domcoord[0]})) {
20876: $check = ' checked="checked"';
1.125 raeburn 20877: }
1.247 raeburn 20878: $table = '<span class="LC_nobreak"><label>'.
20879: '<input type="checkbox" name="'.$name.'" '.
20880: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 20881: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 20882: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 20883: }
1.220 raeburn 20884: $table .= '</label></span>';
1.191 raeburn 20885: $rows ++;
1.125 raeburn 20886: }
20887: }
1.191 raeburn 20888: return ($numdcs,$table,$rows);
1.125 raeburn 20889: }
20890:
1.137 raeburn 20891: sub usersession_titles {
20892: return &Apache::lonlocal::texthash(
20893: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
20894: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 20895: spares => 'Servers offloaded to, when busy',
1.137 raeburn 20896: version => 'LON-CAPA version requirement',
1.138 raeburn 20897: excludedomain => 'Allow all, but exclude specific domains',
20898: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 20899: primary => 'Primary (checked first)',
1.154 raeburn 20900: default => 'Default',
1.137 raeburn 20901: );
20902: }
20903:
1.152 raeburn 20904: sub id_for_thisdom {
20905: my (%servers) = @_;
20906: my %altids;
20907: foreach my $server (keys(%servers)) {
20908: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
20909: if ($serverhome ne $server) {
20910: $altids{$serverhome} = $server;
20911: }
20912: }
20913: return %altids;
20914: }
20915:
1.150 raeburn 20916: sub count_servers {
20917: my ($currbalancer,%servers) = @_;
20918: my (@spares,$numspares);
20919: foreach my $lonhost (sort(keys(%servers))) {
20920: next if ($currbalancer eq $lonhost);
20921: push(@spares,$lonhost);
20922: }
20923: if ($currbalancer) {
20924: $numspares = scalar(@spares);
20925: } else {
20926: $numspares = scalar(@spares) - 1;
20927: }
20928: return ($numspares,@spares);
20929: }
20930:
20931: sub lonbalance_targets_js {
1.171 raeburn 20932: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 20933: my $select = &mt('Select');
20934: my ($alltargets,$allishome,$allinsttypes,@alltypes);
20935: if (ref($servers) eq 'HASH') {
20936: $alltargets = join("','",sort(keys(%{$servers})));
20937: my @homedoms;
20938: foreach my $server (sort(keys(%{$servers}))) {
20939: if (&Apache::lonnet::host_domain($server) eq $dom) {
20940: push(@homedoms,'1');
20941: } else {
20942: push(@homedoms,'0');
20943: }
20944: }
20945: $allishome = join("','",@homedoms);
20946: }
20947: if (ref($types) eq 'ARRAY') {
20948: if (@{$types} > 0) {
20949: @alltypes = @{$types};
20950: }
20951: }
20952: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
20953: $allinsttypes = join("','",@alltypes);
1.342 raeburn 20954: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 20955: if (ref($settings) eq 'HASH') {
20956: %existing = %{$settings};
20957: }
20958: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 20959: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 20960: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 20961: return <<"END";
20962:
20963: <script type="text/javascript">
20964: // <![CDATA[
20965:
1.171 raeburn 20966: currBalancers = new Array('$balancers');
20967:
20968: function toggleTargets(balnum) {
20969: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
20970: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
20971: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
20972: var prevbalancer = prevhostitem.value;
20973: var baltotal = document.getElementById('loadbalancing_total').value;
20974: prevhostitem.value = balancer;
20975: if (prevbalancer != '') {
20976: var prevIdx = currBalancers.indexOf(prevbalancer);
20977: if (prevIdx != -1) {
20978: currBalancers.splice(prevIdx,1);
20979: }
20980: }
1.150 raeburn 20981: if (balancer == '') {
1.171 raeburn 20982: hideSpares(balnum);
1.150 raeburn 20983: } else {
1.171 raeburn 20984: var currIdx = currBalancers.indexOf(balancer);
20985: if (currIdx == -1) {
20986: currBalancers.push(balancer);
20987: }
1.150 raeburn 20988: var homedoms = new Array('$allishome');
1.171 raeburn 20989: var ishomedom = homedoms[lonhostitem.selectedIndex];
20990: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 20991: }
1.171 raeburn 20992: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 20993: return;
20994: }
20995:
1.171 raeburn 20996: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 20997: var alltargets = new Array('$alltargets');
20998: var insttypes = new Array('$allinsttypes');
1.151 raeburn 20999: var offloadtypes = new Array('primary','default');
21000:
1.171 raeburn 21001: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
21002: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 21003:
1.151 raeburn 21004: for (var i=0; i<offloadtypes.length; i++) {
21005: var count = 0;
21006: for (var j=0; j<alltargets.length; j++) {
21007: if (alltargets[j] != balancer) {
1.171 raeburn 21008: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
21009: item.value = alltargets[j];
21010: item.style.textAlign='left';
21011: item.style.textFace='normal';
21012: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
21013: if (currBalancers.indexOf(alltargets[j]) == -1) {
21014: item.disabled = '';
21015: } else {
21016: item.disabled = 'disabled';
21017: item.checked = false;
21018: }
1.151 raeburn 21019: count ++;
21020: }
1.150 raeburn 21021: }
21022: }
1.151 raeburn 21023: for (var k=0; k<insttypes.length; k++) {
21024: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 21025: if (ishomedom == 1) {
1.171 raeburn 21026: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
21027: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 21028: } else {
1.171 raeburn 21029: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
21030: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 21031: }
21032: } else {
1.171 raeburn 21033: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
21034: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 21035: }
1.151 raeburn 21036: if ((insttypes[k] != '_LC_external') &&
21037: ((insttypes[k] != '_LC_internetdom') ||
21038: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 21039: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
21040: item.options.length = 0;
21041: item.options[0] = new Option("","",true,true);
1.210 raeburn 21042: var idx = 0;
1.151 raeburn 21043: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 21044: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
21045: idx ++;
21046: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 21047: }
21048: }
21049: }
21050: }
21051: return;
21052: }
21053:
1.171 raeburn 21054: function hideSpares(balnum) {
1.150 raeburn 21055: var alltargets = new Array('$alltargets');
21056: var insttypes = new Array('$allinsttypes');
21057: var offloadtypes = new Array('primary','default');
21058:
1.171 raeburn 21059: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
21060: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 21061:
21062: var total = alltargets.length - 1;
21063: for (var i=0; i<offloadtypes; i++) {
21064: for (var j=0; j<total; j++) {
1.171 raeburn 21065: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
21066: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
21067: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 21068: }
1.150 raeburn 21069: }
21070: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 21071: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
21072: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 21073: if (insttypes[k] != '_LC_external') {
1.171 raeburn 21074: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
21075: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 21076: }
21077: }
21078: return;
21079: }
21080:
1.171 raeburn 21081: function checkOffloads(item,balnum,type) {
1.150 raeburn 21082: var alltargets = new Array('$alltargets');
21083: var offloadtypes = new Array('primary','default');
21084: if (item.checked) {
21085: var total = alltargets.length - 1;
21086: var other;
21087: if (type == offloadtypes[0]) {
1.151 raeburn 21088: other = offloadtypes[1];
1.150 raeburn 21089: } else {
1.151 raeburn 21090: other = offloadtypes[0];
1.150 raeburn 21091: }
21092: for (var i=0; i<total; i++) {
1.171 raeburn 21093: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 21094: if (server == item.value) {
1.171 raeburn 21095: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
21096: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 21097: }
21098: }
21099: }
21100: }
21101: return;
21102: }
21103:
1.171 raeburn 21104: function singleServerToggle(balnum,type) {
21105: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 21106: if (offloadtoSelIdx == 0) {
1.171 raeburn 21107: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
21108: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 21109:
21110: } else {
1.171 raeburn 21111: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
21112: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 21113: }
21114: return;
21115: }
21116:
1.171 raeburn 21117: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 21118: if (type == '_LC_external') {
1.171 raeburn 21119: return;
1.150 raeburn 21120: }
1.171 raeburn 21121: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 21122: for (var i=0; i<typesRules.length; i++) {
21123: if (formname.elements[typesRules[i]].checked) {
21124: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 21125: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
21126: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 21127: } else {
1.171 raeburn 21128: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
21129: }
21130: }
21131: }
21132: return;
21133: }
21134:
21135: function balancerDeleteChange(balnum) {
21136: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
21137: var baltotal = document.getElementById('loadbalancing_total').value;
21138: var addtarget;
21139: var removetarget;
21140: var action = 'delete';
21141: if (document.getElementById('loadbalancing_delete_'+balnum)) {
21142: var lonhost = hostitem.value;
21143: var currIdx = currBalancers.indexOf(lonhost);
21144: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
21145: if (currIdx != -1) {
21146: currBalancers.splice(currIdx,1);
21147: }
21148: addtarget = lonhost;
21149: } else {
21150: if (currIdx == -1) {
21151: currBalancers.push(lonhost);
21152: }
21153: removetarget = lonhost;
21154: action = 'undelete';
21155: }
21156: balancerChange(balnum,baltotal,action,addtarget,removetarget);
21157: }
21158: return;
21159: }
21160:
21161: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
21162: if (baltotal > 1) {
21163: var offloadtypes = new Array('primary','default');
21164: var alltargets = new Array('$alltargets');
21165: var insttypes = new Array('$allinsttypes');
21166: for (var i=0; i<baltotal; i++) {
21167: if (i != balnum) {
21168: for (var j=0; j<offloadtypes.length; j++) {
21169: var total = alltargets.length - 1;
21170: for (var k=0; k<total; k++) {
21171: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
21172: var server = serveritem.value;
21173: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
21174: if (server == addtarget) {
21175: serveritem.disabled = '';
21176: }
21177: }
21178: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
21179: if (server == removetarget) {
21180: serveritem.disabled = 'disabled';
21181: serveritem.checked = false;
21182: }
21183: }
21184: }
21185: }
21186: for (var j=0; j<insttypes.length; j++) {
21187: if (insttypes[j] != '_LC_external') {
21188: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
21189: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
21190: var currSel = singleserver.selectedIndex;
21191: var currVal = singleserver.options[currSel].value;
21192: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
21193: var numoptions = singleserver.options.length;
21194: var needsnew = 1;
21195: for (var k=0; k<numoptions; k++) {
21196: if (singleserver.options[k] == addtarget) {
21197: needsnew = 0;
21198: break;
21199: }
21200: }
21201: if (needsnew == 1) {
21202: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
21203: }
21204: }
21205: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
21206: singleserver.options.length = 0;
21207: if ((currVal) && (currVal != removetarget)) {
21208: singleserver.options[0] = new Option("","",false,false);
21209: } else {
21210: singleserver.options[0] = new Option("","",true,true);
21211: }
21212: var idx = 0;
21213: for (var m=0; m<alltargets.length; m++) {
21214: if (currBalancers.indexOf(alltargets[m]) == -1) {
21215: idx ++;
21216: if (currVal == alltargets[m]) {
21217: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
21218: } else {
21219: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
21220: }
21221: }
21222: }
21223: }
21224: }
21225: }
21226: }
1.150 raeburn 21227: }
21228: }
21229: }
21230: return;
21231: }
21232:
1.152 raeburn 21233: // ]]>
21234: </script>
21235:
21236: END
21237: }
21238:
1.372 raeburn 21239:
1.152 raeburn 21240: sub new_spares_js {
21241: my @sparestypes = ('primary','default');
21242: my $types = join("','",@sparestypes);
21243: my $select = &mt('Select');
21244: return <<"END";
21245:
21246: <script type="text/javascript">
21247: // <![CDATA[
21248:
21249: function updateNewSpares(formname,lonhost) {
21250: var types = new Array('$types');
21251: var include = new Array();
21252: var exclude = new Array();
21253: for (var i=0; i<types.length; i++) {
21254: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
21255: for (var j=0; j<spareboxes.length; j++) {
21256: if (formname.elements[spareboxes[j]].checked) {
21257: exclude.push(formname.elements[spareboxes[j]].value);
21258: } else {
21259: include.push(formname.elements[spareboxes[j]].value);
21260: }
21261: }
21262: }
21263: for (var i=0; i<types.length; i++) {
21264: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
21265: var selIdx = newSpare.selectedIndex;
21266: var currnew = newSpare.options[selIdx].value;
21267: var okSpares = new Array();
21268: for (var j=0; j<newSpare.options.length; j++) {
21269: var possible = newSpare.options[j].value;
21270: if (possible != '') {
21271: if (exclude.indexOf(possible) == -1) {
21272: okSpares.push(possible);
21273: } else {
21274: if (currnew == possible) {
21275: selIdx = 0;
21276: }
21277: }
21278: }
21279: }
21280: for (var k=0; k<include.length; k++) {
21281: if (okSpares.indexOf(include[k]) == -1) {
21282: okSpares.push(include[k]);
21283: }
21284: }
21285: okSpares.sort();
21286: newSpare.options.length = 0;
21287: if (selIdx == 0) {
21288: newSpare.options[0] = new Option("$select","",true,true);
21289: } else {
21290: newSpare.options[0] = new Option("$select","",false,false);
21291: }
21292: for (var m=0; m<okSpares.length; m++) {
21293: var idx = m+1;
21294: var selThis = 0;
21295: if (selIdx != 0) {
21296: if (okSpares[m] == currnew) {
21297: selThis = 1;
21298: }
21299: }
21300: if (selThis == 1) {
21301: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
21302: } else {
21303: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
21304: }
21305: }
21306: }
21307: return;
21308: }
21309:
21310: function checkNewSpares(lonhost,type) {
21311: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
21312: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 21313: if (chosen != '') {
1.152 raeburn 21314: var othertype;
21315: var othernewSpare;
21316: if (type == 'primary') {
21317: othernewSpare = document.getElementById('newspare_default_'+lonhost);
21318: }
21319: if (type == 'default') {
21320: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
21321: }
21322: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
21323: othernewSpare.selectedIndex = 0;
21324: }
21325: }
21326: return;
21327: }
21328:
21329: // ]]>
21330: </script>
21331:
21332: END
21333:
21334: }
21335:
21336: sub common_domprefs_js {
21337: return <<"END";
21338:
21339: <script type="text/javascript">
21340: // <![CDATA[
21341:
1.150 raeburn 21342: function getIndicesByName(formname,item) {
1.152 raeburn 21343: var group = new Array();
1.150 raeburn 21344: for (var i=0;i<formname.elements.length;i++) {
21345: if (formname.elements[i].name == item) {
1.152 raeburn 21346: group.push(formname.elements[i].id);
1.150 raeburn 21347: }
21348: }
1.152 raeburn 21349: return group;
1.150 raeburn 21350: }
21351:
21352: // ]]>
21353: </script>
21354:
21355: END
1.152 raeburn 21356:
1.150 raeburn 21357: }
21358:
1.165 raeburn 21359: sub recaptcha_js {
21360: my %lt = &captcha_phrases();
21361: return <<"END";
21362:
21363: <script type="text/javascript">
21364: // <![CDATA[
21365:
21366: function updateCaptcha(caller,context) {
21367: var privitem;
21368: var pubitem;
21369: var privtext;
21370: var pubtext;
1.269 raeburn 21371: var versionitem;
21372: var versiontext;
1.165 raeburn 21373: if (document.getElementById(context+'_recaptchapub')) {
21374: pubitem = document.getElementById(context+'_recaptchapub');
21375: } else {
21376: return;
21377: }
21378: if (document.getElementById(context+'_recaptchapriv')) {
21379: privitem = document.getElementById(context+'_recaptchapriv');
21380: } else {
21381: return;
21382: }
21383: if (document.getElementById(context+'_recaptchapubtxt')) {
21384: pubtext = document.getElementById(context+'_recaptchapubtxt');
21385: } else {
21386: return;
21387: }
21388: if (document.getElementById(context+'_recaptchaprivtxt')) {
21389: privtext = document.getElementById(context+'_recaptchaprivtxt');
21390: } else {
21391: return;
21392: }
1.269 raeburn 21393: if (document.getElementById(context+'_recaptchaversion')) {
21394: versionitem = document.getElementById(context+'_recaptchaversion');
21395: } else {
21396: return;
21397: }
21398: if (document.getElementById(context+'_recaptchavertxt')) {
21399: versiontext = document.getElementById(context+'_recaptchavertxt');
21400: } else {
21401: return;
21402: }
1.165 raeburn 21403: if (caller.checked) {
21404: if (caller.value == 'recaptcha') {
21405: pubitem.type = 'text';
21406: privitem.type = 'text';
21407: pubitem.size = '40';
21408: privitem.size = '40';
21409: pubtext.innerHTML = "$lt{'pub'}";
21410: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 21411: versionitem.type = 'text';
21412: versionitem.size = '3';
1.289 raeburn 21413: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 21414: } else {
21415: pubitem.type = 'hidden';
21416: privitem.type = 'hidden';
1.269 raeburn 21417: versionitem.type = 'hidden';
1.165 raeburn 21418: pubtext.innerHTML = '';
21419: privtext.innerHTML = '';
1.269 raeburn 21420: versiontext.innerHTML = '';
1.165 raeburn 21421: }
21422: }
21423: return;
21424: }
21425:
21426: // ]]>
21427: </script>
21428:
21429: END
21430:
21431: }
21432:
1.236 raeburn 21433: sub toggle_display_js {
1.192 raeburn 21434: return <<"END";
21435:
21436: <script type="text/javascript">
21437: // <![CDATA[
21438:
1.236 raeburn 21439: function toggleDisplay(domForm,caller) {
21440: if (document.getElementById(caller)) {
21441: var divitem = document.getElementById(caller);
21442: var optionsElement = domForm.coursecredits;
1.264 raeburn 21443: var checkval = 1;
21444: var dispval = 'block';
1.303 raeburn 21445: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 21446: if (caller == 'emailoptions') {
1.372 raeburn 21447: optionsElement = domForm.cancreate_email;
1.236 raeburn 21448: }
1.257 raeburn 21449: if (caller == 'studentsubmission') {
21450: optionsElement = domForm.postsubmit;
21451: }
1.264 raeburn 21452: if (caller == 'cloneinstcode') {
21453: optionsElement = domForm.canclone;
21454: checkval = 'instcode';
21455: }
1.303 raeburn 21456: if (selfcreateRegExp.test(caller)) {
21457: optionsElement = domForm.elements[caller];
21458: checkval = 'other';
21459: dispval = 'inline'
21460: }
1.236 raeburn 21461: if (optionsElement.length) {
1.192 raeburn 21462: var currval;
1.236 raeburn 21463: for (var i=0; i<optionsElement.length; i++) {
21464: if (optionsElement[i].checked) {
21465: currval = optionsElement[i].value;
1.192 raeburn 21466: }
21467: }
1.264 raeburn 21468: if (currval == checkval) {
21469: divitem.style.display = dispval;
1.192 raeburn 21470: } else {
1.236 raeburn 21471: divitem.style.display = 'none';
1.192 raeburn 21472: }
21473: }
21474: }
21475: return;
21476: }
21477:
21478: // ]]>
21479: </script>
21480:
21481: END
21482:
21483: }
21484:
1.165 raeburn 21485: sub captcha_phrases {
21486: return &Apache::lonlocal::texthash (
21487: priv => 'Private key',
21488: pub => 'Public key',
21489: original => 'original (CAPTCHA)',
21490: recaptcha => 'successor (ReCAPTCHA)',
21491: notused => 'unused',
1.289 raeburn 21492: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 21493: );
21494: }
21495:
1.205 raeburn 21496: sub devalidate_remote_domconfs {
1.212 raeburn 21497: my ($dom,$cachekeys) = @_;
21498: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 21499: my %servers = &Apache::lonnet::internet_dom_servers($dom);
21500: my %thismachine;
21501: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 21502: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.373 raeburn 21503: 'directorysrch','passwdconf','cats','proxyalias');
1.260 raeburn 21504: if (keys(%servers)) {
1.205 raeburn 21505: foreach my $server (keys(%servers)) {
21506: next if ($thismachine{$server});
1.212 raeburn 21507: my @cached;
21508: foreach my $name (@posscached) {
21509: if ($cachekeys->{$name}) {
1.373 raeburn 21510: if ($name eq 'proxyalias') {
21511: if (ref($cachekeys->{$name}) eq 'HASH') {
21512: foreach my $key (keys(%{$cachekeys->{$name}})) {
21513: push(@cached,&escape($name).':'.&escape($key));
21514: }
21515: }
21516: } else {
21517: push(@cached,&escape($name).':'.&escape($dom));
21518: }
1.212 raeburn 21519: }
21520: }
21521: if (@cached) {
21522: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
21523: }
1.205 raeburn 21524: }
21525: }
21526: return;
21527: }
21528:
1.3 raeburn 21529: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>