Annotation of loncom/interface/domainprefs.pm, revision 1.379
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.379 ! raeburn 4: # $Id: domainprefs.pm,v 1.378 2021/02/01 15:58:41 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') {
1.378 raeburn 3784: my (%current,%excluded,%weights);
1.340 raeburn 3785: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
3786: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378 raeburn 3787: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340 raeburn 3788: } else {
1.378 raeburn 3789: $current{'errorthreshold'} = $defaults->{'threshold'};
1.340 raeburn 3790: }
3791: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378 raeburn 3792: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340 raeburn 3793: } else {
1.378 raeburn 3794: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340 raeburn 3795: }
3796: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 3797: foreach my $type ('E','W','N','U') {
1.340 raeburn 3798: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
3799: $weights{$type} = $lonstatus{'weights'}{$type};
3800: } else {
3801: $weights{$type} = $defaults->{$type};
3802: }
3803: }
3804: } else {
1.341 raeburn 3805: foreach my $type ('E','W','N','U') {
1.340 raeburn 3806: $weights{$type} = $defaults->{$type};
3807: }
3808: }
3809: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
3810: if (@{$lonstatus{'excluded'}} > 0) {
3811: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
3812: }
3813: }
1.378 raeburn 3814: foreach my $item ('errorthreshold','errorsysmail') {
3815: $css_class = $rownum%2?' class="LC_odd_row"':'';
3816: $datatable .= '<tr'.$css_class.'>'.
3817: '<td class="LC_left_item"><span class="LC_nobreak">'.
3818: $titles->{$item}.
3819: '</span></td><td class="LC_left_item">'.
3820: '<input type="text" name="'.$item.'" value="'.
3821: $current{$item}.'" size="5" /></td></tr>';
3822: $rownum ++;
3823: }
1.340 raeburn 3824: $css_class = $rownum%2?' class="LC_odd_row"':'';
3825: $datatable .= '<tr'.$css_class.'>'.
3826: '<td class="LC_left_item">'.
3827: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
3828: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 3829: foreach my $type ('E','W','N','U') {
1.340 raeburn 3830: $datatable .= '<td>'.$names->{$type}.'<br />'.
3831: '<input type="text" name="errorweights_'.$type.'" value="'.
3832: $weights{$type}.'" size="5" /></td>';
3833: }
3834: $datatable .= '</tr></table></tr>';
3835: $rownum ++;
3836: $css_class = $rownum%2?' class="LC_odd_row"':'';
3837: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
3838: $titles->{'errorexcluded'}.'</td>'.
3839: '<td class="LC_left_item"><table>';
3840: my $numinrow = 4;
3841: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
3842: for (my $i=0; $i<@ids; $i++) {
3843: my $rem = $i%($numinrow);
3844: if ($rem == 0) {
3845: if ($i > 0) {
3846: $datatable .= '</tr>';
3847: }
3848: $datatable .= '<tr>';
3849: }
3850: my $check;
3851: if ($excluded{$ids[$i]}) {
3852: $check = ' checked="checked" ';
3853: }
3854: $datatable .= '<td class="LC_left_item">'.
3855: '<span class="LC_nobreak"><label>'.
3856: '<input type="checkbox" name="errorexcluded" '.
3857: 'value="'.$ids[$i].'"'.$check.' />'.
3858: $ids[$i].'</label></span></td>';
3859: }
3860: my $colsleft = $numinrow - @ids%($numinrow);
3861: if ($colsleft > 1 ) {
3862: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3863: ' </td>';
3864: } elsif ($colsleft == 1) {
3865: $datatable .= '<td class="LC_left_item"> </td>';
3866: }
3867: $datatable .= '</tr></table></td></tr>';
3868: $rownum ++;
1.286 raeburn 3869: } elsif ($position eq 'bottom') {
1.315 raeburn 3870: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3871: my (@posstypes,%usertypeshash);
3872: if (ref($types) eq 'ARRAY') {
3873: @posstypes = @{$types};
3874: }
3875: if (@posstypes) {
3876: if (ref($usertypes) eq 'HASH') {
3877: %usertypeshash = %{$usertypes};
3878: }
3879: my @overridden;
3880: my $numinrow = 4;
3881: if (ref($settings) eq 'HASH') {
3882: if (ref($settings->{'overrides'}) eq 'HASH') {
3883: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3884: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3885: push(@overridden,$key);
3886: foreach my $item (@contacts) {
3887: if ($settings->{'overrides'}{$key}{$item}) {
3888: $checked{'override_'.$key}{$item} = ' checked="checked" ';
3889: }
3890: }
3891: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3892: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3893: $includeloc{'override_'.$key} = '';
3894: $includestr{'override_'.$key} = '';
3895: if ($settings->{'overrides'}{$key}{'include'} ne '') {
3896: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3897: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3898: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3899: }
1.286 raeburn 3900: }
3901: }
3902: }
1.315 raeburn 3903: }
3904: my $customclass = 'LC_helpdesk_override';
3905: my $optionsprefix = 'LC_options_helpdesk_';
3906:
3907: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3908:
3909: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3910: $numinrow,$othertitle,'overrides',
3911: \$rownum,$onclicktypes,$customclass);
3912: $rownum ++;
3913: $usertypeshash{'default'} = $othertitle;
3914: foreach my $status (@posstypes) {
3915: my $css_class;
3916: if ($rownum%2) {
3917: $css_class = 'LC_odd_row ';
3918: }
3919: $css_class .= $customclass;
3920: my $rowid = $optionsprefix.$status;
3921: my $hidden = 1;
3922: my $currstyle = 'display:none';
3923: if (grep(/^\Q$status\E$/,@overridden)) {
3924: $currstyle = 'display:table-row';
3925: $hidden = 0;
3926: }
3927: my $key = 'override_'.$status;
3928: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3929: $includeloc{$key},$includestr{$key},$status,$rowid,
3930: $usertypeshash{$status},$css_class,$currstyle,
3931: \@contacts,$short_titles);
3932: unless ($hidden) {
3933: $rownum ++;
1.286 raeburn 3934: }
3935: }
1.134 raeburn 3936: }
1.28 raeburn 3937: }
1.30 raeburn 3938: $$rowtotal += $rownum;
1.28 raeburn 3939: return $datatable;
3940: }
3941:
1.340 raeburn 3942: sub core_link_msu {
3943: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3944: &mt('LON-CAPA core group - MSU'),600,500);
3945: }
3946:
1.315 raeburn 3947: sub overridden_helpdesk {
3948: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3949: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3950: my $class = 'LC_left_item';
3951: if ($css_class) {
3952: $css_class = ' class="'.$css_class.'"';
3953: }
3954: if ($rowid) {
3955: $rowid = ' id="'.$rowid.'"';
3956: }
3957: if ($rowstyle) {
3958: $rowstyle = ' style="'.$rowstyle.'"';
3959: }
3960: my ($output,$description);
3961: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3962: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3963: "<td>$description</td>\n".
3964: '<td class="'.$class.'" colspan="2">'.
3965: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3966: '<span class="LC_nobreak">';
3967: if (ref($contacts) eq 'ARRAY') {
3968: foreach my $item (@{$contacts}) {
3969: my $check;
3970: if (ref($checked) eq 'HASH') {
3971: $check = $checked->{$item};
3972: }
3973: my $title;
3974: if (ref($short_titles) eq 'HASH') {
3975: $title = $short_titles->{$item};
3976: }
3977: $output .= '<label>'.
3978: '<input type="checkbox" name="override_'.$type.'"'.$check.
3979: ' value="'.$item.'" />'.$title.'</label> ';
3980: }
3981: }
3982: $output .= '</span><br />'.&mt('Others').': '.
3983: '<input type="text" name="override_'.$type.'_others" '.
3984: 'value="'.$otheremails.'" />';
3985: my %locchecked;
3986: foreach my $loc ('s','b') {
3987: if ($includeloc eq $loc) {
3988: $locchecked{$loc} = ' checked="checked"';
3989: last;
3990: }
3991: }
3992: $output .= '<br />'.&mt('Bcc:').(' 'x6).
3993: '<input type="text" name="override_'.$type.'_bcc" '.
3994: 'value="'.$bccemails.'" /></fieldset>'.
3995: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3996: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 3997: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 3998: '<span class="LC_nobreak">'.&mt('Location:').' '.
3999: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4000: (' 'x2).
4001: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4002: '</span></fieldset>'.
4003: '</td></tr>'."\n";
4004: return $output;
4005: }
4006:
1.286 raeburn 4007: sub contacts_javascript {
4008: return <<"ENDSCRIPT";
4009:
4010: <script type="text/javascript">
4011: // <![CDATA[
4012:
4013: function screenshotSize(field) {
4014: if (document.getElementById('help_screenshotsize')) {
4015: if (field.value == 'no') {
1.289 raeburn 4016: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 4017: } else {
4018: document.getElementById('help_screenshotsize').style.display="";
4019: }
4020: }
4021: return;
4022: }
4023:
1.315 raeburn 4024: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4025: if (form.elements[checkbox].length != undefined) {
4026: var count = 0;
4027: if (docount) {
4028: for (var i=0; i<form.elements[checkbox].length; i++) {
4029: if (form.elements[checkbox][i].checked) {
4030: count ++;
4031: }
4032: }
4033: }
4034: for (var i=0; i<form.elements[checkbox].length; i++) {
4035: var type = form.elements[checkbox][i].value;
4036: if (document.getElementById(prefix+type)) {
4037: if (form.elements[checkbox][i].checked) {
4038: document.getElementById(prefix+type).style.display = 'table-row';
4039: if (count % 2 == 1) {
4040: document.getElementById(prefix+type).className = target+' LC_odd_row';
4041: } else {
4042: document.getElementById(prefix+type).className = target;
4043: }
4044: count ++;
4045: } else {
4046: document.getElementById(prefix+type).style.display = 'none';
4047: }
4048: }
4049: }
4050: }
4051: return;
4052: }
4053:
4054:
1.286 raeburn 4055: // ]]>
4056: </script>
4057:
4058: ENDSCRIPT
4059: }
4060:
1.118 jms 4061: sub print_helpsettings {
1.282 raeburn 4062: my ($position,$dom,$settings,$rowtotal) = @_;
4063: my $confname = $dom.'-domainconfig';
1.285 raeburn 4064: my $formname = 'display';
1.168 raeburn 4065: my ($datatable,$itemcount);
1.282 raeburn 4066: if ($position eq 'top') {
4067: $itemcount = 1;
4068: my (%choices,%defaultchecked,@toggles);
4069: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4070: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4071: &mt('LON-CAPA bug tracker'),600,500));
4072: %defaultchecked = ('submitbugs' => 'on');
4073: @toggles = ('submitbugs');
4074: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4075: \%choices,$itemcount);
4076: $$rowtotal ++;
4077: } else {
4078: my $css_class;
4079: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 4080: my (%customroles,%ordered,%current);
1.301 raeburn 4081: if (ref($settings) eq 'HASH') {
4082: if (ref($settings->{'adhoc'}) eq 'HASH') {
4083: %current = %{$settings->{'adhoc'}};
4084: }
1.285 raeburn 4085: }
4086: my $count = 0;
4087: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 4088: if ($key=~/^rolesdef\_(\w+)$/) {
4089: my $rolename = $1;
1.285 raeburn 4090: my (%privs,$order);
1.282 raeburn 4091: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4092: $customroles{$rolename} = \%privs;
1.285 raeburn 4093: if (ref($current{$rolename}) eq 'HASH') {
4094: $order = $current{$rolename}{'order'};
4095: }
4096: if ($order eq '') {
4097: $order = $count;
4098: }
4099: $ordered{$order} = $rolename;
4100: $count++;
4101: }
4102: }
4103: my $maxnum = scalar(keys(%ordered));
4104: my @roles_by_num = ();
4105: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4106: push(@roles_by_num,$item);
4107: }
4108: my $context = 'domprefs';
4109: my $crstype = 'Course';
4110: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 4111: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 4112: my ($numstatustypes,@jsarray);
4113: if (ref($types) eq 'ARRAY') {
4114: if (@{$types} > 0) {
4115: $numstatustypes = scalar(@{$types});
4116: push(@accesstypes,'status');
4117: @jsarray = ('bystatus');
1.282 raeburn 4118: }
4119: }
1.290 raeburn 4120: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 4121: if (keys(%domhelpdesk)) {
4122: push(@accesstypes,('inc','exc'));
4123: push(@jsarray,('notinc','notexc'));
4124: }
4125: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 4126: my $context = 'domprefs';
4127: my $crstype = 'Course';
1.285 raeburn 4128: my $prefix = 'helproles_';
4129: my $add_class = 'LC_hidden';
4130: foreach my $num (@roles_by_num) {
4131: my $role = $ordered{$num};
4132: my ($desc,$access,@statuses);
4133: if (ref($current{$role}) eq 'HASH') {
4134: $desc = $current{$role}{'desc'};
4135: $access = $current{$role}{'access'};
4136: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4137: @statuses = @{$current{$role}{'insttypes'}};
4138: }
4139: }
4140: if ($desc eq '') {
4141: $desc = $role;
4142: }
4143: my $identifier = 'custhelp'.$num;
1.282 raeburn 4144: my %full=();
4145: my %levels= (
4146: course => {},
4147: domain => {},
4148: system => {},
4149: );
4150: my %levelscurrent=(
4151: course => {},
4152: domain => {},
4153: system => {},
4154: );
4155: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4156: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4157: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 4158: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 4159: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 4160: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4161: for (my $k=0; $k<=$maxnum; $k++) {
4162: my $vpos = $k+1;
4163: my $selstr;
4164: if ($k == $num) {
4165: $selstr = ' selected="selected" ';
4166: }
4167: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4168: }
4169: $datatable .= '</select>'.(' 'x2).
4170: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4171: '</td>'.
4172: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4173: &mt('Name shown to users:').
4174: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4175: '</fieldset>'.
4176: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4177: $othertitle,$usertypes,$types,\%domhelpdesk).
4178: '<fieldset>'.
4179: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 4180: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 4181: \%levelscurrent,$identifier,
4182: 'LC_hidden',$prefix.$num.'_privs').
4183: '</fieldset></td>';
1.282 raeburn 4184: $itemcount ++;
4185: }
4186: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4187: my $newcust = 'custhelp'.$count;
4188: my (%privs,%levelscurrent);
4189: my %full=();
4190: my %levels= (
4191: course => {},
4192: domain => {},
4193: system => {},
4194: );
4195: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4196: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 4197: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 4198: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 4199: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4200: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4201: for (my $k=0; $k<$maxnum+1; $k++) {
4202: my $vpos = $k+1;
4203: my $selstr;
4204: if ($k == $maxnum) {
4205: $selstr = ' selected="selected" ';
4206: }
4207: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4208: }
4209: $datatable .= '</select> '."\n".
1.282 raeburn 4210: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4211: '</label></span></td>'.
1.285 raeburn 4212: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4213: '<span class="LC_nobreak">'.
4214: &mt('Internal name:').
4215: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4216: '</span>'.(' 'x4).
4217: '<span class="LC_nobreak">'.
4218: &mt('Name shown to users:').
4219: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4220: '</span></fieldset>'.
4221: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4222: $usertypes,$types,\%domhelpdesk).
4223: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 4224: &Apache::lonuserutils::custom_role_header($context,$crstype,
4225: \@templateroles,$newcust).
4226: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4227: \%levelscurrent,$newcust).
1.334 raeburn 4228: '</fieldset>'.
4229: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4230: '</td></tr>';
1.282 raeburn 4231: $count ++;
4232: $$rowtotal += $count;
4233: }
1.166 raeburn 4234: return $datatable;
1.121 raeburn 4235: }
4236:
1.285 raeburn 4237: sub adhocbutton {
4238: my ($prefix,$num,$field,$visibility) = @_;
4239: my %lt = &Apache::lonlocal::texthash(
4240: show => 'Show details',
4241: hide => 'Hide details',
4242: );
4243: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4244: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4245: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4246: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4247: }
4248:
4249: sub helpsettings_javascript {
4250: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4251: return unless(ref($roles_by_num) eq 'ARRAY');
4252: my %html_js_lt = &Apache::lonlocal::texthash(
4253: show => 'Show details',
4254: hide => 'Hide details',
4255: );
4256: &html_escape(\%html_js_lt);
4257: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4258: return <<"ENDSCRIPT";
4259: <script type="text/javascript">
4260: // <![CDATA[
4261:
4262: function reorderHelpRoles(form,item) {
4263: var changedVal;
4264: $jstext
4265: var newpos = 'helproles_${total}_pos';
4266: var maxh = 1 + $total;
4267: var current = new Array();
4268: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4269: if (item == newpos) {
4270: changedVal = newitemVal;
4271: } else {
4272: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4273: current[newitemVal] = newpos;
4274: }
4275: for (var i=0; i<helproles.length; i++) {
4276: var elementName = 'helproles_'+helproles[i]+'_pos';
4277: if (elementName != item) {
4278: if (form.elements[elementName]) {
4279: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4280: current[currVal] = elementName;
4281: }
4282: }
4283: }
4284: var oldVal;
4285: for (var j=0; j<maxh; j++) {
4286: if (current[j] == undefined) {
4287: oldVal = j;
4288: }
4289: }
4290: if (oldVal < changedVal) {
4291: for (var k=oldVal+1; k<=changedVal ; k++) {
4292: var elementName = current[k];
4293: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4294: }
4295: } else {
4296: for (var k=changedVal; k<oldVal; k++) {
4297: var elementName = current[k];
4298: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4299: }
4300: }
4301: return;
4302: }
4303:
4304: function helpdeskAccess(num) {
4305: var curraccess = null;
4306: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4307: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4308: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4309: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4310: }
4311: }
4312: }
4313: var shown = Array();
4314: var hidden = Array();
4315: if (curraccess == 'none') {
4316: hidden = Array('$hiddenstr');
4317: } else {
4318: if (curraccess == 'status') {
4319: shown = Array('bystatus');
4320: hidden = Array('notinc','notexc');
4321: } else {
4322: if (curraccess == 'exc') {
4323: shown = Array('notexc');
4324: hidden = Array('notinc','bystatus');
4325: }
4326: if (curraccess == 'inc') {
4327: shown = Array('notinc');
4328: hidden = Array('notexc','bystatus');
4329: }
1.293 raeburn 4330: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 4331: hidden = Array('notinc','notexc','bystatus');
4332: }
4333: }
4334: }
4335: if (hidden.length > 0) {
4336: for (var i=0; i<hidden.length; i++) {
4337: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4338: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4339: }
4340: }
4341: }
4342: if (shown.length > 0) {
4343: for (var i=0; i<shown.length; i++) {
4344: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4345: if (shown[i] == 'privs') {
4346: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4347: } else {
4348: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4349: }
4350: }
4351: }
4352: }
4353: return;
4354: }
4355:
4356: function toggleHelpdeskItem(num,field) {
4357: if (document.getElementById('helproles_'+num+'_'+field)) {
4358: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 4359: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 4360: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4361: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4362: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4363: }
4364: } else {
4365: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4366: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4367: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4368: }
4369: }
4370: }
4371: return;
4372: }
4373:
4374: // ]]>
4375: </script>
4376:
4377: ENDSCRIPT
4378: }
4379:
4380: sub helpdeskroles_access {
4381: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4382: $usertypes,$types,$domhelpdesk) = @_;
4383: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4384: my %lt = &Apache::lonlocal::texthash(
4385: 'rou' => 'Role usage',
4386: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 4387: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4388: 'dh' => 'All with domain helpdesk role',
4389: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 4390: 'none' => 'None',
4391: 'status' => 'Determined based on institutional status',
4392: 'inc' => 'Include all, but exclude specific personnel',
4393: 'exc' => 'Exclude all, but include specific personnel',
4394: );
4395: my %usecheck = (
4396: all => ' checked="checked"',
4397: );
4398: my %displaydiv = (
4399: status => 'none',
4400: inc => 'none',
4401: exc => 'none',
4402: priv => 'block',
4403: );
4404: my $output;
4405: if (ref($current) eq 'HASH') {
4406: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4407: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4408: $usecheck{$current->{access}} = $usecheck{'all'};
4409: delete($usecheck{'all'});
4410: if ($current->{access} =~ /^(status|inc|exc)$/) {
4411: my $access = $1;
4412: $displaydiv{$access} = 'inline';
4413: } elsif ($current->{access} eq 'none') {
4414: $displaydiv{'priv'} = 'none';
4415: }
4416: }
4417: }
4418: }
4419: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4420: '<p>'.$lt{'whi'}.'</p>';
4421: foreach my $access (@{$accesstypes}) {
4422: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4423: ' onclick="helpdeskAccess('."'$num'".');" />'.
4424: $lt{$access}.'</label>';
4425: if ($access eq 'status') {
4426: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4427: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4428: $othertitle,$usertypes,$types).
4429: '</div>';
4430: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4431: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4432: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4433: '</div>';
4434: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4435: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4436: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4437: '</div>';
4438: }
4439: $output .= '</p>';
4440: }
4441: $output .= '</fieldset>';
4442: return $output;
4443: }
4444:
1.121 raeburn 4445: sub radiobutton_prefs {
1.192 raeburn 4446: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 4447: $additional,$align) = @_;
1.121 raeburn 4448: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4449: (ref($choices) eq 'HASH'));
4450:
1.170 raeburn 4451: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 4452:
4453: foreach my $item (@{$toggles}) {
4454: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4455: $checkedon{$item} = ' checked="checked" ';
4456: $checkedoff{$item} = ' ';
1.121 raeburn 4457: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4458: $checkedoff{$item} = ' checked="checked" ';
4459: $checkedon{$item} = ' ';
4460: }
4461: }
4462: if (ref($settings) eq 'HASH') {
1.121 raeburn 4463: foreach my $item (@{$toggles}) {
1.118 jms 4464: if ($settings->{$item} eq '1') {
4465: $checkedon{$item} = ' checked="checked" ';
4466: $checkedoff{$item} = ' ';
4467: } elsif ($settings->{$item} eq '0') {
4468: $checkedoff{$item} = ' checked="checked" ';
4469: $checkedon{$item} = ' ';
4470: }
4471: }
1.121 raeburn 4472: }
1.192 raeburn 4473: if ($onclick) {
4474: $onclick = ' onclick="'.$onclick.'"';
4475: }
1.121 raeburn 4476: foreach my $item (@{$toggles}) {
1.118 jms 4477: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4478: $datatable .=
1.306 raeburn 4479: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 4480: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 4481: '</span></td>';
4482: if ($align eq 'left') {
4483: $datatable .= '<td class="LC_left_item">';
4484: } else {
4485: $datatable .= '<td class="LC_right_item">';
4486: }
1.289 raeburn 4487: $datatable .=
1.257 raeburn 4488: '<span class="LC_nobreak">'.
1.118 jms 4489: '<label><input type="radio" name="'.
1.192 raeburn 4490: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 4491: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 4492: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
4493: '</span>'.$additional.
4494: '</td>'.
1.118 jms 4495: '</tr>';
4496: $itemcount ++;
1.121 raeburn 4497: }
4498: return ($datatable,$itemcount);
4499: }
4500:
1.267 raeburn 4501: sub print_ltitools {
4502: my ($dom,$settings,$rowtotal) = @_;
4503: my $rownum = 0;
4504: my $css_class;
4505: my $itemcount = 1;
4506: my $maxnum = 0;
4507: my %ordered;
4508: if (ref($settings) eq 'HASH') {
4509: foreach my $item (keys(%{$settings})) {
4510: if (ref($settings->{$item}) eq 'HASH') {
4511: my $num = $settings->{$item}{'order'};
4512: $ordered{$num} = $item;
4513: }
4514: }
4515: }
4516: my $confname = $dom.'-domainconfig';
4517: my $switchserver = &check_switchserver($dom,$confname);
4518: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 4519: my $datatable;
1.267 raeburn 4520: my %lt = <itools_names();
4521: my @courseroles = ('cc','in','ta','ep','st');
4522: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.324 raeburn 4523: my @fields = ('fullname','firstname','lastname','email','roles','user');
1.267 raeburn 4524: if (keys(%ordered)) {
4525: my @items = sort { $a <=> $b } keys(%ordered);
4526: for (my $i=0; $i<@items; $i++) {
4527: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4528: my $item = $ordered{$items[$i]};
1.323 raeburn 4529: my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267 raeburn 4530: if (ref($settings->{$item}) eq 'HASH') {
4531: $title = $settings->{$item}->{'title'};
4532: $url = $settings->{$item}->{'url'};
4533: $key = $settings->{$item}->{'key'};
4534: $secret = $settings->{$item}->{'secret'};
1.322 raeburn 4535: $lifetime = $settings->{$item}->{'lifetime'};
1.267 raeburn 4536: my $image = $settings->{$item}->{'image'};
4537: if ($image ne '') {
4538: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
4539: }
1.323 raeburn 4540: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
4541: $sigsel{'HMAC-256'} = ' selected="selected"';
4542: } else {
4543: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
4544: }
1.267 raeburn 4545: }
1.319 raeburn 4546: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267 raeburn 4547: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4548: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
4549: for (my $k=0; $k<=$maxnum; $k++) {
4550: my $vpos = $k+1;
4551: my $selstr;
4552: if ($k == $i) {
4553: $selstr = ' selected="selected" ';
4554: }
4555: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4556: }
4557: $datatable .= '</select>'.(' 'x2).
4558: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4559: &mt('Delete?').'</label></span></td>'.
4560: '<td colspan="2">'.
4561: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4562: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267 raeburn 4563: (' 'x2).
4564: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4565: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4566: (' 'x2).
4567: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4568: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4569: (' 'x2).
4570: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
4571: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
4572: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267 raeburn 4573: '<br /><br />'.
1.323 raeburn 4574: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267 raeburn 4575: ' value="'.$url.'" /></span>'.
4576: (' 'x2).
1.319 raeburn 4577: '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267 raeburn 4578: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4579: (' 'x2).
1.322 raeburn 4580: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
4581: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
4582: (' 'x2).
1.267 raeburn 4583: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4584: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4585: '<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>'.
4586: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4587: '</fieldset>'.
4588: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4589: '<span class="LC_nobreak">'.&mt('Display target:');
4590: my %currdisp;
4591: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4592: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4593: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 4594: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4595: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 4596: } else {
4597: $currdisp{'iframe'} = ' checked="checked"';
4598: }
4599: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4600: $currdisp{'width'} = $1;
4601: }
4602: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4603: $currdisp{'height'} = $1;
4604: }
1.296 raeburn 4605: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4606: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 4607: } else {
4608: $currdisp{'iframe'} = ' checked="checked"';
4609: }
1.298 raeburn 4610: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4611: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4612: $lt{$disp}.'</label>'.(' 'x2);
4613: }
4614: $datatable .= (' 'x4);
4615: foreach my $dimen ('width','height') {
4616: $datatable .= '<label>'.$lt{$dimen}.' '.
4617: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4618: (' 'x2);
4619: }
1.334 raeburn 4620: $datatable .= '</span><br />'.
1.296 raeburn 4621: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 4622: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
1.296 raeburn 4623: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4624: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
4625: '</textarea></div><div style=""></div><br />';
1.319 raeburn 4626: my %units = (
4627: 'passback' => 'days',
4628: 'roster' => 'seconds',
4629: );
1.267 raeburn 4630: foreach my $extra ('passback','roster') {
1.319 raeburn 4631: my $validsty = 'none';
4632: my $currvalid;
1.267 raeburn 4633: my $checkedon = '';
4634: my $checkedoff = ' checked="checked"';
4635: if ($settings->{$item}->{$extra}) {
4636: $checkedon = $checkedoff;
4637: $checkedoff = '';
1.319 raeburn 4638: $validsty = 'inline-block';
4639: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
4640: $currvalid = $settings->{$item}->{$extra.'valid'};
4641: }
4642: }
4643: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
4644: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4645: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
4646: &mt('No').'</label>'.(' 'x2).
4647: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
4648: &mt('Yes').'</label></span></div>'.
4649: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
4650: '<span class="LC_nobreak">'.
4651: &mt("at least [_1] $units{$extra} after launch",
4652: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
4653: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4654: }
1.319 raeburn 4655: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
1.267 raeburn 4656: if ($imgsrc) {
4657: $datatable .= $imgsrc.
4658: '<label><input type="checkbox" name="ltitools_image_del"'.
4659: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
4660: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
4661: } else {
4662: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4663: }
4664: if ($switchserver) {
4665: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4666: } else {
4667: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
4668: }
4669: $datatable .= '</span></fieldset>';
1.324 raeburn 4670: my (%checkedfields,%rolemaps,$userincdom);
1.267 raeburn 4671: if (ref($settings->{$item}) eq 'HASH') {
4672: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
4673: %checkedfields = %{$settings->{$item}->{'fields'}};
4674: }
1.324 raeburn 4675: $userincdom = $settings->{$item}->{'incdom'};
1.267 raeburn 4676: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
4677: %rolemaps = %{$settings->{$item}->{'roles'}};
4678: $checkedfields{'roles'} = 1;
4679: }
4680: }
4681: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4682: '<span class="LC_nobreak">';
1.324 raeburn 4683: my $userfieldstyle = 'display:none;';
4684: my $seluserdom = '';
4685: my $unseluserdom = ' selected="selected"';
1.267 raeburn 4686: foreach my $field (@fields) {
1.324 raeburn 4687: my ($checked,$onclick,$id,$spacer);
1.267 raeburn 4688: if ($checkedfields{$field}) {
4689: $checked = ' checked="checked"';
4690: }
1.324 raeburn 4691: if ($field eq 'user') {
4692: $id = ' id="ltitools_user_field_'.$i.'"';
4693: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
4694: if ($checked) {
4695: $userfieldstyle = 'display:inline-block';
4696: if ($userincdom) {
4697: $seluserdom = $unseluserdom;
4698: $unseluserdom = '';
4699: }
4700: }
4701: } else {
4702: $spacer = (' ' x2);
4703: }
1.267 raeburn 4704: $datatable .= '<label>'.
1.324 raeburn 4705: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
4706: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4707: }
1.324 raeburn 4708: $datatable .= '</span>';
4709: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
4710: '<span class="LC_nobreak"> : '.
4711: '<select name="ltitools_userincdom_'.$i.'">'.
4712: '<option value="">'.&mt('Select').'</option>'.
4713: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
4714: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
4715: '</select></span></div>';
4716: $datatable .= '</fieldset>'.
1.267 raeburn 4717: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4718: foreach my $role (@courseroles) {
4719: my ($selected,$selectnone);
4720: if (!$rolemaps{$role}) {
4721: $selectnone = ' selected="selected"';
4722: }
1.306 raeburn 4723: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4724: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4725: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
4726: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4727: foreach my $ltirole (@ltiroles) {
4728: unless ($selectnone) {
4729: if ($rolemaps{$role} eq $ltirole) {
4730: $selected = ' selected="selected"';
4731: } else {
4732: $selected = '';
4733: }
4734: }
4735: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
4736: }
4737: $datatable .= '</select></td>';
4738: }
1.273 raeburn 4739: $datatable .= '</tr></table></fieldset>';
4740: my %courseconfig;
4741: if (ref($settings->{$item}) eq 'HASH') {
4742: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
4743: %courseconfig = %{$settings->{$item}->{'crsconf'}};
4744: }
4745: }
4746: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4747: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 4748: my $checked;
4749: if ($courseconfig{$item}) {
4750: $checked = ' checked="checked"';
4751: }
4752: $datatable .= '<label>'.
4753: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
1.372 raeburn 4754: $lt{'crs'.$item}.'</label> '."\n";
1.273 raeburn 4755: }
4756: $datatable .= '</span></fieldset>'.
1.267 raeburn 4757: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4758: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
4759: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
4760: my %custom = %{$settings->{$item}->{'custom'}};
4761: if (keys(%custom) > 0) {
4762: foreach my $key (sort(keys(%custom))) {
4763: $datatable .= '<tr><td><span class="LC_nobreak">'.
4764: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
4765: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
4766: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
4767: ' value="'.$custom{$key}.'" /></td></tr>';
4768: }
4769: }
4770: }
4771: $datatable .= '<tr><td><span class="LC_nobreak">'.
4772: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
4773: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
4774: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
4775: $datatable .= '</table></fieldset></td></tr>'."\n";
4776: $itemcount ++;
4777: }
4778: }
4779: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319 raeburn 4780: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267 raeburn 4781: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4782: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
4783: '<select name="ltitools_add_pos"'.$chgstr.'>';
4784: for (my $k=0; $k<$maxnum+1; $k++) {
4785: my $vpos = $k+1;
4786: my $selstr;
4787: if ($k == $maxnum) {
4788: $selstr = ' selected="selected" ';
4789: }
4790: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4791: }
4792: $datatable .= '</select> '."\n".
1.334 raeburn 4793: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.267 raeburn 4794: '<td colspan="2">'.
4795: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4796: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267 raeburn 4797: (' 'x2).
4798: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
4799: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4800: (' 'x2).
4801: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
4802: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4803: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
4804: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
4805: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267 raeburn 4806: '<br />'.
1.323 raeburn 4807: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267 raeburn 4808: (' 'x2).
4809: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
4810: (' 'x2).
1.322 raeburn 4811: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
4812: (' 'x2).
1.267 raeburn 4813: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
4814: '<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".
4815: '</fieldset>'.
4816: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4817: '<span class="LC_nobreak">'.&mt('Display target:');
4818: my %defaultdisp;
4819: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 4820: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4821: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
4822: $lt{$disp}.'</label>'.(' 'x2);
4823: }
4824: $datatable .= (' 'x4);
4825: foreach my $dimen ('width','height') {
4826: $datatable .= '<label>'.$lt{$dimen}.' '.
4827: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
4828: (' 'x2);
4829: }
1.334 raeburn 4830: $datatable .= '</span><br />'.
1.296 raeburn 4831: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 4832: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
1.296 raeburn 4833: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
1.334 raeburn 4834: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
1.296 raeburn 4835: '</div><div style=""></div><br />';
1.319 raeburn 4836: my %units = (
4837: 'passback' => 'days',
4838: 'roster' => 'seconds',
4839: );
4840: my %defaulttimes = (
4841: 'passback' => '7',
1.322 raeburn 4842: 'roster' => '300',
1.319 raeburn 4843: );
1.267 raeburn 4844: foreach my $extra ('passback','roster') {
1.319 raeburn 4845: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
4846: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4847: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
4848: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
4849: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
4850: &mt('Yes').'</label></span></div>'.
4851: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
4852: '<span class="LC_nobreak">'.
4853: &mt("at least [_1] $units{$extra} after launch",
4854: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
4855: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4856: }
1.319 raeburn 4857: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
1.267 raeburn 4858: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4859: if ($switchserver) {
4860: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4861: } else {
4862: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
4863: }
4864: $datatable .= '</span></fieldset>'.
4865: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4866: '<span class="LC_nobreak">';
4867: foreach my $field (@fields) {
1.324 raeburn 4868: my ($id,$onclick,$spacer);
4869: if ($field eq 'user') {
4870: $id = ' id="ltitools_user_field_add"';
4871: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
4872: } else {
4873: $spacer = (' ' x2);
4874: }
1.267 raeburn 4875: $datatable .= '<label>'.
1.324 raeburn 4876: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
4877: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4878: }
1.324 raeburn 4879: $datatable .= '</span>'.
4880: '<div style="display:none;" id="ltitools_user_div_add">'.
4881: '<span class="LC_nobreak"> : '.
4882: '<select name="ltitools_userincdom_add">'.
4883: '<option value="" selected="selected">'.&mt('Select').'</option>'.
4884: '<option value="0">'.&mt('username').'</option>'.
4885: '<option value="1">'.&mt('username:domain').'</option>'.
4886: '</select></span></div></fieldset>';
4887: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1.267 raeburn 4888: foreach my $role (@courseroles) {
4889: my ($checked,$checkednone);
1.306 raeburn 4890: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4891: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4892: '<select name="ltitools_add_roles_'.$role.'">'.
4893: '<option value="" selected="selected">'.&mt('Select').'</option>';
4894: foreach my $ltirole (@ltiroles) {
4895: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
4896: }
4897: $datatable .= '</select></td>';
4898: }
4899: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 4900: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4901: foreach my $item ('label','title','target','linktext','explanation','append') {
1.296 raeburn 4902: $datatable .= '<label>'.
4903: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4904: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 4905: }
4906: $datatable .= '</span></fieldset>'.
1.267 raeburn 4907: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4908: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4909: '<tr><td><span class="LC_nobreak">'.
4910: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4911: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4912: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
1.334 raeburn 4913: '</table></fieldset>'."\n".
1.267 raeburn 4914: '</td>'."\n".
4915: '</tr>'."\n";
4916: $itemcount ++;
4917: return $datatable;
4918: }
4919:
4920: sub ltitools_names {
4921: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 4922: 'title' => 'Title',
4923: 'version' => 'Version',
4924: 'msgtype' => 'Message Type',
1.323 raeburn 4925: 'sigmethod' => 'Signature Method',
1.296 raeburn 4926: 'url' => 'URL',
4927: 'key' => 'Key',
1.322 raeburn 4928: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 4929: 'secret' => 'Secret',
4930: 'icon' => 'Icon',
1.324 raeburn 4931: 'user' => 'User',
1.296 raeburn 4932: 'fullname' => 'Full Name',
4933: 'firstname' => 'First Name',
4934: 'lastname' => 'Last Name',
4935: 'email' => 'E-mail',
4936: 'roles' => 'Role',
1.298 raeburn 4937: 'window' => 'Window',
4938: 'tab' => 'Tab',
1.296 raeburn 4939: 'iframe' => 'iFrame',
4940: 'height' => 'Height',
4941: 'width' => 'Width',
4942: 'linktext' => 'Default Link Text',
4943: 'explanation' => 'Default Explanation',
4944: 'passback' => 'Tool can return grades:',
4945: 'roster' => 'Tool can retrieve roster:',
4946: 'crstarget' => 'Display target',
4947: 'crslabel' => 'Course label',
4948: 'crstitle' => 'Course title',
4949: 'crslinktext' => 'Link Text',
4950: 'crsexplanation' => 'Explanation',
1.318 raeburn 4951: 'crsappend' => 'Provider URL',
1.267 raeburn 4952: );
4953: return %lt;
4954: }
4955:
1.372 raeburn 4956: sub print_proctoring {
4957: my ($dom,$settings,$rowtotal) = @_;
4958: my $itemcount = 1;
4959: my (%ordered,%providernames,%current,%currentdef);
4960: my $confname = $dom.'-domainconfig';
4961: my $switchserver = &check_switchserver($dom,$confname);
4962: if (ref($settings) eq 'HASH') {
4963: foreach my $item (keys(%{$settings})) {
4964: if (ref($settings->{$item}) eq 'HASH') {
4965: my $num = $settings->{$item}{'order'};
4966: $ordered{$num} = $item;
4967: }
4968: }
4969: } else {
4970: %ordered = (
4971: 1 => 'proctorio',
4972: 2 => 'examity',
4973: );
4974: }
4975: %providernames = &proctoring_providernames();
4976: my $maxnum = scalar(keys(%ordered));
4977: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
4978: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
4979: if (ref($requref) eq 'HASH') {
4980: %requserfields = %{$requref};
4981: }
4982: if (ref($opturef) eq 'HASH') {
4983: %optuserfields = %{$opturef};
4984: }
4985: if (ref($defref) eq 'HASH') {
4986: %defaults = %{$defref};
4987: }
4988: if (ref($extref) eq 'HASH') {
4989: %extended = %{$extref};
4990: }
4991: if (ref($crsref) eq 'HASH') {
4992: %crsconf = %{$crsref};
4993: }
4994: if (ref($rolesref) eq 'ARRAY') {
4995: @courseroles = @{$rolesref};
4996: }
4997: if (ref($ltiref) eq 'ARRAY') {
4998: @ltiroles = @{$ltiref};
4999: }
5000: my $datatable;
5001: my $css_class;
5002: if (keys(%ordered)) {
5003: my @items = sort { $a <=> $b } keys(%ordered);
5004: for (my $i=0; $i<@items; $i++) {
5005: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5006: my $provider = $ordered{$items[$i]};
5007: my $optionsty = 'none';
5008: my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
5009: %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
5010: if (ref($settings) eq 'HASH') {
5011: if (ref($settings->{$provider}) eq 'HASH') {
5012: %current = %{$settings->{$provider}};
5013: if ($current{'available'}) {
5014: $optionsty = 'block';
5015: $available = 1;
5016: }
5017: if ($current{'lifetime'} =~ /^\d+$/) {
5018: $lifetime = $current{'lifetime'};
5019: }
5020: if ($current{'version'} =~ /^\d+\.\d+$/) {
5021: $version = $current{'version'};
5022: }
5023: if ($current{'image'} ne '') {
5024: $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
5025: }
5026: if (ref($current{'fields'}) eq 'ARRAY') {
5027: map { $checkedfields{$_} = 1; } @{$current{'fields'}};
5028: }
5029: $userincdom = $current{'incdom'};
5030: if (ref($current{'roles'}) eq 'HASH') {
5031: %rolemaps = %{$current{'roles'}};
5032: $checkedfields{'roles'} = 1;
5033: }
5034: if (ref($current{'defaults'}) eq 'ARRAY') {
5035: foreach my $val (@{$current{'defaults'}}) {
5036: if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
5037: $inuse{$val} = 1;
5038: } else {
5039: foreach my $poss (keys(%{$extended{$provider}})) {
5040: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5041: if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
5042: $inuse{$poss} = $val;
5043: last;
5044: }
5045: }
5046: }
5047: }
5048: }
5049: } elsif (ref($current{'defaults'}) eq 'HASH') {
5050: foreach my $key (keys(%{$current{'defaults'}})) {
5051: my $currval = $current{'defaults'}{$key};
5052: if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
5053: $inuse{$key} = 1;
5054: } else {
5055: my $match;
5056: foreach my $poss (keys(%{$extended{$provider}})) {
5057: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5058: if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
5059: $inuse{$poss} = $key;
5060: last;
5061: }
5062: } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
5063: foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
5064: if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
5065: if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
5066: $currentdef{$inner} = $currval;
5067: $match = 1;
5068: last;
5069: }
5070: } elsif ($inner eq $key) {
5071: $currentdef{$key} = $currval;
5072: $match = 1;
5073: last;
5074: }
5075: }
5076: }
5077: last if ($match);
5078: }
5079: }
5080: }
5081: }
5082: if (ref($current{'crsconf'}) eq 'ARRAY') {
5083: map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
5084: }
5085: }
5086: }
5087: my %lt = &proctoring_titles($provider);
5088: my %fieldtitles = &proctoring_fieldtitles($provider);
5089: my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
5090: my %checkedavailable = (
5091: yes => '',
5092: no => ' checked="checked"',
5093: );
5094: if ($available) {
5095: $checkedavailable{'yes'} = $checkedavailable{'no'};
5096: $checkedavailable{'no'} = '';
5097: }
5098: my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
5099: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5100: .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
5101: for (my $k=0; $k<$maxnum; $k++) {
5102: my $vpos = $k+1;
5103: my $selstr;
5104: if ($k == $i) {
5105: $selstr = ' selected="selected" ';
5106: }
5107: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5108: }
5109: if ($version eq '') {
5110: if ($provider eq 'proctorio') {
5111: $version = '1.0';
5112: } elsif ($provider eq 'examity') {
5113: $version = '1.1';
5114: }
5115: }
5116: if ($lifetime eq '') {
5117: $lifetime = '300';
5118: }
5119: $datatable .=
5120: '</select>'.(' 'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
5121: '<span class="LC_nobreak">'.$lt{'avai'}.' '.
5122: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label> '."\n".
5123: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
5124: '</td>'.
5125: '<td colspan="2">'.
5126: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
5127: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
5128: '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
5129: (' 'x2).
5130: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
5131: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5132: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5133: (' 'x2).
5134: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
5135: '<br />'.
5136: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
5137: '<br />'.
5138: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
5139: (' 'x2).
5140: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
5141: '<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";
5142: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
5143: if ($imgsrc) {
5144: $datatable .= $imgsrc.
5145: '<label><input type="checkbox" name="proctoring_image_del"'.
5146: ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
5147: '<span class="LC_nobreak"> '.&mt('Replace:');
5148: }
5149: $datatable .= ' ';
5150: if ($switchserver) {
5151: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5152: } else {
5153: $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
5154: }
5155: unless ($imgsrc) {
5156: $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
5157: }
5158: $datatable .= '</fieldset>'."\n";
5159: if (ref($requserfields{$provider}) eq 'ARRAY') {
5160: if (@{$requserfields{$provider}} > 0) {
5161: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
5162: foreach my $field (@{$requserfields{$provider}}) {
5163: $datatable .= '<span class="LC_nobreak">'.
5164: '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
5165: $lt{$field}.'</label>';
5166: if ($field eq 'user') {
5167: my $seluserdom = '';
5168: my $unseluserdom = ' selected="selected"';
5169: if ($userincdom) {
5170: $seluserdom = $unseluserdom;
5171: $unseluserdom = '';
5172: }
5173: $datatable .= ': '.
5174: '<select name="proctoring_userincdom_'.$provider.'">'.
5175: '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
5176: '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
5177: '</select> ';
5178: } else {
5179: $datatable .= ' ';
5180: if ($field eq 'roles') {
5181: $showroles = 1;
5182: }
5183: }
5184: $datatable .= '</span> ';
5185: }
5186: }
5187: $datatable .= '</fieldset>'."\n";
5188: }
5189: if (ref($optuserfields{$provider}) eq 'ARRAY') {
5190: if (@{$optuserfields{$provider}} > 0) {
5191: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>';
5192: foreach my $field (@{$optuserfields{$provider}}) {
5193: my $checked;
5194: if ($checkedfields{$field}) {
5195: $checked = ' checked="checked"';
5196: }
5197: $datatable .= '<span class="LC_nobreak">'.
5198: '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span> ';
5199: }
5200: $datatable .= '</fieldset>'."\n";
5201: }
5202: }
5203: if (ref($defaults{$provider}) eq 'ARRAY') {
5204: if (@{$defaults{$provider}}) {
5205: my (%options,@selectboxes);
5206: if (ref($extended{$provider}) eq 'HASH') {
5207: %options = %{$extended{$provider}};
5208: }
5209: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
5210: my ($rem,$numinrow,$dropdowns);
5211: if ($provider eq 'proctorio') {
5212: $datatable .= '<table>';
5213: $numinrow = 4;
5214: }
5215: my $i = 0;
5216: foreach my $field (@{$defaults{$provider}}) {
5217: my $checked;
5218: if ($inuse{$field}) {
5219: $checked = ' checked="checked"';
5220: }
5221: if ($provider eq 'examity') {
5222: if ($field eq 'display') {
5223: $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
5224: foreach my $option ('iframe','tab','window') {
5225: my $checkdisp;
5226: if ($currentdef{'target'} eq $option) {
5227: $checkdisp = ' checked="checked"';
5228: }
5229: $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
5230: $fieldtitles{$option}.'</label>'.(' 'x2);
5231: }
5232: $datatable .= (' 'x4);
5233: foreach my $dimen ('width','height') {
5234: $datatable .= '<label>'.$fieldtitles{$dimen}.' '.
5235: '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
5236: 'value="'.$currentdef{$dimen}.'" /></label>'.
5237: (' 'x2);
5238: }
5239: $datatable .= '</span><br />'.
5240: '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
5241: '<input type="text" name="proctoring_linktext_'.$provider.'" '.
5242: 'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
5243: '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
5244: '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
5245: $currentdef{'explanation'}.
5246: '</textarea></div><div style=""></div><br />';
5247: }
5248: } else {
5249: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
5250: my ($output,$selnone);
5251: unless ($checked) {
5252: $selnone = ' selected="selected"';
5253: }
5254: $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
5255: '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
5256: '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>';
5257: foreach my $option (@{$options{$field}}) {
5258: my $sel;
5259: if ($inuse{$field} eq $option) {
5260: $sel = ' selected="selected"';
5261: }
5262: $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
5263: }
5264: $output .= '</select></span>';
5265: push(@selectboxes,$output);
5266: } else {
5267: $rem = $i%($numinrow);
5268: if ($rem == 0) {
5269: if ($i > 0) {
5270: $datatable .= '</tr>';
5271: }
5272: $datatable .= '<tr>';
5273: }
5274: $datatable .= '<td class="LC_left_item">'.
5275: '<span class="LC_nobreak">'.
5276: '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
5277: $fieldtitles{$field}.'</label></span></td>';
5278: $i++;
5279: }
5280: }
5281: }
5282: if ($provider eq 'proctorio') {
5283: if ($numinrow) {
5284: $rem = $i%$numinrow;
5285: }
5286: my $colsleft = $numinrow - $rem;
5287: if ($colsleft > 1) {
5288: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5289: } else {
5290: $datatable .= '<td class="LC_left_item">';
5291: }
5292: $datatable .= ' '.
5293: '</td></tr></table>';
5294: if (@selectboxes) {
5295: $datatable .= '<hr /><table>';
5296: $numinrow = 2;
5297: for (my $i=0; $i<@selectboxes; $i++) {
5298: $rem = $i%($numinrow);
5299: if ($rem == 0) {
5300: if ($i > 0) {
5301: $datatable .= '</tr>';
5302: }
5303: $datatable .= '<tr>';
5304: }
5305: $datatable .= '<td class="LC_left_item">'.
5306: $selectboxes[$i].'</td>';
5307: }
5308: if ($numinrow) {
5309: $rem = $i%$numinrow;
5310: }
5311: $colsleft = $numinrow - $rem;
5312: if ($colsleft > 1) {
5313: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5314: } else {
5315: $datatable .= '<td class="LC_left_item">';
5316: }
5317: $datatable .= ' '.
5318: '</td></tr></table>';
5319: }
5320: }
5321: $datatable .= '</fieldset>';
5322: }
5323: if (ref($crsconf{$provider}) eq 'ARRAY') {
5324: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5325: '<legend>'.&mt('Configurable in course').'</legend>';
5326: my ($rem,$numinrow);
5327: if ($provider eq 'proctorio') {
5328: $datatable .= '<table>';
5329: $numinrow = 4;
5330: }
5331: my $i = 0;
5332: foreach my $item (@{$crsconf{$provider}}) {
5333: my $name;
5334: if ($provider eq 'examity') {
5335: $name = $lt{'crs'.$item};
5336: } elsif ($provider eq 'proctorio') {
5337: $name = $fieldtitles{$item};
5338: $rem = $i%($numinrow);
5339: if ($rem == 0) {
5340: if ($i > 0) {
5341: $datatable .= '</tr>';
5342: }
5343: $datatable .= '<tr>';
5344: }
5345: $datatable .= '<td class="LC_left_item>';
5346: }
5347: my $checked;
5348: if ($crsconfig{$item}) {
5349: $checked = ' checked="checked"';
5350: }
5351: $datatable .= '<span class="LC_nobreak"><label>'.
5352: '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
5353: $name.'</label></span>';
5354: if ($provider eq 'examity') {
5355: $datatable .= ' ';
5356: }
5357: $datatable .= "\n";
5358: $i++;
5359: }
5360: if ($provider eq 'proctorio') {
5361: if ($numinrow) {
5362: $rem = $i%$numinrow;
5363: }
5364: my $colsleft = $numinrow - $rem;
5365: if ($colsleft > 1) {
5366: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5367: } else {
5368: $datatable .= '<td class="LC_left_item">';
5369: }
5370: $datatable .= ' '.
5371: '</td></tr></table>';
5372: }
5373: $datatable .= '</fieldset>';
5374: }
5375: if ($showroles) {
5376: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5377: '<legend>'.&mt('Role mapping').'</legend><table><tr>';
5378: foreach my $role (@courseroles) {
5379: my ($selected,$selectnone);
5380: if (!$rolemaps{$role}) {
5381: $selectnone = ' selected="selected"';
5382: }
5383: $datatable .= '<td style="text-align: center">'.
5384: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5385: '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
5386: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5387: foreach my $ltirole (@ltiroles) {
5388: unless ($selectnone) {
5389: if ($rolemaps{$role} eq $ltirole) {
5390: $selected = ' selected="selected"';
5391: } else {
5392: $selected = '';
5393: }
5394: }
5395: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5396: }
5397: $datatable .= '</select></td>';
5398: }
5399: $datatable .= '</tr></table></fieldset>'.
5400: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5401: '<legend>'.&mt('Custom items sent on launch').'</legend>'.
5402: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5403: '<tr><td></td><td>lms</td>'.
5404: '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
5405: ' value="Loncapa" disabled="disabled"/></td></tr>';
5406: if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
5407: (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
5408: my %custom = %{$settings->{$provider}->{'custom'}};
5409: if (keys(%custom) > 0) {
5410: foreach my $key (sort(keys(%custom))) {
5411: next if ($key eq 'lms');
5412: $datatable .= '<tr><td><span class="LC_nobreak">'.
5413: '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
5414: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
5415: '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
5416: ' value="'.$custom{$key}.'" /></td></tr>';
5417: }
5418: }
5419: }
5420: $datatable .= '<tr><td><span class="LC_nobreak">'.
5421: '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
5422: &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
5423: '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
5424: '</table></fieldset></td></tr>'."\n";
5425: }
5426: $datatable .= '</td></tr>';
5427: }
5428: $itemcount ++;
5429: }
5430: }
5431: return $datatable;
5432: }
5433:
5434: sub proctoring_data {
5435: my $requserfields = {
5436: proctorio => ['user'],
5437: examity => ['roles','user'],
5438: };
5439: my $optuserfields = {
5440: proctorio => ['fullname'],
5441: examity => ['fullname','firstname','lastname','email'],
5442: };
5443: my $defaults = {
5444: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
5445: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
5446: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
5447: 'closetabs','onescreen','print','downloads','cache','rightclick',
5448: 'reentry','calculator','whiteboard'],
5449: examity => ['display'],
5450: };
5451: my $extended = {
5452: proctorio => {
5453: verifyid => ['verifyidauto','verifyidlive'],
5454: fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
5455: tabslinks => ['notabs','linksonly'],
5456: reentry => ['noreentry','agentreentry'],
5457: calculator => ['calculatorbasic','calculatorsci'],
5458: },
5459: examity => {
5460: display => {
5461: target => ['iframe','tab','window'],
5462: width => '',
5463: height => '',
5464: linktext => '',
5465: explanation => '',
5466: },
5467: },
5468: };
5469: my $crsconf = {
5470: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
5471: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
5472: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
5473: 'closetabs','onescreen','print','downloads','cache','rightclick',
5474: 'reentry','calculator','whiteboard'],
5475: examity => ['label','title','target','linktext','explanation','append'],
5476: };
5477: my $courseroles = ['cc','in','ta','ep','st'];
5478: my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
5479: return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
5480: }
5481:
5482: sub proctoring_titles {
5483: my ($item) = @_;
5484: my (%common_lt,%custom_lt);
5485: %common_lt = &Apache::lonlocal::texthash (
5486: 'avai' => 'Available?',
5487: 'base' => 'Basic Settings',
5488: 'requ' => 'User data required to be sent on launch',
5489: 'optu' => 'User data optionally sent on launch',
5490: 'udsl' => 'User data sent on launch',
5491: 'defa' => 'Defaults for items configurable in course',
5492: 'sigmethod' => 'Signature Method',
5493: 'key' => 'Key',
5494: 'lifetime' => 'Nonce lifetime (s)',
5495: 'secret' => 'Secret',
5496: 'icon' => 'Icon',
5497: 'fullname' => 'Full Name',
5498: 'visible' => 'Visible input',
5499: 'username' => 'username',
5500: 'user' => 'User',
5501: );
5502: if ($item eq 'proctorio') {
5503: %custom_lt = &Apache::lonlocal::texthash (
5504: 'version' => 'OAuth version',
5505: 'url' => 'API URL',
5506: 'uname:dom' => 'username-domain',
5507: );
5508: } elsif ($item eq 'examity') {
5509: %custom_lt = &Apache::lonlocal::texthash (
5510: 'version' => 'LTI Version',
5511: 'url' => 'URL',
5512: 'uname:dom' => 'username:domain',
5513: 'msgtype' => 'Message Type',
5514: 'firstname' => 'First Name',
5515: 'lastname' => 'Last Name',
5516: 'email' => 'E-mail',
5517: 'roles' => 'Role',
5518: 'crstarget' => 'Display target',
5519: 'crslabel' => 'Course label',
5520: 'crstitle' => 'Course title',
5521: 'crslinktext' => 'Link Text',
5522: 'crsexplanation' => 'Explanation',
5523: 'crsappend' => 'Provider URL',
5524: );
5525: }
5526: my %lt = (%common_lt,%custom_lt);
5527: return %lt;
5528: }
5529:
5530: sub proctoring_fieldtitles {
5531: my ($item) = @_;
5532: if ($item eq 'proctorio') {
5533: return &Apache::lonlocal::texthash (
5534: 'recordvideo' => 'Record video',
5535: 'recordaudio' => 'Record audio',
5536: 'recordscreen' => 'Record screen',
5537: 'recordwebtraffic' => 'Record web traffic',
5538: 'recordroomstart' => 'Record room scan',
5539: 'verifyvideo' => 'Verify webcam',
5540: 'verifyaudio' => 'Verify microphone',
5541: 'verifydesktop' => 'Verify desktop recording',
5542: 'verifyid' => 'Photo ID verification',
5543: 'verifysignature' => 'Require signature',
5544: 'fullscreen' => 'Fullscreen',
5545: 'clipboard' => 'Disable copy/paste',
5546: 'tabslinks' => 'New tabs/windows',
5547: 'closetabs' => 'Close other tabs',
5548: 'onescreen' => 'Limit to single screen',
5549: 'print' => 'Disable Printing',
5550: 'downloads' => 'Disable Downloads',
5551: 'cache' => 'Empty cache after exam',
5552: 'rightclick' => 'Disable right click',
5553: 'reentry' => 'Re-entry to exam',
5554: 'calculator' => 'Onscreen calculator',
5555: 'whiteboard' => 'Onscreen whiteboard',
5556: 'verifyidauto' => 'Automated verification',
5557: 'verifyidlive' => 'Live agent verification',
5558: 'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
5559: 'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
5560: 'fullscreensever' => 'Forced, navigation away ends exam',
5561: 'notabs' => 'Disaallowed',
5562: 'linksonly' => 'Allowed from links in exam',
5563: 'noreentry' => 'Disallowed',
5564: 'agentreentry' => 'Agent required for re-entry',
5565: 'calculatorbasic' => 'Basic',
5566: 'calculatorsci' => 'Scientific',
5567: );
5568: } elsif ($item eq 'examity') {
5569: return &Apache::lonlocal::texthash (
5570: 'target' => 'Display target',
5571: 'window' => 'Window',
5572: 'tab' => 'Tab',
5573: 'iframe' => 'iFrame',
5574: 'height' => 'Height (pixels)',
5575: 'width' => 'Width (pixels)',
5576: 'linktext' => 'Default Link Text',
5577: 'explanation' => 'Default Explanation',
5578: 'append' => 'Provider URL',
5579: );
5580: }
5581: }
5582:
5583: sub proctoring_providernames {
5584: return (
5585: proctorio => 'Proctorio',
5586: examity => 'Examity',
5587: );
5588: }
5589:
1.320 raeburn 5590: sub print_lti {
5591: my ($dom,$settings,$rowtotal) = @_;
5592: my $itemcount = 1;
5593: my $maxnum = 0;
5594: my $css_class;
5595: my %ordered;
5596: if (ref($settings) eq 'HASH') {
5597: foreach my $item (keys(%{$settings})) {
5598: if (ref($settings->{$item}) eq 'HASH') {
5599: my $num = $settings->{$item}{'order'};
5600: $ordered{$num} = $item;
5601: }
5602: }
5603: }
5604: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 5605: my $datatable;
1.320 raeburn 5606: my %lt = <i_names();
5607: if (keys(%ordered)) {
5608: my @items = sort { $a <=> $b } keys(%ordered);
5609: for (my $i=0; $i<@items; $i++) {
5610: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5611: my $item = $ordered{$items[$i]};
1.345 raeburn 5612: my ($key,$secret,$lifetime,$consumer,$requser,$current);
1.320 raeburn 5613: if (ref($settings->{$item}) eq 'HASH') {
5614: $key = $settings->{$item}->{'key'};
5615: $secret = $settings->{$item}->{'secret'};
5616: $lifetime = $settings->{$item}->{'lifetime'};
5617: $consumer = $settings->{$item}->{'consumer'};
1.345 raeburn 5618: $requser = $settings->{$item}->{'requser'};
1.320 raeburn 5619: $current = $settings->{$item};
5620: }
1.345 raeburn 5621: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
5622: my %checkedrequser = (
5623: yes => ' checked="checked"',
5624: no => '',
5625: );
5626: if (!$requser) {
5627: $checkedrequser{'no'} = $checkedrequser{'yes'};
5628: $checkedrequser{'yes'} = '';
1.352 raeburn 5629: }
1.320 raeburn 5630: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
5631: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5632: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
5633: for (my $k=0; $k<=$maxnum; $k++) {
5634: my $vpos = $k+1;
5635: my $selstr;
5636: if ($k == $i) {
5637: $selstr = ' selected="selected" ';
5638: }
5639: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5640: }
5641: $datatable .= '</select>'.(' 'x2).
5642: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
5643: &mt('Delete?').'</label></span></td>'.
5644: '<td colspan="2">'.
5645: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5646: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 5647: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
1.320 raeburn 5648: (' 'x2).
5649: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
5650: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
5651: (' 'x2).
5652: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.345 raeburn 5653: 'value="'.$lifetime.'" size="3" /></span>'.
5654: (' 'x2).
5655: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
5656: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
5657: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 5658: '<br /><br />'.
5659: '<span class="LC_nobreak">'.$lt{'key'}.
5660: ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
5661: (' 'x2).
5662: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
5663: '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
5664: '<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>'.
5665: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
1.325 raeburn 5666: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
1.320 raeburn 5667: $itemcount ++;
5668: }
5669: }
5670: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5671: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
5672: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
5673: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
5674: '<select name="lti_pos_add"'.$chgstr.'>';
5675: for (my $k=0; $k<$maxnum+1; $k++) {
5676: my $vpos = $k+1;
5677: my $selstr;
5678: if ($k == $maxnum) {
5679: $selstr = ' selected="selected" ';
5680: }
5681: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5682: }
5683: $datatable .= '</select> '."\n".
1.334 raeburn 5684: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.320 raeburn 5685: '<td colspan="2">'.
5686: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5687: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 5688: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
1.320 raeburn 5689: (' 'x2).
5690: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
5691: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
5692: (' 'x2).
1.345 raeburn 5693: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span> '."\n".
5694: (' 'x2).
5695: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
5696: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
5697: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 5698: '<br /><br />'.
5699: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
5700: (' 'x2).
5701: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
5702: '<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 5703: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
1.320 raeburn 5704: '</td>'."\n".
5705: '</tr>'."\n";
5706: $$rowtotal ++;
5707: return $datatable;;
5708: }
5709:
5710: sub lti_names {
5711: my %lt = &Apache::lonlocal::texthash(
5712: 'version' => 'LTI Version',
5713: 'url' => 'URL',
5714: 'key' => 'Key',
1.322 raeburn 5715: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 5716: 'consumer' => 'Consumer',
1.320 raeburn 5717: 'secret' => 'Secret',
1.345 raeburn 5718: 'requser' => "User's identity sent",
1.320 raeburn 5719: 'email' => 'Email address',
5720: 'sourcedid' => 'User ID',
5721: 'other' => 'Other',
5722: 'passback' => 'Can return grades to Consumer:',
5723: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 5724: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 5725: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 5726: );
5727: return %lt;
5728: }
5729:
5730: sub lti_options {
1.325 raeburn 5731: my ($num,$current,$itemcount,%lt) = @_;
1.363 raeburn 5732: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320 raeburn 5733: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
5734: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
5735: $checked{'makecrs'}{'N'} = ' checked="checked"';
5736: $checked{'mapcrstype'} = {};
5737: $checked{'makeuser'} = {};
5738: $checked{'selfenroll'} = {};
5739: $checked{'crssec'} = {};
5740: $checked{'crssecsrc'} = {};
1.325 raeburn 5741: $checked{'lcauth'} = {};
1.326 raeburn 5742: $checked{'menuitem'} = {};
1.325 raeburn 5743: if ($num eq 'add') {
5744: $checked{'lcauth'}{'lti'} = ' checked="checked"';
5745: }
1.320 raeburn 5746: my $userfieldsty = 'none';
5747: my $crsfieldsty = 'none';
5748: my $crssecfieldsty = 'none';
5749: my $secsrcfieldsty = 'none';
1.363 raeburn 5750: my $callbacksty = 'none';
1.337 raeburn 5751: my $passbacksty = 'none';
1.345 raeburn 5752: my $optionsty = 'block';
1.325 raeburn 5753: my $lcauthparm;
5754: my $lcauthparmstyle = 'display:none';
5755: my $lcauthparmtext;
1.326 raeburn 5756: my $menusty;
1.325 raeburn 5757: my $numinrow = 4;
1.326 raeburn 5758: my %menutitles = <imenu_titles();
1.320 raeburn 5759:
5760: if (ref($current) eq 'HASH') {
1.345 raeburn 5761: if (!$current->{'requser'}) {
5762: $optionsty = 'none';
5763: }
1.320 raeburn 5764: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
5765: $checked{'mapuser'}{'sourcedid'} = '';
5766: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
5767: $checked{'mapuser'}{'email'} = ' checked="checked"';
5768: } else {
5769: $checked{'mapuser'}{'other'} = ' checked="checked"';
5770: $userfield = $current->{'mapuser'};
5771: $userfieldsty = 'inline-block';
5772: }
5773: }
5774: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
5775: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
5776: if ($current->{'mapcrs'} eq 'context_id') {
5777: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
5778: } else {
5779: $checked{'mapcrs'}{'other'} = ' checked="checked"';
5780: $cidfield = $current->{'mapcrs'};
5781: $crsfieldsty = 'inline-block';
5782: }
5783: }
5784: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
5785: foreach my $type (@{$current->{'mapcrstype'}}) {
5786: $checked{'mapcrstype'}{$type} = ' checked="checked"';
5787: }
5788: }
1.345 raeburn 5789: if ($current->{'makecrs'}) {
1.320 raeburn 5790: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 5791: }
1.320 raeburn 5792: if (ref($current->{'makeuser'}) eq 'ARRAY') {
5793: foreach my $role (@{$current->{'makeuser'}}) {
5794: $checked{'makeuser'}{$role} = ' checked="checked"';
5795: }
5796: }
1.325 raeburn 5797: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
5798: $checked{'lcauth'}{$1} = ' checked="checked"';
5799: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
5800: $lcauthparm = $current->{'lcauthparm'};
5801: $lcauthparmstyle = 'display:table-row';
5802: if ($current->{'lcauth'} eq 'localauth') {
5803: $lcauthparmtext = &mt('Local auth argument');
5804: } else {
5805: $lcauthparmtext = &mt('Kerberos domain');
5806: }
5807: }
5808: }
1.320 raeburn 5809: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
5810: foreach my $role (@{$current->{'selfenroll'}}) {
5811: $checked{'selfenroll'}{$role} = ' checked="checked"';
5812: }
5813: }
5814: if (ref($current->{'maproles'}) eq 'HASH') {
5815: %rolemaps = %{$current->{'maproles'}};
5816: }
5817: if ($current->{'section'} ne '') {
5818: $checked{'crssec'}{'Y'} = ' checked="checked"';
5819: $crssecfieldsty = 'inline-block';
5820: if ($current->{'section'} eq 'course_section_sourcedid') {
5821: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
5822: } else {
5823: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
5824: $crssecsrc = $current->{'section'};
5825: $secsrcfieldsty = 'inline-block';
5826: }
5827: } else {
5828: $checked{'crssec'}{'N'} = ' checked="checked"';
5829: }
1.363 raeburn 5830: if ($current->{'callback'} ne '') {
5831: $callback = $current->{'callback'};
5832: $checked{'callback'}{'Y'} = ' checked="checked"';
5833: $callbacksty = 'inline-block';
5834: } else {
5835: $checked{'callback'}{'N'} = ' checked="checked"';
5836: }
1.326 raeburn 5837: if ($current->{'topmenu'}) {
5838: $checked{'topmenu'}{'Y'} = ' checked="checked"';
5839: } else {
5840: $checked{'topmenu'}{'N'} = ' checked="checked"';
5841: }
5842: if ($current->{'inlinemenu'}) {
5843: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5844: } else {
5845: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
5846: }
5847: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
5848: $menusty = 'inline-block';
5849: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
5850: foreach my $item (@{$current->{'lcmenu'}}) {
5851: if (exists($menutitles{$item})) {
5852: $checked{'menuitem'}{$item} = ' checked="checked"';
5853: }
5854: }
5855: }
5856: } else {
5857: $menusty = 'none';
5858: }
1.320 raeburn 5859: } else {
5860: $checked{'makecrs'}{'N'} = ' checked="checked"';
5861: $checked{'crssec'}{'N'} = ' checked="checked"';
1.363 raeburn 5862: $checked{'callback'}{'N'} = ' checked="checked"';
1.326 raeburn 5863: $checked{'topmenu'}{'N'} = ' checked="checked"';
5864: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5865: $checked{'menuitem'}{'grades'} = ' checked="checked"';
5866: $menusty = 'inline-block';
1.320 raeburn 5867: }
1.325 raeburn 5868: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 5869: my %coursetypetitles = &Apache::lonlocal::texthash (
5870: official => 'Official',
5871: unofficial => 'Unofficial',
5872: community => 'Community',
5873: textbook => 'Textbook',
5874: placement => 'Placement Test',
1.325 raeburn 5875: lti => 'LTI Provider',
1.320 raeburn 5876: );
1.325 raeburn 5877: my @authtypes = ('internal','krb4','krb5','localauth');
5878: my %shortauth = (
5879: internal => 'int',
5880: krb4 => 'krb4',
5881: krb5 => 'krb5',
5882: localauth => 'loc'
5883: );
5884: my %authnames = &authtype_names();
1.320 raeburn 5885: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
5886: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
5887: my @courseroles = ('cc','in','ta','ep','st');
5888: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
5889: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
5890: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363 raeburn 5891: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320 raeburn 5892: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 5893: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 5894: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.345 raeburn 5895: my $output = '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 5896: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
5897: foreach my $option ('sourcedid','email','other') {
5898: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
5899: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
5900: ($option eq 'other' ? '' : (' 'x2) );
5901: }
5902: $output .= '</span></div>'.
5903: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
5904: '<input type="text" name="lti_customuser_'.$num.'" '.
1.372 raeburn 5905: 'value="'.$userfield.'" /></div></fieldset>'.
1.345 raeburn 5906: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
1.320 raeburn 5907: foreach my $ltirole (@lticourseroles) {
5908: my ($selected,$selectnone);
5909: if ($rolemaps{$ltirole} eq '') {
5910: $selectnone = ' selected="selected"';
5911: }
5912: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
5913: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
5914: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5915: foreach my $role (@courseroles) {
5916: unless ($selectnone) {
5917: if ($rolemaps{$ltirole} eq $role) {
5918: $selected = ' selected="selected"';
5919: } else {
5920: $selected = '';
5921: }
5922: }
5923: $output .= '<option value="'.$role.'"'.$selected.'>'.
5924: &Apache::lonnet::plaintext($role,'Course').
5925: '</option>';
5926: }
5927: $output .= '</select></td>';
5928: }
5929: $output .= '</tr></table></fieldset>'.
1.345 raeburn 5930: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 5931: foreach my $ltirole (@ltiroles) {
5932: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
5933: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
5934: }
5935: $output .= '</fieldset>'.
1.345 raeburn 5936: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 5937: '<table>'.
5938: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
5939: '</table>'.
5940: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
5941: '<td class="LC_left_item">';
5942: foreach my $auth ('lti',@authtypes) {
5943: my $authtext;
5944: if ($auth eq 'lti') {
5945: $authtext = &mt('None');
5946: } else {
5947: $authtext = $authnames{$shortauth{$auth}};
5948: }
5949: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
5950: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
5951: $authtext.'</label></span> ';
5952: }
5953: $output .= '</td></tr>'.
5954: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
5955: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
5956: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
5957: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
5958: '</table></fieldset>'.
1.345 raeburn 5959: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 5960: '<div class="LC_floatleft"><span class="LC_nobreak">'.
5961: &mt('Unique course identifier').': ';
5962: foreach my $option ('course_offering_sourcedid','context_id','other') {
5963: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
5964: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
5965: ($option eq 'other' ? '' : (' 'x2) );
5966: }
1.334 raeburn 5967: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 5968: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
5969: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
5970: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
5971: foreach my $type (@coursetypes) {
5972: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
5973: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
5974: (' 'x2);
5975: }
5976: $output .= '</span></fieldset>'.
1.345 raeburn 5977: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 5978: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
5979: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
5980: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
5981: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
5982: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
5983: '</fieldset>'.
1.345 raeburn 5984: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 5985: foreach my $lticrsrole (@lticourseroles) {
5986: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
5987: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
5988: }
5989: $output .= '</fieldset>'.
1.345 raeburn 5990: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 5991: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
5992: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
5993: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
5994: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 5995: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 5996: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
5997: '<span class="LC_nobreak">'.&mt('From').':<label>'.
5998: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
5999: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
6000: &mt('Standard field').'</label>'.(' 'x2).
6001: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
6002: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 6003: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 6004: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 6005: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6006: my ($pb1p1chk,$pb1p0chk,$onclickpb);
6007: foreach my $extra ('roster','passback') {
1.320 raeburn 6008: my $checkedon = '';
6009: my $checkedoff = ' checked="checked"';
1.337 raeburn 6010: if ($extra eq 'passback') {
6011: $pb1p1chk = ' checked="checked"';
6012: $pb1p0chk = '';
6013: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
6014: } else {
6015: $onclickpb = '';
6016: }
1.320 raeburn 6017: if (ref($current) eq 'HASH') {
6018: if (($current->{$extra})) {
6019: $checkedon = $checkedoff;
6020: $checkedoff = '';
1.337 raeburn 6021: if ($extra eq 'passback') {
6022: $passbacksty = 'inline-block';
6023: }
6024: if ($current->{'passbackformat'} eq '1.0') {
6025: $pb1p0chk = ' checked="checked"';
6026: $pb1p1chk = '';
6027: }
1.320 raeburn 6028: }
6029: }
6030: $output .= $lt{$extra}.' '.
1.337 raeburn 6031: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 6032: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 6033: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 6034: &mt('Yes').'</label><br />';
6035: }
1.337 raeburn 6036: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
6037: '<span class="LC_nobreak">'.&mt('Grade format').
6038: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
6039: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
6040: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363 raeburn 6041: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
6042: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6043: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback on logout').': '.
6044: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
6045: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
6046: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
6047: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
6048: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
6049: '<span class="LC_nobreak">'.&mt('Parameter').': '.
6050: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
6051: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
1.345 raeburn 6052: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Course defaults (Course Coordinator can override)').'</legend>'.
1.326 raeburn 6053: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
6054: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
6055: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6056: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
1.334 raeburn 6057: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
1.326 raeburn 6058: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6059: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
6060: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
6061: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6062: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
1.334 raeburn 6063: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
1.326 raeburn 6064: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6065: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
6066: '<span class="LC_nobreak">'.&mt('Menu items').': ';
6067: foreach my $type ('fullname','coursetitle','role','logout','grades') {
6068: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
6069: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
6070: (' 'x2);
6071: }
1.334 raeburn 6072: $output .= '</span></div></fieldset>';
1.320 raeburn 6073: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
6074: #
6075: # $output .= '</fieldset>'.
6076: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
6077: return $output;
6078: }
6079:
1.326 raeburn 6080: sub ltimenu_titles {
6081: return &Apache::lonlocal::texthash(
6082: fullname => 'Full name',
6083: coursetitle => 'Course title',
6084: role => 'Role',
6085: logout => 'Logout',
6086: grades => 'Grades',
6087: );
6088: }
6089:
1.121 raeburn 6090: sub print_coursedefaults {
1.139 raeburn 6091: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 6092: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 6093: my $itemcount = 1;
1.192 raeburn 6094: my %choices = &Apache::lonlocal::texthash (
6095: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 6096: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 6097: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6098: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 6099: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6100: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.314 raeburn 6101: texengine => 'Default method to display mathematics',
1.257 raeburn 6102: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 6103: canclone => "People who may clone a course (besides course's owner and coordinators)",
6104: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 6105: );
1.198 raeburn 6106: my %staticdefaults = (
6107: anonsurvey_threshold => 10,
6108: uploadquota => 500,
1.257 raeburn 6109: postsubmit => 60,
1.276 raeburn 6110: mysqltables => 172800,
1.198 raeburn 6111: );
1.139 raeburn 6112: if ($position eq 'top') {
1.257 raeburn 6113: %defaultchecked = (
6114: 'canuse_pdfforms' => 'off',
6115: 'uselcmath' => 'on',
6116: 'usejsme' => 'on',
1.289 raeburn 6117: 'canclone' => 'none',
1.257 raeburn 6118: );
6119: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.349 raeburn 6120: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 6121: if (ref($settings) eq 'HASH') {
6122: if ($settings->{'texengine'}) {
6123: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6124: $deftex = $settings->{'texengine'};
6125: }
6126: }
6127: }
6128: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6129: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6130: '<span class="LC_nobreak">'.$choices{'texengine'}.
6131: '</span></td><td class="LC_right_item">'.
6132: '<select name="texengine">'."\n";
6133: my %texoptions = (
6134: MathJax => 'MathJax',
6135: mimetex => &mt('Convert to Images'),
6136: tth => &mt('TeX to HTML'),
6137: );
6138: foreach my $renderer ('MathJax','mimetex','tth') {
6139: my $selected = '';
6140: if ($renderer eq $deftex) {
6141: $selected = ' selected="selected"';
6142: }
6143: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6144: }
6145: $mathdisp .= '</select></td></tr>'."\n";
6146: $itemcount ++;
1.139 raeburn 6147: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 6148: \%choices,$itemcount);
1.314 raeburn 6149: $datatable = $mathdisp.$datatable;
1.264 raeburn 6150: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6151: $datatable .=
1.306 raeburn 6152: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 6153: '<span class="LC_nobreak">'.$choices{'canclone'}.
6154: '</span></td><td class="LC_left_item">';
6155: my $currcanclone = 'none';
6156: my $onclick;
6157: my @cloneoptions = ('none','domain');
6158: my %clonetitles = (
6159: none => 'No additional course requesters',
6160: domain => "Any course requester in course's domain",
6161: instcode => 'Course requests for official courses ...',
6162: );
6163: my (%codedefaults,@code_order,@posscodes);
6164: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6165: \@code_order) eq 'ok') {
6166: if (@code_order > 0) {
6167: push(@cloneoptions,'instcode');
6168: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6169: }
6170: }
6171: if (ref($settings) eq 'HASH') {
6172: if ($settings->{'canclone'}) {
6173: if (ref($settings->{'canclone'}) eq 'HASH') {
6174: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6175: if (@code_order > 0) {
6176: $currcanclone = 'instcode';
6177: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6178: }
6179: }
6180: } elsif ($settings->{'canclone'} eq 'domain') {
6181: $currcanclone = $settings->{'canclone'};
6182: }
6183: }
1.289 raeburn 6184: }
1.264 raeburn 6185: foreach my $option (@cloneoptions) {
6186: my ($checked,$additional);
6187: if ($currcanclone eq $option) {
6188: $checked = ' checked="checked"';
6189: }
6190: if ($option eq 'instcode') {
6191: if (@code_order) {
6192: my $show = 'none';
6193: if ($checked) {
6194: $show = 'block';
6195: }
1.317 raeburn 6196: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 6197: &mt('Institutional codes for new and cloned course have identical:').
6198: '<br />';
6199: foreach my $item (@code_order) {
6200: my $codechk;
6201: if ($checked) {
6202: if (grep(/^\Q$item\E$/,@posscodes)) {
6203: $codechk = ' checked="checked"';
6204: }
6205: }
6206: $additional .= '<label>'.
6207: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
6208: $item.'</label>';
6209: }
6210: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
6211: }
6212: }
6213: $datatable .=
6214: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
6215: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
6216: '</label> '.$additional.'</span><br />';
6217: }
6218: $datatable .= '</td>'.
6219: '</tr>';
6220: $itemcount ++;
1.139 raeburn 6221: } else {
6222: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 6223: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 6224: my $currusecredits = 0;
1.257 raeburn 6225: my $postsubmitclient = 1;
1.271 raeburn 6226: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 6227: if (ref($settings) eq 'HASH') {
6228: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 6229: if (ref($settings->{'uploadquota'}) eq 'HASH') {
6230: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
6231: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
6232: }
6233: }
1.192 raeburn 6234: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 6235: foreach my $type (@types) {
6236: next if ($type eq 'community');
6237: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
6238: if ($defcredits{$type} ne '') {
6239: $currusecredits = 1;
6240: }
6241: }
6242: }
6243: if (ref($settings->{'postsubmit'}) eq 'HASH') {
6244: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
6245: $postsubmitclient = 0;
6246: foreach my $type (@types) {
6247: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6248: }
6249: } else {
6250: foreach my $type (@types) {
6251: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
6252: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 6253: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 6254: } else {
6255: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6256: }
6257: } else {
6258: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6259: }
6260: }
6261: }
6262: } else {
6263: foreach my $type (@types) {
6264: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 6265: }
6266: }
1.276 raeburn 6267: if (ref($settings->{'mysqltables'}) eq 'HASH') {
6268: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
6269: $currmysql{$type} = $settings->{'mysqltables'}{$type};
6270: }
6271: } else {
6272: foreach my $type (@types) {
6273: $currmysql{$type} = $staticdefaults{'mysqltables'};
6274: }
6275: }
1.258 raeburn 6276: } else {
6277: foreach my $type (@types) {
6278: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6279: }
1.139 raeburn 6280: }
6281: if (!$currdefresponder) {
1.198 raeburn 6282: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 6283: } elsif ($currdefresponder < 1) {
6284: $currdefresponder = 1;
6285: }
1.198 raeburn 6286: foreach my $type (@types) {
6287: if ($curruploadquota{$type} eq '') {
6288: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
6289: }
6290: }
1.139 raeburn 6291: $datatable .=
1.192 raeburn 6292: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6293: $choices{'anonsurvey_threshold'}.
1.139 raeburn 6294: '</span></td>'.
6295: '<td class="LC_right_item"><span class="LC_nobreak">'.
6296: '<input type="text" name="anonsurvey_threshold"'.
6297: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 6298: '</td></tr>'."\n";
6299: $itemcount ++;
6300: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6301: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6302: $choices{'uploadquota'}.
6303: '</span></td>'.
1.306 raeburn 6304: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 6305: '<table><tr>';
1.198 raeburn 6306: foreach my $type (@types) {
1.306 raeburn 6307: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 6308: '<input type="text" name="uploadquota_'.$type.'"'.
6309: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
6310: }
6311: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 6312: $itemcount ++;
1.236 raeburn 6313: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 6314: my $display = 'none';
1.192 raeburn 6315: if ($currusecredits) {
6316: $display = 'block';
6317: }
6318: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 6319: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
6320: foreach my $type (@types) {
6321: next if ($type eq 'community');
1.306 raeburn 6322: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 6323: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 6324: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 6325: }
6326: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 6327: %defaultchecked = ('coursecredits' => 'off');
6328: @toggles = ('coursecredits');
6329: my $current = {
6330: 'coursecredits' => $currusecredits,
6331: };
6332: (my $table,$itemcount) =
6333: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 6334: \%choices,$itemcount,$onclick,$additional,'left');
6335: $datatable .= $table;
6336: $onclick = "toggleDisplay(this.form,'studentsubmission');";
6337: my $display = 'none';
6338: if ($postsubmitclient) {
6339: $display = 'block';
6340: }
6341: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 6342: &mt('Number of seconds submit is disabled').'<br />'.
6343: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
6344: '<table><tr>';
1.257 raeburn 6345: foreach my $type (@types) {
1.306 raeburn 6346: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 6347: '<input type="text" name="'.$type.'_timeout" value="'.
6348: $deftimeout{$type}.'" size="5" /></td>';
6349: }
6350: $additional .= '</tr></table></div>'."\n";
6351: %defaultchecked = ('postsubmit' => 'on');
6352: @toggles = ('postsubmit');
1.280 raeburn 6353: $current = {
6354: 'postsubmit' => $postsubmitclient,
6355: };
1.257 raeburn 6356: ($table,$itemcount) =
6357: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
6358: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 6359: $datatable .= $table;
1.276 raeburn 6360: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6361: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6362: $choices{'mysqltables'}.
6363: '</span></td>'.
1.306 raeburn 6364: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 6365: '<table><tr>';
6366: foreach my $type (@types) {
1.306 raeburn 6367: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 6368: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 6369: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 6370: }
6371: $datatable .= '</tr></table></td></tr>'."\n";
6372: $itemcount ++;
6373:
1.139 raeburn 6374: }
1.192 raeburn 6375: $$rowtotal += $itemcount;
1.121 raeburn 6376: return $datatable;
1.118 jms 6377: }
6378:
1.231 raeburn 6379: sub print_selfenrollment {
6380: my ($position,$dom,$settings,$rowtotal) = @_;
6381: my ($css_class,$datatable);
6382: my $itemcount = 1;
1.271 raeburn 6383: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 6384: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 6385: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
6386: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 6387: my @rows;
6388: my $key;
6389: if ($position eq 'top') {
6390: $key = 'admin';
6391: if (ref($rowsref) eq 'ARRAY') {
6392: @rows = @{$rowsref};
6393: }
6394: } elsif ($position eq 'middle') {
6395: $key = 'default';
6396: @rows = ('types','registered','approval','limit');
6397: }
6398: foreach my $row (@rows) {
6399: if (defined($titlesref->{$row})) {
6400: $itemcount ++;
6401: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6402: $datatable .= '<tr'.$css_class.'>'.
6403: '<td>'.$titlesref->{$row}.'</td>'.
6404: '<td class="LC_left_item">'.
6405: '<table><tr>';
6406: my (%current,%currentcap);
6407: if (ref($settings) eq 'HASH') {
6408: if (ref($settings->{$key}) eq 'HASH') {
6409: foreach my $type (@types) {
6410: if (ref($settings->{$key}->{$type}) eq 'HASH') {
6411: $current{$type} = $settings->{$key}->{$type}->{$row};
6412: }
6413: if (($row eq 'limit') && ($key eq 'default')) {
6414: if (ref($settings->{$key}->{$type}) eq 'HASH') {
6415: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
6416: }
6417: }
6418: }
6419: }
6420: }
6421: my %roles = (
6422: '0' => &Apache::lonnet::plaintext('dc'),
6423: );
6424:
6425: foreach my $type (@types) {
6426: unless (($row eq 'registered') && ($key eq 'default')) {
6427: $datatable .= '<th>'.&mt($type).'</th>';
6428: }
6429: }
6430: unless (($row eq 'registered') && ($key eq 'default')) {
6431: $datatable .= '</tr><tr>';
6432: }
6433: foreach my $type (@types) {
6434: if ($type eq 'community') {
6435: $roles{'1'} = &mt('Community personnel');
6436: } else {
6437: $roles{'1'} = &mt('Course personnel');
6438: }
6439: $datatable .= '<td style="vertical-align: top">';
6440: if ($position eq 'top') {
6441: my %checked;
6442: if ($current{$type} eq '0') {
6443: $checked{'0'} = ' checked="checked"';
6444: } else {
6445: $checked{'1'} = ' checked="checked"';
6446: }
6447: foreach my $role ('1','0') {
6448: $datatable .= '<span class="LC_nobreak"><label>'.
6449: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
6450: 'value="'.$role.'"'.$checked{$role}.' />'.
6451: $roles{$role}.'</label></span> ';
6452: }
6453: } else {
6454: if ($row eq 'types') {
6455: my %checked;
6456: if ($current{$type} =~ /^(all|dom)$/) {
6457: $checked{$1} = ' checked="checked"';
6458: } else {
6459: $checked{''} = ' checked="checked"';
6460: }
6461: foreach my $val ('','dom','all') {
6462: $datatable .= '<span class="LC_nobreak"><label>'.
6463: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6464: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6465: }
6466: } elsif ($row eq 'registered') {
6467: my %checked;
6468: if ($current{$type} eq '1') {
6469: $checked{'1'} = ' checked="checked"';
6470: } else {
6471: $checked{'0'} = ' checked="checked"';
6472: }
6473: foreach my $val ('0','1') {
6474: $datatable .= '<span class="LC_nobreak"><label>'.
6475: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6476: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6477: }
6478: } elsif ($row eq 'approval') {
6479: my %checked;
6480: if ($current{$type} =~ /^([12])$/) {
6481: $checked{$1} = ' checked="checked"';
6482: } else {
6483: $checked{'0'} = ' checked="checked"';
6484: }
6485: for my $val (0..2) {
6486: $datatable .= '<span class="LC_nobreak"><label>'.
6487: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6488: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6489: }
6490: } elsif ($row eq 'limit') {
6491: my %checked;
6492: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
6493: $checked{$1} = ' checked="checked"';
6494: } else {
6495: $checked{'none'} = ' checked="checked"';
6496: }
6497: my $cap;
6498: if ($currentcap{$type} =~ /^\d+$/) {
6499: $cap = $currentcap{$type};
6500: }
6501: foreach my $val ('none','allstudents','selfenrolled') {
6502: $datatable .= '<span class="LC_nobreak"><label>'.
6503: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6504: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6505: }
6506: $datatable .= '<br />'.
6507: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
6508: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
6509: '</span>';
6510: }
6511: }
6512: $datatable .= '</td>';
6513: }
6514: $datatable .= '</tr>';
6515: }
6516: $datatable .= '</table></td></tr>';
6517: }
6518: } elsif ($position eq 'bottom') {
1.235 raeburn 6519: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
6520: }
6521: $$rowtotal += $itemcount;
6522: return $datatable;
6523: }
6524:
6525: sub print_validation_rows {
6526: my ($caller,$dom,$settings,$rowtotal) = @_;
6527: my ($itemsref,$namesref,$fieldsref);
6528: if ($caller eq 'selfenroll') {
6529: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
6530: } elsif ($caller eq 'requestcourses') {
6531: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
6532: }
6533: my %currvalidation;
6534: if (ref($settings) eq 'HASH') {
6535: if (ref($settings->{'validation'}) eq 'HASH') {
6536: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 6537: }
1.235 raeburn 6538: }
6539: my $datatable;
6540: my $itemcount = 0;
6541: foreach my $item (@{$itemsref}) {
6542: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6543: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6544: $namesref->{$item}.
6545: '</span></td>'.
6546: '<td class="LC_left_item">';
6547: if (($item eq 'url') || ($item eq 'button')) {
6548: $datatable .= '<span class="LC_nobreak">'.
6549: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
6550: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
6551: } elsif ($item eq 'fields') {
6552: my @currfields;
6553: if (ref($currvalidation{$item}) eq 'ARRAY') {
6554: @currfields = @{$currvalidation{$item}};
6555: }
6556: foreach my $field (@{$fieldsref}) {
6557: my $check = '';
6558: if (grep(/^\Q$field\E$/,@currfields)) {
6559: $check = ' checked="checked"';
6560: }
6561: $datatable .= '<span class="LC_nobreak"><label>'.
6562: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
6563: ' value="'.$field.'"'.$check.' />'.$field.
6564: '</label></span> ';
6565: }
6566: } elsif ($item eq 'markup') {
1.334 raeburn 6567: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 6568: $currvalidation{$item}.
1.231 raeburn 6569: '</textarea>';
1.235 raeburn 6570: }
6571: $datatable .= '</td></tr>'."\n";
6572: if (ref($rowtotal)) {
1.231 raeburn 6573: $itemcount ++;
6574: }
6575: }
1.235 raeburn 6576: if ($caller eq 'requestcourses') {
6577: my %currhash;
1.248 raeburn 6578: if (ref($settings) eq 'HASH') {
6579: if (ref($settings->{'validation'}) eq 'HASH') {
6580: if ($settings->{'validation'}{'dc'} ne '') {
6581: $currhash{$settings->{'validation'}{'dc'}} = 1;
6582: }
1.235 raeburn 6583: }
6584: }
6585: my $numinrow = 2;
6586: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
6587: 'validationdc',%currhash);
1.247 raeburn 6588: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 6589: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 6590: if ($numdc > 1) {
1.247 raeburn 6591: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 6592: } else {
1.247 raeburn 6593: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 6594: }
1.247 raeburn 6595: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 6596: $itemcount ++;
6597: }
6598: if (ref($rowtotal)) {
6599: $$rowtotal += $itemcount;
6600: }
1.231 raeburn 6601: return $datatable;
6602: }
6603:
1.357 raeburn 6604: sub print_privacy {
6605: my ($position,$dom,$settings,$rowtotal) = @_;
6606: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
6607: my $itemcount = 0;
6608: unless ($position eq 'top') {
6609: @items = ('domain','author','course','community');
6610: %names = &Apache::lonlocal::texthash (
6611: domain => 'Assigned domain role(s)',
6612: author => 'Assigned co-author role(s)',
6613: course => 'Assigned course role(s)',
6614: community => 'Assigned community role',
6615: );
6616: $numinrow = 4;
6617: ($othertitle,$usertypes,$types) =
6618: &Apache::loncommon::sorted_inst_types($dom);
6619: }
6620: if (($position eq 'top') || ($position eq 'middle')) {
6621: my (%by_ip,%by_location,@intdoms,@instdoms);
6622: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
6623: if ($position eq 'top') {
6624: my %curr;
6625: my @options = ('none','user','domain','auto');
6626: my %titles = &Apache::lonlocal::texthash (
6627: none => 'Not allowed',
6628: user => 'User authorizes',
6629: domain => 'DC authorizes',
6630: auto => 'Unrestricted',
6631: instdom => 'Other domain shares institution/provider',
6632: extdom => 'Other domain has different institution/provider',
6633: );
6634: my %names = &Apache::lonlocal::texthash (
6635: domain => 'Domain role',
6636: author => 'Co-author role',
6637: course => 'Course role',
6638: community => 'Community role',
6639: );
6640: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6641: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6642: foreach my $domtype ('instdom','extdom') {
6643: my (%checked,$skip);
6644: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6645: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
6646: '<td class="LC_left_item">';
6647: if ($domtype eq 'instdom') {
6648: unless (@instdoms > 1) {
6649: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
6650: $skip = 1;
6651: }
6652: } elsif ($domtype eq 'extdom') {
6653: if (keys(%by_location) == 0) {
6654: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
6655: $skip = 1;
6656: }
6657: }
6658: unless ($skip) {
6659: foreach my $roletype ('domain','author','course','community') {
6660: $checked{'auto'} = ' checked="checked"';
6661: if (ref($settings) eq 'HASH') {
6662: if (ref($settings->{approval}) eq 'HASH') {
6663: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
6664: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
6665: $checked{$1} = ' checked="checked"';
6666: $checked{'auto'} = '';
6667: }
6668: }
6669: }
6670: }
6671: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
6672: foreach my $option (@options) {
6673: $datatable .= '<span class="LC_nobreak"><label>'.
6674: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
6675: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
6676: '</label></span> ';
6677: }
6678: $datatable .= '</fieldset>';
6679: }
6680: }
6681: $datatable .= '</td></tr>';
6682: $itemcount ++;
6683: }
6684: } elsif ($position eq 'middle') {
6685: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
6686: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6687: foreach my $item (@{$types}) {
6688: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
6689: $numinrow,$itemcount,'','','','','',
6690: '',$usertypes->{$item});
6691: $itemcount ++;
6692: }
6693: }
6694: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
6695: $numinrow,$itemcount,'','','','','',
6696: '',$othertitle);
6697: $itemcount ++;
6698: } else {
1.360 raeburn 6699: my (@insttypes,%insttitles);
6700: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6701: @insttypes = @{$types};
6702: %insttitles = %{$usertypes};
6703: }
6704: foreach my $item (@insttypes,'default') {
6705: my $title;
6706: if ($item eq 'default') {
6707: $title = $othertitle;
6708: } else {
6709: $title = $insttitles{$item};
6710: }
6711: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6712: $datatable .= '<tr'.$css_class.'>'.
6713: '<td class="LC_left_item">'.$title.'</td>'.
6714: '<td class="LC_left_item">'.
6715: &mt('Nothing to set here, as there are no other domains').
6716: '</td></tr>';
6717: $itemcount ++;
6718: }
1.357 raeburn 6719: }
6720: }
6721: } else {
6722: my $prefix;
6723: if ($position eq 'lower') {
6724: $prefix = 'priv';
6725: } else {
6726: $prefix = 'unpriv';
6727: }
6728: foreach my $item (@items) {
6729: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
6730: $numinrow,$itemcount,'','','','','',
6731: '',$names{$item});
6732: $itemcount ++;
6733: }
6734: }
6735: if (ref($rowtotal)) {
6736: $$rowtotal += $itemcount;
6737: }
6738: return $datatable;
6739: }
6740:
1.354 raeburn 6741: sub print_passwords {
6742: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
6743: my ($datatable,$css_class);
6744: my $itemcount = 0;
6745: my %titles = &Apache::lonlocal::texthash (
6746: captcha => '"Forgot Password" CAPTCHA validation',
6747: link => 'Reset link expiration (hours)',
6748: case => 'Case-sensitive usernames/e-mail',
6749: prelink => 'Information required (form 1)',
6750: postlink => 'Information required (form 2)',
6751: emailsrc => 'LON-CAPA e-mail address type(s)',
6752: customtext => 'Domain specific text (HTML)',
6753: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
6754: intauth_check => 'Check bcrypt cost if authenticated',
6755: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
6756: permanent => 'Permanent e-mail address',
6757: critical => 'Critical notification address',
6758: notify => 'Notification address',
6759: min => 'Minimum password length',
6760: max => 'Maximum password length',
6761: chars => 'Required characters',
6762: expire => 'Password expiration (days)',
1.356 raeburn 6763: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 6764: );
6765: if ($position eq 'top') {
6766: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6767: my $shownlinklife = 2;
6768: my $prelink = 'both';
6769: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
6770: if (ref($settings) eq 'HASH') {
6771: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
6772: $shownlinklife = $settings->{resetlink};
6773: }
6774: if (ref($settings->{resetcase}) eq 'ARRAY') {
6775: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
6776: }
6777: if ($settings->{resetprelink} =~ /^(both|either)$/) {
6778: $prelink = $settings->{resetprelink};
6779: }
6780: if (ref($settings->{resetpostlink}) eq 'HASH') {
6781: %postlink = %{$settings->{resetpostlink}};
6782: }
6783: if (ref($settings->{resetemail}) eq 'ARRAY') {
6784: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
6785: }
6786: if ($settings->{resetremove}) {
6787: $nostdtext = 1;
6788: }
6789: if ($settings->{resetcustom}) {
6790: $customurl = $settings->{resetcustom};
6791: }
6792: } else {
6793: if (ref($types) eq 'ARRAY') {
6794: foreach my $item (@{$types}) {
6795: $casesens{$item} = 1;
6796: $postlink{$item} = ['username','email'];
6797: }
6798: }
6799: $casesens{'default'} = 1;
6800: $postlink{'default'} = ['username','email'];
6801: $prelink = 'both';
6802: %emailsrc = (
6803: permanent => 1,
6804: critical => 1,
6805: notify => 1,
6806: );
6807: }
6808: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
6809: $itemcount ++;
6810: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6811: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
6812: '<td class="LC_left_item">'.
6813: '<input type="textbox" value="'.$shownlinklife.'" '.
6814: 'name="passwords_link" size="3" /></td></tr>';
6815: $itemcount ++;
6816: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6817: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
6818: '<td class="LC_left_item">';
6819: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6820: foreach my $item (@{$types}) {
6821: my $checkedcase;
6822: if ($casesens{$item}) {
6823: $checkedcase = ' checked="checked"';
6824: }
6825: $datatable .= '<span class="LC_nobreak"><label>'.
6826: '<input type="checkbox" name="passwords_case_sensitive" value="'.
6827: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 6828: '</span> ';
1.354 raeburn 6829: }
6830: }
6831: my $checkedcase;
6832: if ($casesens{'default'}) {
6833: $checkedcase = ' checked="checked"';
6834: }
6835: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
6836: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
6837: $othertitle.'</label></span></td>';
6838: $itemcount ++;
6839: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6840: my %checkedpre = (
6841: both => ' checked="checked"',
6842: either => '',
6843: );
6844: if ($prelink eq 'either') {
6845: $checkedpre{either} = ' checked="checked"';
6846: $checkedpre{both} = '';
6847: }
6848: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
6849: '<td class="LC_left_item"><span class="LC_nobreak">'.
6850: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
6851: &mt('Both username and e-mail address').'</label></span> '.
6852: '<span class="LC_nobreak"><label>'.
6853: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
6854: &mt('Either username or e-mail address').'</label></span></td></tr>';
6855: $itemcount ++;
6856: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6857: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
6858: '<td class="LC_left_item">';
6859: my %postlinked;
6860: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6861: foreach my $item (@{$types}) {
6862: undef(%postlinked);
6863: $datatable .= '<fieldset style="display: inline-block;">'.
6864: '<legend>'.$usertypes->{$item}.'</legend>';
6865: if (ref($postlink{$item}) eq 'ARRAY') {
6866: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
6867: }
6868: foreach my $field ('email','username') {
6869: my $checked;
6870: if ($postlinked{$field}) {
6871: $checked = ' checked="checked"';
6872: }
6873: $datatable .= '<span class="LC_nobreak"><label>'.
6874: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
6875: $field.'"'.$checked.' />'.$field.'</label>'.
6876: '<span> ';
6877: }
6878: $datatable .= '</fieldset>';
6879: }
6880: }
6881: if (ref($postlink{'default'}) eq 'ARRAY') {
6882: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
6883: }
6884: $datatable .= '<fieldset style="display: inline-block;">'.
6885: '<legend>'.$othertitle.'</legend>';
6886: foreach my $field ('email','username') {
6887: my $checked;
6888: if ($postlinked{$field}) {
6889: $checked = ' checked="checked"';
6890: }
6891: $datatable .= '<span class="LC_nobreak"><label>'.
6892: '<input type="checkbox" name="passwords_postlink_default" value="'.
6893: $field.'"'.$checked.' />'.$field.'</label>'.
6894: '<span> ';
6895: }
6896: $datatable .= '</fieldset></td></tr>';
6897: $itemcount ++;
6898: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6899: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
6900: '<td class="LC_left_item">';
6901: foreach my $type ('permanent','critical','notify') {
6902: my $checkedemail;
6903: if ($emailsrc{$type}) {
6904: $checkedemail = ' checked="checked"';
6905: }
6906: $datatable .= '<span class="LC_nobreak"><label>'.
6907: '<input type="checkbox" name="passwords_emailsrc" value="'.
6908: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
6909: '<span> ';
6910: }
6911: $datatable .= '</td></tr>';
6912: $itemcount ++;
6913: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6914: my $switchserver = &check_switchserver($dom,$confname);
6915: my ($showstd,$noshowstd);
6916: if ($nostdtext) {
6917: $noshowstd = ' checked="checked"';
6918: } else {
6919: $showstd = ' checked="checked"';
6920: }
6921: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
6922: '<td class="LC_left_item"><span class="LC_nobreak">'.
6923: &mt('Retain standard text:').
6924: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
6925: &mt('Yes').'</label>'.' '.
6926: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
6927: &mt('No').'</label></span><br />'.
6928: '<span class="LC_fontsize_small">'.
6929: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
6930: &mt('Include custom text:');
6931: if ($customurl) {
1.369 raeburn 6932: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 6933: undef,undef,undef,undef,'background-color:#ffffff');
6934: $datatable .= '<span class="LC_nobreak"> '.$link.
6935: '<label><input type="checkbox" name="passwords_custom_del"'.
6936: ' value="1" />'.&mt('Delete?').'</label></span>'.
6937: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
6938: }
6939: if ($switchserver) {
6940: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
6941: } else {
6942: $datatable .='<span class="LC_nobreak"> '.
6943: '<input type="file" name="passwords_customfile" /></span>';
6944: }
6945: $datatable .= '</td></tr>';
6946: } elsif ($position eq 'middle') {
6947: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
6948: my @items = ('intauth_cost','intauth_check','intauth_switch');
6949: my %defaults;
6950: if (ref($domconf{'defaults'}) eq 'HASH') {
6951: %defaults = %{$domconf{'defaults'}};
6952: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
6953: $defaults{'intauth_cost'} = 10;
6954: }
6955: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
6956: $defaults{'intauth_check'} = 0;
6957: }
6958: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
6959: $defaults{'intauth_switch'} = 0;
6960: }
6961: } else {
6962: %defaults = (
6963: 'intauth_cost' => 10,
6964: 'intauth_check' => 0,
6965: 'intauth_switch' => 0,
6966: );
6967: }
6968: foreach my $item (@items) {
6969: if ($itemcount%2) {
6970: $css_class = '';
6971: } else {
6972: $css_class = ' class="LC_odd_row" ';
6973: }
6974: $datatable .= '<tr'.$css_class.'>'.
6975: '<td><span class="LC_nobreak">'.$titles{$item}.
6976: '</span></td><td class="LC_left_item" colspan="3">';
6977: if ($item eq 'intauth_switch') {
6978: my @options = (0,1,2);
6979: my %optiondesc = &Apache::lonlocal::texthash (
6980: 0 => 'No',
6981: 1 => 'Yes',
6982: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
6983: );
6984: $datatable .= '<table width="100%">';
6985: foreach my $option (@options) {
6986: my $checked = ' ';
6987: if ($defaults{$item} eq $option) {
6988: $checked = ' checked="checked"';
6989: }
6990: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6991: '<label><input type="radio" name="'.$item.
6992: '" value="'.$option.'"'.$checked.' />'.
6993: $optiondesc{$option}.'</label></span></td></tr>';
6994: }
6995: $datatable .= '</table>';
6996: } elsif ($item eq 'intauth_check') {
6997: my @options = (0,1,2);
6998: my %optiondesc = &Apache::lonlocal::texthash (
6999: 0 => 'No',
7000: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
7001: 2 => 'Yes, disallow login if stored cost is less than domain default',
7002: );
7003: $datatable .= '<table width="100%">';
7004: foreach my $option (@options) {
7005: my $checked = ' ';
7006: my $onclick;
7007: if ($defaults{$item} eq $option) {
7008: $checked = ' checked="checked"';
7009: }
7010: if ($option == 2) {
7011: $onclick = ' onclick="javascript:warnIntAuth(this);"';
7012: }
7013: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7014: '<label><input type="radio" name="'.$item.
7015: '" value="'.$option.'"'.$checked.$onclick.' />'.
7016: $optiondesc{$option}.'</label></span></td></tr>';
7017: }
7018: $datatable .= '</table>';
7019: } else {
7020: $datatable .= '<input type="text" name="'.$item.'" value="'.
7021: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
7022: }
7023: $datatable .= '</td></tr>';
7024: $itemcount ++;
7025: }
7026: } elsif ($position eq 'lower') {
1.356 raeburn 7027: my ($min,$max,%chars,$expire,$numsaved);
1.365 raeburn 7028: $min = $Apache::lonnet::passwdmin;
1.354 raeburn 7029: if (ref($settings) eq 'HASH') {
7030: if ($settings->{min}) {
7031: $min = $settings->{min};
7032: }
7033: if ($settings->{max}) {
7034: $max = $settings->{max};
7035: }
7036: if (ref($settings->{chars}) eq 'ARRAY') {
7037: map { $chars{$_} = 1; } (@{$settings->{chars}});
7038: }
7039: if ($settings->{expire}) {
7040: $expire = $settings->{expire};
7041: }
1.358 raeburn 7042: if ($settings->{numsaved}) {
7043: $numsaved = $settings->{numsaved};
1.356 raeburn 7044: }
1.354 raeburn 7045: }
7046: my %rulenames = &Apache::lonlocal::texthash(
7047: uc => 'At least one upper case letter',
7048: lc => 'At least one lower case letter',
7049: num => 'At least one number',
7050: spec => 'At least one non-alphanumeric',
7051: );
7052: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7053: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
7054: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 7055: '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
7056: 'onblur="javascript:warnIntPass(this);" />'.
7057: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
1.354 raeburn 7058: '</span></td></tr>';
7059: $itemcount ++;
7060: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7061: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
7062: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 7063: '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
7064: 'onblur="javascript:warnIntPass(this);" />'.
1.354 raeburn 7065: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
7066: '</span></td></tr>';
7067: $itemcount ++;
7068: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7069: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
7070: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
7071: '</span></td>';
7072: my $numinrow = 2;
7073: my @possrules = ('uc','lc','num','spec');
7074: $datatable .= '<td class="LC_left_item"><table>';
7075: for (my $i=0; $i<@possrules; $i++) {
7076: my ($rem,$checked);
7077: if ($chars{$possrules[$i]}) {
7078: $checked = ' checked="checked"';
7079: }
7080: $rem = $i%($numinrow);
7081: if ($rem == 0) {
7082: if ($i > 0) {
7083: $datatable .= '</tr>';
7084: }
7085: $datatable .= '<tr>';
7086: }
7087: $datatable .= '<td><span class="LC_nobreak"><label>'.
7088: '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
7089: $rulenames{$possrules[$i]}.'</label></span></td>';
7090: }
7091: my $rem = @possrules%($numinrow);
7092: my $colsleft = $numinrow - $rem;
7093: if ($colsleft > 1 ) {
7094: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7095: ' </td>';
7096: } elsif ($colsleft == 1) {
7097: $datatable .= '<td class="LC_left_item"> </td>';
7098: }
7099: $datatable .='</table></td></tr>';
7100: $itemcount ++;
7101: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7102: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
7103: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 7104: '<input type="text" name="passwords_expire" value="'.$expire.'" size="4" '.
7105: 'onblur="javascript:warnIntPass(this);" />'.
1.354 raeburn 7106: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
7107: '</span></td></tr>';
1.356 raeburn 7108: $itemcount ++;
7109: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7110: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
7111: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.367 raeburn 7112: '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
7113: 'onblur="javascript:warnIntPass(this);" />'.
1.356 raeburn 7114: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
7115: '</span></td></tr>';
1.354 raeburn 7116: } else {
1.359 raeburn 7117: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7118: my %ownerchg = (
7119: by => {},
7120: for => {},
7121: );
7122: my %ownertitles = &Apache::lonlocal::texthash (
7123: by => 'Course owner status(es) allowed',
7124: for => 'Student status(es) allowed',
7125: );
1.354 raeburn 7126: if (ref($settings) eq 'HASH') {
1.359 raeburn 7127: if (ref($settings->{crsownerchg}) eq 'HASH') {
7128: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
7129: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
7130: }
7131: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
7132: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
7133: }
1.354 raeburn 7134: }
7135: }
7136: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7137: $datatable .= '<tr '.$css_class.'>'.
7138: '<td>'.
7139: &mt('Requirements').'<ul>'.
1.359 raeburn 7140: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 7141: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
7142: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 7143: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 7144: '</ul>'.
7145: '</td>'.
1.359 raeburn 7146: '<td class="LC_left_item">';
7147: foreach my $item ('by','for') {
7148: $datatable .= '<fieldset style="display: inline-block;">'.
7149: '<legend>'.$ownertitles{$item}.'</legend>';
7150: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7151: foreach my $type (@{$types}) {
7152: my $checked;
7153: if ($ownerchg{$item}{$type}) {
7154: $checked = ' checked="checked"';
7155: }
7156: $datatable .= '<span class="LC_nobreak"><label>'.
7157: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
7158: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 7159: '</span> ';
1.359 raeburn 7160: }
7161: }
7162: my $checked;
7163: if ($ownerchg{$item}{'default'}) {
7164: $checked = ' checked="checked"';
7165: }
7166: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7167: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
7168: $othertitle.'</label></span></fieldset>';
7169: }
7170: $datatable .= '</td></tr>';
1.354 raeburn 7171: }
7172: return $datatable;
7173: }
7174:
1.373 raeburn 7175: sub print_wafproxy {
7176: my ($position,$dom,$settings,$rowtotal) = @_;
7177: my $css_class;
7178: my $itemcount = 0;
7179: my $datatable;
7180: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7181: my (%othercontrol,%otherdoms,%aliases,%values,$setdom);
1.374 raeburn 7182: my %lt = &wafproxy_titles();
1.373 raeburn 7183: foreach my $server (sort(keys(%servers))) {
7184: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
7185: my $serverdom;
7186: if ($serverhome ne $server) {
7187: $serverdom = &Apache::lonnet::host_domain($serverhome);
7188: $othercontrol{$server} = $serverdom;
7189: } else {
7190: $serverdom = &Apache::lonnet::host_domain($server);
7191: if ($serverdom ne $dom) {
7192: $othercontrol{$server} = $serverdom;
7193: } else {
7194: $setdom = 1;
7195: if (ref($settings) eq 'HASH') {
7196: %{$values{$dom}} = ();
7197: if (ref($settings->{'alias'}) eq 'HASH') {
7198: $aliases{$dom} = $settings->{'alias'};
7199: }
1.376 raeburn 7200: foreach my $item ('ipheader','trusted','vpnint','vpnext') {
1.373 raeburn 7201: $values{$dom}{$item} = $settings->{$item};
7202: }
7203: }
7204: }
7205: }
7206: }
7207: if (keys(%othercontrol)) {
7208: %otherdoms = reverse(%othercontrol);
7209: foreach my $domain (keys(%otherdoms)) {
7210: %{$values{$domain}} = ();
7211: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
7212: if (ref($config{$domain}) eq 'HASH') {
7213: if (ref($config{$domain}{'wafproxy'}) eq 'HASH') {
7214: $aliases{$domain} = $config{$domain}{'wafproxy'}{'alias'};
1.376 raeburn 7215: foreach my $item ('ipheader','trusted','vpnint','vpnext') {
1.373 raeburn 7216: $values{$domain}{$item} = $config{$domain}{'wafproxy'}{$item};
7217: }
7218: }
7219: }
7220: }
7221: }
7222: if ($position eq 'top') {
7223: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7224: foreach my $server (sort(keys(%servers))) {
7225: $itemcount ++;
7226: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7227: $datatable .= '<tr'.$css_class.'>'.
7228: '<td>'.&mt('Hostname').': '.
7229: &Apache::lonnet::hostname($server).'</td>'.
1.374 raeburn 7230: '<td class="LC_right_item">';
1.373 raeburn 7231: if ($othercontrol{$server}) {
7232: my $current;
7233: if (ref($aliases{$othercontrol{$server}}) eq 'HASH') {
7234: $current = $aliases{$othercontrol{$server}{$server}};
7235: }
7236: if ($current) {
7237: $datatable .= $current;
7238: } else {
7239: $datatable .= &mt('None in effect');
7240: }
7241: $datatable .= '<br /><span class="LC_small">('.
7242: &mt('WAF/Reverse Proxy controlled by domain: [_1]',
7243: '<b>'.$othercontrol{$server}.'</b>').'</span>';
7244: } else {
7245: my $current;
7246: if (ref($aliases{$dom}) eq 'HASH') {
7247: if ($aliases{$dom}{$server}) {
7248: $current = $aliases{$dom}{$server};
7249: }
7250: }
7251: $datatable .= '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.374 raeburn 7252: 'value="'.$current.'" size="30" />';
1.373 raeburn 7253: }
7254: $datatable .= '</td></tr>';
7255: }
7256: } else {
7257: if ($setdom) {
7258: $itemcount ++;
7259: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7260: $datatable .= '<tr'.$css_class.'>'.
1.374 raeburn 7261: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.373 raeburn 7262: &mt('Format for comma separated IP blocks').':<br />'.
7263: &mt('A.B.C.D/N or A.B.C.D - E.F.G.H').'</td>'.
7264: '<td class="LC_left_item"><table>';
1.376 raeburn 7265: foreach my $item ('ipheader','trusted','vpnint','vpnext') {
1.373 raeburn 7266: $datatable .= '<tr>'.
1.374 raeburn 7267: '<td valign="top">'.$lt{$item}.': ';
7268: if ($item eq 'ipheader') {
7269: $datatable .= '<input type="text" value="'.$values{$dom}{$item}.'" '.
7270: 'name="wafproxy_'.$item.'" />';
7271:
7272: } else {
7273: $datatable .= '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
7274: $values{$dom}{$item}.'</textarea>';
7275: }
7276: $datatable .= '</td></tr>';
1.373 raeburn 7277: }
7278: $datatable .= '</table></td></tr>';
7279: }
7280: if (keys(%otherdoms)) {
7281: foreach my $domain (sort(keys(%otherdoms))) {
7282: $itemcount ++;
7283: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7284: $datatable .= '<tr'.$css_class.'>'.
1.374 raeburn 7285: '<td class="LC_left_item">'.&mt('Domain: [_1]',$domain).'</td>'.
7286: '<td class="LC_left_item"><table>';
1.376 raeburn 7287: foreach my $item ('ipheader','trusted','vpnint','vpnext') {
1.373 raeburn 7288: my $showval = &mt('None');
7289: if ($values{$domain}{$item}) {
7290: $showval = $values{$domain}{$item};
7291: }
7292: $datatable .= '<tr>'.
7293: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
7294: }
7295: $datatable .= '</table></td></tr>';
7296: }
7297: }
7298: }
7299: $$rowtotal += $itemcount;
7300: return $datatable;
7301: }
7302:
7303: sub wafproxy_titles {
7304: return &Apache::lonlocal::texthash(
1.376 raeburn 7305: vpnint => 'Internal IP Range(s) for VPN sessions',
7306: vpnext => 'IP Range for backend WAF connections',
1.373 raeburn 7307: trusted => 'Trusted IP range(s)',
7308: ipheader => 'Custom request header',
7309: );
7310: }
7311:
1.137 raeburn 7312: sub print_usersessions {
7313: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 7314: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 7315: my (%by_ip,%by_location,@intdoms,@instdoms);
7316: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 7317:
7318: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 7319: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 7320: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 7321: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 7322: if ($position eq 'top') {
1.152 raeburn 7323: if (keys(%serverhomes) > 1) {
1.145 raeburn 7324: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 7325: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 7326: if (ref($settings) eq 'HASH') {
7327: if (ref($settings->{'offloadnow'}) eq 'HASH') {
7328: $curroffloadnow = $settings->{'offloadnow'};
7329: }
1.371 raeburn 7330: if (ref($settings->{'offloadoth'}) eq 'HASH') {
7331: $curroffloadoth = $settings->{'offloadoth'};
7332: }
1.261 raeburn 7333: }
1.371 raeburn 7334: my $other_insts = scalar(keys(%by_location));
7335: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
7336: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 7337: } else {
1.140 raeburn 7338: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 7339: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
7340: '</td></tr>';
1.140 raeburn 7341: }
1.137 raeburn 7342: } else {
1.279 raeburn 7343: my %titles = &usersession_titles();
7344: my ($prefix,@types);
7345: if ($position eq 'bottom') {
7346: $prefix = 'remote';
7347: @types = ('version','excludedomain','includedomain');
1.145 raeburn 7348: } else {
1.279 raeburn 7349: $prefix = 'hosted';
7350: @types = ('excludedomain','includedomain');
7351: }
7352: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
7353: }
7354: $$rowtotal += $itemcount;
7355: return $datatable;
7356: }
7357:
7358: sub rules_by_location {
7359: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
7360: my ($datatable,$itemcount,$css_class);
7361: if (keys(%{$by_location}) == 0) {
7362: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7363: $datatable = '<tr'.$css_class.'><td colspan="2">'.
7364: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
7365: '</td></tr>';
7366: $itemcount = 1;
7367: } else {
7368: $itemcount = 0;
7369: my $numinrow = 5;
7370: my (%current,%checkedon,%checkedoff);
7371: my @locations = sort(keys(%{$by_location}));
7372: foreach my $type (@{$types}) {
7373: $checkedon{$type} = '';
7374: $checkedoff{$type} = ' checked="checked"';
7375: }
7376: if (ref($settings) eq 'HASH') {
7377: if (ref($settings->{$prefix}) eq 'HASH') {
7378: foreach my $key (keys(%{$settings->{$prefix}})) {
7379: $current{$key} = $settings->{$prefix}{$key};
7380: if ($key eq 'version') {
7381: if ($current{$key} ne '') {
1.145 raeburn 7382: $checkedon{$key} = ' checked="checked"';
7383: $checkedoff{$key} = '';
7384: }
1.279 raeburn 7385: } elsif (ref($current{$key}) eq 'ARRAY') {
7386: $checkedon{$key} = ' checked="checked"';
7387: $checkedoff{$key} = '';
1.137 raeburn 7388: }
7389: }
7390: }
1.279 raeburn 7391: }
7392: foreach my $type (@{$types}) {
7393: next if ($type ne 'version' && !@locations);
7394: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7395: $datatable .= '<tr'.$css_class.'>
7396: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
7397: <span class="LC_nobreak">
7398: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
7399: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
7400: if ($type eq 'version') {
7401: my @lcversions = &Apache::lonnet::all_loncaparevs();
7402: my $selector = '<select name="'.$prefix.'_version">';
7403: foreach my $version (@lcversions) {
7404: my $selected = '';
7405: if ($current{'version'} eq $version) {
7406: $selected = ' selected="selected"';
1.145 raeburn 7407: }
1.279 raeburn 7408: $selector .= ' <option value="'.$version.'"'.
7409: $selected.'>'.$version.'</option>';
7410: }
7411: $selector .= '</select> ';
7412: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
7413: } else {
7414: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
7415: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
7416: ' />'.(' 'x2).
7417: '<input type="button" value="'.&mt('uncheck all').'" '.
7418: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
7419: "\n".
7420: '</div><div><table>';
7421: my $rem;
7422: for (my $i=0; $i<@locations; $i++) {
7423: my ($showloc,$value,$checkedtype);
7424: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
7425: my $ip = $by_location->{$locations[$i]}->[0];
7426: if (ref($by_ip->{$ip}) eq 'ARRAY') {
7427: $value = join(':',@{$by_ip->{$ip}});
7428: $showloc = join(', ',@{$by_ip->{$ip}});
7429: if (ref($current{$type}) eq 'ARRAY') {
7430: foreach my $loc (@{$by_ip->{$ip}}) {
7431: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
7432: $checkedtype = ' checked="checked"';
7433: last;
1.145 raeburn 7434: }
1.138 raeburn 7435: }
7436: }
7437: }
1.137 raeburn 7438: }
1.279 raeburn 7439: $rem = $i%($numinrow);
7440: if ($rem == 0) {
7441: if ($i > 0) {
7442: $datatable .= '</tr>';
7443: }
7444: $datatable .= '<tr>';
7445: }
7446: $datatable .= '<td class="LC_left_item">'.
7447: '<span class="LC_nobreak"><label>'.
7448: '<input type="checkbox" name="'.$prefix.'_'.$type.
7449: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
7450: '</label></span></td>';
7451: }
7452: $rem = @locations%($numinrow);
7453: my $colsleft = $numinrow - $rem;
7454: if ($colsleft > 1 ) {
7455: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7456: ' </td>';
7457: } elsif ($colsleft == 1) {
7458: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 7459: }
1.279 raeburn 7460: $datatable .= '</tr></table>';
1.137 raeburn 7461: }
1.279 raeburn 7462: $datatable .= '</td></tr>';
7463: $itemcount ++;
1.137 raeburn 7464: }
7465: }
1.279 raeburn 7466: return ($datatable,$itemcount);
1.137 raeburn 7467: }
7468:
1.275 raeburn 7469: sub print_ssl {
7470: my ($position,$dom,$settings,$rowtotal) = @_;
7471: my ($css_class,$datatable);
7472: my $itemcount = 1;
7473: if ($position eq 'top') {
1.281 raeburn 7474: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7475: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7476: my $same_institution;
7477: if ($intdom ne '') {
7478: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
7479: if (ref($internet_names) eq 'ARRAY') {
7480: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
7481: $same_institution = 1;
7482: }
7483: }
7484: }
1.275 raeburn 7485: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 7486: $datatable = '<tr'.$css_class.'><td colspan="2">';
7487: if ($same_institution) {
7488: my %domservers = &Apache::lonnet::get_servers($dom);
7489: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
7490: } else {
7491: $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.");
7492: }
7493: $datatable .= '</td></tr>';
1.275 raeburn 7494: $itemcount ++;
7495: } else {
7496: my %titles = &ssl_titles();
7497: my (%by_ip,%by_location,@intdoms,@instdoms);
7498: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7499: my @alldoms = &Apache::lonnet::all_domains();
7500: my %serverhomes = %Apache::lonnet::serverhomeIDs;
7501: my @domservers = &Apache::lonnet::get_servers($dom);
7502: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7503: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 7504: if (($position eq 'connto') || ($position eq 'connfrom')) {
7505: my $legacy;
7506: unless (ref($settings) eq 'HASH') {
7507: my $name;
7508: if ($position eq 'connto') {
7509: $name = 'loncAllowInsecure';
7510: } else {
7511: $name = 'londAllowInsecure';
7512: }
7513: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
7514: my @ids=&Apache::lonnet::current_machine_ids();
7515: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
7516: my %what = (
7517: $name => 1,
7518: );
7519: my ($result,$returnhash) =
7520: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
7521: if ($result eq 'ok') {
7522: if (ref($returnhash) eq 'HASH') {
7523: $legacy = $returnhash->{$name};
7524: }
7525: }
7526: } else {
7527: $legacy = $Apache::lonnet::perlvar{$name};
7528: }
7529: }
1.275 raeburn 7530: foreach my $type ('dom','intdom','other') {
7531: my %checked;
7532: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7533: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
7534: '<td class="LC_right_item">';
7535: my $skip;
7536: if ($type eq 'dom') {
7537: unless (keys(%servers) > 1) {
7538: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
7539: $skip = 1;
7540: }
7541: }
7542: if ($type eq 'intdom') {
7543: unless (@instdoms > 1) {
7544: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
7545: $skip = 1;
7546: }
7547: } elsif ($type eq 'other') {
7548: if (keys(%by_location) == 0) {
7549: $datatable .= &mt('Nothing to set here, as there are no other institutions');
7550: $skip = 1;
7551: }
7552: }
7553: unless ($skip) {
7554: $checked{'yes'} = ' checked="checked"';
7555: if (ref($settings) eq 'HASH') {
1.293 raeburn 7556: if (ref($settings->{$position}) eq 'HASH') {
7557: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 7558: $checked{$1} = $checked{'yes'};
7559: delete($checked{'yes'});
7560: }
7561: }
1.293 raeburn 7562: } else {
7563: if ($legacy == 0) {
7564: $checked{'req'} = $checked{'yes'};
7565: delete($checked{'yes'});
7566: }
1.275 raeburn 7567: }
7568: foreach my $option ('no','yes','req') {
7569: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 7570: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 7571: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7572: '</label></span>'.(' 'x2);
7573: }
7574: }
7575: $datatable .= '</td></tr>';
7576: $itemcount ++;
7577: }
7578: } else {
7579: my $prefix = 'replication';
7580: my @types = ('certreq','nocertreq');
1.279 raeburn 7581: if (keys(%by_location) == 0) {
7582: $datatable .= '<tr'.$css_class.'><td>'.
7583: &mt('Nothing to set here, as there are no other institutions').
7584: '</td></tr>';
7585: $itemcount ++;
1.275 raeburn 7586: } else {
1.279 raeburn 7587: ($datatable,$itemcount) =
7588: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 7589: }
7590: }
7591: }
7592: $$rowtotal += $itemcount;
7593: return $datatable;
7594: }
7595:
7596: sub ssl_titles {
7597: return &Apache::lonlocal::texthash (
7598: dom => 'LON-CAPA servers/VMs from same domain',
7599: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
7600: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 7601: connto => 'Connections to other servers',
7602: connfrom => 'Connections from other servers',
1.275 raeburn 7603: replication => 'Replicating content to other institutions',
7604: certreq => 'Client certificate required, but specific domains exempt',
7605: nocertreq => 'No client certificate required, except for specific domains',
7606: no => 'SSL not used',
7607: yes => 'SSL Optional (used if available)',
7608: req => 'SSL Required',
7609: );
1.279 raeburn 7610: }
7611:
7612: sub print_trust {
7613: my ($prefix,$dom,$settings,$rowtotal) = @_;
7614: my ($css_class,$datatable,%checked,%choices);
7615: my (%by_ip,%by_location,@intdoms,@instdoms);
7616: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7617: my $itemcount = 1;
7618: my %titles = &trust_titles();
7619: my @types = ('exc','inc');
7620: if ($prefix eq 'top') {
7621: $prefix = 'content';
7622: } elsif ($prefix eq 'bottom') {
7623: $prefix = 'msg';
7624: }
7625: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
7626: $$rowtotal += $itemcount;
7627: return $datatable;
7628: }
7629:
7630: sub trust_titles {
7631: return &Apache::lonlocal::texthash(
7632: content => "Access to this domain's content by others",
7633: shared => "Access to other domain's content by this domain",
7634: enroll => "Enrollment in this domain's courses by others",
7635: othcoau => "Co-author roles in this domain for others",
7636: coaurem => "Co-author roles for this domain's users elsewhere",
7637: domroles => "Domain roles in this domain assignable to others",
7638: catalog => "Course Catalog for this domain displayed elsewhere",
7639: reqcrs => "Requests for creation of courses in this domain by others",
7640: msg => "Users in other domains can send messages to this domain",
7641: exc => "Allow all, but exclude specific domains",
7642: inc => "Deny all, but include specific domains",
7643: );
1.275 raeburn 7644: }
7645:
1.138 raeburn 7646: sub build_location_hashes {
1.275 raeburn 7647: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 7648: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 7649: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 7650: my %iphost = &Apache::lonnet::get_iphost();
7651: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
7652: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
7653: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
7654: foreach my $id (@{$iphost{$primary_ip}}) {
7655: my $intdom = &Apache::lonnet::internet_dom($id);
7656: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
7657: push(@{$intdoms},$intdom);
7658: }
7659: }
7660: }
7661: foreach my $ip (keys(%iphost)) {
7662: if (ref($iphost{$ip}) eq 'ARRAY') {
7663: foreach my $id (@{$iphost{$ip}}) {
7664: my $location = &Apache::lonnet::internet_dom($id);
7665: if ($location) {
1.275 raeburn 7666: if (grep(/^\Q$location\E$/,@{$intdoms})) {
7667: my $dom = &Apache::lonnet::host_domain($id);
7668: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
7669: push(@{$instdoms},$dom);
7670: }
7671: next;
7672: }
1.138 raeburn 7673: if (ref($by_ip->{$ip}) eq 'ARRAY') {
7674: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
7675: push(@{$by_ip->{$ip}},$location);
7676: }
7677: } else {
7678: $by_ip->{$ip} = [$location];
7679: }
7680: }
7681: }
7682: }
7683: }
7684: foreach my $ip (sort(keys(%{$by_ip}))) {
7685: if (ref($by_ip->{$ip}) eq 'ARRAY') {
7686: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
7687: my $first = $by_ip->{$ip}->[0];
7688: if (ref($by_location->{$first}) eq 'ARRAY') {
7689: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
7690: push(@{$by_location->{$first}},$ip);
7691: }
7692: } else {
7693: $by_location->{$first} = [$ip];
7694: }
7695: }
7696: }
7697: return;
7698: }
7699:
1.145 raeburn 7700: sub current_offloads_to {
7701: my ($dom,$settings,$servers) = @_;
7702: my (%spareid,%otherdomconfigs);
1.152 raeburn 7703: if (ref($servers) eq 'HASH') {
1.145 raeburn 7704: foreach my $lonhost (sort(keys(%{$servers}))) {
7705: my $gotspares;
1.152 raeburn 7706: if (ref($settings) eq 'HASH') {
7707: if (ref($settings->{'spares'}) eq 'HASH') {
7708: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
7709: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
7710: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
7711: $gotspares = 1;
7712: }
1.145 raeburn 7713: }
7714: }
7715: unless ($gotspares) {
7716: my $gotspares;
7717: my $serverhomeID =
7718: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
7719: my $serverhomedom =
7720: &Apache::lonnet::host_domain($serverhomeID);
7721: if ($serverhomedom ne $dom) {
7722: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
7723: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
7724: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
7725: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
7726: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
7727: $gotspares = 1;
7728: }
7729: }
7730: } else {
7731: $otherdomconfigs{$serverhomedom} =
7732: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
7733: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
7734: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
7735: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
7736: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
7737: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
7738: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
7739: $gotspares = 1;
7740: }
7741: }
7742: }
7743: }
7744: }
7745: }
7746: }
7747: unless ($gotspares) {
7748: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
7749: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
7750: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
7751: } else {
7752: my $server_hostname = &Apache::lonnet::hostname($lonhost);
7753: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
7754: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
7755: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
7756: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
7757: } else {
1.150 raeburn 7758: my %what = (
7759: spareid => 1,
7760: );
7761: my ($result,$returnhash) =
7762: &Apache::lonnet::get_remote_globals($lonhost,\%what);
7763: if ($result eq 'ok') {
7764: if (ref($returnhash) eq 'HASH') {
7765: if (ref($returnhash->{'spareid'}) eq 'HASH') {
7766: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
7767: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
7768: }
7769: }
1.145 raeburn 7770: }
7771: }
7772: }
7773: }
7774: }
7775: }
7776: return %spareid;
7777: }
7778:
7779: sub spares_row {
1.371 raeburn 7780: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
7781: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 7782: my $css_class;
7783: my $numinrow = 4;
7784: my $itemcount = 1;
7785: my $datatable;
1.152 raeburn 7786: my %typetitles = &sparestype_titles();
7787: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 7788: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 7789: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
7790: my ($othercontrol,$serverdom);
7791: if ($serverhome ne $server) {
7792: $serverdom = &Apache::lonnet::host_domain($serverhome);
7793: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
7794: } else {
7795: $serverdom = &Apache::lonnet::host_domain($server);
7796: if ($serverdom ne $dom) {
7797: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
7798: }
7799: }
7800: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 7801: my ($checkednow,$checkedoth);
1.261 raeburn 7802: if (ref($curroffloadnow) eq 'HASH') {
7803: if ($curroffloadnow->{$server}) {
7804: $checkednow = ' checked="checked"';
7805: }
7806: }
1.371 raeburn 7807: if (ref($curroffloadoth) eq 'HASH') {
7808: if ($curroffloadoth->{$server}) {
7809: $checkedoth = ' checked="checked"';
7810: }
7811: }
1.145 raeburn 7812: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7813: $datatable .= '<tr'.$css_class.'>
7814: <td rowspan="2">
1.183 bisitz 7815: <span class="LC_nobreak">'.
7816: &mt('[_1] when busy, offloads to:'
1.261 raeburn 7817: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 7818: '<span class="LC_nobreak">'."\n".
1.261 raeburn 7819: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 7820: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 7821: "\n";
1.371 raeburn 7822: if ($other_insts) {
7823: $datatable .= '<br />'.
7824: '<span class="LC_nobreak">'."\n".
7825: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
7826: ' '.&mt('Switch other institutions on next access').'</label></span>'.
7827: "\n";
7828: }
1.145 raeburn 7829: my (%current,%canselect);
1.152 raeburn 7830: my @choices =
7831: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
7832: foreach my $type ('primary','default') {
7833: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 7834: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
7835: my @spares = @{$spareid->{$server}{$type}};
7836: if (@spares > 0) {
1.152 raeburn 7837: if ($othercontrol) {
7838: $current{$type} = join(', ',@spares);
7839: } else {
7840: $current{$type} .= '<table>';
7841: my $numspares = scalar(@spares);
7842: for (my $i=0; $i<@spares; $i++) {
7843: my $rem = $i%($numinrow);
7844: if ($rem == 0) {
7845: if ($i > 0) {
7846: $current{$type} .= '</tr>';
7847: }
7848: $current{$type} .= '<tr>';
1.145 raeburn 7849: }
1.152 raeburn 7850: $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'".');" /> '.
7851: $spareid->{$server}{$type}[$i].
7852: '</label></td>'."\n";
7853: }
7854: my $rem = @spares%($numinrow);
7855: my $colsleft = $numinrow - $rem;
7856: if ($colsleft > 1 ) {
7857: $current{$type} .= '<td colspan="'.$colsleft.
7858: '" class="LC_left_item">'.
7859: ' </td>';
7860: } elsif ($colsleft == 1) {
7861: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 7862: }
1.152 raeburn 7863: $current{$type} .= '</tr></table>';
1.150 raeburn 7864: }
1.145 raeburn 7865: }
7866: }
7867: if ($current{$type} eq '') {
7868: $current{$type} = &mt('None specified');
7869: }
1.152 raeburn 7870: if ($othercontrol) {
7871: if ($type eq 'primary') {
7872: $canselect{$type} = $othercontrol;
7873: }
7874: } else {
7875: $canselect{$type} =
7876: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
7877: '<select name="newspare_'.$type.'_'.$server.'" '.
7878: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
7879: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
7880: if (@choices > 0) {
7881: foreach my $lonhost (@choices) {
7882: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
7883: }
7884: }
7885: $canselect{$type} .= '</select>'."\n";
7886: }
7887: } else {
7888: $current{$type} = &mt('Could not be determined');
7889: if ($type eq 'primary') {
7890: $canselect{$type} = $othercontrol;
7891: }
1.145 raeburn 7892: }
1.152 raeburn 7893: if ($type eq 'default') {
7894: $datatable .= '<tr'.$css_class.'>';
7895: }
7896: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
7897: '<td>'.$current{$type}.'</td>'."\n".
7898: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 7899: }
7900: $itemcount ++;
7901: }
7902: }
7903: $$rowtotal += $itemcount;
7904: return $datatable;
7905: }
7906:
1.152 raeburn 7907: sub possible_newspares {
7908: my ($server,$currspares,$serverhomes,$altids) = @_;
7909: my $serverhostname = &Apache::lonnet::hostname($server);
7910: my %excluded;
7911: if ($serverhostname ne '') {
7912: %excluded = (
7913: $serverhostname => 1,
7914: );
7915: }
7916: if (ref($currspares) eq 'HASH') {
7917: foreach my $type (keys(%{$currspares})) {
7918: if (ref($currspares->{$type}) eq 'ARRAY') {
7919: if (@{$currspares->{$type}} > 0) {
7920: foreach my $curr (@{$currspares->{$type}}) {
7921: my $hostname = &Apache::lonnet::hostname($curr);
7922: $excluded{$hostname} = 1;
7923: }
7924: }
7925: }
7926: }
7927: }
7928: my @choices;
7929: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
7930: if (keys(%{$serverhomes}) > 1) {
7931: foreach my $name (sort(keys(%{$serverhomes}))) {
7932: unless ($excluded{$name}) {
7933: if (exists($altids->{$serverhomes->{$name}})) {
7934: push(@choices,$altids->{$serverhomes->{$name}});
7935: } else {
7936: push(@choices,$serverhomes->{$name});
1.145 raeburn 7937: }
7938: }
7939: }
7940: }
7941: }
1.152 raeburn 7942: return sort(@choices);
1.145 raeburn 7943: }
7944:
1.150 raeburn 7945: sub print_loadbalancing {
7946: my ($dom,$settings,$rowtotal) = @_;
7947: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7948: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7949: my $numinrow = 1;
7950: my $datatable;
7951: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 7952: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 7953: if (ref($settings) eq 'HASH') {
7954: %existing = %{$settings};
7955: }
7956: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
7957: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 7958: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 7959: } else {
7960: return;
7961: }
7962: my ($othertitle,$usertypes,$types) =
7963: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 7964: my $rownum = 8;
1.150 raeburn 7965: if (ref($types) eq 'ARRAY') {
7966: $rownum += scalar(@{$types});
7967: }
1.171 raeburn 7968: my @css_class = ('LC_odd_row','LC_even_row');
7969: my $balnum = 0;
7970: my $islast;
7971: my (@toshow,$disabledtext);
7972: if (keys(%currbalancer) > 0) {
7973: @toshow = sort(keys(%currbalancer));
7974: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
7975: push(@toshow,'');
7976: }
7977: } else {
7978: @toshow = ('');
7979: $disabledtext = &mt('No existing load balancer');
7980: }
7981: foreach my $lonhost (@toshow) {
7982: if ($balnum == scalar(@toshow)-1) {
7983: $islast = 1;
7984: } else {
7985: $islast = 0;
7986: }
7987: my $cssidx = $balnum%2;
7988: my $targets_div_style = 'display: none';
7989: my $disabled_div_style = 'display: block';
7990: my $homedom_div_style = 'display: none';
7991: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 7992: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 7993: '<p>';
7994: if ($lonhost eq '') {
1.210 raeburn 7995: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 7996: if (keys(%currbalancer) > 0) {
7997: $datatable .= &mt('Add balancer:');
7998: } else {
7999: $datatable .= &mt('Enable balancer:');
8000: }
8001: $datatable .= ' '.
8002: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
8003: ' id="loadbalancing_lonhost_'.$balnum.'"'.
8004: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
8005: '<option value="" selected="selected">'.&mt('None').
8006: '</option>'."\n";
8007: foreach my $server (sort(keys(%servers))) {
8008: next if ($currbalancer{$server});
8009: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
8010: }
1.210 raeburn 8011: $datatable .=
1.171 raeburn 8012: '</select>'."\n".
8013: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
8014: } else {
8015: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
8016: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
8017: &mt('Stop balancing').'</label>'.
8018: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
8019: $targets_div_style = 'display: block';
8020: $disabled_div_style = 'display: none';
8021: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
8022: $homedom_div_style = 'display: block';
8023: }
8024: }
1.306 raeburn 8025: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 8026: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
8027: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
8028: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
8029: my ($numspares,@spares) = &count_servers($lonhost,%servers);
8030: my @sparestypes = ('primary','default');
8031: my %typetitles = &sparestype_titles();
1.284 raeburn 8032: my %hostherechecked = (
8033: no => ' checked="checked"',
8034: );
1.342 raeburn 8035: my %balcookiechecked = (
8036: no => ' checked="checked"',
8037: );
1.171 raeburn 8038: foreach my $sparetype (@sparestypes) {
8039: my $targettable;
8040: for (my $i=0; $i<$numspares; $i++) {
8041: my $checked;
8042: if (ref($currtargets{$lonhost}) eq 'HASH') {
8043: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
8044: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
8045: $checked = ' checked="checked"';
8046: }
8047: }
8048: }
8049: my ($chkboxval,$disabled);
8050: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
8051: $chkboxval = $spares[$i];
8052: }
8053: if (exists($currbalancer{$spares[$i]})) {
8054: $disabled = ' disabled="disabled"';
8055: }
1.210 raeburn 8056: $targettable .=
1.253 raeburn 8057: '<td><span class="LC_nobreak"><label>'.
8058: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 8059: $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 8060: '</span></label></span></td>';
1.171 raeburn 8061: my $rem = $i%($numinrow);
8062: if ($rem == 0) {
8063: if (($i > 0) && ($i < $numspares-1)) {
8064: $targettable .= '</tr>';
8065: }
8066: if ($i < $numspares-1) {
8067: $targettable .= '<tr>';
1.150 raeburn 8068: }
8069: }
8070: }
1.171 raeburn 8071: if ($targettable ne '') {
8072: my $rem = $numspares%($numinrow);
8073: my $colsleft = $numinrow - $rem;
8074: if ($colsleft > 1 ) {
8075: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8076: ' </td>';
8077: } elsif ($colsleft == 1) {
8078: $targettable .= '<td class="LC_left_item"> </td>';
8079: }
8080: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
8081: '<table><tr>'.$targettable.'</tr></table><br />';
8082: }
1.284 raeburn 8083: $hostherechecked{$sparetype} = '';
8084: if (ref($currtargets{$lonhost}) eq 'HASH') {
8085: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
8086: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
8087: $hostherechecked{$sparetype} = ' checked="checked"';
8088: $hostherechecked{'no'} = '';
8089: }
8090: }
8091: }
8092: }
1.342 raeburn 8093: if ($currcookies{$lonhost}) {
8094: %balcookiechecked = (
8095: yes => ' checked="checked"',
8096: );
8097: }
1.284 raeburn 8098: $datatable .= &mt('Hosting on balancer itself').'<br />'.
8099: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
8100: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
8101: foreach my $sparetype (@sparestypes) {
8102: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
8103: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
8104: '</i></label><br />';
1.171 raeburn 8105: }
1.342 raeburn 8106: $datatable .= &mt('Use balancer cookie').'<br />'.
8107: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
8108: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
8109: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
8110: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
8111: '</div></td></tr>'.
1.171 raeburn 8112: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
8113: $othertitle,$usertypes,$types,\%servers,
8114: \%currbalancer,$lonhost,
8115: $targets_div_style,$homedom_div_style,
8116: $css_class[$cssidx],$balnum,$islast);
8117: $$rowtotal += $rownum;
8118: $balnum ++;
8119: }
8120: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
8121: return $datatable;
8122: }
8123:
8124: sub get_loadbalancers_config {
1.342 raeburn 8125: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 8126: return unless ((ref($servers) eq 'HASH') &&
8127: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 8128: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
8129: (ref($currcookies) eq 'HASH'));
1.171 raeburn 8130: if (keys(%{$existing}) > 0) {
8131: my $oldlonhost;
8132: foreach my $key (sort(keys(%{$existing}))) {
8133: if ($key eq 'lonhost') {
8134: $oldlonhost = $existing->{'lonhost'};
8135: $currbalancer->{$oldlonhost} = 1;
8136: } elsif ($key eq 'targets') {
8137: if ($oldlonhost) {
8138: $currtargets->{$oldlonhost} = $existing->{'targets'};
8139: }
8140: } elsif ($key eq 'rules') {
8141: if ($oldlonhost) {
8142: $currrules->{$oldlonhost} = $existing->{'rules'};
8143: }
8144: } elsif (ref($existing->{$key}) eq 'HASH') {
8145: $currbalancer->{$key} = 1;
8146: $currtargets->{$key} = $existing->{$key}{'targets'};
8147: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 8148: if ($existing->{$key}{'cookie'}) {
8149: $currcookies->{$key} = 1;
8150: }
1.150 raeburn 8151: }
8152: }
1.171 raeburn 8153: } else {
8154: my ($balancerref,$targetsref) =
8155: &Apache::lonnet::get_lonbalancer_config($servers);
8156: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
8157: foreach my $server (sort(keys(%{$balancerref}))) {
8158: $currbalancer->{$server} = 1;
8159: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 8160: }
8161: }
8162: }
1.171 raeburn 8163: return;
1.150 raeburn 8164: }
8165:
8166: sub loadbalancing_rules {
8167: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 8168: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
8169: $css_class,$balnum,$islast) = @_;
1.150 raeburn 8170: my $output;
1.171 raeburn 8171: my $num = 0;
1.210 raeburn 8172: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 8173: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8174: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8175: foreach my $type (@{$alltypes}) {
1.171 raeburn 8176: $num ++;
1.150 raeburn 8177: my $current;
8178: if (ref($currrules) eq 'HASH') {
8179: $current = $currrules->{$type};
8180: }
1.253 raeburn 8181: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 8182: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 8183: $current = '';
8184: }
8185: }
8186: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 8187: $servers,$currbalancer,$lonhost,$dom,
8188: $targets_div_style,$homedom_div_style,
8189: $css_class,$balnum,$num,$islast);
1.150 raeburn 8190: }
8191: }
8192: return $output;
8193: }
8194:
8195: sub loadbalancing_titles {
8196: my ($dom,$intdom,$usertypes,$types) = @_;
8197: my %othertypes = (
8198: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
8199: '_LC_author' => &mt('Users from [_1] with author role',$dom),
8200: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
8201: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 8202: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
8203: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 8204: );
1.209 raeburn 8205: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 8206: my @available;
1.150 raeburn 8207: if (ref($types) eq 'ARRAY') {
1.302 raeburn 8208: @available = @{$types};
1.150 raeburn 8209: }
1.302 raeburn 8210: unless (grep(/^default$/,@available)) {
8211: push(@available,'default');
8212: }
8213: unshift(@alltypes,@available);
1.150 raeburn 8214: my %titles;
8215: foreach my $type (@alltypes) {
8216: if ($type =~ /^_LC_/) {
8217: $titles{$type} = $othertypes{$type};
8218: } elsif ($type eq 'default') {
8219: $titles{$type} = &mt('All users from [_1]',$dom);
8220: if (ref($types) eq 'ARRAY') {
8221: if (@{$types} > 0) {
8222: $titles{$type} = &mt('Other users from [_1]',$dom);
8223: }
8224: }
8225: } elsif (ref($usertypes) eq 'HASH') {
8226: $titles{$type} = $usertypes->{$type};
8227: }
8228: }
8229: return (\@alltypes,\%othertypes,\%titles);
8230: }
8231:
8232: sub loadbalance_rule_row {
1.171 raeburn 8233: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
8234: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 8235: my @rulenames;
1.150 raeburn 8236: my %ruletitles = &offloadtype_text();
1.209 raeburn 8237: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 8238: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 8239: } else {
1.209 raeburn 8240: @rulenames = ('default','homeserver');
8241: if ($type eq '_LC_external') {
8242: push(@rulenames,'externalbalancer');
8243: } else {
8244: push(@rulenames,'specific');
8245: }
8246: push(@rulenames,'none');
1.150 raeburn 8247: }
8248: my $style = $targets_div_style;
1.253 raeburn 8249: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 8250: $style = $homedom_div_style;
8251: }
1.171 raeburn 8252: my $space;
8253: if ($islast && $num == 1) {
1.317 raeburn 8254: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 8255: }
1.210 raeburn 8256: my $output =
1.306 raeburn 8257: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 8258: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
8259: '<td valaign="top">'.$space.
8260: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 8261: for (my $i=0; $i<@rulenames; $i++) {
8262: my $rule = $rulenames[$i];
8263: my ($checked,$extra);
8264: if ($rulenames[$i] eq 'default') {
8265: $rule = '';
8266: }
8267: if ($rulenames[$i] eq 'specific') {
8268: if (ref($servers) eq 'HASH') {
8269: my $default;
8270: if (($current ne '') && (exists($servers->{$current}))) {
8271: $checked = ' checked="checked"';
8272: }
8273: unless ($checked) {
8274: $default = ' selected="selected"';
8275: }
1.210 raeburn 8276: $extra =
1.171 raeburn 8277: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
8278: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
8279: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
8280: '<option value=""'.$default.'></option>'."\n";
8281: foreach my $server (sort(keys(%{$servers}))) {
8282: if (ref($currbalancer) eq 'HASH') {
8283: next if (exists($currbalancer->{$server}));
8284: }
1.150 raeburn 8285: my $selected;
1.171 raeburn 8286: if ($server eq $current) {
1.150 raeburn 8287: $selected = ' selected="selected"';
8288: }
1.171 raeburn 8289: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 8290: }
8291: $extra .= '</select>';
8292: }
8293: } elsif ($rule eq $current) {
8294: $checked = ' checked="checked"';
8295: }
8296: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 8297: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
8298: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
8299: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 8300: ')"'.$checked.' /> ';
8301: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
8302: $output .= $ruletitles{'particular'};
8303: } else {
8304: $output .= $ruletitles{$rulenames[$i]};
8305: }
8306: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 8307: }
8308: $output .= '</div></td></tr>'."\n";
8309: return $output;
8310: }
8311:
8312: sub offloadtype_text {
8313: my %ruletitles = &Apache::lonlocal::texthash (
8314: 'default' => 'Offloads to default destinations',
8315: 'homeserver' => "Offloads to user's home server",
8316: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
8317: 'specific' => 'Offloads to specific server',
1.161 raeburn 8318: 'none' => 'No offload',
1.209 raeburn 8319: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
8320: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 8321: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 8322: );
8323: return %ruletitles;
8324: }
8325:
8326: sub sparestype_titles {
8327: my %typestitles = &Apache::lonlocal::texthash (
8328: 'primary' => 'primary',
8329: 'default' => 'default',
8330: );
8331: return %typestitles;
8332: }
8333:
1.28 raeburn 8334: sub contact_titles {
8335: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 8336: 'supportemail' => 'Support E-mail address',
8337: 'adminemail' => 'Default Server Admin E-mail address',
8338: 'errormail' => 'Error reports to be e-mailed to',
8339: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 8340: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
8341: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 8342: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
8343: 'requestsmail' => 'E-mail from course requests requiring approval',
8344: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 8345: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 8346: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 8347: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
8348: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 8349: 'errorweights' => 'Weights used to compute error count',
8350: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 8351: );
8352: my %short_titles = &Apache::lonlocal::texthash (
8353: adminemail => 'Admin E-mail address',
8354: supportemail => 'Support E-mail',
8355: );
8356: return (\%titles,\%short_titles);
8357: }
8358:
1.286 raeburn 8359: sub helpform_fields {
8360: my %titles = &Apache::lonlocal::texthash (
8361: 'username' => 'Name',
8362: 'user' => 'Username/domain',
8363: 'phone' => 'Phone',
8364: 'cc' => 'Cc e-mail',
8365: 'course' => 'Course Details',
8366: 'section' => 'Sections',
1.289 raeburn 8367: 'screenshot' => 'File upload',
1.286 raeburn 8368: );
8369: my @fields = ('username','phone','user','course','section','cc','screenshot');
8370: my %possoptions = (
8371: username => ['yes','no','req'],
1.289 raeburn 8372: phone => ['yes','no','req'],
1.286 raeburn 8373: user => ['yes','no'],
1.289 raeburn 8374: cc => ['yes','no'],
1.286 raeburn 8375: course => ['yes','no'],
8376: section => ['yes','no'],
8377: screenshot => ['yes','no'],
8378: );
8379: my %fieldoptions = &Apache::lonlocal::texthash (
8380: 'yes' => 'Optional',
8381: 'req' => 'Required',
8382: 'no' => "Not shown",
8383: );
8384: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
8385: }
8386:
1.72 raeburn 8387: sub tool_titles {
8388: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 8389: aboutme => 'Personal web page',
1.86 raeburn 8390: blog => 'Blog',
1.162 raeburn 8391: webdav => 'WebDAV',
1.86 raeburn 8392: portfolio => 'Portfolio',
1.88 bisitz 8393: official => 'Official courses (with institutional codes)',
8394: unofficial => 'Unofficial courses',
1.98 raeburn 8395: community => 'Communities',
1.216 raeburn 8396: textbook => 'Textbook courses',
1.271 raeburn 8397: placement => 'Placement tests',
1.86 raeburn 8398: );
1.72 raeburn 8399: return %titles;
8400: }
8401:
1.101 raeburn 8402: sub courserequest_titles {
8403: my %titles = &Apache::lonlocal::texthash (
8404: official => 'Official',
8405: unofficial => 'Unofficial',
8406: community => 'Communities',
1.216 raeburn 8407: textbook => 'Textbook',
1.271 raeburn 8408: placement => 'Placement tests',
1.325 raeburn 8409: lti => 'LTI Provider',
1.101 raeburn 8410: norequest => 'Not allowed',
1.325 raeburn 8411: approval => 'Approval by DC',
1.101 raeburn 8412: validate => 'With validation',
8413: autolimit => 'Numerical limit',
1.103 raeburn 8414: unlimited => '(blank for unlimited)',
1.101 raeburn 8415: );
8416: return %titles;
8417: }
8418:
1.163 raeburn 8419: sub authorrequest_titles {
8420: my %titles = &Apache::lonlocal::texthash (
8421: norequest => 'Not allowed',
8422: approval => 'Approval by Dom. Coord.',
8423: automatic => 'Automatic approval',
8424: );
8425: return %titles;
1.210 raeburn 8426: }
1.163 raeburn 8427:
1.101 raeburn 8428: sub courserequest_conditions {
8429: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 8430: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 8431: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 8432: );
8433: return %conditions;
8434: }
8435:
8436:
1.27 raeburn 8437: sub print_usercreation {
1.30 raeburn 8438: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 8439: my $numinrow = 4;
1.28 raeburn 8440: my $datatable;
8441: if ($position eq 'top') {
1.30 raeburn 8442: $$rowtotal ++;
1.34 raeburn 8443: my $rowcount = 0;
1.32 raeburn 8444: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 8445: if (ref($rules) eq 'HASH') {
8446: if (keys(%{$rules}) > 0) {
1.32 raeburn 8447: $datatable .= &user_formats_row('username',$settings,$rules,
8448: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 8449: $$rowtotal ++;
1.32 raeburn 8450: $rowcount ++;
8451: }
8452: }
8453: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
8454: if (ref($idrules) eq 'HASH') {
8455: if (keys(%{$idrules}) > 0) {
8456: $datatable .= &user_formats_row('id',$settings,$idrules,
8457: $idruleorder,$numinrow,$rowcount);
8458: $$rowtotal ++;
8459: $rowcount ++;
1.28 raeburn 8460: }
8461: }
1.39 raeburn 8462: if ($rowcount == 0) {
8463: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
8464: $$rowtotal ++;
8465: $rowcount ++;
8466: }
1.34 raeburn 8467: } elsif ($position eq 'middle') {
1.224 raeburn 8468: my @creators = ('author','course','requestcrs');
1.37 raeburn 8469: my ($rules,$ruleorder) =
8470: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 8471: my %lt = &usercreation_types();
8472: my %checked;
8473: if (ref($settings) eq 'HASH') {
8474: if (ref($settings->{'cancreate'}) eq 'HASH') {
8475: foreach my $item (@creators) {
8476: $checked{$item} = $settings->{'cancreate'}{$item};
8477: }
8478: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
8479: foreach my $item (@creators) {
8480: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
8481: $checked{$item} = 'none';
8482: }
8483: }
8484: }
8485: }
8486: my $rownum = 0;
8487: foreach my $item (@creators) {
8488: $rownum ++;
1.224 raeburn 8489: if ($checked{$item} eq '') {
8490: $checked{$item} = 'any';
1.34 raeburn 8491: }
8492: my $css_class;
8493: if ($rownum%2) {
8494: $css_class = '';
8495: } else {
8496: $css_class = ' class="LC_odd_row" ';
8497: }
8498: $datatable .= '<tr'.$css_class.'>'.
8499: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 8500: '</span></td><td style="text-align: right">';
1.224 raeburn 8501: my @options = ('any');
8502: if (ref($rules) eq 'HASH') {
8503: if (keys(%{$rules}) > 0) {
8504: push(@options,('official','unofficial'));
1.37 raeburn 8505: }
8506: }
1.224 raeburn 8507: push(@options,'none');
1.37 raeburn 8508: foreach my $option (@options) {
1.50 raeburn 8509: my $type = 'radio';
1.34 raeburn 8510: my $check = ' ';
1.224 raeburn 8511: if ($checked{$item} eq $option) {
8512: $check = ' checked="checked" ';
1.34 raeburn 8513: }
8514: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 8515: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 8516: $item.'" value="'.$option.'"'.$check.'/> '.
8517: $lt{$option}.'</label> </span>';
8518: }
8519: $datatable .= '</td></tr>';
8520: }
1.28 raeburn 8521: } else {
8522: my @contexts = ('author','course','domain');
1.325 raeburn 8523: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 8524: my %checked;
8525: if (ref($settings) eq 'HASH') {
8526: if (ref($settings->{'authtypes'}) eq 'HASH') {
8527: foreach my $item (@contexts) {
8528: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
8529: foreach my $auth (@authtypes) {
8530: if ($settings->{'authtypes'}{$item}{$auth}) {
8531: $checked{$item}{$auth} = ' checked="checked" ';
8532: }
8533: }
8534: }
8535: }
1.27 raeburn 8536: }
1.35 raeburn 8537: } else {
8538: foreach my $item (@contexts) {
1.36 raeburn 8539: foreach my $auth (@authtypes) {
1.35 raeburn 8540: $checked{$item}{$auth} = ' checked="checked" ';
8541: }
8542: }
1.27 raeburn 8543: }
1.28 raeburn 8544: my %title = &context_names();
8545: my %authname = &authtype_names();
8546: my $rownum = 0;
8547: my $css_class;
8548: foreach my $item (@contexts) {
8549: if ($rownum%2) {
8550: $css_class = '';
8551: } else {
8552: $css_class = ' class="LC_odd_row" ';
8553: }
1.30 raeburn 8554: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 8555: '<td>'.$title{$item}.
8556: '</td><td class="LC_left_item">'.
8557: '<span class="LC_nobreak">';
8558: foreach my $auth (@authtypes) {
8559: $datatable .= '<label>'.
8560: '<input type="checkbox" name="'.$item.'_auth" '.
8561: $checked{$item}{$auth}.' value="'.$auth.'" />'.
8562: $authname{$auth}.'</label> ';
8563: }
8564: $datatable .= '</span></td></tr>';
8565: $rownum ++;
1.27 raeburn 8566: }
1.30 raeburn 8567: $$rowtotal += $rownum;
1.27 raeburn 8568: }
8569: return $datatable;
8570: }
8571:
1.224 raeburn 8572: sub print_selfcreation {
8573: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 8574: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
8575: $emaildomain,$datatable);
1.224 raeburn 8576: if (ref($settings) eq 'HASH') {
8577: if (ref($settings->{'cancreate'}) eq 'HASH') {
8578: $createsettings = $settings->{'cancreate'};
1.236 raeburn 8579: if (ref($createsettings) eq 'HASH') {
8580: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
8581: @selfcreate = @{$createsettings->{'selfcreate'}};
8582: } elsif ($createsettings->{'selfcreate'} ne '') {
8583: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
8584: @selfcreate = ('email','login','sso');
8585: } elsif ($createsettings->{'selfcreate'} ne 'none') {
8586: @selfcreate = ($createsettings->{'selfcreate'});
8587: }
8588: }
8589: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
8590: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 8591: }
1.305 raeburn 8592: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
8593: $emailoptions = $createsettings->{'emailoptions'};
8594: }
1.303 raeburn 8595: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
8596: $emailverified = $createsettings->{'emailverified'};
8597: }
8598: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
8599: $emaildomain = $createsettings->{'emaildomain'};
8600: }
1.224 raeburn 8601: }
8602: }
8603: }
8604: my %radiohash;
8605: my $numinrow = 4;
8606: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 8607: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 8608: if ($position eq 'top') {
8609: my %choices = &Apache::lonlocal::texthash (
8610: cancreate_login => 'Institutional Login',
8611: cancreate_sso => 'Institutional Single Sign On',
8612: );
8613: my @toggles = sort(keys(%choices));
8614: my %defaultchecked = (
8615: 'cancreate_login' => 'off',
8616: 'cancreate_sso' => 'off',
8617: );
1.228 raeburn 8618: my ($onclick,$itemcount);
1.224 raeburn 8619: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
8620: \%choices,$itemcount,$onclick);
1.228 raeburn 8621: $$rowtotal += $itemcount;
8622:
1.224 raeburn 8623: if (ref($usertypes) eq 'HASH') {
8624: if (keys(%{$usertypes}) > 0) {
8625: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
8626: $dom,$numinrow,$othertitle,
1.305 raeburn 8627: 'statustocreate',$rowtotal);
1.224 raeburn 8628: $$rowtotal ++;
8629: }
8630: }
1.240 raeburn 8631: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
8632: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8633: $fieldtitles{'inststatus'} = &mt('Institutional status');
8634: my $rem;
8635: my $numperrow = 2;
8636: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
8637: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 8638: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 8639: '<td class="LC_left_item">'."\n".
1.334 raeburn 8640: '<table>'."\n";
1.240 raeburn 8641: for (my $i=0; $i<@fields; $i++) {
8642: $rem = $i%($numperrow);
8643: if ($rem == 0) {
8644: if ($i > 0) {
8645: $datatable .= '</tr>';
8646: }
8647: $datatable .= '<tr>';
8648: }
8649: my $currval;
1.248 raeburn 8650: if (ref($createsettings) eq 'HASH') {
8651: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
8652: $currval = $createsettings->{'shibenv'}{$fields[$i]};
8653: }
1.240 raeburn 8654: }
8655: $datatable .= '<td class="LC_left_item">'.
8656: '<span class="LC_nobreak">'.
8657: '<input type="text" name="shibenv_'.$fields[$i].'" '.
8658: 'value="'.$currval.'" size="10" /> '.
8659: $fieldtitles{$fields[$i]}.'</span></td>';
8660: }
8661: my $colsleft = $numperrow - $rem;
8662: if ($colsleft > 1 ) {
8663: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8664: ' </td>';
8665: } elsif ($colsleft == 1) {
8666: $datatable .= '<td class="LC_left_item"> </td>';
8667: }
8668: $datatable .= '</tr></table></td></tr>';
8669: $$rowtotal ++;
1.224 raeburn 8670: } elsif ($position eq 'middle') {
8671: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 8672: my @posstypes;
1.224 raeburn 8673: if (ref($types) eq 'ARRAY') {
1.302 raeburn 8674: @posstypes = @{$types};
8675: }
8676: unless (grep(/^default$/,@posstypes)) {
8677: push(@posstypes,'default');
8678: }
8679: my %usertypeshash;
8680: if (ref($usertypes) eq 'HASH') {
8681: %usertypeshash = %{$usertypes};
8682: }
8683: $usertypeshash{'default'} = $othertitle;
8684: foreach my $status (@posstypes) {
8685: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
8686: $numinrow,$$rowtotal,\%usertypeshash);
8687: $$rowtotal ++;
1.224 raeburn 8688: }
8689: } else {
1.236 raeburn 8690: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 8691: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 8692: );
8693: my @toggles = sort(keys(%choices));
8694: my %defaultchecked = (
8695: 'cancreate_email' => 'off',
8696: );
1.305 raeburn 8697: my $customclass = 'LC_selfcreate_email';
8698: my $classprefix = 'LC_canmodify_emailusername_';
8699: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 8700: my $display = 'none';
1.305 raeburn 8701: my $rowstyle = 'display:none';
1.236 raeburn 8702: if (grep(/^\Qemail\E$/,@selfcreate)) {
8703: $display = 'block';
1.305 raeburn 8704: $rowstyle = 'display:table-row';
1.236 raeburn 8705: }
1.305 raeburn 8706: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
8707: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
8708: \%choices,$$rowtotal,$onclick);
8709: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
8710: $rowstyle);
8711: $$rowtotal ++;
8712: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
8713: $rowstyle);
8714: $$rowtotal ++;
8715: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 8716: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 8717: my ($emailrules,$emailruleorder) =
8718: &Apache::lonnet::inst_userrules($dom,'email');
8719: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8720: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8721: if (ref($types) eq 'ARRAY') {
8722: @posstypes = @{$types};
8723: }
8724: if (@posstypes) {
8725: unless (grep(/^default$/,@posstypes)) {
8726: push(@posstypes,'default');
1.302 raeburn 8727: }
8728: if (ref($usertypes) eq 'HASH') {
8729: %usertypeshash = %{$usertypes};
8730: }
1.305 raeburn 8731: my $currassign;
8732: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
8733: $currassign = {
8734: selfassign => $domdefaults{'inststatusguest'},
8735: };
8736: @ordered = @{$domdefaults{'inststatusguest'}};
8737: } else {
8738: $currassign = { selfassign => [] };
8739: }
8740: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
8741: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
8742: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
8743: $numinrow,$othertitle,'selfassign',
8744: $rowtotal,$onclicktypes,$customclass,
8745: $rowstyle);
8746: $$rowtotal ++;
1.302 raeburn 8747: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 8748: foreach my $status (@posstypes) {
8749: my $css_class;
8750: if ($$rowtotal%2) {
8751: $css_class = 'LC_odd_row ';
8752: }
8753: $css_class .= $customclass;
8754: my $rowid = $optionsprefix.$status;
8755: my $hidden = 1;
8756: my $currstyle = 'display:none';
8757: if (grep(/^\Q$status\E$/,@ordered)) {
8758: $currstyle = $rowstyle;
8759: $hidden = 0;
8760: }
8761: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
8762: $emailrules,$emailruleorder,$settings,$status,$rowid,
8763: $usertypeshash{$status},$css_class,$currstyle,$intdom);
8764: unless ($hidden) {
8765: $$rowtotal ++;
8766: }
1.224 raeburn 8767: }
1.302 raeburn 8768: } else {
1.305 raeburn 8769: my $css_class;
8770: if ($$rowtotal%2) {
8771: $css_class = 'LC_odd_row ';
8772: }
8773: $css_class .= $customclass;
1.302 raeburn 8774: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 8775: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
8776: $emailrules,$emailruleorder,$settings,'default','',
8777: $othertitle,$css_class,$rowstyle,$intdom);
8778: $$rowtotal ++;
1.224 raeburn 8779: }
8780: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 8781: $numinrow = 1;
1.305 raeburn 8782: if (@posstypes) {
8783: foreach my $status (@posstypes) {
8784: my $rowid = $classprefix.$status;
8785: my $datarowstyle = 'display:none';
8786: if (grep(/^\Q$status\E$/,@ordered)) {
8787: $datarowstyle = $rowstyle;
8788: }
8789: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
8790: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
8791: $infotitles,$rowid,$customclass,$datarowstyle);
8792: unless ($datarowstyle eq 'display:none') {
8793: $$rowtotal ++;
8794: }
1.224 raeburn 8795: }
1.305 raeburn 8796: } else {
8797: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
8798: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
8799: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 8800: }
8801: }
8802: return $datatable;
8803: }
8804:
1.305 raeburn 8805: sub selfcreate_javascript {
8806: return <<"ENDSCRIPT";
8807:
8808: <script type="text/javascript">
8809: // <![CDATA[
8810:
8811: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
8812: var x = document.getElementsByClassName(target);
8813: var insttypes = 0;
8814: var insttypeRegExp = new RegExp(prefix);
8815: if ((x.length != undefined) && (x.length > 0)) {
8816: if (form.elements[radio].length != undefined) {
8817: for (var i=0; i<form.elements[radio].length; i++) {
8818: if (form.elements[radio][i].checked) {
8819: if (form.elements[radio][i].value == 1) {
8820: for (var j=0; j<x.length; j++) {
8821: if (x[j].id == 'undefined') {
8822: x[j].style.display = 'table-row';
8823: } else if (insttypeRegExp.test(x[j].id)) {
8824: insttypes ++;
8825: } else {
8826: x[j].style.display = 'table-row';
8827: }
8828: }
8829: } else {
8830: for (var j=0; j<x.length; j++) {
8831: x[j].style.display = 'none';
8832: }
1.236 raeburn 8833: }
1.305 raeburn 8834: break;
8835: }
8836: }
8837: if (insttypes > 0) {
8838: toggleDataRow(form,checkbox,target,altprefix);
8839: toggleDataRow(form,checkbox,target,prefix,1);
8840: }
8841: }
8842: }
8843: return;
8844: }
8845:
8846: function toggleDataRow(form,checkbox,target,prefix,docount) {
8847: if (form.elements[checkbox].length != undefined) {
8848: var count = 0;
8849: if (docount) {
8850: for (var i=0; i<form.elements[checkbox].length; i++) {
8851: if (form.elements[checkbox][i].checked) {
8852: count ++;
1.236 raeburn 8853: }
1.305 raeburn 8854: }
8855: }
8856: for (var i=0; i<form.elements[checkbox].length; i++) {
8857: var type = form.elements[checkbox][i].value;
8858: if (document.getElementById(prefix+type)) {
8859: if (form.elements[checkbox][i].checked) {
8860: document.getElementById(prefix+type).style.display = 'table-row';
8861: if (count % 2 == 1) {
8862: document.getElementById(prefix+type).className = target+' LC_odd_row';
8863: } else {
8864: document.getElementById(prefix+type).className = target;
1.236 raeburn 8865: }
1.305 raeburn 8866: count ++;
1.236 raeburn 8867: } else {
1.305 raeburn 8868: document.getElementById(prefix+type).style.display = 'none';
8869: }
8870: }
8871: }
8872: }
8873: return;
8874: }
8875:
8876: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
8877: var caller = radio+'_'+status;
8878: if (form.elements[caller].length != undefined) {
8879: for (var i=0; i<form.elements[caller].length; i++) {
8880: if (form.elements[caller][i].checked) {
8881: if (document.getElementById(altprefix+'_inst_'+status)) {
8882: var curr = form.elements[caller][i].value;
8883: if (prefix) {
8884: document.getElementById(prefix+'_'+status).style.display = 'none';
8885: }
8886: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
8887: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
8888: if (curr == 'custom') {
8889: if (prefix) {
8890: document.getElementById(prefix+'_'+status).style.display = 'inline';
8891: }
8892: } else if (curr == 'inst') {
8893: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
8894: } else if (curr == 'noninst') {
8895: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 8896: }
1.305 raeburn 8897: break;
1.236 raeburn 8898: }
8899: }
8900: }
8901: }
8902: }
8903:
1.305 raeburn 8904: // ]]>
8905: </script>
8906:
8907: ENDSCRIPT
8908: }
8909:
8910: sub noninst_users {
8911: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
8912: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
8913: my $class = 'LC_left_item';
8914: if ($css_class) {
8915: $css_class = ' class="'.$css_class.'"';
8916: }
8917: if ($rowid) {
8918: $rowid = ' id="'.$rowid.'"';
8919: }
8920: if ($rowstyle) {
8921: $rowstyle = ' style="'.$rowstyle.'"';
8922: }
8923: my ($output,$description);
8924: if ($type eq 'default') {
8925: $description = &mt('Requests for: [_1]',$typetitle);
8926: } else {
8927: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
8928: }
8929: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
8930: "<td>$description</td>\n".
8931: '<td class="'.$class.'" colspan="2">'.
8932: '<table><tr>';
8933: my %headers = &Apache::lonlocal::texthash(
8934: approve => 'Processing',
8935: email => 'E-mail',
8936: username => 'Username',
8937: );
8938: foreach my $item ('approve','email','username') {
8939: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 8940: }
1.305 raeburn 8941: $output .= '</tr><tr>';
8942: foreach my $item ('approve','email','username') {
1.306 raeburn 8943: $output .= '<td style="vertical-align: top">';
1.305 raeburn 8944: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
8945: if ($item eq 'approve') {
8946: %choices = &Apache::lonlocal::texthash (
8947: automatic => 'Automatically approved',
8948: approval => 'Queued for approval',
8949: );
8950: @options = ('automatic','approval');
8951: $hashref = $processing;
8952: $defoption = 'automatic';
8953: $name = 'cancreate_emailprocess_'.$type;
8954: } elsif ($item eq 'email') {
8955: %choices = &Apache::lonlocal::texthash (
8956: any => 'Any e-mail',
8957: inst => 'Institutional only',
8958: noninst => 'Non-institutional only',
8959: custom => 'Custom restrictions',
8960: );
8961: @options = ('any','inst','noninst');
8962: my $showcustom;
8963: if (ref($emailrules) eq 'HASH') {
8964: if (keys(%{$emailrules}) > 0) {
8965: push(@options,'custom');
8966: $showcustom = 'cancreate_emailrule';
8967: if (ref($settings) eq 'HASH') {
8968: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
8969: foreach my $rule (@{$settings->{'email_rule'}}) {
8970: if (exists($emailrules->{$rule})) {
8971: $hascustom ++;
8972: }
8973: }
8974: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
8975: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
8976: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
8977: if (exists($emailrules->{$rule})) {
8978: $hascustom ++;
8979: }
8980: }
8981: }
8982: }
8983: }
8984: }
8985: }
8986: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
8987: "'cancreate_emaildomain','$type'".');"';
8988: $hashref = $emailoptions;
8989: $defoption = 'any';
8990: $name = 'cancreate_emailoptions_'.$type;
8991: } elsif ($item eq 'username') {
8992: %choices = &Apache::lonlocal::texthash (
8993: all => 'Same as e-mail',
8994: first => 'Omit @domain',
8995: free => 'Free to choose',
8996: );
8997: @options = ('all','first','free');
8998: $hashref = $emailverified;
8999: $defoption = 'all';
9000: $name = 'cancreate_usernameoptions_'.$type;
9001: }
9002: foreach my $option (@options) {
9003: my $checked;
9004: if (ref($hashref) eq 'HASH') {
9005: if ($type eq '') {
9006: if (!exists($hashref->{'default'})) {
9007: if ($option eq $defoption) {
9008: $checked = ' checked="checked"';
9009: }
9010: } else {
9011: if ($hashref->{'default'} eq $option) {
9012: $checked = ' checked="checked"';
9013: }
1.303 raeburn 9014: }
9015: } else {
1.305 raeburn 9016: if (!exists($hashref->{$type})) {
9017: if ($option eq $defoption) {
9018: $checked = ' checked="checked"';
9019: }
9020: } else {
9021: if ($hashref->{$type} eq $option) {
9022: $checked = ' checked="checked"';
9023: }
1.303 raeburn 9024: }
9025: }
1.305 raeburn 9026: } elsif (($item eq 'email') && ($hascustom)) {
9027: if ($option eq 'custom') {
9028: $checked = ' checked="checked"';
9029: }
9030: } elsif ($option eq $defoption) {
9031: $checked = ' checked="checked"';
9032: }
9033: $output .= '<span class="LC_nobreak"><label>'.
9034: '<input type="radio" name="'.$name.'"'.
9035: $checked.' value="'.$option.'"'.$onclick.' />'.
9036: $choices{$option}.'</label></span><br />';
9037: if ($item eq 'email') {
9038: if ($option eq 'custom') {
9039: my $id = 'cancreate_emailrule_'.$type;
9040: my $display = 'none';
9041: if ($checked) {
9042: $display = 'inline';
1.303 raeburn 9043: }
1.305 raeburn 9044: my $numinrow = 2;
9045: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
9046: '<legend>'.&mt('Disallow').'</legend><table>'.
9047: &user_formats_row('email',$settings,$emailrules,
9048: $emailruleorder,$numinrow,'',$type);
9049: '</table></fieldset>';
9050: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
9051: my %text = &Apache::lonlocal::texthash (
9052: inst => 'must end:',
9053: noninst => 'cannot end:',
9054: );
9055: my $value;
9056: if (ref($emaildomain) eq 'HASH') {
9057: if (ref($emaildomain->{$type}) eq 'HASH') {
9058: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 9059: }
9060: }
1.305 raeburn 9061: if ($value eq '') {
9062: $value = '@'.$intdom;
9063: }
9064: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
9065: my $display = 'none';
9066: if ($checked) {
9067: $display = 'inline';
9068: }
9069: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
9070: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
9071: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
9072: '</div>';
1.303 raeburn 9073: }
9074: }
9075: }
1.305 raeburn 9076: $output .= '</td>'."\n";
1.303 raeburn 9077: }
1.305 raeburn 9078: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 9079: return $output;
9080: }
9081:
1.165 raeburn 9082: sub captcha_choice {
1.305 raeburn 9083: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 9084: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
9085: $vertext,$currver);
1.165 raeburn 9086: my %lt = &captcha_phrases();
9087: $keyentry = 'hidden';
1.354 raeburn 9088: my $colspan=2;
1.165 raeburn 9089: if ($context eq 'cancreate') {
1.224 raeburn 9090: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 9091: } elsif ($context eq 'login') {
9092: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 9093: } elsif ($context eq 'passwords') {
9094: $rowname = &mt('"Forgot Password" CAPTCHA validation');
9095: $colspan=1;
1.165 raeburn 9096: }
9097: if (ref($settings) eq 'HASH') {
9098: if ($settings->{'captcha'}) {
9099: $checked{$settings->{'captcha'}} = ' checked="checked"';
9100: } else {
9101: $checked{'original'} = ' checked="checked"';
9102: }
9103: if ($settings->{'captcha'} eq 'recaptcha') {
9104: $pubtext = $lt{'pub'};
9105: $privtext = $lt{'priv'};
9106: $keyentry = 'text';
1.269 raeburn 9107: $vertext = $lt{'ver'};
9108: $currver = $settings->{'recaptchaversion'};
9109: if ($currver ne '2') {
9110: $currver = 1;
9111: }
1.165 raeburn 9112: }
9113: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
9114: $currpub = $settings->{'recaptchakeys'}{'public'};
9115: $currpriv = $settings->{'recaptchakeys'}{'private'};
9116: }
9117: } else {
9118: $checked{'original'} = ' checked="checked"';
9119: }
1.305 raeburn 9120: my $css_class;
9121: if ($itemcount%2) {
9122: $css_class = 'LC_odd_row';
9123: }
9124: if ($customcss) {
9125: $css_class .= " $customcss";
9126: }
9127: $css_class =~ s/^\s+//;
9128: if ($css_class) {
9129: $css_class = ' class="'.$css_class.'"';
9130: }
9131: if ($rowstyle) {
9132: $css_class .= ' style="'.$rowstyle.'"';
9133: }
1.169 raeburn 9134: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 9135: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 9136: '<table><tr><td>'."\n";
9137: foreach my $option ('original','recaptcha','notused') {
9138: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
9139: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
9140: $lt{$option}.'</label></span>';
9141: unless ($option eq 'notused') {
9142: $output .= (' 'x2)."\n";
9143: }
9144: }
9145: #
9146: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
9147: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 9148: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 9149: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 9150: #
1.165 raeburn 9151: $output .= '</td></tr>'."\n".
1.305 raeburn 9152: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 9153: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
9154: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
9155: $currpub.'" size="40" /></span><br />'."\n".
9156: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
9157: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 9158: $currpriv.'" size="40" /></span><br />'.
9159: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
9160: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
9161: $currver.'" size="3" /></span><br />'.
9162: '</td></tr></table>'."\n".
1.165 raeburn 9163: '</td></tr>';
9164: return $output;
9165: }
9166:
1.32 raeburn 9167: sub user_formats_row {
1.305 raeburn 9168: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 9169: my $output;
9170: my %text = (
9171: 'username' => 'new usernames',
9172: 'id' => 'IDs',
9173: );
1.305 raeburn 9174: unless ($type eq 'email') {
9175: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
9176: $output = '<tr '.$css_class.'>'.
9177: '<td><span class="LC_nobreak">'.
9178: &mt("Format rules to check for $text{$type}: ").
9179: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 9180: }
1.27 raeburn 9181: my $rem;
9182: if (ref($ruleorder) eq 'ARRAY') {
9183: for (my $i=0; $i<@{$ruleorder}; $i++) {
9184: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
9185: my $rem = $i%($numinrow);
9186: if ($rem == 0) {
9187: if ($i > 0) {
9188: $output .= '</tr>';
9189: }
9190: $output .= '<tr>';
9191: }
9192: my $check = ' ';
1.39 raeburn 9193: if (ref($settings) eq 'HASH') {
9194: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
9195: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
9196: $check = ' checked="checked" ';
9197: }
1.305 raeburn 9198: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
9199: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
9200: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
9201: $check = ' checked="checked" ';
9202: }
9203: }
1.27 raeburn 9204: }
9205: }
1.305 raeburn 9206: my $name = $type.'_rule';
9207: if ($type eq 'email') {
9208: $name .= '_'.$status;
9209: }
1.27 raeburn 9210: $output .= '<td class="LC_left_item">'.
9211: '<span class="LC_nobreak"><label>'.
1.311 raeburn 9212: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 9213: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
9214: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
9215: }
9216: }
9217: $rem = @{$ruleorder}%($numinrow);
9218: }
1.305 raeburn 9219: my $colsleft;
9220: if ($rem) {
9221: $colsleft = $numinrow - $rem;
9222: }
1.27 raeburn 9223: if ($colsleft > 1 ) {
9224: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9225: ' </td>';
9226: } elsif ($colsleft == 1) {
9227: $output .= '<td class="LC_left_item"> </td>';
9228: }
1.305 raeburn 9229: $output .= '</tr></table>';
9230: unless ($type eq 'email') {
9231: $output .= '</td></tr>';
9232: }
1.27 raeburn 9233: return $output;
9234: }
9235:
1.34 raeburn 9236: sub usercreation_types {
9237: my %lt = &Apache::lonlocal::texthash (
9238: author => 'When adding a co-author',
9239: course => 'When adding a user to a course',
1.100 raeburn 9240: requestcrs => 'When requesting a course',
1.34 raeburn 9241: any => 'Any',
9242: official => 'Institutional only ',
9243: unofficial => 'Non-institutional only',
9244: none => 'None',
9245: );
9246: return %lt;
1.48 raeburn 9247: }
1.34 raeburn 9248:
1.224 raeburn 9249: sub selfcreation_types {
9250: my %lt = &Apache::lonlocal::texthash (
9251: selfcreate => 'User creates own account',
9252: any => 'Any',
9253: official => 'Institutional only ',
9254: unofficial => 'Non-institutional only',
9255: email => 'E-mail address',
9256: login => 'Institutional Login',
9257: sso => 'SSO',
9258: );
9259: }
9260:
1.28 raeburn 9261: sub authtype_names {
9262: my %lt = &Apache::lonlocal::texthash(
9263: int => 'Internal',
9264: krb4 => 'Kerberos 4',
9265: krb5 => 'Kerberos 5',
9266: loc => 'Local',
1.325 raeburn 9267: lti => 'LTI',
1.28 raeburn 9268: );
9269: return %lt;
9270: }
9271:
9272: sub context_names {
9273: my %context_title = &Apache::lonlocal::texthash(
9274: author => 'Creating users when an Author',
9275: course => 'Creating users when in a course',
9276: domain => 'Creating users when a Domain Coordinator',
9277: );
9278: return %context_title;
9279: }
9280:
1.33 raeburn 9281: sub print_usermodification {
9282: my ($position,$dom,$settings,$rowtotal) = @_;
9283: my $numinrow = 4;
9284: my ($context,$datatable,$rowcount);
9285: if ($position eq 'top') {
9286: $rowcount = 0;
9287: $context = 'author';
9288: foreach my $role ('ca','aa') {
9289: $datatable .= &modifiable_userdata_row($context,$role,$settings,
9290: $numinrow,$rowcount);
9291: $$rowtotal ++;
9292: $rowcount ++;
9293: }
1.230 raeburn 9294: } elsif ($position eq 'bottom') {
1.33 raeburn 9295: $context = 'course';
9296: $rowcount = 0;
9297: foreach my $role ('st','ep','ta','in','cr') {
9298: $datatable .= &modifiable_userdata_row($context,$role,$settings,
9299: $numinrow,$rowcount);
9300: $$rowtotal ++;
9301: $rowcount ++;
9302: }
9303: }
9304: return $datatable;
9305: }
9306:
1.43 raeburn 9307: sub print_defaults {
1.236 raeburn 9308: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 9309: my $rownum = 0;
1.294 raeburn 9310: my ($datatable,$css_class,$titles);
9311: unless ($position eq 'bottom') {
9312: $titles = &defaults_titles($dom);
9313: }
1.236 raeburn 9314: if ($position eq 'top') {
9315: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
9316: 'datelocale_def','portal_def');
9317: my %defaults;
9318: if (ref($settings) eq 'HASH') {
9319: %defaults = %{$settings};
1.43 raeburn 9320: } else {
1.236 raeburn 9321: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9322: foreach my $item (@items) {
9323: $defaults{$item} = $domdefaults{$item};
9324: }
1.43 raeburn 9325: }
1.236 raeburn 9326: foreach my $item (@items) {
9327: if ($rownum%2) {
9328: $css_class = '';
9329: } else {
9330: $css_class = ' class="LC_odd_row" ';
9331: }
9332: $datatable .= '<tr'.$css_class.'>'.
9333: '<td><span class="LC_nobreak">'.$titles->{$item}.
9334: '</span></td><td class="LC_right_item" colspan="3">';
9335: if ($item eq 'auth_def') {
1.325 raeburn 9336: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 9337: my %shortauth = (
9338: internal => 'int',
9339: krb4 => 'krb4',
9340: krb5 => 'krb5',
1.325 raeburn 9341: localauth => 'loc',
9342: lti => 'lti',
1.236 raeburn 9343: );
9344: my %authnames = &authtype_names();
9345: foreach my $auth (@authtypes) {
9346: my $checked = ' ';
9347: if ($defaults{$item} eq $auth) {
9348: $checked = ' checked="checked" ';
9349: }
9350: $datatable .= '<label><input type="radio" name="'.$item.
9351: '" value="'.$auth.'"'.$checked.'/>'.
9352: $authnames{$shortauth{$auth}}.'</label> ';
9353: }
9354: } elsif ($item eq 'timezone_def') {
9355: my $includeempty = 1;
9356: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
9357: } elsif ($item eq 'datelocale_def') {
9358: my $includeempty = 1;
9359: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
9360: } elsif ($item eq 'lang_def') {
1.263 raeburn 9361: my $includeempty = 1;
9362: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 9363: } else {
9364: my $size;
9365: if ($item eq 'portal_def') {
9366: $size = ' size="25"';
9367: }
9368: $datatable .= '<input type="text" name="'.$item.'" value="'.
9369: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 9370: }
1.236 raeburn 9371: $datatable .= '</td></tr>';
9372: $rownum ++;
9373: }
1.354 raeburn 9374: } else {
1.294 raeburn 9375: my %defaults;
9376: if (ref($settings) eq 'HASH') {
1.354 raeburn 9377: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
9378: my $maxnum = @{$settings->{'inststatusorder'}};
9379: for (my $i=0; $i<$maxnum; $i++) {
9380: $css_class = $rownum%2?' class="LC_odd_row"':'';
9381: my $item = $settings->{'inststatusorder'}->[$i];
9382: my $title = $settings->{'inststatustypes'}->{$item};
9383: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
9384: $datatable .= '<tr'.$css_class.'>'.
9385: '<td><span class="LC_nobreak">'.
9386: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
9387: for (my $k=0; $k<=$maxnum; $k++) {
9388: my $vpos = $k+1;
9389: my $selstr;
9390: if ($k == $i) {
9391: $selstr = ' selected="selected" ';
9392: }
9393: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9394: }
9395: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
9396: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
9397: &mt('delete').'</span></td>'.
9398: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed:').
9399: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
9400: '</span></td></tr>';
9401: }
9402: $css_class = $rownum%2?' class="LC_odd_row"':'';
9403: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
9404: $datatable .= '<tr '.$css_class.'>'.
9405: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
9406: for (my $k=0; $k<=$maxnum; $k++) {
9407: my $vpos = $k+1;
9408: my $selstr;
9409: if ($k == $maxnum) {
9410: $selstr = ' selected="selected" ';
9411: }
9412: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9413: }
9414: $datatable .= '</select> '.&mt('Internal ID:').
9415: '<input type="text" size="10" name="addinststatus" value="" />'.
9416: ' '.&mt('(new)').
9417: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
9418: &mt('Name displayed:').
9419: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
9420: '</tr>'."\n";
9421: $rownum ++;
1.294 raeburn 9422: }
1.354 raeburn 9423: }
9424: }
9425: $$rowtotal += $rownum;
1.43 raeburn 9426: return $datatable;
9427: }
9428:
1.168 raeburn 9429: sub get_languages_hash {
9430: my %langchoices;
9431: foreach my $id (&Apache::loncommon::languageids()) {
9432: my $code = &Apache::loncommon::supportedlanguagecode($id);
9433: if ($code ne '') {
9434: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
9435: }
9436: }
9437: return %langchoices;
9438: }
9439:
1.43 raeburn 9440: sub defaults_titles {
1.141 raeburn 9441: my ($dom) = @_;
1.43 raeburn 9442: my %titles = &Apache::lonlocal::texthash (
9443: 'auth_def' => 'Default authentication type',
9444: 'auth_arg_def' => 'Default authentication argument',
9445: 'lang_def' => 'Default language',
1.54 raeburn 9446: 'timezone_def' => 'Default timezone',
1.68 raeburn 9447: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 9448: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 9449: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
9450: 'intauth_check' => 'Check bcrypt cost if authenticated',
9451: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 9452: );
1.141 raeburn 9453: if ($dom) {
9454: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
9455: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
9456: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
9457: $protocol = 'http' if ($protocol ne 'https');
9458: if ($uint_dom) {
9459: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
9460: $uint_dom);
9461: }
9462: }
1.43 raeburn 9463: return (\%titles);
9464: }
9465:
1.346 raeburn 9466: sub print_scantron {
9467: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
9468: if ($position eq 'top') {
9469: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
9470: } else {
9471: return &print_scantronconfig($dom,$settings,\$rowtotal);
9472: }
9473: }
9474:
9475: sub scantron_javascript {
9476: return <<"ENDSCRIPT";
9477:
9478: <script type="text/javascript">
9479: // <![CDATA[
9480:
9481: function toggleScantron(form) {
1.347 raeburn 9482: var csvfieldset = new Array();
1.346 raeburn 9483: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 9484: csvfieldset.push(document.getElementById('scantroncsv_cols'));
9485: }
9486: if (document.getElementById('scantroncsv_options')) {
9487: csvfieldset.push(document.getElementById('scantroncsv_options'));
9488: }
9489: if (csvfieldset.length) {
1.346 raeburn 9490: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 9491: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 9492: if (scantroncsv.checked) {
1.347 raeburn 9493: for (var i=0; i<csvfieldset.length; i++) {
9494: csvfieldset[i].style.display = 'block';
9495: }
1.346 raeburn 9496: } else {
1.347 raeburn 9497: for (var i=0; i<csvfieldset.length; i++) {
9498: csvfieldset[i].style.display = 'none';
9499: }
1.346 raeburn 9500: var csvselects = document.getElementsByClassName('scantronconfig_csv');
9501: if (csvselects.length) {
9502: for (var j=0; j<csvselects.length; j++) {
9503: csvselects[j].selectedIndex = 0;
9504: }
9505: }
9506: }
9507: }
9508: }
9509: return;
9510: }
9511: // ]]>
9512: </script>
9513:
9514: ENDSCRIPT
9515:
9516: }
9517:
1.46 raeburn 9518: sub print_scantronformat {
9519: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
9520: my $itemcount = 1;
1.60 raeburn 9521: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
9522: %confhash);
1.46 raeburn 9523: my $switchserver = &check_switchserver($dom,$confname);
9524: my %lt = &Apache::lonlocal::texthash (
1.95 www 9525: default => 'Default bubblesheet format file error',
9526: custom => 'Custom bubblesheet format file error',
1.46 raeburn 9527: );
9528: my %scantronfiles = (
9529: default => 'default.tab',
9530: custom => 'custom.tab',
9531: );
9532: foreach my $key (keys(%scantronfiles)) {
9533: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
9534: .$scantronfiles{$key};
9535: }
9536: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
9537: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
9538: if (!$switchserver) {
9539: my $servadm = $r->dir_config('lonAdmEMail');
9540: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
9541: if ($configuserok eq 'ok') {
9542: if ($author_ok eq 'ok') {
9543: my %legacyfile = (
1.346 raeburn 9544: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
9545: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 9546: );
9547: my %md5chk;
9548: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 9549: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
9550: chomp($md5chk{$type});
1.46 raeburn 9551: }
9552: if ($md5chk{'default'} ne $md5chk{'custom'}) {
9553: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 9554: ($scantronurls{$type},my $error) =
1.46 raeburn 9555: &legacy_scantronformat($r,$dom,$confname,
9556: $type,$legacyfile{$type},
9557: $scantronurls{$type},
9558: $scantronfiles{$type});
1.60 raeburn 9559: if ($error ne '') {
9560: $error{$type} = $error;
9561: }
9562: }
9563: if (keys(%error) == 0) {
9564: $is_custom = 1;
1.346 raeburn 9565: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 9566: $scantronurls{'custom'};
1.346 raeburn 9567: my $putresult =
1.60 raeburn 9568: &Apache::lonnet::put_dom('configuration',
9569: \%confhash,$dom);
9570: if ($putresult ne 'ok') {
1.346 raeburn 9571: $error{'custom'} =
1.60 raeburn 9572: '<span class="LC_error">'.
9573: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
9574: }
1.46 raeburn 9575: }
9576: } else {
1.60 raeburn 9577: ($scantronurls{'default'},my $error) =
1.46 raeburn 9578: &legacy_scantronformat($r,$dom,$confname,
9579: 'default',$legacyfile{'default'},
9580: $scantronurls{'default'},
9581: $scantronfiles{'default'});
1.60 raeburn 9582: if ($error eq '') {
9583: $confhash{'scantron'}{'scantronformat'} = '';
9584: my $putresult =
9585: &Apache::lonnet::put_dom('configuration',
9586: \%confhash,$dom);
9587: if ($putresult ne 'ok') {
9588: $error{'default'} =
9589: '<span class="LC_error">'.
9590: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
9591: }
9592: } else {
9593: $error{'default'} = $error;
9594: }
1.46 raeburn 9595: }
9596: }
9597: }
9598: } else {
1.95 www 9599: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 9600: }
9601: }
9602: if (ref($settings) eq 'HASH') {
9603: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
9604: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
9605: if ((!@info) || ($info[0] eq 'no_such_dir')) {
9606: $scantronurl = '';
9607: } else {
9608: $scantronurl = $settings->{'scantronformat'};
9609: }
9610: $is_custom = 1;
9611: } else {
9612: $scantronurl = $scantronurls{'default'};
9613: }
9614: } else {
1.60 raeburn 9615: if ($is_custom) {
9616: $scantronurl = $scantronurls{'custom'};
9617: } else {
9618: $scantronurl = $scantronurls{'default'};
9619: }
1.46 raeburn 9620: }
9621: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9622: $datatable .= '<tr'.$css_class.'>';
9623: if (!$is_custom) {
1.65 raeburn 9624: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
9625: '<span class="LC_nobreak">';
1.46 raeburn 9626: if ($scantronurl) {
1.199 raeburn 9627: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
9628: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 9629: } else {
9630: $datatable = &mt('File unavailable for display');
9631: }
1.65 raeburn 9632: $datatable .= '</span></td>';
1.60 raeburn 9633: if (keys(%error) == 0) {
1.306 raeburn 9634: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 9635: if (!$switchserver) {
9636: $datatable .= &mt('Upload:').'<br />';
9637: }
9638: } else {
9639: my $errorstr;
9640: foreach my $key (sort(keys(%error))) {
9641: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
9642: }
9643: $datatable .= '<td>'.$errorstr;
9644: }
1.46 raeburn 9645: } else {
9646: if (keys(%error) > 0) {
9647: my $errorstr;
9648: foreach my $key (sort(keys(%error))) {
9649: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
9650: }
1.60 raeburn 9651: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 9652: } elsif ($scantronurl) {
1.199 raeburn 9653: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
9654: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 9655: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 9656: $link.
9657: '<label><input type="checkbox" name="scantronformat_del"'.
9658: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 9659: '<td><span class="LC_nobreak"> '.
9660: &mt('Replace:').'</span><br />';
1.46 raeburn 9661: }
9662: }
9663: if (keys(%error) == 0) {
9664: if ($switchserver) {
9665: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
9666: } else {
1.65 raeburn 9667: $datatable .='<span class="LC_nobreak"> '.
9668: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 9669: }
9670: }
9671: $datatable .= '</td></tr>';
9672: $$rowtotal ++;
9673: return $datatable;
9674: }
9675:
9676: sub legacy_scantronformat {
9677: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
9678: my ($url,$error);
9679: my @statinfo = &Apache::lonnet::stat_file($newurl);
9680: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
9681: (my $result,$url) =
9682: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
9683: '','',$newfile);
9684: if ($result ne 'ok') {
1.130 raeburn 9685: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 9686: }
9687: }
9688: return ($url,$error);
9689: }
1.43 raeburn 9690:
1.346 raeburn 9691: sub print_scantronconfig {
9692: my ($dom,$settings,$rowtotal) = @_;
9693: my $itemcount = 2;
9694: my $is_checked = ' checked="checked"';
1.347 raeburn 9695: my %optionson = (
9696: hdr => ' checked="checked"',
9697: pad => ' checked="checked"',
9698: rem => ' checked="checked"',
9699: );
9700: my %optionsoff = (
9701: hdr => '',
9702: pad => '',
9703: rem => '',
9704: );
1.346 raeburn 9705: my $currcsvsty = 'none';
1.347 raeburn 9706: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 9707: my @fields = &scantroncsv_fields();
9708: my %titles = &scantronconfig_titles();
9709: if (ref($settings) eq 'HASH') {
9710: if (ref($settings->{config}) eq 'HASH') {
9711: if ($settings->{config}->{dat}) {
9712: $checked{'dat'} = $is_checked;
9713: }
9714: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 9715: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
9716: %csvfields = %{$settings->{config}->{csv}->{fields}};
9717: if (keys(%csvfields) > 0) {
9718: $checked{'csv'} = $is_checked;
9719: $currcsvsty = 'block';
9720: }
9721: }
9722: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
9723: %csvoptions = %{$settings->{config}->{csv}->{options}};
9724: foreach my $option (keys(%optionson)) {
9725: unless ($csvoptions{$option}) {
9726: $optionsoff{$option} = $optionson{$option};
9727: $optionson{$option} = '';
9728: }
9729: }
1.346 raeburn 9730: }
9731: }
9732: } else {
9733: $checked{'dat'} = $is_checked;
9734: }
9735: } else {
9736: $checked{'dat'} = $is_checked;
9737: }
9738: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
9739: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
9740: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
9741: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
9742: foreach my $item ('dat','csv') {
9743: my $id;
9744: if ($item eq 'csv') {
9745: $id = 'id="scantronconfcsv" ';
1.347 raeburn 9746: }
1.346 raeburn 9747: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
9748: $titles{$item}.'</label>'.(' 'x3);
9749: if ($item eq 'csv') {
9750: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
9751: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
9752: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
9753: foreach my $col (@fields) {
9754: my $selnone;
9755: if ($csvfields{$col} eq '') {
9756: $selnone = ' selected="selected"';
9757: }
9758: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
9759: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
9760: '<option value=""'.$selnone.'></option>';
9761: for (my $i=0; $i<20; $i++) {
9762: my $shown = $i+1;
9763: my $sel;
9764: unless ($selnone) {
9765: if (exists($csvfields{$col})) {
9766: if ($csvfields{$col} == $i) {
9767: $sel = ' selected="selected"';
9768: }
9769: }
9770: }
9771: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
9772: }
9773: $datatable .= '</select></td></tr>';
9774: }
1.347 raeburn 9775: $datatable .= '</table></fieldset>'.
9776: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
9777: '<legend>'.&mt('CSV Options').'</legend>';
9778: foreach my $option ('hdr','pad','rem') {
9779: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
9780: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
9781: &mt('Yes').'</label>'.(' 'x2)."\n".
9782: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
9783: }
9784: $datatable .= '</fieldset>';
1.346 raeburn 9785: $itemcount ++;
9786: }
9787: }
9788: $datatable .= '</td></tr>';
9789: $$rowtotal ++;
9790: return $datatable;
9791: }
9792:
9793: sub scantronconfig_titles {
9794: return &Apache::lonlocal::texthash(
9795: dat => 'Standard format (.dat)',
9796: csv => 'Comma separated values (.csv)',
1.347 raeburn 9797: hdr => 'Remove first line in file (contains column titles)',
9798: pad => 'Prepend 0s to PaperID',
1.348 raeburn 9799: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 9800: CODE => 'CODE',
9801: ID => 'Student ID',
9802: PaperID => 'Paper ID',
9803: FirstName => 'First Name',
9804: LastName => 'Last Name',
9805: FirstQuestion => 'First Question Response',
9806: Section => 'Section',
9807: );
9808: }
9809:
9810: sub scantroncsv_fields {
9811: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
9812: }
9813:
1.49 raeburn 9814: sub print_coursecategories {
1.57 raeburn 9815: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
9816: my $datatable;
9817: if ($position eq 'top') {
1.238 raeburn 9818: my (%checked);
9819: my @catitems = ('unauth','auth');
9820: my @cattypes = ('std','domonly','codesrch','none');
9821: $checked{'unauth'} = 'std';
9822: $checked{'auth'} = 'std';
9823: if (ref($settings) eq 'HASH') {
9824: foreach my $type (@cattypes) {
9825: if ($type eq $settings->{'unauth'}) {
9826: $checked{'unauth'} = $type;
9827: }
9828: if ($type eq $settings->{'auth'}) {
9829: $checked{'auth'} = $type;
9830: }
9831: }
9832: }
9833: my %lt = &Apache::lonlocal::texthash (
9834: unauth => 'Catalog type for unauthenticated users',
9835: auth => 'Catalog type for authenticated users',
9836: none => 'No catalog',
9837: std => 'Standard catalog',
9838: domonly => 'Domain-only catalog',
9839: codesrch => "Code search form",
9840: );
9841: my $itemcount = 0;
9842: foreach my $item (@catitems) {
9843: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
9844: $datatable .= '<tr '.$css_class.'>'.
9845: '<td>'.$lt{$item}.'</td>'.
9846: '<td class="LC_right_item"><span class="LC_nobreak">';
9847: foreach my $type (@cattypes) {
9848: my $ischecked;
9849: if ($checked{$item} eq $type) {
9850: $ischecked=' checked="checked"';
9851: }
9852: $datatable .= '<label>'.
9853: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
9854: ' />'.$lt{$type}.'</label> ';
9855: }
1.327 raeburn 9856: $datatable .= '</span></td></tr>';
1.238 raeburn 9857: $itemcount ++;
9858: }
9859: $$rowtotal += $itemcount;
9860: } elsif ($position eq 'middle') {
1.57 raeburn 9861: my $toggle_cats_crs = ' ';
9862: my $toggle_cats_dom = ' checked="checked" ';
9863: my $can_cat_crs = ' ';
9864: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 9865: my $toggle_catscomm_comm = ' ';
9866: my $toggle_catscomm_dom = ' checked="checked" ';
9867: my $can_catcomm_comm = ' ';
9868: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 9869: my $toggle_catsplace_place = ' ';
9870: my $toggle_catsplace_dom = ' checked="checked" ';
9871: my $can_catplace_place = ' ';
9872: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 9873:
1.57 raeburn 9874: if (ref($settings) eq 'HASH') {
9875: if ($settings->{'togglecats'} eq 'crs') {
9876: $toggle_cats_crs = $toggle_cats_dom;
9877: $toggle_cats_dom = ' ';
9878: }
9879: if ($settings->{'categorize'} eq 'crs') {
9880: $can_cat_crs = $can_cat_dom;
9881: $can_cat_dom = ' ';
9882: }
1.120 raeburn 9883: if ($settings->{'togglecatscomm'} eq 'comm') {
9884: $toggle_catscomm_comm = $toggle_catscomm_dom;
9885: $toggle_catscomm_dom = ' ';
9886: }
9887: if ($settings->{'categorizecomm'} eq 'comm') {
9888: $can_catcomm_comm = $can_catcomm_dom;
9889: $can_catcomm_dom = ' ';
9890: }
1.272 raeburn 9891: if ($settings->{'togglecatsplace'} eq 'place') {
9892: $toggle_catsplace_place = $toggle_catsplace_dom;
9893: $toggle_catsplace_dom = ' ';
9894: }
9895: if ($settings->{'categorizeplace'} eq 'place') {
9896: $can_catplace_place = $can_catplace_dom;
9897: $can_catplace_dom = ' ';
9898: }
1.57 raeburn 9899: }
9900: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 9901: togglecats => 'Show/Hide a course in catalog',
9902: togglecatscomm => 'Show/Hide a community in catalog',
9903: togglecatsplace => 'Show/Hide a placement test in catalog',
9904: categorize => 'Assign a category to a course',
9905: categorizecomm => 'Assign a category to a community',
9906: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 9907: );
9908: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 9909: dom => 'Set in Domain',
9910: crs => 'Set in Course',
9911: comm => 'Set in Community',
9912: place => 'Set in Placement Test',
1.57 raeburn 9913: );
9914: $datatable = '<tr class="LC_odd_row">'.
9915: '<td>'.$title{'togglecats'}.'</td>'.
9916: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
9917: '<input type="radio" name="togglecats"'.
9918: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9919: '<label><input type="radio" name="togglecats"'.
9920: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
9921: '</tr><tr>'.
9922: '<td>'.$title{'categorize'}.'</td>'.
9923: '<td class="LC_right_item"><span class="LC_nobreak">'.
9924: '<label><input type="radio" name="categorize"'.
9925: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9926: '<label><input type="radio" name="categorize"'.
9927: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 9928: '</tr><tr class="LC_odd_row">'.
9929: '<td>'.$title{'togglecatscomm'}.'</td>'.
9930: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
9931: '<input type="radio" name="togglecatscomm"'.
9932: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9933: '<label><input type="radio" name="togglecatscomm"'.
9934: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
9935: '</tr><tr>'.
9936: '<td>'.$title{'categorizecomm'}.'</td>'.
9937: '<td class="LC_right_item"><span class="LC_nobreak">'.
9938: '<label><input type="radio" name="categorizecomm"'.
9939: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9940: '<label><input type="radio" name="categorizecomm"'.
9941: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 9942: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 9943: '<td>'.$title{'togglecatsplace'}.'</td>'.
9944: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
9945: '<input type="radio" name="togglecatsplace"'.
9946: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9947: '<label><input type="radio" name="togglecatscomm"'.
9948: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
9949: '</tr><tr>'.
9950: '<td>'.$title{'categorizeplace'}.'</td>'.
9951: '<td class="LC_right_item"><span class="LC_nobreak">'.
9952: '<label><input type="radio" name="categorizeplace"'.
9953: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9954: '<label><input type="radio" name="categorizeplace"'.
9955: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 9956: '</tr>';
1.272 raeburn 9957: $$rowtotal += 6;
1.57 raeburn 9958: } else {
9959: my $css_class;
9960: my $itemcount = 1;
9961: my $cathash;
9962: if (ref($settings) eq 'HASH') {
9963: $cathash = $settings->{'cats'};
9964: }
9965: if (ref($cathash) eq 'HASH') {
9966: my (@cats,@trails,%allitems,%idx,@jsarray);
9967: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
9968: \%allitems,\%idx,\@jsarray);
9969: my $maxdepth = scalar(@cats);
9970: my $colattrib = '';
9971: if ($maxdepth > 2) {
9972: $colattrib = ' colspan="2" ';
9973: }
9974: my @path;
9975: if (@cats > 0) {
9976: if (ref($cats[0]) eq 'ARRAY') {
9977: my $numtop = @{$cats[0]};
9978: my $maxnum = $numtop;
1.120 raeburn 9979: my %default_names = (
9980: instcode => &mt('Official courses'),
9981: communities => &mt('Communities'),
1.272 raeburn 9982: placement => &mt('Placement Tests'),
1.120 raeburn 9983: );
9984:
9985: if ((!grep(/^instcode$/,@{$cats[0]})) ||
9986: ($cathash->{'instcode::0'} eq '') ||
9987: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 9988: ($cathash->{'communities::0'} eq '') ||
9989: (!grep(/^placement$/,@{$cats[0]})) ||
9990: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 9991: $maxnum ++;
9992: }
9993: my $lastidx;
9994: for (my $i=0; $i<$numtop; $i++) {
9995: my $parent = $cats[0][$i];
9996: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9997: my $item = &escape($parent).'::0';
9998: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
9999: $lastidx = $idx{$item};
10000: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
10001: .'<select name="'.$item.'"'.$chgstr.'>';
10002: for (my $k=0; $k<=$maxnum; $k++) {
10003: my $vpos = $k+1;
10004: my $selstr;
10005: if ($k == $i) {
10006: $selstr = ' selected="selected" ';
10007: }
10008: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10009: }
1.214 raeburn 10010: $datatable .= '</select></span></td><td>';
1.272 raeburn 10011: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 10012: $datatable .= '<span class="LC_nobreak">'
10013: .$default_names{$parent}.'</span>';
10014: if ($parent eq 'instcode') {
10015: $datatable .= '<br /><span class="LC_nobreak">('
10016: .&mt('with institutional codes')
10017: .')</span></td><td'.$colattrib.'>';
10018: } else {
10019: $datatable .= '<table><tr><td>';
10020: }
10021: $datatable .= '<span class="LC_nobreak">'
10022: .'<label><input type="radio" name="'
10023: .$parent.'" value="1" checked="checked" />'
10024: .&mt('Display').'</label>';
10025: if ($parent eq 'instcode') {
10026: $datatable .= ' ';
10027: } else {
10028: $datatable .= '</span></td></tr><tr><td>'
10029: .'<span class="LC_nobreak">';
10030: }
10031: $datatable .= '<label><input type="radio" name="'
10032: .$parent.'" value="0" />'
10033: .&mt('Do not display').'</label></span>';
1.272 raeburn 10034: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 10035: $datatable .= '</td></tr></table>';
10036: }
10037: $datatable .= '</td>';
1.57 raeburn 10038: } else {
10039: $datatable .= $parent
1.214 raeburn 10040: .' <span class="LC_nobreak"><label>'
10041: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 10042: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
10043: }
10044: my $depth = 1;
10045: push(@path,$parent);
10046: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
10047: pop(@path);
10048: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
10049: $itemcount ++;
10050: }
1.48 raeburn 10051: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 10052: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
10053: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 10054: for (my $k=0; $k<=$maxnum; $k++) {
10055: my $vpos = $k+1;
10056: my $selstr;
1.57 raeburn 10057: if ($k == $numtop) {
1.48 raeburn 10058: $selstr = ' selected="selected" ';
10059: }
10060: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10061: }
1.59 bisitz 10062: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 10063: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
10064: .'</tr>'."\n";
1.48 raeburn 10065: $itemcount ++;
1.272 raeburn 10066: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 10067: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
10068: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10069: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
10070: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
10071: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
10072: for (my $k=0; $k<=$maxnum; $k++) {
10073: my $vpos = $k+1;
10074: my $selstr;
10075: if ($k == $maxnum) {
10076: $selstr = ' selected="selected" ';
10077: }
10078: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 10079: }
1.120 raeburn 10080: $datatable .= '</select></span></td>'.
10081: '<td><span class="LC_nobreak">'.
10082: $default_names{$default}.'</span>';
10083: if ($default eq 'instcode') {
10084: $datatable .= '<br /><span class="LC_nobreak">('
10085: .&mt('with institutional codes').')</span>';
10086: }
10087: $datatable .= '</td>'
10088: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
10089: .&mt('Display').'</label> '
10090: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
10091: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 10092: }
10093: }
10094: }
1.57 raeburn 10095: } else {
10096: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 10097: }
10098: } else {
1.327 raeburn 10099: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 10100: .&initialize_categories($itemcount);
1.48 raeburn 10101: }
1.57 raeburn 10102: $$rowtotal += $itemcount;
1.48 raeburn 10103: }
10104: return $datatable;
10105: }
10106:
1.69 raeburn 10107: sub print_serverstatuses {
10108: my ($dom,$settings,$rowtotal) = @_;
10109: my $datatable;
10110: my @pages = &serverstatus_pages();
10111: my (%namedaccess,%machineaccess);
10112: foreach my $type (@pages) {
10113: $namedaccess{$type} = '';
10114: $machineaccess{$type}= '';
10115: }
10116: if (ref($settings) eq 'HASH') {
10117: foreach my $type (@pages) {
10118: if (exists($settings->{$type})) {
10119: if (ref($settings->{$type}) eq 'HASH') {
10120: foreach my $key (keys(%{$settings->{$type}})) {
10121: if ($key eq 'namedusers') {
10122: $namedaccess{$type} = $settings->{$type}->{$key};
10123: } elsif ($key eq 'machines') {
10124: $machineaccess{$type} = $settings->{$type}->{$key};
10125: }
10126: }
10127: }
10128: }
10129: }
10130: }
1.81 raeburn 10131: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 10132: my $rownum = 0;
10133: my $css_class;
10134: foreach my $type (@pages) {
10135: $rownum ++;
10136: $css_class = $rownum%2?' class="LC_odd_row"':'';
10137: $datatable .= '<tr'.$css_class.'>'.
10138: '<td><span class="LC_nobreak">'.
10139: $titles->{$type}.'</span></td>'.
10140: '<td class="LC_left_item">'.
10141: '<input type="text" name="'.$type.'_namedusers" '.
10142: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
10143: '<td class="LC_right_item">'.
10144: '<span class="LC_nobreak">'.
10145: '<input type="text" name="'.$type.'_machines" '.
10146: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 10147: '</span></td></tr>'."\n";
1.69 raeburn 10148: }
10149: $$rowtotal += $rownum;
10150: return $datatable;
10151: }
10152:
10153: sub serverstatus_pages {
10154: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 10155: 'checksums','clusterstatus','certstatus','metadata_keywords',
10156: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
10157: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 10158: }
10159:
1.236 raeburn 10160: sub defaults_javascript {
10161: my ($settings) = @_;
1.354 raeburn 10162: return unless (ref($settings) eq 'HASH');
1.236 raeburn 10163: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10164: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
10165: if ($maxnum eq '') {
10166: $maxnum = 0;
10167: }
10168: $maxnum ++;
1.249 raeburn 10169: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 10170: return <<"ENDSCRIPT";
10171: <script type="text/javascript">
10172: // <![CDATA[
10173: function reorderTypes(form,caller) {
10174: var changedVal;
10175: $jstext
10176: var newpos = 'addinststatus_pos';
10177: var current = new Array;
10178: var maxh = $maxnum;
10179: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
10180: var oldVal;
10181: if (caller == newpos) {
10182: changedVal = newitemVal;
10183: } else {
10184: var curritem = 'inststatus_pos_'+caller;
10185: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
10186: current[newitemVal] = newpos;
10187: }
10188: for (var i=0; i<inststatuses.length; i++) {
10189: if (inststatuses[i] != caller) {
10190: var elementName = 'inststatus_pos_'+inststatuses[i];
10191: if (form.elements[elementName]) {
10192: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
10193: current[currVal] = elementName;
10194: }
10195: }
10196: }
10197: for (var j=0; j<maxh; j++) {
10198: if (current[j] == undefined) {
10199: oldVal = j;
10200: }
10201: }
10202: if (oldVal < changedVal) {
10203: for (var k=oldVal+1; k<=changedVal ; k++) {
10204: var elementName = current[k];
10205: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
10206: }
10207: } else {
10208: for (var k=changedVal; k<oldVal; k++) {
10209: var elementName = current[k];
10210: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
10211: }
10212: }
10213: return;
10214: }
10215:
10216: // ]]>
10217: </script>
10218:
10219: ENDSCRIPT
10220: }
1.354 raeburn 10221: return;
10222: }
10223:
10224: sub passwords_javascript {
1.365 raeburn 10225: my %intalert = &Apache::lonlocal::texthash (
10226: 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.',
10227: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
10228: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
10229: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
10230: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
10231: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
10232: );
10233: &js_escape(\%intalert);
10234: my $defmin = $Apache::lonnet::passwdmin;
1.354 raeburn 10235: my $intauthjs = <<"ENDSCRIPT";
10236:
10237: function warnIntAuth(field) {
10238: if (field.name == 'intauth_check') {
10239: if (field.value == '2') {
1.365 raeburn 10240: alert('$intalert{authcheck}');
1.354 raeburn 10241: }
10242: }
10243: if (field.name == 'intauth_cost') {
10244: field.value.replace(/\s/g,'');
10245: if (field.value != '') {
10246: var regexdigit=/^\\d+\$/;
10247: if (!regexdigit.test(field.value)) {
1.365 raeburn 10248: alert('$intalert{authcost}');
10249: }
10250: }
10251: }
10252: return;
10253: }
10254:
10255: function warnIntPass(field) {
10256: field.value.replace(/^\s+/,'');
10257: field.value.replace(/\s+\$/,'');
10258: var regexdigit=/^\\d+\$/;
10259: if (field.name == 'passwords_min') {
10260: if (field.value == '') {
10261: alert('$intalert{passmin}');
10262: field.value = '$defmin';
10263: } else {
10264: if (!regexdigit.test(field.value)) {
10265: alert('$intalert{passmin}');
10266: field.value = '$defmin';
10267: }
1.366 raeburn 10268: var minval = parseInt(field.value,10);
1.365 raeburn 10269: if (minval < $defmin) {
10270: alert('$intalert{passmin}');
10271: field.value = '$defmin';
10272: }
10273: }
10274: } else {
10275: if (field.value == '0') {
10276: field.value = '';
10277: }
10278: if (field.value != '') {
10279: if (field.name == 'passwords_expire') {
10280: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
10281: if (!regexpposnum.test(field.value)) {
10282: alert('$intalert{passexp}');
10283: field.value = '';
10284: } else {
10285: var expval = parseFloat(field.value);
10286: if (expval == 0) {
10287: alert('$intalert{passexp}');
10288: field.value = '';
10289: }
10290: }
10291: } else {
10292: if (!regexdigit.test(field.value)) {
10293: if (field.name == 'passwords_max') {
10294: alert('$intalert{passmax}');
10295: } else {
10296: if (field.name == 'passwords_numsaved') {
10297: alert('$intalert{passnum}');
10298: }
10299: }
1.370 raeburn 10300: field.value = '';
1.365 raeburn 10301: }
1.354 raeburn 10302: }
10303: }
10304: }
10305: return;
10306: }
10307:
10308: ENDSCRIPT
10309: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 10310: }
10311:
1.49 raeburn 10312: sub coursecategories_javascript {
10313: my ($settings) = @_;
1.57 raeburn 10314: my ($output,$jstext,$cathash);
1.49 raeburn 10315: if (ref($settings) eq 'HASH') {
1.57 raeburn 10316: $cathash = $settings->{'cats'};
10317: }
10318: if (ref($cathash) eq 'HASH') {
1.49 raeburn 10319: my (@cats,@jsarray,%idx);
1.57 raeburn 10320: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 10321: if (@jsarray > 0) {
10322: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
10323: for (my $i=0; $i<@jsarray; $i++) {
10324: if (ref($jsarray[$i]) eq 'ARRAY') {
10325: my $catstr = join('","',@{$jsarray[$i]});
10326: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
10327: }
10328: }
10329: }
10330: } else {
10331: $jstext = ' var categories = Array(1);'."\n".
10332: ' categories[0] = Array("instcode_pos");'."\n";
10333: }
1.237 bisitz 10334: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
10335: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 10336: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 10337: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
10338: &js_escape(\$instcode_reserved);
10339: &js_escape(\$communities_reserved);
1.272 raeburn 10340: &js_escape(\$placement_reserved);
1.265 damieng 10341: &js_escape(\$choose_again);
1.49 raeburn 10342: $output = <<"ENDSCRIPT";
10343: <script type="text/javascript">
1.109 raeburn 10344: // <![CDATA[
1.49 raeburn 10345: function reorderCats(form,parent,item,idx) {
10346: var changedVal;
10347: $jstext
10348: var newpos = 'addcategory_pos';
10349: if (parent == '') {
10350: var has_instcode = 0;
10351: var maxtop = categories[idx].length;
10352: for (var j=0; j<maxtop; j++) {
10353: if (categories[idx][j] == 'instcode::0') {
10354: has_instcode == 1;
10355: }
10356: }
10357: if (has_instcode == 0) {
10358: categories[idx][maxtop] = 'instcode_pos';
10359: }
10360: } else {
10361: newpos += '_'+parent;
10362: }
10363: var maxh = 1 + categories[idx].length;
10364: var current = new Array;
10365: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
10366: if (item == newpos) {
10367: changedVal = newitemVal;
10368: } else {
10369: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
10370: current[newitemVal] = newpos;
10371: }
10372: for (var i=0; i<categories[idx].length; i++) {
10373: var elementName = categories[idx][i];
10374: if (elementName != item) {
10375: if (form.elements[elementName]) {
10376: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
10377: current[currVal] = elementName;
10378: }
10379: }
10380: }
10381: var oldVal;
10382: for (var j=0; j<maxh; j++) {
10383: if (current[j] == undefined) {
10384: oldVal = j;
10385: }
10386: }
10387: if (oldVal < changedVal) {
10388: for (var k=oldVal+1; k<=changedVal ; k++) {
10389: var elementName = current[k];
10390: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
10391: }
10392: } else {
10393: for (var k=changedVal; k<oldVal; k++) {
10394: var elementName = current[k];
10395: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
10396: }
10397: }
10398: return;
10399: }
1.120 raeburn 10400:
10401: function categoryCheck(form) {
10402: if (form.elements['addcategory_name'].value == 'instcode') {
10403: alert('$instcode_reserved\\n$choose_again');
10404: return false;
10405: }
10406: if (form.elements['addcategory_name'].value == 'communities') {
10407: alert('$communities_reserved\\n$choose_again');
10408: return false;
10409: }
1.272 raeburn 10410: if (form.elements['addcategory_name'].value == 'placement') {
10411: alert('$placement_reserved\\n$choose_again');
10412: return false;
10413: }
1.120 raeburn 10414: return true;
10415: }
10416:
1.109 raeburn 10417: // ]]>
1.49 raeburn 10418: </script>
10419:
10420: ENDSCRIPT
10421: return $output;
10422: }
10423:
1.48 raeburn 10424: sub initialize_categories {
10425: my ($itemcount) = @_;
1.120 raeburn 10426: my ($datatable,$css_class,$chgstr);
10427: my %default_names = (
10428: instcode => 'Official courses (with institutional codes)',
10429: communities => 'Communities',
1.272 raeburn 10430: placement => 'Placement Tests',
1.120 raeburn 10431: );
1.328 raeburn 10432: my %selnum = (
10433: instcode => '0',
10434: communities => '1',
10435: placement => '2',
10436: );
10437: my %selected;
1.272 raeburn 10438: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 10439: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 10440: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 10441: map { $selected{$selnum{$_}} = '' } keys(%selnum);
10442: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 10443: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 10444: .'<select name="'.$default.'_pos"'.$chgstr.'>'
10445: .'<option value="0"'.$selected{'0'}.'>1</option>'
10446: .'<option value="1"'.$selected{'1'}.'>2</option>'
10447: .'<option value="2"'.$selected{'2'}.'>3</option>'
10448: .'<option value="3">4</option></select> '
1.120 raeburn 10449: .$default_names{$default}
10450: .'</span></td><td><span class="LC_nobreak">'
10451: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
10452: .&mt('Display').'</label> <label>'
10453: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 10454: .'</label></span></td></tr>';
1.120 raeburn 10455: $itemcount ++;
10456: }
1.48 raeburn 10457: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 10458: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 10459: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 10460: .'<select name="addcategory_pos"'.$chgstr.'>'
10461: .'<option value="0">1</option>'
10462: .'<option value="1">2</option>'
1.328 raeburn 10463: .'<option value="2">3</option>'
10464: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 10465: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
10466: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
10467: .'</td></tr>';
1.48 raeburn 10468: return $datatable;
10469: }
10470:
10471: sub build_category_rows {
1.49 raeburn 10472: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
10473: my ($text,$name,$item,$chgstr);
1.48 raeburn 10474: if (ref($cats) eq 'ARRAY') {
10475: my $maxdepth = scalar(@{$cats});
10476: if (ref($cats->[$depth]) eq 'HASH') {
10477: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
10478: my $numchildren = @{$cats->[$depth]{$parent}};
10479: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 10480: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 10481: my ($idxnum,$parent_name,$parent_item);
10482: my $higher = $depth - 1;
10483: if ($higher == 0) {
10484: $parent_name = &escape($parent).'::'.$higher;
10485: } else {
10486: if (ref($path) eq 'ARRAY') {
10487: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
10488: }
10489: }
10490: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 10491: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 10492: if ($j < $numchildren) {
1.48 raeburn 10493: $name = $cats->[$depth]{$parent}[$j];
10494: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 10495: $idxnum = $idx->{$item};
10496: } else {
10497: $name = $parent_name;
10498: $item = $parent_item;
1.48 raeburn 10499: }
1.49 raeburn 10500: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
10501: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 10502: for (my $i=0; $i<=$numchildren; $i++) {
10503: my $vpos = $i+1;
10504: my $selstr;
10505: if ($j == $i) {
10506: $selstr = ' selected="selected" ';
10507: }
10508: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
10509: }
10510: $text .= '</select> ';
10511: if ($j < $numchildren) {
10512: my $deeper = $depth+1;
10513: $text .= $name.' '
10514: .'<label><input type="checkbox" name="deletecategory" value="'
10515: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
10516: if(ref($path) eq 'ARRAY') {
10517: push(@{$path},$name);
1.49 raeburn 10518: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 10519: pop(@{$path});
10520: }
10521: } else {
1.330 raeburn 10522: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 10523: if ($j == $numchildren) {
10524: $text .= $name;
10525: } else {
10526: $text .= $item;
10527: }
10528: $text .= '" value="" />';
10529: }
10530: $text .= '</td></tr>';
10531: }
10532: $text .= '</table></td>';
10533: } else {
10534: my $higher = $depth-1;
10535: if ($higher == 0) {
10536: $name = &escape($parent).'::'.$higher;
10537: } else {
10538: if (ref($path) eq 'ARRAY') {
10539: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
10540: }
10541: }
10542: my $colspan;
10543: if ($parent ne 'instcode') {
10544: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 10545: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 10546: }
10547: }
10548: }
10549: }
10550: return $text;
10551: }
10552:
1.33 raeburn 10553: sub modifiable_userdata_row {
1.305 raeburn 10554: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 10555: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 10556: my ($role,$rolename,$statustype);
10557: $role = $item;
1.224 raeburn 10558: if ($context eq 'cancreate') {
1.305 raeburn 10559: if ($item =~ /^(emailusername)_(.+)$/) {
10560: $role = $1;
10561: $statustype = $2;
1.228 raeburn 10562: if (ref($usertypes) eq 'HASH') {
10563: if ($usertypes->{$statustype}) {
10564: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
10565: } else {
10566: $rolename = &mt('Data provided by user');
10567: }
10568: }
1.224 raeburn 10569: }
10570: } elsif ($context eq 'selfcreate') {
1.63 raeburn 10571: if (ref($usertypes) eq 'HASH') {
10572: $rolename = $usertypes->{$role};
10573: } else {
10574: $rolename = $role;
10575: }
1.325 raeburn 10576: } elsif ($context eq 'lti') {
10577: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 10578: } elsif ($context eq 'privacy') {
10579: $rolename = $itemdesc;
1.33 raeburn 10580: } else {
1.63 raeburn 10581: if ($role eq 'cr') {
10582: $rolename = &mt('Custom role');
10583: } else {
10584: $rolename = &Apache::lonnet::plaintext($role);
10585: }
1.33 raeburn 10586: }
1.224 raeburn 10587: my (@fields,%fieldtitles);
10588: if (ref($fieldsref) eq 'ARRAY') {
10589: @fields = @{$fieldsref};
10590: } else {
10591: @fields = ('lastname','firstname','middlename','generation',
10592: 'permanentemail','id');
10593: }
10594: if ((ref($titlesref) eq 'HASH')) {
10595: %fieldtitles = %{$titlesref};
10596: } else {
10597: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10598: }
1.33 raeburn 10599: my $output;
1.305 raeburn 10600: my $css_class;
10601: if ($rowcount%2) {
10602: $css_class = 'LC_odd_row';
10603: }
10604: if ($customcss) {
10605: $css_class .= " $customcss";
10606: }
10607: $css_class =~ s/^\s+//;
10608: if ($css_class) {
10609: $css_class = ' class="'.$css_class.'"';
10610: }
10611: if ($rowstyle) {
10612: $css_class .= ' style="'.$rowstyle.'"';
10613: }
10614: if ($rowid) {
10615: $rowid = ' id="'.$rowid.'"';
10616: }
10617: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 10618: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
10619: '<td class="LC_left_item" colspan="2"><table>';
10620: my $rem;
10621: my %checks;
1.325 raeburn 10622: my %current;
1.33 raeburn 10623: if (ref($settings) eq 'HASH') {
1.325 raeburn 10624: my $hashref;
10625: if ($context eq 'lti') {
10626: if (ref($settings) eq 'HASH') {
10627: $hashref = $settings->{'instdata'};
10628: }
1.357 raeburn 10629: } elsif ($context eq 'privacy') {
10630: my ($key,$inner) = split(/_/,$role);
10631: if (ref($settings) eq 'HASH') {
10632: if (ref($settings->{$key}) eq 'HASH') {
10633: $hashref = $settings->{$key}->{$inner};
10634: }
10635: }
1.325 raeburn 10636: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 10637: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 10638: $hashref = $settings->{'lti_instdata'};
10639: }
10640: if ($role eq 'emailusername') {
10641: if ($statustype) {
10642: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
10643: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 10644: }
1.325 raeburn 10645: }
10646: }
10647: }
10648: if (ref($hashref) eq 'HASH') {
10649: foreach my $field (@fields) {
10650: if ($hashref->{$field}) {
10651: if ($role eq 'emailusername') {
10652: $checks{$field} = $hashref->{$field};
10653: } else {
10654: $checks{$field} = ' checked="checked" ';
1.33 raeburn 10655: }
10656: }
10657: }
10658: }
10659: }
1.305 raeburn 10660:
10661: my $total = scalar(@fields);
10662: for (my $i=0; $i<$total; $i++) {
10663: $rem = $i%($numinrow);
1.33 raeburn 10664: if ($rem == 0) {
10665: if ($i > 0) {
10666: $output .= '</tr>';
10667: }
10668: $output .= '<tr>';
10669: }
10670: my $check = ' ';
1.228 raeburn 10671: unless ($role eq 'emailusername') {
10672: if (exists($checks{$fields[$i]})) {
1.354 raeburn 10673: $check = $checks{$fields[$i]};
1.357 raeburn 10674: } elsif ($context eq 'privacy') {
10675: if ($role =~ /^priv_(domain|course)$/) {
10676: if (ref($settings) ne 'HASH') {
10677: $check = ' checked="checked" ';
10678: }
10679: } elsif ($role =~ /^priv_(author|community)$/) {
10680: if (ref($settings) ne 'HASH') {
10681: unless ($fields[$i] eq 'id') {
10682: $check = ' checked="checked" ';
10683: }
10684: }
10685: } elsif ($role =~ /^(unpriv|othdom)_/) {
10686: if (ref($settings) ne 'HASH') {
10687: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
10688: $check = ' checked="checked" ';
10689: }
10690: }
10691: }
1.325 raeburn 10692: } elsif ($context ne 'lti') {
1.228 raeburn 10693: if ($role eq 'st') {
10694: if (ref($settings) ne 'HASH') {
10695: $check = ' checked="checked" ';
10696: }
1.33 raeburn 10697: }
10698: }
10699: }
10700: $output .= '<td class="LC_left_item">'.
1.228 raeburn 10701: '<span class="LC_nobreak">';
1.325 raeburn 10702: my $prefix = 'canmodify';
1.228 raeburn 10703: if ($role eq 'emailusername') {
10704: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
10705: $checks{$fields[$i]} = 'omit';
10706: }
10707: foreach my $option ('required','optional','omit') {
10708: my $checked='';
10709: if ($checks{$fields[$i]} eq $option) {
10710: $checked='checked="checked" ';
10711: }
10712: $output .= '<label>'.
1.325 raeburn 10713: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 10714: &mt($option).'</label>'.(' ' x2);
10715: }
10716: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
10717: } else {
1.325 raeburn 10718: if ($context eq 'lti') {
10719: $prefix = 'lti';
1.357 raeburn 10720: } elsif ($context eq 'privacy') {
10721: $prefix = 'privacy';
1.325 raeburn 10722: }
1.228 raeburn 10723: $output .= '<label>'.
1.325 raeburn 10724: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 10725: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
10726: '</label>';
10727: }
10728: $output .= '</span></td>';
1.33 raeburn 10729: }
1.305 raeburn 10730: $rem = $total%$numinrow;
10731: my $colsleft;
10732: if ($rem) {
10733: $colsleft = $numinrow - $rem;
10734: }
10735: if ($colsleft > 1) {
1.33 raeburn 10736: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10737: ' </td>';
10738: } elsif ($colsleft == 1) {
10739: $output .= '<td class="LC_left_item"> </td>';
10740: }
10741: $output .= '</tr></table></td></tr>';
10742: return $output;
10743: }
1.28 raeburn 10744:
1.93 raeburn 10745: sub insttypes_row {
1.305 raeburn 10746: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
10747: $customcss,$rowstyle) = @_;
1.93 raeburn 10748: my %lt = &Apache::lonlocal::texthash (
10749: cansearch => 'Users allowed to search',
10750: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 10751: lockablenames => 'User preference to lock name',
1.305 raeburn 10752: selfassign => 'Self-reportable affiliations',
1.315 raeburn 10753: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 10754: );
10755: my $showdom;
10756: if ($context eq 'cansearch') {
10757: $showdom = ' ('.$dom.')';
10758: }
1.165 raeburn 10759: my $class = 'LC_left_item';
10760: if ($context eq 'statustocreate') {
10761: $class = 'LC_right_item';
10762: }
1.305 raeburn 10763: my $css_class;
10764: if ($$rowtotal%2) {
10765: $css_class = 'LC_odd_row';
10766: }
10767: if ($customcss) {
10768: $css_class .= ' '.$customcss;
10769: }
10770: $css_class =~ s/^\s+//;
10771: if ($css_class) {
10772: $css_class = ' class="'.$css_class.'"';
10773: }
10774: if ($rowstyle) {
10775: $css_class .= ' style="'.$rowstyle.'"';
10776: }
10777: if ($onclick) {
10778: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 10779: }
10780: my $output = '<tr'.$css_class.'>'.
10781: '<td>'.$lt{$context}.$showdom.
10782: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 10783: my $rem;
10784: if (ref($types) eq 'ARRAY') {
10785: for (my $i=0; $i<@{$types}; $i++) {
10786: if (defined($usertypes->{$types->[$i]})) {
10787: my $rem = $i%($numinrow);
10788: if ($rem == 0) {
10789: if ($i > 0) {
10790: $output .= '</tr>';
10791: }
10792: $output .= '<tr>';
1.23 raeburn 10793: }
1.26 raeburn 10794: my $check = ' ';
1.99 raeburn 10795: if (ref($settings) eq 'HASH') {
10796: if (ref($settings->{$context}) eq 'ARRAY') {
10797: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
10798: $check = ' checked="checked" ';
10799: }
1.315 raeburn 10800: } elsif (ref($settings->{$context}) eq 'HASH') {
10801: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
10802: $check = ' checked="checked" ';
10803: }
1.99 raeburn 10804: } elsif ($context eq 'statustocreate') {
1.26 raeburn 10805: $check = ' checked="checked" ';
10806: }
1.23 raeburn 10807: }
1.26 raeburn 10808: $output .= '<td class="LC_left_item">'.
10809: '<span class="LC_nobreak"><label>'.
1.93 raeburn 10810: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 10811: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 10812: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 10813: }
10814: }
1.26 raeburn 10815: $rem = @{$types}%($numinrow);
1.23 raeburn 10816: }
10817: my $colsleft = $numinrow - $rem;
1.315 raeburn 10818: if ($context eq 'overrides') {
10819: if ($colsleft > 1) {
10820: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
10821: } else {
10822: $output .= '<td class="LC_left_item">';
10823: }
10824: $output .= ' ';
1.23 raeburn 10825: } else {
1.334 raeburn 10826: if ($rem == 0) {
1.315 raeburn 10827: $output .= '<tr>';
10828: }
10829: if ($colsleft > 1) {
10830: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
10831: } else {
10832: $output .= '<td class="LC_left_item">';
10833: }
10834: my $defcheck = ' ';
10835: if (ref($settings) eq 'HASH') {
10836: if (ref($settings->{$context}) eq 'ARRAY') {
10837: if (grep(/^default$/,@{$settings->{$context}})) {
10838: $defcheck = ' checked="checked" ';
10839: }
10840: } elsif ($context eq 'statustocreate') {
1.99 raeburn 10841: $defcheck = ' checked="checked" ';
10842: }
1.26 raeburn 10843: }
1.315 raeburn 10844: $output .= '<span class="LC_nobreak"><label>'.
10845: '<input type="checkbox" name="'.$context.'" '.
10846: 'value="default"'.$defcheck.$onclick.' />'.
10847: $othertitle.'</label></span>';
1.23 raeburn 10848: }
1.315 raeburn 10849: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 10850: return $output;
1.23 raeburn 10851: }
10852:
10853: sub sorted_searchtitles {
10854: my %searchtitles = &Apache::lonlocal::texthash(
10855: 'uname' => 'username',
10856: 'lastname' => 'last name',
10857: 'lastfirst' => 'last name, first name',
10858: );
10859: my @titleorder = ('uname','lastname','lastfirst');
10860: return (\%searchtitles,\@titleorder);
10861: }
10862:
1.25 raeburn 10863: sub sorted_searchtypes {
10864: my %srchtypes_desc = (
10865: exact => 'is exact match',
10866: contains => 'contains ..',
10867: begins => 'begins with ..',
10868: );
10869: my @srchtypeorder = ('exact','begins','contains');
10870: return (\%srchtypes_desc,\@srchtypeorder);
10871: }
10872:
1.3 raeburn 10873: sub usertype_update_row {
10874: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
10875: my $datatable;
10876: my $numinrow = 4;
10877: foreach my $type (@{$types}) {
10878: if (defined($usertypes->{$type})) {
10879: $$rownums ++;
10880: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
10881: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
10882: '</td><td class="LC_left_item"><table>';
10883: for (my $i=0; $i<@{$fields}; $i++) {
10884: my $rem = $i%($numinrow);
10885: if ($rem == 0) {
10886: if ($i > 0) {
10887: $datatable .= '</tr>';
10888: }
10889: $datatable .= '<tr>';
10890: }
10891: my $check = ' ';
1.39 raeburn 10892: if (ref($settings) eq 'HASH') {
10893: if (ref($settings->{'fields'}) eq 'HASH') {
10894: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
10895: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
10896: $check = ' checked="checked" ';
10897: }
1.3 raeburn 10898: }
10899: }
10900: }
10901:
10902: if ($i == @{$fields}-1) {
10903: my $colsleft = $numinrow - $rem;
10904: if ($colsleft > 1) {
10905: $datatable .= '<td colspan="'.$colsleft.'">';
10906: } else {
10907: $datatable .= '<td>';
10908: }
10909: } else {
10910: $datatable .= '<td>';
10911: }
1.8 raeburn 10912: $datatable .= '<span class="LC_nobreak"><label>'.
10913: '<input type="checkbox" name="updateable_'.$type.
10914: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
10915: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 10916: }
10917: $datatable .= '</tr></table></td></tr>';
10918: }
10919: }
10920: return $datatable;
1.1 raeburn 10921: }
10922:
10923: sub modify_login {
1.205 raeburn 10924: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 10925: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
10926: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
10927: %title = ( coursecatalog => 'Display course catalog',
10928: adminmail => 'Display administrator E-mail address',
1.188 raeburn 10929: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 10930: newuser => 'Link for visitors to create a user account',
10931: loginheader => 'Log-in box header');
10932: @offon = ('off','on');
1.112 raeburn 10933: if (ref($domconfig{login}) eq 'HASH') {
10934: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
10935: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
10936: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
10937: }
10938: }
10939: }
1.9 raeburn 10940: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
10941: \%domconfig,\%loginhash);
1.188 raeburn 10942: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 10943: foreach my $item (@toggles) {
10944: $loginhash{login}{$item} = $env{'form.'.$item};
10945: }
1.41 raeburn 10946: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 10947: if (ref($colchanges{'login'}) eq 'HASH') {
10948: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
10949: \%loginhash);
10950: }
1.110 raeburn 10951:
1.149 raeburn 10952: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 10953: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 10954: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 10955: if (keys(%servers) > 1) {
10956: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 10957: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
10958: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
10959: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
10960: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
10961: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
10962: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
10963: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
10964: $changes{'loginvia'}{$lonhost} = 1;
10965: } else {
10966: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
10967: $changes{'loginvia'}{$lonhost} = 1;
10968: }
10969: } else {
10970: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
10971: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
10972: $changes{'loginvia'}{$lonhost} = 1;
10973: }
10974: }
10975: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
10976: foreach my $item (@loginvia_attribs) {
10977: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
10978: }
10979: } else {
10980: foreach my $item (@loginvia_attribs) {
10981: my $new = $env{'form.'.$lonhost.'_'.$item};
10982: if (($item eq 'serverpath') && ($new eq 'custom')) {
10983: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
10984: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
10985: $new = '/';
10986: }
10987: }
10988: if (($item eq 'custompath') &&
10989: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
10990: $new = '';
10991: }
10992: if ($new ne $curr_loginvia{$lonhost}{$item}) {
10993: $changes{'loginvia'}{$lonhost} = 1;
10994: }
10995: if ($item eq 'exempt') {
1.256 raeburn 10996: $new = &check_exempt_addresses($new);
1.128 raeburn 10997: }
10998: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
10999: }
11000: }
1.112 raeburn 11001: } else {
1.128 raeburn 11002: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11003: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 11004: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 11005: foreach my $item (@loginvia_attribs) {
11006: my $new = $env{'form.'.$lonhost.'_'.$item};
11007: if (($item eq 'serverpath') && ($new eq 'custom')) {
11008: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
11009: $new = '/';
11010: }
11011: }
11012: if (($item eq 'custompath') &&
11013: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
11014: $new = '';
11015: }
11016: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
11017: }
1.110 raeburn 11018: }
11019: }
11020: }
11021: }
1.119 raeburn 11022:
1.168 raeburn 11023: my $servadm = $r->dir_config('lonAdmEMail');
11024: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
11025: if (ref($domconfig{'login'}) eq 'HASH') {
11026: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
11027: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
11028: if ($lang eq 'nolang') {
11029: push(@currlangs,$lang);
11030: } elsif (defined($langchoices{$lang})) {
11031: push(@currlangs,$lang);
11032: } else {
11033: next;
11034: }
11035: }
11036: }
11037: }
11038: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
11039: if (@currlangs > 0) {
11040: foreach my $lang (@currlangs) {
11041: if (grep(/^\Q$lang\E$/,@delurls)) {
11042: $changes{'helpurl'}{$lang} = 1;
11043: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
11044: $changes{'helpurl'}{$lang} = 1;
11045: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
11046: push(@newlangs,$lang);
11047: } else {
11048: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
11049: }
11050: }
11051: }
11052: unless (grep(/^nolang$/,@currlangs)) {
11053: if ($env{'form.loginhelpurl_nolang.filename'}) {
11054: $changes{'helpurl'}{'nolang'} = 1;
11055: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
11056: push(@newlangs,'nolang');
11057: }
11058: }
11059: if ($env{'form.loginhelpurl_add_lang'}) {
11060: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
11061: ($env{'form.loginhelpurl_add_file.filename'})) {
11062: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
11063: $addedfile = $env{'form.loginhelpurl_add_lang'};
11064: }
11065: }
11066: if ((@newlangs > 0) || ($addedfile)) {
11067: my $error;
11068: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11069: if ($configuserok eq 'ok') {
11070: if ($switchserver) {
11071: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
11072: } elsif ($author_ok eq 'ok') {
11073: my @allnew = @newlangs;
11074: if ($addedfile ne '') {
11075: push(@allnew,$addedfile);
11076: }
11077: foreach my $lang (@allnew) {
11078: my $formelem = 'loginhelpurl_'.$lang;
11079: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
11080: $formelem = 'loginhelpurl_add_file';
11081: }
11082: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
11083: "help/$lang",'','',$newfile{$lang});
11084: if ($result eq 'ok') {
11085: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
11086: $changes{'helpurl'}{$lang} = 1;
11087: } else {
11088: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
11089: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 11090: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 11091: (!grep(/^\Q$lang\E$/,@delurls))) {
11092: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
11093: }
11094: }
11095: }
11096: } else {
11097: $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);
11098: }
11099: } else {
11100: $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);
11101: }
11102: if ($error) {
11103: &Apache::lonnet::logthis($error);
11104: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11105: }
11106: }
1.256 raeburn 11107:
11108: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
11109: if (ref($domconfig{'login'}) eq 'HASH') {
11110: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
11111: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
11112: if ($domservers{$lonhost}) {
11113: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
11114: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 11115: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 11116: }
11117: }
11118: }
11119: }
11120: }
11121: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
11122: foreach my $lonhost (sort(keys(%domservers))) {
11123: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
11124: $changes{'headtag'}{$lonhost} = 1;
11125: } else {
11126: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
11127: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
11128: }
11129: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
11130: push(@newhosts,$lonhost);
11131: } elsif ($currheadtagurls{$lonhost}) {
11132: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
11133: if ($currexempt{$lonhost}) {
1.289 raeburn 11134: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 11135: $changes{'headtag'}{$lonhost} = 1;
11136: }
11137: } elsif ($possexempt{$lonhost}) {
11138: $changes{'headtag'}{$lonhost} = 1;
11139: }
11140: if ($possexempt{$lonhost}) {
11141: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
11142: }
11143: }
11144: }
11145: }
11146: if (@newhosts) {
11147: my $error;
11148: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11149: if ($configuserok eq 'ok') {
11150: if ($switchserver) {
11151: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
11152: } elsif ($author_ok eq 'ok') {
11153: foreach my $lonhost (@newhosts) {
11154: my $formelem = 'loginheadtag_'.$lonhost;
11155: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
11156: "login/headtag/$lonhost",'','',
11157: $env{'form.loginheadtag_'.$lonhost.'.filename'});
11158: if ($result eq 'ok') {
11159: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
11160: $changes{'headtag'}{$lonhost} = 1;
11161: if ($possexempt{$lonhost}) {
11162: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
11163: }
11164: } else {
11165: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
11166: $newheadtagurls{$lonhost},$result);
11167: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
11168: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
11169: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
11170: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
11171: }
11172: }
11173: }
11174: } else {
11175: $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);
11176: }
11177: } else {
11178: $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);
11179: }
11180: if ($error) {
11181: &Apache::lonnet::logthis($error);
11182: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11183: }
11184: }
1.169 raeburn 11185: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 11186:
11187: my $defaulthelpfile = '/adm/loginproblems.html';
11188: my $defaulttext = &mt('Default in use');
11189:
1.1 raeburn 11190: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
11191: $dom);
11192: if ($putresult eq 'ok') {
1.188 raeburn 11193: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 11194: my %defaultchecked = (
11195: 'coursecatalog' => 'on',
1.188 raeburn 11196: 'helpdesk' => 'on',
1.42 raeburn 11197: 'adminmail' => 'off',
1.43 raeburn 11198: 'newuser' => 'off',
1.42 raeburn 11199: );
1.55 raeburn 11200: if (ref($domconfig{'login'}) eq 'HASH') {
11201: foreach my $item (@toggles) {
11202: if ($defaultchecked{$item} eq 'on') {
11203: if (($domconfig{'login'}{$item} eq '0') &&
11204: ($env{'form.'.$item} eq '1')) {
11205: $changes{$item} = 1;
11206: } elsif (($domconfig{'login'}{$item} eq '' ||
11207: $domconfig{'login'}{$item} eq '1') &&
11208: ($env{'form.'.$item} eq '0')) {
11209: $changes{$item} = 1;
11210: }
11211: } elsif ($defaultchecked{$item} eq 'off') {
11212: if (($domconfig{'login'}{$item} eq '1') &&
11213: ($env{'form.'.$item} eq '0')) {
11214: $changes{$item} = 1;
11215: } elsif (($domconfig{'login'}{$item} eq '' ||
11216: $domconfig{'login'}{$item} eq '0') &&
11217: ($env{'form.'.$item} eq '1')) {
11218: $changes{$item} = 1;
11219: }
1.42 raeburn 11220: }
11221: }
1.41 raeburn 11222: }
1.6 raeburn 11223: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 11224: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 11225: if (ref($lastactref) eq 'HASH') {
11226: $lastactref->{'domainconfig'} = 1;
11227: }
1.1 raeburn 11228: $resulttext = &mt('Changes made:').'<ul>';
11229: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 11230: if ($item eq 'loginvia') {
1.112 raeburn 11231: if (ref($changes{$item}) eq 'HASH') {
11232: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
11233: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 11234: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
11235: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
11236: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
11237: $protocol = 'http' if ($protocol ne 'https');
11238: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
11239:
11240: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
11241: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
11242: } else {
11243: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
11244: }
11245: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
11246: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
11247: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
11248: }
11249: $resulttext .= '</li>';
11250: } else {
11251: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
11252: }
1.112 raeburn 11253: } else {
1.128 raeburn 11254: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 11255: }
11256: }
1.128 raeburn 11257: $resulttext .= '</ul></li>';
1.112 raeburn 11258: }
1.168 raeburn 11259: } elsif ($item eq 'helpurl') {
11260: if (ref($changes{$item}) eq 'HASH') {
11261: foreach my $lang (sort(keys(%{$changes{$item}}))) {
11262: if (grep(/^\Q$lang\E$/,@delurls)) {
11263: my ($chg,$link);
11264: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
11265: if ($lang eq 'nolang') {
11266: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
11267: } else {
11268: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
11269: }
11270: $resulttext .= '<li>'.$chg.'</li>';
11271: } else {
11272: my $chg;
11273: if ($lang eq 'nolang') {
11274: $chg = &mt('custom log-in help file for no preferred language');
11275: } else {
11276: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
11277: }
11278: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
11279: $loginhash{'login'}{'helpurl'}{$lang}.
11280: '?inhibitmenu=yes',$chg,600,500).
11281: '</li>';
11282: }
11283: }
11284: }
1.256 raeburn 11285: } elsif ($item eq 'headtag') {
11286: if (ref($changes{$item}) eq 'HASH') {
11287: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
11288: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
11289: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
11290: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
11291: $resulttext .= '<li><a href="'.
11292: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
11293: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
11294: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
11295: if ($possexempt{$lonhost}) {
11296: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
11297: } else {
11298: $resulttext .= &mt('included for any client IP');
11299: }
11300: $resulttext .= '</li>';
11301: }
11302: }
11303: }
1.169 raeburn 11304: } elsif ($item eq 'captcha') {
11305: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 11306: my $chgtxt;
1.169 raeburn 11307: if ($loginhash{'login'}{$item} eq 'notused') {
11308: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
11309: } else {
11310: my %captchas = &captcha_phrases();
11311: if ($captchas{$loginhash{'login'}{$item}}) {
11312: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
11313: } else {
11314: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
11315: }
11316: }
11317: $resulttext .= '<li>'.$chgtxt.'</li>';
11318: }
11319: } elsif ($item eq 'recaptchakeys') {
11320: if (ref($loginhash{'login'}) eq 'HASH') {
11321: my ($privkey,$pubkey);
11322: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
11323: $pubkey = $loginhash{'login'}{$item}{'public'};
11324: $privkey = $loginhash{'login'}{$item}{'private'};
11325: }
11326: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
11327: if (!$pubkey) {
11328: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
11329: } else {
11330: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
11331: }
11332: if (!$privkey) {
11333: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
11334: } else {
1.251 raeburn 11335: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 11336: }
11337: $chgtxt .= '</ul>';
11338: $resulttext .= '<li>'.$chgtxt.'</li>';
11339: }
1.269 raeburn 11340: } elsif ($item eq 'recaptchaversion') {
11341: if (ref($loginhash{'login'}) eq 'HASH') {
11342: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 11343: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 11344: '</li>';
11345: }
11346: }
1.41 raeburn 11347: } else {
11348: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
11349: }
1.1 raeburn 11350: }
1.6 raeburn 11351: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 11352: } else {
11353: $resulttext = &mt('No changes made to log-in page settings');
11354: }
11355: } else {
1.11 albertel 11356: $resulttext = '<span class="LC_error">'.
11357: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11358: }
1.6 raeburn 11359: if ($errors) {
1.9 raeburn 11360: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 11361: $errors.'</ul>';
11362: }
11363: return $resulttext;
11364: }
11365:
1.256 raeburn 11366: sub check_exempt_addresses {
11367: my ($iplist) = @_;
11368: $iplist =~ s/^\s+//;
11369: $iplist =~ s/\s+$//;
11370: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
11371: my (@okips,$new);
11372: foreach my $ip (@poss_ips) {
11373: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
11374: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
11375: push(@okips,$ip);
11376: }
11377: }
11378: }
11379: if (@okips > 0) {
11380: $new = join(',',@okips);
11381: } else {
11382: $new = '';
11383: }
11384: return $new;
11385: }
11386:
1.6 raeburn 11387: sub color_font_choices {
11388: my %choices =
11389: &Apache::lonlocal::texthash (
11390: img => "Header",
11391: bgs => "Background colors",
11392: links => "Link colors",
1.55 raeburn 11393: images => "Images",
1.6 raeburn 11394: font => "Font color",
1.201 raeburn 11395: fontmenu => "Font menu",
1.76 raeburn 11396: pgbg => "Page",
1.6 raeburn 11397: tabbg => "Header",
11398: sidebg => "Border",
11399: link => "Link",
11400: alink => "Active link",
11401: vlink => "Visited link",
11402: );
11403: return %choices;
11404: }
11405:
11406: sub modify_rolecolors {
1.205 raeburn 11407: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 11408: my ($resulttext,%rolehash);
11409: $rolehash{'rolecolors'} = {};
1.55 raeburn 11410: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
11411: if ($domconfig{'rolecolors'} eq '') {
11412: $domconfig{'rolecolors'} = {};
11413: }
11414: }
1.9 raeburn 11415: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 11416: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
11417: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
11418: $dom);
11419: if ($putresult eq 'ok') {
11420: if (keys(%changes) > 0) {
1.41 raeburn 11421: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 11422: if (ref($lastactref) eq 'HASH') {
11423: $lastactref->{'domainconfig'} = 1;
11424: }
1.6 raeburn 11425: $resulttext = &display_colorchgs($dom,\%changes,$roles,
11426: $rolehash{'rolecolors'});
11427: } else {
11428: $resulttext = &mt('No changes made to default color schemes');
11429: }
11430: } else {
1.11 albertel 11431: $resulttext = '<span class="LC_error">'.
11432: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 11433: }
11434: if ($errors) {
11435: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11436: $errors.'</ul>';
11437: }
11438: return $resulttext;
11439: }
11440:
11441: sub modify_colors {
1.9 raeburn 11442: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 11443: my (%changes,%choices);
1.51 raeburn 11444: my @bgs;
1.6 raeburn 11445: my @links = ('link','alink','vlink');
1.41 raeburn 11446: my @logintext;
1.6 raeburn 11447: my @images;
11448: my $servadm = $r->dir_config('lonAdmEMail');
11449: my $errors;
1.200 raeburn 11450: my %defaults;
1.6 raeburn 11451: foreach my $role (@{$roles}) {
11452: if ($role eq 'login') {
1.12 raeburn 11453: %choices = &login_choices();
1.41 raeburn 11454: @logintext = ('textcol','bgcol');
1.12 raeburn 11455: } else {
11456: %choices = &color_font_choices();
11457: }
11458: if ($role eq 'login') {
1.41 raeburn 11459: @images = ('img','logo','domlogo','login');
1.51 raeburn 11460: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 11461: } else {
11462: @images = ('img');
1.200 raeburn 11463: @bgs = ('pgbg','tabbg','sidebg');
11464: }
11465: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
11466: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
11467: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
11468: }
11469: if ($role eq 'login') {
11470: foreach my $item (@logintext) {
1.234 raeburn 11471: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
11472: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
11473: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
11474: }
11475: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 11476: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
11477: }
11478: }
11479: } else {
1.234 raeburn 11480: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
11481: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
11482: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
11483: }
11484: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 11485: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
11486: }
1.6 raeburn 11487: }
1.200 raeburn 11488: foreach my $item (@bgs) {
1.234 raeburn 11489: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
11490: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
11491: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
11492: }
11493: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 11494: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
11495: }
11496: }
11497: foreach my $item (@links) {
1.234 raeburn 11498: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
11499: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
11500: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
11501: }
11502: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 11503: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
11504: }
1.6 raeburn 11505: }
1.46 raeburn 11506: my ($configuserok,$author_ok,$switchserver) =
11507: &config_check($dom,$confname,$servadm);
1.9 raeburn 11508: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 11509: if (ref($domconfig->{$role}) ne 'HASH') {
11510: $domconfig->{$role} = {};
11511: }
1.8 raeburn 11512: foreach my $img (@images) {
1.70 raeburn 11513: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
11514: if (defined($env{'form.login_showlogo_'.$img})) {
11515: $confhash->{$role}{'showlogo'}{$img} = 1;
11516: } else {
11517: $confhash->{$role}{'showlogo'}{$img} = 0;
11518: }
11519: }
1.18 albertel 11520: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
11521: && !defined($domconfig->{$role}{$img})
11522: && !$env{'form.'.$role.'_del_'.$img}
11523: && $env{'form.'.$role.'_import_'.$img}) {
11524: # import the old configured image from the .tab setting
11525: # if they haven't provided a new one
11526: $domconfig->{$role}{$img} =
11527: $env{'form.'.$role.'_import_'.$img};
11528: }
1.6 raeburn 11529: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 11530: my $error;
1.6 raeburn 11531: if ($configuserok eq 'ok') {
1.9 raeburn 11532: if ($switchserver) {
1.12 raeburn 11533: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 11534: } else {
11535: if ($author_ok eq 'ok') {
11536: my ($result,$logourl) =
11537: &publishlogo($r,'upload',$role.'_'.$img,
11538: $dom,$confname,$img,$width,$height);
11539: if ($result eq 'ok') {
11540: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 11541: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 11542: } else {
1.12 raeburn 11543: $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 11544: }
11545: } else {
1.46 raeburn 11546: $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 11547: }
11548: }
11549: } else {
1.46 raeburn 11550: $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 11551: }
11552: if ($error) {
1.8 raeburn 11553: &Apache::lonnet::logthis($error);
1.11 albertel 11554: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 11555: }
11556: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 11557: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
11558: my $error;
11559: if ($configuserok eq 'ok') {
11560: # is confname an author?
11561: if ($switchserver eq '') {
11562: if ($author_ok eq 'ok') {
11563: my ($result,$logourl) =
11564: &publishlogo($r,'copy',$domconfig->{$role}{$img},
11565: $dom,$confname,$img,$width,$height);
11566: if ($result eq 'ok') {
11567: $confhash->{$role}{$img} = $logourl;
1.18 albertel 11568: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 11569: }
11570: }
11571: }
11572: }
1.6 raeburn 11573: }
11574: }
11575: }
11576: if (ref($domconfig) eq 'HASH') {
11577: if (ref($domconfig->{$role}) eq 'HASH') {
11578: foreach my $img (@images) {
11579: if ($domconfig->{$role}{$img} ne '') {
11580: if ($env{'form.'.$role.'_del_'.$img}) {
11581: $confhash->{$role}{$img} = '';
1.12 raeburn 11582: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 11583: } else {
1.9 raeburn 11584: if ($confhash->{$role}{$img} eq '') {
11585: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
11586: }
1.6 raeburn 11587: }
11588: } else {
11589: if ($env{'form.'.$role.'_del_'.$img}) {
11590: $confhash->{$role}{$img} = '';
1.12 raeburn 11591: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 11592: }
11593: }
1.70 raeburn 11594: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
11595: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
11596: if ($confhash->{$role}{'showlogo'}{$img} ne
11597: $domconfig->{$role}{'showlogo'}{$img}) {
11598: $changes{$role}{'showlogo'}{$img} = 1;
11599: }
11600: } else {
11601: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
11602: $changes{$role}{'showlogo'}{$img} = 1;
11603: }
11604: }
11605: }
11606: }
1.6 raeburn 11607: if ($domconfig->{$role}{'font'} ne '') {
11608: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
11609: $changes{$role}{'font'} = 1;
11610: }
11611: } else {
11612: if ($confhash->{$role}{'font'}) {
11613: $changes{$role}{'font'} = 1;
11614: }
11615: }
1.107 raeburn 11616: if ($role ne 'login') {
11617: if ($domconfig->{$role}{'fontmenu'} ne '') {
11618: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
11619: $changes{$role}{'fontmenu'} = 1;
11620: }
11621: } else {
11622: if ($confhash->{$role}{'fontmenu'}) {
11623: $changes{$role}{'fontmenu'} = 1;
11624: }
1.97 tempelho 11625: }
11626: }
1.6 raeburn 11627: foreach my $item (@bgs) {
11628: if ($domconfig->{$role}{$item} ne '') {
11629: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11630: $changes{$role}{'bgs'}{$item} = 1;
11631: }
11632: } else {
11633: if ($confhash->{$role}{$item}) {
11634: $changes{$role}{'bgs'}{$item} = 1;
11635: }
11636: }
11637: }
11638: foreach my $item (@links) {
11639: if ($domconfig->{$role}{$item} ne '') {
11640: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11641: $changes{$role}{'links'}{$item} = 1;
11642: }
11643: } else {
11644: if ($confhash->{$role}{$item}) {
11645: $changes{$role}{'links'}{$item} = 1;
11646: }
11647: }
11648: }
1.41 raeburn 11649: foreach my $item (@logintext) {
11650: if ($domconfig->{$role}{$item} ne '') {
11651: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11652: $changes{$role}{'logintext'}{$item} = 1;
11653: }
11654: } else {
11655: if ($confhash->{$role}{$item}) {
11656: $changes{$role}{'logintext'}{$item} = 1;
11657: }
11658: }
11659: }
1.6 raeburn 11660: } else {
11661: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 11662: \@logintext,$confhash,\%changes);
1.6 raeburn 11663: }
11664: } else {
11665: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 11666: \@logintext,$confhash,\%changes);
1.6 raeburn 11667: }
11668: }
11669: return ($errors,%changes);
11670: }
11671:
1.46 raeburn 11672: sub config_check {
11673: my ($dom,$confname,$servadm) = @_;
11674: my ($configuserok,$author_ok,$switchserver,%currroles);
11675: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
11676: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
11677: $confname,$servadm);
11678: if ($configuserok eq 'ok') {
11679: $switchserver = &check_switchserver($dom,$confname);
11680: if ($switchserver eq '') {
11681: $author_ok = &check_authorstatus($dom,$confname,%currroles);
11682: }
11683: }
11684: return ($configuserok,$author_ok,$switchserver);
11685: }
11686:
1.6 raeburn 11687: sub default_change_checker {
1.41 raeburn 11688: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 11689: foreach my $item (@{$links}) {
11690: if ($confhash->{$role}{$item}) {
11691: $changes->{$role}{'links'}{$item} = 1;
11692: }
11693: }
11694: foreach my $item (@{$bgs}) {
11695: if ($confhash->{$role}{$item}) {
11696: $changes->{$role}{'bgs'}{$item} = 1;
11697: }
11698: }
1.41 raeburn 11699: foreach my $item (@{$logintext}) {
11700: if ($confhash->{$role}{$item}) {
11701: $changes->{$role}{'logintext'}{$item} = 1;
11702: }
11703: }
1.6 raeburn 11704: foreach my $img (@{$images}) {
11705: if ($env{'form.'.$role.'_del_'.$img}) {
11706: $confhash->{$role}{$img} = '';
1.12 raeburn 11707: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 11708: }
1.70 raeburn 11709: if ($role eq 'login') {
11710: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
11711: $changes->{$role}{'showlogo'}{$img} = 1;
11712: }
11713: }
1.6 raeburn 11714: }
11715: if ($confhash->{$role}{'font'}) {
11716: $changes->{$role}{'font'} = 1;
11717: }
1.48 raeburn 11718: }
1.6 raeburn 11719:
11720: sub display_colorchgs {
11721: my ($dom,$changes,$roles,$confhash) = @_;
11722: my (%choices,$resulttext);
11723: if (!grep(/^login$/,@{$roles})) {
11724: $resulttext = &mt('Changes made:').'<br />';
11725: }
11726: foreach my $role (@{$roles}) {
11727: if ($role eq 'login') {
11728: %choices = &login_choices();
11729: } else {
11730: %choices = &color_font_choices();
11731: }
11732: if (ref($changes->{$role}) eq 'HASH') {
11733: if ($role ne 'login') {
11734: $resulttext .= '<h4>'.&mt($role).'</h4>';
11735: }
11736: foreach my $key (sort(keys(%{$changes->{$role}}))) {
11737: if ($role ne 'login') {
11738: $resulttext .= '<ul>';
11739: }
11740: if (ref($changes->{$role}{$key}) eq 'HASH') {
11741: if ($role ne 'login') {
11742: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
11743: }
11744: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 11745: if (($role eq 'login') && ($key eq 'showlogo')) {
11746: if ($confhash->{$role}{$key}{$item}) {
11747: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
11748: } else {
11749: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
11750: }
11751: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 11752: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
11753: } else {
1.12 raeburn 11754: my $newitem = $confhash->{$role}{$item};
11755: if ($key eq 'images') {
1.306 raeburn 11756: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 11757: }
11758: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 11759: }
11760: }
11761: if ($role ne 'login') {
11762: $resulttext .= '</ul></li>';
11763: }
11764: } else {
11765: if ($confhash->{$role}{$key} eq '') {
11766: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
11767: } else {
11768: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
11769: }
11770: }
11771: if ($role ne 'login') {
11772: $resulttext .= '</ul>';
11773: }
11774: }
11775: }
11776: }
1.3 raeburn 11777: return $resulttext;
1.1 raeburn 11778: }
11779:
1.9 raeburn 11780: sub thumb_dimensions {
11781: return ('200','50');
11782: }
11783:
1.16 raeburn 11784: sub check_dimensions {
11785: my ($inputfile) = @_;
11786: my ($fullwidth,$fullheight);
11787: if ($inputfile =~ m|^[/\w.\-]+$|) {
11788: if (open(PIPE,"identify $inputfile 2>&1 |")) {
11789: my $imageinfo = <PIPE>;
11790: if (!close(PIPE)) {
11791: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
11792: }
11793: chomp($imageinfo);
11794: my ($fullsize) =
1.21 raeburn 11795: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 11796: if ($fullsize) {
11797: ($fullwidth,$fullheight) = split(/x/,$fullsize);
11798: }
11799: }
11800: }
11801: return ($fullwidth,$fullheight);
11802: }
11803:
1.9 raeburn 11804: sub check_configuser {
11805: my ($uhome,$dom,$confname,$servadm) = @_;
11806: my ($configuserok,%currroles);
11807: if ($uhome eq 'no_host') {
11808: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 11809: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 11810: $configuserok =
11811: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
11812: $configpass,'','','','','',undef,$servadm);
11813: } else {
11814: $configuserok = 'ok';
11815: %currroles =
11816: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
11817: }
11818: return ($configuserok,%currroles);
11819: }
11820:
11821: sub check_authorstatus {
11822: my ($dom,$confname,%currroles) = @_;
11823: my $author_ok;
1.40 raeburn 11824: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 11825: my $start = time;
11826: my $end = 0;
11827: $author_ok =
11828: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 11829: 'au',$end,$start,'','','domconfig');
1.9 raeburn 11830: } else {
11831: $author_ok = 'ok';
11832: }
11833: return $author_ok;
11834: }
11835:
11836: sub publishlogo {
1.46 raeburn 11837: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 11838: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 11839: if ($action eq 'upload') {
11840: $fname=$env{'form.'.$formname.'.filename'};
11841: chop($env{'form.'.$formname});
11842: } else {
11843: ($fname) = ($formname =~ /([^\/]+)$/);
11844: }
1.46 raeburn 11845: if ($savefileas ne '') {
11846: $fname = $savefileas;
11847: }
1.9 raeburn 11848: $fname=&Apache::lonnet::clean_filename($fname);
11849: # See if there is anything left
11850: unless ($fname) { return ('error: no uploaded file'); }
11851: $fname="$subdir/$fname";
1.210 raeburn 11852: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 11853: my $filepath="$docroot/priv";
11854: my $relpath = "$dom/$confname";
1.9 raeburn 11855: my ($fnamepath,$file,$fetchthumb);
11856: $file=$fname;
11857: if ($fname=~m|/|) {
11858: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
11859: }
1.164 raeburn 11860: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 11861: my $count;
1.164 raeburn 11862: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 11863: $filepath.="/$parts[$count]";
11864: if ((-e $filepath)!=1) {
11865: mkdir($filepath,02770);
11866: }
11867: }
11868: # Check for bad extension and disallow upload
11869: if ($file=~/\.(\w+)$/ &&
11870: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
11871: $output =
1.207 bisitz 11872: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 11873: } elsif ($file=~/\.(\w+)$/ &&
11874: !defined(&Apache::loncommon::fileembstyle($1))) {
11875: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
11876: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 11877: $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 11878: } elsif (-d "$filepath/$file") {
1.195 bisitz 11879: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 11880: } else {
11881: my $source = $filepath.'/'.$file;
11882: my $logfile;
1.316 raeburn 11883: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 11884: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 11885: }
11886: print $logfile
11887: "\n================= Publish ".localtime()." ================\n".
11888: $env{'user.name'}.':'.$env{'user.domain'}."\n";
11889: # Save the file
1.316 raeburn 11890: if (!open(FH,">",$source)) {
1.9 raeburn 11891: &Apache::lonnet::logthis('Failed to create '.$source);
11892: return (&mt('Failed to create file'));
11893: }
11894: if ($action eq 'upload') {
11895: if (!print FH ($env{'form.'.$formname})) {
11896: &Apache::lonnet::logthis('Failed to write to '.$source);
11897: return (&mt('Failed to write file'));
11898: }
11899: } else {
11900: my $original = &Apache::lonnet::filelocation('',$formname);
11901: if(!copy($original,$source)) {
11902: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
11903: return (&mt('Failed to write file'));
11904: }
11905: }
11906: close(FH);
11907: chmod(0660, $source); # Permissions to rw-rw---.
11908:
11909: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
11910: my $copyfile=$targetdir.'/'.$file;
11911:
11912: my @parts=split(/\//,$targetdir);
11913: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
11914: for (my $count=5;$count<=$#parts;$count++) {
11915: $path.="/$parts[$count]";
11916: if (!-e $path) {
11917: print $logfile "\nCreating directory ".$path;
11918: mkdir($path,02770);
11919: }
11920: }
11921: my $versionresult;
11922: if (-e $copyfile) {
11923: $versionresult = &logo_versioning($targetdir,$file,$logfile);
11924: } else {
11925: $versionresult = 'ok';
11926: }
11927: if ($versionresult eq 'ok') {
11928: if (copy($source,$copyfile)) {
11929: print $logfile "\nCopied original source to ".$copyfile."\n";
11930: $output = 'ok';
11931: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 11932: push(@{$modified_urls},[$copyfile,$source]);
11933: my $metaoutput =
11934: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
11935: unless ($registered_cleanup) {
11936: my $handlers = $r->get_handlers('PerlCleanupHandler');
11937: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
11938: $registered_cleanup=1;
11939: }
1.9 raeburn 11940: } else {
11941: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
11942: $output = &mt('Failed to copy file to RES space').", $!";
11943: }
11944: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
11945: my $inputfile = $filepath.'/'.$file;
11946: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 11947: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
11948: if ($fullwidth ne '' && $fullheight ne '') {
11949: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
11950: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 11951: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
11952: system({$args[0]} @args);
1.16 raeburn 11953: chmod(0660, $filepath.'/tn-'.$file);
11954: if (-e $outfile) {
11955: my $copyfile=$targetdir.'/tn-'.$file;
11956: if (copy($outfile,$copyfile)) {
11957: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 11958: my $thumb_metaoutput =
11959: &write_metadata($dom,$confname,$formname,
11960: $targetdir,'tn-'.$file,$logfile);
11961: push(@{$modified_urls},[$copyfile,$outfile]);
11962: unless ($registered_cleanup) {
11963: my $handlers = $r->get_handlers('PerlCleanupHandler');
11964: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
11965: $registered_cleanup=1;
11966: }
1.267 raeburn 11967: $madethumb = 1;
1.16 raeburn 11968: } else {
11969: print $logfile "\nUnable to write ".$copyfile.
11970: ':'.$!."\n";
11971: }
11972: }
1.9 raeburn 11973: }
11974: }
11975: }
11976: } else {
11977: $output = $versionresult;
11978: }
11979: }
1.267 raeburn 11980: return ($output,$logourl,$madethumb);
1.9 raeburn 11981: }
11982:
11983: sub logo_versioning {
11984: my ($targetdir,$file,$logfile) = @_;
11985: my $target = $targetdir.'/'.$file;
11986: my ($maxversion,$fn,$extn,$output);
11987: $maxversion = 0;
11988: if ($file =~ /^(.+)\.(\w+)$/) {
11989: $fn=$1;
11990: $extn=$2;
11991: }
11992: opendir(DIR,$targetdir);
11993: while (my $filename=readdir(DIR)) {
11994: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
11995: $maxversion=($1>$maxversion)?$1:$maxversion;
11996: }
11997: }
11998: $maxversion++;
11999: print $logfile "\nCreating old version ".$maxversion."\n";
12000: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
12001: if (copy($target,$copyfile)) {
12002: print $logfile "Copied old target to ".$copyfile."\n";
12003: $copyfile=$copyfile.'.meta';
12004: if (copy($target.'.meta',$copyfile)) {
12005: print $logfile "Copied old target metadata to ".$copyfile."\n";
12006: $output = 'ok';
12007: } else {
12008: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
12009: $output = &mt('Failed to copy old meta').", $!, ";
12010: }
12011: } else {
12012: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
12013: $output = &mt('Failed to copy old target').", $!, ";
12014: }
12015: return $output;
12016: }
12017:
12018: sub write_metadata {
12019: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
12020: my (%metadatafields,%metadatakeys,$output);
12021: $metadatafields{'title'}=$formname;
12022: $metadatafields{'creationdate'}=time;
12023: $metadatafields{'lastrevisiondate'}=time;
12024: $metadatafields{'copyright'}='public';
12025: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
12026: $env{'user.domain'};
12027: $metadatafields{'authorspace'}=$confname.':'.$dom;
12028: $metadatafields{'domain'}=$dom;
12029: {
12030: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
12031: my $mfh;
1.316 raeburn 12032: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 12033: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 12034: unless ($_=~/\./) {
12035: my $unikey=$_;
12036: $unikey=~/^([A-Za-z]+)/;
12037: my $tag=$1;
12038: $tag=~tr/A-Z/a-z/;
12039: print $mfh "\n\<$tag";
12040: foreach (split(/\,/,$metadatakeys{$unikey})) {
12041: my $value=$metadatafields{$unikey.'.'.$_};
12042: $value=~s/\"/\'\'/g;
12043: print $mfh ' '.$_.'="'.$value.'"';
12044: }
12045: print $mfh '>'.
12046: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
12047: .'</'.$tag.'>';
12048: }
12049: }
12050: $output = 'ok';
12051: print $logfile "\nWrote metadata";
12052: close($mfh);
12053: } else {
12054: print $logfile "\nFailed to open metadata file";
1.9 raeburn 12055: $output = &mt('Could not write metadata');
12056: }
12057: }
1.155 raeburn 12058: return $output;
12059: }
12060:
12061: sub notifysubscribed {
12062: foreach my $targetsource (@{$modified_urls}){
12063: next unless (ref($targetsource) eq 'ARRAY');
12064: my ($target,$source)=@{$targetsource};
12065: if ($source ne '') {
1.316 raeburn 12066: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 12067: print $logfh "\nCleanup phase: Notifications\n";
12068: my @subscribed=&subscribed_hosts($target);
12069: foreach my $subhost (@subscribed) {
12070: print $logfh "\nNotifying host ".$subhost.':';
12071: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
12072: print $logfh $reply;
12073: }
12074: my @subscribedmeta=&subscribed_hosts("$target.meta");
12075: foreach my $subhost (@subscribedmeta) {
12076: print $logfh "\nNotifying host for metadata only ".$subhost.':';
12077: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
12078: $subhost);
12079: print $logfh $reply;
12080: }
12081: print $logfh "\n============ Done ============\n";
1.160 raeburn 12082: close($logfh);
1.155 raeburn 12083: }
12084: }
12085: }
12086: return OK;
12087: }
12088:
12089: sub subscribed_hosts {
12090: my ($target) = @_;
12091: my @subscribed;
1.316 raeburn 12092: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 12093: while (my $subline=<$fh>) {
12094: if ($subline =~ /^($match_lonid):/) {
12095: my $host = $1;
12096: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
12097: unless (grep(/^\Q$host\E$/,@subscribed)) {
12098: push(@subscribed,$host);
12099: }
12100: }
12101: }
12102: }
12103: }
12104: return @subscribed;
1.9 raeburn 12105: }
12106:
12107: sub check_switchserver {
12108: my ($dom,$confname) = @_;
12109: my ($allowed,$switchserver);
12110: my $home = &Apache::lonnet::homeserver($confname,$dom);
12111: if ($home eq 'no_host') {
12112: $home = &Apache::lonnet::domain($dom,'primary');
12113: }
12114: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 12115: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
12116: if (!$allowed) {
1.180 raeburn 12117: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 12118: }
12119: return $switchserver;
12120: }
12121:
1.1 raeburn 12122: sub modify_quotas {
1.216 raeburn 12123: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 12124: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 12125: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 12126: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
12127: $validationfieldsref);
1.86 raeburn 12128: if ($action eq 'quotas') {
12129: $context = 'tools';
1.163 raeburn 12130: } else {
1.86 raeburn 12131: $context = $action;
12132: }
12133: if ($context eq 'requestcourses') {
1.325 raeburn 12134: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 12135: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 12136: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
12137: %titles = &courserequest_titles();
12138: $toolregexp = join('|',@usertools);
12139: %conditions = &courserequest_conditions();
1.216 raeburn 12140: $confname = $dom.'-domainconfig';
12141: my $servadm = $r->dir_config('lonAdmEMail');
12142: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 12143: ($validationitemsref,$validationnamesref,$validationfieldsref) =
12144: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 12145: } elsif ($context eq 'requestauthor') {
12146: @usertools = ('author');
12147: %titles = &authorrequest_titles();
1.86 raeburn 12148: } else {
1.162 raeburn 12149: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 12150: %titles = &tool_titles();
1.86 raeburn 12151: }
1.212 raeburn 12152: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 12153: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 12154: foreach my $key (keys(%env)) {
1.101 raeburn 12155: if ($context eq 'requestcourses') {
12156: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
12157: my $item = $1;
12158: my $type = $2;
12159: if ($type =~ /^limit_(.+)/) {
12160: $limithash{$item}{$1} = $env{$key};
12161: } else {
12162: $confhash{$item}{$type} = $env{$key};
12163: }
12164: }
1.163 raeburn 12165: } elsif ($context eq 'requestauthor') {
12166: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
12167: $confhash{$1} = $env{$key};
12168: }
1.101 raeburn 12169: } else {
1.86 raeburn 12170: if ($key =~ /^form\.quota_(.+)$/) {
12171: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 12172: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
12173: $confhash{'authorquota'}{$1} = $env{$key};
12174: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 12175: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
12176: }
1.72 raeburn 12177: }
12178: }
1.163 raeburn 12179: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 12180: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 12181: @approvalnotify = sort(@approvalnotify);
12182: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 12183: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 12184: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
12185: foreach my $type (@hasuniquecode) {
12186: if (grep(/^\Q$type\E$/,@crstypes)) {
12187: $confhash{'uniquecode'}{$type} = 1;
12188: }
1.216 raeburn 12189: }
1.242 raeburn 12190: my (%newbook,%allpos);
1.216 raeburn 12191: if ($context eq 'requestcourses') {
1.242 raeburn 12192: foreach my $type ('textbooks','templates') {
12193: @{$allpos{$type}} = ();
12194: my $invalid;
12195: if ($type eq 'textbooks') {
12196: $invalid = &mt('Invalid LON-CAPA course for textbook');
12197: } else {
12198: $invalid = &mt('Invalid LON-CAPA course for template');
12199: }
12200: if ($env{'form.'.$type.'_addbook'}) {
12201: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
12202: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
12203: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
12204: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
12205: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
12206: } else {
12207: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
12208: my $position = $env{'form.'.$type.'_addbook_pos'};
12209: $position =~ s/\D+//g;
12210: if ($position ne '') {
12211: $allpos{$type}[$position] = $newbook{$type};
12212: }
1.216 raeburn 12213: }
1.242 raeburn 12214: } else {
12215: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 12216: }
12217: }
1.242 raeburn 12218: }
1.216 raeburn 12219: }
1.102 raeburn 12220: if (ref($domconfig{$action}) eq 'HASH') {
12221: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
12222: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
12223: $changes{'notify'}{'approval'} = 1;
12224: }
12225: } else {
1.144 raeburn 12226: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 12227: $changes{'notify'}{'approval'} = 1;
12228: }
12229: }
1.218 raeburn 12230: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
12231: if (ref($confhash{'uniquecode'}) eq 'HASH') {
12232: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
12233: unless ($confhash{'uniquecode'}{$crstype}) {
12234: $changes{'uniquecode'} = 1;
12235: }
12236: }
12237: unless ($changes{'uniquecode'}) {
12238: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
12239: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
12240: $changes{'uniquecode'} = 1;
12241: }
12242: }
12243: }
12244: } else {
12245: $changes{'uniquecode'} = 1;
12246: }
12247: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
12248: $changes{'uniquecode'} = 1;
1.216 raeburn 12249: }
12250: if ($context eq 'requestcourses') {
1.242 raeburn 12251: foreach my $type ('textbooks','templates') {
12252: if (ref($domconfig{$action}{$type}) eq 'HASH') {
12253: my %deletions;
12254: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
12255: if (@todelete) {
12256: map { $deletions{$_} = 1; } @todelete;
12257: }
12258: my %imgdeletions;
12259: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
12260: if (@todeleteimages) {
12261: map { $imgdeletions{$_} = 1; } @todeleteimages;
12262: }
12263: my $maxnum = $env{'form.'.$type.'_maxnum'};
12264: for (my $i=0; $i<=$maxnum; $i++) {
12265: my $itemid = $env{'form.'.$type.'_id_'.$i};
12266: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
12267: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
12268: if ($deletions{$key}) {
12269: if ($domconfig{$action}{$type}{$key}{'image'}) {
12270: #FIXME need to obsolete item in RES space
12271: }
12272: next;
12273: } else {
12274: my $newpos = $env{'form.'.$itemid};
12275: $newpos =~ s/\D+//g;
1.243 raeburn 12276: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 12277: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 12278: ($type eq 'templates'));
1.242 raeburn 12279: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
12280: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
12281: $changes{$type}{$key} = 1;
12282: }
12283: }
12284: $allpos{$type}[$newpos] = $key;
12285: }
12286: if ($imgdeletions{$key}) {
12287: $changes{$type}{$key} = 1;
1.216 raeburn 12288: #FIXME need to obsolete item in RES space
1.242 raeburn 12289: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
12290: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 12291: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
12292: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
12293: } else {
12294: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
12295: $cdom,$cnum,$type,$configuserok,
12296: $switchserver,$author_ok);
12297: if ($imgurl) {
12298: $confhash{$type}{$key}{'image'} = $imgurl;
12299: $changes{$type}{$key} = 1;
12300: }
12301: if ($error) {
12302: &Apache::lonnet::logthis($error);
12303: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12304: }
12305: }
1.242 raeburn 12306: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
12307: $confhash{$type}{$key}{'image'} =
12308: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 12309: }
12310: }
12311: }
12312: }
12313: }
12314: }
1.102 raeburn 12315: } else {
1.144 raeburn 12316: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 12317: $changes{'notify'}{'approval'} = 1;
12318: }
1.218 raeburn 12319: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 12320: $changes{'uniquecode'} = 1;
12321: }
12322: }
12323: if ($context eq 'requestcourses') {
1.242 raeburn 12324: foreach my $type ('textbooks','templates') {
12325: if ($newbook{$type}) {
12326: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 12327: foreach my $item ('subject','title','publisher','author') {
12328: next if ((($item eq 'author') || ($item eq 'publisher')) &&
12329: ($type eq 'template'));
1.242 raeburn 12330: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
12331: if ($env{'form.'.$type.'_addbook_'.$item}) {
12332: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
12333: }
12334: }
12335: if ($type eq 'textbooks') {
12336: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
12337: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 12338: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
12339: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
12340: } else {
12341: my ($imageurl,$error) =
12342: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
12343: $configuserok,$switchserver,$author_ok);
12344: if ($imageurl) {
12345: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
12346: }
12347: if ($error) {
12348: &Apache::lonnet::logthis($error);
12349: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12350: }
1.242 raeburn 12351: }
12352: }
1.216 raeburn 12353: }
12354: }
1.242 raeburn 12355: if (@{$allpos{$type}} > 0) {
12356: my $idx = 0;
12357: foreach my $item (@{$allpos{$type}}) {
12358: if ($item ne '') {
12359: $confhash{$type}{$item}{'order'} = $idx;
12360: if (ref($domconfig{$action}) eq 'HASH') {
12361: if (ref($domconfig{$action}{$type}) eq 'HASH') {
12362: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
12363: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
12364: $changes{$type}{$item} = 1;
12365: }
1.216 raeburn 12366: }
12367: }
12368: }
1.242 raeburn 12369: $idx ++;
1.216 raeburn 12370: }
12371: }
12372: }
12373: }
1.235 raeburn 12374: if (ref($validationitemsref) eq 'ARRAY') {
12375: foreach my $item (@{$validationitemsref}) {
12376: if ($item eq 'fields') {
12377: my @changed;
12378: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
12379: if (@{$confhash{'validation'}{$item}} > 0) {
12380: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
12381: }
1.266 raeburn 12382: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12383: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12384: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
12385: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
12386: $domconfig{'requestcourses'}{'validation'}{$item});
12387: } else {
12388: @changed = @{$confhash{'validation'}{$item}};
12389: }
1.235 raeburn 12390: } else {
12391: @changed = @{$confhash{'validation'}{$item}};
12392: }
12393: } else {
12394: @changed = @{$confhash{'validation'}{$item}};
12395: }
12396: if (@changed) {
12397: if ($confhash{'validation'}{$item}) {
12398: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
12399: } else {
12400: $changes{'validation'}{$item} = &mt('None');
12401: }
12402: }
12403: } else {
12404: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
12405: if ($item eq 'markup') {
12406: if ($env{'form.requestcourses_validation_'.$item}) {
12407: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
12408: }
12409: }
1.266 raeburn 12410: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12411: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12412: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
12413: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
12414: }
12415: } else {
12416: if ($confhash{'validation'}{$item} ne '') {
12417: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
12418: }
1.235 raeburn 12419: }
12420: } else {
12421: if ($confhash{'validation'}{$item} ne '') {
12422: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
12423: }
12424: }
12425: }
12426: }
12427: }
12428: if ($env{'form.validationdc'}) {
12429: my $newval = $env{'form.validationdc'};
1.285 raeburn 12430: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 12431: if (exists($domcoords{$newval})) {
12432: $confhash{'validation'}{'dc'} = $newval;
12433: }
12434: }
12435: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 12436: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12437: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12438: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
12439: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
12440: if ($confhash{'validation'}{'dc'} eq '') {
12441: $changes{'validation'}{'dc'} = &mt('None');
12442: } else {
12443: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
12444: }
1.235 raeburn 12445: }
1.266 raeburn 12446: } elsif ($confhash{'validation'}{'dc'} ne '') {
12447: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 12448: }
12449: } elsif ($confhash{'validation'}{'dc'} ne '') {
12450: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
12451: }
12452: } elsif ($confhash{'validation'}{'dc'} ne '') {
12453: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 12454: }
1.266 raeburn 12455: } else {
12456: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12457: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12458: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
12459: $changes{'validation'}{'dc'} = &mt('None');
12460: }
12461: }
1.235 raeburn 12462: }
12463: }
1.102 raeburn 12464: }
12465: } else {
1.86 raeburn 12466: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 12467: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 12468: }
1.72 raeburn 12469: foreach my $item (@usertools) {
12470: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 12471: my $unset;
1.101 raeburn 12472: if ($context eq 'requestcourses') {
1.104 raeburn 12473: $unset = '0';
12474: if ($type eq '_LC_adv') {
12475: $unset = '';
12476: }
1.101 raeburn 12477: if ($confhash{$item}{$type} eq 'autolimit') {
12478: $confhash{$item}{$type} .= '=';
12479: unless ($limithash{$item}{$type} =~ /\D/) {
12480: $confhash{$item}{$type} .= $limithash{$item}{$type};
12481: }
12482: }
1.163 raeburn 12483: } elsif ($context eq 'requestauthor') {
12484: $unset = '0';
12485: if ($type eq '_LC_adv') {
12486: $unset = '';
12487: }
1.72 raeburn 12488: } else {
1.101 raeburn 12489: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
12490: $confhash{$item}{$type} = 1;
12491: } else {
12492: $confhash{$item}{$type} = 0;
12493: }
1.72 raeburn 12494: }
1.86 raeburn 12495: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 12496: if ($action eq 'requestauthor') {
12497: if ($domconfig{$action}{$type} ne $confhash{$type}) {
12498: $changes{$type} = 1;
12499: }
12500: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 12501: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
12502: $changes{$item}{$type} = 1;
12503: }
12504: } else {
12505: if ($context eq 'requestcourses') {
1.104 raeburn 12506: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 12507: $changes{$item}{$type} = 1;
12508: }
12509: } else {
12510: if (!$confhash{$item}{$type}) {
12511: $changes{$item}{$type} = 1;
12512: }
12513: }
12514: }
12515: } else {
12516: if ($context eq 'requestcourses') {
1.104 raeburn 12517: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 12518: $changes{$item}{$type} = 1;
12519: }
1.163 raeburn 12520: } elsif ($context eq 'requestauthor') {
12521: if ($confhash{$type} ne $unset) {
12522: $changes{$type} = 1;
12523: }
1.72 raeburn 12524: } else {
12525: if (!$confhash{$item}{$type}) {
12526: $changes{$item}{$type} = 1;
12527: }
12528: }
12529: }
1.1 raeburn 12530: }
12531: }
1.163 raeburn 12532: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 12533: if (ref($domconfig{'quotas'}) eq 'HASH') {
12534: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
12535: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
12536: if (exists($confhash{'defaultquota'}{$key})) {
12537: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
12538: $changes{'defaultquota'}{$key} = 1;
12539: }
12540: } else {
12541: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 12542: }
12543: }
1.86 raeburn 12544: } else {
12545: foreach my $key (keys(%{$domconfig{'quotas'}})) {
12546: if (exists($confhash{'defaultquota'}{$key})) {
12547: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
12548: $changes{'defaultquota'}{$key} = 1;
12549: }
12550: } else {
12551: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 12552: }
1.1 raeburn 12553: }
12554: }
1.197 raeburn 12555: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
12556: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
12557: if (exists($confhash{'authorquota'}{$key})) {
12558: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
12559: $changes{'authorquota'}{$key} = 1;
12560: }
12561: } else {
12562: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
12563: }
12564: }
12565: }
1.1 raeburn 12566: }
1.86 raeburn 12567: if (ref($confhash{'defaultquota'}) eq 'HASH') {
12568: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
12569: if (ref($domconfig{'quotas'}) eq 'HASH') {
12570: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
12571: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
12572: $changes{'defaultquota'}{$key} = 1;
12573: }
12574: } else {
12575: if (!exists($domconfig{'quotas'}{$key})) {
12576: $changes{'defaultquota'}{$key} = 1;
12577: }
1.72 raeburn 12578: }
12579: } else {
1.86 raeburn 12580: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 12581: }
1.1 raeburn 12582: }
12583: }
1.197 raeburn 12584: if (ref($confhash{'authorquota'}) eq 'HASH') {
12585: foreach my $key (keys(%{$confhash{'authorquota'}})) {
12586: if (ref($domconfig{'quotas'}) eq 'HASH') {
12587: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
12588: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
12589: $changes{'authorquota'}{$key} = 1;
12590: }
12591: } else {
12592: $changes{'authorquota'}{$key} = 1;
12593: }
12594: } else {
12595: $changes{'authorquota'}{$key} = 1;
12596: }
12597: }
12598: }
1.1 raeburn 12599: }
1.72 raeburn 12600:
1.163 raeburn 12601: if ($context eq 'requestauthor') {
12602: $domdefaults{'requestauthor'} = \%confhash;
12603: } else {
12604: foreach my $key (keys(%confhash)) {
1.242 raeburn 12605: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 12606: $domdefaults{$key} = $confhash{$key};
12607: }
1.163 raeburn 12608: }
1.72 raeburn 12609: }
1.163 raeburn 12610:
1.1 raeburn 12611: my %quotahash = (
1.86 raeburn 12612: $action => { %confhash }
1.1 raeburn 12613: );
12614: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
12615: $dom);
12616: if ($putresult eq 'ok') {
12617: if (keys(%changes) > 0) {
1.72 raeburn 12618: my $cachetime = 24*60*60;
12619: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 12620: if (ref($lastactref) eq 'HASH') {
12621: $lastactref->{'domdefaults'} = 1;
12622: }
1.1 raeburn 12623: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 12624: unless (($context eq 'requestcourses') ||
1.163 raeburn 12625: ($context eq 'requestauthor')) {
1.86 raeburn 12626: if (ref($changes{'defaultquota'}) eq 'HASH') {
12627: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
12628: foreach my $type (@{$types},'default') {
12629: if (defined($changes{'defaultquota'}{$type})) {
12630: my $typetitle = $usertypes->{$type};
12631: if ($type eq 'default') {
12632: $typetitle = $othertitle;
12633: }
1.213 raeburn 12634: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 12635: }
12636: }
1.86 raeburn 12637: $resulttext .= '</ul></li>';
1.72 raeburn 12638: }
1.197 raeburn 12639: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 12640: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 12641: foreach my $type (@{$types},'default') {
12642: if (defined($changes{'authorquota'}{$type})) {
12643: my $typetitle = $usertypes->{$type};
12644: if ($type eq 'default') {
12645: $typetitle = $othertitle;
12646: }
1.213 raeburn 12647: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 12648: }
12649: }
12650: $resulttext .= '</ul></li>';
12651: }
1.72 raeburn 12652: }
1.80 raeburn 12653: my %newenv;
1.72 raeburn 12654: foreach my $item (@usertools) {
1.163 raeburn 12655: my (%haschgs,%inconf);
12656: if ($context eq 'requestauthor') {
12657: %haschgs = %changes;
1.210 raeburn 12658: %inconf = %confhash;
1.163 raeburn 12659: } else {
12660: if (ref($changes{$item}) eq 'HASH') {
12661: %haschgs = %{$changes{$item}};
12662: }
12663: if (ref($confhash{$item}) eq 'HASH') {
12664: %inconf = %{$confhash{$item}};
12665: }
12666: }
12667: if (keys(%haschgs) > 0) {
1.80 raeburn 12668: my $newacc =
12669: &Apache::lonnet::usertools_access($env{'user.name'},
12670: $env{'user.domain'},
1.86 raeburn 12671: $item,'reload',$context);
1.210 raeburn 12672: if (($context eq 'requestcourses') ||
1.163 raeburn 12673: ($context eq 'requestauthor')) {
1.108 raeburn 12674: if ($env{'environment.canrequest.'.$item} ne $newacc) {
12675: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 12676: }
12677: } else {
12678: if ($env{'environment.availabletools.'.$item} ne $newacc) {
12679: $newenv{'environment.availabletools.'.$item} = $newacc;
12680: }
1.80 raeburn 12681: }
1.163 raeburn 12682: unless ($context eq 'requestauthor') {
12683: $resulttext .= '<li>'.$titles{$item}.'<ul>';
12684: }
1.72 raeburn 12685: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 12686: if ($haschgs{$type}) {
1.72 raeburn 12687: my $typetitle = $usertypes->{$type};
12688: if ($type eq 'default') {
12689: $typetitle = $othertitle;
12690: } elsif ($type eq '_LC_adv') {
12691: $typetitle = 'LON-CAPA Advanced Users';
12692: }
1.163 raeburn 12693: if ($inconf{$type}) {
1.101 raeburn 12694: if ($context eq 'requestcourses') {
12695: my $cond;
1.163 raeburn 12696: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 12697: if ($1 eq '') {
12698: $cond = &mt('(Automatic processing of any request).');
12699: } else {
12700: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
12701: }
12702: } else {
1.163 raeburn 12703: $cond = $conditions{$inconf{$type}};
1.101 raeburn 12704: }
12705: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 12706: } elsif ($context eq 'requestauthor') {
12707: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
12708: $titles{$inconf{$type}},$typetitle);
12709:
1.101 raeburn 12710: } else {
12711: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
12712: }
1.72 raeburn 12713: } else {
1.104 raeburn 12714: if ($type eq '_LC_adv') {
1.163 raeburn 12715: if ($inconf{$type} eq '0') {
1.104 raeburn 12716: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
12717: } else {
12718: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
12719: }
12720: } else {
12721: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
12722: }
1.72 raeburn 12723: }
12724: }
1.26 raeburn 12725: }
1.163 raeburn 12726: unless ($context eq 'requestauthor') {
12727: $resulttext .= '</ul></li>';
12728: }
1.26 raeburn 12729: }
1.1 raeburn 12730: }
1.163 raeburn 12731: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 12732: if (ref($changes{'notify'}) eq 'HASH') {
12733: if ($changes{'notify'}{'approval'}) {
12734: if (ref($confhash{'notify'}) eq 'HASH') {
12735: if ($confhash{'notify'}{'approval'}) {
12736: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
12737: } else {
1.163 raeburn 12738: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 12739: }
12740: }
12741: }
12742: }
12743: }
1.216 raeburn 12744: if ($action eq 'requestcourses') {
12745: my @offon = ('off','on');
12746: if ($changes{'uniquecode'}) {
1.218 raeburn 12747: if (ref($confhash{'uniquecode'}) eq 'HASH') {
12748: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
12749: $resulttext .= '<li>'.
12750: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
12751: '</li>';
12752: } else {
12753: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
12754: '</li>';
12755: }
1.216 raeburn 12756: }
1.242 raeburn 12757: foreach my $type ('textbooks','templates') {
12758: if (ref($changes{$type}) eq 'HASH') {
12759: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
12760: foreach my $key (sort(keys(%{$changes{$type}}))) {
12761: my %coursehash = &Apache::lonnet::coursedescription($key);
12762: my $coursetitle = $coursehash{'description'};
12763: my $position = $confhash{$type}{$key}{'order'} + 1;
12764: $resulttext .= '<li>';
1.243 raeburn 12765: foreach my $item ('subject','title','publisher','author') {
12766: next if ((($item eq 'author') || ($item eq 'publisher')) &&
12767: ($type eq 'templates'));
1.242 raeburn 12768: my $name = $item.':';
12769: $name =~ s/^(\w)/\U$1/;
12770: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
12771: }
12772: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
12773: if ($type eq 'textbooks') {
12774: if ($confhash{$type}{$key}{'image'}) {
12775: $resulttext .= ' '.&mt('Image: [_1]',
12776: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
12777: ' alt="Textbook cover" />').'<br />';
12778: }
12779: }
12780: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 12781: }
1.242 raeburn 12782: $resulttext .= '</ul></li>';
1.216 raeburn 12783: }
12784: }
1.235 raeburn 12785: if (ref($changes{'validation'}) eq 'HASH') {
12786: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
12787: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
12788: foreach my $item (@{$validationitemsref}) {
12789: if (exists($changes{'validation'}{$item})) {
12790: if ($item eq 'markup') {
12791: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
12792: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
12793: } else {
12794: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
12795: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
12796: }
12797: }
12798: }
12799: if (exists($changes{'validation'}{'dc'})) {
12800: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
12801: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
12802: }
12803: }
12804: }
1.216 raeburn 12805: }
1.1 raeburn 12806: $resulttext .= '</ul>';
1.80 raeburn 12807: if (keys(%newenv)) {
12808: &Apache::lonnet::appenv(\%newenv);
12809: }
1.1 raeburn 12810: } else {
1.86 raeburn 12811: if ($context eq 'requestcourses') {
12812: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 12813: } elsif ($context eq 'requestauthor') {
12814: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 12815: } else {
1.90 weissno 12816: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 12817: }
1.1 raeburn 12818: }
12819: } else {
1.11 albertel 12820: $resulttext = '<span class="LC_error">'.
12821: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12822: }
1.216 raeburn 12823: if ($errors) {
12824: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
12825: '<ul>'.$errors.'</ul></p>';
12826: }
1.3 raeburn 12827: return $resulttext;
1.1 raeburn 12828: }
12829:
1.216 raeburn 12830: sub process_textbook_image {
1.242 raeburn 12831: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 12832: my $filename = $env{'form.'.$caller.'.filename'};
12833: my ($error,$url);
12834: my ($width,$height) = (50,50);
12835: if ($configuserok eq 'ok') {
12836: if ($switchserver) {
12837: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
12838: $switchserver);
12839: } elsif ($author_ok eq 'ok') {
12840: my ($result,$imageurl) =
12841: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 12842: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 12843: if ($result eq 'ok') {
12844: $url = $imageurl;
12845: } else {
12846: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
12847: }
12848: } else {
12849: $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);
12850: }
12851: } else {
12852: $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);
12853: }
12854: return ($url,$error);
12855: }
12856:
1.267 raeburn 12857: sub modify_ltitools {
12858: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
12859: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 12860: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 12861: my $confname = $dom.'-domainconfig';
12862: my $servadm = $r->dir_config('lonAdmEMail');
12863: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12864: my (%posslti,%possfield);
12865: my @courseroles = ('cc','in','ta','ep','st');
12866: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
12867: map { $posslti{$_} = 1; } @ltiroles;
12868: my @allfields = ('fullname','firstname','lastname','email','user','roles');
12869: map { $possfield{$_} = 1; } @allfields;
12870: my %lt = <itools_names();
12871: if ($env{'form.ltitools_add'}) {
12872: my $title = $env{'form.ltitools_add_title'};
12873: $title =~ s/(`)/'/g;
12874: ($newid,my $error) = &get_ltitools_id($dom,$title);
12875: if ($newid) {
12876: my $position = $env{'form.ltitools_add_pos'};
12877: $position =~ s/\D+//g;
12878: if ($position ne '') {
12879: $allpos[$position] = $newid;
12880: }
12881: $changes{$newid} = 1;
1.322 raeburn 12882: foreach my $item ('title','url','key','secret','lifetime') {
1.267 raeburn 12883: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322 raeburn 12884: if ($item eq 'lifetime') {
12885: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
12886: }
1.267 raeburn 12887: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 12888: if (($item eq 'key') || ($item eq 'secret')) {
12889: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
12890: } else {
12891: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
12892: }
1.267 raeburn 12893: }
12894: }
12895: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
12896: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
12897: }
12898: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
12899: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
12900: }
1.323 raeburn 12901: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
12902: $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
12903: } else {
12904: $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
12905: }
1.296 raeburn 12906: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 12907: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
12908: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 12909: if (($item eq 'width') || ($item eq 'height')) {
12910: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
12911: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
12912: }
12913: } else {
12914: if ($env{'form.ltitools_add_'.$item} ne '') {
12915: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
12916: }
1.267 raeburn 12917: }
12918: }
12919: if ($env{'form.ltitools_add_target'} eq 'window') {
12920: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 12921: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
12922: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 12923: } else {
12924: $confhash{$newid}{'display'}{'target'} = 'iframe';
12925: }
12926: foreach my $item ('passback','roster') {
1.319 raeburn 12927: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 12928: $confhash{$newid}{$item} = 1;
1.319 raeburn 12929: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
12930: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
12931: $lifetime =~ s/^\s+|\s+$//g;
12932: if ($lifetime =~ /^\d+\.?\d*$/) {
12933: $confhash{$newid}{$item.'valid'} = $lifetime;
12934: }
12935: }
1.267 raeburn 12936: }
12937: }
12938: if ($env{'form.ltitools_add_image.filename'} ne '') {
12939: my ($imageurl,$error) =
1.307 raeburn 12940: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 12941: $configuserok,$switchserver,$author_ok);
12942: if ($imageurl) {
12943: $confhash{$newid}{'image'} = $imageurl;
12944: }
12945: if ($error) {
12946: &Apache::lonnet::logthis($error);
12947: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12948: }
12949: }
12950: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
12951: foreach my $field (@fields) {
12952: if ($possfield{$field}) {
12953: if ($field eq 'roles') {
12954: foreach my $role (@courseroles) {
12955: my $choice = $env{'form.ltitools_add_roles_'.$role};
12956: if (($choice ne '') && ($posslti{$choice})) {
12957: $confhash{$newid}{'roles'}{$role} = $choice;
12958: if ($role eq 'cc') {
12959: $confhash{$newid}{'roles'}{'co'} = $choice;
12960: }
12961: }
12962: }
12963: } else {
12964: $confhash{$newid}{'fields'}{$field} = 1;
12965: }
12966: }
12967: }
1.324 raeburn 12968: if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
12969: if ($confhash{$newid}{'fields'}{'user'}) {
12970: if ($env{'form.ltitools_userincdom_add'}) {
12971: $confhash{$newid}{'incdom'} = 1;
12972: }
12973: }
12974: }
1.273 raeburn 12975: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
12976: foreach my $item (@courseconfig) {
12977: $confhash{$newid}{'crsconf'}{$item} = 1;
12978: }
1.267 raeburn 12979: if ($env{'form.ltitools_add_custom'}) {
12980: my $name = $env{'form.ltitools_add_custom_name'};
12981: my $value = $env{'form.ltitools_add_custom_value'};
12982: $value =~ s/(`)/'/g;
12983: $name =~ s/(`)/'/g;
12984: $confhash{$newid}{'custom'}{$name} = $value;
12985: }
12986: } else {
12987: my $error = &mt('Failed to acquire unique ID for new external tool');
12988: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12989: }
12990: }
12991: if (ref($domconfig{$action}) eq 'HASH') {
12992: my %deletions;
12993: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
12994: if (@todelete) {
12995: map { $deletions{$_} = 1; } @todelete;
12996: }
12997: my %customadds;
12998: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
12999: if (@newcustom) {
13000: map { $customadds{$_} = 1; } @newcustom;
13001: }
13002: my %imgdeletions;
13003: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
13004: if (@todeleteimages) {
13005: map { $imgdeletions{$_} = 1; } @todeleteimages;
13006: }
13007: my $maxnum = $env{'form.ltitools_maxnum'};
13008: for (my $i=0; $i<=$maxnum; $i++) {
13009: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 13010: $itemid =~ s/\D+//g;
1.267 raeburn 13011: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
13012: if ($deletions{$itemid}) {
13013: if ($domconfig{$action}{$itemid}{'image'}) {
13014: #FIXME need to obsolete item in RES space
13015: }
13016: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
13017: next;
13018: } else {
13019: my $newpos = $env{'form.ltitools_'.$itemid};
13020: $newpos =~ s/\D+//g;
1.322 raeburn 13021: foreach my $item ('title','url','lifetime') {
1.267 raeburn 13022: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
13023: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
13024: $changes{$itemid} = 1;
13025: }
13026: }
1.297 raeburn 13027: foreach my $item ('key','secret') {
13028: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
13029: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
13030: $changes{$itemid} = 1;
13031: }
13032: }
1.267 raeburn 13033: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
13034: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
13035: }
13036: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
13037: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
13038: }
1.323 raeburn 13039: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
13040: $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
13041: } else {
13042: $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
13043: }
13044: if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
13045: if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
13046: $changes{$itemid} = 1;
13047: }
13048: } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
13049: $changes{$itemid} = 1;
13050: }
1.267 raeburn 13051: foreach my $size ('width','height') {
13052: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
13053: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
13054: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
13055: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
13056: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13057: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
13058: $changes{$itemid} = 1;
13059: }
13060: } else {
13061: $changes{$itemid} = 1;
13062: }
1.296 raeburn 13063: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13064: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
13065: $changes{$itemid} = 1;
13066: }
13067: }
13068: }
13069: foreach my $item ('linktext','explanation') {
13070: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
13071: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
13072: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
13073: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
13074: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13075: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
13076: $changes{$itemid} = 1;
13077: }
13078: } else {
13079: $changes{$itemid} = 1;
13080: }
13081: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13082: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
13083: $changes{$itemid} = 1;
13084: }
1.267 raeburn 13085: }
13086: }
13087: if ($env{'form.ltitools_target_'.$i} eq 'window') {
13088: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 13089: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
13090: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 13091: } else {
13092: $confhash{$itemid}{'display'}{'target'} = 'iframe';
13093: }
13094: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13095: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
13096: $changes{$itemid} = 1;
13097: }
13098: } else {
13099: $changes{$itemid} = 1;
13100: }
13101: foreach my $extra ('passback','roster') {
13102: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
13103: $confhash{$itemid}{$extra} = 1;
1.319 raeburn 13104: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
1.338 raeburn 13105: my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
1.319 raeburn 13106: $lifetime =~ s/^\s+|\s+$//g;
13107: if ($lifetime =~ /^\d+\.?\d*$/) {
13108: $confhash{$itemid}{$extra.'valid'} = $lifetime;
13109: }
13110: }
1.267 raeburn 13111: }
13112: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
13113: $changes{$itemid} = 1;
13114: }
1.319 raeburn 13115: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
13116: $changes{$itemid} = 1;
13117: }
1.267 raeburn 13118: }
1.273 raeburn 13119: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 13120: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 13121: if (grep(/^\Q$item\E$/,@courseconfig)) {
13122: $confhash{$itemid}{'crsconf'}{$item} = 1;
13123: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
13124: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
13125: $changes{$itemid} = 1;
13126: }
13127: } else {
13128: $changes{$itemid} = 1;
13129: }
13130: }
13131: }
1.267 raeburn 13132: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
13133: foreach my $field (@fields) {
13134: if ($possfield{$field}) {
13135: if ($field eq 'roles') {
13136: foreach my $role (@courseroles) {
13137: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
13138: if (($choice ne '') && ($posslti{$choice})) {
13139: $confhash{$itemid}{'roles'}{$role} = $choice;
13140: if ($role eq 'cc') {
13141: $confhash{$itemid}{'roles'}{'co'} = $choice;
13142: }
13143: }
13144: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
13145: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
13146: $changes{$itemid} = 1;
13147: }
13148: } elsif ($confhash{$itemid}{'roles'}{$role}) {
13149: $changes{$itemid} = 1;
13150: }
13151: }
13152: } else {
13153: $confhash{$itemid}{'fields'}{$field} = 1;
13154: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
13155: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
13156: $changes{$itemid} = 1;
13157: }
13158: } else {
13159: $changes{$itemid} = 1;
13160: }
13161: }
13162: }
13163: }
1.324 raeburn 13164: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
13165: if ($confhash{$itemid}{'fields'}{'user'}) {
13166: if ($env{'form.ltitools_userincdom_'.$i}) {
13167: $confhash{$itemid}{'incdom'} = 1;
13168: }
13169: if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
13170: $changes{$itemid} = 1;
13171: }
13172: }
13173: }
1.267 raeburn 13174: $allpos[$newpos] = $itemid;
13175: }
13176: if ($imgdeletions{$itemid}) {
13177: $changes{$itemid} = 1;
13178: #FIXME need to obsolete item in RES space
13179: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
13180: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
13181: $itemid,$configuserok,$switchserver,
13182: $author_ok);
13183: if ($imgurl) {
13184: $confhash{$itemid}{'image'} = $imgurl;
13185: $changes{$itemid} = 1;
13186: }
13187: if ($error) {
13188: &Apache::lonnet::logthis($error);
13189: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13190: }
13191: } elsif ($domconfig{$action}{$itemid}{'image'}) {
13192: $confhash{$itemid}{'image'} =
13193: $domconfig{$action}{$itemid}{'image'};
13194: }
13195: if ($customadds{$i}) {
13196: my $name = $env{'form.ltitools_custom_name_'.$i};
13197: $name =~ s/(`)/'/g;
13198: $name =~ s/^\s+//;
13199: $name =~ s/\s+$//;
13200: my $value = $env{'form.ltitools_custom_value_'.$i};
13201: $value =~ s/(`)/'/g;
13202: $value =~ s/^\s+//;
13203: $value =~ s/\s+$//;
13204: if ($name ne '') {
13205: $confhash{$itemid}{'custom'}{$name} = $value;
13206: $changes{$itemid} = 1;
13207: }
13208: }
13209: my %customdels;
13210: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
13211: if (@customdeletions) {
13212: $changes{$itemid} = 1;
13213: }
13214: map { $customdels{$_} = 1; } @customdeletions;
13215: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
13216: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
13217: unless ($customdels{$key}) {
13218: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
13219: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
13220: }
13221: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
13222: $changes{$itemid} = 1;
13223: }
13224: }
13225: }
13226: }
13227: unless ($changes{$itemid}) {
13228: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
13229: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
13230: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
13231: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
13232: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
13233: $changes{$itemid} = 1;
13234: last;
13235: }
13236: }
13237: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
13238: $changes{$itemid} = 1;
13239: }
13240: }
13241: last if ($changes{$itemid});
13242: }
13243: }
13244: }
13245: }
13246: }
13247: if (@allpos > 0) {
13248: my $idx = 0;
13249: foreach my $itemid (@allpos) {
13250: if ($itemid ne '') {
13251: $confhash{$itemid}{'order'} = $idx;
13252: if (ref($domconfig{$action}) eq 'HASH') {
13253: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
13254: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
13255: $changes{$itemid} = 1;
13256: }
13257: }
13258: }
13259: $idx ++;
13260: }
13261: }
13262: }
13263: my %ltitoolshash = (
13264: $action => { %confhash }
13265: );
13266: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
13267: $dom);
13268: if ($putresult eq 'ok') {
1.297 raeburn 13269: my %ltienchash = (
13270: $action => { %encconfig }
13271: );
13272: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267 raeburn 13273: if (keys(%changes) > 0) {
13274: my $cachetime = 24*60*60;
1.297 raeburn 13275: my %ltiall = %confhash;
13276: foreach my $id (keys(%ltiall)) {
13277: if (ref($encconfig{$id}) eq 'HASH') {
13278: foreach my $item ('key','secret') {
13279: $ltiall{$id}{$item} = $encconfig{$id}{$item};
13280: }
13281: }
13282: }
13283: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 13284: if (ref($lastactref) eq 'HASH') {
13285: $lastactref->{'ltitools'} = 1;
13286: }
13287: $resulttext = &mt('Changes made:').'<ul>';
13288: my %bynum;
13289: foreach my $itemid (sort(keys(%changes))) {
13290: my $position = $confhash{$itemid}{'order'};
13291: $bynum{$position} = $itemid;
13292: }
13293: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13294: my $itemid = $bynum{$pos};
13295: if (ref($confhash{$itemid}) ne 'HASH') {
13296: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
13297: } else {
13298: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
13299: if ($confhash{$itemid}{'image'}) {
13300: $resulttext .= ' '.
13301: '<img src="'.$confhash{$itemid}{'image'}.'"'.
13302: ' alt="'.&mt('Tool Provider icon').'" />';
13303: }
13304: $resulttext .= '</li><ul>';
13305: my $position = $pos + 1;
13306: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323 raeburn 13307: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267 raeburn 13308: if ($confhash{$itemid}{$item} ne '') {
13309: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
13310: }
13311: }
1.297 raeburn 13312: if ($encconfig{$itemid}{'key'} ne '') {
13313: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
13314: }
13315: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 13316: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 13317: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 13318: $resulttext .= ('*'x$num).'</li>';
13319: }
1.273 raeburn 13320: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 13321: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 13322: my $numconfig = 0;
13323: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
13324: foreach my $item (@possconfig) {
13325: if ($confhash{$itemid}{'crsconf'}{$item}) {
13326: $numconfig ++;
1.296 raeburn 13327: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 13328: }
13329: }
13330: }
13331: if (!$numconfig) {
1.372 raeburn 13332: $resulttext .= ' '.&mt('None');
1.273 raeburn 13333: }
13334: $resulttext .= '</li>';
1.267 raeburn 13335: foreach my $item ('passback','roster') {
13336: $resulttext .= '<li>'.$lt{$item}.' ';
13337: if ($confhash{$itemid}{$item}) {
13338: $resulttext .= &mt('Yes');
1.319 raeburn 13339: if ($confhash{$itemid}{$item.'valid'}) {
13340: if ($item eq 'passback') {
13341: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
13342: $confhash{$itemid}{$item.'valid'});
13343: } else {
13344: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
13345: $confhash{$itemid}{$item.'valid'});
13346: }
13347: }
1.267 raeburn 13348: } else {
13349: $resulttext .= &mt('No');
13350: }
13351: $resulttext .= '</li>';
13352: }
13353: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
13354: my $displaylist;
13355: if ($confhash{$itemid}{'display'}{'target'}) {
13356: $displaylist = &mt('Display target').': '.
13357: $confhash{$itemid}{'display'}{'target'}.',';
13358: }
13359: foreach my $size ('width','height') {
13360: if ($confhash{$itemid}{'display'}{$size}) {
13361: $displaylist .= (' 'x2).$lt{$size}.': '.
13362: $confhash{$itemid}{'display'}{$size}.',';
13363: }
13364: }
13365: if ($displaylist) {
13366: $displaylist =~ s/,$//;
13367: $resulttext .= '<li>'.$displaylist.'</li>';
13368: }
1.296 raeburn 13369: foreach my $item ('linktext','explanation') {
13370: if ($confhash{$itemid}{'display'}{$item}) {
13371: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
13372: }
13373: }
13374: }
1.267 raeburn 13375: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
13376: my $fieldlist;
13377: foreach my $field (@allfields) {
13378: if ($confhash{$itemid}{'fields'}{$field}) {
13379: $fieldlist .= (' 'x2).$lt{$field}.',';
13380: }
13381: }
13382: if ($fieldlist) {
13383: $fieldlist =~ s/,$//;
1.324 raeburn 13384: if ($confhash{$itemid}{'fields'}{'user'}) {
13385: if ($confhash{$itemid}{'incdom'}) {
13386: $fieldlist .= ' ('.&mt('username:domain').')';
13387: } else {
13388: $fieldlist .= ' ('.&mt('username').')';
13389: }
13390: }
1.267 raeburn 13391: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
13392: }
13393: }
13394: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
13395: my $rolemaps;
13396: foreach my $role (@courseroles) {
13397: if ($confhash{$itemid}{'roles'}{$role}) {
13398: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
13399: $confhash{$itemid}{'roles'}{$role}.',';
13400: }
13401: }
13402: if ($rolemaps) {
13403: $rolemaps =~ s/,$//;
13404: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
13405: }
13406: }
13407: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
13408: my $customlist;
13409: if (keys(%{$confhash{$itemid}{'custom'}})) {
13410: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
13411: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
13412: }
13413: }
13414: if ($customlist) {
1.317 raeburn 13415: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 13416: }
13417: }
13418: $resulttext .= '</ul></li>';
13419: }
13420: }
13421: $resulttext .= '</ul>';
13422: } else {
13423: $resulttext = &mt('No changes made.');
13424: }
13425: } else {
13426: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13427: }
13428: if ($errors) {
13429: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13430: $errors.'</ul>';
13431: }
13432: return $resulttext;
13433: }
13434:
13435: sub process_ltitools_image {
13436: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
13437: my $filename = $env{'form.'.$caller.'.filename'};
13438: my ($error,$url);
13439: my ($width,$height) = (21,21);
13440: if ($configuserok eq 'ok') {
13441: if ($switchserver) {
13442: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
13443: $switchserver);
13444: } elsif ($author_ok eq 'ok') {
13445: my ($result,$imageurl,$madethumb) =
13446: &publishlogo($r,'upload',$caller,$dom,$confname,
13447: "ltitools/$itemid/icon",$width,$height);
13448: if ($result eq 'ok') {
13449: if ($madethumb) {
13450: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
13451: my $imagethumb = "$path/tn-".$imagefile;
13452: $url = $imagethumb;
13453: } else {
13454: $url = $imageurl;
13455: }
13456: } else {
13457: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
13458: }
13459: } else {
13460: $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);
13461: }
13462: } else {
13463: $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);
13464: }
13465: return ($url,$error);
13466: }
13467:
13468: sub get_ltitools_id {
13469: my ($cdom,$title) = @_;
13470: # get lock on ltitools db
13471: my $lockhash = {
13472: lock => $env{'user.name'}.
13473: ':'.$env{'user.domain'},
13474: };
13475: my $tries = 0;
13476: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
13477: my ($id,$error);
13478:
13479: while (($gotlock ne 'ok') && ($tries<10)) {
13480: $tries ++;
13481: sleep (0.1);
13482: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
13483: }
13484: if ($gotlock eq 'ok') {
13485: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
13486: if ($currids{'lock'}) {
13487: delete($currids{'lock'});
13488: if (keys(%currids)) {
13489: my @curr = sort { $a <=> $b } keys(%currids);
13490: if ($curr[-1] =~ /^\d+$/) {
13491: $id = 1 + $curr[-1];
13492: }
13493: } else {
13494: $id = 1;
13495: }
13496: if ($id) {
13497: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
13498: $error = 'nostore';
13499: }
13500: } else {
13501: $error = 'nonumber';
13502: }
13503: }
13504: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
13505: } else {
13506: $error = 'nolock';
13507: }
13508: return ($id,$error);
13509: }
13510:
1.372 raeburn 13511: sub modify_proctoring {
13512: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
13513: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13514: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
13515: my $confname = $dom.'-domainconfig';
13516: my $servadm = $r->dir_config('lonAdmEMail');
13517: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
13518: my %providernames = &proctoring_providernames();
13519: my $maxnum = scalar(keys(%providernames));
13520:
13521: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
13522: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
13523: if (ref($requref) eq 'HASH') {
13524: %requserfields = %{$requref};
13525: }
13526: if (ref($opturef) eq 'HASH') {
13527: %optuserfields = %{$opturef};
13528: }
13529: if (ref($defref) eq 'HASH') {
13530: %defaults = %{$defref};
13531: }
13532: if (ref($extref) eq 'HASH') {
13533: %extended = %{$extref};
13534: }
13535: if (ref($crsref) eq 'HASH') {
13536: %crsconf = %{$crsref};
13537: }
13538: if (ref($rolesref) eq 'ARRAY') {
13539: @courseroles = @{$rolesref};
13540: }
13541: if (ref($ltiref) eq 'ARRAY') {
13542: @ltiroles = @{$ltiref};
13543: }
13544:
13545: if (ref($domconfig{$action}) eq 'HASH') {
13546: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
13547: if (@todeleteimages) {
13548: map { $imgdeletions{$_} = 1; } @todeleteimages;
13549: }
13550: }
13551: my %customadds;
13552: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
13553: if (@newcustom) {
13554: map { $customadds{$_} = 1; } @newcustom;
13555: }
13556: foreach my $provider (sort(keys(%providernames))) {
13557: $confhash{$provider} = {};
13558: my $pos = $env{'form.proctoring_pos_'.$provider};
13559: $pos =~ s/\D+//g;
13560: $allpos[$pos] = $provider;
13561: my (%current,%currentenc);
13562: my $showroles = 0;
13563: if (ref($domconfig{$action}) eq 'HASH') {
13564: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
13565: %current = %{$domconfig{$action}{$provider}};
13566: foreach my $item ('key','secret') {
13567: $currentenc{$item} = $current{$item};
13568: delete($current{$item});
13569: }
13570: }
13571: }
13572: if ($env{'form.proctoring_available_'.$provider}) {
13573: $confhash{$provider}{'available'} = 1;
13574: unless ($current{'available'}) {
13575: $changes{$provider} = 1;
13576: }
13577: } else {
13578: %{$confhash{$provider}} = %current;
13579: %{$encconfhash{$provider}} = %currentenc;
13580: $confhash{$provider}{'available'} = 0;
13581: if ($current{'available'}) {
13582: $changes{$provider} = 1;
13583: }
13584: }
13585: if ($confhash{$provider}{'available'}) {
13586: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
13587: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
13588: if ($field eq 'lifetime') {
13589: if ($possval =~ /^\d+$/) {
13590: $confhash{$provider}{$field} = $possval;
13591: }
13592: } elsif ($field eq 'version') {
13593: if ($possval =~ /^\d+\.\d+$/) {
13594: $confhash{$provider}{$field} = $possval;
13595: }
13596: } elsif ($field eq 'sigmethod') {
13597: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
13598: $confhash{$provider}{$field} = $possval;
13599: }
13600: } elsif ($field eq 'url') {
13601: $confhash{$provider}{$field} = $possval;
13602: } elsif (($field eq 'key') || ($field eq 'secret')) {
13603: $encconfhash{$provider}{$field} = $possval;
13604: unless ($currentenc{$field} eq $possval) {
13605: $changes{$provider} = 1;
13606: }
13607: }
13608: unless (($field eq 'key') || ($field eq 'secret')) {
13609: unless ($current{$field} eq $confhash{$provider}{$field}) {
13610: $changes{$provider} = 1;
13611: }
13612: }
13613: }
13614: if ($imgdeletions{$provider}) {
13615: $changes{$provider} = 1;
13616: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
13617: my ($imageurl,$error) =
13618: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
13619: $configuserok,$switchserver,$author_ok);
13620: if ($imageurl) {
13621: $confhash{$provider}{'image'} = $imageurl;
13622: $changes{$provider} = 1;
13623: }
13624: if ($error) {
13625: &Apache::lonnet::logthis($error);
13626: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13627: }
13628: } elsif (exists($current{'image'})) {
13629: $confhash{$provider}{'image'} = $current{'image'};
13630: }
13631: if (ref($requserfields{$provider}) eq 'ARRAY') {
13632: if (@{$requserfields{$provider}} > 0) {
13633: if (grep(/^user$/,@{$requserfields{$provider}})) {
13634: if ($env{'form.proctoring_userincdom_'.$provider}) {
13635: $confhash{$provider}{'incdom'} = 1;
13636: }
13637: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
13638: $changes{$provider} = 1;
13639: }
13640: }
13641: if (grep(/^roles$/,@{$requserfields{$provider}})) {
13642: $showroles = 1;
13643: }
13644: }
13645: }
13646: $confhash{$provider}{'fields'} = [];
13647: if (ref($optuserfields{$provider}) eq 'ARRAY') {
13648: if (@{$optuserfields{$provider}} > 0) {
13649: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
13650: foreach my $field (@{$optuserfields{$provider}}) {
13651: if (grep(/^\Q$field\E$/,@optfields)) {
13652: push(@{$confhash{$provider}{'fields'}},$field);
13653: }
13654: }
13655: }
13656: if (ref($current{'fields'}) eq 'ARRAY') {
13657: unless ($changes{$provider}) {
13658: my @new = sort(@{$confhash{$provider}{'fields'}});
13659: my @old = sort(@{$current{'fields'}});
13660: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
13661: if (@diffs) {
13662: $changes{$provider} = 1;
13663: }
13664: }
13665: } elsif (@{$confhash{$provider}{'fields'}}) {
13666: $changes{$provider} = 1;
13667: }
13668: }
13669: if (ref($defaults{$provider}) eq 'ARRAY') {
13670: if (@{$defaults{$provider}} > 0) {
13671: my %options;
13672: if (ref($extended{$provider}) eq 'HASH') {
13673: %options = %{$extended{$provider}};
13674: }
13675: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
13676: foreach my $field (@{$defaults{$provider}}) {
13677: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
13678: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
13679: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
13680: push(@{$confhash{$provider}{'defaults'}},$poss);
13681: }
13682: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
13683: foreach my $inner (keys(%{$options{$field}})) {
13684: if (ref($options{$field}{$inner}) eq 'ARRAY') {
13685: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
13686: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
13687: $confhash{$provider}{'defaults'}{$inner} = $poss;
13688: }
13689: } else {
13690: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
13691: }
13692: }
13693: } else {
13694: if (grep(/^\Q$field\E$/,@checked)) {
13695: push(@{$confhash{$provider}{'defaults'}},$field);
13696: }
13697: }
13698: }
13699: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
13700: if (ref($current{'defaults'}) eq 'ARRAY') {
13701: unless ($changes{$provider}) {
13702: my @new = sort(@{$confhash{$provider}{'defaults'}});
13703: my @old = sort(@{$current{'defaults'}});
13704: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
13705: if (@diffs) {
13706: $changes{$provider} = 1;
13707: }
13708: }
13709: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
13710: if (@{$current{'defaults'}}) {
13711: $changes{$provider} = 1;
13712: }
13713: }
13714: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
13715: if (ref($current{'defaults'}) eq 'HASH') {
13716: unless ($changes{$provider}) {
13717: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
13718: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
13719: $changes{$provider} = 1;
13720: last;
13721: }
13722: }
13723: }
13724: unless ($changes{$provider}) {
13725: foreach my $key (keys(%{$current{'defaults'}})) {
13726: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
13727: $changes{$provider} = 1;
13728: last;
13729: }
13730: }
13731: }
13732: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
13733: $changes{$provider} = 1;
13734: }
13735: }
13736: }
13737: }
13738: if (ref($crsconf{$provider}) eq 'ARRAY') {
13739: if (@{$crsconf{$provider}} > 0) {
13740: $confhash{$provider}{'crsconf'} = [];
13741: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
13742: foreach my $crsfield (@{$crsconf{$provider}}) {
13743: if (grep(/^\Q$crsfield\E$/,@checked)) {
13744: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
13745: }
13746: }
13747: if (ref($current{'crsconf'}) eq 'ARRAY') {
13748: unless ($changes{$provider}) {
13749: my @new = sort(@{$confhash{$provider}{'crsconf'}});
13750: my @old = sort(@{$current{'crsconf'}});
13751: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
13752: if (@diffs) {
13753: $changes{$provider} = 1;
13754: }
13755: }
13756: } elsif (@{$confhash{$provider}{'crsconf'}}) {
13757: $changes{$provider} = 1;
13758: }
13759: }
13760: }
13761: if ($showroles) {
13762: $confhash{$provider}{'roles'} = {};
13763: foreach my $role (@courseroles) {
13764: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
13765: if (grep(/^\Q$poss\E$/,@ltiroles)) {
13766: $confhash{$provider}{'roles'}{$role} = $poss;
13767: }
13768: }
13769: unless ($changes{$provider}) {
13770: if (ref($current{'roles'}) eq 'HASH') {
13771: foreach my $role (keys(%{$current{'roles'}})) {
13772: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
13773: $changes{$provider} = 1;
13774: last
13775: }
13776: }
13777: unless ($changes{$provider}) {
13778: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
13779: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
13780: $changes{$provider} = 1;
13781: last;
13782: }
13783: }
13784: }
13785: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
13786: $changes{$provider} = 1;
13787: }
13788: }
13789: }
13790: if (ref($current{'custom'}) eq 'HASH') {
13791: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
13792: foreach my $key (keys(%{$current{'custom'}})) {
13793: if (grep(/^\Q$key\E$/,@customdels)) {
13794: $changes{$provider} = 1;
13795: } else {
13796: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
13797: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
13798: $changes{$provider} = 1;
13799: }
13800: }
13801: }
13802: }
13803: if ($customadds{$provider}) {
13804: my $name = $env{'form.proctoring_custom_name_'.$provider};
13805: $name =~ s/(`)/'/g;
13806: $name =~ s/^\s+//;
13807: $name =~ s/\s+$//;
13808: my $value = $env{'form.proctoring_custom_value_'.$provider};
13809: $value =~ s/(`)/'/g;
13810: $value =~ s/^\s+//;
13811: $value =~ s/\s+$//;
13812: if ($name ne '') {
13813: $confhash{$provider}{'custom'}{$name} = $value;
13814: $changes{$provider} = 1;
13815: }
13816: }
13817: }
13818: }
13819: if (@allpos > 0) {
13820: my $idx = 0;
13821: foreach my $provider (@allpos) {
13822: if ($provider ne '') {
13823: $confhash{$provider}{'order'} = $idx;
13824: unless ($changes{$provider}) {
13825: if (ref($domconfig{$action}) eq 'HASH') {
13826: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
13827: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
13828: $changes{$provider} = 1;
13829: }
13830: }
13831: }
13832: }
13833: $idx ++;
13834: }
13835: }
13836: }
13837: my %proc_hash = (
13838: $action => { %confhash }
13839: );
13840: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
13841: $dom);
13842: if ($putresult eq 'ok') {
13843: my %proc_enchash = (
13844: $action => { %encconfhash }
13845: );
13846: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom);
13847: if (keys(%changes) > 0) {
13848: my $cachetime = 24*60*60;
13849: my %procall = %confhash;
13850: foreach my $provider (keys(%procall)) {
13851: if (ref($encconfhash{$provider}) eq 'HASH') {
13852: foreach my $key ('key','secret') {
13853: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
13854: }
13855: }
13856: }
13857: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
13858: if (ref($lastactref) eq 'HASH') {
13859: $lastactref->{'proctoring'} = 1;
13860: }
13861: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
13862: my %bynum;
13863: foreach my $provider (sort(keys(%changes))) {
13864: my $position = $confhash{$provider}{'order'};
13865: $bynum{$position} = $provider;
13866: }
13867: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13868: my $provider = $bynum{$pos};
13869: my %lt = &proctoring_titles($provider);
13870: my %fieldtitles = &proctoring_fieldtitles($provider);
13871: if (!$confhash{$provider}{'available'}) {
13872: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
13873: } else {
13874: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
13875: if ($confhash{$provider}{'image'}) {
13876: $resulttext .= ' '.
13877: '<img src="'.$confhash{$provider}{'image'}.'"'.
13878: ' alt="'.&mt('Proctoring icon').'" />';
13879: }
13880: $resulttext .= '<ul>';
13881: my $position = $pos + 1;
13882: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
13883: foreach my $key ('version','sigmethod','url','lifetime') {
13884: if ($confhash{$provider}{$key} ne '') {
13885: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
13886: }
13887: }
13888: if ($encconfhash{$provider}{'key'} ne '') {
13889: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
13890: }
13891: if ($encconfhash{$provider}{'secret'} ne '') {
13892: $resulttext .= '<li>'.$lt{'secret'}.': ';
13893: my $num = length($encconfhash{$provider}{'secret'});
13894: $resulttext .= ('*'x$num).'</li>';
13895: }
13896: my (@fields,$showroles);
13897: if (ref($requserfields{$provider}) eq 'ARRAY') {
13898: push(@fields,@{$requserfields{$provider}});
13899: }
13900: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
13901: push(@fields,@{$confhash{$provider}{'fields'}});
13902: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
13903: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
13904: }
13905: if (@fields) {
13906: if (grep(/^roles$/,@fields)) {
13907: $showroles = 1;
13908: }
13909: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
13910: join('", "', map { $lt{$_}; } @fields).'"</li>';
13911: }
13912: if (ref($requserfields{$provider}) eq 'ARRAY') {
13913: if (grep(/^user$/,@{$requserfields{$provider}})) {
13914: if ($confhash{$provider}{'incdom'}) {
13915: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
13916: } else {
13917: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
13918: }
13919: }
13920: }
13921: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
13922: if (@{$confhash{$provider}{'defaults'}} > 0) {
13923: $resulttext .= '<li>'.$lt{'defa'};
13924: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
13925: $resulttext .= ' "'.$fieldtitles{$field}.'",';
13926: }
13927: $resulttext =~ s/,$//;
13928: $resulttext .= '</li>';
13929: }
13930: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
13931: if (keys(%{$confhash{$provider}{'defaults'}})) {
13932: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
13933: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
13934: if ($confhash{$provider}{'defaults'}{$key} ne '') {
13935: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
13936: }
13937: }
13938: $resulttext .= '</ul></li>';
13939: }
13940: }
13941: if (ref($crsconf{$provider}) eq 'ARRAY') {
13942: if (@{$crsconf{$provider}} > 0) {
13943: $resulttext .= '<li>'.&mt('Configurable in course:');
13944: my $numconfig = 0;
13945: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
13946: if (@{$confhash{$provider}{'crsconf'}} > 0) {
13947: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
13948: $numconfig ++;
13949: if ($provider eq 'examity') {
13950: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
13951: } else {
13952: $resulttext .= ' "'.$fieldtitles{$field}.'",';
13953: }
13954: }
13955: $resulttext =~ s/,$//;
13956: }
13957: }
13958: if (!$numconfig) {
13959: $resulttext .= ' '.&mt('None');
13960: }
13961: $resulttext .= '</li>';
13962: }
13963: }
13964: if ($showroles) {
13965: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
13966: my $rolemaps;
13967: foreach my $role (@courseroles) {
13968: if ($confhash{$provider}{'roles'}{$role}) {
13969: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
13970: $confhash{$provider}{'roles'}{$role}.',';
13971: }
13972: }
13973: if ($rolemaps) {
13974: $rolemaps =~ s/,$//;
13975: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
13976: }
13977: }
13978: }
13979: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
13980: my $customlist;
13981: if (keys(%{$confhash{$provider}{'custom'}})) {
13982: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
13983: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
13984: }
13985: $customlist =~ s/,$//;
13986: }
13987: if ($customlist) {
13988: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
13989: }
13990: }
13991: $resulttext .= '</ul></li>';
13992: }
13993: }
13994: $resulttext .= '</ul>';
13995: } else {
13996: $resulttext = &mt('No changes made.');
13997: }
13998: } else {
13999: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14000: }
14001: if ($errors) {
14002: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14003: $errors.'</ul>';
14004: }
14005: return $resulttext;
14006: }
14007:
14008: sub process_proctoring_image {
14009: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
14010: my $filename = $env{'form.'.$caller.'.filename'};
14011: my ($error,$url);
14012: my ($width,$height) = (21,21);
14013: if ($configuserok eq 'ok') {
14014: if ($switchserver) {
14015: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
14016: $switchserver);
14017: } elsif ($author_ok eq 'ok') {
14018: my ($result,$imageurl,$madethumb) =
14019: &publishlogo($r,'upload',$caller,$dom,$confname,
14020: "proctoring/$provider/icon",$width,$height);
14021: if ($result eq 'ok') {
14022: if ($madethumb) {
14023: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
14024: my $imagethumb = "$path/tn-".$imagefile;
14025: $url = $imagethumb;
14026: } else {
14027: $url = $imageurl;
14028: }
14029: } else {
14030: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14031: }
14032: } else {
14033: $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);
14034: }
14035: } else {
14036: $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);
14037: }
14038: return ($url,$error);
14039: }
14040:
1.320 raeburn 14041: sub modify_lti {
14042: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
14043: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14044: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
14045: my (%posslti,%posslticrs,%posscrstype);
14046: my @courseroles = ('cc','in','ta','ep','st');
14047: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
14048: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
14049: my @coursetypes = ('official','unofficial','community','textbook','placement');
14050: my %coursetypetitles = &Apache::lonlocal::texthash (
14051: official => 'Official',
14052: unofficial => 'Unofficial',
14053: community => 'Community',
14054: textbook => 'Textbook',
14055: placement => 'Placement Test',
14056: );
1.325 raeburn 14057: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 14058: my %lt = <i_names();
14059: map { $posslti{$_} = 1; } @ltiroles;
14060: map { $posslticrs{$_} = 1; } @lticourseroles;
14061: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 14062:
1.326 raeburn 14063: my %menutitles = <imenu_titles();
14064:
1.320 raeburn 14065: my (@items,%deletions,%itemids);
14066: if ($env{'form.lti_add'}) {
14067: my $consumer = $env{'form.lti_consumer_add'};
14068: $consumer =~ s/(`)/'/g;
14069: ($newid,my $error) = &get_lti_id($dom,$consumer);
14070: if ($newid) {
14071: $itemids{'add'} = $newid;
14072: push(@items,'add');
14073: $changes{$newid} = 1;
14074: } else {
14075: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
14076: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14077: }
14078: }
14079: if (ref($domconfig{$action}) eq 'HASH') {
14080: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
14081: if (@todelete) {
14082: map { $deletions{$_} = 1; } @todelete;
14083: }
14084: my $maxnum = $env{'form.lti_maxnum'};
14085: for (my $i=0; $i<=$maxnum; $i++) {
14086: my $itemid = $env{'form.lti_id_'.$i};
14087: $itemid =~ s/\D+//g;
14088: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14089: if ($deletions{$itemid}) {
14090: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
14091: } else {
14092: push(@items,$i);
14093: $itemids{$i} = $itemid;
14094: }
14095: }
14096: }
14097: }
14098: foreach my $idx (@items) {
14099: my $itemid = $itemids{$idx};
14100: next unless ($itemid);
14101: my $position = $env{'form.lti_pos_'.$idx};
14102: $position =~ s/\D+//g;
14103: if ($position ne '') {
14104: $allpos[$position] = $itemid;
14105: }
1.345 raeburn 14106: foreach my $item ('consumer','key','secret','lifetime','requser') {
1.320 raeburn 14107: my $formitem = 'form.lti_'.$item.'_'.$idx;
14108: $env{$formitem} =~ s/(`)/'/g;
14109: if ($item eq 'lifetime') {
14110: $env{$formitem} =~ s/[^\d.]//g;
14111: }
14112: if ($env{$formitem} ne '') {
14113: if (($item eq 'key') || ($item eq 'secret')) {
14114: $encconfig{$itemid}{$item} = $env{$formitem};
14115: } else {
14116: $confhash{$itemid}{$item} = $env{$formitem};
14117: unless (($idx eq 'add') || ($changes{$itemid})) {
14118: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
14119: $changes{$itemid} = 1;
14120: }
14121: }
14122: }
14123: }
14124: }
14125: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
14126: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
14127: }
1.345 raeburn 14128: if ($confhash{$itemid}{'requser'}) {
14129: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
14130: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
14131: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
14132: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
14133: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
14134: my $mapuser = $env{'form.lti_customuser_'.$idx};
14135: $mapuser =~ s/(`)/'/g;
14136: $mapuser =~ s/^\s+|\s+$//g;
14137: $confhash{$itemid}{'mapuser'} = $mapuser;
14138: }
14139: foreach my $ltirole (@lticourseroles) {
14140: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
14141: if (grep(/^\Q$possrole\E$/,@courseroles)) {
14142: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
14143: }
14144: }
14145: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
14146: my @makeuser;
14147: foreach my $ltirole (sort(@possmakeuser)) {
14148: if ($posslti{$ltirole}) {
14149: push(@makeuser,$ltirole);
14150: }
14151: }
14152: $confhash{$itemid}{'makeuser'} = \@makeuser;
14153: if (@makeuser) {
14154: my $lcauth = $env{'form.lti_lcauth_'.$idx};
14155: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
14156: $confhash{$itemid}{'lcauth'} = $lcauth;
14157: if ($lcauth ne 'internal') {
14158: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
14159: $lcauthparm =~ s/^(\s+|\s+)$//g;
14160: $lcauthparm =~ s/`//g;
14161: if ($lcauthparm ne '') {
14162: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
14163: }
14164: }
14165: } else {
14166: $confhash{$itemid}{'lcauth'} = 'lti';
14167: }
1.320 raeburn 14168: }
1.345 raeburn 14169: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
14170: if (@possinstdata) {
14171: foreach my $field (@possinstdata) {
14172: if (exists($fieldtitles{$field})) {
14173: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 14174: }
14175: }
14176: }
1.345 raeburn 14177: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
14178: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
14179: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
14180: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
14181: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
14182: $mapcrs =~ s/(`)/'/g;
14183: $mapcrs =~ s/^\s+|\s+$//g;
14184: $confhash{$itemid}{'mapcrs'} = $mapcrs;
14185: }
14186: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
14187: my @crstypes;
14188: foreach my $type (sort(@posstypes)) {
14189: if ($posscrstype{$type}) {
14190: push(@crstypes,$type);
1.325 raeburn 14191: }
14192: }
1.345 raeburn 14193: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
14194: if ($env{'form.lti_makecrs_'.$idx}) {
14195: $confhash{$itemid}{'makecrs'} = 1;
1.320 raeburn 14196: }
1.345 raeburn 14197: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
14198: my @selfenroll;
14199: foreach my $type (sort(@possenroll)) {
14200: if ($posslticrs{$type}) {
14201: push(@selfenroll,$type);
14202: }
1.320 raeburn 14203: }
1.345 raeburn 14204: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
14205: if ($env{'form.lti_crssec_'.$idx}) {
14206: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
14207: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
14208: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
14209: my $section = $env{'form.lti_customsection_'.$idx};
14210: $section =~ s/(`)/'/g;
14211: $section =~ s/^\s+|\s+$//g;
14212: if ($section ne '') {
14213: $confhash{$itemid}{'section'} = $section;
14214: }
1.320 raeburn 14215: }
14216: }
1.363 raeburn 14217: if ($env{'form.lti_callback_'.$idx}) {
14218: if ($env{'form.lti_callbackparam_'.$idx}) {
14219: my $callback = $env{'form.lti_callbackparam_'.$idx};
14220: $callback =~ s/^\s+|\s+$//g;
14221: $confhash{$itemid}{'callback'} = $callback;
14222: }
14223: }
1.345 raeburn 14224: foreach my $field ('passback','roster','topmenu','inlinemenu') {
14225: if ($env{'form.lti_'.$field.'_'.$idx}) {
14226: $confhash{$itemid}{$field} = 1;
14227: }
1.320 raeburn 14228: }
1.345 raeburn 14229: if ($env{'form.lti_passback_'.$idx}) {
14230: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
14231: $confhash{$itemid}{'passbackformat'} = '1.0';
14232: } else {
14233: $confhash{$itemid}{'passbackformat'} = '1.1';
14234: }
1.337 raeburn 14235: }
1.345 raeburn 14236: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
14237: $confhash{$itemid}{lcmenu} = [];
14238: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
14239: foreach my $field (@possmenu) {
14240: if (exists($menutitles{$field})) {
14241: if ($field eq 'grades') {
14242: next unless ($env{'form.lti_inlinemenu_'.$idx});
14243: }
14244: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 14245: }
14246: }
14247: }
1.345 raeburn 14248: unless (($idx eq 'add') || ($changes{$itemid})) {
1.363 raeburn 14249: foreach my $field ('mapuser','mapcrs','makecrs','section','passback','roster','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
1.345 raeburn 14250: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.337 raeburn 14251: $changes{$itemid} = 1;
14252: }
14253: }
1.320 raeburn 14254: unless ($changes{$itemid}) {
1.345 raeburn 14255: if ($domconfig{$action}{$itemid}{'passback'} eq $confhash{$itemid}{'passback'}) {
14256: if ($domconfig{$action}{$itemid}{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 14257: $changes{$itemid} = 1;
14258: }
1.345 raeburn 14259: }
1.320 raeburn 14260: }
1.345 raeburn 14261: foreach my $field ('makeuser','mapcrstype','selfenroll','instdata','lcmenu') {
14262: unless ($changes{$itemid}) {
14263: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
14264: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
14265: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
14266: $confhash{$itemid}{$field});
14267: if (@diffs) {
14268: $changes{$itemid} = 1;
14269: }
14270: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
14271: $changes{$itemid} = 1;
14272: }
14273: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
14274: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 14275: $changes{$itemid} = 1;
14276: }
14277: }
1.345 raeburn 14278: }
14279: }
14280: unless ($changes{$itemid}) {
14281: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
14282: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
14283: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
14284: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
14285: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.320 raeburn 14286: $changes{$itemid} = 1;
14287: last;
14288: }
14289: }
1.345 raeburn 14290: unless ($changes{$itemid}) {
14291: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
14292: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
14293: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
14294: $changes{$itemid} = 1;
14295: last;
14296: }
14297: }
14298: }
14299: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
14300: $changes{$itemid} = 1;
1.320 raeburn 14301: }
1.345 raeburn 14302: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
14303: unless ($changes{$itemid}) {
14304: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
14305: $changes{$itemid} = 1;
14306: }
1.320 raeburn 14307: }
14308: }
14309: }
14310: }
14311: }
14312: }
14313: if (@allpos > 0) {
14314: my $idx = 0;
14315: foreach my $itemid (@allpos) {
14316: if ($itemid ne '') {
14317: $confhash{$itemid}{'order'} = $idx;
14318: if (ref($domconfig{$action}) eq 'HASH') {
14319: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14320: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
14321: $changes{$itemid} = 1;
14322: }
14323: }
14324: }
14325: $idx ++;
14326: }
14327: }
14328: }
14329: my %ltihash = (
14330: $action => { %confhash }
14331: );
14332: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
14333: $dom);
14334: if ($putresult eq 'ok') {
14335: my %ltienchash = (
14336: $action => { %encconfig }
14337: );
14338: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
14339: if (keys(%changes) > 0) {
14340: my $cachetime = 24*60*60;
14341: my %ltiall = %confhash;
14342: foreach my $id (keys(%ltiall)) {
14343: if (ref($encconfig{$id}) eq 'HASH') {
14344: foreach my $item ('key','secret') {
14345: $ltiall{$id}{$item} = $encconfig{$id}{$item};
14346: }
14347: }
14348: }
14349: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
14350: if (ref($lastactref) eq 'HASH') {
14351: $lastactref->{'lti'} = 1;
14352: }
14353: $resulttext = &mt('Changes made:').'<ul>';
14354: my %bynum;
14355: foreach my $itemid (sort(keys(%changes))) {
14356: my $position = $confhash{$itemid}{'order'};
14357: $bynum{$position} = $itemid;
14358: }
14359: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
14360: my $itemid = $bynum{$pos};
14361: if (ref($confhash{$itemid}) ne 'HASH') {
14362: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
14363: } else {
14364: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b></li><ul>';
14365: my $position = $pos + 1;
14366: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
14367: foreach my $item ('version','lifetime') {
14368: if ($confhash{$itemid}{$item} ne '') {
14369: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
14370: }
14371: }
14372: if ($encconfig{$itemid}{'key'} ne '') {
14373: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
14374: }
14375: if ($encconfig{$itemid}{'secret'} ne '') {
14376: $resulttext .= '<li>'.$lt{'secret'}.': ';
14377: my $num = length($encconfig{$itemid}{'secret'});
14378: $resulttext .= ('*'x$num).'</li>';
14379: }
1.345 raeburn 14380: if ($confhash{$itemid}{'requser'}) {
14381: if ($confhash{$itemid}{'mapuser'}) {
14382: my $shownmapuser;
14383: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
14384: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
14385: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
14386: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
14387: } else {
14388: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 14389: }
1.345 raeburn 14390: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 14391: }
1.345 raeburn 14392: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
14393: my $rolemaps;
14394: foreach my $role (@ltiroles) {
14395: if ($confhash{$itemid}{'maproles'}{$role}) {
14396: $rolemaps .= (' 'x2).$role.'='.
14397: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
14398: 'Course').',';
14399: }
14400: }
14401: if ($rolemaps) {
14402: $rolemaps =~ s/,$//;
14403: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
14404: }
14405: }
14406: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
14407: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
14408: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
14409: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
14410: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
14411: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
14412: } else {
14413: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
14414: $confhash{$itemid}{'lcauth'});
14415: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
14416: $resulttext .= '; '.&mt('a randomly generated password will be created');
14417: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
14418: if ($confhash{$itemid}{'lcauthparm'} ne '') {
14419: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
14420: }
14421: } else {
14422: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
14423: }
14424: }
14425: $resulttext .= '</li>';
14426: } else {
14427: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
14428: }
1.320 raeburn 14429: }
1.345 raeburn 14430: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
14431: if (@{$confhash{$itemid}{'instdata'}} > 0) {
14432: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
14433: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 14434: } else {
1.345 raeburn 14435: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 14436: }
1.320 raeburn 14437: }
1.345 raeburn 14438: if ($confhash{$itemid}{'mapcrs'}) {
14439: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
14440: }
14441: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
14442: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
14443: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
14444: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
14445: '</li>';
14446: } else {
14447: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
14448: }
1.325 raeburn 14449: }
1.345 raeburn 14450: if ($confhash{$itemid}{'makecrs'}) {
14451: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
1.320 raeburn 14452: } else {
1.345 raeburn 14453: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
1.320 raeburn 14454: }
1.345 raeburn 14455: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
14456: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
14457: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
14458: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
14459: '</li>';
14460: } else {
14461: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
14462: }
1.320 raeburn 14463: }
1.345 raeburn 14464: if ($confhash{$itemid}{'section'}) {
14465: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
14466: $resulttext .= '<li>'.&mt('User section from standard field:').
14467: ' (course_section_sourcedid)'.'</li>';
14468: } else {
14469: $resulttext .= '<li>'.&mt('User section from:').' '.
14470: $confhash{$itemid}{'section'}.'</li>';
14471: }
1.320 raeburn 14472: } else {
1.345 raeburn 14473: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
1.320 raeburn 14474: }
1.363 raeburn 14475: if ($confhash{$itemid}{'callback'}) {
14476: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
14477: } else {
14478: $resulttext .= '<li>'.&mt('No callback to logout LON-CAPA session when user logs out of Comsumer');
14479: }
1.345 raeburn 14480: foreach my $item ('passback','roster','topmenu','inlinemenu') {
14481: $resulttext .= '<li>'.$lt{$item}.': ';
14482: if ($confhash{$itemid}{$item}) {
14483: $resulttext .= &mt('Yes');
14484: if ($item eq 'passback') {
14485: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
14486: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
14487: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
14488: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
14489: }
1.337 raeburn 14490: }
1.345 raeburn 14491: } else {
14492: $resulttext .= &mt('No');
1.337 raeburn 14493: }
1.345 raeburn 14494: $resulttext .= '</li>';
1.320 raeburn 14495: }
1.345 raeburn 14496: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
14497: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
14498: $resulttext .= '<li>'.&mt('Menu items:').' '.
14499: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
14500: } else {
14501: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
14502: }
1.326 raeburn 14503: }
14504: }
1.320 raeburn 14505: $resulttext .= '</ul></li>';
14506: }
14507: }
14508: $resulttext .= '</ul>';
14509: } else {
14510: $resulttext = &mt('No changes made.');
14511: }
14512: } else {
14513: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14514: }
14515: if ($errors) {
14516: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14517: $errors.'</ul>';
14518: }
14519: return $resulttext;
14520: }
14521:
14522: sub get_lti_id {
14523: my ($domain,$consumer) = @_;
14524: # get lock on lti db
14525: my $lockhash = {
14526: lock => $env{'user.name'}.
14527: ':'.$env{'user.domain'},
14528: };
14529: my $tries = 0;
14530: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
14531: my ($id,$error);
14532:
14533: while (($gotlock ne 'ok') && ($tries<10)) {
14534: $tries ++;
14535: sleep (0.1);
14536: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
14537: }
14538: if ($gotlock eq 'ok') {
14539: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
14540: if ($currids{'lock'}) {
14541: delete($currids{'lock'});
14542: if (keys(%currids)) {
14543: my @curr = sort { $a <=> $b } keys(%currids);
14544: if ($curr[-1] =~ /^\d+$/) {
14545: $id = 1 + $curr[-1];
14546: }
14547: } else {
14548: $id = 1;
14549: }
14550: if ($id) {
14551: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
14552: $error = 'nostore';
14553: }
14554: } else {
14555: $error = 'nonumber';
14556: }
14557: }
14558: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
14559: } else {
14560: $error = 'nolock';
14561: }
14562: return ($id,$error);
14563: }
14564:
1.3 raeburn 14565: sub modify_autoenroll {
1.205 raeburn 14566: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 14567: my ($resulttext,%changes);
14568: my %currautoenroll;
14569: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
14570: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
14571: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
14572: }
14573: }
14574: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
14575: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 14576: sender => 'Sender for notification messages',
1.274 raeburn 14577: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
14578: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 14579: my @offon = ('off','on');
1.17 raeburn 14580: my $sender_uname = $env{'form.sender_uname'};
14581: my $sender_domain = $env{'form.sender_domain'};
14582: if ($sender_domain eq '') {
14583: $sender_uname = '';
14584: } elsif ($sender_uname eq '') {
14585: $sender_domain = '';
14586: }
1.129 raeburn 14587: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 14588: my $failsafe = $env{'form.autoenroll_failsafe'};
14589: $failsafe =~ s{^\s+|\s+$}{}g;
14590: if ($failsafe =~ /\D/) {
14591: undef($failsafe);
14592: }
1.1 raeburn 14593: my %autoenrollhash = (
1.129 raeburn 14594: autoenroll => { 'run' => $env{'form.autoenroll_run'},
14595: 'sender_uname' => $sender_uname,
14596: 'sender_domain' => $sender_domain,
14597: 'co-owners' => $coowners,
1.274 raeburn 14598: 'autofailsafe' => $failsafe,
1.1 raeburn 14599: }
14600: );
1.4 raeburn 14601: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
14602: $dom);
1.1 raeburn 14603: if ($putresult eq 'ok') {
14604: if (exists($currautoenroll{'run'})) {
14605: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
14606: $changes{'run'} = 1;
14607: }
14608: } elsif ($autorun) {
14609: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 14610: $changes{'run'} = 1;
1.1 raeburn 14611: }
14612: }
1.17 raeburn 14613: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 14614: $changes{'sender'} = 1;
14615: }
1.17 raeburn 14616: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 14617: $changes{'sender'} = 1;
14618: }
1.129 raeburn 14619: if ($currautoenroll{'co-owners'} ne '') {
14620: if ($currautoenroll{'co-owners'} ne $coowners) {
14621: $changes{'coowners'} = 1;
14622: }
14623: } elsif ($coowners) {
14624: $changes{'coowners'} = 1;
1.274 raeburn 14625: }
14626: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
14627: $changes{'autofailsafe'} = 1;
14628: }
1.1 raeburn 14629: if (keys(%changes) > 0) {
14630: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 14631: if ($changes{'run'}) {
1.1 raeburn 14632: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
14633: }
14634: if ($changes{'sender'}) {
1.17 raeburn 14635: if ($sender_uname eq '' || $sender_domain eq '') {
14636: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
14637: } else {
14638: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
14639: }
1.1 raeburn 14640: }
1.129 raeburn 14641: if ($changes{'coowners'}) {
14642: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
14643: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 14644: if (ref($lastactref) eq 'HASH') {
14645: $lastactref->{'domainconfig'} = 1;
14646: }
1.129 raeburn 14647: }
1.274 raeburn 14648: if ($changes{'autofailsafe'}) {
14649: if ($failsafe ne '') {
1.299 raeburn 14650: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 14651: } else {
1.299 raeburn 14652: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 14653: }
14654: &Apache::lonnet::get_domain_defaults($dom,1);
14655: if (ref($lastactref) eq 'HASH') {
14656: $lastactref->{'domdefaults'} = 1;
14657: }
14658: }
1.1 raeburn 14659: $resulttext .= '</ul>';
14660: } else {
14661: $resulttext = &mt('No changes made to auto-enrollment settings');
14662: }
14663: } else {
1.11 albertel 14664: $resulttext = '<span class="LC_error">'.
14665: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14666: }
1.3 raeburn 14667: return $resulttext;
1.1 raeburn 14668: }
14669:
14670: sub modify_autoupdate {
1.3 raeburn 14671: my ($dom,%domconfig) = @_;
1.1 raeburn 14672: my ($resulttext,%currautoupdate,%fields,%changes);
14673: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
14674: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
14675: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
14676: }
14677: }
14678: my @offon = ('off','on');
14679: my %title = &Apache::lonlocal::texthash (
14680: run => 'Auto-update:',
14681: classlists => 'Updates to user information in classlists?'
14682: );
1.44 raeburn 14683: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 14684: my %fieldtitles = &Apache::lonlocal::texthash (
14685: id => 'Student/Employee ID',
1.20 raeburn 14686: permanentemail => 'E-mail address',
1.1 raeburn 14687: lastname => 'Last Name',
14688: firstname => 'First Name',
14689: middlename => 'Middle Name',
1.132 raeburn 14690: generation => 'Generation',
1.1 raeburn 14691: );
1.142 raeburn 14692: $othertitle = &mt('All users');
1.1 raeburn 14693: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 14694: $othertitle = &mt('Other users');
1.1 raeburn 14695: }
14696: foreach my $key (keys(%env)) {
14697: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 14698: my ($usertype,$item) = ($1,$2);
14699: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
14700: if ($usertype eq 'default') {
14701: push(@{$fields{$1}},$2);
14702: } elsif (ref($types) eq 'ARRAY') {
14703: if (grep(/^\Q$usertype\E$/,@{$types})) {
14704: push(@{$fields{$1}},$2);
14705: }
14706: }
14707: }
1.1 raeburn 14708: }
14709: }
1.131 raeburn 14710: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
14711: @lockablenames = sort(@lockablenames);
14712: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
14713: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
14714: if (@changed) {
14715: $changes{'lockablenames'} = 1;
14716: }
14717: } else {
14718: if (@lockablenames) {
14719: $changes{'lockablenames'} = 1;
14720: }
14721: }
1.1 raeburn 14722: my %updatehash = (
14723: autoupdate => { run => $env{'form.autoupdate_run'},
14724: classlists => $env{'form.classlists'},
14725: fields => {%fields},
1.131 raeburn 14726: lockablenames => \@lockablenames,
1.1 raeburn 14727: }
14728: );
14729: foreach my $key (keys(%currautoupdate)) {
14730: if (($key eq 'run') || ($key eq 'classlists')) {
14731: if (exists($updatehash{autoupdate}{$key})) {
14732: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
14733: $changes{$key} = 1;
14734: }
14735: }
14736: } elsif ($key eq 'fields') {
14737: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 14738: foreach my $item (@{$types},'default') {
1.1 raeburn 14739: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
14740: my $change = 0;
14741: foreach my $type (@{$currautoupdate{$key}{$item}}) {
14742: if (!exists($fields{$item})) {
14743: $change = 1;
1.132 raeburn 14744: last;
1.1 raeburn 14745: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 14746: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 14747: $change = 1;
1.132 raeburn 14748: last;
1.1 raeburn 14749: }
14750: }
14751: }
14752: if ($change) {
14753: push(@{$changes{$key}},$item);
14754: }
1.26 raeburn 14755: }
1.1 raeburn 14756: }
14757: }
1.131 raeburn 14758: } elsif ($key eq 'lockablenames') {
14759: if (ref($currautoupdate{$key}) eq 'ARRAY') {
14760: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
14761: if (@changed) {
14762: $changes{'lockablenames'} = 1;
14763: }
14764: } else {
14765: if (@lockablenames) {
14766: $changes{'lockablenames'} = 1;
14767: }
14768: }
14769: }
14770: }
14771: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
14772: if (@lockablenames) {
14773: $changes{'lockablenames'} = 1;
1.1 raeburn 14774: }
14775: }
1.26 raeburn 14776: foreach my $item (@{$types},'default') {
14777: if (defined($fields{$item})) {
14778: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 14779: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
14780: my $change = 0;
14781: if (ref($fields{$item}) eq 'ARRAY') {
14782: foreach my $type (@{$fields{$item}}) {
14783: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
14784: $change = 1;
14785: last;
14786: }
14787: }
14788: }
14789: if ($change) {
14790: push(@{$changes{'fields'}},$item);
14791: }
14792: } else {
1.26 raeburn 14793: push(@{$changes{'fields'}},$item);
14794: }
14795: } else {
14796: push(@{$changes{'fields'}},$item);
1.1 raeburn 14797: }
14798: }
14799: }
14800: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
14801: $dom);
14802: if ($putresult eq 'ok') {
14803: if (keys(%changes) > 0) {
14804: $resulttext = &mt('Changes made:').'<ul>';
14805: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 14806: if ($key eq 'lockablenames') {
14807: $resulttext .= '<li>';
14808: if (@lockablenames) {
14809: $usertypes->{'default'} = $othertitle;
14810: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
14811: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
14812: } else {
14813: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
14814: }
14815: $resulttext .= '</li>';
14816: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 14817: foreach my $item (@{$changes{$key}}) {
14818: my @newvalues;
14819: foreach my $type (@{$fields{$item}}) {
14820: push(@newvalues,$fieldtitles{$type});
14821: }
1.3 raeburn 14822: my $newvaluestr;
14823: if (@newvalues > 0) {
14824: $newvaluestr = join(', ',@newvalues);
14825: } else {
14826: $newvaluestr = &mt('none');
1.6 raeburn 14827: }
1.1 raeburn 14828: if ($item eq 'default') {
1.26 raeburn 14829: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 14830: } else {
1.26 raeburn 14831: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 14832: }
14833: }
14834: } else {
14835: my $newvalue;
14836: if ($key eq 'run') {
14837: $newvalue = $offon[$env{'form.autoupdate_run'}];
14838: } else {
14839: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 14840: }
1.1 raeburn 14841: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
14842: }
14843: }
14844: $resulttext .= '</ul>';
14845: } else {
1.3 raeburn 14846: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 14847: }
14848: } else {
1.11 albertel 14849: $resulttext = '<span class="LC_error">'.
14850: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14851: }
1.3 raeburn 14852: return $resulttext;
1.1 raeburn 14853: }
14854:
1.125 raeburn 14855: sub modify_autocreate {
14856: my ($dom,%domconfig) = @_;
14857: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
14858: if (ref($domconfig{'autocreate'}) eq 'HASH') {
14859: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
14860: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
14861: }
14862: }
14863: my %title= ( xml => 'Auto-creation of courses in XML course description files',
14864: req => 'Auto-creation of validated requests for official courses',
14865: xmldc => 'Identity of course creator of courses from XML files',
14866: );
14867: my @types = ('xml','req');
14868: foreach my $item (@types) {
14869: $newvals{$item} = $env{'form.autocreate_'.$item};
14870: $newvals{$item} =~ s/\D//g;
14871: $newvals{$item} = 0 if ($newvals{$item} eq '');
14872: }
14873: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 14874: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 14875: unless (exists($domcoords{$newvals{'xmldc'}})) {
14876: $newvals{'xmldc'} = '';
14877: }
14878: %autocreatehash = (
14879: autocreate => { xml => $newvals{'xml'},
14880: req => $newvals{'req'},
14881: }
14882: );
14883: if ($newvals{'xmldc'} ne '') {
14884: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
14885: }
14886: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
14887: $dom);
14888: if ($putresult eq 'ok') {
14889: my @items = @types;
14890: if ($newvals{'xml'}) {
14891: push(@items,'xmldc');
14892: }
14893: foreach my $item (@items) {
14894: if (exists($currautocreate{$item})) {
14895: if ($currautocreate{$item} ne $newvals{$item}) {
14896: $changes{$item} = 1;
14897: }
14898: } elsif ($newvals{$item}) {
14899: $changes{$item} = 1;
14900: }
14901: }
14902: if (keys(%changes) > 0) {
14903: my @offon = ('off','on');
14904: $resulttext = &mt('Changes made:').'<ul>';
14905: foreach my $item (@types) {
14906: if ($changes{$item}) {
14907: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 14908: $resulttext .= '<li>'.
14909: &mt("$title{$item} set to [_1]$newtxt [_2]",
14910: '<b>','</b>').
14911: '</li>';
1.125 raeburn 14912: }
14913: }
14914: if ($changes{'xmldc'}) {
14915: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
14916: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 14917: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 14918: }
14919: $resulttext .= '</ul>';
14920: } else {
14921: $resulttext = &mt('No changes made to auto-creation settings');
14922: }
14923: } else {
14924: $resulttext = '<span class="LC_error">'.
14925: &mt('An error occurred: [_1]',$putresult).'</span>';
14926: }
14927: return $resulttext;
14928: }
14929:
1.23 raeburn 14930: sub modify_directorysrch {
1.295 raeburn 14931: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 14932: my ($resulttext,%changes);
14933: my %currdirsrch;
14934: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
14935: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
14936: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
14937: }
14938: }
1.277 raeburn 14939: my %title = ( available => 'Institutional directory search available',
14940: localonly => 'Other domains can search institution',
14941: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 14942: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 14943: searchby => 'Search types',
14944: searchtypes => 'Search latitude');
14945: my @offon = ('off','on');
1.24 raeburn 14946: my @otherdoms = ('Yes','No');
1.23 raeburn 14947:
1.25 raeburn 14948: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 14949: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
14950: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
14951:
1.44 raeburn 14952: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 14953: if (keys(%{$usertypes}) == 0) {
14954: @cansearch = ('default');
14955: } else {
14956: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
14957: foreach my $type (@{$currdirsrch{'cansearch'}}) {
14958: if (!grep(/^\Q$type\E$/,@cansearch)) {
14959: push(@{$changes{'cansearch'}},$type);
14960: }
1.23 raeburn 14961: }
1.26 raeburn 14962: foreach my $type (@cansearch) {
14963: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
14964: push(@{$changes{'cansearch'}},$type);
14965: }
1.23 raeburn 14966: }
1.26 raeburn 14967: } else {
14968: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 14969: }
14970: }
14971:
14972: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
14973: foreach my $by (@{$currdirsrch{'searchby'}}) {
14974: if (!grep(/^\Q$by\E$/,@searchby)) {
14975: push(@{$changes{'searchby'}},$by);
14976: }
14977: }
14978: foreach my $by (@searchby) {
14979: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
14980: push(@{$changes{'searchby'}},$by);
14981: }
14982: }
14983: } else {
14984: push(@{$changes{'searchby'}},@searchby);
14985: }
1.25 raeburn 14986:
14987: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
14988: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
14989: if (!grep(/^\Q$type\E$/,@searchtypes)) {
14990: push(@{$changes{'searchtypes'}},$type);
14991: }
14992: }
14993: foreach my $type (@searchtypes) {
14994: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
14995: push(@{$changes{'searchtypes'}},$type);
14996: }
14997: }
14998: } else {
14999: if (exists($currdirsrch{'searchtypes'})) {
15000: foreach my $type (@searchtypes) {
15001: if ($type ne $currdirsrch{'searchtypes'}) {
15002: push(@{$changes{'searchtypes'}},$type);
15003: }
15004: }
15005: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
15006: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
15007: }
15008: } else {
15009: push(@{$changes{'searchtypes'}},@searchtypes);
15010: }
15011: }
15012:
1.23 raeburn 15013: my %dirsrch_hash = (
15014: directorysrch => { available => $env{'form.dirsrch_available'},
15015: cansearch => \@cansearch,
1.277 raeburn 15016: localonly => $env{'form.dirsrch_instlocalonly'},
15017: lclocalonly => $env{'form.dirsrch_domlocalonly'},
15018: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 15019: searchby => \@searchby,
1.25 raeburn 15020: searchtypes => \@searchtypes,
1.23 raeburn 15021: }
15022: );
15023: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
15024: $dom);
15025: if ($putresult eq 'ok') {
15026: if (exists($currdirsrch{'available'})) {
15027: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
15028: $changes{'available'} = 1;
15029: }
15030: } else {
15031: if ($env{'form.dirsrch_available'} eq '1') {
15032: $changes{'available'} = 1;
15033: }
15034: }
1.277 raeburn 15035: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 15036: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
15037: $changes{'lcavailable'} = 1;
15038: }
1.277 raeburn 15039: } else {
15040: if ($env{'form.dirsrch_lcavailable'} eq '1') {
15041: $changes{'lcavailable'} = 1;
15042: }
15043: }
1.24 raeburn 15044: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 15045: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
15046: $changes{'localonly'} = 1;
15047: }
1.24 raeburn 15048: } else {
1.277 raeburn 15049: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 15050: $changes{'localonly'} = 1;
15051: }
15052: }
1.277 raeburn 15053: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 15054: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
15055: $changes{'lclocalonly'} = 1;
15056: }
1.277 raeburn 15057: } else {
15058: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
15059: $changes{'lclocalonly'} = 1;
15060: }
15061: }
1.23 raeburn 15062: if (keys(%changes) > 0) {
15063: $resulttext = &mt('Changes made:').'<ul>';
15064: if ($changes{'available'}) {
15065: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
15066: }
1.277 raeburn 15067: if ($changes{'lcavailable'}) {
15068: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
15069: }
1.24 raeburn 15070: if ($changes{'localonly'}) {
1.277 raeburn 15071: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 15072: }
1.277 raeburn 15073: if ($changes{'lclocalonly'}) {
15074: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 15075: }
1.23 raeburn 15076: if (ref($changes{'cansearch'}) eq 'ARRAY') {
15077: my $chgtext;
1.26 raeburn 15078: if (ref($usertypes) eq 'HASH') {
15079: if (keys(%{$usertypes}) > 0) {
15080: foreach my $type (@{$types}) {
15081: if (grep(/^\Q$type\E$/,@cansearch)) {
15082: $chgtext .= $usertypes->{$type}.'; ';
15083: }
15084: }
15085: if (grep(/^default$/,@cansearch)) {
15086: $chgtext .= $othertitle;
15087: } else {
15088: $chgtext =~ s/\; $//;
15089: }
1.210 raeburn 15090: $resulttext .=
1.178 raeburn 15091: '<li>'.
15092: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
15093: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
15094: '</li>';
1.23 raeburn 15095: }
15096: }
15097: }
15098: if (ref($changes{'searchby'}) eq 'ARRAY') {
15099: my ($searchtitles,$titleorder) = &sorted_searchtitles();
15100: my $chgtext;
15101: foreach my $type (@{$titleorder}) {
15102: if (grep(/^\Q$type\E$/,@searchby)) {
15103: if (defined($searchtitles->{$type})) {
15104: $chgtext .= $searchtitles->{$type}.'; ';
15105: }
15106: }
15107: }
15108: $chgtext =~ s/\; $//;
15109: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
15110: }
1.25 raeburn 15111: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
15112: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
15113: my $chgtext;
15114: foreach my $type (@{$srchtypeorder}) {
15115: if (grep(/^\Q$type\E$/,@searchtypes)) {
15116: if (defined($srchtypes_desc->{$type})) {
15117: $chgtext .= $srchtypes_desc->{$type}.'; ';
15118: }
15119: }
15120: }
15121: $chgtext =~ s/\; $//;
1.178 raeburn 15122: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 15123: }
15124: $resulttext .= '</ul>';
1.295 raeburn 15125: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
15126: if (ref($lastactref) eq 'HASH') {
15127: $lastactref->{'directorysrch'} = 1;
15128: }
1.23 raeburn 15129: } else {
1.277 raeburn 15130: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 15131: }
15132: } else {
15133: $resulttext = '<span class="LC_error">'.
1.27 raeburn 15134: &mt('An error occurred: [_1]',$putresult).'</span>';
15135: }
15136: return $resulttext;
15137: }
15138:
1.28 raeburn 15139: sub modify_contacts {
1.205 raeburn 15140: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 15141: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
15142: if (ref($domconfig{'contacts'}) eq 'HASH') {
15143: foreach my $key (keys(%{$domconfig{'contacts'}})) {
15144: $currsetting{$key} = $domconfig{'contacts'}{$key};
15145: }
15146: }
1.286 raeburn 15147: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 15148: my @contacts = ('supportemail','adminemail');
1.286 raeburn 15149: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 15150: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 15151: my @toggles = ('reporterrors','reportupdates','reportstatus');
15152: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 15153: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 15154: foreach my $type (@mailings) {
15155: @{$newsetting{$type}} =
15156: &Apache::loncommon::get_env_multiple('form.'.$type);
15157: foreach my $item (@contacts) {
15158: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
15159: $contacts_hash{contacts}{$type}{$item} = 1;
15160: } else {
15161: $contacts_hash{contacts}{$type}{$item} = 0;
15162: }
1.289 raeburn 15163: }
1.28 raeburn 15164: $others{$type} = $env{'form.'.$type.'_others'};
15165: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 15166: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15167: $bcc{$type} = $env{'form.'.$type.'_bcc'};
15168: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 15169: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
15170: $includestr{$type} = $env{'form.'.$type.'_includestr'};
15171: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
15172: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
15173: }
1.134 raeburn 15174: }
1.28 raeburn 15175: }
15176: foreach my $item (@contacts) {
15177: $to{$item} = $env{'form.'.$item};
15178: $contacts_hash{'contacts'}{$item} = $to{$item};
15179: }
1.203 raeburn 15180: foreach my $item (@toggles) {
15181: if ($env{'form.'.$item} =~ /^(0|1)$/) {
15182: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
15183: }
15184: }
1.340 raeburn 15185: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
15186: foreach my $item (@lonstatus) {
15187: if ($item eq 'excluded') {
15188: my (%serverhomes,@excluded);
15189: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
15190: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
15191: if (@possexcluded) {
15192: foreach my $id (sort(@possexcluded)) {
15193: if ($serverhomes{$id}) {
15194: push(@excluded,$id);
15195: }
15196: }
15197: }
15198: if (@excluded) {
15199: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
15200: }
15201: } elsif ($item eq 'weights') {
1.377 raeburn 15202: foreach my $type ('E','W','N','U') {
1.340 raeburn 15203: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
15204: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
15205: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
15206: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
15207: $env{'form.error'.$item.'_'.$type};
15208: }
15209: }
15210: }
15211: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
15212: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
15213: if ($env{'form.error'.$item} =~ /^\d+$/) {
15214: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
15215: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
15216: }
15217: }
15218: }
15219: }
1.286 raeburn 15220: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
15221: foreach my $field (@{$fields}) {
15222: if (ref($possoptions->{$field}) eq 'ARRAY') {
15223: my $value = $env{'form.helpform_'.$field};
15224: $value =~ s/^\s+|\s+$//g;
15225: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 15226: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 15227: if ($field eq 'screenshot') {
15228: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
15229: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 15230: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 15231: }
15232: }
15233: }
15234: }
15235: }
15236: }
1.315 raeburn 15237: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
15238: my (@statuses,%usertypeshash,@overrides);
15239: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
15240: @statuses = @{$types};
15241: if (ref($usertypes) eq 'HASH') {
15242: %usertypeshash = %{$usertypes};
15243: }
15244: }
15245: if (@statuses) {
15246: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
15247: foreach my $type (@possoverrides) {
15248: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
15249: push(@overrides,$type);
15250: }
15251: }
15252: if (@overrides) {
15253: foreach my $type (@overrides) {
15254: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
15255: foreach my $item (@contacts) {
15256: if (grep(/^\Q$item\E$/,@standard)) {
15257: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
15258: $newsetting{'override_'.$type}{$item} = 1;
15259: } else {
15260: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
15261: $newsetting{'override_'.$type}{$item} = 0;
15262: }
15263: }
15264: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
15265: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
15266: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
15267: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
15268: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
15269: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
15270: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
15271: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
15272: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
15273: }
15274: }
15275: }
15276: }
1.28 raeburn 15277: if (keys(%currsetting) > 0) {
15278: foreach my $item (@contacts) {
15279: if ($to{$item} ne $currsetting{$item}) {
15280: $changes{$item} = 1;
15281: }
15282: }
15283: foreach my $type (@mailings) {
15284: foreach my $item (@contacts) {
15285: if (ref($currsetting{$type}) eq 'HASH') {
15286: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
15287: push(@{$changes{$type}},$item);
15288: }
15289: } else {
15290: push(@{$changes{$type}},@{$newsetting{$type}});
15291: }
15292: }
15293: if ($others{$type} ne $currsetting{$type}{'others'}) {
15294: push(@{$changes{$type}},'others');
15295: }
1.289 raeburn 15296: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15297: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
15298: push(@{$changes{$type}},'bcc');
15299: }
1.286 raeburn 15300: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
15301: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
15302: push(@{$changes{$type}},'include');
15303: }
15304: }
15305: }
15306: if (ref($fields) eq 'ARRAY') {
15307: if (ref($currsetting{'helpform'}) eq 'HASH') {
15308: foreach my $field (@{$fields}) {
15309: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
15310: push(@{$changes{'helpform'}},$field);
15311: }
15312: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
15313: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
15314: push(@{$changes{'helpform'}},'maxsize');
15315: }
15316: }
15317: }
15318: } else {
15319: foreach my $field (@{$fields}) {
15320: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
15321: push(@{$changes{'helpform'}},$field);
15322: }
15323: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
15324: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
15325: push(@{$changes{'helpform'}},'maxsize');
15326: }
15327: }
15328: }
1.134 raeburn 15329: }
1.28 raeburn 15330: }
1.315 raeburn 15331: if (@statuses) {
15332: if (ref($currsetting{'overrides'}) eq 'HASH') {
15333: foreach my $key (keys(%{$currsetting{'overrides'}})) {
15334: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
15335: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
15336: foreach my $item (@contacts,'bcc','others','include') {
15337: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
15338: push(@{$changes{'overrides'}},$key);
15339: last;
15340: }
15341: }
15342: } else {
15343: push(@{$changes{'overrides'}},$key);
15344: }
15345: }
15346: }
15347: foreach my $key (@overrides) {
15348: unless (exists($currsetting{'overrides'}{$key})) {
15349: push(@{$changes{'overrides'}},$key);
15350: }
15351: }
15352: } else {
15353: foreach my $key (@overrides) {
15354: push(@{$changes{'overrides'}},$key);
15355: }
15356: }
15357: }
1.340 raeburn 15358: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
15359: foreach my $key ('excluded','weights','threshold','sysmail') {
15360: if ($key eq 'excluded') {
15361: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
15362: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
15363: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
15364: (@{$currsetting{'lonstatus'}{$key}})) {
15365: my @diffs =
15366: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
15367: $currsetting{'lonstatus'}{$key});
15368: if (@diffs) {
15369: push(@{$changes{'lonstatus'}},$key);
15370: }
15371: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
15372: push(@{$changes{'lonstatus'}},$key);
15373: }
15374: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
15375: (@{$currsetting{'lonstatus'}{$key}})) {
15376: push(@{$changes{'lonstatus'}},$key);
15377: }
15378: } elsif ($key eq 'weights') {
15379: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
15380: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
15381: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 15382: foreach my $type ('E','W','N','U') {
1.340 raeburn 15383: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
15384: $currsetting{'lonstatus'}{$key}{$type}) {
15385: push(@{$changes{'lonstatus'}},$key);
15386: last;
15387: }
15388: }
15389: } else {
1.341 raeburn 15390: foreach my $type ('E','W','N','U') {
1.340 raeburn 15391: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
15392: push(@{$changes{'lonstatus'}},$key);
15393: last;
15394: }
15395: }
15396: }
15397: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 15398: foreach my $type ('E','W','N','U') {
1.340 raeburn 15399: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
15400: push(@{$changes{'lonstatus'}},$key);
15401: last;
15402: }
15403: }
15404: }
15405: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
15406: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
15407: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
15408: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
15409: push(@{$changes{'lonstatus'}},$key);
15410: }
15411: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
15412: push(@{$changes{'lonstatus'}},$key);
15413: }
15414: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
15415: push(@{$changes{'lonstatus'}},$key);
15416: }
15417: }
15418: }
15419: } else {
15420: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
15421: foreach my $key ('excluded','weights','threshold','sysmail') {
15422: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
15423: push(@{$changes{'lonstatus'}},$key);
15424: }
15425: }
15426: }
15427: }
1.28 raeburn 15428: } else {
15429: my %default;
15430: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
15431: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
15432: $default{'errormail'} = 'adminemail';
15433: $default{'packagesmail'} = 'adminemail';
15434: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 15435: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 15436: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 15437: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 15438: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 15439: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 15440: foreach my $item (@contacts) {
15441: if ($to{$item} ne $default{$item}) {
1.286 raeburn 15442: $changes{$item} = 1;
1.203 raeburn 15443: }
1.28 raeburn 15444: }
15445: foreach my $type (@mailings) {
15446: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
15447: push(@{$changes{$type}},@{$newsetting{$type}});
15448: }
15449: if ($others{$type} ne '') {
15450: push(@{$changes{$type}},'others');
1.134 raeburn 15451: }
1.286 raeburn 15452: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15453: if ($bcc{$type} ne '') {
15454: push(@{$changes{$type}},'bcc');
15455: }
1.286 raeburn 15456: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
15457: push(@{$changes{$type}},'include');
15458: }
1.134 raeburn 15459: }
1.28 raeburn 15460: }
1.286 raeburn 15461: if (ref($fields) eq 'ARRAY') {
15462: foreach my $field (@{$fields}) {
15463: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
15464: push(@{$changes{'helpform'}},$field);
15465: }
15466: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
15467: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
15468: push(@{$changes{'helpform'}},'maxsize');
15469: }
15470: }
15471: }
1.289 raeburn 15472: }
1.340 raeburn 15473: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
15474: foreach my $key ('excluded','weights','threshold','sysmail') {
15475: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
15476: push(@{$changes{'lonstatus'}},$key);
15477: }
15478: }
15479: }
1.28 raeburn 15480: }
1.203 raeburn 15481: foreach my $item (@toggles) {
15482: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
15483: $changes{$item} = 1;
15484: } elsif ((!$env{'form.'.$item}) &&
15485: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
15486: $changes{$item} = 1;
15487: }
15488: }
1.28 raeburn 15489: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
15490: $dom);
15491: if ($putresult eq 'ok') {
15492: if (keys(%changes) > 0) {
1.205 raeburn 15493: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 15494: if (ref($lastactref) eq 'HASH') {
15495: $lastactref->{'domainconfig'} = 1;
15496: }
1.28 raeburn 15497: my ($titles,$short_titles) = &contact_titles();
15498: $resulttext = &mt('Changes made:').'<ul>';
15499: foreach my $item (@contacts) {
15500: if ($changes{$item}) {
15501: $resulttext .= '<li>'.$titles->{$item}.
15502: &mt(' set to: ').
15503: '<span class="LC_cusr_emph">'.
15504: $to{$item}.'</span></li>';
15505: }
15506: }
15507: foreach my $type (@mailings) {
15508: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 15509: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 15510: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 15511: } else {
15512: $resulttext .= '<li>'.$titles->{$type}.': ';
15513: }
1.28 raeburn 15514: my @text;
15515: foreach my $item (@{$newsetting{$type}}) {
15516: push(@text,$short_titles->{$item});
15517: }
15518: if ($others{$type} ne '') {
15519: push(@text,$others{$type});
15520: }
1.286 raeburn 15521: if (@text) {
15522: $resulttext .= '<span class="LC_cusr_emph">'.
15523: join(', ',@text).'</span>';
15524: }
15525: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15526: if ($bcc{$type} ne '') {
1.286 raeburn 15527: my $bcctext;
15528: if (@text) {
1.289 raeburn 15529: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 15530: } else {
15531: $bcctext = '(Bcc)';
15532: }
15533: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
15534: } elsif (!@text) {
15535: $resulttext .= &mt('No one');
15536: }
1.289 raeburn 15537: if ($includestr{$type} ne '') {
1.286 raeburn 15538: if ($includeloc{$type} eq 'b') {
15539: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
15540: } elsif ($includeloc{$type} eq 's') {
15541: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
15542: }
1.134 raeburn 15543: }
1.286 raeburn 15544: } elsif (!@text) {
15545: $resulttext .= &mt('No recipients');
1.134 raeburn 15546: }
15547: $resulttext .= '</li>';
1.28 raeburn 15548: }
15549: }
1.315 raeburn 15550: if (ref($changes{'overrides'}) eq 'ARRAY') {
15551: my @deletions;
15552: foreach my $type (@{$changes{'overrides'}}) {
15553: if ($usertypeshash{$type}) {
15554: if (grep(/^\Q$type\E/,@overrides)) {
15555: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
15556: $usertypeshash{$type}).'<ul><li>';
15557: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
15558: my @text;
15559: foreach my $item (@contacts) {
15560: if ($newsetting{'override_'.$type}{$item}) {
15561: push(@text,$short_titles->{$item});
15562: }
15563: }
15564: if ($newsetting{'override_'.$type}{'others'} ne '') {
15565: push(@text,$newsetting{'override_'.$type}{'others'});
15566: }
15567:
15568: if (@text) {
15569: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
15570: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
15571: }
15572: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
15573: my $bcctext;
15574: if (@text) {
15575: $bcctext = ' '.&mt('with Bcc to');
15576: } else {
15577: $bcctext = '(Bcc)';
15578: }
15579: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
15580: } elsif (!@text) {
15581: $resulttext .= &mt('Helpdesk e-mail sent to no one');
15582: }
15583: $resulttext .= '</li>';
15584: if ($newsetting{'override_'.$type}{'include'} ne '') {
15585: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
15586: if ($loc eq 'b') {
15587: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
15588: } elsif ($loc eq 's') {
15589: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
15590: }
15591: }
15592: }
15593: $resulttext .= '</li></ul></li>';
15594: } else {
15595: push(@deletions,$usertypeshash{$type});
15596: }
15597: }
15598: }
15599: if (@deletions) {
15600: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
15601: join(', ',@deletions)).'</li>';
15602: }
15603: }
1.203 raeburn 15604: my @offon = ('off','on');
1.340 raeburn 15605: my $corelink = &core_link_msu();
1.203 raeburn 15606: if ($changes{'reporterrors'}) {
15607: $resulttext .= '<li>'.
15608: &mt('E-mail error reports to [_1] set to "'.
15609: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 15610: $corelink).
1.203 raeburn 15611: '</li>';
15612: }
15613: if ($changes{'reportupdates'}) {
15614: $resulttext .= '<li>'.
15615: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
15616: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 15617: $corelink).
1.203 raeburn 15618: '</li>';
15619: }
1.340 raeburn 15620: if ($changes{'reportstatus'}) {
15621: $resulttext .= '<li>'.
15622: &mt('E-mail status if errors above threshold to [_1] set to "'.
15623: $offon[$env{'form.reportstatus'}].'".',
15624: $corelink).
15625: '</li>';
15626: }
15627: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
15628: $resulttext .= '<li>'.
15629: &mt('Nightly status check e-mail settings').':<ul>';
15630: my (%defval,%use_def,%shown);
15631: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
15632: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
15633: $defval{'weights'} =
1.341 raeburn 15634: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 15635: $defval{'excluded'} = &mt('None');
15636: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
15637: foreach my $item ('threshold','sysmail','weights','excluded') {
15638: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
15639: if (($item eq 'threshold') || ($item eq 'sysmail')) {
15640: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
15641: } elsif ($item eq 'weights') {
15642: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 15643: foreach my $type ('E','W','N','U') {
1.340 raeburn 15644: $shown{$item} .= $lonstatus_names->{$type}.'=';
15645: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
15646: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
15647: } else {
15648: $shown{$item} .= $lonstatus_defs->{$type};
15649: }
15650: $shown{$item} .= ', ';
15651: }
15652: $shown{$item} =~ s/, $//;
15653: } else {
15654: $shown{$item} = $defval{$item};
15655: }
15656: } elsif ($item eq 'excluded') {
15657: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
15658: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
15659: } else {
15660: $shown{$item} = $defval{$item};
15661: }
15662: }
15663: } else {
15664: $shown{$item} = $defval{$item};
15665: }
15666: }
15667: } else {
15668: foreach my $item ('threshold','weights','excluded','sysmail') {
15669: $shown{$item} = $defval{$item};
15670: }
15671: }
15672: foreach my $item ('threshold','weights','excluded','sysmail') {
15673: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
15674: $shown{$item}).'</li>';
15675: }
15676: $resulttext .= '</ul></li>';
15677: }
1.286 raeburn 15678: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
15679: my (@optional,@required,@unused,$maxsizechg);
15680: foreach my $field (@{$changes{'helpform'}}) {
15681: if ($field eq 'maxsize') {
15682: $maxsizechg = 1;
15683: next;
15684: }
15685: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 15686: push(@optional,$field);
1.286 raeburn 15687: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
15688: push(@unused,$field);
15689: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 15690: push(@required,$field);
1.286 raeburn 15691: }
15692: }
15693: if (@optional) {
15694: $resulttext .= '<li>'.
15695: &mt('Help form fields changed to "Optional": [_1].',
15696: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
15697: '</li>';
15698: }
15699: if (@required) {
15700: $resulttext .= '<li>'.
15701: &mt('Help form fields changed to "Required": [_1].',
15702: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
15703: '</li>';
15704: }
15705: if (@unused) {
15706: $resulttext .= '<li>'.
15707: &mt('Help form fields changed to "Not shown": [_1].',
15708: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
15709: '</li>';
15710: }
15711: if ($maxsizechg) {
15712: $resulttext .= '<li>'.
15713: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
15714: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
15715: '</li>';
15716: }
15717: }
1.28 raeburn 15718: $resulttext .= '</ul>';
15719: } else {
1.288 raeburn 15720: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 15721: }
15722: } else {
15723: $resulttext = '<span class="LC_error">'.
15724: &mt('An error occurred: [_1].',$putresult).'</span>';
15725: }
15726: return $resulttext;
15727: }
15728:
1.357 raeburn 15729: sub modify_privacy {
15730: my ($dom,%domconfig) = @_;
15731: my ($resulttext,%current,%changes);
15732: if (ref($domconfig{'privacy'}) eq 'HASH') {
15733: %current = %{$domconfig{'privacy'}};
15734: }
15735: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
15736: my @items = ('domain','author','course','community');
15737: my %names = &Apache::lonlocal::texthash (
15738: domain => 'Assigned domain role(s)',
15739: author => 'Assigned co-author role(s)',
15740: course => 'Assigned course role(s)',
15741: community => 'Assigned community role',
15742: );
15743: my %roles = &Apache::lonlocal::texthash (
15744: domain => 'Domain role',
15745: author => 'Co-author role',
15746: course => 'Course role',
15747: community => 'Community role',
15748: );
15749: my %titles = &Apache::lonlocal::texthash (
15750: approval => 'Approval for role in different domain',
15751: othdom => 'User information available in other domain',
15752: priv => 'Information viewable by privileged user in same domain',
15753: unpriv => 'Information viewable by unprivileged user in same domain',
15754: instdom => 'Other domain shares institution/provider',
15755: extdom => 'Other domain has different institution/provider',
15756: none => 'Not allowed',
15757: user => 'User authorizes',
15758: domain => 'Domain Coordinator authorizes',
15759: auto => 'Unrestricted',
15760: );
15761: my %fieldnames = &Apache::lonlocal::texthash (
15762: id => 'Student/Employee ID',
15763: permanentemail => 'E-mail address',
15764: lastname => 'Last Name',
15765: firstname => 'First Name',
15766: middlename => 'Middle Name',
15767: generation => 'Generation',
15768: );
15769: my ($othertitle,$usertypes,$types) =
15770: &Apache::loncommon::sorted_inst_types($dom);
15771: my (%by_ip,%by_location,@intdoms,@instdoms);
15772: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
15773:
15774: my %privacyhash = (
15775: 'approval' => {
15776: instdom => {},
15777: extdom => {},
15778: },
15779: 'othdom' => {},
15780: 'priv' => {},
15781: 'unpriv' => {},
15782: );
15783: foreach my $item (@items) {
15784: if (@instdoms > 1) {
15785: if ($env{'form.privacy_approval_instdom'.$item} =~ /^(none|user|domain|auto)$/) {
15786: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
15787: }
15788: if (ref($current{'approval'}) eq 'HASH') {
15789: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
15790: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
15791: $changes{'approval'} = 1;
15792: }
15793: }
15794: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
15795: $changes{'approval'} = 1;
15796: }
15797: }
15798: if (keys(%by_location) > 0) {
15799: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
15800: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
15801: }
15802: if (ref($current{'approval'}) eq 'HASH') {
15803: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
15804: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
15805: $changes{'approval'} = 1;
15806: }
15807: }
15808: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
15809: $changes{'approval'} = 1;
15810: }
15811: }
15812: foreach my $status ('priv','unpriv') {
15813: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
15814: my @newvalues;
15815: foreach my $field (@possibles) {
15816: if (grep(/^\Q$field\E$/,@fields)) {
15817: $privacyhash{$status}{$item}{$field} = 1;
15818: push(@newvalues,$field);
15819: }
15820: }
15821: @newvalues = sort(@newvalues);
15822: if (ref($current{$status}) eq 'HASH') {
15823: if (ref($current{$status}{$item}) eq 'HASH') {
15824: my @currvalues = sort(keys(%{$current{$status}{$item}}));
15825: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
15826: if (@diffs > 0) {
15827: $changes{$status} = 1;
15828: }
15829: }
15830: } else {
15831: my @stdfields;
15832: foreach my $field (@fields) {
15833: if ($field eq 'id') {
15834: next if ($status eq 'unpriv');
15835: next if (($status eq 'priv') && ($item eq 'community'));
15836: }
15837: push(@stdfields,$field);
15838: }
15839: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
15840: if (@diffs > 0) {
15841: $changes{$status} = 1;
15842: }
15843: }
15844: }
15845: }
15846: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
15847: my @statuses;
15848: if (ref($types) eq 'ARRAY') {
15849: @statuses = @{$types};
15850: }
15851: foreach my $type (@statuses,'default') {
15852: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
15853: my @newvalues;
15854: foreach my $field (sort(@possfields)) {
15855: if (grep(/^\Q$field\E$/,@fields)) {
15856: $privacyhash{'othdom'}{$type}{$field} = 1;
15857: push(@newvalues,$field);
15858: }
15859: }
15860: @newvalues = sort(@newvalues);
15861: if (ref($current{'othdom'}) eq 'HASH') {
15862: if (ref($current{'othdom'}{$type}) eq 'HASH') {
15863: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
15864: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
15865: if (@diffs > 0) {
15866: $changes{'othdom'} = 1;
15867: }
15868: }
15869: } else {
15870: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
15871: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
15872: if (@diffs > 0) {
15873: $changes{'othdom'} = 1;
15874: }
15875: }
15876: }
15877: }
15878: my %confighash = (
15879: privacy => \%privacyhash,
15880: );
15881: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
15882: if ($putresult eq 'ok') {
15883: if (keys(%changes) > 0) {
15884: $resulttext = &mt('Changes made: ').'<ul>';
15885: foreach my $key ('approval','othdom','priv','unpriv') {
15886: if ($changes{$key}) {
15887: $resulttext .= '<li>'.$titles{$key}.':<ul>';
15888: if ($key eq 'approval') {
15889: if (keys(%{$privacyhash{$key}{instdom}})) {
15890: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
15891: foreach my $item (@items) {
15892: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
15893: }
15894: $resulttext .= '</ul></li>';
15895: }
15896: if (keys(%{$privacyhash{$key}{extdom}})) {
15897: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
15898: foreach my $item (@items) {
15899: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
15900: }
15901: $resulttext .= '</ul></li>';
15902: }
15903: } elsif ($key eq 'othdom') {
15904: my @statuses;
15905: if (ref($types) eq 'ARRAY') {
15906: @statuses = @{$types};
15907: }
15908: if (ref($privacyhash{$key}) eq 'HASH') {
15909: foreach my $status (@statuses,'default') {
15910: if ($status eq 'default') {
15911: $resulttext .= '<li>'.$othertitle.': ';
15912: } elsif (ref($usertypes) eq 'HASH') {
15913: $resulttext .= '<li>'.$usertypes->{$status}.': ';
15914: } else {
15915: next;
15916: }
15917: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
15918: if (keys(%{$privacyhash{$key}{$status}})) {
15919: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
15920: } else {
15921: $resulttext .= &mt('none');
15922: }
15923: }
15924: $resulttext .= '</li>';
15925: }
15926: }
15927: } else {
15928: foreach my $item (@items) {
15929: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
15930: $resulttext .= '<li>'.$names{$item}.': ';
15931: if (keys(%{$privacyhash{$key}{$item}})) {
15932: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
15933: } else {
15934: $resulttext .= &mt('none');
15935: }
15936: $resulttext .= '</li>';
15937: }
15938: }
15939: }
15940: $resulttext .= '</ul></li>';
15941: }
15942: }
15943: } else {
15944: $resulttext = &mt('No changes made to user information settings');
15945: }
15946: } else {
15947: $resulttext = '<span class="LC_error">'.
15948: &mt('An error occurred: [_1]',$putresult).'</span>';
15949: }
15950: return $resulttext;
15951: }
15952:
1.354 raeburn 15953: sub modify_passwords {
15954: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 15955: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
15956: $updatedefaults,$updateconf);
1.354 raeburn 15957: my $customfn = 'resetpw.html';
15958: if (ref($domconfig{'passwords'}) eq 'HASH') {
15959: %current = %{$domconfig{'passwords'}};
15960: }
15961: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15962: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
15963: if (ref($types) eq 'ARRAY') {
15964: @oktypes = @{$types};
15965: }
15966: push(@oktypes,'default');
15967:
15968: my %titles = &Apache::lonlocal::texthash (
15969: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
15970: intauth_check => 'Check bcrypt cost if authenticated',
15971: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
15972: permanent => 'Permanent e-mail address',
15973: critical => 'Critical notification address',
15974: notify => 'Notification address',
15975: min => 'Minimum password length',
15976: max => 'Maximum password length',
15977: chars => 'Required characters',
15978: expire => 'Password expiration (days)',
1.356 raeburn 15979: numsaved => 'Number of previous passwords to save',
1.354 raeburn 15980: reset => 'Resetting Forgotten Password',
15981: intauth => 'Encryption of Stored Passwords (Internal Auth)',
15982: rules => 'Rules for LON-CAPA Passwords',
15983: crsownerchg => 'Course Owner Changing Student Passwords',
15984: username => 'Username',
15985: email => 'E-mail address',
15986: );
15987:
15988: #
15989: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
15990: #
15991: my (%curr_defaults,%save_defaults);
15992: if (ref($domconfig{'defaults'}) eq 'HASH') {
15993: foreach my $key (keys(%{$domconfig{'defaults'}})) {
15994: if ($key =~ /^intauth_(cost|check|switch)$/) {
15995: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
15996: } else {
15997: $save_defaults{$key} = $domconfig{'defaults'}{$key};
15998: }
15999: }
16000: }
16001: my %staticdefaults = (
16002: 'resetlink' => 2,
16003: 'resetcase' => \@oktypes,
16004: 'resetprelink' => 'both',
16005: 'resetemail' => ['critical','notify','permanent'],
16006: 'intauth_cost' => 10,
16007: 'intauth_check' => 0,
16008: 'intauth_switch' => 0,
16009: );
1.365 raeburn 16010: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 16011: foreach my $type (@oktypes) {
16012: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
16013: }
16014: my $linklife = $env{'form.passwords_link'};
16015: $linklife =~ s/^\s+|\s+$//g;
16016: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
16017: $newvalues{'resetlink'} = $linklife;
16018: if ($current{'resetlink'}) {
16019: if ($current{'resetlink'} ne $linklife) {
16020: $changes{'reset'} = 1;
16021: }
1.368 raeburn 16022: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16023: if ($staticdefaults{'resetlink'} ne $linklife) {
16024: $changes{'reset'} = 1;
16025: }
16026: }
16027: } elsif ($current{'resetlink'}) {
16028: $changes{'reset'} = 1;
16029: }
16030: my @casesens;
16031: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
16032: foreach my $case (sort(@posscase)) {
16033: if (grep(/^\Q$case\E$/,@oktypes)) {
16034: push(@casesens,$case);
16035: }
16036: }
16037: $newvalues{'resetcase'} = \@casesens;
16038: if (ref($current{'resetcase'}) eq 'ARRAY') {
16039: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
16040: if (@diffs > 0) {
16041: $changes{'reset'} = 1;
16042: }
1.368 raeburn 16043: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16044: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
16045: if (@diffs > 0) {
16046: $changes{'reset'} = 1;
16047: }
16048: }
16049: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
16050: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
16051: if (exists($current{'resetprelink'})) {
16052: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
16053: $changes{'reset'} = 1;
16054: }
1.368 raeburn 16055: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16056: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
16057: $changes{'reset'} = 1;
16058: }
16059: }
16060: } elsif ($current{'resetprelink'}) {
16061: $changes{'reset'} = 1;
16062: }
16063: foreach my $type (@oktypes) {
16064: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
16065: my @postlink;
16066: foreach my $item (sort(@possplink)) {
16067: if ($item =~ /^(email|username)$/) {
16068: push(@postlink,$item);
16069: }
16070: }
16071: $newvalues{'resetpostlink'}{$type} = \@postlink;
16072: unless ($changes{'reset'}) {
16073: if (ref($current{'resetpostlink'}) eq 'HASH') {
16074: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
16075: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
16076: if (@diffs > 0) {
16077: $changes{'reset'} = 1;
16078: }
16079: } else {
16080: $changes{'reset'} = 1;
16081: }
1.368 raeburn 16082: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16083: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
16084: if (@diffs > 0) {
16085: $changes{'reset'} = 1;
16086: }
16087: }
16088: }
16089: }
16090: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
16091: my @resetemail;
16092: foreach my $item (sort(@possemailsrc)) {
16093: if ($item =~ /^(permanent|critical|notify)$/) {
16094: push(@resetemail,$item);
16095: }
16096: }
16097: $newvalues{'resetemail'} = \@resetemail;
16098: unless ($changes{'reset'}) {
16099: if (ref($current{'resetemail'}) eq 'ARRAY') {
16100: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
16101: if (@diffs > 0) {
16102: $changes{'reset'} = 1;
16103: }
1.368 raeburn 16104: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16105: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
16106: if (@diffs > 0) {
16107: $changes{'reset'} = 1;
16108: }
16109: }
16110: }
16111: if ($env{'form.passwords_stdtext'} == 0) {
16112: $newvalues{'resetremove'} = 1;
16113: unless ($current{'resetremove'}) {
16114: $changes{'reset'} = 1;
16115: }
16116: } elsif ($current{'resetremove'}) {
16117: $changes{'reset'} = 1;
16118: }
16119: if ($env{'form.passwords_customfile.filename'} ne '') {
16120: my $servadm = $r->dir_config('lonAdmEMail');
16121: my ($configuserok,$author_ok,$switchserver) =
16122: &config_check($dom,$confname,$servadm);
16123: my $error;
16124: if ($configuserok eq 'ok') {
16125: if ($switchserver) {
16126: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
16127: } else {
16128: if ($author_ok eq 'ok') {
16129: my ($result,$customurl) =
16130: &publishlogo($r,'upload','passwords_customfile',$dom,
16131: $confname,'customtext/resetpw','','',$customfn);
16132: if ($result eq 'ok') {
16133: $newvalues{'resetcustom'} = $customurl;
16134: $changes{'reset'} = 1;
16135: } else {
16136: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
16137: }
16138: } else {
16139: $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);
16140: }
16141: }
16142: } else {
16143: $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);
16144: }
16145: if ($error) {
16146: &Apache::lonnet::logthis($error);
16147: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
16148: }
16149: } elsif ($current{'resetcustom'}) {
16150: if ($env{'form.passwords_custom_del'}) {
16151: $changes{'reset'} = 1;
16152: } else {
16153: $newvalues{'resetcustom'} = $current{'resetcustom'};
16154: }
16155: }
16156: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
16157: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
16158: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
16159: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
16160: $changes{'intauth'} = 1;
16161: }
16162: } else {
16163: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
16164: }
16165: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
16166: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
16167: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
16168: $changes{'intauth'} = 1;
16169: }
16170: } else {
16171: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
16172: }
16173: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
16174: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
16175: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
16176: $changes{'intauth'} = 1;
16177: }
16178: } else {
16179: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
16180: }
16181: foreach my $item ('cost','check','switch') {
16182: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
16183: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
16184: $updatedefaults = 1;
16185: }
16186: }
1.356 raeburn 16187: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 16188: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.356 raeburn 16189: my $ruleok;
16190: if ($rule eq 'expire') {
1.365 raeburn 16191: if (($env{'form.passwords_'.$rule} =~ /^\d+(|\.\d*)$/) &&
16192: ($env{'form.passwords_'.$rule} ne '0')) {
1.359 raeburn 16193: $ruleok = 1;
1.356 raeburn 16194: }
1.365 raeburn 16195: } elsif ($rule eq 'min') {
16196: if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
16197: if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
16198: $ruleok = 1;
16199: }
16200: }
16201: } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
16202: ($env{'form.passwords_'.$rule} ne '0')) {
1.356 raeburn 16203: $ruleok = 1;
16204: }
16205: if ($ruleok) {
1.354 raeburn 16206: $newvalues{$rule} = $env{'form.passwords_'.$rule};
16207: if (exists($current{$rule})) {
16208: if ($newvalues{$rule} ne $current{$rule}) {
16209: $changes{'rules'} = 1;
16210: }
16211: } elsif ($rule eq 'min') {
16212: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
16213: $changes{'rules'} = 1;
16214: }
1.370 raeburn 16215: } else {
16216: $changes{'rules'} = 1;
1.354 raeburn 16217: }
16218: } elsif (exists($current{$rule})) {
16219: $changes{'rules'} = 1;
16220: }
16221: }
16222: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
16223: my @chars;
16224: foreach my $item (sort(@posschars)) {
16225: if ($item =~ /^(uc|lc|num|spec)$/) {
16226: push(@chars,$item);
16227: }
16228: }
16229: $newvalues{'chars'} = \@chars;
16230: unless ($changes{'rules'}) {
16231: if (ref($current{'chars'}) eq 'ARRAY') {
16232: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
16233: if (@diffs > 0) {
16234: $changes{'rules'} = 1;
16235: }
16236: } else {
16237: if (@chars > 0) {
16238: $changes{'rules'} = 1;
16239: }
16240: }
16241: }
1.359 raeburn 16242: my %crsownerchg = (
16243: by => [],
16244: for => [],
16245: );
16246: foreach my $item ('by','for') {
16247: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
16248: foreach my $type (sort(@posstypes)) {
16249: if (grep(/^\Q$type\E$/,@oktypes)) {
16250: push(@{$crsownerchg{$item}},$type);
16251: }
16252: }
16253: }
16254: $newvalues{'crsownerchg'} = \%crsownerchg;
16255: if (ref($current{'crsownerchg'}) eq 'HASH') {
16256: foreach my $item ('by','for') {
16257: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
16258: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
16259: if (@diffs > 0) {
16260: $changes{'crsownerchg'} = 1;
16261: last;
16262: }
16263: }
16264: }
1.368 raeburn 16265: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 16266: foreach my $item ('by','for') {
16267: if (@{$crsownerchg{$item}} > 0) {
16268: $changes{'crsownerchg'} = 1;
16269: last;
16270: }
1.354 raeburn 16271: }
16272: }
16273:
16274: my %confighash = (
16275: defaults => \%save_defaults,
16276: passwords => \%newvalues,
16277: );
16278: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
16279:
16280: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
16281: if ($putresult eq 'ok') {
16282: if (keys(%changes) > 0) {
16283: $resulttext = &mt('Changes made: ').'<ul>';
16284: foreach my $key ('reset','intauth','rules','crsownerchg') {
16285: if ($changes{$key}) {
1.355 raeburn 16286: unless ($key eq 'intauth') {
16287: $updateconf = 1;
16288: }
1.354 raeburn 16289: $resulttext .= '<li>'.$titles{$key}.':<ul>';
16290: if ($key eq 'reset') {
16291: if ($confighash{'passwords'}{'captcha'} eq 'original') {
16292: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
16293: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
16294: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 16295: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
16296: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
16297: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
16298: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
16299: }
1.354 raeburn 16300: } else {
16301: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
16302: }
16303: if ($confighash{'passwords'}{'resetlink'}) {
16304: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
16305: } else {
16306: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
16307: &mt('Will default to 2 hours').'</li>';
16308: }
16309: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
16310: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
16311: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
16312: } else {
16313: my $casesens;
16314: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
16315: if ($type eq 'default') {
16316: $casesens .= $othertitle.', ';
16317: } elsif ($usertypes->{$type} ne '') {
16318: $casesens .= $usertypes->{$type}.', ';
16319: }
16320: }
16321: $casesens =~ s/\Q, \E$//;
16322: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
16323: }
16324: } else {
16325: $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>';
16326: }
16327: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
16328: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
16329: } else {
16330: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
16331: }
16332: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
16333: my $output;
16334: if (ref($types) eq 'ARRAY') {
16335: foreach my $type (@{$types}) {
16336: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
16337: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
16338: $output .= $usertypes->{$type}.' -- '.&mt('none');
16339: } else {
16340: $output .= $usertypes->{$type}.' -- '.
16341: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
16342: }
16343: }
16344: }
16345: }
16346: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
16347: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
16348: $output .= $othertitle.' -- '.&mt('none');
16349: } else {
16350: $output .= $othertitle.' -- '.
16351: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
16352: }
16353: }
16354: if ($output) {
16355: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
16356: } else {
16357: $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>';
16358: }
16359: } else {
16360: $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>';
16361: }
16362: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
16363: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
16364: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
16365: } else {
16366: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
16367: }
16368: } else {
1.379 ! raeburn 16369: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
1.354 raeburn 16370: }
16371: if ($confighash{'passwords'}{'resetremove'}) {
16372: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
16373: } else {
16374: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
16375: }
16376: if ($confighash{'passwords'}{'resetcustom'}) {
16377: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 16378: &mt('custom text'),600,500,undef,undef,
16379: undef,undef,'background-color:#ffffff');
16380: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 16381: } else {
16382: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
16383: }
16384: } elsif ($key eq 'intauth') {
16385: foreach my $item ('cost','switch','check') {
16386: my $value = $save_defaults{$key.'_'.$item};
16387: if ($item eq 'switch') {
16388: my %optiondesc = &Apache::lonlocal::texthash (
16389: 0 => 'No',
16390: 1 => 'Yes',
16391: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
16392: );
16393: if ($value =~ /^(0|1|2)$/) {
16394: $value = $optiondesc{$value};
16395: } else {
16396: $value = &mt('none -- defaults to No');
16397: }
16398: } elsif ($item eq 'check') {
16399: my %optiondesc = &Apache::lonlocal::texthash (
16400: 0 => 'No',
16401: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
16402: 2 => 'Yes, disallow login if stored cost is less than domain default',
16403: );
16404: if ($value =~ /^(0|1|2)$/) {
16405: $value = $optiondesc{$value};
16406: } else {
16407: $value = &mt('none -- defaults to No');
16408: }
16409: }
16410: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
16411: }
16412: } elsif ($key eq 'rules') {
1.356 raeburn 16413: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 16414: if ($confighash{'passwords'}{$rule} eq '') {
16415: if ($rule eq 'min') {
1.356 raeburn 16416: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 16417: ' '.&mt('Default of [_1] will be used',
16418: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 16419: } else {
16420: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 16421: }
16422: } else {
16423: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
16424: }
16425: }
1.370 raeburn 16426: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
16427: if (@{$confighash{'passwords'}{'chars'}} > 0) {
16428: my %rulenames = &Apache::lonlocal::texthash(
16429: uc => 'At least one upper case letter',
16430: lc => 'At least one lower case letter',
16431: num => 'At least one number',
16432: spec => 'At least one non-alphanumeric',
16433: );
16434: my $needed = '<ul><li>'.
16435: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
16436: '</li></ul>';
16437: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
16438: } else {
16439: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
16440: }
16441: } else {
16442: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
16443: }
1.354 raeburn 16444: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 16445: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
16446: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
16447: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
16448: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
16449: } else {
16450: my %crsownerstr;
16451: foreach my $item ('by','for') {
16452: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
16453: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
16454: if ($type eq 'default') {
16455: $crsownerstr{$item} .= $othertitle.', ';
16456: } elsif ($usertypes->{$type} ne '') {
16457: $crsownerstr{$item} .= $usertypes->{$type}.', ';
16458: }
16459: }
16460: $crsownerstr{$item} =~ s/\Q, \E$//;
16461: }
16462: }
16463: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
16464: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
16465: }
1.354 raeburn 16466: } else {
1.359 raeburn 16467: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 16468: }
16469: }
16470: $resulttext .= '</ul></li>';
16471: }
16472: }
16473: $resulttext .= '</ul>';
16474: } else {
16475: $resulttext = &mt('No changes made to password settings');
16476: }
1.355 raeburn 16477: my $cachetime = 24*60*60;
1.354 raeburn 16478: if ($updatedefaults) {
16479: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16480: if (ref($lastactref) eq 'HASH') {
16481: $lastactref->{'domdefaults'} = 1;
16482: }
16483: }
1.355 raeburn 16484: if ($updateconf) {
16485: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
16486: if (ref($lastactref) eq 'HASH') {
16487: $lastactref->{'passwdconf'} = 1;
16488: }
16489: }
1.354 raeburn 16490: } else {
16491: $resulttext = '<span class="LC_error">'.
16492: &mt('An error occurred: [_1]',$putresult).'</span>';
16493: }
16494: if ($errors) {
16495: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
16496: $errors.'</ul></p>';
16497: }
16498: return $resulttext;
16499: }
16500:
1.28 raeburn 16501: sub modify_usercreation {
1.27 raeburn 16502: my ($dom,%domconfig) = @_;
1.224 raeburn 16503: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 16504: my $warningmsg;
1.27 raeburn 16505: if (ref($domconfig{'usercreation'}) eq 'HASH') {
16506: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 16507: if ($key eq 'cancreate') {
16508: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
16509: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 16510: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
16511: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
16512: } else {
1.224 raeburn 16513: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
16514: }
16515: }
16516: }
16517: } elsif ($key eq 'email_rule') {
16518: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
16519: } else {
16520: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
16521: }
1.27 raeburn 16522: }
16523: }
16524: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 16525: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 16526: my @contexts = ('author','course','requestcrs');
1.34 raeburn 16527: foreach my $item(@contexts) {
1.224 raeburn 16528: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 16529: }
1.34 raeburn 16530: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
16531: foreach my $item (@contexts) {
1.224 raeburn 16532: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
16533: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 16534: }
1.27 raeburn 16535: }
1.34 raeburn 16536: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
16537: foreach my $item (@contexts) {
1.43 raeburn 16538: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 16539: if ($cancreate{$item} ne 'any') {
16540: push(@{$changes{'cancreate'}},$item);
16541: }
16542: } else {
16543: if ($cancreate{$item} ne 'none') {
16544: push(@{$changes{'cancreate'}},$item);
16545: }
1.27 raeburn 16546: }
16547: }
16548: } else {
1.43 raeburn 16549: foreach my $item (@contexts) {
1.34 raeburn 16550: push(@{$changes{'cancreate'}},$item);
16551: }
1.27 raeburn 16552: }
1.34 raeburn 16553:
1.27 raeburn 16554: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
16555: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
16556: if (!grep(/^\Q$type\E$/,@username_rule)) {
16557: push(@{$changes{'username_rule'}},$type);
16558: }
16559: }
16560: foreach my $type (@username_rule) {
16561: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
16562: push(@{$changes{'username_rule'}},$type);
16563: }
16564: }
16565: } else {
16566: push(@{$changes{'username_rule'}},@username_rule);
16567: }
16568:
1.32 raeburn 16569: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
16570: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
16571: if (!grep(/^\Q$type\E$/,@id_rule)) {
16572: push(@{$changes{'id_rule'}},$type);
16573: }
16574: }
16575: foreach my $type (@id_rule) {
16576: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
16577: push(@{$changes{'id_rule'}},$type);
16578: }
16579: }
16580: } else {
16581: push(@{$changes{'id_rule'}},@id_rule);
16582: }
16583:
1.43 raeburn 16584: my @authen_contexts = ('author','course','domain');
1.325 raeburn 16585: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 16586: my %authhash;
1.43 raeburn 16587: foreach my $item (@authen_contexts) {
1.28 raeburn 16588: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
16589: foreach my $auth (@authtypes) {
16590: if (grep(/^\Q$auth\E$/,@authallowed)) {
16591: $authhash{$item}{$auth} = 1;
16592: } else {
16593: $authhash{$item}{$auth} = 0;
16594: }
16595: }
16596: }
16597: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 16598: foreach my $item (@authen_contexts) {
1.28 raeburn 16599: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
16600: foreach my $auth (@authtypes) {
16601: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
16602: push(@{$changes{'authtypes'}},$item);
16603: last;
16604: }
16605: }
16606: }
16607: }
16608: } else {
1.43 raeburn 16609: foreach my $item (@authen_contexts) {
1.28 raeburn 16610: push(@{$changes{'authtypes'}},$item);
16611: }
16612: }
16613:
1.224 raeburn 16614: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
16615: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
16616: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
16617: $save_usercreate{'id_rule'} = \@id_rule;
16618: $save_usercreate{'username_rule'} = \@username_rule,
16619: $save_usercreate{'authtypes'} = \%authhash;
16620:
1.27 raeburn 16621: my %usercreation_hash = (
1.224 raeburn 16622: usercreation => \%save_usercreate,
16623: );
1.27 raeburn 16624:
16625: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
16626: $dom);
1.50 raeburn 16627:
1.224 raeburn 16628: if ($putresult eq 'ok') {
16629: if (keys(%changes) > 0) {
16630: $resulttext = &mt('Changes made:').'<ul>';
16631: if (ref($changes{'cancreate'}) eq 'ARRAY') {
16632: my %lt = &usercreation_types();
16633: foreach my $type (@{$changes{'cancreate'}}) {
16634: my $chgtext = $lt{$type}.', ';
16635: if ($cancreate{$type} eq 'none') {
16636: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
16637: } elsif ($cancreate{$type} eq 'any') {
16638: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
16639: } elsif ($cancreate{$type} eq 'official') {
16640: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
16641: } elsif ($cancreate{$type} eq 'unofficial') {
16642: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
16643: }
16644: $resulttext .= '<li>'.$chgtext.'</li>';
16645: }
16646: }
16647: if (ref($changes{'username_rule'}) eq 'ARRAY') {
16648: my ($rules,$ruleorder) =
16649: &Apache::lonnet::inst_userrules($dom,'username');
16650: my $chgtext = '<ul>';
16651: foreach my $type (@username_rule) {
16652: if (ref($rules->{$type}) eq 'HASH') {
16653: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
16654: }
16655: }
16656: $chgtext .= '</ul>';
16657: if (@username_rule > 0) {
16658: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
16659: } else {
16660: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
16661: }
16662: }
16663: if (ref($changes{'id_rule'}) eq 'ARRAY') {
16664: my ($idrules,$idruleorder) =
16665: &Apache::lonnet::inst_userrules($dom,'id');
16666: my $chgtext = '<ul>';
16667: foreach my $type (@id_rule) {
16668: if (ref($idrules->{$type}) eq 'HASH') {
16669: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
16670: }
16671: }
16672: $chgtext .= '</ul>';
16673: if (@id_rule > 0) {
16674: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
16675: } else {
16676: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
16677: }
16678: }
16679: my %authname = &authtype_names();
16680: my %context_title = &context_names();
16681: if (ref($changes{'authtypes'}) eq 'ARRAY') {
16682: my $chgtext = '<ul>';
16683: foreach my $type (@{$changes{'authtypes'}}) {
16684: my @allowed;
16685: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
16686: foreach my $auth (@authtypes) {
16687: if ($authhash{$type}{$auth}) {
16688: push(@allowed,$authname{$auth});
16689: }
16690: }
16691: if (@allowed > 0) {
16692: $chgtext .= join(', ',@allowed).'</li>';
16693: } else {
16694: $chgtext .= &mt('none').'</li>';
16695: }
16696: }
16697: $chgtext .= '</ul>';
16698: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
16699: $resulttext .= '</li>';
16700: }
16701: $resulttext .= '</ul>';
16702: } else {
16703: $resulttext = &mt('No changes made to user creation settings');
16704: }
16705: } else {
16706: $resulttext = '<span class="LC_error">'.
16707: &mt('An error occurred: [_1]',$putresult).'</span>';
16708: }
16709: if ($warningmsg ne '') {
16710: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
16711: }
16712: return $resulttext;
16713: }
16714:
16715: sub modify_selfcreation {
1.305 raeburn 16716: my ($dom,$lastactref,%domconfig) = @_;
16717: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
16718: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
16719: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 16720: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
16721: if (ref($typesref) eq 'ARRAY') {
16722: @types = @{$typesref};
16723: }
16724: if (ref($usertypesref) eq 'HASH') {
16725: %usertypes = %{$usertypesref};
1.228 raeburn 16726: }
1.303 raeburn 16727: $usertypes{'default'} = $othertitle;
1.224 raeburn 16728: #
16729: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
16730: #
16731: if (ref($domconfig{'usercreation'}) eq 'HASH') {
16732: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
16733: if ($key eq 'cancreate') {
16734: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
16735: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
16736: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 16737: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
16738: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
16739: ($item eq 'emailusername') || ($item eq 'shibenv') ||
16740: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 16741: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 16742: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
16743: } else {
16744: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
16745: }
16746: }
16747: }
16748: } elsif ($key eq 'email_rule') {
16749: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
16750: } else {
16751: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
16752: }
16753: }
16754: }
16755: #
16756: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
16757: #
16758: if (ref($domconfig{'usermodification'}) eq 'HASH') {
16759: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
16760: if ($key eq 'selfcreate') {
16761: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
16762: } else {
16763: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
16764: }
16765: }
16766: }
1.305 raeburn 16767: #
16768: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
16769: #
16770: if (ref($domconfig{'inststatus'}) eq 'HASH') {
16771: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
16772: if ($key eq 'inststatusguest') {
16773: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
16774: } else {
16775: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
16776: }
16777: }
16778: }
1.224 raeburn 16779:
16780: my @contexts = ('selfcreate');
16781: @{$cancreate{'selfcreate'}} = ();
16782: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 16783: if (@types) {
16784: @{$cancreate{'statustocreate'}} = ();
16785: }
1.236 raeburn 16786: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 16787: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 16788: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 16789: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 16790: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 16791: my %selfcreatetypes = (
16792: sso => 'users authenticated by institutional single sign on',
16793: login => 'users authenticated by institutional log-in',
1.303 raeburn 16794: email => 'users verified by e-mail',
1.50 raeburn 16795: );
1.224 raeburn 16796: #
16797: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
16798: # is permitted.
16799: #
1.305 raeburn 16800: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 16801:
1.305 raeburn 16802: my (@statuses,%email_rule);
1.228 raeburn 16803: foreach my $item ('login','sso','email') {
1.224 raeburn 16804: if ($item eq 'email') {
1.236 raeburn 16805: if ($env{'form.cancreate_email'}) {
1.305 raeburn 16806: if (@types) {
16807: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
16808: foreach my $status (@poss_statuses) {
16809: if (grep(/^\Q$status\E$/,(@types,'default'))) {
16810: push(@statuses,$status);
16811: }
16812: }
16813: $save_inststatus{'inststatusguest'} = \@statuses;
16814: } else {
16815: push(@statuses,'default');
16816: }
16817: if (@statuses) {
16818: my %curr_rule;
16819: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
16820: foreach my $type (@statuses) {
16821: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 16822: }
1.305 raeburn 16823: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
16824: foreach my $type (@statuses) {
16825: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
16826: }
16827: }
16828: push(@{$cancreate{'selfcreate'}},'email');
16829: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
16830: my %curremaildom;
16831: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
16832: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
16833: }
16834: foreach my $type (@statuses) {
16835: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
16836: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
16837: }
16838: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
16839: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
16840: }
16841: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
16842: #
16843: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
16844: #
16845: my $chosen = $1;
16846: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
16847: my $emaildom;
16848: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
16849: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
16850: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
16851: if (ref($curremaildom{$type}) eq 'HASH') {
16852: if (exists($curremaildom{$type}{$chosen})) {
16853: if ($curremaildom{$type}{$chosen} ne $emaildom) {
16854: push(@{$changes{'cancreate'}},'emaildomain');
16855: }
16856: } elsif ($emaildom ne '') {
16857: push(@{$changes{'cancreate'}},'emaildomain');
16858: }
16859: } elsif ($emaildom ne '') {
16860: push(@{$changes{'cancreate'}},'emaildomain');
16861: }
16862: }
16863: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
16864: } elsif ($chosen eq 'custom') {
16865: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
16866: $email_rule{$type} = [];
16867: if (ref($emailrules) eq 'HASH') {
16868: foreach my $rule (@possemail_rules) {
16869: if (exists($emailrules->{$rule})) {
16870: push(@{$email_rule{$type}},$rule);
16871: }
16872: }
16873: }
16874: if (@{$email_rule{$type}}) {
16875: $cancreate{'emailoptions'}{$type} = 'custom';
16876: if (ref($curr_rule{$type}) eq 'ARRAY') {
16877: if (@{$curr_rule{$type}} > 0) {
16878: foreach my $rule (@{$curr_rule{$type}}) {
16879: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
16880: push(@{$changes{'email_rule'}},$type);
16881: }
16882: }
16883: }
16884: foreach my $type (@{$email_rule{$type}}) {
16885: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
16886: push(@{$changes{'email_rule'}},$type);
16887: }
16888: }
16889: } else {
16890: push(@{$changes{'email_rule'}},$type);
16891: }
16892: }
16893: } else {
16894: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
16895: }
16896: }
16897: }
16898: if (@types) {
16899: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
16900: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
16901: if (@changed) {
16902: push(@{$changes{'inststatus'}},'inststatusguest');
16903: }
16904: } else {
16905: push(@{$changes{'inststatus'}},'inststatusguest');
16906: }
16907: }
16908: } else {
16909: delete($env{'form.cancreate_email'});
16910: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
16911: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
16912: push(@{$changes{'inststatus'}},'inststatusguest');
16913: }
16914: }
16915: }
16916: } else {
16917: $save_inststatus{'inststatusguest'} = [];
16918: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
16919: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
16920: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 16921: }
16922: }
1.224 raeburn 16923: }
16924: } else {
16925: if ($env{'form.cancreate_'.$item}) {
16926: push(@{$cancreate{'selfcreate'}},$item);
16927: }
16928: }
16929: }
1.305 raeburn 16930: my (%userinfo,%savecaptcha);
1.224 raeburn 16931: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
16932: #
1.228 raeburn 16933: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
16934: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 16935: #
1.236 raeburn 16936:
1.244 raeburn 16937: if ($env{'form.cancreate_email'}) {
1.228 raeburn 16938: push(@contexts,'emailusername');
1.305 raeburn 16939: if (@statuses) {
16940: foreach my $type (@statuses) {
1.228 raeburn 16941: if (ref($infofields) eq 'ARRAY') {
16942: foreach my $field (@{$infofields}) {
16943: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
16944: $cancreate{'emailusername'}{$type}{$field} = $1;
16945: }
16946: }
1.224 raeburn 16947: }
16948: }
16949: }
16950: #
16951: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 16952: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 16953: #
16954:
16955: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
16956: @approvalnotify = sort(@approvalnotify);
16957: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
16958: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
16959: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
16960: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
16961: push(@{$changes{'cancreate'}},'notify');
16962: }
16963: } else {
16964: if ($cancreate{'notify'}{'approval'}) {
16965: push(@{$changes{'cancreate'}},'notify');
16966: }
16967: }
16968: } elsif ($cancreate{'notify'}{'approval'}) {
16969: push(@{$changes{'cancreate'}},'notify');
16970: }
16971:
16972: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
16973: }
16974: #
1.236 raeburn 16975: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 16976: # institutional log-in.
16977: #
16978: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
16979: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
16980: ($domdefaults{'auth_def'} eq 'localauth'))) {
16981: $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.').' '.
16982: &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.');
16983: }
16984: }
16985: my @fields = ('lastname','firstname','middlename','generation',
16986: 'permanentemail','id');
1.240 raeburn 16987: my @shibfields = (@fields,'inststatus');
1.224 raeburn 16988: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
16989: #
16990: # Where usernames may created for institutional log-in and/or institutional single sign on:
16991: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
16992: # may self-create accounts
16993: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
16994: # which the user may supply, if institutional data is unavailable.
16995: #
16996: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 16997: if (@types) {
1.305 raeburn 16998: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
16999: push(@contexts,'statustocreate');
1.303 raeburn 17000: foreach my $type (@types) {
1.224 raeburn 17001: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
17002: foreach my $field (@fields) {
17003: if (grep(/^\Q$field\E$/,@modifiable)) {
17004: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
17005: } else {
17006: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
17007: }
17008: }
17009: }
17010: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 17011: foreach my $type (@types) {
1.224 raeburn 17012: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
17013: foreach my $field (@fields) {
17014: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
17015: $curr_usermodify{'selfcreate'}{$type}{$field}) {
17016: push(@{$changes{'selfcreate'}},$type);
17017: last;
17018: }
17019: }
17020: }
17021: }
17022: } else {
1.303 raeburn 17023: foreach my $type (@types) {
1.224 raeburn 17024: push(@{$changes{'selfcreate'}},$type);
17025: }
17026: }
17027: }
1.240 raeburn 17028: foreach my $field (@shibfields) {
17029: if ($env{'form.shibenv_'.$field} ne '') {
17030: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
17031: }
17032: }
17033: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
17034: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
17035: foreach my $field (@shibfields) {
17036: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
17037: push(@{$changes{'cancreate'}},'shibenv');
17038: }
17039: }
17040: } else {
17041: foreach my $field (@shibfields) {
17042: if ($env{'form.shibenv_'.$field}) {
17043: push(@{$changes{'cancreate'}},'shibenv');
17044: last;
17045: }
17046: }
17047: }
17048: }
1.224 raeburn 17049: }
17050: foreach my $item (@contexts) {
17051: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
17052: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
17053: if (ref($cancreate{$item}) eq 'ARRAY') {
17054: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
17055: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17056: push(@{$changes{'cancreate'}},$item);
17057: }
17058: }
17059: }
17060: }
17061: if (ref($cancreate{$item}) eq 'ARRAY') {
17062: foreach my $type (@{$cancreate{$item}}) {
17063: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
17064: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17065: push(@{$changes{'cancreate'}},$item);
17066: }
17067: }
17068: }
17069: }
17070: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
17071: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 17072: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
17073: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
17074: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
17075: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 17076: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17077: push(@{$changes{'cancreate'}},$item);
17078: }
17079: }
17080: }
1.305 raeburn 17081: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17082: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 17083: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17084: push(@{$changes{'cancreate'}},$item);
17085: }
1.224 raeburn 17086: }
17087: }
17088: }
1.305 raeburn 17089: foreach my $type (keys(%{$cancreate{$item}})) {
17090: if (ref($cancreate{$item}{$type}) eq 'HASH') {
17091: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
17092: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
17093: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 17094: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17095: push(@{$changes{'cancreate'}},$item);
17096: }
17097: }
17098: } else {
17099: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17100: push(@{$changes{'cancreate'}},$item);
17101: }
17102: }
17103: }
1.305 raeburn 17104: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17105: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 17106: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17107: push(@{$changes{'cancreate'}},$item);
17108: }
1.224 raeburn 17109: }
17110: }
17111: }
17112: }
17113: } elsif ($curr_usercreation{'cancreate'}{$item}) {
17114: if (ref($cancreate{$item}) eq 'ARRAY') {
17115: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
17116: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17117: push(@{$changes{'cancreate'}},$item);
17118: }
17119: }
1.305 raeburn 17120: }
17121: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17122: if (ref($cancreate{$item}) eq 'HASH') {
17123: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17124: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 17125: }
17126: }
17127: } elsif ($item eq 'emailusername') {
1.228 raeburn 17128: if (ref($cancreate{$item}) eq 'HASH') {
17129: foreach my $type (keys(%{$cancreate{$item}})) {
17130: if (ref($cancreate{$item}{$type}) eq 'HASH') {
17131: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
17132: if ($cancreate{$item}{$type}{$field}) {
17133: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17134: push(@{$changes{'cancreate'}},$item);
17135: }
17136: last;
17137: }
17138: }
17139: }
17140: }
1.224 raeburn 17141: }
17142: }
17143: }
17144: #
17145: # Populate %save_usercreate hash with updates to self-creation configuration.
17146: #
17147: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
17148: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 17149: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 17150: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
17151: if (ref($cancreate{'notify'}) eq 'HASH') {
17152: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
17153: }
1.236 raeburn 17154: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
17155: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
17156: }
1.303 raeburn 17157: if (ref($cancreate{'emailverified'}) eq 'HASH') {
17158: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
17159: }
1.305 raeburn 17160: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
17161: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
17162: }
1.303 raeburn 17163: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
17164: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
17165: }
1.224 raeburn 17166: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
17167: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
17168: }
1.240 raeburn 17169: if (ref($cancreate{'shibenv'}) eq 'HASH') {
17170: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
17171: }
1.224 raeburn 17172: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 17173: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 17174:
17175: my %userconfig_hash = (
17176: usercreation => \%save_usercreate,
17177: usermodification => \%save_usermodify,
1.305 raeburn 17178: inststatus => \%save_inststatus,
1.224 raeburn 17179: );
1.305 raeburn 17180:
1.224 raeburn 17181: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
17182: $dom);
17183: #
1.305 raeburn 17184: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 17185: #
1.27 raeburn 17186: if ($putresult eq 'ok') {
17187: if (keys(%changes) > 0) {
17188: $resulttext = &mt('Changes made:').'<ul>';
17189: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 17190: my %lt = &selfcreation_types();
1.34 raeburn 17191: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 17192: my $chgtext = '';
1.45 raeburn 17193: if ($type eq 'selfcreate') {
1.50 raeburn 17194: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 17195: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 17196: } else {
1.224 raeburn 17197: $chgtext .= &mt('Self-creation of a new account is permitted for:').
17198: '<ul>';
1.50 raeburn 17199: foreach my $case (@{$cancreate{$type}}) {
17200: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
17201: }
17202: $chgtext .= '</ul>';
1.100 raeburn 17203: if (ref($cancreate{$type}) eq 'ARRAY') {
17204: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
17205: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
17206: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 17207: $chgtext .= '<span class="LC_warning">'.
17208: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
17209: '</span><br />';
17210: }
17211: }
17212: }
17213: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 17214: if (!@statuses) {
17215: $chgtext .= '<span class="LC_warning">'.
17216: &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.").
17217: '</span><br />';
1.303 raeburn 17218:
1.100 raeburn 17219: }
17220: }
17221: }
1.43 raeburn 17222: }
1.240 raeburn 17223: } elsif ($type eq 'shibenv') {
17224: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 17225: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 17226: } else {
17227: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
17228: '<ul>';
17229: foreach my $field (@shibfields) {
17230: next if ($cancreate{$type}{$field} eq '');
17231: if ($field eq 'inststatus') {
17232: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
17233: } else {
17234: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
17235: }
17236: }
17237: $chgtext .= '</ul>';
1.303 raeburn 17238: }
1.93 raeburn 17239: } elsif ($type eq 'statustocreate') {
1.96 raeburn 17240: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
17241: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
17242: if (@{$cancreate{'selfcreate'}} > 0) {
17243: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 17244: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 17245: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 17246: $chgtext .= '<br />'.
17247: '<span class="LC_warning">'.
17248: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
17249: '</span>';
17250: }
1.303 raeburn 17251: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 17252: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 17253: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
17254: } else {
17255: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
17256: }
17257: $chgtext .= '<ul>';
17258: foreach my $case (@{$cancreate{$type}}) {
17259: if ($case eq 'default') {
17260: $chgtext .= '<li>'.$othertitle.'</li>';
17261: } else {
1.303 raeburn 17262: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 17263: }
17264: }
1.100 raeburn 17265: $chgtext .= '</ul>';
17266: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 17267: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 17268: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
17269: '</span>';
1.100 raeburn 17270: }
17271: }
17272: } else {
17273: if (@{$cancreate{$type}} == 0) {
17274: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
17275: } else {
17276: $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 17277: }
17278: }
1.303 raeburn 17279: $chgtext .= '<br />';
1.93 raeburn 17280: }
1.236 raeburn 17281: } elsif ($type eq 'selfcreateprocessing') {
17282: my %choices = &Apache::lonlocal::texthash (
17283: automatic => 'Automatic approval',
17284: approval => 'Queued for approval',
17285: );
1.305 raeburn 17286: if (@types) {
17287: if (@statuses) {
1.303 raeburn 17288: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 17289: '<ul>';
1.305 raeburn 17290: foreach my $status (@statuses) {
17291: if ($status eq 'default') {
17292: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 17293: } else {
1.305 raeburn 17294: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 17295: }
17296: }
17297: $chgtext .= '</ul>';
17298: }
17299: } else {
17300: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
17301: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
17302: }
17303: } elsif ($type eq 'emailverified') {
17304: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 17305: all => 'Same as e-mail',
17306: first => 'Omit @domain',
17307: free => 'Free to choose',
1.303 raeburn 17308: );
1.305 raeburn 17309: if (@types) {
17310: if (@statuses) {
1.303 raeburn 17311: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
17312: '<ul>';
1.305 raeburn 17313: foreach my $status (@statuses) {
1.362 raeburn 17314: if ($status eq 'default') {
1.305 raeburn 17315: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 17316: } else {
1.305 raeburn 17317: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 17318: }
17319: }
17320: $chgtext .= '</ul>';
17321: }
17322: } else {
1.305 raeburn 17323: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 17324: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 17325: }
1.305 raeburn 17326: } elsif ($type eq 'emailoptions') {
17327: my %options = &Apache::lonlocal::texthash (
17328: any => 'Any e-mail',
17329: inst => 'Institutional only',
17330: noninst => 'Non-institutional only',
17331: custom => 'Custom restrictions',
17332: );
17333: if (@types) {
17334: if (@statuses) {
17335: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
17336: '<ul>';
17337: foreach my $status (@statuses) {
17338: if ($type eq 'default') {
17339: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
17340: } else {
17341: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 17342: }
17343: }
1.305 raeburn 17344: $chgtext .= '</ul>';
17345: }
17346: } else {
17347: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
17348: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
17349: } else {
17350: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
17351: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 17352: }
1.305 raeburn 17353: }
17354: } elsif ($type eq 'emaildomain') {
17355: my $output;
17356: if (@statuses) {
17357: foreach my $type (@statuses) {
17358: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
17359: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
17360: if ($type eq 'default') {
17361: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17362: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
17363: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
17364: } else {
17365: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
17366: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
17367: }
1.303 raeburn 17368: } else {
1.305 raeburn 17369: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17370: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
17371: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
17372: } else {
17373: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
17374: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
17375: }
1.303 raeburn 17376: }
1.305 raeburn 17377: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
17378: if ($type eq 'default') {
17379: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17380: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
17381: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
17382: } else {
17383: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
17384: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
17385: }
1.303 raeburn 17386: } else {
1.305 raeburn 17387: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17388: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
17389: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
17390: } else {
17391: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
17392: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
17393: }
1.303 raeburn 17394: }
17395: }
17396: }
17397: }
1.305 raeburn 17398: }
17399: if ($output ne '') {
17400: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
17401: '<ul>'.$output.'</ul>';
1.236 raeburn 17402: }
1.165 raeburn 17403: } elsif ($type eq 'captcha') {
1.224 raeburn 17404: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 17405: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
17406: } else {
17407: my %captchas = &captcha_phrases();
1.224 raeburn 17408: if ($captchas{$savecaptcha{$type}}) {
17409: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 17410: } else {
1.210 raeburn 17411: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 17412: }
17413: }
17414: } elsif ($type eq 'recaptchakeys') {
17415: my ($privkey,$pubkey);
1.224 raeburn 17416: if (ref($savecaptcha{$type}) eq 'HASH') {
17417: $pubkey = $savecaptcha{$type}{'public'};
17418: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 17419: }
17420: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
17421: if (!$pubkey) {
17422: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
17423: } else {
17424: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
17425: }
17426: if (!$privkey) {
17427: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
17428: } else {
17429: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
17430: }
17431: $chgtext .= '</ul>';
1.269 raeburn 17432: } elsif ($type eq 'recaptchaversion') {
17433: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 17434: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 17435: }
1.224 raeburn 17436: } elsif ($type eq 'emailusername') {
17437: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 17438: if (@statuses) {
17439: foreach my $type (@statuses) {
1.228 raeburn 17440: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
17441: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 17442: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 17443: '<ul>';
17444: foreach my $field (@{$infofields}) {
17445: if ($cancreate{'emailusername'}{$type}{$field}) {
17446: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
17447: }
17448: }
1.245 raeburn 17449: $chgtext .= '</ul>';
17450: } else {
1.303 raeburn 17451: $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 17452: }
17453: } else {
1.303 raeburn 17454: $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 17455: }
17456: }
17457: }
17458: }
17459: } elsif ($type eq 'notify') {
1.303 raeburn 17460: my $numapprove = 0;
1.224 raeburn 17461: if (ref($changes{'cancreate'}) eq 'ARRAY') {
17462: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
17463: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 17464: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
17465: $numapprove ++;
1.224 raeburn 17466: }
17467: }
1.43 raeburn 17468: }
1.303 raeburn 17469: unless ($numapprove) {
17470: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
17471: }
1.34 raeburn 17472: }
1.224 raeburn 17473: if ($chgtext) {
17474: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 17475: }
17476: }
17477: }
1.305 raeburn 17478: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 17479: my ($emailrules,$emailruleorder) =
17480: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 17481: foreach my $type (@{$changes{'email_rule'}}) {
17482: if (ref($email_rule{$type}) eq 'ARRAY') {
17483: my $chgtext = '<ul>';
17484: foreach my $rule (@{$email_rule{$type}}) {
17485: if (ref($emailrules->{$rule}) eq 'HASH') {
17486: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
17487: }
17488: }
17489: $chgtext .= '</ul>';
1.310 raeburn 17490: my $typename;
1.305 raeburn 17491: if (@types) {
17492: if ($type eq 'default') {
17493: $typename = $othertitle;
17494: } else {
17495: $typename = $usertypes{$type};
17496: }
17497: $chgtext .= &mt('(Affiliation: [_1])',$typename);
17498: }
17499: if (@{$email_rule{$type}} > 0) {
17500: $resulttext .= '<li>'.
17501: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
17502: $usertypes{$type}).
17503: $chgtext.
17504: '</li>';
17505: } else {
17506: $resulttext .= '<li>'.
1.310 raeburn 17507: &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 17508: '</li>'.
1.310 raeburn 17509: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 17510: }
1.43 raeburn 17511: }
17512: }
1.305 raeburn 17513: }
17514: if (ref($changes{'inststatus'}) eq 'ARRAY') {
17515: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
17516: if (@{$save_inststatus{'inststatusguest'}} > 0) {
17517: my $chgtext = '<ul>';
17518: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
17519: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
17520: }
17521: $chgtext .= '</ul>';
17522: $resulttext .= '<li>'.
17523: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
17524: $chgtext.
17525: '</li>';
17526: } else {
17527: $resulttext .= '<li>'.
17528: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
17529: '</li>';
17530: }
1.43 raeburn 17531: }
17532: }
1.224 raeburn 17533: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
17534: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
17535: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
17536: foreach my $type (@{$changes{'selfcreate'}}) {
17537: my $typename = $type;
1.303 raeburn 17538: if (keys(%usertypes) > 0) {
17539: if ($usertypes{$type} ne '') {
17540: $typename = $usertypes{$type};
1.224 raeburn 17541: }
17542: }
17543: my @modifiable;
17544: $resulttext .= '<li>'.
17545: &mt('Self-creation of account by users with status: [_1]',
17546: '<span class="LC_cusr_emph">'.$typename.'</span>').
17547: ' - '.&mt('modifiable fields (if institutional data blank): ');
17548: foreach my $field (@fields) {
17549: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
17550: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 17551: }
17552: }
1.224 raeburn 17553: if (@modifiable > 0) {
17554: $resulttext .= join(', ',@modifiable);
1.43 raeburn 17555: } else {
1.224 raeburn 17556: $resulttext .= &mt('none');
1.43 raeburn 17557: }
1.224 raeburn 17558: $resulttext .= '</li>';
1.28 raeburn 17559: }
1.224 raeburn 17560: $resulttext .= '</ul></li>';
1.28 raeburn 17561: }
1.27 raeburn 17562: $resulttext .= '</ul>';
1.305 raeburn 17563: my $cachetime = 24*60*60;
17564: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
17565: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17566: if (ref($lastactref) eq 'HASH') {
17567: $lastactref->{'domdefaults'} = 1;
17568: }
1.27 raeburn 17569: } else {
1.224 raeburn 17570: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 17571: }
17572: } else {
17573: $resulttext = '<span class="LC_error">'.
1.23 raeburn 17574: &mt('An error occurred: [_1]',$putresult).'</span>';
17575: }
1.43 raeburn 17576: if ($warningmsg ne '') {
17577: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
17578: }
1.23 raeburn 17579: return $resulttext;
17580: }
17581:
1.165 raeburn 17582: sub process_captcha {
1.369 raeburn 17583: my ($container,$changes,$newsettings,$currsettings) = @_;
17584: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 17585: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
17586: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
17587: $newsettings->{'captcha'} = 'original';
17588: }
1.369 raeburn 17589: my %current;
17590: if (ref($currsettings) eq 'HASH') {
17591: %current = %{$currsettings};
17592: }
17593: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 17594: if ($container eq 'cancreate') {
1.169 raeburn 17595: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
17596: push(@{$changes->{'cancreate'}},'captcha');
17597: } elsif (!defined($changes->{'cancreate'})) {
17598: $changes->{'cancreate'} = ['captcha'];
17599: }
1.368 raeburn 17600: } elsif ($container eq 'passwords') {
17601: $changes->{'reset'} = 1;
1.169 raeburn 17602: } else {
17603: $changes->{'captcha'} = 1;
1.165 raeburn 17604: }
17605: }
1.269 raeburn 17606: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 17607: if ($newsettings->{'captcha'} eq 'recaptcha') {
17608: $newpub = $env{'form.'.$container.'_recaptchapub'};
17609: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 17610: $newpub =~ s/[^\w\-]//g;
17611: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 17612: $newsettings->{'recaptchakeys'} = {
17613: public => $newpub,
17614: private => $newpriv,
17615: };
1.269 raeburn 17616: $newversion = $env{'form.'.$container.'_recaptchaversion'};
17617: $newversion =~ s/\D//g;
17618: if ($newversion ne '2') {
17619: $newversion = 1;
17620: }
17621: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 17622: }
1.369 raeburn 17623: if (ref($current{'recaptchakeys'}) eq 'HASH') {
17624: $currpub = $current{'recaptchakeys'}{'public'};
17625: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 17626: unless ($newsettings->{'captcha'} eq 'recaptcha') {
17627: $newsettings->{'recaptchakeys'} = {
17628: public => '',
17629: private => '',
17630: }
17631: }
1.165 raeburn 17632: }
1.369 raeburn 17633: if ($current{'captcha'} eq 'recaptcha') {
17634: $currversion = $current{'recaptchaversion'};
1.269 raeburn 17635: if ($currversion ne '2') {
17636: $currversion = 1;
17637: }
17638: }
17639: if ($currversion ne $newversion) {
17640: if ($container eq 'cancreate') {
17641: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
17642: push(@{$changes->{'cancreate'}},'recaptchaversion');
17643: } elsif (!defined($changes->{'cancreate'})) {
17644: $changes->{'cancreate'} = ['recaptchaversion'];
17645: }
1.368 raeburn 17646: } elsif ($container eq 'passwords') {
17647: $changes->{'reset'} = 1;
1.269 raeburn 17648: } else {
17649: $changes->{'recaptchaversion'} = 1;
17650: }
17651: }
1.165 raeburn 17652: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 17653: if ($container eq 'cancreate') {
17654: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
17655: push(@{$changes->{'cancreate'}},'recaptchakeys');
17656: } elsif (!defined($changes->{'cancreate'})) {
17657: $changes->{'cancreate'} = ['recaptchakeys'];
17658: }
1.368 raeburn 17659: } elsif ($container eq 'passwords') {
17660: $changes->{'reset'} = 1;
1.169 raeburn 17661: } else {
1.210 raeburn 17662: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 17663: }
17664: }
17665: return;
17666: }
17667:
1.33 raeburn 17668: sub modify_usermodification {
17669: my ($dom,%domconfig) = @_;
1.224 raeburn 17670: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 17671: if (ref($domconfig{'usermodification'}) eq 'HASH') {
17672: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 17673: if ($key eq 'selfcreate') {
17674: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
17675: } else {
17676: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
17677: }
1.33 raeburn 17678: }
17679: }
1.224 raeburn 17680: my @contexts = ('author','course');
1.33 raeburn 17681: my %context_title = (
17682: author => 'In author context',
17683: course => 'In course context',
17684: );
17685: my @fields = ('lastname','firstname','middlename','generation',
17686: 'permanentemail','id');
17687: my %roles = (
17688: author => ['ca','aa'],
17689: course => ['st','ep','ta','in','cr'],
17690: );
17691: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
17692: foreach my $context (@contexts) {
17693: foreach my $role (@{$roles{$context}}) {
17694: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
17695: foreach my $item (@fields) {
17696: if (grep(/^\Q$item\E$/,@modifiable)) {
17697: $modifyhash{$context}{$role}{$item} = 1;
17698: } else {
17699: $modifyhash{$context}{$role}{$item} = 0;
17700: }
17701: }
17702: }
17703: if (ref($curr_usermodification{$context}) eq 'HASH') {
17704: foreach my $role (@{$roles{$context}}) {
17705: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
17706: foreach my $field (@fields) {
17707: if ($modifyhash{$context}{$role}{$field} ne
17708: $curr_usermodification{$context}{$role}{$field}) {
17709: push(@{$changes{$context}},$role);
17710: last;
17711: }
17712: }
17713: }
17714: }
17715: } else {
17716: foreach my $context (@contexts) {
17717: foreach my $role (@{$roles{$context}}) {
17718: push(@{$changes{$context}},$role);
17719: }
17720: }
17721: }
17722: }
17723: my %usermodification_hash = (
17724: usermodification => \%modifyhash,
17725: );
17726: my $putresult = &Apache::lonnet::put_dom('configuration',
17727: \%usermodification_hash,$dom);
17728: if ($putresult eq 'ok') {
17729: if (keys(%changes) > 0) {
17730: $resulttext = &mt('Changes made: ').'<ul>';
17731: foreach my $context (@contexts) {
17732: if (ref($changes{$context}) eq 'ARRAY') {
17733: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
17734: if (ref($changes{$context}) eq 'ARRAY') {
17735: foreach my $role (@{$changes{$context}}) {
17736: my $rolename;
1.224 raeburn 17737: if ($role eq 'cr') {
17738: $rolename = &mt('Custom');
1.33 raeburn 17739: } else {
1.224 raeburn 17740: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 17741: }
17742: my @modifiable;
1.224 raeburn 17743: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 17744: foreach my $field (@fields) {
17745: if ($modifyhash{$context}{$role}{$field}) {
17746: push(@modifiable,$fieldtitles{$field});
17747: }
17748: }
17749: if (@modifiable > 0) {
17750: $resulttext .= join(', ',@modifiable);
17751: } else {
17752: $resulttext .= &mt('none');
17753: }
17754: $resulttext .= '</li>';
17755: }
17756: $resulttext .= '</ul></li>';
17757: }
17758: }
17759: }
17760: $resulttext .= '</ul>';
17761: } else {
17762: $resulttext = &mt('No changes made to user modification settings');
17763: }
17764: } else {
17765: $resulttext = '<span class="LC_error">'.
17766: &mt('An error occurred: [_1]',$putresult).'</span>';
17767: }
17768: return $resulttext;
17769: }
17770:
1.43 raeburn 17771: sub modify_defaults {
1.212 raeburn 17772: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 17773: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 17774: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 17775: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 17776: 'portal_def');
1.325 raeburn 17777: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 17778: foreach my $item (@items) {
17779: $newvalues{$item} = $env{'form.'.$item};
17780: if ($item eq 'auth_def') {
17781: if ($newvalues{$item} ne '') {
17782: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
17783: push(@errors,$item);
17784: }
17785: }
17786: } elsif ($item eq 'lang_def') {
17787: if ($newvalues{$item} ne '') {
17788: if ($newvalues{$item} =~ /^(\w+)/) {
17789: my $langcode = $1;
1.103 raeburn 17790: if ($langcode ne 'x_chef') {
17791: if (code2language($langcode) eq '') {
17792: push(@errors,$item);
17793: }
1.43 raeburn 17794: }
17795: } else {
17796: push(@errors,$item);
17797: }
17798: }
1.54 raeburn 17799: } elsif ($item eq 'timezone_def') {
17800: if ($newvalues{$item} ne '') {
1.62 raeburn 17801: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 17802: push(@errors,$item);
17803: }
17804: }
1.68 raeburn 17805: } elsif ($item eq 'datelocale_def') {
17806: if ($newvalues{$item} ne '') {
17807: my @datelocale_ids = DateTime::Locale->ids();
17808: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
17809: push(@errors,$item);
17810: }
17811: }
1.141 raeburn 17812: } elsif ($item eq 'portal_def') {
17813: if ($newvalues{$item} ne '') {
17814: 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])\/?$/) {
17815: push(@errors,$item);
17816: }
17817: }
1.43 raeburn 17818: }
17819: if (grep(/^\Q$item\E$/,@errors)) {
17820: $newvalues{$item} = $domdefaults{$item};
17821: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
17822: $changes{$item} = 1;
17823: }
1.72 raeburn 17824: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 17825: }
1.354 raeburn 17826: my %staticdefaults = (
17827: 'intauth_cost' => 10,
17828: 'intauth_check' => 0,
17829: 'intauth_switch' => 0,
17830: );
17831: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
17832: if (exists($domdefaults{$item})) {
17833: $newvalues{$item} = $domdefaults{$item};
17834: } else {
17835: $newvalues{$item} = $staticdefaults{$item};
17836: }
17837: }
1.43 raeburn 17838: my %defaults_hash = (
1.72 raeburn 17839: defaults => \%newvalues,
17840: );
1.43 raeburn 17841: my $title = &defaults_titles();
1.236 raeburn 17842:
17843: my $currinststatus;
17844: if (ref($domconfig{'inststatus'}) eq 'HASH') {
17845: $currinststatus = $domconfig{'inststatus'};
17846: } else {
17847: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17848: $currinststatus = {
17849: inststatustypes => $usertypes,
17850: inststatusorder => $types,
17851: inststatusguest => [],
17852: };
17853: }
17854: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
17855: my @allpos;
17856: my %alltypes;
1.305 raeburn 17857: my @inststatusguest;
17858: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
17859: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
17860: unless (grep(/^\Q$type\E$/,@todelete)) {
17861: push(@inststatusguest,$type);
17862: }
17863: }
17864: }
17865: my ($currtitles,$currorder);
1.236 raeburn 17866: if (ref($currinststatus) eq 'HASH') {
17867: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
17868: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
17869: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
17870: if ($currinststatus->{inststatustypes}->{$type} ne '') {
17871: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
17872: }
17873: }
17874: unless (grep(/^\Q$type\E$/,@todelete)) {
17875: my $position = $env{'form.inststatus_pos_'.$type};
17876: $position =~ s/\D+//g;
17877: $allpos[$position] = $type;
17878: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
17879: $alltypes{$type} =~ s/`//g;
17880: }
17881: }
17882: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
17883: $currtitles =~ s/,$//;
17884: }
17885: }
17886: if ($env{'form.addinststatus'}) {
17887: my $newtype = $env{'form.addinststatus'};
17888: $newtype =~ s/\W//g;
17889: unless (exists($alltypes{$newtype})) {
17890: $alltypes{$newtype} = $env{'form.addinststatus_title'};
17891: $alltypes{$newtype} =~ s/`//g;
17892: my $position = $env{'form.addinststatus_pos'};
17893: $position =~ s/\D+//g;
17894: if ($position ne '') {
17895: $allpos[$position] = $newtype;
17896: }
17897: }
17898: }
1.305 raeburn 17899: my @orderedstatus;
1.236 raeburn 17900: foreach my $type (@allpos) {
17901: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
17902: push(@orderedstatus,$type);
17903: }
17904: }
17905: foreach my $type (keys(%alltypes)) {
17906: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
17907: delete($alltypes{$type});
17908: }
17909: }
17910: $defaults_hash{'inststatus'} = {
17911: inststatustypes => \%alltypes,
17912: inststatusorder => \@orderedstatus,
1.305 raeburn 17913: inststatusguest => \@inststatusguest,
1.236 raeburn 17914: };
17915: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
17916: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
17917: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
17918: }
17919: }
17920: if ($currorder ne join(',',@orderedstatus)) {
17921: $changes{'inststatus'}{'inststatusorder'} = 1;
17922: }
17923: my $newtitles;
17924: foreach my $item (@orderedstatus) {
17925: $newtitles .= $alltypes{$item}.',';
17926: }
17927: $newtitles =~ s/,$//;
17928: if ($currtitles ne $newtitles) {
17929: $changes{'inststatus'}{'inststatustypes'} = 1;
17930: }
1.43 raeburn 17931: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
17932: $dom);
17933: if ($putresult eq 'ok') {
17934: if (keys(%changes) > 0) {
17935: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 17936: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 17937: 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";
17938: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 17939: if ($item eq 'inststatus') {
17940: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 17941: if (@orderedstatus) {
1.236 raeburn 17942: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
17943: foreach my $type (@orderedstatus) {
17944: $resulttext .= $alltypes{$type}.', ';
17945: }
17946: $resulttext =~ s/, $//;
17947: $resulttext .= '</li>';
1.305 raeburn 17948: } else {
17949: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 17950: }
17951: }
17952: } else {
17953: my $value = $env{'form.'.$item};
17954: if ($value eq '') {
17955: $value = &mt('none');
17956: } elsif ($item eq 'auth_def') {
17957: my %authnames = &authtype_names();
17958: my %shortauth = (
17959: internal => 'int',
17960: krb4 => 'krb4',
17961: krb5 => 'krb5',
17962: localauth => 'loc',
1.325 raeburn 17963: lti => 'lti',
1.236 raeburn 17964: );
17965: $value = $authnames{$shortauth{$value}};
17966: }
17967: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
17968: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 17969: }
17970: }
17971: $resulttext .= '</ul>';
17972: $mailmsgtext .= "\n";
17973: my $cachetime = 24*60*60;
1.72 raeburn 17974: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 17975: if (ref($lastactref) eq 'HASH') {
17976: $lastactref->{'domdefaults'} = 1;
17977: }
1.68 raeburn 17978: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 17979: my $notify = 1;
17980: if (ref($domconfig{'contacts'}) eq 'HASH') {
17981: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
17982: $notify = 0;
17983: }
17984: }
17985: if ($notify) {
17986: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
17987: "LON-CAPA Domain Settings Change - $dom",
17988: $mailmsgtext);
17989: }
1.54 raeburn 17990: }
1.43 raeburn 17991: } else {
1.54 raeburn 17992: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 17993: }
17994: } else {
17995: $resulttext = '<span class="LC_error">'.
17996: &mt('An error occurred: [_1]',$putresult).'</span>';
17997: }
17998: if (@errors > 0) {
17999: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
18000: foreach my $item (@errors) {
18001: $resulttext .= ' "'.$title->{$item}.'",';
18002: }
18003: $resulttext =~ s/,$//;
18004: }
18005: return $resulttext;
18006: }
18007:
1.46 raeburn 18008: sub modify_scantron {
1.205 raeburn 18009: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 18010: my ($resulttext,%confhash,%changes,$errors);
18011: my $custom = 'custom.tab';
18012: my $default = 'default.tab';
18013: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 18014: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 18015: &config_check($dom,$confname,$servadm);
18016: if ($env{'form.scantronformat.filename'} ne '') {
18017: my $error;
18018: if ($configuserok eq 'ok') {
18019: if ($switchserver) {
1.130 raeburn 18020: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 18021: } else {
18022: if ($author_ok eq 'ok') {
18023: my ($result,$scantronurl) =
18024: &publishlogo($r,'upload','scantronformat',$dom,
18025: $confname,'scantron','','',$custom);
18026: if ($result eq 'ok') {
18027: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 18028: $changes{'scantronformat'} = 1;
1.46 raeburn 18029: } else {
18030: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
18031: }
18032: } else {
18033: $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);
18034: }
18035: }
18036: } else {
18037: $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);
18038: }
18039: if ($error) {
18040: &Apache::lonnet::logthis($error);
18041: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18042: }
18043: }
1.48 raeburn 18044: if (ref($domconfig{'scantron'}) eq 'HASH') {
18045: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
18046: if ($env{'form.scantronformat_del'}) {
18047: $confhash{'scantron'}{'scantronformat'} = '';
18048: $changes{'scantronformat'} = 1;
1.347 raeburn 18049: } else {
18050: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 18051: }
18052: }
18053: }
1.347 raeburn 18054: my @options = ('hdr','pad','rem');
1.346 raeburn 18055: my @fields = &scantroncsv_fields();
18056: my %titles = &scantronconfig_titles();
1.347 raeburn 18057: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 18058: my ($newdat,$currdat,%newcol,%currcol);
18059: if (grep(/^dat$/,@formats)) {
18060: $confhash{'scantron'}{config}{dat} = 1;
18061: $newdat = 1;
18062: } else {
18063: $newdat = 0;
18064: }
18065: if (grep(/^csv$/,@formats)) {
18066: my %bynum;
18067: foreach my $field (@fields) {
18068: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
18069: my $posscol = $1;
18070: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 18071: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 18072: $bynum{$posscol} = $field;
18073: $newcol{$field} = $posscol;
18074: }
18075: }
18076: }
1.347 raeburn 18077: if (keys(%newcol)) {
18078: foreach my $option (@options) {
18079: if ($env{'form.scantroncsv_'.$option}) {
18080: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
18081: }
18082: }
18083: }
1.346 raeburn 18084: }
18085: $currdat = 1;
18086: if (ref($domconfig{'scantron'}) eq 'HASH') {
18087: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 18088: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 18089: $currdat = 0;
18090: }
18091: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 18092: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
18093: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
18094: }
1.346 raeburn 18095: }
18096: }
18097: }
18098: if ($currdat != $newdat) {
18099: $changes{'config'} = 1;
18100: } else {
18101: foreach my $field (@fields) {
18102: if ($currcol{$field} ne '') {
18103: if ($currcol{$field} ne $newcol{$field}) {
18104: $changes{'config'} = 1;
18105: last;
1.347 raeburn 18106: }
1.346 raeburn 18107: } elsif ($newcol{$field} ne '') {
18108: $changes{'config'} = 1;
18109: last;
18110: }
18111: }
18112: }
1.46 raeburn 18113: if (keys(%confhash) > 0) {
18114: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
18115: $dom);
18116: if ($putresult eq 'ok') {
18117: if (keys(%changes) > 0) {
1.48 raeburn 18118: if (ref($confhash{'scantron'}) eq 'HASH') {
18119: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 18120: if ($changes{'scantronformat'}) {
18121: if ($confhash{'scantron'}{'scantronformat'} eq '') {
18122: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
18123: } else {
18124: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
18125: }
18126: }
1.347 raeburn 18127: if ($changes{'config'}) {
1.346 raeburn 18128: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
18129: if ($confhash{'scantron'}{'config'}{'dat'}) {
18130: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
18131: }
18132: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 18133: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
18134: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
18135: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
18136: foreach my $field (@fields) {
18137: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
18138: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
18139: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
18140: }
18141: }
18142: $resulttext .= '</ul></li>';
18143: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
18144: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
18145: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
18146: foreach my $option (@options) {
18147: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
18148: $resulttext .= '<li>'.$titles{$option}.'</li>';
18149: }
18150: }
18151: $resulttext .= '</ul></li>';
18152: }
1.346 raeburn 18153: }
18154: }
18155: }
18156: }
18157: } else {
18158: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
18159: }
1.46 raeburn 18160: }
1.48 raeburn 18161: $resulttext .= '</ul>';
18162: } else {
1.130 raeburn 18163: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 18164: }
18165: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 18166: if (ref($lastactref) eq 'HASH') {
18167: $lastactref->{'domainconfig'} = 1;
18168: }
1.46 raeburn 18169: } else {
1.346 raeburn 18170: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 18171: }
18172: } else {
18173: $resulttext = '<span class="LC_error">'.
18174: &mt('An error occurred: [_1]',$putresult).'</span>';
18175: }
18176: } else {
1.130 raeburn 18177: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 18178: }
18179: if ($errors) {
1.353 raeburn 18180: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18181: $errors.'</ul></p>';
1.46 raeburn 18182: }
18183: return $resulttext;
18184: }
18185:
1.48 raeburn 18186: sub modify_coursecategories {
1.239 raeburn 18187: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 18188: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
18189: $cathash);
1.48 raeburn 18190: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 18191: my @catitems = ('unauth','auth');
18192: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 18193: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 18194: $cathash = $domconfig{'coursecategories'}{'cats'};
18195: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
18196: $changes{'togglecats'} = 1;
18197: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
18198: }
18199: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
18200: $changes{'categorize'} = 1;
18201: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
18202: }
1.120 raeburn 18203: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
18204: $changes{'togglecatscomm'} = 1;
18205: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
18206: }
18207: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
18208: $changes{'categorizecomm'} = 1;
18209: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 18210:
18211: }
18212: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
18213: $changes{'togglecatsplace'} = 1;
18214: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
18215: }
18216: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
18217: $changes{'categorizeplace'} = 1;
18218: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 18219: }
1.238 raeburn 18220: foreach my $item (@catitems) {
18221: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
18222: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
18223: $changes{$item} = 1;
18224: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
18225: }
18226: }
18227: }
1.57 raeburn 18228: } else {
18229: $changes{'togglecats'} = 1;
18230: $changes{'categorize'} = 1;
1.124 raeburn 18231: $changes{'togglecatscomm'} = 1;
18232: $changes{'categorizecomm'} = 1;
1.272 raeburn 18233: $changes{'togglecatsplace'} = 1;
18234: $changes{'categorizeplace'} = 1;
1.87 raeburn 18235: $domconfig{'coursecategories'} = {
18236: togglecats => $env{'form.togglecats'},
18237: categorize => $env{'form.categorize'},
1.124 raeburn 18238: togglecatscomm => $env{'form.togglecatscomm'},
18239: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 18240: togglecatsplace => $env{'form.togglecatsplace'},
18241: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 18242: };
1.238 raeburn 18243: foreach my $item (@catitems) {
18244: if ($env{'form.coursecat_'.$item} ne 'std') {
18245: $changes{$item} = 1;
18246: }
18247: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
18248: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
18249: }
18250: }
1.57 raeburn 18251: }
18252: if (ref($cathash) eq 'HASH') {
18253: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 18254: push (@deletecategory,'instcode::0');
18255: }
1.120 raeburn 18256: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
18257: push(@deletecategory,'communities::0');
18258: }
1.272 raeburn 18259: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
18260: push(@deletecategory,'placement::0');
18261: }
1.48 raeburn 18262: }
1.57 raeburn 18263: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
18264: if (ref($cathash) eq 'HASH') {
1.48 raeburn 18265: if (@deletecategory > 0) {
18266: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 18267: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 18268: foreach my $item (@deletecategory) {
1.57 raeburn 18269: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
18270: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 18271: $deletions{$item} = 1;
1.57 raeburn 18272: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 18273: }
18274: }
18275: }
1.57 raeburn 18276: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 18277: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 18278: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 18279: $reorderings{$item} = 1;
1.57 raeburn 18280: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 18281: }
18282: if ($env{'form.addcategory_name_'.$item} ne '') {
18283: my $newcat = $env{'form.addcategory_name_'.$item};
18284: my $newdepth = $depth+1;
18285: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 18286: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 18287: $adds{$newitem} = 1;
18288: }
18289: if ($env{'form.subcat_'.$item} ne '') {
18290: my $newcat = $env{'form.subcat_'.$item};
18291: my $newdepth = $depth+1;
18292: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 18293: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 18294: $adds{$newitem} = 1;
18295: }
18296: }
18297: }
18298: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 18299: if (ref($cathash) eq 'HASH') {
1.48 raeburn 18300: my $newitem = 'instcode::0';
1.57 raeburn 18301: if ($cathash->{$newitem} eq '') {
18302: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 18303: $adds{$newitem} = 1;
18304: }
18305: } else {
18306: my $newitem = 'instcode::0';
1.57 raeburn 18307: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 18308: $adds{$newitem} = 1;
18309: }
18310: }
1.120 raeburn 18311: if ($env{'form.communities'} eq '1') {
18312: if (ref($cathash) eq 'HASH') {
18313: my $newitem = 'communities::0';
18314: if ($cathash->{$newitem} eq '') {
18315: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
18316: $adds{$newitem} = 1;
18317: }
18318: } else {
18319: my $newitem = 'communities::0';
18320: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
18321: $adds{$newitem} = 1;
18322: }
18323: }
1.272 raeburn 18324: if ($env{'form.placement'} eq '1') {
18325: if (ref($cathash) eq 'HASH') {
18326: my $newitem = 'placement::0';
18327: if ($cathash->{$newitem} eq '') {
18328: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
18329: $adds{$newitem} = 1;
18330: }
18331: } else {
18332: my $newitem = 'placement::0';
18333: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
18334: $adds{$newitem} = 1;
18335: }
18336: }
1.48 raeburn 18337: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 18338: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 18339: ($env{'form.addcategory_name'} ne 'communities') &&
18340: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 18341: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
18342: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
18343: $adds{$newitem} = 1;
18344: }
1.48 raeburn 18345: }
1.57 raeburn 18346: my $putresult;
1.48 raeburn 18347: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
18348: if (keys(%deletions) > 0) {
18349: foreach my $key (keys(%deletions)) {
18350: if ($predelallitems{$key} ne '') {
18351: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
18352: }
18353: }
18354: }
18355: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 18356: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 18357: if (ref($chkcats[0]) eq 'ARRAY') {
18358: my $depth = 0;
18359: my $chg = 0;
18360: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
18361: my $name = $chkcats[0][$i];
18362: my $item;
18363: if ($name eq '') {
18364: $chg ++;
18365: } else {
18366: $item = &escape($name).'::0';
18367: if ($chg) {
1.57 raeburn 18368: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 18369: }
18370: $depth ++;
1.57 raeburn 18371: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 18372: $depth --;
18373: }
18374: }
18375: }
1.57 raeburn 18376: }
18377: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
18378: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 18379: if ($putresult eq 'ok') {
1.57 raeburn 18380: my %title = (
1.120 raeburn 18381: togglecats => 'Show/Hide a course in catalog',
18382: categorize => 'Assign a category to a course',
18383: togglecatscomm => 'Show/Hide a community in catalog',
18384: categorizecomm => 'Assign a category to a community',
1.57 raeburn 18385: );
18386: my %level = (
1.120 raeburn 18387: dom => 'set in Domain ("Modify Course/Community")',
18388: crs => 'set in Course ("Course Configuration")',
18389: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 18390: none => 'No catalog',
18391: std => 'Standard catalog',
18392: domonly => 'Domain-only catalog',
18393: codesrch => 'Code search form',
1.57 raeburn 18394: );
1.48 raeburn 18395: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 18396: if ($changes{'togglecats'}) {
18397: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
18398: }
18399: if ($changes{'categorize'}) {
18400: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 18401: }
1.120 raeburn 18402: if ($changes{'togglecatscomm'}) {
18403: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
18404: }
18405: if ($changes{'categorizecomm'}) {
18406: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
18407: }
1.238 raeburn 18408: if ($changes{'unauth'}) {
18409: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
18410: }
18411: if ($changes{'auth'}) {
18412: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
18413: }
1.57 raeburn 18414: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
18415: my $cathash;
18416: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
18417: $cathash = $domconfig{'coursecategories'}{'cats'};
18418: } else {
18419: $cathash = {};
18420: }
18421: my (@cats,@trails,%allitems);
18422: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
18423: if (keys(%deletions) > 0) {
18424: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
18425: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
18426: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
18427: }
18428: $resulttext .= '</ul></li>';
18429: }
18430: if (keys(%reorderings) > 0) {
18431: my %sort_by_trail;
18432: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
18433: foreach my $key (keys(%reorderings)) {
18434: if ($allitems{$key} ne '') {
18435: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
18436: }
1.48 raeburn 18437: }
1.57 raeburn 18438: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
18439: $resulttext .= '<li>'.$trails[$trail].'</li>';
18440: }
18441: $resulttext .= '</ul></li>';
1.48 raeburn 18442: }
1.57 raeburn 18443: if (keys(%adds) > 0) {
18444: my %sort_by_trail;
18445: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
18446: foreach my $key (keys(%adds)) {
18447: if ($allitems{$key} ne '') {
18448: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
18449: }
18450: }
18451: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
18452: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 18453: }
1.57 raeburn 18454: $resulttext .= '</ul></li>';
1.48 raeburn 18455: }
1.364 raeburn 18456: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
18457: if (ref($lastactref) eq 'HASH') {
18458: $lastactref->{'cats'} = 1;
18459: }
1.48 raeburn 18460: }
18461: $resulttext .= '</ul>';
1.239 raeburn 18462: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 18463: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
18464: if ($changes{'auth'}) {
18465: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
18466: }
18467: if ($changes{'unauth'}) {
18468: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
18469: }
18470: my $cachetime = 24*60*60;
18471: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 18472: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 18473: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 18474: }
18475: }
1.48 raeburn 18476: } else {
18477: $resulttext = '<span class="LC_error">'.
1.57 raeburn 18478: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 18479: }
18480: } else {
1.120 raeburn 18481: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 18482: }
18483: return $resulttext;
18484: }
18485:
1.69 raeburn 18486: sub modify_serverstatuses {
18487: my ($dom,%domconfig) = @_;
18488: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
18489: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
18490: %currserverstatus = %{$domconfig{'serverstatuses'}};
18491: }
18492: my @pages = &serverstatus_pages();
18493: foreach my $type (@pages) {
18494: $newserverstatus{$type}{'namedusers'} = '';
18495: $newserverstatus{$type}{'machines'} = '';
18496: if (defined($env{'form.'.$type.'_namedusers'})) {
18497: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
18498: my @okusers;
18499: foreach my $user (@users) {
18500: my ($uname,$udom) = split(/:/,$user);
18501: if (($udom =~ /^$match_domain$/) &&
18502: (&Apache::lonnet::domain($udom)) &&
18503: ($uname =~ /^$match_username$/)) {
18504: if (!grep(/^\Q$user\E/,@okusers)) {
18505: push(@okusers,$user);
18506: }
18507: }
18508: }
18509: if (@okusers > 0) {
18510: @okusers = sort(@okusers);
18511: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
18512: }
18513: }
18514: if (defined($env{'form.'.$type.'_machines'})) {
18515: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
18516: my @okmachines;
18517: foreach my $ip (@machines) {
18518: my @parts = split(/\./,$ip);
18519: next if (@parts < 4);
18520: my $badip = 0;
18521: for (my $i=0; $i<4; $i++) {
18522: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
18523: $badip = 1;
18524: last;
18525: }
18526: }
18527: if (!$badip) {
18528: push(@okmachines,$ip);
18529: }
18530: }
18531: @okmachines = sort(@okmachines);
18532: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
18533: }
18534: }
18535: my %serverstatushash = (
18536: serverstatuses => \%newserverstatus,
18537: );
18538: foreach my $type (@pages) {
1.83 raeburn 18539: foreach my $setting ('namedusers','machines') {
1.84 raeburn 18540: my (@current,@new);
1.83 raeburn 18541: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 18542: if ($currserverstatus{$type}{$setting} ne '') {
18543: @current = split(/,/,$currserverstatus{$type}{$setting});
18544: }
18545: }
18546: if ($newserverstatus{$type}{$setting} ne '') {
18547: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 18548: }
18549: if (@current > 0) {
18550: if (@new > 0) {
18551: foreach my $item (@current) {
18552: if (!grep(/^\Q$item\E$/,@new)) {
18553: $changes{$type}{$setting} = 1;
1.82 raeburn 18554: last;
18555: }
18556: }
1.84 raeburn 18557: foreach my $item (@new) {
18558: if (!grep(/^\Q$item\E$/,@current)) {
18559: $changes{$type}{$setting} = 1;
18560: last;
1.82 raeburn 18561: }
18562: }
18563: } else {
1.83 raeburn 18564: $changes{$type}{$setting} = 1;
1.69 raeburn 18565: }
1.83 raeburn 18566: } elsif (@new > 0) {
18567: $changes{$type}{$setting} = 1;
1.69 raeburn 18568: }
18569: }
18570: }
18571: if (keys(%changes) > 0) {
1.81 raeburn 18572: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 18573: my $putresult = &Apache::lonnet::put_dom('configuration',
18574: \%serverstatushash,$dom);
18575: if ($putresult eq 'ok') {
18576: $resulttext .= &mt('Changes made:').'<ul>';
18577: foreach my $type (@pages) {
1.84 raeburn 18578: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 18579: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 18580: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 18581: if ($newserverstatus{$type}{'namedusers'} eq '') {
18582: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
18583: } else {
18584: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
18585: }
1.84 raeburn 18586: }
18587: if ($changes{$type}{'machines'}) {
1.69 raeburn 18588: if ($newserverstatus{$type}{'machines'} eq '') {
18589: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
18590: } else {
18591: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
18592: }
18593:
18594: }
18595: $resulttext .= '</ul></li>';
18596: }
18597: }
18598: $resulttext .= '</ul>';
18599: } else {
18600: $resulttext = '<span class="LC_error">'.
18601: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
18602:
18603: }
18604: } else {
18605: $resulttext = &mt('No changes made to access to server status pages');
18606: }
18607: return $resulttext;
18608: }
18609:
1.118 jms 18610: sub modify_helpsettings {
1.285 raeburn 18611: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 18612: my ($resulttext,$errors,%changes,%helphash);
18613: my %defaultchecked = ('submitbugs' => 'on');
18614: my @offon = ('off','on');
1.118 jms 18615: my @toggles = ('submitbugs');
1.285 raeburn 18616: my %current = ('submitbugs' => '',
18617: 'adhoc' => {},
18618: );
1.118 jms 18619: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 18620: %current = %{$domconfig{'helpsettings'}};
18621: }
1.285 raeburn 18622: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 18623: foreach my $item (@toggles) {
18624: if ($defaultchecked{$item} eq 'on') {
18625: if ($current{$item} eq '') {
18626: if ($env{'form.'.$item} eq '0') {
18627: $changes{$item} = 1;
18628: }
18629: } elsif ($current{$item} ne $env{'form.'.$item}) {
18630: $changes{$item} = 1;
18631: }
18632: } elsif ($defaultchecked{$item} eq 'off') {
18633: if ($current{$item} eq '') {
18634: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 18635: $changes{$item} = 1;
18636: }
1.282 raeburn 18637: } elsif ($current{$item} ne $env{'form.'.$item}) {
18638: $changes{$item} = 1;
18639: }
18640: }
18641: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
18642: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
18643: }
18644: }
1.285 raeburn 18645: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 18646: my $confname = $dom.'-domainconfig';
18647: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 18648: my (@allpos,%newsettings,%changedprivs,$newrole);
18649: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 18650: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 18651: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 18652: my %lt = &Apache::lonlocal::texthash(
18653: s => 'system',
18654: d => 'domain',
18655: order => 'Display order',
18656: access => 'Role usage',
1.291 raeburn 18657: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 18658: dh => 'All with domain helpdesk role',
18659: da => 'All with domain helpdesk assistant role',
1.285 raeburn 18660: none => 'None',
18661: status => 'Determined based on institutional status',
18662: inc => 'Include all, but exclude specific personnel',
18663: exc => 'Exclude all, but include specific personnel',
18664: );
18665: for (my $num=0; $num<=$maxnum; $num++) {
18666: my ($prefix,$identifier,$rolename,%curr);
18667: if ($num == $maxnum) {
18668: next unless ($env{'form.newcusthelp'} == $maxnum);
18669: $identifier = 'custhelp'.$num;
18670: $prefix = 'helproles_'.$num;
18671: $rolename = $env{'form.custhelpname'.$num};
18672: $rolename=~s/[^A-Za-z0-9]//gs;
18673: next if ($rolename eq '');
18674: next if (exists($existing{'rolesdef_'.$rolename}));
18675: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
18676: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
18677: $newprivs{'c'},$confname,$dom);
18678: if ($result ne 'ok') {
18679: $errors .= '<li><span class="LC_error">'.
18680: &mt('An error occurred storing the new custom role: [_1]',
18681: $result).'</span></li>';
18682: next;
18683: } else {
18684: $changedprivs{$rolename} = \%newprivs;
18685: $newrole = $rolename;
18686: }
18687: } else {
18688: $prefix = 'helproles_'.$num;
18689: $rolename = $env{'form.'.$prefix};
18690: next if ($rolename eq '');
18691: next unless (exists($existing{'rolesdef_'.$rolename}));
18692: $identifier = 'custhelp'.$num;
18693: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
18694: my %currprivs;
1.289 raeburn 18695: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 18696: split(/\_/,$existing{'rolesdef_'.$rolename});
18697: foreach my $level ('c','d','s') {
18698: if ($newprivs{$level} ne $currprivs{$level}) {
18699: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
18700: $newprivs{'c'},$confname,$dom);
18701: if ($result ne 'ok') {
18702: $errors .= '<li><span class="LC_error">'.
18703: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
18704: $rolename,$result).'</span></li>';
18705: } else {
18706: $changedprivs{$rolename} = \%newprivs;
18707: }
18708: last;
18709: }
18710: }
18711: if (ref($current{'adhoc'}) eq 'HASH') {
18712: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
18713: %curr = %{$current{'adhoc'}{$rolename}};
18714: }
18715: }
18716: }
18717: my $newpos = $env{'form.'.$prefix.'_pos'};
18718: $newpos =~ s/\D+//g;
18719: $allpos[$newpos] = $rolename;
18720: my $newdesc = $env{'form.'.$prefix.'_desc'};
18721: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
18722: if ($curr{'desc'}) {
18723: if ($curr{'desc'} ne $newdesc) {
18724: $changes{'customrole'}{$rolename}{'desc'} = 1;
18725: $newsettings{$rolename}{'desc'} = $newdesc;
18726: }
18727: } elsif ($newdesc ne '') {
18728: $changes{'customrole'}{$rolename}{'desc'} = 1;
18729: $newsettings{$rolename}{'desc'} = $newdesc;
18730: }
18731: my $access = $env{'form.'.$prefix.'_access'};
18732: if (grep(/^\Q$access\E$/,@accesstypes)) {
18733: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
18734: if ($access eq 'status') {
18735: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
18736: if (scalar(@statuses) == 0) {
1.289 raeburn 18737: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 18738: } else {
18739: my (@shownstatus,$numtypes);
18740: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
18741: if (ref($types) eq 'ARRAY') {
18742: $numtypes = scalar(@{$types});
18743: foreach my $type (sort(@statuses)) {
18744: if ($type eq 'default') {
18745: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
18746: } elsif (grep(/^\Q$type\E$/,@{$types})) {
18747: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
18748: push(@shownstatus,$usertypes->{$type});
18749: }
18750: }
18751: }
18752: if (grep(/^default$/,@statuses)) {
18753: push(@shownstatus,$othertitle);
18754: }
18755: if (scalar(@shownstatus) == 1+$numtypes) {
18756: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
18757: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
18758: } else {
18759: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
18760: if (ref($curr{'status'}) eq 'ARRAY') {
18761: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
18762: if (@diffs) {
18763: $changes{'customrole'}{$rolename}{$access} = 1;
18764: }
18765: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
18766: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 18767: }
1.166 raeburn 18768: }
18769: }
1.285 raeburn 18770: } elsif (($access eq 'inc') || ($access eq 'exc')) {
18771: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
18772: my @newspecstaff;
18773: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
18774: foreach my $person (sort(@personnel)) {
18775: if ($domhelpdesk{$person}) {
18776: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
18777: }
18778: }
18779: if (ref($curr{$access}) eq 'ARRAY') {
18780: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
18781: if (@diffs) {
18782: $changes{'customrole'}{$rolename}{$access} = 1;
18783: }
18784: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
18785: $changes{'customrole'}{$rolename}{$access} = 1;
18786: }
18787: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
18788: my ($uname,$udom) = split(/:/,$person);
18789: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
18790: }
18791: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 18792: }
1.285 raeburn 18793: } else {
18794: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
18795: }
18796: unless ($curr{'access'} eq $access) {
18797: $changes{'customrole'}{$rolename}{'access'} = 1;
18798: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 18799: }
18800: }
1.285 raeburn 18801: if (@allpos > 0) {
18802: my $idx = 0;
18803: foreach my $rolename (@allpos) {
18804: if ($rolename ne '') {
18805: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
18806: if (ref($current{'adhoc'}) eq 'HASH') {
18807: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
18808: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
18809: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 18810: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 18811: }
18812: }
1.282 raeburn 18813: }
1.285 raeburn 18814: $idx ++;
1.166 raeburn 18815: }
18816: }
1.118 jms 18817: }
1.123 jms 18818: my $putresult;
18819: if (keys(%changes) > 0) {
1.166 raeburn 18820: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 18821: if ($putresult eq 'ok') {
1.285 raeburn 18822: if (ref($helphash{'helpsettings'}) eq 'HASH') {
18823: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
18824: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
18825: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
18826: }
18827: }
18828: my $cachetime = 24*60*60;
18829: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18830: if (ref($lastactref) eq 'HASH') {
18831: $lastactref->{'domdefaults'} = 1;
18832: }
18833: } else {
18834: $errors .= '<li><span class="LC_error">'.
18835: &mt('An error occurred storing the settings: [_1]',
18836: $putresult).'</span></li>';
18837: }
18838: }
18839: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
18840: $resulttext = &mt('Changes made:').'<ul>';
18841: my (%shownprivs,@levelorder);
18842: @levelorder = ('c','d','s');
18843: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 18844: foreach my $item (sort(keys(%changes))) {
18845: if ($item eq 'submitbugs') {
18846: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
18847: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
18848: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 18849: } elsif ($item eq 'customrole') {
18850: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 18851: my @keyorder = ('order','desc','access','status','exc','inc');
18852: my %keytext = &Apache::lonlocal::texthash(
18853: order => 'Order',
18854: desc => 'Role description',
18855: access => 'Role usage',
1.300 droeschl 18856: status => 'Allowed institutional types',
1.285 raeburn 18857: exc => 'Allowed personnel',
18858: inc => 'Disallowed personnel',
18859: );
1.282 raeburn 18860: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 18861: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
18862: if ($role eq $newrole) {
18863: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
18864: $role).'<ul>';
18865: } else {
18866: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
18867: $role).'<ul>';
18868: }
18869: foreach my $key (@keyorder) {
18870: if ($changes{'customrole'}{$role}{$key}) {
18871: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
18872: $keytext{$key},$newsettings{$role}{$key}).
18873: '</li>';
18874: }
18875: }
18876: if (ref($changedprivs{$role}) eq 'HASH') {
18877: $shownprivs{$role} = 1;
18878: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
18879: foreach my $level (@levelorder) {
18880: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
18881: next if ($item eq '');
18882: my ($priv) = split(/\&/,$item,2);
18883: if (&Apache::lonnet::plaintext($priv)) {
18884: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
18885: unless ($level eq 'c') {
18886: $resulttext .= ' ('.$lt{$level}.')';
18887: }
18888: $resulttext .= '</li>';
18889: }
18890: }
18891: }
18892: $resulttext .= '</ul>';
18893: }
18894: $resulttext .= '</ul></li>';
18895: }
18896: }
18897: }
18898: }
18899: }
18900: }
18901: if (keys(%changedprivs)) {
18902: foreach my $role (sort(keys(%changedprivs))) {
18903: unless ($shownprivs{$role}) {
18904: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
18905: $role).'<ul>'.
18906: '<li>'.&mt('Privileges set to :').'<ul>';
18907: foreach my $level (@levelorder) {
18908: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
18909: next if ($item eq '');
18910: my ($priv) = split(/\&/,$item,2);
18911: if (&Apache::lonnet::plaintext($priv)) {
18912: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
18913: unless ($level eq 'c') {
18914: $resulttext .= ' ('.$lt{$level}.')';
18915: }
18916: $resulttext .= '</li>';
18917: }
1.282 raeburn 18918: }
18919: }
1.285 raeburn 18920: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 18921: }
18922: }
18923: }
1.285 raeburn 18924: $resulttext .= '</ul>';
18925: } else {
18926: $resulttext = &mt('No changes made to help settings');
1.118 jms 18927: }
18928: if ($errors) {
1.168 raeburn 18929: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 18930: $errors.'</ul>';
1.118 jms 18931: }
18932: return $resulttext;
18933: }
18934:
1.121 raeburn 18935: sub modify_coursedefaults {
1.212 raeburn 18936: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 18937: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 18938: my %defaultchecked = (
18939: 'canuse_pdfforms' => 'off',
18940: 'uselcmath' => 'on',
18941: 'usejsme' => 'on'
18942: );
18943: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 18944: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 18945: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
18946: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
18947: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 18948: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 18949: my %staticdefaults = (
18950: anonsurvey_threshold => 10,
18951: uploadquota => 500,
1.257 raeburn 18952: postsubmit => 60,
1.276 raeburn 18953: mysqltables => 172800,
1.198 raeburn 18954: );
1.314 raeburn 18955: my %texoptions = (
18956: MathJax => 'MathJax',
18957: mimetex => &mt('Convert to Images'),
18958: tth => &mt('TeX to HTML'),
18959: );
1.121 raeburn 18960: $defaultshash{'coursedefaults'} = {};
18961:
18962: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
18963: if ($domconfig{'coursedefaults'} eq '') {
18964: $domconfig{'coursedefaults'} = {};
18965: }
18966: }
18967:
18968: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
18969: foreach my $item (@toggles) {
18970: if ($defaultchecked{$item} eq 'on') {
18971: if (($domconfig{'coursedefaults'}{$item} eq '') &&
18972: ($env{'form.'.$item} eq '0')) {
18973: $changes{$item} = 1;
1.192 raeburn 18974: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 18975: $changes{$item} = 1;
18976: }
18977: } elsif ($defaultchecked{$item} eq 'off') {
18978: if (($domconfig{'coursedefaults'}{$item} eq '') &&
18979: ($env{'form.'.$item} eq '1')) {
18980: $changes{$item} = 1;
18981: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
18982: $changes{$item} = 1;
18983: }
18984: }
18985: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
18986: }
1.198 raeburn 18987: foreach my $item (@numbers) {
18988: my ($currdef,$newdef);
1.208 raeburn 18989: $newdef = $env{'form.'.$item};
1.198 raeburn 18990: if ($item eq 'anonsurvey_threshold') {
18991: $currdef = $domconfig{'coursedefaults'}{$item};
18992: $newdef =~ s/\D//g;
18993: if ($newdef eq '' || $newdef < 1) {
18994: $newdef = 1;
18995: }
18996: $defaultshash{'coursedefaults'}{$item} = $newdef;
18997: } else {
1.276 raeburn 18998: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
18999: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
19000: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 19001: }
19002: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 19003: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 19004: }
19005: if ($currdef ne $newdef) {
19006: if ($item eq 'anonsurvey_threshold') {
19007: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
19008: $changes{$item} = 1;
19009: }
1.276 raeburn 19010: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 19011: my $setting = $1;
1.276 raeburn 19012: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
19013: $changes{$setting} = 1;
1.198 raeburn 19014: }
19015: }
1.139 raeburn 19016: }
19017: }
1.314 raeburn 19018: my $texengine;
19019: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
19020: $texengine = $env{'form.texengine'};
1.349 raeburn 19021: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
19022: if ($currdef eq '') {
19023: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 19024: $changes{'texengine'} = 1;
19025: }
1.349 raeburn 19026: } elsif ($currdef ne $texengine) {
1.314 raeburn 19027: $changes{'texengine'} = 1;
19028: }
19029: }
19030: if ($texengine ne '') {
19031: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
19032: }
1.264 raeburn 19033: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
19034: my @currclonecode;
19035: if (ref($currclone) eq 'HASH') {
19036: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
19037: @currclonecode = @{$currclone->{'instcode'}};
19038: }
19039: }
19040: my $newclone;
1.289 raeburn 19041: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 19042: $newclone = $env{'form.canclone'};
19043: }
19044: if ($newclone eq 'instcode') {
19045: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
19046: my (%codedefaults,@code_order,@clonecode);
19047: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
19048: \@code_order);
19049: foreach my $item (@code_order) {
19050: if (grep(/^\Q$item\E$/,@newcodes)) {
19051: push(@clonecode,$item);
19052: }
19053: }
19054: if (@clonecode) {
19055: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
19056: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
19057: if (@diffs) {
19058: $changes{'canclone'} = 1;
19059: }
19060: } else {
19061: $newclone eq '';
19062: }
19063: } elsif ($newclone ne '') {
1.289 raeburn 19064: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
19065: }
1.264 raeburn 19066: if ($newclone ne $currclone) {
19067: $changes{'canclone'} = 1;
19068: }
1.257 raeburn 19069: my %credits;
19070: foreach my $type (@types) {
19071: unless ($type eq 'community') {
19072: $credits{$type} = $env{'form.'.$type.'_credits'};
19073: $credits{$type} =~ s/[^\d.]+//g;
19074: }
19075: }
19076: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
19077: ($env{'form.coursecredits'} eq '1')) {
19078: $changes{'coursecredits'} = 1;
19079: foreach my $type (keys(%credits)) {
19080: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
19081: }
19082: } else {
1.289 raeburn 19083: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 19084: foreach my $type (@types) {
19085: unless ($type eq 'community') {
1.289 raeburn 19086: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 19087: $changes{'coursecredits'} = 1;
19088: }
19089: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
19090: }
19091: }
19092: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
19093: foreach my $type (@types) {
19094: unless ($type eq 'community') {
19095: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
19096: $changes{'coursecredits'} = 1;
19097: last;
19098: }
19099: }
19100: }
19101: }
19102: }
19103: if ($env{'form.postsubmit'} eq '1') {
19104: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
19105: my %currtimeout;
19106: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19107: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
19108: $changes{'postsubmit'} = 1;
19109: }
19110: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19111: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
19112: }
19113: } else {
19114: $changes{'postsubmit'} = 1;
19115: }
19116: foreach my $type (@types) {
19117: my $timeout = $env{'form.'.$type.'_timeout'};
19118: $timeout =~ s/\D//g;
19119: if ($timeout == $staticdefaults{'postsubmit'}) {
19120: $timeout = '';
19121: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
19122: $timeout = '0';
19123: }
19124: unless ($timeout eq '') {
19125: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
19126: }
19127: if (exists($currtimeout{$type})) {
19128: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 19129: $changes{'postsubmit'} = 1;
1.257 raeburn 19130: }
19131: } elsif ($timeout ne '') {
19132: $changes{'postsubmit'} = 1;
19133: }
19134: }
19135: } else {
19136: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
19137: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19138: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
19139: $changes{'postsubmit'} = 1;
19140: }
19141: } else {
19142: $changes{'postsubmit'} = 1;
19143: }
1.192 raeburn 19144: }
1.121 raeburn 19145: }
19146: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
19147: $dom);
19148: if ($putresult eq 'ok') {
19149: if (keys(%changes) > 0) {
1.213 raeburn 19150: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 19151: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 19152: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314 raeburn 19153: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
19154: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257 raeburn 19155: if ($changes{$item}) {
19156: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
19157: }
1.289 raeburn 19158: }
1.192 raeburn 19159: if ($changes{'coursecredits'}) {
19160: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 19161: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
19162: $domdefaults{$type.'credits'} =
19163: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
19164: }
19165: }
19166: }
19167: if ($changes{'postsubmit'}) {
19168: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19169: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
19170: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19171: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
19172: $domdefaults{$type.'postsubtimeout'} =
19173: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
19174: }
19175: }
1.192 raeburn 19176: }
19177: }
1.198 raeburn 19178: if ($changes{'uploadquota'}) {
19179: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
19180: foreach my $type (@types) {
19181: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
19182: }
19183: }
19184: }
1.264 raeburn 19185: if ($changes{'canclone'}) {
19186: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
19187: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
19188: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
19189: if (@clonecodes) {
19190: $domdefaults{'canclone'} = join('+',@clonecodes);
19191: }
19192: }
19193: } else {
19194: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
19195: }
19196: }
1.121 raeburn 19197: my $cachetime = 24*60*60;
19198: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 19199: if (ref($lastactref) eq 'HASH') {
19200: $lastactref->{'domdefaults'} = 1;
19201: }
1.121 raeburn 19202: }
19203: $resulttext = &mt('Changes made:').'<ul>';
19204: foreach my $item (sort(keys(%changes))) {
19205: if ($item eq 'canuse_pdfforms') {
19206: if ($env{'form.'.$item} eq '1') {
19207: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
19208: } else {
19209: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
19210: }
1.257 raeburn 19211: } elsif ($item eq 'uselcmath') {
19212: if ($env{'form.'.$item} eq '1') {
19213: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
19214: } else {
19215: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
19216: }
19217: } elsif ($item eq 'usejsme') {
19218: if ($env{'form.'.$item} eq '1') {
19219: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
19220: } else {
1.289 raeburn 19221: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 19222: }
1.314 raeburn 19223: } elsif ($item eq 'texengine') {
19224: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
19225: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
19226: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
19227: }
1.139 raeburn 19228: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 19229: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 19230: } elsif ($item eq 'uploadquota') {
19231: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
19232: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
19233: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
19234: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 19235: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 19236: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 19237: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
19238: '</ul>'.
19239: '</li>';
19240: } else {
19241: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
19242: }
1.276 raeburn 19243: } elsif ($item eq 'mysqltables') {
19244: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
19245: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
19246: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
19247: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
19248: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
19249: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
19250: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
19251: '</ul>'.
19252: '</li>';
19253: } else {
19254: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
19255: }
1.257 raeburn 19256: } elsif ($item eq 'postsubmit') {
19257: if ($domdefaults{'postsubmit'} eq 'off') {
19258: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
19259: } else {
19260: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 19261: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 19262: $resulttext .= &mt('durations:').'<ul>';
19263: foreach my $type (@types) {
19264: $resulttext .= '<li>';
19265: my $timeout;
19266: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19267: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
19268: }
19269: my $display;
19270: if ($timeout eq '0') {
19271: $display = &mt('unlimited');
19272: } elsif ($timeout eq '') {
19273: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
19274: } else {
19275: $display = &mt('[quant,_1,second]',$timeout);
19276: }
19277: if ($type eq 'community') {
19278: $resulttext .= &mt('Communities');
19279: } elsif ($type eq 'official') {
19280: $resulttext .= &mt('Official courses');
19281: } elsif ($type eq 'unofficial') {
19282: $resulttext .= &mt('Unofficial courses');
19283: } elsif ($type eq 'textbook') {
19284: $resulttext .= &mt('Textbook courses');
1.271 raeburn 19285: } elsif ($type eq 'placement') {
19286: $resulttext .= &mt('Placement tests');
1.257 raeburn 19287: }
19288: $resulttext .= ' -- '.$display.'</li>';
19289: }
19290: $resulttext .= '</ul>';
19291: }
1.289 raeburn 19292: $resulttext .= '</li>';
1.257 raeburn 19293: }
1.192 raeburn 19294: } elsif ($item eq 'coursecredits') {
19295: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
19296: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 19297: ($domdefaults{'unofficialcredits'} eq '') &&
19298: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 19299: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
19300: } else {
19301: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
19302: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
19303: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 19304: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 19305: '</ul>'.
19306: '</li>';
19307: }
19308: } else {
19309: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
19310: }
1.264 raeburn 19311: } elsif ($item eq 'canclone') {
19312: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
19313: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
19314: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
19315: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
19316: }
19317: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
19318: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
19319: } else {
1.289 raeburn 19320: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 19321: }
1.140 raeburn 19322: }
1.121 raeburn 19323: }
19324: $resulttext .= '</ul>';
19325: } else {
19326: $resulttext = &mt('No changes made to course defaults');
19327: }
19328: } else {
19329: $resulttext = '<span class="LC_error">'.
19330: &mt('An error occurred: [_1]',$putresult).'</span>';
19331: }
19332: return $resulttext;
19333: }
19334:
1.231 raeburn 19335: sub modify_selfenrollment {
19336: my ($dom,$lastactref,%domconfig) = @_;
19337: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 19338: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 19339: my %titles = &tool_titles();
1.232 raeburn 19340: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
19341: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 19342: $ordered{'default'} = ['types','registered','approval','limit'];
19343:
19344: my (%roles,%shown,%toplevel);
19345: $roles{'0'} = &Apache::lonnet::plaintext('dc');
19346:
19347: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
19348: if ($domconfig{'selfenrollment'} eq '') {
19349: $domconfig{'selfenrollment'} = {};
19350: }
19351: }
19352: %toplevel = (
19353: admin => 'Configuration Rights',
19354: default => 'Default settings',
19355: validation => 'Validation of self-enrollment requests',
19356: );
1.233 raeburn 19357: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 19358:
19359: if (ref($ordered{'admin'}) eq 'ARRAY') {
19360: foreach my $item (@{$ordered{'admin'}}) {
19361: foreach my $type (@types) {
19362: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
19363: $selfenrollhash{'admin'}{$type}{$item} = 1;
19364: } else {
19365: $selfenrollhash{'admin'}{$type}{$item} = 0;
19366: }
19367: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
19368: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
19369: if ($selfenrollhash{'admin'}{$type}{$item} ne
19370: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
19371: push(@{$changes{'admin'}{$type}},$item);
19372: }
19373: } else {
19374: if (!$selfenrollhash{'admin'}{$type}{$item}) {
19375: push(@{$changes{'admin'}{$type}},$item);
19376: }
19377: }
19378: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
19379: push(@{$changes{'admin'}{$type}},$item);
19380: }
19381: }
19382: }
19383: }
19384:
19385: foreach my $item (@{$ordered{'default'}}) {
19386: foreach my $type (@types) {
19387: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
19388: if ($item eq 'types') {
19389: unless (($value eq 'all') || ($value eq 'dom')) {
19390: $value = '';
19391: }
19392: } elsif ($item eq 'registered') {
19393: unless ($value eq '1') {
19394: $value = 0;
19395: }
19396: } elsif ($item eq 'approval') {
19397: unless ($value =~ /^[012]$/) {
19398: $value = 0;
19399: }
19400: } else {
19401: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
19402: $value = 'none';
19403: }
19404: }
19405: $selfenrollhash{'default'}{$type}{$item} = $value;
19406: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
19407: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
19408: if ($selfenrollhash{'default'}{$type}{$item} ne
19409: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
19410: push(@{$changes{'default'}{$type}},$item);
19411: }
19412: } else {
19413: push(@{$changes{'default'}{$type}},$item);
19414: }
19415: } else {
19416: push(@{$changes{'default'}{$type}},$item);
19417: }
19418: if ($item eq 'limit') {
19419: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
19420: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
19421: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
19422: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
19423: }
19424: } else {
19425: $selfenrollhash{'default'}{$type}{'cap'} = '';
19426: }
19427: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
19428: if ($selfenrollhash{'default'}{$type}{'cap'} ne
19429: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
19430: push(@{$changes{'default'}{$type}},'cap');
19431: }
19432: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
19433: push(@{$changes{'default'}{$type}},'cap');
19434: }
19435: }
19436: }
19437: }
19438:
19439: foreach my $item (@{$itemsref}) {
19440: if ($item eq 'fields') {
19441: my @changed;
19442: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
19443: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
19444: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
19445: }
19446: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
19447: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
19448: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
19449: $domconfig{'selfenrollment'}{'validation'}{$item});
19450: } else {
19451: @changed = @{$selfenrollhash{'validation'}{$item}};
19452: }
19453: } else {
19454: @changed = @{$selfenrollhash{'validation'}{$item}};
19455: }
19456: if (@changed) {
19457: if ($selfenrollhash{'validation'}{$item}) {
19458: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
19459: } else {
19460: $changes{'validation'}{$item} = &mt('None');
19461: }
19462: }
19463: } else {
19464: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
19465: if ($item eq 'markup') {
19466: if ($env{'form.selfenroll_validation_'.$item}) {
19467: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
19468: }
19469: }
19470: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
19471: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
19472: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
19473: }
19474: }
19475: }
19476: }
19477:
19478: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
19479: $dom);
19480: if ($putresult eq 'ok') {
19481: if (keys(%changes) > 0) {
19482: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
19483: $resulttext = &mt('Changes made:').'<ul>';
19484: foreach my $key ('admin','default','validation') {
19485: if (ref($changes{$key}) eq 'HASH') {
19486: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
19487: if ($key eq 'validation') {
19488: foreach my $item (@{$itemsref}) {
19489: if (exists($changes{$key}{$item})) {
19490: if ($item eq 'markup') {
19491: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
19492: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
19493: } else {
19494: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
19495: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
19496: }
19497: }
19498: }
19499: } else {
19500: foreach my $type (@types) {
19501: if ($type eq 'community') {
19502: $roles{'1'} = &mt('Community personnel');
19503: } else {
19504: $roles{'1'} = &mt('Course personnel');
19505: }
19506: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 19507: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
19508: if ($key eq 'admin') {
19509: my @mgrdc = ();
19510: if (ref($ordered{$key}) eq 'ARRAY') {
19511: foreach my $item (@{$ordered{'admin'}}) {
19512: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
19513: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
19514: push(@mgrdc,$item);
19515: }
19516: }
19517: }
19518: if (@mgrdc) {
19519: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
19520: } else {
19521: delete($domdefaults{$type.'selfenrolladmdc'});
19522: }
19523: }
19524: } else {
19525: if (ref($ordered{$key}) eq 'ARRAY') {
19526: foreach my $item (@{$ordered{$key}}) {
19527: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
19528: $domdefaults{$type.'selfenroll'.$item} =
19529: $selfenrollhash{$key}{$type}{$item};
19530: }
19531: }
19532: }
19533: }
19534: }
1.231 raeburn 19535: $resulttext .= '<li>'.$titles{$type}.'<ul>';
19536: foreach my $item (@{$ordered{$key}}) {
19537: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
19538: $resulttext .= '<li>';
19539: if ($key eq 'admin') {
19540: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
19541: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
19542: } else {
19543: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
19544: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
19545: }
19546: $resulttext .= '</li>';
19547: }
19548: }
19549: $resulttext .= '</ul></li>';
19550: }
19551: }
19552: $resulttext .= '</ul></li>';
19553: }
19554: }
1.305 raeburn 19555: }
19556: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
19557: my $cachetime = 24*60*60;
19558: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19559: if (ref($lastactref) eq 'HASH') {
19560: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 19561: }
1.231 raeburn 19562: }
19563: $resulttext .= '</ul>';
19564: } else {
19565: $resulttext = &mt('No changes made to self-enrollment settings');
19566: }
19567: } else {
19568: $resulttext = '<span class="LC_error">'.
19569: &mt('An error occurred: [_1]',$putresult).'</span>';
19570: }
19571: return $resulttext;
19572: }
19573:
1.373 raeburn 19574: sub modify_wafproxy {
19575: my ($dom,$action,$lastactref,%domconfig) = @_;
19576: my %servers = &Apache::lonnet::internet_dom_servers($dom);
19577: my (%othercontrol,%canset,%values,%curralias,%currvalue,@warnings,%wafproxy,
19578: %changes,%expirecache);
19579: foreach my $server (sort(keys(%servers))) {
19580: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
19581: if ($serverhome eq $server) {
19582: my $serverdom = &Apache::lonnet::host_domain($server);
19583: if ($serverdom eq $dom) {
19584: $canset{$server} = 1;
19585: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
19586: %{$values{$dom}} = ();
19587: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
19588: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
19589: }
19590: foreach my $item ('ipheader','trusted','exempt') {
19591: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
19592: }
19593: }
19594: }
19595: }
19596: }
19597: my $output;
19598: if (keys(%canset)) {
19599: %{$wafproxy{'alias'}} = ();
19600: foreach my $key (sort(keys(%canset))) {
19601: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
19602: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
19603: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
19604: $changes{'alias'} = 1;
19605: }
19606: if ($wafproxy{'alias'}{$key} eq '') {
19607: if ($curralias{$key}) {
19608: $expirecache{$key} = 1;
19609: }
19610: delete($wafproxy{'alias'}{$key});
19611: }
19612: }
19613: unless (keys(%{$wafproxy{'alias'}})) {
19614: delete($wafproxy{'alias'});
19615: }
19616: # Localization for values in %warn occus in &mt() calls separately.
19617: my %warn = (
19618: trusted => 'trusted IP range(s)',
19619: exempt => 'exempt IP range(s)',
19620: );
19621: foreach my $item ('ipheader','trusted','exempt') {
19622: my $possible = $env{'form.wafproxy_'.$item};
19623: $possible =~ s/^\s+|\s+$//g;
19624: if ($possible ne '') {
19625: if ($item eq 'ipheader') {
19626: $wafproxy{$item} = $possible;
19627: } else {
19628: my (@ok,$count);
19629: $possible =~ s/[\r\n]+/\s/g;
19630: $possible =~ s/\s*-\s*/-/g;
19631: $possible =~ s/\s+/,/g;
19632: $count = 0;
19633: if ($possible) {
19634: foreach my $poss (split(/\,/,$possible)) {
19635: $count ++;
19636: if (&validate_ip_pattern($poss)) {
19637: push(@ok,$poss);
19638: }
19639: }
19640: if (@ok) {
19641: $wafproxy{$item} = join(',',@ok);
19642: }
19643: my $diff = $count - scalar(@ok);
19644: if ($diff) {
19645: push(@warnings,'<li>'.
19646: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
19647: $diff,$warn{$item}).
19648: '</li>');
19649: }
19650: if ($wafproxy{$item} ne $currvalue{$item}) {
19651: $changes{$item} = 1;
19652: }
19653: }
19654: }
19655: } else {
19656: if ($currvalue{$item}) {
19657: $changes{$item} = 1;
19658: }
19659: }
19660: }
19661: }
19662: if (keys(%changes)) {
19663: my %defaultshash = (
19664: wafproxy => \%wafproxy,
19665: );
19666: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
19667: $dom);
19668: if ($putresult eq 'ok') {
19669: my $cachetime = 24*60*60;
19670: my (%domdefaults,$updatedomdefs);
19671: foreach my $item ('ipheader','trusted','exempt') {
19672: if ($changes{$item}) {
19673: unless ($updatedomdefs) {
19674: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
19675: $updatedomdefs = 1;
19676: }
19677: if ($wafproxy{$item}) {
19678: $domdefaults{'waf_'.$item} = $wafproxy{$item};
19679: } elsif (exists($domdefaults{'waf_'.$item})) {
19680: delete($domdefaults{'waf_'.$item});
19681: }
19682: }
19683: }
19684: if ($updatedomdefs) {
19685: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19686: if (ref($lastactref) eq 'HASH') {
19687: $lastactref->{'domdefaults'} = 1;
19688: }
19689: }
19690: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
19691: my %updates = %expirecache;
19692: foreach my $key (keys(%expirecache)) {
19693: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
19694: }
19695: if (ref($wafproxy{'alias'}) eq 'HASH') {
19696: my $cachetime = 24*60*60;
19697: foreach my $key (keys(%{$wafproxy{'alias'}})) {
19698: $updates{$key} = 1;
19699: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
19700: $cachetime);
19701: }
19702: }
19703: if (ref($lastactref) eq 'HASH') {
19704: $lastactref->{'proxyalias'} = \%updates;
19705: }
19706: }
19707: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
19708: foreach my $item ('alias','ipheader','trusted','exempt') {
19709: if ($changes{$item}) {
19710: if ($item eq 'alias') {
19711: my $numaliased = 0;
19712: if (ref($wafproxy{'alias'}) eq 'HASH') {
19713: my $shown;
19714: if (keys(%{$wafproxy{'alias'}})) {
19715: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
19716: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
19717: &Apache::lonnet::hostname($server),
19718: $wafproxy{'alias'}{$server}).'</li>';
19719: $numaliased ++;
19720: }
19721: if ($numaliased) {
19722: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
19723: '<ul>'.$shown.'</ul>').'</li>';
19724: }
19725: }
19726: }
19727: unless ($numaliased) {
19728: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
19729: }
19730: } else {
19731: if ($item eq 'ipheader') {
19732: if ($wafproxy{$item}) {
19733: $output .= '<li>'.&mt('Custom request header set to [_1]',
19734: $wafproxy{$item}).'</li>';
19735: } else {
19736: $output .= '<li>'.&mt('Custom request header deleted').'</li>';
19737: }
19738: } elsif ($item eq 'trusted') {
19739: if ($wafproxy{$item}) {
19740: $output .= '<li>'.&mt('Trusted IP range(s) set to [_1]',
19741: $wafproxy{$item}).'</li>';
19742: } else {
19743: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
19744: }
19745: } elsif ($item eq 'exempt') {
19746: if ($wafproxy{$item}) {
19747: $output .= '<li>'.&mt('Exempt IP range(s) set to [_1]',
19748: $wafproxy{$item}).'</li>';
19749: } else {
19750: $output .= '<li>'.&mt('Exempt IP range(s) deleted').'</li>';
19751: }
19752: }
19753: }
19754: }
19755: }
19756: } else {
19757: $output = '<span class="LC_error">'.
19758: &mt('An error occurred: [_1]',$putresult).'</span>';
19759: }
19760: } elsif (keys(%canset)) {
19761: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
19762: }
19763: if (@warnings) {
19764: $output .= '<br />'.&mt('Warnings:').'<ul>'.
19765: join("\n",@warnings).'</ul>';
19766: }
19767: return $output;
19768: }
19769:
19770: sub validate_ip_pattern {
19771: my ($pattern) = @_;
19772: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
19773: my ($start,$end) = ($1,$2);
19774: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
19775: return 1;
19776: }
19777: } elsif (&Net::CIDR::cidrvalidate($pattern)) {
19778: return 1;
19779: }
19780: return
19781: }
19782:
1.137 raeburn 19783: sub modify_usersessions {
1.212 raeburn 19784: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 19785: my @hostingtypes = ('version','excludedomain','includedomain');
19786: my @offloadtypes = ('primary','default');
19787: my %types = (
19788: remote => \@hostingtypes,
19789: hosted => \@hostingtypes,
19790: spares => \@offloadtypes,
19791: );
19792: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 19793: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 19794: my (%by_ip,%by_location,@intdoms,@instdoms);
19795: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 19796: my @locations = sort(keys(%by_location));
1.137 raeburn 19797: my (%defaultshash,%changes);
19798: foreach my $prefix (@prefixes) {
19799: $defaultshash{'usersessions'}{$prefix} = {};
19800: }
1.212 raeburn 19801: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 19802: my $resulttext;
1.138 raeburn 19803: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 19804: foreach my $prefix (@prefixes) {
1.145 raeburn 19805: next if ($prefix eq 'spares');
19806: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 19807: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
19808: if ($type eq 'version') {
19809: my $value = $env{'form.'.$prefix.'_'.$type};
19810: my $okvalue;
19811: if ($value ne '') {
19812: if (grep(/^\Q$value\E$/,@lcversions)) {
19813: $okvalue = $value;
19814: }
19815: }
19816: if (ref($domconfig{'usersessions'}) eq 'HASH') {
19817: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
19818: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
19819: if ($inuse == 0) {
19820: $changes{$prefix}{$type} = 1;
19821: } else {
19822: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
19823: $changes{$prefix}{$type} = 1;
19824: }
19825: if ($okvalue ne '') {
19826: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
19827: }
19828: }
19829: } else {
19830: if (($inuse == 1) && ($okvalue ne '')) {
19831: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
19832: $changes{$prefix}{$type} = 1;
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: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
19849: my @okvals;
19850: foreach my $val (@vals) {
1.138 raeburn 19851: if ($val =~ /:/) {
19852: my @items = split(/:/,$val);
19853: foreach my $item (@items) {
19854: if (ref($by_location{$item}) eq 'ARRAY') {
19855: push(@okvals,$item);
19856: }
19857: }
19858: } else {
19859: if (ref($by_location{$val}) eq 'ARRAY') {
19860: push(@okvals,$val);
19861: }
1.137 raeburn 19862: }
19863: }
19864: @okvals = sort(@okvals);
19865: if (ref($domconfig{'usersessions'}) eq 'HASH') {
19866: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
19867: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
19868: if ($inuse == 0) {
19869: $changes{$prefix}{$type} = 1;
19870: } else {
19871: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
19872: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
19873: if (@changed > 0) {
19874: $changes{$prefix}{$type} = 1;
19875: }
19876: }
19877: } else {
19878: if ($inuse == 1) {
19879: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
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: }
19896: }
19897: }
1.145 raeburn 19898:
19899: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 19900: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 19901: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
19902: my $savespares;
19903:
19904: foreach my $lonhost (sort(keys(%servers))) {
19905: my $serverhomeID =
19906: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 19907: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 19908: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
19909: my %spareschg;
19910: foreach my $type (@{$types{'spares'}}) {
19911: my @okspares;
19912: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
19913: foreach my $server (@checked) {
1.152 raeburn 19914: if (&Apache::lonnet::hostname($server) ne '') {
19915: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
19916: unless (grep(/^\Q$server\E$/,@okspares)) {
19917: push(@okspares,$server);
19918: }
1.145 raeburn 19919: }
19920: }
19921: }
19922: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
19923: my $newspare;
1.152 raeburn 19924: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
19925: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 19926: $newspare = $new;
19927: }
19928: }
1.152 raeburn 19929: my @spares;
19930: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
19931: @spares = sort(@okspares,$newspare);
19932: } else {
19933: @spares = sort(@okspares);
19934: }
19935: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 19936: if (ref($spareid{$lonhost}) eq 'HASH') {
19937: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 19938: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 19939: if (@diffs > 0) {
19940: $spareschg{$type} = 1;
19941: }
19942: }
19943: }
19944: }
19945: if (keys(%spareschg) > 0) {
19946: $changes{'spares'}{$lonhost} = \%spareschg;
19947: }
19948: }
1.261 raeburn 19949: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 19950: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 19951: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
19952: my @okoffload;
19953: if (@offloadnow) {
19954: foreach my $server (@offloadnow) {
19955: if (&Apache::lonnet::hostname($server) ne '') {
19956: unless (grep(/^\Q$server\E$/,@okoffload)) {
19957: push(@okoffload,$server);
19958: }
19959: }
19960: }
19961: if (@okoffload) {
19962: foreach my $lonhost (@okoffload) {
19963: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
19964: }
19965: }
19966: }
1.371 raeburn 19967: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
19968: my @okoffloadoth;
19969: if (@offloadoth) {
19970: foreach my $server (@offloadoth) {
19971: if (&Apache::lonnet::hostname($server) ne '') {
19972: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
19973: push(@okoffloadoth,$server);
19974: }
19975: }
19976: }
19977: if (@okoffloadoth) {
19978: foreach my $lonhost (@okoffloadoth) {
19979: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
19980: }
19981: }
19982: }
1.145 raeburn 19983: if (ref($domconfig{'usersessions'}) eq 'HASH') {
19984: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
19985: if (ref($changes{'spares'}) eq 'HASH') {
19986: if (keys(%{$changes{'spares'}}) > 0) {
19987: $savespares = 1;
19988: }
19989: }
19990: } else {
19991: $savespares = 1;
19992: }
1.371 raeburn 19993: foreach my $offload ('offloadnow','offloadoth') {
19994: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
19995: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
19996: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
19997: $changes{$offload} = 1;
19998: last;
19999: }
1.261 raeburn 20000: }
1.371 raeburn 20001: unless ($changes{$offload}) {
20002: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
20003: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
20004: $changes{$offload} = 1;
20005: last;
20006: }
1.261 raeburn 20007: }
20008: }
1.371 raeburn 20009: } else {
20010: if (($offload eq 'offloadnow') && (@okoffload)) {
20011: $changes{'offloadnow'} = 1;
20012: }
20013: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
20014: $changes{'offloadoth'} = 1;
20015: }
20016: }
20017: }
20018: } else {
20019: if (@okoffload) {
1.261 raeburn 20020: $changes{'offloadnow'} = 1;
20021: }
1.371 raeburn 20022: if (@okoffloadoth) {
20023: $changes{'offloadoth'} = 1;
20024: }
1.145 raeburn 20025: }
1.147 raeburn 20026: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
20027: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 20028: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20029: $dom);
20030: if ($putresult eq 'ok') {
20031: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
20032: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
20033: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
20034: }
20035: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
20036: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
20037: }
1.261 raeburn 20038: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
20039: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
20040: }
1.371 raeburn 20041: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
20042: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
20043: }
1.137 raeburn 20044: }
20045: my $cachetime = 24*60*60;
20046: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 20047: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 20048: if (ref($lastactref) eq 'HASH') {
20049: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 20050: $lastactref->{'usersessions'} = 1;
1.212 raeburn 20051: }
1.147 raeburn 20052: if (keys(%changes) > 0) {
20053: my %lt = &usersession_titles();
20054: $resulttext = &mt('Changes made:').'<ul>';
20055: foreach my $prefix (@prefixes) {
20056: if (ref($changes{$prefix}) eq 'HASH') {
20057: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
20058: if ($prefix eq 'spares') {
20059: if (ref($changes{$prefix}) eq 'HASH') {
20060: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
20061: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 20062: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 20063: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
20064: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 20065: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
20066: foreach my $type (@{$types{$prefix}}) {
20067: if ($changes{$prefix}{$lonhost}{$type}) {
20068: my $offloadto = &mt('None');
20069: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
20070: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
20071: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
20072: }
1.145 raeburn 20073: }
1.147 raeburn 20074: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 20075: }
1.137 raeburn 20076: }
20077: }
1.147 raeburn 20078: $resulttext .= '</li>';
1.137 raeburn 20079: }
20080: }
1.147 raeburn 20081: } else {
20082: foreach my $type (@{$types{$prefix}}) {
20083: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 20084: my ($newvalue,$notinuse);
1.147 raeburn 20085: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
20086: if (ref($defaultshash{'usersessions'}{$prefix})) {
20087: if ($type eq 'version') {
20088: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 20089: } else {
20090: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
20091: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
20092: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
20093: }
20094: } else {
20095: $notinuse = 1;
1.147 raeburn 20096: }
1.145 raeburn 20097: }
20098: }
20099: }
1.147 raeburn 20100: if ($newvalue eq '') {
20101: if ($type eq 'version') {
20102: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 20103: } elsif ($notinuse) {
20104: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 20105: } else {
20106: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
20107: }
1.145 raeburn 20108: } else {
1.147 raeburn 20109: if ($type eq 'version') {
1.344 raeburn 20110: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 20111: }
20112: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 20113: }
1.137 raeburn 20114: }
20115: }
20116: }
1.147 raeburn 20117: $resulttext .= '</ul>';
1.137 raeburn 20118: }
20119: }
1.261 raeburn 20120: if ($changes{'offloadnow'}) {
20121: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
20122: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 20123: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 20124: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
20125: $resulttext .= '<li>'.$lonhost.'</li>';
20126: }
20127: $resulttext .= '</ul>';
20128: } else {
1.371 raeburn 20129: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
20130: }
20131: } else {
20132: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
20133: }
20134: }
20135: if ($changes{'offloadoth'}) {
20136: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
20137: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
20138: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
20139: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
20140: $resulttext .= '<li>'.$lonhost.'</li>';
20141: }
20142: $resulttext .= '</ul>';
20143: } else {
20144: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 20145: }
20146: } else {
1.371 raeburn 20147: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 20148: }
20149: }
1.147 raeburn 20150: $resulttext .= '</ul>';
20151: } else {
20152: $resulttext = $nochgmsg;
1.137 raeburn 20153: }
20154: } else {
20155: $resulttext = '<span class="LC_error">'.
20156: &mt('An error occurred: [_1]',$putresult).'</span>';
20157: }
20158: } else {
1.147 raeburn 20159: $resulttext = $nochgmsg;
1.137 raeburn 20160: }
20161: return $resulttext;
20162: }
20163:
1.275 raeburn 20164: sub modify_ssl {
20165: my ($dom,$lastactref,%domconfig) = @_;
20166: my (%by_ip,%by_location,@intdoms,@instdoms);
20167: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
20168: my @locations = sort(keys(%by_location));
20169: my %servers = &Apache::lonnet::internet_dom_servers($dom);
20170: my (%defaultshash,%changes);
20171: my $action = 'ssl';
1.293 raeburn 20172: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 20173: foreach my $prefix (@prefixes) {
20174: $defaultshash{$action}{$prefix} = {};
20175: }
20176: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
20177: my $resulttext;
20178: my %iphost = &Apache::lonnet::get_iphost();
20179: my @reptypes = ('certreq','nocertreq');
20180: my @connecttypes = ('dom','intdom','other');
20181: my %types = (
1.293 raeburn 20182: connto => \@connecttypes,
20183: connfrom => \@connecttypes,
20184: replication => \@reptypes,
1.275 raeburn 20185: );
20186: foreach my $prefix (sort(keys(%types))) {
20187: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 20188: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 20189: my $value = 'yes';
20190: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
20191: $value = $env{'form.'.$prefix.'_'.$type};
20192: }
1.335 raeburn 20193: if (ref($domconfig{$action}) eq 'HASH') {
20194: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
20195: if ($domconfig{$action}{$prefix}{$type} ne '') {
20196: if ($value ne $domconfig{$action}{$prefix}{$type}) {
20197: $changes{$prefix}{$type} = 1;
20198: }
20199: $defaultshash{$action}{$prefix}{$type} = $value;
20200: } else {
20201: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 20202: $changes{$prefix}{$type} = 1;
20203: }
20204: } else {
20205: $defaultshash{$action}{$prefix}{$type} = $value;
20206: $changes{$prefix}{$type} = 1;
20207: }
20208: } else {
20209: $defaultshash{$action}{$prefix}{$type} = $value;
20210: $changes{$prefix}{$type} = 1;
20211: }
20212: if (($type eq 'dom') && (keys(%servers) == 1)) {
20213: delete($changes{$prefix}{$type});
20214: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
20215: delete($changes{$prefix}{$type});
20216: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
20217: delete($changes{$prefix}{$type});
20218: }
20219: } elsif ($prefix eq 'replication') {
20220: if (@locations > 0) {
20221: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
20222: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
20223: my @okvals;
20224: foreach my $val (@vals) {
20225: if ($val =~ /:/) {
20226: my @items = split(/:/,$val);
20227: foreach my $item (@items) {
20228: if (ref($by_location{$item}) eq 'ARRAY') {
20229: push(@okvals,$item);
20230: }
20231: }
20232: } else {
20233: if (ref($by_location{$val}) eq 'ARRAY') {
20234: push(@okvals,$val);
20235: }
20236: }
20237: }
20238: @okvals = sort(@okvals);
20239: if (ref($domconfig{$action}) eq 'HASH') {
20240: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
20241: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
20242: if ($inuse == 0) {
20243: $changes{$prefix}{$type} = 1;
20244: } else {
20245: $defaultshash{$action}{$prefix}{$type} = \@okvals;
20246: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
20247: if (@changed > 0) {
20248: $changes{$prefix}{$type} = 1;
20249: }
20250: }
20251: } else {
20252: if ($inuse == 1) {
20253: $defaultshash{$action}{$prefix}{$type} = \@okvals;
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: }
20270: }
20271: }
20272: }
1.336 raeburn 20273: if (keys(%changes)) {
20274: foreach my $prefix (keys(%changes)) {
20275: if (ref($changes{$prefix}) eq 'HASH') {
20276: if (scalar(keys(%{$changes{$prefix}})) == 0) {
20277: delete($changes{$prefix});
20278: }
20279: } else {
20280: delete($changes{$prefix});
20281: }
20282: }
20283: }
1.275 raeburn 20284: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
20285: if (keys(%changes) > 0) {
20286: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20287: $dom);
20288: if ($putresult eq 'ok') {
20289: if (ref($defaultshash{$action}) eq 'HASH') {
20290: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
20291: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
20292: }
1.293 raeburn 20293: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 20294: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 20295: }
20296: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 20297: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 20298: }
20299: }
20300: my $cachetime = 24*60*60;
20301: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20302: if (ref($lastactref) eq 'HASH') {
20303: $lastactref->{'domdefaults'} = 1;
20304: }
20305: if (keys(%changes) > 0) {
20306: my %titles = &ssl_titles();
20307: $resulttext = &mt('Changes made:').'<ul>';
20308: foreach my $prefix (@prefixes) {
20309: if (ref($changes{$prefix}) eq 'HASH') {
20310: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
20311: foreach my $type (@{$types{$prefix}}) {
20312: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 20313: my ($newvalue,$notinuse);
1.275 raeburn 20314: if (ref($defaultshash{$action}) eq 'HASH') {
20315: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 20316: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 20317: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 20318: } else {
20319: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
20320: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
20321: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
20322: }
20323: } else {
20324: $notinuse = 1;
1.275 raeburn 20325: }
20326: }
20327: }
1.344 raeburn 20328: if ($notinuse) {
20329: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
20330: } elsif ($newvalue eq '') {
1.275 raeburn 20331: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
20332: } else {
20333: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
20334: }
20335: }
20336: }
20337: }
20338: $resulttext .= '</ul>';
20339: }
20340: }
20341: } else {
20342: $resulttext = $nochgmsg;
20343: }
20344: } else {
20345: $resulttext = '<span class="LC_error">'.
20346: &mt('An error occurred: [_1]',$putresult).'</span>';
20347: }
20348: } else {
20349: $resulttext = $nochgmsg;
20350: }
20351: return $resulttext;
20352: }
20353:
1.279 raeburn 20354: sub modify_trust {
20355: my ($dom,$lastactref,%domconfig) = @_;
20356: my (%by_ip,%by_location,@intdoms,@instdoms);
20357: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
20358: my @locations = sort(keys(%by_location));
20359: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
20360: my @types = ('exc','inc');
20361: my (%defaultshash,%changes);
20362: foreach my $prefix (@prefixes) {
20363: $defaultshash{'trust'}{$prefix} = {};
20364: }
20365: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
20366: my $resulttext;
20367: foreach my $prefix (@prefixes) {
20368: foreach my $type (@types) {
20369: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
20370: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
20371: my @okvals;
20372: foreach my $val (@vals) {
20373: if ($val =~ /:/) {
20374: my @items = split(/:/,$val);
20375: foreach my $item (@items) {
20376: if (ref($by_location{$item}) eq 'ARRAY') {
20377: push(@okvals,$item);
20378: }
20379: }
20380: } else {
20381: if (ref($by_location{$val}) eq 'ARRAY') {
20382: push(@okvals,$val);
20383: }
20384: }
20385: }
20386: @okvals = sort(@okvals);
20387: if (ref($domconfig{'trust'}) eq 'HASH') {
20388: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
20389: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
20390: if ($inuse == 0) {
20391: $changes{$prefix}{$type} = 1;
20392: } else {
20393: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
20394: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
20395: if (@changed > 0) {
20396: $changes{$prefix}{$type} = 1;
20397: }
20398: }
20399: } else {
20400: if ($inuse == 1) {
20401: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
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: }
20418: }
20419: my $nochgmsg = &mt('No changes made to trust settings.');
20420: if (keys(%changes) > 0) {
20421: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20422: $dom);
20423: if ($putresult eq 'ok') {
20424: if (ref($defaultshash{'trust'}) eq 'HASH') {
20425: foreach my $prefix (@prefixes) {
20426: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
20427: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
20428: }
20429: }
20430: }
20431: my $cachetime = 24*60*60;
20432: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20433: if (ref($lastactref) eq 'HASH') {
20434: $lastactref->{'domdefaults'} = 1;
20435: }
20436: if (keys(%changes) > 0) {
20437: my %lt = &trust_titles();
20438: $resulttext = &mt('Changes made:').'<ul>';
20439: foreach my $prefix (@prefixes) {
20440: if (ref($changes{$prefix}) eq 'HASH') {
20441: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
20442: foreach my $type (@types) {
20443: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 20444: my ($newvalue,$notinuse);
1.279 raeburn 20445: if (ref($defaultshash{'trust'}) eq 'HASH') {
20446: if (ref($defaultshash{'trust'}{$prefix})) {
20447: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
20448: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
20449: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
20450: }
1.344 raeburn 20451: } else {
20452: $notinuse = 1;
1.279 raeburn 20453: }
20454: }
20455: }
1.344 raeburn 20456: if ($notinuse) {
20457: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
20458: } elsif ($newvalue eq '') {
1.279 raeburn 20459: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
20460: } else {
20461: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
20462: }
20463: }
20464: }
20465: $resulttext .= '</ul>';
20466: }
20467: }
20468: $resulttext .= '</ul>';
20469: } else {
20470: $resulttext = $nochgmsg;
20471: }
20472: } else {
20473: $resulttext = '<span class="LC_error">'.
20474: &mt('An error occurred: [_1]',$putresult).'</span>';
20475: }
20476: } else {
20477: $resulttext = $nochgmsg;
20478: }
20479: return $resulttext;
20480: }
20481:
1.150 raeburn 20482: sub modify_loadbalancing {
20483: my ($dom,%domconfig) = @_;
20484: my $primary_id = &Apache::lonnet::domain($dom,'primary');
20485: my $intdom = &Apache::lonnet::internet_dom($primary_id);
20486: my ($othertitle,$usertypes,$types) =
20487: &Apache::loncommon::sorted_inst_types($dom);
20488: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 20489: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 20490: my @sparestypes = ('primary','default');
20491: my %typetitles = &sparestype_titles();
20492: my $resulttext;
1.342 raeburn 20493: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 20494: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
20495: %existing = %{$domconfig{'loadbalancing'}};
20496: }
20497: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 20498: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 20499: my ($saveloadbalancing,%defaultshash,%changes);
20500: my ($alltypes,$othertypes,$titles) =
20501: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
20502: my %ruletitles = &offloadtype_text();
20503: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
20504: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
20505: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
20506: if ($balancer eq '') {
20507: next;
20508: }
1.210 raeburn 20509: if (!exists($servers{$balancer})) {
1.171 raeburn 20510: if (exists($currbalancer{$balancer})) {
20511: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 20512: }
1.171 raeburn 20513: next;
20514: }
20515: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
20516: push(@{$changes{'delete'}},$balancer);
20517: next;
20518: }
20519: if (!exists($currbalancer{$balancer})) {
20520: push(@{$changes{'add'}},$balancer);
20521: }
20522: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
20523: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
20524: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
20525: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
20526: $saveloadbalancing = 1;
20527: }
20528: foreach my $sparetype (@sparestypes) {
20529: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
20530: my @offloadto;
20531: foreach my $target (@targets) {
20532: if (($servers{$target}) && ($target ne $balancer)) {
20533: if ($sparetype eq 'default') {
20534: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
20535: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 20536: }
20537: }
1.171 raeburn 20538: unless(grep(/^\Q$target\E$/,@offloadto)) {
20539: push(@offloadto,$target);
20540: }
1.150 raeburn 20541: }
20542: }
1.284 raeburn 20543: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
20544: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
20545: push(@offloadto,$balancer);
20546: }
20547: }
20548: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 20549: }
1.342 raeburn 20550: if ($env{'form.loadbalancing_cookie_'.$i}) {
20551: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
20552: if (exists($currbalancer{$balancer})) {
20553: unless ($currcookies{$balancer}) {
20554: $changes{'curr'}{$balancer}{'cookie'} = 1;
20555: }
20556: }
20557: } elsif (exists($currbalancer{$balancer})) {
20558: if ($currcookies{$balancer}) {
20559: $changes{'curr'}{$balancer}{'cookie'} = 1;
20560: }
20561: }
1.171 raeburn 20562: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 20563: foreach my $sparetype (@sparestypes) {
1.171 raeburn 20564: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
20565: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 20566: if (@targetdiffs > 0) {
1.171 raeburn 20567: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 20568: }
1.171 raeburn 20569: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20570: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
20571: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 20572: }
20573: }
20574: }
20575: } else {
1.171 raeburn 20576: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 20577: foreach my $sparetype (@sparestypes) {
1.171 raeburn 20578: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20579: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
20580: $changes{'curr'}{$balancer}{'targets'} = 1;
20581: }
1.150 raeburn 20582: }
20583: }
1.210 raeburn 20584: }
1.150 raeburn 20585: }
20586: my $ishomedom;
1.171 raeburn 20587: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
20588: $ishomedom = 1;
1.150 raeburn 20589: }
20590: if (ref($alltypes) eq 'ARRAY') {
20591: foreach my $type (@{$alltypes}) {
20592: my $rule;
1.210 raeburn 20593: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 20594: (!$ishomedom)) {
1.171 raeburn 20595: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
20596: }
20597: if ($rule eq 'specific') {
1.255 raeburn 20598: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 20599: if (exists($servers{$specifiedhost})) {
1.255 raeburn 20600: $rule = $specifiedhost;
20601: }
1.150 raeburn 20602: }
1.171 raeburn 20603: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
20604: if (ref($currrules{$balancer}) eq 'HASH') {
20605: if ($rule ne $currrules{$balancer}{$type}) {
20606: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 20607: }
20608: } elsif ($rule ne '') {
1.171 raeburn 20609: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 20610: }
20611: }
20612: }
1.171 raeburn 20613: }
20614: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
20615: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
20616: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
20617: $defaultshash{'loadbalancing'} = {};
20618: }
20619: my $putresult = &Apache::lonnet::put_dom('configuration',
20620: \%defaultshash,$dom);
20621: if ($putresult eq 'ok') {
20622: if (keys(%changes) > 0) {
1.252 raeburn 20623: my %toupdate;
1.171 raeburn 20624: if (ref($changes{'delete'}) eq 'ARRAY') {
20625: foreach my $balancer (sort(@{$changes{'delete'}})) {
20626: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 20627: $toupdate{$balancer} = 1;
1.150 raeburn 20628: }
1.171 raeburn 20629: }
20630: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 20631: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 20632: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 20633: $toupdate{$balancer} = 1;
1.171 raeburn 20634: }
20635: }
20636: if (ref($changes{'curr'}) eq 'HASH') {
20637: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 20638: $toupdate{$balancer} = 1;
1.171 raeburn 20639: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
20640: if ($changes{'curr'}{$balancer}{'targets'}) {
20641: my %offloadstr;
20642: foreach my $sparetype (@sparestypes) {
20643: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20644: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
20645: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
20646: }
20647: }
1.150 raeburn 20648: }
1.171 raeburn 20649: if (keys(%offloadstr) == 0) {
20650: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 20651: } else {
1.171 raeburn 20652: my $showoffload;
20653: foreach my $sparetype (@sparestypes) {
20654: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
20655: if (defined($offloadstr{$sparetype})) {
20656: $showoffload .= $offloadstr{$sparetype};
20657: } else {
20658: $showoffload .= &mt('None');
20659: }
20660: $showoffload .= (' 'x3);
20661: }
20662: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 20663: }
20664: }
20665: }
1.171 raeburn 20666: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
20667: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
20668: foreach my $type (@{$alltypes}) {
20669: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
20670: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
20671: my $balancetext;
20672: if ($rule eq '') {
20673: $balancetext = $ruletitles{'default'};
1.209 raeburn 20674: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 20675: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 20676: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 20677: foreach my $sparetype (@sparestypes) {
20678: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20679: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
20680: }
20681: }
1.253 raeburn 20682: foreach my $item (@{$alltypes}) {
20683: next if ($item =~ /^_LC_ipchange/);
20684: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
20685: if ($hasrule eq 'homeserver') {
20686: map { $toupdate{$_} = 1; } (keys(%libraryservers));
20687: } else {
20688: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
20689: if ($servers{$hasrule}) {
20690: $toupdate{$hasrule} = 1;
20691: }
20692: }
20693: }
20694: }
1.254 raeburn 20695: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
20696: $balancetext = $ruletitles{$rule};
20697: } else {
20698: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
20699: $balancetext = $ruletitles{'particular'}.' '.$receiver;
20700: if ($receiver) {
20701: $toupdate{$receiver};
20702: }
20703: }
20704: } else {
20705: $balancetext = $ruletitles{$rule};
1.252 raeburn 20706: }
1.171 raeburn 20707: } else {
20708: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
20709: }
1.210 raeburn 20710: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 20711: }
20712: }
20713: }
20714: }
1.342 raeburn 20715: if ($changes{'curr'}{$balancer}{'cookie'}) {
20716: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
20717: $balancer).'</li>';
20718: }
1.375 raeburn 20719: }
20720: }
20721: if (keys(%toupdate)) {
20722: my %thismachine;
20723: my $updatedhere;
20724: my $cachetime = 60*60*24;
20725: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
20726: foreach my $lonhost (keys(%toupdate)) {
20727: if ($thismachine{$lonhost}) {
20728: unless ($updatedhere) {
20729: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
20730: $defaultshash{'loadbalancing'},
20731: $cachetime);
20732: $updatedhere = 1;
1.252 raeburn 20733: }
1.375 raeburn 20734: } else {
20735: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
20736: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 20737: }
1.150 raeburn 20738: }
1.171 raeburn 20739: }
20740: if ($resulttext ne '') {
20741: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 20742: } else {
20743: $resulttext = $nochgmsg;
20744: }
20745: } else {
1.171 raeburn 20746: $resulttext = $nochgmsg;
1.150 raeburn 20747: }
20748: } else {
1.171 raeburn 20749: $resulttext = '<span class="LC_error">'.
20750: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 20751: }
20752: } else {
1.171 raeburn 20753: $resulttext = $nochgmsg;
1.150 raeburn 20754: }
20755: return $resulttext;
20756: }
20757:
1.48 raeburn 20758: sub recurse_check {
20759: my ($chkcats,$categories,$depth,$name) = @_;
20760: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
20761: my $chg = 0;
20762: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
20763: my $category = $chkcats->[$depth]{$name}[$j];
20764: my $item;
20765: if ($category eq '') {
20766: $chg ++;
20767: } else {
20768: my $deeper = $depth + 1;
20769: $item = &escape($category).':'.&escape($name).':'.$depth;
20770: if ($chg) {
20771: $categories->{$item} -= $chg;
20772: }
20773: &recurse_check($chkcats,$categories,$deeper,$category);
20774: $deeper --;
20775: }
20776: }
20777: }
20778: return;
20779: }
20780:
20781: sub recurse_cat_deletes {
20782: my ($item,$coursecategories,$deletions) = @_;
20783: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
20784: my $subdepth = $depth + 1;
20785: if (ref($coursecategories) eq 'HASH') {
20786: foreach my $subitem (keys(%{$coursecategories})) {
20787: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
20788: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
20789: delete($coursecategories->{$subitem});
20790: $deletions->{$subitem} = 1;
20791: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 20792: }
1.48 raeburn 20793: }
20794: }
20795: return;
20796: }
20797:
1.125 raeburn 20798: sub active_dc_picker {
1.191 raeburn 20799: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 20800: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 20801: my @domcoord = keys(%domcoords);
20802: if (keys(%currhash)) {
20803: foreach my $dc (keys(%currhash)) {
20804: unless (exists($domcoords{$dc})) {
20805: push(@domcoord,$dc);
20806: }
20807: }
20808: }
20809: @domcoord = sort(@domcoord);
1.210 raeburn 20810: my $numdcs = scalar(@domcoord);
1.191 raeburn 20811: my $rows = 0;
20812: my $table;
1.125 raeburn 20813: if ($numdcs > 1) {
1.191 raeburn 20814: $table = '<table>';
20815: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 20816: my $rem = $i%($numinrow);
20817: if ($rem == 0) {
20818: if ($i > 0) {
1.191 raeburn 20819: $table .= '</tr>';
1.125 raeburn 20820: }
1.191 raeburn 20821: $table .= '<tr>';
20822: $rows ++;
1.125 raeburn 20823: }
1.191 raeburn 20824: my $check = '';
20825: if ($inputtype eq 'radio') {
20826: if (keys(%currhash) == 0) {
20827: if (!$i) {
20828: $check = ' checked="checked"';
20829: }
20830: } elsif (exists($currhash{$domcoord[$i]})) {
20831: $check = ' checked="checked"';
20832: }
20833: } else {
20834: if (exists($currhash{$domcoord[$i]})) {
20835: $check = ' checked="checked"';
1.125 raeburn 20836: }
20837: }
1.191 raeburn 20838: if ($i == @domcoord - 1) {
1.125 raeburn 20839: my $colsleft = $numinrow - $rem;
20840: if ($colsleft > 1) {
1.191 raeburn 20841: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 20842: } else {
1.191 raeburn 20843: $table .= '<td class="LC_left_item">';
1.125 raeburn 20844: }
20845: } else {
1.191 raeburn 20846: $table .= '<td class="LC_left_item">';
20847: }
20848: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
20849: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
20850: $table .= '<span class="LC_nobreak"><label>'.
20851: '<input type="'.$inputtype.'" name="'.$name.'"'.
20852: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
20853: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 20854: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 20855: }
1.219 raeburn 20856: $table .= '</label></span></td>';
1.191 raeburn 20857: }
20858: $table .= '</tr></table>';
20859: } elsif ($numdcs == 1) {
1.219 raeburn 20860: my ($dcname,$dcdom) = split(':',$domcoord[0]);
20861: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 20862: if ($inputtype eq 'radio') {
1.247 raeburn 20863: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 20864: if ($user ne $dcname.':'.$dcdom) {
20865: $table .= ' ('.$dcname.':'.$dcdom.')';
20866: }
1.191 raeburn 20867: } else {
20868: my $check;
20869: if (exists($currhash{$domcoord[0]})) {
20870: $check = ' checked="checked"';
1.125 raeburn 20871: }
1.247 raeburn 20872: $table = '<span class="LC_nobreak"><label>'.
20873: '<input type="checkbox" name="'.$name.'" '.
20874: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 20875: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 20876: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 20877: }
1.220 raeburn 20878: $table .= '</label></span>';
1.191 raeburn 20879: $rows ++;
1.125 raeburn 20880: }
20881: }
1.191 raeburn 20882: return ($numdcs,$table,$rows);
1.125 raeburn 20883: }
20884:
1.137 raeburn 20885: sub usersession_titles {
20886: return &Apache::lonlocal::texthash(
20887: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
20888: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 20889: spares => 'Servers offloaded to, when busy',
1.137 raeburn 20890: version => 'LON-CAPA version requirement',
1.138 raeburn 20891: excludedomain => 'Allow all, but exclude specific domains',
20892: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 20893: primary => 'Primary (checked first)',
1.154 raeburn 20894: default => 'Default',
1.137 raeburn 20895: );
20896: }
20897:
1.152 raeburn 20898: sub id_for_thisdom {
20899: my (%servers) = @_;
20900: my %altids;
20901: foreach my $server (keys(%servers)) {
20902: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
20903: if ($serverhome ne $server) {
20904: $altids{$serverhome} = $server;
20905: }
20906: }
20907: return %altids;
20908: }
20909:
1.150 raeburn 20910: sub count_servers {
20911: my ($currbalancer,%servers) = @_;
20912: my (@spares,$numspares);
20913: foreach my $lonhost (sort(keys(%servers))) {
20914: next if ($currbalancer eq $lonhost);
20915: push(@spares,$lonhost);
20916: }
20917: if ($currbalancer) {
20918: $numspares = scalar(@spares);
20919: } else {
20920: $numspares = scalar(@spares) - 1;
20921: }
20922: return ($numspares,@spares);
20923: }
20924:
20925: sub lonbalance_targets_js {
1.171 raeburn 20926: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 20927: my $select = &mt('Select');
20928: my ($alltargets,$allishome,$allinsttypes,@alltypes);
20929: if (ref($servers) eq 'HASH') {
20930: $alltargets = join("','",sort(keys(%{$servers})));
20931: my @homedoms;
20932: foreach my $server (sort(keys(%{$servers}))) {
20933: if (&Apache::lonnet::host_domain($server) eq $dom) {
20934: push(@homedoms,'1');
20935: } else {
20936: push(@homedoms,'0');
20937: }
20938: }
20939: $allishome = join("','",@homedoms);
20940: }
20941: if (ref($types) eq 'ARRAY') {
20942: if (@{$types} > 0) {
20943: @alltypes = @{$types};
20944: }
20945: }
20946: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
20947: $allinsttypes = join("','",@alltypes);
1.342 raeburn 20948: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 20949: if (ref($settings) eq 'HASH') {
20950: %existing = %{$settings};
20951: }
20952: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 20953: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 20954: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 20955: return <<"END";
20956:
20957: <script type="text/javascript">
20958: // <![CDATA[
20959:
1.171 raeburn 20960: currBalancers = new Array('$balancers');
20961:
20962: function toggleTargets(balnum) {
20963: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
20964: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
20965: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
20966: var prevbalancer = prevhostitem.value;
20967: var baltotal = document.getElementById('loadbalancing_total').value;
20968: prevhostitem.value = balancer;
20969: if (prevbalancer != '') {
20970: var prevIdx = currBalancers.indexOf(prevbalancer);
20971: if (prevIdx != -1) {
20972: currBalancers.splice(prevIdx,1);
20973: }
20974: }
1.150 raeburn 20975: if (balancer == '') {
1.171 raeburn 20976: hideSpares(balnum);
1.150 raeburn 20977: } else {
1.171 raeburn 20978: var currIdx = currBalancers.indexOf(balancer);
20979: if (currIdx == -1) {
20980: currBalancers.push(balancer);
20981: }
1.150 raeburn 20982: var homedoms = new Array('$allishome');
1.171 raeburn 20983: var ishomedom = homedoms[lonhostitem.selectedIndex];
20984: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 20985: }
1.171 raeburn 20986: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 20987: return;
20988: }
20989:
1.171 raeburn 20990: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 20991: var alltargets = new Array('$alltargets');
20992: var insttypes = new Array('$allinsttypes');
1.151 raeburn 20993: var offloadtypes = new Array('primary','default');
20994:
1.171 raeburn 20995: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
20996: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 20997:
1.151 raeburn 20998: for (var i=0; i<offloadtypes.length; i++) {
20999: var count = 0;
21000: for (var j=0; j<alltargets.length; j++) {
21001: if (alltargets[j] != balancer) {
1.171 raeburn 21002: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
21003: item.value = alltargets[j];
21004: item.style.textAlign='left';
21005: item.style.textFace='normal';
21006: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
21007: if (currBalancers.indexOf(alltargets[j]) == -1) {
21008: item.disabled = '';
21009: } else {
21010: item.disabled = 'disabled';
21011: item.checked = false;
21012: }
1.151 raeburn 21013: count ++;
21014: }
1.150 raeburn 21015: }
21016: }
1.151 raeburn 21017: for (var k=0; k<insttypes.length; k++) {
21018: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 21019: if (ishomedom == 1) {
1.171 raeburn 21020: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
21021: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 21022: } else {
1.171 raeburn 21023: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
21024: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 21025: }
21026: } else {
1.171 raeburn 21027: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
21028: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 21029: }
1.151 raeburn 21030: if ((insttypes[k] != '_LC_external') &&
21031: ((insttypes[k] != '_LC_internetdom') ||
21032: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 21033: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
21034: item.options.length = 0;
21035: item.options[0] = new Option("","",true,true);
1.210 raeburn 21036: var idx = 0;
1.151 raeburn 21037: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 21038: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
21039: idx ++;
21040: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 21041: }
21042: }
21043: }
21044: }
21045: return;
21046: }
21047:
1.171 raeburn 21048: function hideSpares(balnum) {
1.150 raeburn 21049: var alltargets = new Array('$alltargets');
21050: var insttypes = new Array('$allinsttypes');
21051: var offloadtypes = new Array('primary','default');
21052:
1.171 raeburn 21053: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
21054: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 21055:
21056: var total = alltargets.length - 1;
21057: for (var i=0; i<offloadtypes; i++) {
21058: for (var j=0; j<total; j++) {
1.171 raeburn 21059: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
21060: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
21061: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 21062: }
1.150 raeburn 21063: }
21064: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 21065: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
21066: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 21067: if (insttypes[k] != '_LC_external') {
1.171 raeburn 21068: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
21069: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 21070: }
21071: }
21072: return;
21073: }
21074:
1.171 raeburn 21075: function checkOffloads(item,balnum,type) {
1.150 raeburn 21076: var alltargets = new Array('$alltargets');
21077: var offloadtypes = new Array('primary','default');
21078: if (item.checked) {
21079: var total = alltargets.length - 1;
21080: var other;
21081: if (type == offloadtypes[0]) {
1.151 raeburn 21082: other = offloadtypes[1];
1.150 raeburn 21083: } else {
1.151 raeburn 21084: other = offloadtypes[0];
1.150 raeburn 21085: }
21086: for (var i=0; i<total; i++) {
1.171 raeburn 21087: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 21088: if (server == item.value) {
1.171 raeburn 21089: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
21090: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 21091: }
21092: }
21093: }
21094: }
21095: return;
21096: }
21097:
1.171 raeburn 21098: function singleServerToggle(balnum,type) {
21099: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 21100: if (offloadtoSelIdx == 0) {
1.171 raeburn 21101: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
21102: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 21103:
21104: } else {
1.171 raeburn 21105: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
21106: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 21107: }
21108: return;
21109: }
21110:
1.171 raeburn 21111: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 21112: if (type == '_LC_external') {
1.171 raeburn 21113: return;
1.150 raeburn 21114: }
1.171 raeburn 21115: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 21116: for (var i=0; i<typesRules.length; i++) {
21117: if (formname.elements[typesRules[i]].checked) {
21118: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 21119: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
21120: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 21121: } else {
1.171 raeburn 21122: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
21123: }
21124: }
21125: }
21126: return;
21127: }
21128:
21129: function balancerDeleteChange(balnum) {
21130: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
21131: var baltotal = document.getElementById('loadbalancing_total').value;
21132: var addtarget;
21133: var removetarget;
21134: var action = 'delete';
21135: if (document.getElementById('loadbalancing_delete_'+balnum)) {
21136: var lonhost = hostitem.value;
21137: var currIdx = currBalancers.indexOf(lonhost);
21138: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
21139: if (currIdx != -1) {
21140: currBalancers.splice(currIdx,1);
21141: }
21142: addtarget = lonhost;
21143: } else {
21144: if (currIdx == -1) {
21145: currBalancers.push(lonhost);
21146: }
21147: removetarget = lonhost;
21148: action = 'undelete';
21149: }
21150: balancerChange(balnum,baltotal,action,addtarget,removetarget);
21151: }
21152: return;
21153: }
21154:
21155: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
21156: if (baltotal > 1) {
21157: var offloadtypes = new Array('primary','default');
21158: var alltargets = new Array('$alltargets');
21159: var insttypes = new Array('$allinsttypes');
21160: for (var i=0; i<baltotal; i++) {
21161: if (i != balnum) {
21162: for (var j=0; j<offloadtypes.length; j++) {
21163: var total = alltargets.length - 1;
21164: for (var k=0; k<total; k++) {
21165: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
21166: var server = serveritem.value;
21167: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
21168: if (server == addtarget) {
21169: serveritem.disabled = '';
21170: }
21171: }
21172: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
21173: if (server == removetarget) {
21174: serveritem.disabled = 'disabled';
21175: serveritem.checked = false;
21176: }
21177: }
21178: }
21179: }
21180: for (var j=0; j<insttypes.length; j++) {
21181: if (insttypes[j] != '_LC_external') {
21182: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
21183: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
21184: var currSel = singleserver.selectedIndex;
21185: var currVal = singleserver.options[currSel].value;
21186: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
21187: var numoptions = singleserver.options.length;
21188: var needsnew = 1;
21189: for (var k=0; k<numoptions; k++) {
21190: if (singleserver.options[k] == addtarget) {
21191: needsnew = 0;
21192: break;
21193: }
21194: }
21195: if (needsnew == 1) {
21196: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
21197: }
21198: }
21199: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
21200: singleserver.options.length = 0;
21201: if ((currVal) && (currVal != removetarget)) {
21202: singleserver.options[0] = new Option("","",false,false);
21203: } else {
21204: singleserver.options[0] = new Option("","",true,true);
21205: }
21206: var idx = 0;
21207: for (var m=0; m<alltargets.length; m++) {
21208: if (currBalancers.indexOf(alltargets[m]) == -1) {
21209: idx ++;
21210: if (currVal == alltargets[m]) {
21211: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
21212: } else {
21213: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
21214: }
21215: }
21216: }
21217: }
21218: }
21219: }
21220: }
1.150 raeburn 21221: }
21222: }
21223: }
21224: return;
21225: }
21226:
1.152 raeburn 21227: // ]]>
21228: </script>
21229:
21230: END
21231: }
21232:
1.372 raeburn 21233:
1.152 raeburn 21234: sub new_spares_js {
21235: my @sparestypes = ('primary','default');
21236: my $types = join("','",@sparestypes);
21237: my $select = &mt('Select');
21238: return <<"END";
21239:
21240: <script type="text/javascript">
21241: // <![CDATA[
21242:
21243: function updateNewSpares(formname,lonhost) {
21244: var types = new Array('$types');
21245: var include = new Array();
21246: var exclude = new Array();
21247: for (var i=0; i<types.length; i++) {
21248: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
21249: for (var j=0; j<spareboxes.length; j++) {
21250: if (formname.elements[spareboxes[j]].checked) {
21251: exclude.push(formname.elements[spareboxes[j]].value);
21252: } else {
21253: include.push(formname.elements[spareboxes[j]].value);
21254: }
21255: }
21256: }
21257: for (var i=0; i<types.length; i++) {
21258: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
21259: var selIdx = newSpare.selectedIndex;
21260: var currnew = newSpare.options[selIdx].value;
21261: var okSpares = new Array();
21262: for (var j=0; j<newSpare.options.length; j++) {
21263: var possible = newSpare.options[j].value;
21264: if (possible != '') {
21265: if (exclude.indexOf(possible) == -1) {
21266: okSpares.push(possible);
21267: } else {
21268: if (currnew == possible) {
21269: selIdx = 0;
21270: }
21271: }
21272: }
21273: }
21274: for (var k=0; k<include.length; k++) {
21275: if (okSpares.indexOf(include[k]) == -1) {
21276: okSpares.push(include[k]);
21277: }
21278: }
21279: okSpares.sort();
21280: newSpare.options.length = 0;
21281: if (selIdx == 0) {
21282: newSpare.options[0] = new Option("$select","",true,true);
21283: } else {
21284: newSpare.options[0] = new Option("$select","",false,false);
21285: }
21286: for (var m=0; m<okSpares.length; m++) {
21287: var idx = m+1;
21288: var selThis = 0;
21289: if (selIdx != 0) {
21290: if (okSpares[m] == currnew) {
21291: selThis = 1;
21292: }
21293: }
21294: if (selThis == 1) {
21295: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
21296: } else {
21297: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
21298: }
21299: }
21300: }
21301: return;
21302: }
21303:
21304: function checkNewSpares(lonhost,type) {
21305: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
21306: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 21307: if (chosen != '') {
1.152 raeburn 21308: var othertype;
21309: var othernewSpare;
21310: if (type == 'primary') {
21311: othernewSpare = document.getElementById('newspare_default_'+lonhost);
21312: }
21313: if (type == 'default') {
21314: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
21315: }
21316: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
21317: othernewSpare.selectedIndex = 0;
21318: }
21319: }
21320: return;
21321: }
21322:
21323: // ]]>
21324: </script>
21325:
21326: END
21327:
21328: }
21329:
21330: sub common_domprefs_js {
21331: return <<"END";
21332:
21333: <script type="text/javascript">
21334: // <![CDATA[
21335:
1.150 raeburn 21336: function getIndicesByName(formname,item) {
1.152 raeburn 21337: var group = new Array();
1.150 raeburn 21338: for (var i=0;i<formname.elements.length;i++) {
21339: if (formname.elements[i].name == item) {
1.152 raeburn 21340: group.push(formname.elements[i].id);
1.150 raeburn 21341: }
21342: }
1.152 raeburn 21343: return group;
1.150 raeburn 21344: }
21345:
21346: // ]]>
21347: </script>
21348:
21349: END
1.152 raeburn 21350:
1.150 raeburn 21351: }
21352:
1.165 raeburn 21353: sub recaptcha_js {
21354: my %lt = &captcha_phrases();
21355: return <<"END";
21356:
21357: <script type="text/javascript">
21358: // <![CDATA[
21359:
21360: function updateCaptcha(caller,context) {
21361: var privitem;
21362: var pubitem;
21363: var privtext;
21364: var pubtext;
1.269 raeburn 21365: var versionitem;
21366: var versiontext;
1.165 raeburn 21367: if (document.getElementById(context+'_recaptchapub')) {
21368: pubitem = document.getElementById(context+'_recaptchapub');
21369: } else {
21370: return;
21371: }
21372: if (document.getElementById(context+'_recaptchapriv')) {
21373: privitem = document.getElementById(context+'_recaptchapriv');
21374: } else {
21375: return;
21376: }
21377: if (document.getElementById(context+'_recaptchapubtxt')) {
21378: pubtext = document.getElementById(context+'_recaptchapubtxt');
21379: } else {
21380: return;
21381: }
21382: if (document.getElementById(context+'_recaptchaprivtxt')) {
21383: privtext = document.getElementById(context+'_recaptchaprivtxt');
21384: } else {
21385: return;
21386: }
1.269 raeburn 21387: if (document.getElementById(context+'_recaptchaversion')) {
21388: versionitem = document.getElementById(context+'_recaptchaversion');
21389: } else {
21390: return;
21391: }
21392: if (document.getElementById(context+'_recaptchavertxt')) {
21393: versiontext = document.getElementById(context+'_recaptchavertxt');
21394: } else {
21395: return;
21396: }
1.165 raeburn 21397: if (caller.checked) {
21398: if (caller.value == 'recaptcha') {
21399: pubitem.type = 'text';
21400: privitem.type = 'text';
21401: pubitem.size = '40';
21402: privitem.size = '40';
21403: pubtext.innerHTML = "$lt{'pub'}";
21404: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 21405: versionitem.type = 'text';
21406: versionitem.size = '3';
1.289 raeburn 21407: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 21408: } else {
21409: pubitem.type = 'hidden';
21410: privitem.type = 'hidden';
1.269 raeburn 21411: versionitem.type = 'hidden';
1.165 raeburn 21412: pubtext.innerHTML = '';
21413: privtext.innerHTML = '';
1.269 raeburn 21414: versiontext.innerHTML = '';
1.165 raeburn 21415: }
21416: }
21417: return;
21418: }
21419:
21420: // ]]>
21421: </script>
21422:
21423: END
21424:
21425: }
21426:
1.236 raeburn 21427: sub toggle_display_js {
1.192 raeburn 21428: return <<"END";
21429:
21430: <script type="text/javascript">
21431: // <![CDATA[
21432:
1.236 raeburn 21433: function toggleDisplay(domForm,caller) {
21434: if (document.getElementById(caller)) {
21435: var divitem = document.getElementById(caller);
21436: var optionsElement = domForm.coursecredits;
1.264 raeburn 21437: var checkval = 1;
21438: var dispval = 'block';
1.303 raeburn 21439: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 21440: if (caller == 'emailoptions') {
1.372 raeburn 21441: optionsElement = domForm.cancreate_email;
1.236 raeburn 21442: }
1.257 raeburn 21443: if (caller == 'studentsubmission') {
21444: optionsElement = domForm.postsubmit;
21445: }
1.264 raeburn 21446: if (caller == 'cloneinstcode') {
21447: optionsElement = domForm.canclone;
21448: checkval = 'instcode';
21449: }
1.303 raeburn 21450: if (selfcreateRegExp.test(caller)) {
21451: optionsElement = domForm.elements[caller];
21452: checkval = 'other';
21453: dispval = 'inline'
21454: }
1.236 raeburn 21455: if (optionsElement.length) {
1.192 raeburn 21456: var currval;
1.236 raeburn 21457: for (var i=0; i<optionsElement.length; i++) {
21458: if (optionsElement[i].checked) {
21459: currval = optionsElement[i].value;
1.192 raeburn 21460: }
21461: }
1.264 raeburn 21462: if (currval == checkval) {
21463: divitem.style.display = dispval;
1.192 raeburn 21464: } else {
1.236 raeburn 21465: divitem.style.display = 'none';
1.192 raeburn 21466: }
21467: }
21468: }
21469: return;
21470: }
21471:
21472: // ]]>
21473: </script>
21474:
21475: END
21476:
21477: }
21478:
1.165 raeburn 21479: sub captcha_phrases {
21480: return &Apache::lonlocal::texthash (
21481: priv => 'Private key',
21482: pub => 'Public key',
21483: original => 'original (CAPTCHA)',
21484: recaptcha => 'successor (ReCAPTCHA)',
21485: notused => 'unused',
1.289 raeburn 21486: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 21487: );
21488: }
21489:
1.205 raeburn 21490: sub devalidate_remote_domconfs {
1.212 raeburn 21491: my ($dom,$cachekeys) = @_;
21492: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 21493: my %servers = &Apache::lonnet::internet_dom_servers($dom);
21494: my %thismachine;
21495: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 21496: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.373 raeburn 21497: 'directorysrch','passwdconf','cats','proxyalias');
1.260 raeburn 21498: if (keys(%servers)) {
1.205 raeburn 21499: foreach my $server (keys(%servers)) {
21500: next if ($thismachine{$server});
1.212 raeburn 21501: my @cached;
21502: foreach my $name (@posscached) {
21503: if ($cachekeys->{$name}) {
1.373 raeburn 21504: if ($name eq 'proxyalias') {
21505: if (ref($cachekeys->{$name}) eq 'HASH') {
21506: foreach my $key (keys(%{$cachekeys->{$name}})) {
21507: push(@cached,&escape($name).':'.&escape($key));
21508: }
21509: }
21510: } else {
21511: push(@cached,&escape($name).':'.&escape($dom));
21512: }
1.212 raeburn 21513: }
21514: }
21515: if (@cached) {
21516: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
21517: }
1.205 raeburn 21518: }
21519: }
21520: return;
21521: }
21522:
1.3 raeburn 21523: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>