Annotation of loncom/interface/domainprefs.pm, revision 1.373
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.373 ! raeburn 4: # $Id: domainprefs.pm,v 1.372 2020/09/17 00:35:04 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',
! 266: 'usermodification','scantron','requestcourses','requestauthor'
! 267: 'coursecategories','serverstatuses','helpsettings','coursedefaults',
1.372 raeburn 268: 'ltitools','proctoring','selfenrollment','usersessions','ssl',
269: 'trust','lti');
1.171 raeburn 270: my %existing;
271: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
272: %existing = %{$domconfig{'loadbalancing'}};
273: }
274: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 275: push(@prefs_order,'loadbalancing');
276: }
1.30 raeburn 277: my %prefs = (
278: 'rolecolors' =>
279: { text => 'Default color schemes',
1.67 raeburn 280: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 281: header => [{col1 => 'Student Settings',
282: col2 => '',},
283: {col1 => 'Coordinator Settings',
284: col2 => '',},
285: {col1 => 'Author Settings',
286: col2 => '',},
287: {col1 => 'Administrator Settings',
288: col2 => '',}],
1.230 raeburn 289: print => \&print_rolecolors,
290: modify => \&modify_rolecolors,
1.30 raeburn 291: },
1.110 raeburn 292: 'login' =>
1.30 raeburn 293: { text => 'Log-in page options',
1.67 raeburn 294: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 295: header => [{col1 => 'Log-in Page Items',
296: col2 => '',},
297: {col1 => 'Log-in Help',
1.256 raeburn 298: col2 => 'Value'},
299: {col1 => 'Custom HTML in document head',
1.168 raeburn 300: col2 => 'Value'}],
1.230 raeburn 301: print => \&print_login,
302: modify => \&modify_login,
1.30 raeburn 303: },
1.43 raeburn 304: 'defaults' =>
1.236 raeburn 305: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 306: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 307: header => [{col1 => 'Setting',
1.236 raeburn 308: col2 => 'Value'},
309: {col1 => 'Institutional user types',
1.305 raeburn 310: col2 => 'Name displayed'}],
1.230 raeburn 311: print => \&print_defaults,
312: modify => \&modify_defaults,
1.43 raeburn 313: },
1.373 ! raeburn 314: 'wafproxy' =>
! 315: { text => 'Web Application Firewall/Reverse Proxy',
! 316: help => 'Domain_Configuration_WAF_Proxy',
! 317: header => [{col1 => 'Domain server',
! 318: col2 => 'Alias for WAF/Reverse Proxy',
! 319: },
! 320: {col1 => 'Setting',
! 321: col2 => 'Value',}],
! 322: print => \&print_wafproxy,
! 323: modify => \&modify_wafproxy,
! 324: },
1.354 raeburn 325: 'passwords' =>
326: { text => 'Passwords (Internal authentication)',
327: help => 'Domain_Configuration_Passwords',
328: header => [{col1 => 'Resetting Forgotten Password',
329: col2 => 'Settings'},
330: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
331: col2 => 'Settings'},
332: {col1 => 'Rules for LON-CAPA Passwords',
333: col2 => 'Settings'},
334: {col1 => 'Course Owner Changing Student Passwords',
335: col2 => 'Settings'}],
336: print => \&print_passwords,
337: modify => \&modify_passwords,
338: },
1.30 raeburn 339: 'quotas' =>
1.197 raeburn 340: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 341: help => 'Domain_Configuration_Quotas',
1.77 raeburn 342: header => [{col1 => 'User affiliation',
1.72 raeburn 343: col2 => 'Available tools',
1.213 raeburn 344: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 345: print => \&print_quotas,
346: modify => \&modify_quotas,
1.30 raeburn 347: },
348: 'autoenroll' =>
349: { text => 'Auto-enrollment settings',
1.67 raeburn 350: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 351: header => [{col1 => 'Configuration setting',
352: col2 => 'Value(s)'}],
1.230 raeburn 353: print => \&print_autoenroll,
354: modify => \&modify_autoenroll,
1.30 raeburn 355: },
356: 'autoupdate' =>
357: { text => 'Auto-update settings',
1.67 raeburn 358: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 359: header => [{col1 => 'Setting',
360: col2 => 'Value',},
1.131 raeburn 361: {col1 => 'Setting',
362: col2 => 'Affiliation'},
1.43 raeburn 363: {col1 => 'User population',
1.227 bisitz 364: col2 => 'Updatable user data'}],
1.230 raeburn 365: print => \&print_autoupdate,
366: modify => \&modify_autoupdate,
1.30 raeburn 367: },
1.125 raeburn 368: 'autocreate' =>
369: { text => 'Auto-course creation settings',
370: help => 'Domain_Configuration_Auto_Creation',
371: header => [{col1 => 'Configuration Setting',
372: col2 => 'Value',}],
1.230 raeburn 373: print => \&print_autocreate,
374: modify => \&modify_autocreate,
1.125 raeburn 375: },
1.30 raeburn 376: 'directorysrch' =>
1.277 raeburn 377: { text => 'Directory searches',
1.67 raeburn 378: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 379: header => [{col1 => 'Institutional Directory Setting',
380: col2 => 'Value',},
381: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 382: col2 => 'Value',}],
1.230 raeburn 383: print => \&print_directorysrch,
384: modify => \&modify_directorysrch,
1.30 raeburn 385: },
386: 'contacts' =>
1.286 raeburn 387: { text => 'E-mail addresses and helpform',
1.67 raeburn 388: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 389: header => [{col1 => 'Default e-mail addresses',
390: col2 => 'Value',},
391: {col1 => 'Recipient(s) for notifications',
392: col2 => 'Value',},
1.340 raeburn 393: {col1 => 'Nightly status check e-mail',
394: col2 => 'Settings',},
1.286 raeburn 395: {col1 => 'Ask helpdesk form settings',
396: col2 => 'Value',},],
1.230 raeburn 397: print => \&print_contacts,
398: modify => \&modify_contacts,
1.30 raeburn 399: },
400: 'usercreation' =>
401: { text => 'User creation',
1.67 raeburn 402: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 403: header => [{col1 => 'Format rule type',
404: col2 => 'Format rules in force'},
1.34 raeburn 405: {col1 => 'User account creation',
406: col2 => 'Usernames which may be created',},
1.30 raeburn 407: {col1 => 'Context',
1.43 raeburn 408: col2 => 'Assignable authentication types'}],
1.230 raeburn 409: print => \&print_usercreation,
410: modify => \&modify_usercreation,
1.30 raeburn 411: },
1.224 raeburn 412: 'selfcreation' =>
413: { text => 'Users self-creating accounts',
414: help => 'Domain_Configuration_Self_Creation',
415: header => [{col1 => 'Self-creation with institutional username',
416: col2 => 'Enabled?'},
417: {col1 => 'Institutional user type (login/SSO self-creation)',
418: col2 => 'Information user can enter'},
1.303 raeburn 419: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 420: col2 => 'Settings'}],
1.230 raeburn 421: print => \&print_selfcreation,
422: modify => \&modify_selfcreation,
1.224 raeburn 423: },
1.69 raeburn 424: 'usermodification' =>
1.33 raeburn 425: { text => 'User modification',
1.67 raeburn 426: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 427: header => [{col1 => 'Target user has role',
1.227 bisitz 428: col2 => 'User information updatable in author context'},
1.33 raeburn 429: {col1 => 'Target user has role',
1.227 bisitz 430: col2 => 'User information updatable in course context'}],
1.230 raeburn 431: print => \&print_usermodification,
432: modify => \&modify_usermodification,
1.33 raeburn 433: },
1.69 raeburn 434: 'scantron' =>
1.346 raeburn 435: { text => 'Bubblesheet format',
1.67 raeburn 436: help => 'Domain_Configuration_Scantron_Format',
1.346 raeburn 437: header => [ {col1 => 'Bubblesheet format file',
438: col2 => ''},
439: {col1 => 'Bubblesheet data upload formats',
440: col2 => 'Settings'}],
1.230 raeburn 441: print => \&print_scantron,
442: modify => \&modify_scantron,
1.46 raeburn 443: },
1.86 raeburn 444: 'requestcourses' =>
445: {text => 'Request creation of courses',
446: help => 'Domain_Configuration_Request_Courses',
447: header => [{col1 => 'User affiliation',
1.102 raeburn 448: col2 => 'Availability/Processing of requests',},
449: {col1 => 'Setting',
1.216 raeburn 450: col2 => 'Value'},
451: {col1 => 'Available textbooks',
1.235 raeburn 452: col2 => ''},
1.242 raeburn 453: {col1 => 'Available templates',
454: col2 => ''},
1.235 raeburn 455: {col1 => 'Validation (not official courses)',
456: col2 => 'Value'},],
1.230 raeburn 457: print => \&print_quotas,
458: modify => \&modify_quotas,
1.86 raeburn 459: },
1.163 raeburn 460: 'requestauthor' =>
1.223 bisitz 461: {text => 'Request Authoring Space',
1.163 raeburn 462: help => 'Domain_Configuration_Request_Author',
463: header => [{col1 => 'User affiliation',
464: col2 => 'Availability/Processing of requests',},
465: {col1 => 'Setting',
466: col2 => 'Value'}],
1.230 raeburn 467: print => \&print_quotas,
468: modify => \&modify_quotas,
1.163 raeburn 469: },
1.69 raeburn 470: 'coursecategories' =>
1.120 raeburn 471: { text => 'Cataloging of courses/communities',
1.67 raeburn 472: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 473: header => [{col1 => 'Catalog type/availability',
474: col2 => '',},
475: {col1 => 'Category settings for standard catalog',
1.57 raeburn 476: col2 => '',},
477: {col1 => 'Categories',
478: col2 => '',
479: }],
1.230 raeburn 480: print => \&print_coursecategories,
481: modify => \&modify_coursecategories,
1.69 raeburn 482: },
483: 'serverstatuses' =>
1.77 raeburn 484: {text => 'Access to server status pages',
1.69 raeburn 485: help => 'Domain_Configuration_Server_Status',
486: header => [{col1 => 'Status Page',
487: col2 => 'Other named users',
488: col3 => 'Specific IPs',
489: }],
1.230 raeburn 490: print => \&print_serverstatuses,
491: modify => \&modify_serverstatuses,
1.69 raeburn 492: },
1.118 jms 493: 'helpsettings' =>
1.282 raeburn 494: {text => 'Support settings',
1.118 jms 495: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 496: header => [{col1 => 'Help Page Settings (logged-in users)',
497: col2 => 'Value'},
498: {col1 => 'Helpdesk Roles',
499: col2 => 'Settings'},],
1.230 raeburn 500: print => \&print_helpsettings,
501: modify => \&modify_helpsettings,
1.118 jms 502: },
1.121 raeburn 503: 'coursedefaults' =>
504: {text => 'Course/Community defaults',
505: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 506: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
507: col2 => 'Value',},
508: {col1 => 'Defaults which can be overridden for each course by a DC',
509: col2 => 'Value',},],
1.230 raeburn 510: print => \&print_coursedefaults,
511: modify => \&modify_coursedefaults,
1.121 raeburn 512: },
1.231 raeburn 513: 'selfenrollment' =>
514: {text => 'Self-enrollment in Course/Community',
515: help => 'Domain_Configuration_Selfenrollment',
516: header => [{col1 => 'Configuration Rights',
517: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
518: {col1 => 'Defaults',
519: col2 => 'Value'},
520: {col1 => 'Self-enrollment validation (optional)',
521: col2 => 'Value'},],
522: print => \&print_selfenrollment,
523: modify => \&modify_selfenrollment,
524: },
1.120 raeburn 525: 'privacy' =>
1.357 raeburn 526: {text => 'Availability of User Information',
1.120 raeburn 527: help => 'Domain_Configuration_User_Privacy',
1.357 raeburn 528: header => [{col1 => 'Role assigned in different domain',
529: col2 => 'Approval options'},
530: {col1 => 'Role assigned in different domain to user of type',
531: col2 => 'User information available in that domain'},
532: {col1 => "Role assigned in user's domain",
533: col2 => 'Information viewable by privileged user'},
534: {col1 => "Role assigned in user's domain",
535: col2 => 'Information viewable by unprivileged user'}],
1.230 raeburn 536: print => \&print_privacy,
537: modify => \&modify_privacy,
1.120 raeburn 538: },
1.141 raeburn 539: 'usersessions' =>
1.145 raeburn 540: {text => 'User session hosting/offloading',
1.137 raeburn 541: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 542: header => [{col1 => 'Domain server',
543: col2 => 'Servers to offload sessions to when busy'},
544: {col1 => 'Hosting of users from other domains',
1.137 raeburn 545: col2 => 'Rules'},
546: {col1 => "Hosting domain's own users elsewhere",
547: col2 => 'Rules'}],
1.230 raeburn 548: print => \&print_usersessions,
549: modify => \&modify_usersessions,
1.137 raeburn 550: },
1.279 raeburn 551: 'loadbalancing' =>
1.185 raeburn 552: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 553: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 554: header => [{col1 => 'Balancers',
1.150 raeburn 555: col2 => 'Default destinations',
1.183 bisitz 556: col3 => 'User affiliation',
1.150 raeburn 557: col4 => 'Overrides'},
558: ],
1.230 raeburn 559: print => \&print_loadbalancing,
560: modify => \&modify_loadbalancing,
1.150 raeburn 561: },
1.279 raeburn 562: 'ltitools' =>
1.267 raeburn 563: {text => 'External Tools (LTI)',
1.296 raeburn 564: help => 'Domain_Configuration_LTI_Tools',
1.267 raeburn 565: header => [{col1 => 'Setting',
566: col2 => 'Value',}],
567: print => \&print_ltitools,
568: modify => \&modify_ltitools,
569: },
1.372 raeburn 570: 'proctoring' =>
571: {text => 'Remote Proctoring Integration',
572: help => 'Domain_Configuration_Proctoring',
573: header => [{col1 => 'Name',
574: col2 => 'Configuration'}],
575: print => \&print_proctoring,
576: modify => \&modify_proctoring,
577: },
1.279 raeburn 578: 'ssl' =>
1.275 raeburn 579: {text => 'LON-CAPA Network (SSL)',
580: help => 'Domain_Configuration_Network_SSL',
581: header => [{col1 => 'Server',
582: col2 => 'Certificate Status'},
583: {col1 => 'Connections to other servers',
584: col2 => 'Rules'},
1.293 raeburn 585: {col1 => 'Connections from other servers',
586: col2 => 'Rules'},
1.275 raeburn 587: {col1 => "Replicating domain's published content",
588: col2 => 'Rules'}],
589: print => \&print_ssl,
590: modify => \&modify_ssl,
591: },
1.279 raeburn 592: 'trust' =>
593: {text => 'Trust Settings',
594: help => 'Domain_Configuration_Trust',
595: header => [{col1 => "Access to this domain's content by others",
596: col2 => 'Rules'},
597: {col1 => "Access to other domain's content by this domain",
598: col2 => 'Rules'},
599: {col1 => "Enrollment in this domain's courses by others",
600: col2 => 'Rules',},
601: {col1 => "Co-author roles in this domain for others",
602: col2 => 'Rules',},
603: {col1 => "Co-author roles for this domain's users elsewhere",
604: col2 => 'Rules',},
605: {col1 => "Domain roles in this domain assignable to others",
606: col2 => 'Rules'},
607: {col1 => "Course catalog for this domain displayed elsewhere",
608: col2 => 'Rules'},
609: {col1 => "Requests for creation of courses in this domain by others",
610: col2 => 'Rules'},
611: {col1 => "Users in other domains can send messages to this domain",
612: col2 => 'Rules'},],
613: print => \&print_trust,
614: modify => \&modify_trust,
615: },
1.320 raeburn 616: 'lti' =>
617: {text => 'LTI Provider',
618: help => 'Domain_Configuration_LTI_Provider',
619: header => [{col1 => 'Setting',
620: col2 => 'Value',}],
621: print => \&print_lti,
622: modify => \&modify_lti,
623: },
1.3 raeburn 624: );
1.110 raeburn 625: if (keys(%servers) > 1) {
626: $prefs{'login'} = { text => 'Log-in page options',
627: help => 'Domain_Configuration_Login_Page',
628: header => [{col1 => 'Log-in Service',
629: col2 => 'Server Setting',},
630: {col1 => 'Log-in Page Items',
1.168 raeburn 631: col2 => ''},
632: {col1 => 'Log-in Help',
1.256 raeburn 633: col2 => 'Value'},
634: {col1 => 'Custom HTML in document head',
1.168 raeburn 635: col2 => 'Value'}],
1.230 raeburn 636: print => \&print_login,
637: modify => \&modify_login,
1.110 raeburn 638: };
639: }
1.174 foxr 640:
1.6 raeburn 641: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 642: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 643: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 644: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 645: text=>"Settings to display/modify"});
1.9 raeburn 646: my $confname = $dom.'-domainconfig';
1.174 foxr 647:
1.3 raeburn 648: if ($phase eq 'process') {
1.212 raeburn 649: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
650: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 651: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 652: $r->rflush();
1.212 raeburn 653: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 654: }
1.30 raeburn 655: } elsif ($phase eq 'display') {
1.192 raeburn 656: my $js = &recaptcha_js().
1.236 raeburn 657: &toggle_display_js();
1.171 raeburn 658: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 659: my ($othertitle,$usertypes,$types) =
660: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 661: $js .= &lonbalance_targets_js($dom,$types,\%servers,
662: $domconfig{'loadbalancing'}).
1.170 raeburn 663: &new_spares_js().
664: &common_domprefs_js().
665: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 666: }
1.216 raeburn 667: if (grep(/^requestcourses$/,@actions)) {
668: my $javascript_validations;
669: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
670: $js .= <<END;
671: <script type="text/javascript">
672: $javascript_validations
673: </script>
674: $coursebrowserjs
675: END
676: }
1.305 raeburn 677: if (grep(/^selfcreation$/,@actions)) {
678: $js .= &selfcreate_javascript();
679: }
1.286 raeburn 680: if (grep(/^contacts$/,@actions)) {
681: $js .= &contacts_javascript();
682: }
1.346 raeburn 683: if (grep(/^scantron$/,@actions)) {
684: $js .= &scantron_javascript();
685: }
1.150 raeburn 686: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 687: } else {
1.180 raeburn 688: # check if domconfig user exists for the domain.
689: my $servadm = $r->dir_config('lonAdmEMail');
690: my ($configuserok,$author_ok,$switchserver) =
691: &config_check($dom,$confname,$servadm);
692: unless ($configuserok eq 'ok') {
1.181 raeburn 693: &Apache::lonconfigsettings::print_header($r,$phase,$context);
694: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 695: $confname).
1.181 raeburn 696: '<br />'
697: );
1.180 raeburn 698: if ($switchserver) {
1.181 raeburn 699: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
700: '<br />'.
701: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
702: '<br />'.
703: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
704: '<br />'.
705: &mt('To do that now, use the following link: [_1]',$switchserver)
706: );
707: } else {
708: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
709: '<br />'.
710: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
711: );
1.180 raeburn 712: }
713: $r->print(&Apache::loncommon::end_page());
714: return OK;
715: }
1.21 raeburn 716: if (keys(%domconfig) == 0) {
717: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 718: my @ids=&Apache::lonnet::current_machine_ids();
719: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 720: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 721: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 722: my $custom_img_count = 0;
723: foreach my $img (@loginimages) {
724: if ($designhash{$dom.'.login.'.$img} ne '') {
725: $custom_img_count ++;
726: }
727: }
728: foreach my $role (@roles) {
729: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
730: $custom_img_count ++;
731: }
732: }
733: if ($custom_img_count > 0) {
1.94 raeburn 734: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 735: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 736: $r->print(
737: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
738: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
739: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
740: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
741: if ($switch_server) {
1.30 raeburn 742: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 743: }
1.91 raeburn 744: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 745: return OK;
746: }
747: }
748: }
1.91 raeburn 749: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 750: }
751: return OK;
752: }
753:
754: sub process_changes {
1.205 raeburn 755: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 756: my %domconfig;
757: if (ref($values) eq 'HASH') {
758: %domconfig = %{$values};
759: }
1.3 raeburn 760: my $output;
761: if ($action eq 'login') {
1.205 raeburn 762: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 763: } elsif ($action eq 'rolecolors') {
1.9 raeburn 764: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 765: $lastactref,%domconfig);
1.3 raeburn 766: } elsif ($action eq 'quotas') {
1.216 raeburn 767: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 768: } elsif ($action eq 'autoenroll') {
1.205 raeburn 769: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 770: } elsif ($action eq 'autoupdate') {
771: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 772: } elsif ($action eq 'autocreate') {
773: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 774: } elsif ($action eq 'directorysrch') {
1.295 raeburn 775: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 776: } elsif ($action eq 'usercreation') {
1.28 raeburn 777: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 778: } elsif ($action eq 'selfcreation') {
1.305 raeburn 779: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 780: } elsif ($action eq 'usermodification') {
781: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 782: } elsif ($action eq 'contacts') {
1.205 raeburn 783: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 784: } elsif ($action eq 'defaults') {
1.212 raeburn 785: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 786: } elsif ($action eq 'scantron') {
1.205 raeburn 787: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 788: } elsif ($action eq 'coursecategories') {
1.239 raeburn 789: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 790: } elsif ($action eq 'serverstatuses') {
791: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 792: } elsif ($action eq 'requestcourses') {
1.216 raeburn 793: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 794: } elsif ($action eq 'requestauthor') {
1.216 raeburn 795: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 796: } elsif ($action eq 'helpsettings') {
1.285 raeburn 797: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 798: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 799: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 800: } elsif ($action eq 'selfenrollment') {
801: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 802: } elsif ($action eq 'usersessions') {
1.212 raeburn 803: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 804: } elsif ($action eq 'loadbalancing') {
805: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 806: } elsif ($action eq 'ltitools') {
807: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.372 raeburn 808: } elsif ($action eq 'proctoring') {
809: $output = &modify_proctoring($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 810: } elsif ($action eq 'ssl') {
811: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 812: } elsif ($action eq 'trust') {
813: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 814: } elsif ($action eq 'lti') {
815: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.357 raeburn 816: } elsif ($action eq 'privacy') {
817: $output = &modify_privacy($dom,%domconfig);
1.354 raeburn 818: } elsif ($action eq 'passwords') {
819: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.373 ! raeburn 820: } elsif ($action eq 'wafproxy') {
! 821: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
1.3 raeburn 822: }
823: return $output;
824: }
825:
826: sub print_config_box {
1.9 raeburn 827: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 828: my $rowtotal = 0;
1.49 raeburn 829: my $output;
830: if ($action eq 'coursecategories') {
831: $output = &coursecategories_javascript($settings);
1.236 raeburn 832: } elsif ($action eq 'defaults') {
833: $output = &defaults_javascript($settings);
1.354 raeburn 834: } elsif ($action eq 'passwords') {
835: $output = &passwords_javascript();
1.282 raeburn 836: } elsif ($action eq 'helpsettings') {
837: my (%privs,%levelscurrent);
838: my %full=();
839: my %levels=(
840: course => {},
841: domain => {},
842: system => {},
843: );
844: my $context = 'domain';
845: my $crstype = 'Course';
846: my $formname = 'display';
847: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
848: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
849: $output =
850: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
851: \@templateroles);
1.334 raeburn 852: } elsif ($action eq 'ltitools') {
853: $output .= <itools_javascript($settings);
854: } elsif ($action eq 'lti') {
855: $output .= <i_javascript($settings);
1.372 raeburn 856: } elsif ($action eq 'proctoring') {
857: $output .= &proctoring_javascript($settings);
1.91 raeburn 858: }
1.236 raeburn 859: $output .=
1.30 raeburn 860: '<table class="LC_nested_outer">
1.3 raeburn 861: <tr>
1.306 raeburn 862: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 863: &mt($item->{text}).' '.
864: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
865: '</tr>';
1.30 raeburn 866: $rowtotal ++;
1.110 raeburn 867: my $numheaders = 1;
868: if (ref($item->{'header'}) eq 'ARRAY') {
869: $numheaders = scalar(@{$item->{'header'}});
870: }
871: if ($numheaders > 1) {
1.64 raeburn 872: my $colspan = '';
1.145 raeburn 873: my $rightcolspan = '';
1.369 raeburn 874: my $leftnobr = '';
1.238 raeburn 875: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 876: ($action eq 'directorysrch') ||
1.256 raeburn 877: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 878: $colspan = ' colspan="2"';
879: }
1.145 raeburn 880: if ($action eq 'usersessions') {
881: $rightcolspan = ' colspan="3"';
882: }
1.369 raeburn 883: if ($action eq 'passwords') {
884: $leftnobr = ' LC_nobreak';
885: }
1.30 raeburn 886: $output .= '
1.3 raeburn 887: <tr>
888: <td>
889: <table class="LC_nested">
890: <tr class="LC_info_row">
1.369 raeburn 891: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 892: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 893: </tr>';
1.69 raeburn 894: $rowtotal ++;
1.230 raeburn 895: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 896: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 897: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 898: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.373 ! raeburn 899: ($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'wafproxy')) {
1.230 raeburn 900: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354 raeburn 901: } elsif ($action eq 'passwords') {
902: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 903: } elsif ($action eq 'coursecategories') {
1.230 raeburn 904: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346 raeburn 905: } elsif ($action eq 'scantron') {
906: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 907: } elsif ($action eq 'login') {
1.256 raeburn 908: if ($numheaders == 4) {
1.168 raeburn 909: $colspan = ' colspan="2"';
910: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
911: } else {
912: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
913: }
1.230 raeburn 914: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 915: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 916: } elsif ($action eq 'rolecolors') {
1.30 raeburn 917: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 918: }
1.30 raeburn 919: $output .= '
1.6 raeburn 920: </table>
921: </td>
922: </tr>
923: <tr>
924: <td>
925: <table class="LC_nested">
926: <tr class="LC_info_row">
1.230 raeburn 927: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 928: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 929: </tr>';
930: $rowtotal ++;
1.230 raeburn 931: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
932: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 933: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.357 raeburn 934: ($action eq 'trust') || ($action eq 'contacts') ||
935: ($action eq 'privacy') || ($action eq 'passwords')) {
1.238 raeburn 936: if ($action eq 'coursecategories') {
937: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
938: $colspan = ' colspan="2"';
1.279 raeburn 939: } elsif ($action eq 'trust') {
940: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354 raeburn 941: } elsif ($action eq 'passwords') {
942: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.238 raeburn 943: } else {
944: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
945: }
1.279 raeburn 946: if ($action eq 'trust') {
947: $output .= '
948: </table>
949: </td>
950: </tr>';
951: my @trusthdrs = qw(2 3 4 5 6 7);
952: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
953: for (my $i=0; $i<@trusthdrs; $i++) {
954: $output .= '
955: <tr>
956: <td>
957: <table class="LC_nested">
958: <tr class="LC_info_row">
959: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
960: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
961: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
962: </table>
963: </td>
964: </tr>';
965: }
966: $output .= '
967: <tr>
968: <td>
969: <table class="LC_nested">
970: <tr class="LC_info_row">
971: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
972: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
973: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
974: } else {
975: $output .= '
1.63 raeburn 976: </table>
977: </td>
978: </tr>
979: <tr>
980: <td>
981: <table class="LC_nested">
982: <tr class="LC_info_row">
983: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 984: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 985: </tr>'."\n";
1.279 raeburn 986: if ($action eq 'coursecategories') {
987: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.357 raeburn 988: } elsif (($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'passwords')) {
1.354 raeburn 989: if ($action eq 'passwords') {
990: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
991: } else {
992: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
993: }
994: $output .= '
1.340 raeburn 995: </tr>
996: </table>
997: </td>
998: </tr>
999: <tr>
1000: <td>
1001: <table class="LC_nested">
1002: <tr class="LC_info_row">
1.369 raeburn 1003: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.354 raeburn 1004: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
1005: if ($action eq 'passwords') {
1006: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
1007: } else {
1008: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1009: }
1010: $output .= '
1.340 raeburn 1011: </table>
1012: </td>
1013: </tr>
1014: <tr>';
1.279 raeburn 1015: } else {
1016: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1017: }
1.238 raeburn 1018: }
1.63 raeburn 1019: $rowtotal ++;
1.236 raeburn 1020: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282 raeburn 1021: ($action eq 'defaults') || ($action eq 'directorysrch') ||
1.373 ! raeburn 1022: ($action eq 'helpsettings') || ($action eq 'wafproxy')) {
1.230 raeburn 1023: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346 raeburn 1024: } elsif ($action eq 'scantron') {
1025: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293 raeburn 1026: } elsif ($action eq 'ssl') {
1027: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
1028: </table>
1029: </td>
1030: </tr>
1031: <tr>
1032: <td>
1033: <table class="LC_nested">
1034: <tr class="LC_info_row">
1035: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1036: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1037: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
1038: </table>
1039: </td>
1040: </tr>
1041: <tr>
1042: <td>
1043: <table class="LC_nested">
1044: <tr class="LC_info_row">
1045: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1046: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
1047: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 1048: } elsif ($action eq 'login') {
1.256 raeburn 1049: if ($numheaders == 4) {
1.168 raeburn 1050: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
1051: </table>
1052: </td>
1053: </tr>
1054: <tr>
1055: <td>
1056: <table class="LC_nested">
1057: <tr class="LC_info_row">
1058: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 1059: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 1060: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1061: $rowtotal ++;
1062: } else {
1063: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1064: }
1.256 raeburn 1065: $output .= '
1066: </table>
1067: </td>
1068: </tr>
1069: <tr>
1070: <td>
1071: <table class="LC_nested">
1072: <tr class="LC_info_row">';
1073: if ($numheaders == 4) {
1074: $output .= '
1075: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1076: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1077: </tr>';
1078: } else {
1079: $output .= '
1080: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1081: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1082: </tr>';
1083: }
1084: $rowtotal ++;
1085: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1086: } elsif ($action eq 'requestcourses') {
1.247 raeburn 1087: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1088: $rowtotal ++;
1089: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 1090: </table>
1091: </td>
1092: </tr>
1093: <tr>
1094: <td>
1095: <table class="LC_nested">
1096: <tr class="LC_info_row">
1097: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1098: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 1099: &textbookcourses_javascript($settings).
1100: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1101: </table>
1102: </td>
1103: </tr>
1104: <tr>
1105: <td>
1106: <table class="LC_nested">
1107: <tr class="LC_info_row">
1108: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1109: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1110: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 1111: </table>
1112: </td>
1113: </tr>
1114: <tr>
1115: <td>
1116: <table class="LC_nested">
1117: <tr class="LC_info_row">
1.306 raeburn 1118: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1119: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1120: </tr>'.
1121: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1122: } elsif ($action eq 'requestauthor') {
1123: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1124: $rowtotal ++;
1.122 jms 1125: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1126: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1127: </table>
1128: </td>
1129: </tr>
1130: <tr>
1131: <td>
1132: <table class="LC_nested">
1133: <tr class="LC_info_row">
1.306 raeburn 1134: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1135: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1136: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1137: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1138: </tr>'.
1.30 raeburn 1139: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1140: </table>
1141: </td>
1142: </tr>
1143: <tr>
1144: <td>
1145: <table class="LC_nested">
1146: <tr class="LC_info_row">
1.59 bisitz 1147: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1148: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1149: </tr>'.
1.30 raeburn 1150: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1151: $rowtotal += 2;
1.6 raeburn 1152: }
1.3 raeburn 1153: } else {
1.30 raeburn 1154: $output .= '
1.3 raeburn 1155: <tr>
1156: <td>
1157: <table class="LC_nested">
1.30 raeburn 1158: <tr class="LC_info_row">';
1.277 raeburn 1159: if ($action eq 'login') {
1.30 raeburn 1160: $output .= '
1.59 bisitz 1161: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1162: } elsif ($action eq 'serverstatuses') {
1163: $output .= '
1.306 raeburn 1164: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1165: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1166:
1.6 raeburn 1167: } else {
1.30 raeburn 1168: $output .= '
1.306 raeburn 1169: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1170: }
1.72 raeburn 1171: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1172: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1173: &mt($item->{'header'}->[0]->{'col2'});
1174: if ($action eq 'serverstatuses') {
1175: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1176: }
1.69 raeburn 1177: } else {
1.306 raeburn 1178: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1179: &mt($item->{'header'}->[0]->{'col2'});
1180: }
1181: $output .= '</td>';
1182: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1183: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1184: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1185: &mt($item->{'header'}->[0]->{'col3'});
1186: } else {
1.306 raeburn 1187: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1188: &mt($item->{'header'}->[0]->{'col3'});
1189: }
1.69 raeburn 1190: if ($action eq 'serverstatuses') {
1191: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1192: }
1193: $output .= '</td>';
1.6 raeburn 1194: }
1.150 raeburn 1195: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1196: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1197: &mt($item->{'header'}->[0]->{'col4'});
1198: }
1.69 raeburn 1199: $output .= '</tr>';
1.48 raeburn 1200: $rowtotal ++;
1.168 raeburn 1201: if ($action eq 'quotas') {
1.86 raeburn 1202: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1203: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1204: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.372 raeburn 1205: ($action eq 'ltitools') || ($action eq 'lti') ||
1206: ($action eq 'proctoring')) {
1.230 raeburn 1207: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1208: }
1.3 raeburn 1209: }
1.30 raeburn 1210: $output .= '
1.3 raeburn 1211: </table>
1212: </td>
1213: </tr>
1.30 raeburn 1214: </table><br />';
1215: return ($output,$rowtotal);
1.1 raeburn 1216: }
1217:
1.3 raeburn 1218: sub print_login {
1.168 raeburn 1219: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 1220: my ($css_class,$datatable);
1.6 raeburn 1221: my %choices = &login_choices();
1.110 raeburn 1222:
1.168 raeburn 1223: if ($caller eq 'service') {
1.149 raeburn 1224: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1225: my $choice = $choices{'disallowlogin'};
1226: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1227: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1228: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1229: '<th>'.$choices{'server'}.'</th>'.
1230: '<th>'.$choices{'serverpath'}.'</th>'.
1231: '<th>'.$choices{'custompath'}.'</th>'.
1232: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1233: my %disallowed;
1234: if (ref($settings) eq 'HASH') {
1235: if (ref($settings->{'loginvia'}) eq 'HASH') {
1236: %disallowed = %{$settings->{'loginvia'}};
1237: }
1238: }
1239: foreach my $lonhost (sort(keys(%servers))) {
1240: my $direct = 'selected="selected"';
1.128 raeburn 1241: if (ref($disallowed{$lonhost}) eq 'HASH') {
1242: if ($disallowed{$lonhost}{'server'} ne '') {
1243: $direct = '';
1244: }
1.110 raeburn 1245: }
1.115 raeburn 1246: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1247: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1248: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1249: '</option>';
1.184 raeburn 1250: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1251: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1252: my $selected = '';
1.128 raeburn 1253: if (ref($disallowed{$lonhost}) eq 'HASH') {
1254: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1255: $selected = 'selected="selected"';
1256: }
1.110 raeburn 1257: }
1258: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1259: $servers{$hostid}.'</option>';
1260: }
1.128 raeburn 1261: $datatable .= '</select></td>'.
1262: '<td><select name="'.$lonhost.'_serverpath">';
1263: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1264: my $pathname = $path;
1265: if ($path eq 'custom') {
1266: $pathname = &mt('Custom Path').' ->';
1267: }
1268: my $selected = '';
1269: if (ref($disallowed{$lonhost}) eq 'HASH') {
1270: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1271: $selected = 'selected="selected"';
1272: }
1273: } elsif ($path eq '') {
1274: $selected = 'selected="selected"';
1275: }
1276: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1277: }
1278: $datatable .= '</select></td>';
1279: my ($custom,$exempt);
1280: if (ref($disallowed{$lonhost}) eq 'HASH') {
1281: $custom = $disallowed{$lonhost}{'custompath'};
1282: $exempt = $disallowed{$lonhost}{'exempt'};
1283: }
1284: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1285: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1286: '</tr>';
1.110 raeburn 1287: }
1288: $datatable .= '</table></td></tr>';
1289: return $datatable;
1.168 raeburn 1290: } elsif ($caller eq 'page') {
1291: my %defaultchecked = (
1292: 'coursecatalog' => 'on',
1.188 raeburn 1293: 'helpdesk' => 'on',
1.168 raeburn 1294: 'adminmail' => 'off',
1295: 'newuser' => 'off',
1296: );
1.188 raeburn 1297: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1298: my (%checkedon,%checkedoff);
1.42 raeburn 1299: foreach my $item (@toggles) {
1.168 raeburn 1300: if ($defaultchecked{$item} eq 'on') {
1301: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1302: $checkedoff{$item} = ' ';
1.168 raeburn 1303: } elsif ($defaultchecked{$item} eq 'off') {
1304: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1305: $checkedon{$item} = ' ';
1306: }
1.1 raeburn 1307: }
1.168 raeburn 1308: my @images = ('img','logo','domlogo','login');
1309: my @logintext = ('textcol','bgcol');
1310: my @bgs = ('pgbg','mainbg','sidebg');
1311: my @links = ('link','alink','vlink');
1312: my %designhash = &Apache::loncommon::get_domainconf($dom);
1313: my %defaultdesign = %Apache::loncommon::defaultdesign;
1314: my (%is_custom,%designs);
1315: my %defaults = (
1316: font => $defaultdesign{'login.font'},
1317: );
1.6 raeburn 1318: foreach my $item (@images) {
1.168 raeburn 1319: $defaults{$item} = $defaultdesign{'login.'.$item};
1320: $defaults{'showlogo'}{$item} = 1;
1321: }
1322: foreach my $item (@bgs) {
1323: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1324: }
1.41 raeburn 1325: foreach my $item (@logintext) {
1.168 raeburn 1326: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1327: }
1.168 raeburn 1328: foreach my $item (@links) {
1329: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1330: }
1.168 raeburn 1331: if (ref($settings) eq 'HASH') {
1332: foreach my $item (@toggles) {
1333: if ($settings->{$item} eq '1') {
1334: $checkedon{$item} = ' checked="checked" ';
1335: $checkedoff{$item} = ' ';
1336: } elsif ($settings->{$item} eq '0') {
1337: $checkedoff{$item} = ' checked="checked" ';
1338: $checkedon{$item} = ' ';
1339: }
1340: }
1341: foreach my $item (@images) {
1342: if (defined($settings->{$item})) {
1343: $designs{$item} = $settings->{$item};
1344: $is_custom{$item} = 1;
1345: }
1346: if (defined($settings->{'showlogo'}{$item})) {
1347: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1348: }
1349: }
1350: foreach my $item (@logintext) {
1351: if ($settings->{$item} ne '') {
1352: $designs{'logintext'}{$item} = $settings->{$item};
1353: $is_custom{$item} = 1;
1354: }
1355: }
1356: if ($settings->{'font'} ne '') {
1357: $designs{'font'} = $settings->{'font'};
1358: $is_custom{'font'} = 1;
1359: }
1360: foreach my $item (@bgs) {
1361: if ($settings->{$item} ne '') {
1362: $designs{'bgs'}{$item} = $settings->{$item};
1363: $is_custom{$item} = 1;
1364: }
1365: }
1366: foreach my $item (@links) {
1367: if ($settings->{$item} ne '') {
1368: $designs{'links'}{$item} = $settings->{$item};
1369: $is_custom{$item} = 1;
1370: }
1371: }
1372: } else {
1373: if ($designhash{$dom.'.login.font'} ne '') {
1374: $designs{'font'} = $designhash{$dom.'.login.font'};
1375: $is_custom{'font'} = 1;
1376: }
1377: foreach my $item (@images) {
1378: if ($designhash{$dom.'.login.'.$item} ne '') {
1379: $designs{$item} = $designhash{$dom.'.login.'.$item};
1380: $is_custom{$item} = 1;
1381: }
1382: }
1383: foreach my $item (@bgs) {
1384: if ($designhash{$dom.'.login.'.$item} ne '') {
1385: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1386: $is_custom{$item} = 1;
1387: }
1.6 raeburn 1388: }
1.168 raeburn 1389: foreach my $item (@links) {
1390: if ($designhash{$dom.'.login.'.$item} ne '') {
1391: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1392: $is_custom{$item} = 1;
1393: }
1.6 raeburn 1394: }
1395: }
1.168 raeburn 1396: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1397: logo => 'Institution Logo',
1398: domlogo => 'Domain Logo',
1399: login => 'Login box');
1400: my $itemcount = 1;
1401: foreach my $item (@toggles) {
1402: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1403: $datatable .=
1404: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1405: '</td><td>'.
1406: '<span class="LC_nobreak"><label><input type="radio" name="'.
1407: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1408: '</label> <label><input type="radio" name="'.$item.'"'.
1409: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1410: '</tr>';
1411: $itemcount ++;
1.6 raeburn 1412: }
1.168 raeburn 1413: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1414: $datatable .= '</tr></table></td></tr>';
1415: } elsif ($caller eq 'help') {
1416: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1417: my $switchserver = &check_switchserver($dom,$confname);
1418: my $itemcount = 1;
1419: $defaulturl = '/adm/loginproblems.html';
1420: $defaulttype = 'default';
1421: %lt = &Apache::lonlocal::texthash (
1422: del => 'Delete?',
1423: rep => 'Replace:',
1424: upl => 'Upload:',
1425: default => 'Default',
1426: custom => 'Custom',
1427: );
1428: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1429: my @currlangs;
1430: if (ref($settings) eq 'HASH') {
1431: if (ref($settings->{'helpurl'}) eq 'HASH') {
1432: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1433: next if ($settings->{'helpurl'}{$key} eq '');
1434: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1435: $type{$key} = 'custom';
1436: unless ($key eq 'nolang') {
1437: push(@currlangs,$key);
1438: }
1439: }
1440: } elsif ($settings->{'helpurl'} ne '') {
1441: $type{'nolang'} = 'custom';
1442: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1443: }
1444: }
1.168 raeburn 1445: foreach my $lang ('nolang',sort(@currlangs)) {
1446: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1447: $datatable .= '<tr'.$css_class.'>';
1448: if ($url{$lang} eq '') {
1449: $url{$lang} = $defaulturl;
1450: }
1451: if ($type{$lang} eq '') {
1452: $type{$lang} = $defaulttype;
1453: }
1454: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1455: if ($lang eq 'nolang') {
1456: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1457: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1458: } else {
1459: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1460: $langchoices{$lang},
1461: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1462: }
1463: $datatable .= '</span></td>'."\n".
1464: '<td class="LC_left_item">';
1465: if ($type{$lang} eq 'custom') {
1466: $datatable .= '<span class="LC_nobreak"><label>'.
1467: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1468: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1469: } else {
1470: $datatable .= $lt{'upl'};
1471: }
1472: $datatable .='<br />';
1473: if ($switchserver) {
1474: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1475: } else {
1476: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1477: }
1.168 raeburn 1478: $datatable .= '</td></tr>';
1479: $itemcount ++;
1.6 raeburn 1480: }
1.168 raeburn 1481: my @addlangs;
1482: foreach my $lang (sort(keys(%langchoices))) {
1483: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1484: push(@addlangs,$lang);
1485: }
1486: if (@addlangs > 0) {
1487: my %toadd;
1488: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1489: $toadd{''} = &mt('Select');
1490: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1491: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1492: &mt('Add log-in help page for a specific language:').' '.
1493: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1494: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1495: if ($switchserver) {
1496: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1497: } else {
1498: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1499: }
1.168 raeburn 1500: $datatable .= '</td></tr>';
1.169 raeburn 1501: $itemcount ++;
1.6 raeburn 1502: }
1.169 raeburn 1503: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1504: } elsif ($caller eq 'headtag') {
1505: my %domservers = &Apache::lonnet::get_servers($dom);
1506: my $choice = $choices{'headtag'};
1507: $css_class = ' class="LC_odd_row"';
1508: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1509: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1510: '<th>'.$choices{'current'}.'</th>'.
1511: '<th>'.$choices{'action'}.'</th>'.
1512: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1513: my (%currurls,%currexempt);
1514: if (ref($settings) eq 'HASH') {
1515: if (ref($settings->{'headtag'}) eq 'HASH') {
1516: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1517: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1518: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1519: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1520: }
1521: }
1522: }
1523: }
1524: my %lt = &Apache::lonlocal::texthash(
1525: del => 'Delete?',
1526: rep => 'Replace:',
1527: upl => 'Upload:',
1528: curr => 'View contents',
1529: none => 'None',
1530: );
1531: my $switchserver = &check_switchserver($dom,$confname);
1532: foreach my $lonhost (sort(keys(%domservers))) {
1533: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1534: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1535: if ($currurls{$lonhost}) {
1536: $datatable .= '<td class="LC_right_item"><a href="'.
1537: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1538: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1539: '">'.$lt{'curr'}.'</a></td>'.
1540: '<td><span class="LC_nobreak"><label>'.
1541: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1542: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1543: } else {
1544: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1545: }
1546: $datatable .='<br />';
1547: if ($switchserver) {
1548: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1549: } else {
1550: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1551: }
1.330 raeburn 1552: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1553: }
1554: $datatable .= '</table></td></tr>';
1.1 raeburn 1555: }
1.6 raeburn 1556: return $datatable;
1557: }
1558:
1559: sub login_choices {
1560: my %choices =
1561: &Apache::lonlocal::texthash (
1.116 bisitz 1562: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1563: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1564: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1565: disallowlogin => "Login page requests redirected",
1566: hostid => "Server",
1.128 raeburn 1567: server => "Redirect to:",
1568: serverpath => "Path",
1569: custompath => "Custom",
1570: exempt => "Exempt IP(s)",
1.110 raeburn 1571: directlogin => "No redirect",
1572: newuser => "Link to create a user account",
1573: img => "Header",
1574: logo => "Main Logo",
1575: domlogo => "Domain Logo",
1576: login => "Log-in Header",
1577: textcol => "Text color",
1578: bgcol => "Box color",
1579: bgs => "Background colors",
1580: links => "Link colors",
1581: font => "Font color",
1582: pgbg => "Header",
1583: mainbg => "Page",
1584: sidebg => "Login box",
1585: link => "Link",
1586: alink => "Active link",
1587: vlink => "Visited link",
1.256 raeburn 1588: headtag => "Custom markup",
1589: action => "Action",
1590: current => "Current",
1.6 raeburn 1591: );
1592: return %choices;
1593: }
1594:
1595: sub print_rolecolors {
1.30 raeburn 1596: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1597: my %choices = &color_font_choices();
1598: my @bgs = ('pgbg','tabbg','sidebg');
1599: my @links = ('link','alink','vlink');
1600: my @images = ('img');
1601: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1602: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1603: my %defaultdesign = %Apache::loncommon::defaultdesign;
1604: my (%is_custom,%designs);
1.200 raeburn 1605: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1606: if (ref($settings) eq 'HASH') {
1607: if (ref($settings->{$role}) eq 'HASH') {
1608: if ($settings->{$role}->{'img'} ne '') {
1609: $designs{'img'} = $settings->{$role}->{'img'};
1610: $is_custom{'img'} = 1;
1611: }
1612: if ($settings->{$role}->{'font'} ne '') {
1613: $designs{'font'} = $settings->{$role}->{'font'};
1614: $is_custom{'font'} = 1;
1615: }
1.97 tempelho 1616: if ($settings->{$role}->{'fontmenu'} ne '') {
1617: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1618: $is_custom{'fontmenu'} = 1;
1619: }
1.6 raeburn 1620: foreach my $item (@bgs) {
1621: if ($settings->{$role}->{$item} ne '') {
1622: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1623: $is_custom{$item} = 1;
1624: }
1625: }
1626: foreach my $item (@links) {
1627: if ($settings->{$role}->{$item} ne '') {
1628: $designs{'links'}{$item} = $settings->{$role}->{$item};
1629: $is_custom{$item} = 1;
1630: }
1631: }
1632: }
1633: } else {
1634: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1635: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1636: $is_custom{'img'} = 1;
1637: }
1.97 tempelho 1638: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1639: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1640: $is_custom{'fontmenu'} = 1;
1641: }
1.6 raeburn 1642: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1643: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1644: $is_custom{'font'} = 1;
1645: }
1646: foreach my $item (@bgs) {
1647: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1648: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1649: $is_custom{$item} = 1;
1650:
1651: }
1652: }
1653: foreach my $item (@links) {
1654: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1655: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1656: $is_custom{$item} = 1;
1657: }
1658: }
1659: }
1660: my $itemcount = 1;
1.30 raeburn 1661: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1662: $datatable .= '</tr></table></td></tr>';
1663: return $datatable;
1664: }
1665:
1.200 raeburn 1666: sub role_defaults {
1667: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1668: my %defaults;
1669: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1670: return %defaults;
1671: }
1672: my %defaultdesign = %Apache::loncommon::defaultdesign;
1673: if ($role eq 'login') {
1674: %defaults = (
1675: font => $defaultdesign{$role.'.font'},
1676: );
1677: if (ref($logintext) eq 'ARRAY') {
1678: foreach my $item (@{$logintext}) {
1679: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1680: }
1681: }
1682: foreach my $item (@{$images}) {
1683: $defaults{'showlogo'}{$item} = 1;
1684: }
1685: } else {
1686: %defaults = (
1687: img => $defaultdesign{$role.'.img'},
1688: font => $defaultdesign{$role.'.font'},
1689: fontmenu => $defaultdesign{$role.'.fontmenu'},
1690: );
1691: }
1692: foreach my $item (@{$bgs}) {
1693: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1694: }
1695: foreach my $item (@{$links}) {
1696: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1697: }
1698: foreach my $item (@{$images}) {
1699: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1700: }
1701: return %defaults;
1702: }
1703:
1.6 raeburn 1704: sub display_color_options {
1.9 raeburn 1705: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1706: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1707: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1708: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1709: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1710: '<td>'.$choices->{'font'}.'</td>';
1711: if (!$is_custom->{'font'}) {
1.329 raeburn 1712: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1713: } else {
1714: $datatable .= '<td> </td>';
1715: }
1.174 foxr 1716: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1717:
1.8 raeburn 1718: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1719: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1720: ' value="'.$current_color.'" /> '.
1.329 raeburn 1721: ' </span></td></tr>';
1.107 raeburn 1722: unless ($role eq 'login') {
1723: $datatable .= '<tr'.$css_class.'>'.
1724: '<td>'.$choices->{'fontmenu'}.'</td>';
1725: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 1726: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1727: } else {
1728: $datatable .= '<td> </td>';
1729: }
1.202 raeburn 1730: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1731: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1732: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1733: '<input class="colorchooser" type="text" size="10" name="'
1734: .$role.'_fontmenu"'.
1735: ' value="'.$current_color.'" /> '.
1.329 raeburn 1736: ' </span></td></tr>';
1.97 tempelho 1737: }
1.9 raeburn 1738: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1739: foreach my $img (@{$images}) {
1.18 albertel 1740: $itemcount ++;
1.6 raeburn 1741: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1742: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1743: '<td>'.$choices->{$img};
1.41 raeburn 1744: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1745: if ($role eq 'login') {
1746: if ($img eq 'login') {
1747: $login_hdr_pick =
1.135 bisitz 1748: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1749: $logincolors =
1750: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1751: $designs,$defaults);
1.70 raeburn 1752: } elsif ($img ne 'domlogo') {
1753: $datatable.= &logo_display_options($img,$defaults,$designs);
1754: }
1755: }
1756: $datatable .= '</td>';
1.6 raeburn 1757: if ($designs->{$img} ne '') {
1758: $imgfile = $designs->{$img};
1.18 albertel 1759: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1760: } else {
1761: $imgfile = $defaults->{$img};
1762: }
1763: if ($imgfile) {
1.9 raeburn 1764: my ($showfile,$fullsize);
1765: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1766: my $urldir = $1;
1767: my $filename = $2;
1768: my @info = &Apache::lonnet::stat_file($designs->{$img});
1769: if (@info) {
1770: my $thumbfile = 'tn-'.$filename;
1771: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1772: if (@thumb) {
1773: $showfile = $urldir.'/'.$thumbfile;
1774: } else {
1775: $showfile = $imgfile;
1776: }
1777: } else {
1778: $showfile = '';
1779: }
1780: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1781: $showfile = $imgfile;
1.6 raeburn 1782: my $imgdir = $1;
1783: my $filename = $2;
1.159 raeburn 1784: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1785: $showfile = "/$imgdir/tn-".$filename;
1786: } else {
1.159 raeburn 1787: my $input = $londocroot.$imgfile;
1788: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1789: if (!-e $output) {
1.9 raeburn 1790: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1791: my ($fullwidth,$fullheight) = &check_dimensions($input);
1792: if ($fullwidth ne '' && $fullheight ne '') {
1793: if ($fullwidth > $width && $fullheight > $height) {
1794: my $size = $width.'x'.$height;
1.316 raeburn 1795: my @args = ('convert','-sample',$size,$input,$output);
1796: system({$args[0]} @args);
1.159 raeburn 1797: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1798: }
1799: }
1.6 raeburn 1800: }
1801: }
1.16 raeburn 1802: }
1.6 raeburn 1803: if ($showfile) {
1.40 raeburn 1804: if ($showfile =~ m{^/(adm|res)/}) {
1805: if ($showfile =~ m{^/res/}) {
1806: my $local_showfile =
1807: &Apache::lonnet::filelocation('',$showfile);
1808: &Apache::lonnet::repcopy($local_showfile);
1809: }
1810: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1811: }
1812: if ($imgfile) {
1813: if ($imgfile =~ m{^/(adm|res)/}) {
1814: if ($imgfile =~ m{^/res/}) {
1815: my $local_imgfile =
1816: &Apache::lonnet::filelocation('',$imgfile);
1817: &Apache::lonnet::repcopy($local_imgfile);
1818: }
1819: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1820: } else {
1821: $fullsize = $imgfile;
1822: }
1823: }
1.41 raeburn 1824: $datatable .= '<td>';
1825: if ($img eq 'login') {
1.135 bisitz 1826: $datatable .= $login_hdr_pick;
1827: }
1.41 raeburn 1828: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1829: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1830: } else {
1.201 raeburn 1831: $datatable .= '<td> </td><td class="LC_left_item">'.
1832: &mt('Upload:').'<br />';
1.6 raeburn 1833: }
1834: } else {
1.201 raeburn 1835: $datatable .= '<td> </td><td class="LC_left_item">'.
1836: &mt('Upload:').'<br />';
1.6 raeburn 1837: }
1.9 raeburn 1838: if ($switchserver) {
1839: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1840: } else {
1.135 bisitz 1841: if ($img ne 'login') { # suppress file selection for Log-in header
1842: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1843: }
1.9 raeburn 1844: }
1845: $datatable .= '</td></tr>';
1.6 raeburn 1846: }
1847: $itemcount ++;
1848: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1849: $datatable .= '<tr'.$css_class.'>'.
1850: '<td>'.$choices->{'bgs'}.'</td>';
1851: my $bgs_def;
1852: foreach my $item (@{$bgs}) {
1853: if (!$is_custom->{$item}) {
1.329 raeburn 1854: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span class="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 1855: }
1856: }
1857: if ($bgs_def) {
1.8 raeburn 1858: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1859: } else {
1860: $datatable .= '<td> </td>';
1861: }
1862: $datatable .= '<td class="LC_right_item">'.
1863: '<table border="0"><tr>';
1.174 foxr 1864:
1.6 raeburn 1865: foreach my $item (@{$bgs}) {
1.306 raeburn 1866: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 1867: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1868: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1869: $datatable .= ' ';
1.6 raeburn 1870: }
1.174 foxr 1871: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1872: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1873: }
1874: $datatable .= '</tr></table></td></tr>';
1875: $itemcount ++;
1876: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1877: $datatable .= '<tr'.$css_class.'>'.
1878: '<td>'.$choices->{'links'}.'</td>';
1879: my $links_def;
1880: foreach my $item (@{$links}) {
1881: if (!$is_custom->{$item}) {
1.329 raeburn 1882: $links_def .= '<td>'.$choices->{$item}.'<br /><span class="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1883: }
1884: }
1885: if ($links_def) {
1.8 raeburn 1886: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1887: } else {
1888: $datatable .= '<td> </td>';
1889: }
1890: $datatable .= '<td class="LC_right_item">'.
1891: '<table border="0"><tr>';
1892: foreach my $item (@{$links}) {
1.234 raeburn 1893: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 1894: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 1895: if ($designs->{'links'}{$item}) {
1.174 foxr 1896: $datatable.=' ';
1.6 raeburn 1897: }
1.174 foxr 1898: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1899: '" /></td>';
1900: }
1.30 raeburn 1901: $$rowtotal += $itemcount;
1.3 raeburn 1902: return $datatable;
1903: }
1904:
1.70 raeburn 1905: sub logo_display_options {
1906: my ($img,$defaults,$designs) = @_;
1907: my $checkedon;
1908: if (ref($defaults) eq 'HASH') {
1909: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1910: if ($defaults->{'showlogo'}{$img}) {
1911: $checkedon = 'checked="checked" ';
1912: }
1913: }
1914: }
1915: if (ref($designs) eq 'HASH') {
1916: if (ref($designs->{'showlogo'}) eq 'HASH') {
1917: if (defined($designs->{'showlogo'}{$img})) {
1918: if ($designs->{'showlogo'}{$img} == 0) {
1919: $checkedon = '';
1920: } elsif ($designs->{'showlogo'}{$img} == 1) {
1921: $checkedon = 'checked="checked" ';
1922: }
1923: }
1924: }
1925: }
1926: return '<br /><label> <input type="checkbox" name="'.
1927: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1928: &mt('show').'</label>'."\n";
1929: }
1930:
1.41 raeburn 1931: sub login_header_options {
1.135 bisitz 1932: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1933: my $output = '';
1.41 raeburn 1934: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1935: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1936: if (!$is_custom->{'textcol'}) {
1937: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1938: ' ';
1939: }
1940: if (!$is_custom->{'bgcol'}) {
1941: $output .= $choices->{'bgcol'}.': '.
1942: '<span id="css_'.$role.'_font" style="background-color: '.
1943: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1944: }
1945: $output .= '<br />';
1946: }
1947: $output .='<br />';
1948: return $output;
1949: }
1950:
1951: sub login_text_colors {
1.201 raeburn 1952: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1953: my $color_menu = '<table border="0"><tr>';
1954: foreach my $item (@{$logintext}) {
1.306 raeburn 1955: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 1956: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1957: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1958: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1959: }
1960: $color_menu .= '</tr></table><br />';
1961: return $color_menu;
1962: }
1963:
1964: sub image_changes {
1965: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1966: my $output;
1.135 bisitz 1967: if ($img eq 'login') {
1.331 raeburn 1968: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 1969: } elsif (!$is_custom) {
1.70 raeburn 1970: if ($img ne 'domlogo') {
1.331 raeburn 1971: $output = &mt('Default image:').'<br />';
1.41 raeburn 1972: } else {
1.331 raeburn 1973: $output = &mt('Default in use:').'<br />';
1.41 raeburn 1974: }
1975: }
1.331 raeburn 1976: if ($img ne 'login') {
1.135 bisitz 1977: if ($img_import) {
1978: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1979: }
1980: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1981: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1982: if ($is_custom) {
1983: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1984: '<input type="checkbox" name="'.
1985: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1986: '</label> '.&mt('Replace:').'</span><br />';
1987: } else {
1.306 raeburn 1988: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1989: }
1.41 raeburn 1990: }
1991: return $output;
1992: }
1993:
1.3 raeburn 1994: sub print_quotas {
1.86 raeburn 1995: my ($dom,$settings,$rowtotal,$action) = @_;
1996: my $context;
1997: if ($action eq 'quotas') {
1998: $context = 'tools';
1999: } else {
2000: $context = $action;
2001: }
1.197 raeburn 2002: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 2003: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2004: my $typecount = 0;
1.101 raeburn 2005: my ($css_class,%titles);
1.86 raeburn 2006: if ($context eq 'requestcourses') {
1.325 raeburn 2007: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 2008: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2009: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2010: %titles = &courserequest_titles();
1.163 raeburn 2011: } elsif ($context eq 'requestauthor') {
2012: @usertools = ('author');
2013: @options = ('norequest','approval','automatic');
1.210 raeburn 2014: %titles = &authorrequest_titles();
1.86 raeburn 2015: } else {
1.162 raeburn 2016: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 2017: %titles = &tool_titles();
1.86 raeburn 2018: }
1.26 raeburn 2019: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2020: foreach my $type (@{$types}) {
1.197 raeburn 2021: my ($currdefquota,$currauthorquota);
1.163 raeburn 2022: unless (($context eq 'requestcourses') ||
2023: ($context eq 'requestauthor')) {
1.86 raeburn 2024: if (ref($settings) eq 'HASH') {
2025: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 2026: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2027: } else {
2028: $currdefquota = $settings->{$type};
2029: }
1.197 raeburn 2030: if (ref($settings->{authorquota}) eq 'HASH') {
2031: $currauthorquota = $settings->{authorquota}->{$type};
2032: }
1.78 raeburn 2033: }
1.72 raeburn 2034: }
1.3 raeburn 2035: if (defined($usertypes->{$type})) {
2036: $typecount ++;
2037: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2038: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2039: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2040: '<td class="LC_left_item">';
1.101 raeburn 2041: if ($context eq 'requestcourses') {
2042: $datatable .= '<table><tr>';
2043: }
2044: my %cell;
1.72 raeburn 2045: foreach my $item (@usertools) {
1.101 raeburn 2046: if ($context eq 'requestcourses') {
2047: my ($curroption,$currlimit);
2048: if (ref($settings) eq 'HASH') {
2049: if (ref($settings->{$item}) eq 'HASH') {
2050: $curroption = $settings->{$item}->{$type};
2051: if ($curroption =~ /^autolimit=(\d*)$/) {
2052: $currlimit = $1;
2053: }
2054: }
2055: }
2056: if (!$curroption) {
2057: $curroption = 'norequest';
2058: }
2059: $datatable .= '<th>'.$titles{$item}.'</th>';
2060: foreach my $option (@options) {
2061: my $val = $option;
2062: if ($option eq 'norequest') {
2063: $val = 0;
2064: }
2065: if ($option eq 'validate') {
2066: my $canvalidate = 0;
2067: if (ref($validations{$item}) eq 'HASH') {
2068: if ($validations{$item}{$type}) {
2069: $canvalidate = 1;
2070: }
2071: }
2072: next if (!$canvalidate);
2073: }
2074: my $checked = '';
2075: if ($option eq $curroption) {
2076: $checked = ' checked="checked"';
2077: } elsif ($option eq 'autolimit') {
2078: if ($curroption =~ /^autolimit/) {
2079: $checked = ' checked="checked"';
2080: }
2081: }
2082: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2083: '<input type="radio" name="crsreq_'.$item.
2084: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2085: $titles{$option}.'</label>';
1.101 raeburn 2086: if ($option eq 'autolimit') {
1.127 raeburn 2087: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2088: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2089: 'value="'.$currlimit.'" />';
1.101 raeburn 2090: }
1.127 raeburn 2091: $cell{$item} .= '</span> ';
1.103 raeburn 2092: if ($option eq 'autolimit') {
1.127 raeburn 2093: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2094: }
1.101 raeburn 2095: }
1.163 raeburn 2096: } elsif ($context eq 'requestauthor') {
2097: my $curroption;
2098: if (ref($settings) eq 'HASH') {
2099: $curroption = $settings->{$type};
2100: }
2101: if (!$curroption) {
2102: $curroption = 'norequest';
2103: }
2104: foreach my $option (@options) {
2105: my $val = $option;
2106: if ($option eq 'norequest') {
2107: $val = 0;
2108: }
2109: my $checked = '';
2110: if ($option eq $curroption) {
2111: $checked = ' checked="checked"';
2112: }
2113: $datatable .= '<span class="LC_nobreak"><label>'.
2114: '<input type="radio" name="authorreq_'.$type.
2115: '" value="'.$val.'"'.$checked.' />'.
2116: $titles{$option}.'</label></span> ';
2117: }
1.101 raeburn 2118: } else {
2119: my $checked = 'checked="checked" ';
2120: if (ref($settings) eq 'HASH') {
2121: if (ref($settings->{$item}) eq 'HASH') {
2122: if ($settings->{$item}->{$type} == 0) {
2123: $checked = '';
2124: } elsif ($settings->{$item}->{$type} == 1) {
2125: $checked = 'checked="checked" ';
2126: }
1.78 raeburn 2127: }
1.72 raeburn 2128: }
1.101 raeburn 2129: $datatable .= '<span class="LC_nobreak"><label>'.
2130: '<input type="checkbox" name="'.$context.'_'.$item.
2131: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2132: '</label></span> ';
1.72 raeburn 2133: }
1.101 raeburn 2134: }
2135: if ($context eq 'requestcourses') {
2136: $datatable .= '</tr><tr>';
2137: foreach my $item (@usertools) {
1.106 raeburn 2138: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2139: }
2140: $datatable .= '</tr></table>';
1.72 raeburn 2141: }
1.86 raeburn 2142: $datatable .= '</td>';
1.163 raeburn 2143: unless (($context eq 'requestcourses') ||
2144: ($context eq 'requestauthor')) {
1.86 raeburn 2145: $datatable .=
1.197 raeburn 2146: '<td class="LC_right_item">'.
2147: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2148: '<input type="text" name="quota_'.$type.
1.72 raeburn 2149: '" value="'.$currdefquota.
1.197 raeburn 2150: '" size="5" /></span>'.(' ' x 2).
2151: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2152: '<input type="text" name="authorquota_'.$type.
2153: '" value="'.$currauthorquota.
2154: '" size="5" /></span></td>';
1.86 raeburn 2155: }
2156: $datatable .= '</tr>';
1.3 raeburn 2157: }
2158: }
2159: }
1.163 raeburn 2160: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2161: $defaultquota = '20';
1.197 raeburn 2162: $authorquota = '500';
1.86 raeburn 2163: if (ref($settings) eq 'HASH') {
2164: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2165: $defaultquota = $settings->{'defaultquota'}->{'default'};
2166: } elsif (defined($settings->{'default'})) {
2167: $defaultquota = $settings->{'default'};
2168: }
1.197 raeburn 2169: if (ref($settings->{'authorquota'}) eq 'HASH') {
2170: $authorquota = $settings->{'authorquota'}->{'default'};
2171: }
1.3 raeburn 2172: }
2173: }
2174: $typecount ++;
2175: $css_class = $typecount%2?' class="LC_odd_row"':'';
2176: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2177: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2178: '<td class="LC_left_item">';
1.101 raeburn 2179: if ($context eq 'requestcourses') {
2180: $datatable .= '<table><tr>';
2181: }
2182: my %defcell;
1.72 raeburn 2183: foreach my $item (@usertools) {
1.101 raeburn 2184: if ($context eq 'requestcourses') {
2185: my ($curroption,$currlimit);
2186: if (ref($settings) eq 'HASH') {
2187: if (ref($settings->{$item}) eq 'HASH') {
2188: $curroption = $settings->{$item}->{'default'};
2189: if ($curroption =~ /^autolimit=(\d*)$/) {
2190: $currlimit = $1;
2191: }
2192: }
2193: }
2194: if (!$curroption) {
2195: $curroption = 'norequest';
2196: }
2197: $datatable .= '<th>'.$titles{$item}.'</th>';
2198: foreach my $option (@options) {
2199: my $val = $option;
2200: if ($option eq 'norequest') {
2201: $val = 0;
2202: }
2203: if ($option eq 'validate') {
2204: my $canvalidate = 0;
2205: if (ref($validations{$item}) eq 'HASH') {
2206: if ($validations{$item}{'default'}) {
2207: $canvalidate = 1;
2208: }
2209: }
2210: next if (!$canvalidate);
2211: }
2212: my $checked = '';
2213: if ($option eq $curroption) {
2214: $checked = ' checked="checked"';
2215: } elsif ($option eq 'autolimit') {
2216: if ($curroption =~ /^autolimit/) {
2217: $checked = ' checked="checked"';
2218: }
2219: }
2220: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2221: '<input type="radio" name="crsreq_'.$item.
2222: '_default" value="'.$val.'"'.$checked.' />'.
2223: $titles{$option}.'</label>';
2224: if ($option eq 'autolimit') {
1.127 raeburn 2225: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2226: $item.'_limit_default" size="1" '.
2227: 'value="'.$currlimit.'" />';
2228: }
1.127 raeburn 2229: $defcell{$item} .= '</span> ';
1.104 raeburn 2230: if ($option eq 'autolimit') {
1.127 raeburn 2231: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2232: }
1.101 raeburn 2233: }
1.163 raeburn 2234: } elsif ($context eq 'requestauthor') {
2235: my $curroption;
2236: if (ref($settings) eq 'HASH') {
1.172 raeburn 2237: $curroption = $settings->{'default'};
1.163 raeburn 2238: }
2239: if (!$curroption) {
2240: $curroption = 'norequest';
2241: }
2242: foreach my $option (@options) {
2243: my $val = $option;
2244: if ($option eq 'norequest') {
2245: $val = 0;
2246: }
2247: my $checked = '';
2248: if ($option eq $curroption) {
2249: $checked = ' checked="checked"';
2250: }
2251: $datatable .= '<span class="LC_nobreak"><label>'.
2252: '<input type="radio" name="authorreq_default"'.
2253: ' value="'.$val.'"'.$checked.' />'.
2254: $titles{$option}.'</label></span> ';
2255: }
1.101 raeburn 2256: } else {
2257: my $checked = 'checked="checked" ';
2258: if (ref($settings) eq 'HASH') {
2259: if (ref($settings->{$item}) eq 'HASH') {
2260: if ($settings->{$item}->{'default'} == 0) {
2261: $checked = '';
2262: } elsif ($settings->{$item}->{'default'} == 1) {
2263: $checked = 'checked="checked" ';
2264: }
1.78 raeburn 2265: }
1.72 raeburn 2266: }
1.101 raeburn 2267: $datatable .= '<span class="LC_nobreak"><label>'.
2268: '<input type="checkbox" name="'.$context.'_'.$item.
2269: '" value="default" '.$checked.'/>'.$titles{$item}.
2270: '</label></span> ';
2271: }
2272: }
2273: if ($context eq 'requestcourses') {
2274: $datatable .= '</tr><tr>';
2275: foreach my $item (@usertools) {
1.106 raeburn 2276: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2277: }
1.101 raeburn 2278: $datatable .= '</tr></table>';
1.72 raeburn 2279: }
1.86 raeburn 2280: $datatable .= '</td>';
1.163 raeburn 2281: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2282: $datatable .= '<td class="LC_right_item">'.
2283: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2284: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2285: $defaultquota.'" size="5" /></span>'.(' ' x2).
2286: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2287: '<input type="text" name="authorquota" value="'.
2288: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2289: }
2290: $datatable .= '</tr>';
1.72 raeburn 2291: $typecount ++;
2292: $css_class = $typecount%2?' class="LC_odd_row"':'';
2293: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2294: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2295: if ($context eq 'requestcourses') {
1.109 raeburn 2296: $datatable .= &mt('(overrides affiliation, if set)').
2297: '</td>'.
2298: '<td class="LC_left_item">'.
2299: '<table><tr>';
1.101 raeburn 2300: } else {
1.109 raeburn 2301: $datatable .= &mt('(overrides affiliation, if checked)').
2302: '</td>'.
2303: '<td class="LC_left_item" colspan="2">'.
2304: '<br />';
1.101 raeburn 2305: }
2306: my %advcell;
1.72 raeburn 2307: foreach my $item (@usertools) {
1.101 raeburn 2308: if ($context eq 'requestcourses') {
2309: my ($curroption,$currlimit);
2310: if (ref($settings) eq 'HASH') {
2311: if (ref($settings->{$item}) eq 'HASH') {
2312: $curroption = $settings->{$item}->{'_LC_adv'};
2313: if ($curroption =~ /^autolimit=(\d*)$/) {
2314: $currlimit = $1;
2315: }
2316: }
2317: }
2318: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2319: my $checked = '';
2320: if ($curroption eq '') {
2321: $checked = ' checked="checked"';
2322: }
2323: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2324: '<input type="radio" name="crsreq_'.$item.
2325: '__LC_adv" value=""'.$checked.' />'.
2326: &mt('No override set').'</label></span> ';
1.101 raeburn 2327: foreach my $option (@options) {
2328: my $val = $option;
2329: if ($option eq 'norequest') {
2330: $val = 0;
2331: }
2332: if ($option eq 'validate') {
2333: my $canvalidate = 0;
2334: if (ref($validations{$item}) eq 'HASH') {
2335: if ($validations{$item}{'_LC_adv'}) {
2336: $canvalidate = 1;
2337: }
2338: }
2339: next if (!$canvalidate);
2340: }
2341: my $checked = '';
1.104 raeburn 2342: if ($val eq $curroption) {
1.101 raeburn 2343: $checked = ' checked="checked"';
2344: } elsif ($option eq 'autolimit') {
2345: if ($curroption =~ /^autolimit/) {
2346: $checked = ' checked="checked"';
2347: }
2348: }
2349: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2350: '<input type="radio" name="crsreq_'.$item.
2351: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2352: $titles{$option}.'</label>';
2353: if ($option eq 'autolimit') {
1.127 raeburn 2354: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2355: $item.'_limit__LC_adv" size="1" '.
2356: 'value="'.$currlimit.'" />';
2357: }
1.127 raeburn 2358: $advcell{$item} .= '</span> ';
1.104 raeburn 2359: if ($option eq 'autolimit') {
1.127 raeburn 2360: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2361: }
1.101 raeburn 2362: }
1.163 raeburn 2363: } elsif ($context eq 'requestauthor') {
2364: my $curroption;
2365: if (ref($settings) eq 'HASH') {
2366: $curroption = $settings->{'_LC_adv'};
2367: }
2368: my $checked = '';
2369: if ($curroption eq '') {
2370: $checked = ' checked="checked"';
2371: }
2372: $datatable .= '<span class="LC_nobreak"><label>'.
2373: '<input type="radio" name="authorreq__LC_adv"'.
2374: ' value=""'.$checked.' />'.
2375: &mt('No override set').'</label></span> ';
2376: foreach my $option (@options) {
2377: my $val = $option;
2378: if ($option eq 'norequest') {
2379: $val = 0;
2380: }
2381: my $checked = '';
2382: if ($val eq $curroption) {
2383: $checked = ' checked="checked"';
2384: }
2385: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2386: '<input type="radio" name="authorreq__LC_adv"'.
2387: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2388: $titles{$option}.'</label></span> ';
2389: }
1.101 raeburn 2390: } else {
2391: my $checked = 'checked="checked" ';
2392: if (ref($settings) eq 'HASH') {
2393: if (ref($settings->{$item}) eq 'HASH') {
2394: if ($settings->{$item}->{'_LC_adv'} == 0) {
2395: $checked = '';
2396: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2397: $checked = 'checked="checked" ';
2398: }
1.79 raeburn 2399: }
1.72 raeburn 2400: }
1.101 raeburn 2401: $datatable .= '<span class="LC_nobreak"><label>'.
2402: '<input type="checkbox" name="'.$context.'_'.$item.
2403: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2404: '</label></span> ';
2405: }
2406: }
2407: if ($context eq 'requestcourses') {
2408: $datatable .= '</tr><tr>';
2409: foreach my $item (@usertools) {
1.106 raeburn 2410: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2411: }
1.101 raeburn 2412: $datatable .= '</tr></table>';
1.72 raeburn 2413: }
1.98 raeburn 2414: $datatable .= '</td></tr>';
1.30 raeburn 2415: $$rowtotal += $typecount;
1.3 raeburn 2416: return $datatable;
2417: }
2418:
1.163 raeburn 2419: sub print_requestmail {
1.305 raeburn 2420: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2421: my ($now,$datatable,%currapp);
1.102 raeburn 2422: $now = time;
2423: if (ref($settings) eq 'HASH') {
2424: if (ref($settings->{'notify'}) eq 'HASH') {
2425: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2426: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2427: }
2428: }
2429: }
1.191 raeburn 2430: my $numinrow = 2;
1.224 raeburn 2431: my $css_class;
1.305 raeburn 2432: if ($$rowtotal%2) {
2433: $css_class = 'LC_odd_row';
2434: }
2435: if ($customcss) {
2436: $css_class .= " $customcss";
2437: }
2438: $css_class =~ s/^\s+//;
2439: if ($css_class) {
2440: $css_class = ' class="'.$css_class.'"';
2441: }
2442: if ($rowstyle) {
2443: $css_class .= ' style="'.$rowstyle.'"';
2444: }
1.163 raeburn 2445: my $text;
2446: if ($action eq 'requestcourses') {
2447: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2448: } elsif ($action eq 'requestauthor') {
2449: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2450: } else {
1.224 raeburn 2451: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2452: }
1.224 raeburn 2453: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2454: ' <td>'.$text.'</td>'.
1.102 raeburn 2455: ' <td class="LC_left_item">';
1.191 raeburn 2456: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2457: $action.'notifyapproval',%currapp);
1.191 raeburn 2458: if ($numdc > 0) {
2459: $datatable .= $table;
1.102 raeburn 2460: } else {
2461: $datatable .= &mt('There are no active Domain Coordinators');
2462: }
2463: $datatable .='</td></tr>';
2464: return $datatable;
2465: }
2466:
1.216 raeburn 2467: sub print_studentcode {
2468: my ($settings,$rowtotal) = @_;
2469: my $rownum = 0;
1.218 raeburn 2470: my ($output,%current);
1.325 raeburn 2471: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2472: if (ref($settings) eq 'HASH') {
2473: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2474: foreach my $type (@crstypes) {
2475: $current{$type} = $settings->{'uniquecode'}{$type};
2476: }
1.218 raeburn 2477: }
2478: }
2479: $output .= '<tr>'.
2480: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2481: '<td class="LC_left_item">';
2482: foreach my $type (@crstypes) {
2483: my $check = ' ';
2484: if ($current{$type}) {
2485: $check = ' checked="checked" ';
2486: }
2487: $output .= '<span class="LC_nobreak"><label>'.
2488: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2489: &mt($type).'</label></span>'.(' 'x2).' ';
2490: }
2491: $output .= '</td></tr>';
2492: $$rowtotal ++;
2493: return $output;
1.216 raeburn 2494: }
2495:
2496: sub print_textbookcourses {
1.242 raeburn 2497: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2498: my $rownum = 0;
2499: my $css_class;
2500: my $itemcount = 1;
2501: my $maxnum = 0;
2502: my $bookshash;
2503: if (ref($settings) eq 'HASH') {
1.242 raeburn 2504: $bookshash = $settings->{$type};
1.216 raeburn 2505: }
2506: my %ordered;
2507: if (ref($bookshash) eq 'HASH') {
2508: foreach my $item (keys(%{$bookshash})) {
2509: if (ref($bookshash->{$item}) eq 'HASH') {
2510: my $num = $bookshash->{$item}{'order'};
2511: $ordered{$num} = $item;
2512: }
2513: }
2514: }
2515: my $confname = $dom.'-domainconfig';
2516: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2517: my $maxnum = scalar(keys(%ordered));
2518: my $datatable;
1.216 raeburn 2519: if (keys(%ordered)) {
2520: my @items = sort { $a <=> $b } keys(%ordered);
2521: for (my $i=0; $i<@items; $i++) {
2522: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2523: my $key = $ordered{$items[$i]};
2524: my %coursehash=&Apache::lonnet::coursedescription($key);
2525: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2526: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2527: if (ref($bookshash->{$key}) eq 'HASH') {
2528: $subject = $bookshash->{$key}->{'subject'};
2529: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2530: if ($type eq 'textbooks') {
1.243 raeburn 2531: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2532: $author = $bookshash->{$key}->{'author'};
2533: $image = $bookshash->{$key}->{'image'};
2534: if ($image ne '') {
2535: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2536: my $imagethumb = "$path/tn-".$imagefile;
2537: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2538: }
1.216 raeburn 2539: }
2540: }
1.242 raeburn 2541: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2542: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2543: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2544: for (my $k=0; $k<=$maxnum; $k++) {
2545: my $vpos = $k+1;
2546: my $selstr;
2547: if ($k == $i) {
2548: $selstr = ' selected="selected" ';
2549: }
2550: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2551: }
2552: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2553: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2554: &mt('Delete?').'</label></span></td>'.
2555: '<td colspan="2">'.
1.242 raeburn 2556: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2557: (' 'x2).
1.242 raeburn 2558: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2559: if ($type eq 'textbooks') {
2560: $datatable .= (' 'x2).
1.243 raeburn 2561: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2562: (' 'x2).
1.242 raeburn 2563: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2564: (' 'x2).
2565: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2566: if ($image) {
1.267 raeburn 2567: $datatable .= $imgsrc.
1.242 raeburn 2568: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2569: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2570: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2571: }
2572: if ($switchserver) {
2573: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2574: } else {
2575: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2576: }
1.216 raeburn 2577: }
1.242 raeburn 2578: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2579: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2580: $coursetitle.'</span></td></tr>'."\n";
2581: $itemcount ++;
2582: }
2583: }
2584: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2585: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2586: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2587: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2588: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2589: for (my $k=0; $k<$maxnum+1; $k++) {
2590: my $vpos = $k+1;
2591: my $selstr;
2592: if ($k == $maxnum) {
2593: $selstr = ' selected="selected" ';
2594: }
2595: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2596: }
2597: $datatable .= '</select> '."\n".
1.334 raeburn 2598: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 2599: '<td colspan="2">'.
1.242 raeburn 2600: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2601: (' 'x2).
1.242 raeburn 2602: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2603: (' 'x2);
2604: if ($type eq 'textbooks') {
1.243 raeburn 2605: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2606: (' 'x2).
2607: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2608: (' 'x2).
2609: '<span class="LC_nobreak">'.&mt('Image:').' ';
2610: if ($switchserver) {
2611: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2612: } else {
2613: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2614: }
1.334 raeburn 2615: $datatable .= '</span>'."\n";
1.216 raeburn 2616: }
1.334 raeburn 2617: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2618: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2619: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2620: &Apache::loncommon::selectcourse_link
1.334 raeburn 2621: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 2622: '</span></td>'."\n".
2623: '</tr>'."\n";
2624: $itemcount ++;
2625: return $datatable;
2626: }
2627:
1.217 raeburn 2628: sub textbookcourses_javascript {
1.242 raeburn 2629: my ($settings) = @_;
2630: return unless(ref($settings) eq 'HASH');
2631: my (%ordered,%total,%jstext);
2632: foreach my $type ('textbooks','templates') {
2633: $total{$type} = 0;
2634: if (ref($settings->{$type}) eq 'HASH') {
2635: foreach my $item (keys(%{$settings->{$type}})) {
2636: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2637: my $num = $settings->{$type}->{$item}{'order'};
2638: $ordered{$type}{$num} = $item;
2639: }
2640: }
2641: $total{$type} = scalar(keys(%{$settings->{$type}}));
2642: }
2643: my @jsarray = ();
2644: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2645: push(@jsarray,$ordered{$type}{$item});
2646: }
2647: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2648: }
2649: return <<"ENDSCRIPT";
2650: <script type="text/javascript">
2651: // <![CDATA[
1.242 raeburn 2652: function reorderBooks(form,item,caller) {
1.217 raeburn 2653: var changedVal;
1.242 raeburn 2654: $jstext{'textbooks'};
2655: $jstext{'templates'};
2656: var newpos;
2657: var maxh;
2658: if (caller == 'textbooks') {
2659: newpos = 'textbooks_addbook_pos';
2660: maxh = 1 + $total{'textbooks'};
2661: } else {
2662: newpos = 'templates_addbook_pos';
2663: maxh = 1 + $total{'templates'};
2664: }
1.217 raeburn 2665: var current = new Array;
2666: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2667: if (item == newpos) {
2668: changedVal = newitemVal;
2669: } else {
2670: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2671: current[newitemVal] = newpos;
2672: }
1.242 raeburn 2673: if (caller == 'textbooks') {
2674: for (var i=0; i<textbooks.length; i++) {
2675: var elementName = 'textbooks_'+textbooks[i];
2676: if (elementName != item) {
2677: if (form.elements[elementName]) {
2678: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2679: current[currVal] = elementName;
2680: }
2681: }
2682: }
2683: }
2684: if (caller == 'templates') {
2685: for (var i=0; i<templates.length; i++) {
2686: var elementName = 'templates_'+templates[i];
2687: if (elementName != item) {
2688: if (form.elements[elementName]) {
2689: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2690: current[currVal] = elementName;
2691: }
1.217 raeburn 2692: }
2693: }
2694: }
2695: var oldVal;
2696: for (var j=0; j<maxh; j++) {
2697: if (current[j] == undefined) {
2698: oldVal = j;
2699: }
2700: }
2701: if (oldVal < changedVal) {
2702: for (var k=oldVal+1; k<=changedVal ; k++) {
2703: var elementName = current[k];
2704: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2705: }
2706: } else {
2707: for (var k=changedVal; k<oldVal; k++) {
2708: var elementName = current[k];
2709: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2710: }
2711: }
2712: return;
2713: }
2714:
2715: // ]]>
2716: </script>
2717:
2718: ENDSCRIPT
2719: }
2720:
1.267 raeburn 2721: sub ltitools_javascript {
2722: my ($settings) = @_;
1.319 raeburn 2723: my $togglejs = <itools_toggle_js();
2724: unless (ref($settings) eq 'HASH') {
2725: return $togglejs;
2726: }
1.267 raeburn 2727: my (%ordered,$total,%jstext);
2728: $total = 0;
2729: foreach my $item (keys(%{$settings})) {
2730: if (ref($settings->{$item}) eq 'HASH') {
2731: my $num = $settings->{$item}{'order'};
2732: $ordered{$num} = $item;
2733: }
2734: }
2735: $total = scalar(keys(%{$settings}));
2736: my @jsarray = ();
2737: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2738: push(@jsarray,$ordered{$item});
2739: }
2740: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2741: return <<"ENDSCRIPT";
2742: <script type="text/javascript">
2743: // <![CDATA[
1.319 raeburn 2744: function reorderLTITools(form,item) {
1.267 raeburn 2745: var changedVal;
2746: $jstext
2747: var newpos = 'ltitools_add_pos';
2748: var maxh = 1 + $total;
2749: var current = new Array;
2750: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2751: if (item == newpos) {
2752: changedVal = newitemVal;
2753: } else {
2754: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2755: current[newitemVal] = newpos;
2756: }
2757: for (var i=0; i<ltitools.length; i++) {
2758: var elementName = 'ltitools_'+ltitools[i];
2759: if (elementName != item) {
2760: if (form.elements[elementName]) {
2761: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2762: current[currVal] = elementName;
2763: }
2764: }
2765: }
2766: var oldVal;
2767: for (var j=0; j<maxh; j++) {
2768: if (current[j] == undefined) {
2769: oldVal = j;
2770: }
2771: }
2772: if (oldVal < changedVal) {
2773: for (var k=oldVal+1; k<=changedVal ; k++) {
2774: var elementName = current[k];
2775: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2776: }
2777: } else {
2778: for (var k=changedVal; k<oldVal; k++) {
2779: var elementName = current[k];
2780: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2781: }
2782: }
2783: return;
2784: }
2785:
2786: // ]]>
2787: </script>
2788:
1.319 raeburn 2789: $togglejs
2790:
2791: ENDSCRIPT
2792: }
2793:
2794: sub ltitools_toggle_js {
2795: return <<"ENDSCRIPT";
2796: <script type="text/javascript">
2797: // <![CDATA[
2798:
2799: function toggleLTITools(form,setting,item) {
2800: var radioname = '';
2801: var divid = '';
2802: if ((setting == 'passback') || (setting == 'roster')) {
2803: radioname = 'ltitools_'+setting+'_'+item;
2804: divid = 'ltitools_'+setting+'time_'+item;
2805: var num = form.elements[radioname].length;
2806: if (num) {
2807: var setvis = '';
2808: for (var i=0; i<num; i++) {
2809: if (form.elements[radioname][i].checked) {
2810: if (form.elements[radioname][i].value == '1') {
2811: if (document.getElementById(divid)) {
2812: document.getElementById(divid).style.display = 'inline-block';
2813: }
2814: setvis = 1;
2815: }
2816: break;
2817: }
2818: }
2819: }
2820: if (!setvis) {
2821: if (document.getElementById(divid)) {
2822: document.getElementById(divid).style.display = 'none';
2823: }
2824: }
2825: }
1.324 raeburn 2826: if (setting == 'user') {
2827: divid = 'ltitools_'+setting+'_div_'+item;
2828: var checkid = 'ltitools_'+setting+'_field_'+item;
2829: if (document.getElementById(divid)) {
2830: if (document.getElementById(checkid)) {
2831: if (document.getElementById(checkid).checked) {
2832: document.getElementById(divid).style.display = 'inline-block';
2833: } else {
2834: document.getElementById(divid).style.display = 'none';
2835: }
2836: }
2837: }
2838: }
1.319 raeburn 2839: return;
2840: }
2841: // ]]>
2842: </script>
2843:
1.267 raeburn 2844: ENDSCRIPT
2845: }
2846:
1.372 raeburn 2847: sub proctoring_javascript {
2848: my ($settings) = @_;
2849: my (%ordered,$total,%jstext);
2850: $total = 0;
2851: if (ref($settings) eq 'HASH') {
2852: foreach my $item (keys(%{$settings})) {
2853: if (ref($settings->{$item}) eq 'HASH') {
2854: my $num = $settings->{$item}{'order'};
2855: $ordered{$num} = $item;
2856: }
2857: }
2858: $total = scalar(keys(%{$settings}));
2859: } else {
2860: %ordered = (
2861: 0 => 'proctorio',
2862: 1 => 'examity',
2863: );
2864: $total = 2;
2865: }
2866: my @jsarray = ();
2867: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2868: push(@jsarray,$ordered{$item});
2869: }
2870: my $jstext = ' var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
2871: return <<"ENDSCRIPT";
2872: <script type="text/javascript">
2873: // <![CDATA[
2874: function reorderProctoring(form,item) {
2875: var changedVal;
2876: $jstext
2877: var maxh = $total;
2878: var current = new Array;
2879: var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2880: for (var i=0; i<proctors.length; i++) {
2881: var elementName = 'proctoring_pos_'+proctors[i];
2882: if (elementName != item) {
2883: if (form.elements[elementName]) {
2884: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2885: current[currVal] = elementName;
2886: }
2887: }
2888: }
2889: var oldVal;
2890: for (var j=0; j<maxh; j++) {
2891: if (current[j] == undefined) {
2892: oldVal = j;
2893: }
2894: }
2895: if (oldVal < changedVal) {
2896: for (var k=oldVal+1; k<=changedVal ; k++) {
2897: var elementName = current[k];
2898: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2899: }
2900: } else {
2901: for (var k=changedVal; k<oldVal; k++) {
2902: var elementName = current[k];
2903: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2904: }
2905: }
2906: return;
2907: }
2908:
2909: function toggleProctoring(form,item) {
2910: var fieldsets = document.getElementsByClassName('proctoring_'+item);
2911: if (fieldsets.length) {
2912: var radioname = 'proctoring_available_'+item;
2913: var num = form.elements[radioname].length;
2914: if (num) {
2915: var setvis = '';
2916: for (var i=0; i<num; i++) {
2917: if (form.elements[radioname][i].checked) {
2918: if (form.elements[radioname][i].value == '1') {
2919: setvis = 1;
2920: break;
2921: }
2922: }
2923: }
2924: for (var j=0; j<fieldsets.length; j++) {
2925: if (setvis) {
2926: fieldsets[j].style.display = 'block';
2927: } else {
2928: fieldsets[j].style.display = 'none';
2929: }
2930: }
2931: }
2932: }
2933: return;
2934: }
2935:
2936: // ]]>
2937: </script>
2938:
2939: ENDSCRIPT
2940: }
2941:
2942:
1.320 raeburn 2943: sub lti_javascript {
2944: my ($settings) = @_;
2945: my $togglejs = <i_toggle_js();
2946: unless (ref($settings) eq 'HASH') {
2947: return $togglejs;
2948: }
2949: my (%ordered,$total,%jstext);
2950: $total = 0;
2951: foreach my $item (keys(%{$settings})) {
2952: if (ref($settings->{$item}) eq 'HASH') {
2953: my $num = $settings->{$item}{'order'};
2954: $ordered{$num} = $item;
2955: }
2956: }
2957: $total = scalar(keys(%{$settings}));
2958: my @jsarray = ();
2959: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2960: push(@jsarray,$ordered{$item});
2961: }
2962: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
2963: return <<"ENDSCRIPT";
2964: <script type="text/javascript">
2965: // <![CDATA[
2966: function reorderLTI(form,item) {
2967: var changedVal;
2968: $jstext
2969: var newpos = 'lti_pos_add';
2970: var maxh = 1 + $total;
2971: var current = new Array;
2972: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2973: if (item == newpos) {
2974: changedVal = newitemVal;
2975: } else {
2976: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2977: current[newitemVal] = newpos;
2978: }
2979: for (var i=0; i<lti.length; i++) {
2980: var elementName = 'lti_pos_'+lti[i];
2981: if (elementName != item) {
2982: if (form.elements[elementName]) {
2983: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2984: current[currVal] = elementName;
2985: }
2986: }
2987: }
2988: var oldVal;
2989: for (var j=0; j<maxh; j++) {
2990: if (current[j] == undefined) {
2991: oldVal = j;
2992: }
2993: }
2994: if (oldVal < changedVal) {
2995: for (var k=oldVal+1; k<=changedVal ; k++) {
2996: var elementName = current[k];
2997: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2998: }
2999: } else {
3000: for (var k=changedVal; k<oldVal; k++) {
3001: var elementName = current[k];
3002: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3003: }
3004: }
3005: return;
3006: }
3007: // ]]>
3008: </script>
3009:
3010: $togglejs
3011:
3012: ENDSCRIPT
3013: }
3014:
3015: sub lti_toggle_js {
1.325 raeburn 3016: my %lcauthparmtext = &Apache::lonlocal::texthash (
3017: localauth => 'Local auth argument',
3018: krb => 'Kerberos domain',
3019: );
1.320 raeburn 3020: return <<"ENDSCRIPT";
3021: <script type="text/javascript">
3022: // <![CDATA[
3023:
3024: function toggleLTI(form,setting,item) {
1.345 raeburn 3025: if (setting == 'requser') {
3026: var fieldsets = document.getElementsByClassName('ltioption_'+item);
3027: if (fieldsets.length) {
3028: var radioname = 'lti_'+setting+'_'+item;
3029: var num = form.elements[radioname].length;
3030: if (num) {
3031: var setvis = '';
3032: for (var i=0; i<num; i++) {
3033: if (form.elements[radioname][i].checked) {
3034: if (form.elements[radioname][i].value == '1') {
3035: setvis = 1;
3036: break;
3037: }
3038: }
3039: }
1.352 raeburn 3040: for (var j=0; j<fieldsets.length; j++) {
1.345 raeburn 3041: if (setvis) {
3042: fieldsets[j].style.display = 'block';
3043: } else {
3044: fieldsets[j].style.display = 'none';
3045: }
3046: }
3047: }
3048: }
1.363 raeburn 3049: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320 raeburn 3050: var radioname = '';
3051: var divid = '';
3052: if (setting == 'user') {
3053: radioname = 'lti_mapuser_'+item;
3054: divid = 'lti_userfield_'+item;
1.343 raeburn 3055: } else if (setting == 'crs') {
1.320 raeburn 3056: radioname = 'lti_mapcrs_'+item;
3057: divid = 'lti_crsfield_'+item;
1.363 raeburn 3058: } else if (setting == 'callback') {
3059: radioname = 'lti_callback_'+item;
3060: divid = 'lti_callbackfield_'+item;
1.337 raeburn 3061: } else {
1.351 raeburn 3062: radioname = 'lti_passback_'+item;
1.337 raeburn 3063: divid = 'lti_passback_'+item;
1.320 raeburn 3064: }
3065: var num = form.elements[radioname].length;
3066: if (num) {
3067: var setvis = '';
3068: for (var i=0; i<num; i++) {
3069: if (form.elements[radioname][i].checked) {
1.363 raeburn 3070: if ((setting == 'passback') || (setting == 'callback')) {
1.337 raeburn 3071: if (form.elements[radioname][i].value == '1') {
3072: if (document.getElementById(divid)) {
3073: document.getElementById(divid).style.display = 'inline-block';
3074: }
3075: setvis = 1;
3076: break;
3077: }
3078: } else {
3079: if (form.elements[radioname][i].value == 'other') {
3080: if (document.getElementById(divid)) {
3081: document.getElementById(divid).style.display = 'inline-block';
3082: }
3083: setvis = 1;
3084: break;
1.320 raeburn 3085: }
3086: }
3087: }
3088: }
3089: if (!setvis) {
3090: if (document.getElementById(divid)) {
3091: document.getElementById(divid).style.display = 'none';
3092: }
3093: }
3094: }
3095: } else if ((setting == 'sec') || (setting == 'secsrc')) {
3096: var numsec = form.elements['lti_crssec_'+item].length;
3097: if (numsec) {
3098: var setvis = '';
3099: for (var i=0; i<numsec; i++) {
3100: if (form.elements['lti_crssec_'+item][i].checked) {
3101: if (form.elements['lti_crssec_'+item][i].value == '1') {
3102: if (document.getElementById('lti_crssecfield_'+item)) {
3103: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3104: setvis = 1;
3105: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3106: if (numsrcsec) {
3107: var setsrcvis = '';
3108: for (var j=0; j<numsrcsec; j++) {
3109: if (form.elements['lti_crssecsrc_'+item][j].checked) {
3110: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3111: if (document.getElementById('lti_secsrcfield_'+item)) {
3112: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3113: setsrcvis = 1;
3114: }
3115: }
3116: }
3117: }
3118: if (!setsrcvis) {
3119: if (document.getElementById('lti_secsrcfield_'+item)) {
3120: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3121: }
3122: }
3123: }
3124: }
3125: }
3126: }
3127: }
3128: if (!setvis) {
3129: if (document.getElementById('lti_crssecfield_'+item)) {
3130: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3131: }
3132: if (document.getElementById('lti_secsrcfield_'+item)) {
3133: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3134: }
3135: }
3136: }
1.325 raeburn 3137: } else if (setting == 'lcauth') {
3138: var numauth = form.elements['lti_lcauth_'+item].length;
3139: if (numauth) {
3140: for (var i=0; i<numauth; i++) {
3141: if (form.elements['lti_lcauth_'+item][i].checked) {
3142: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3143: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3144: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3145: } else {
3146: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3147: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3148: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3149: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3150: } else {
3151: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3152: }
3153: }
3154: }
3155: }
3156: }
3157: }
3158: }
1.326 raeburn 3159: } else if (setting == 'lcmenu') {
3160: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3161: var divid = 'lti_menufield_'+item;
3162: var setvis = '';
3163: for (var i=0; i<menus.length; i++) {
3164: var radioname = menus[i];
3165: var num = form.elements[radioname].length;
3166: if (num) {
3167: for (var j=0; j<num; j++) {
3168: if (form.elements[radioname][j].checked) {
3169: if (form.elements[radioname][j].value == '1') {
3170: if (document.getElementById(divid)) {
3171: document.getElementById(divid).style.display = 'inline-block';
3172: }
3173: setvis = 1;
3174: break;
3175: }
3176: }
3177: }
3178: }
3179: if (setvis == 1) {
3180: break;
3181: }
3182: }
3183: if (!setvis) {
3184: if (document.getElementById(divid)) {
3185: document.getElementById(divid).style.display = 'none';
3186: }
3187: }
1.320 raeburn 3188: }
3189: return;
3190: }
3191: // ]]>
3192: </script>
3193:
3194: ENDSCRIPT
3195: }
3196:
1.3 raeburn 3197: sub print_autoenroll {
1.30 raeburn 3198: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3199: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 3200: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 3201: if (ref($settings) eq 'HASH') {
3202: if (exists($settings->{'run'})) {
3203: if ($settings->{'run'} eq '0') {
3204: $runoff = ' checked="checked" ';
3205: $runon = ' ';
3206: } else {
3207: $runon = ' checked="checked" ';
3208: $runoff = ' ';
3209: }
3210: } else {
3211: if ($autorun) {
3212: $runon = ' checked="checked" ';
3213: $runoff = ' ';
3214: } else {
3215: $runoff = ' checked="checked" ';
3216: $runon = ' ';
3217: }
3218: }
1.129 raeburn 3219: if (exists($settings->{'co-owners'})) {
3220: if ($settings->{'co-owners'} eq '0') {
3221: $coownersoff = ' checked="checked" ';
3222: $coownerson = ' ';
3223: } else {
3224: $coownerson = ' checked="checked" ';
3225: $coownersoff = ' ';
3226: }
3227: } else {
3228: $coownersoff = ' checked="checked" ';
3229: $coownerson = ' ';
3230: }
1.3 raeburn 3231: if (exists($settings->{'sender_domain'})) {
3232: $defdom = $settings->{'sender_domain'};
3233: }
1.274 raeburn 3234: if (exists($settings->{'autofailsafe'})) {
3235: $failsafe = $settings->{'autofailsafe'};
3236: }
1.14 raeburn 3237: } else {
3238: if ($autorun) {
3239: $runon = ' checked="checked" ';
3240: $runoff = ' ';
3241: } else {
3242: $runoff = ' checked="checked" ';
3243: $runon = ' ';
3244: }
1.3 raeburn 3245: }
3246: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3247: my $notif_sender;
3248: if (ref($settings) eq 'HASH') {
3249: $notif_sender = $settings->{'sender_uname'};
3250: }
1.3 raeburn 3251: my $datatable='<tr class="LC_odd_row">'.
3252: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3253: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3254: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3255: $runon.' value="1" />'.&mt('Yes').'</label> '.
3256: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3257: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3258: '</tr><tr>'.
3259: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3260: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3261: &mt('username').': '.
3262: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3263: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3264: ': '.$domform.'</span></td></tr>'.
3265: '<tr class="LC_odd_row">'.
3266: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3267: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3268: '<input type="radio" name="autoassign_coowners"'.
3269: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3270: '<label><input type="radio" name="autoassign_coowners"'.
3271: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 3272: '</tr><tr>'.
3273: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
3274: '<td class="LC_right_item"><span class="LC_nobreak">'.
3275: '<input type="text" name="autoenroll_failsafe"'.
1.333 raeburn 3276: ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.274 raeburn 3277: $$rowtotal += 4;
1.3 raeburn 3278: return $datatable;
3279: }
3280:
3281: sub print_autoupdate {
1.30 raeburn 3282: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 3283: my $datatable;
3284: if ($position eq 'top') {
3285: my $updateon = ' ';
3286: my $updateoff = ' checked="checked" ';
3287: my $classlistson = ' ';
3288: my $classlistsoff = ' checked="checked" ';
3289: if (ref($settings) eq 'HASH') {
3290: if ($settings->{'run'} eq '1') {
3291: $updateon = $updateoff;
3292: $updateoff = ' ';
3293: }
3294: if ($settings->{'classlists'} eq '1') {
3295: $classlistson = $classlistsoff;
3296: $classlistsoff = ' ';
3297: }
3298: }
3299: my %title = (
3300: run => 'Auto-update active?',
3301: classlists => 'Update information in classlists?',
3302: );
3303: $datatable = '<tr class="LC_odd_row">'.
3304: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 3305: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3306: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 3307: $updateon.' value="1" />'.&mt('Yes').'</label> '.
3308: '<label><input type="radio" name="autoupdate_run"'.
3309: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3310: '</tr><tr>'.
3311: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 3312: '<td class="LC_right_item"><span class="LC_nobreak">'.
3313: '<label><input type="radio" name="classlists"'.
3314: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
3315: '<label><input type="radio" name="classlists"'.
3316: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3317: '</tr>';
1.30 raeburn 3318: $$rowtotal += 2;
1.131 raeburn 3319: } elsif ($position eq 'middle') {
3320: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3321: my $numinrow = 3;
3322: my $locknamesettings;
3323: $datatable .= &insttypes_row($settings,$types,$usertypes,
3324: $dom,$numinrow,$othertitle,
1.305 raeburn 3325: 'lockablenames',$rowtotal);
1.131 raeburn 3326: $$rowtotal ++;
1.3 raeburn 3327: } else {
1.44 raeburn 3328: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3329: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3330: 'permanentemail','id');
1.33 raeburn 3331: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3332: my $numrows = 0;
1.26 raeburn 3333: if (ref($types) eq 'ARRAY') {
3334: if (@{$types} > 0) {
3335: $datatable =
3336: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3337: \@fields,$types,\$numrows);
1.30 raeburn 3338: $$rowtotal += @{$types};
1.26 raeburn 3339: }
1.3 raeburn 3340: }
3341: $datatable .=
3342: &usertype_update_row($settings,{'default' => $othertitle},
3343: \%fieldtitles,\@fields,['default'],
3344: \$numrows);
1.30 raeburn 3345: $$rowtotal ++;
1.3 raeburn 3346: }
3347: return $datatable;
3348: }
3349:
1.125 raeburn 3350: sub print_autocreate {
3351: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 3352: my (%createon,%createoff,%currhash);
1.125 raeburn 3353: my @types = ('xml','req');
3354: if (ref($settings) eq 'HASH') {
3355: foreach my $item (@types) {
3356: $createoff{$item} = ' checked="checked" ';
3357: $createon{$item} = ' ';
3358: if (exists($settings->{$item})) {
3359: if ($settings->{$item}) {
3360: $createon{$item} = ' checked="checked" ';
3361: $createoff{$item} = ' ';
3362: }
3363: }
3364: }
1.210 raeburn 3365: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 3366: $currhash{$settings->{'xmldc'}} = 1;
3367: }
1.125 raeburn 3368: } else {
3369: foreach my $item (@types) {
3370: $createoff{$item} = ' checked="checked" ';
3371: $createon{$item} = ' ';
3372: }
3373: }
3374: $$rowtotal += 2;
1.191 raeburn 3375: my $numinrow = 2;
1.125 raeburn 3376: my $datatable='<tr class="LC_odd_row">'.
3377: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3378: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3379: '<input type="radio" name="autocreate_xml"'.
3380: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3381: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3382: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3383: '</td></tr><tr>'.
3384: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3385: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3386: '<input type="radio" name="autocreate_req"'.
3387: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3388: '<label><input type="radio" name="autocreate_req"'.
3389: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 3390: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3391: 'autocreate_xmldc',%currhash);
1.247 raeburn 3392: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3393: if ($numdc > 1) {
1.247 raeburn 3394: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3395: '</td><td class="LC_left_item">';
1.125 raeburn 3396: } else {
1.247 raeburn 3397: $datatable .= &mt('Course creation processed as:').
3398: '</td><td class="LC_right_item">';
1.125 raeburn 3399: }
1.247 raeburn 3400: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 3401: $$rowtotal += $rows;
1.125 raeburn 3402: return $datatable;
3403: }
3404:
1.23 raeburn 3405: sub print_directorysrch {
1.277 raeburn 3406: my ($position,$dom,$settings,$rowtotal) = @_;
3407: my $datatable;
3408: if ($position eq 'top') {
3409: my $instsrchon = ' ';
3410: my $instsrchoff = ' checked="checked" ';
3411: my ($exacton,$containson,$beginson);
3412: my $instlocalon = ' ';
3413: my $instlocaloff = ' checked="checked" ';
3414: if (ref($settings) eq 'HASH') {
3415: if ($settings->{'available'} eq '1') {
3416: $instsrchon = $instsrchoff;
3417: $instsrchoff = ' ';
3418: }
3419: if ($settings->{'localonly'} eq '1') {
3420: $instlocalon = $instlocaloff;
3421: $instlocaloff = ' ';
3422: }
3423: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3424: foreach my $type (@{$settings->{'searchtypes'}}) {
3425: if ($type eq 'exact') {
3426: $exacton = ' checked="checked" ';
3427: } elsif ($type eq 'contains') {
3428: $containson = ' checked="checked" ';
3429: } elsif ($type eq 'begins') {
3430: $beginson = ' checked="checked" ';
3431: }
3432: }
3433: } else {
3434: if ($settings->{'searchtypes'} eq 'exact') {
3435: $exacton = ' checked="checked" ';
3436: } elsif ($settings->{'searchtypes'} eq 'contains') {
3437: $containson = ' checked="checked" ';
3438: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 3439: $exacton = ' checked="checked" ';
3440: $containson = ' checked="checked" ';
3441: }
3442: }
1.277 raeburn 3443: }
3444: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3445: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3446:
3447: my $numinrow = 4;
3448: my $cansrchrow = 0;
3449: $datatable='<tr class="LC_odd_row">'.
3450: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3451: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3452: '<input type="radio" name="dirsrch_available"'.
3453: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3454: '<label><input type="radio" name="dirsrch_available"'.
3455: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3456: '</tr><tr>'.
3457: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3458: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3459: '<input type="radio" name="dirsrch_instlocalonly"'.
3460: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3461: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3462: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3463: '</tr>';
3464: $$rowtotal += 2;
3465: if (ref($usertypes) eq 'HASH') {
3466: if (keys(%{$usertypes}) > 0) {
3467: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 3468: $numinrow,$othertitle,'cansearch',
3469: $rowtotal);
1.277 raeburn 3470: $cansrchrow = 1;
1.25 raeburn 3471: }
1.23 raeburn 3472: }
1.277 raeburn 3473: if ($cansrchrow) {
3474: $$rowtotal ++;
3475: $datatable .= '<tr>';
3476: } else {
3477: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 3478: }
1.277 raeburn 3479: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3480: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3481: foreach my $title (@{$titleorder}) {
3482: if (defined($searchtitles->{$title})) {
3483: my $check = ' ';
3484: if (ref($settings) eq 'HASH') {
3485: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3486: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3487: $check = ' checked="checked" ';
3488: }
1.39 raeburn 3489: }
1.25 raeburn 3490: }
1.277 raeburn 3491: $datatable .= '<td class="LC_left_item">'.
3492: '<span class="LC_nobreak"><label>'.
3493: '<input type="checkbox" name="searchby" '.
3494: 'value="'.$title.'"'.$check.'/>'.
3495: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 3496: }
3497: }
1.277 raeburn 3498: $datatable .= '</tr></table></td></tr>';
3499: $$rowtotal ++;
3500: if ($cansrchrow) {
3501: $datatable .= '<tr class="LC_odd_row">';
3502: } else {
3503: $datatable .= '<tr>';
3504: }
3505: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3506: '<td class="LC_left_item" colspan="2">'.
3507: '<span class="LC_nobreak"><label>'.
3508: '<input type="checkbox" name="searchtypes" '.
3509: $exacton.' value="exact" />'.&mt('Exact match').
3510: '</label> '.
3511: '<label><input type="checkbox" name="searchtypes" '.
3512: $beginson.' value="begins" />'.&mt('Begins with').
3513: '</label> '.
3514: '<label><input type="checkbox" name="searchtypes" '.
3515: $containson.' value="contains" />'.&mt('Contains').
3516: '</label></span></td></tr>';
3517: $$rowtotal ++;
1.26 raeburn 3518: } else {
1.277 raeburn 3519: my $domsrchon = ' checked="checked" ';
3520: my $domsrchoff = ' ';
3521: my $domlocalon = ' ';
3522: my $domlocaloff = ' checked="checked" ';
3523: if (ref($settings) eq 'HASH') {
3524: if ($settings->{'lclocalonly'} eq '1') {
3525: $domlocalon = $domlocaloff;
3526: $domlocaloff = ' ';
3527: }
3528: if ($settings->{'lcavailable'} eq '0') {
3529: $domsrchoff = $domsrchon;
3530: $domsrchon = ' ';
3531: }
3532: }
3533: $datatable='<tr class="LC_odd_row">'.
3534: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3535: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3536: '<input type="radio" name="dirsrch_domavailable"'.
3537: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3538: '<label><input type="radio" name="dirsrch_domavailable"'.
3539: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3540: '</tr><tr>'.
3541: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3542: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3543: '<input type="radio" name="dirsrch_domlocalonly"'.
3544: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3545: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3546: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3547: '</tr>';
3548: $$rowtotal += 2;
1.26 raeburn 3549: }
1.25 raeburn 3550: return $datatable;
3551: }
3552:
1.28 raeburn 3553: sub print_contacts {
1.286 raeburn 3554: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3555: my $datatable;
3556: my @contacts = ('adminemail','supportemail');
1.286 raeburn 3557: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 3558: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 3559: if ($position eq 'top') {
3560: if (ref($settings) eq 'HASH') {
3561: foreach my $item (@contacts) {
3562: if (exists($settings->{$item})) {
3563: $to{$item} = $settings->{$item};
3564: }
3565: }
3566: }
3567: } elsif ($position eq 'middle') {
3568: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 3569: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 3570: foreach my $type (@mailings) {
3571: $otheremails{$type} = '';
3572: }
1.340 raeburn 3573: } elsif ($position eq 'lower') {
3574: if (ref($settings) eq 'HASH') {
3575: if (ref($settings->{'lonstatus'}) eq 'HASH') {
3576: %lonstatus = %{$settings->{'lonstatus'}};
3577: }
3578: }
1.286 raeburn 3579: } else {
3580: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 3581: foreach my $type (@mailings) {
3582: $otheremails{$type} = '';
3583: }
1.286 raeburn 3584: $bccemails{'helpdeskmail'} = '';
3585: $bccemails{'otherdomsmail'} = '';
3586: $includestr{'helpdeskmail'} = '';
3587: $includestr{'otherdomsmail'} = '';
3588: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3589: }
1.28 raeburn 3590: if (ref($settings) eq 'HASH') {
1.340 raeburn 3591: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 3592: foreach my $type (@mailings) {
3593: if (exists($settings->{$type})) {
3594: if (ref($settings->{$type}) eq 'HASH') {
3595: foreach my $item (@contacts) {
3596: if ($settings->{$type}{$item}) {
3597: $checked{$type}{$item} = ' checked="checked" ';
3598: }
3599: }
3600: $otheremails{$type} = $settings->{$type}{'others'};
3601: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3602: $bccemails{$type} = $settings->{$type}{'bcc'};
3603: if ($settings->{$type}{'include'} ne '') {
3604: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3605: $includestr{$type} = &unescape($includestr{$type});
3606: }
3607: }
3608: }
3609: } elsif ($type eq 'lonstatusmail') {
3610: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3611: }
1.28 raeburn 3612: }
3613: }
1.286 raeburn 3614: if ($position eq 'bottom') {
3615: foreach my $type (@mailings) {
3616: $bccemails{$type} = $settings->{$type}{'bcc'};
3617: if ($settings->{$type}{'include'} ne '') {
3618: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3619: $includestr{$type} = &unescape($includestr{$type});
3620: }
3621: }
3622: if (ref($settings->{'helpform'}) eq 'HASH') {
3623: if (ref($fields) eq 'ARRAY') {
3624: foreach my $field (@{$fields}) {
3625: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3626: }
1.286 raeburn 3627: }
3628: if (exists($settings->{'helpform'}{'maxsize'})) {
3629: $maxsize = $settings->{'helpform'}{'maxsize'};
3630: } else {
1.289 raeburn 3631: $maxsize = '1.0';
1.286 raeburn 3632: }
3633: } else {
3634: if (ref($fields) eq 'ARRAY') {
3635: foreach my $field (@{$fields}) {
3636: $currfield{$field} = 'yes';
1.134 raeburn 3637: }
1.28 raeburn 3638: }
1.286 raeburn 3639: $maxsize = '1.0';
1.28 raeburn 3640: }
3641: }
3642: } else {
1.286 raeburn 3643: if ($position eq 'top') {
3644: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3645: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3646: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3647: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 3648: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3649: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3650: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3651: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 3652: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3653: } elsif ($position eq 'bottom') {
3654: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3655: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3656: if (ref($fields) eq 'ARRAY') {
3657: foreach my $field (@{$fields}) {
3658: $currfield{$field} = 'yes';
3659: }
3660: }
3661: $maxsize = '1.0';
3662: }
1.28 raeburn 3663: }
3664: my ($titles,$short_titles) = &contact_titles();
3665: my $rownum = 0;
3666: my $css_class;
1.286 raeburn 3667: if ($position eq 'top') {
3668: foreach my $item (@contacts) {
3669: $css_class = $rownum%2?' class="LC_odd_row"':'';
3670: $datatable .= '<tr'.$css_class.'>'.
3671: '<td><span class="LC_nobreak">'.$titles->{$item}.
3672: '</span></td><td class="LC_right_item">'.
3673: '<input type="text" name="'.$item.'" value="'.
3674: $to{$item}.'" /></td></tr>';
3675: $rownum ++;
3676: }
1.315 raeburn 3677: } elsif ($position eq 'bottom') {
3678: $css_class = $rownum%2?' class="LC_odd_row"':'';
3679: $datatable .= '<tr'.$css_class.'>'.
3680: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3681: &mt('(e-mail, subject, and description always shown)').
3682: '</td><td class="LC_left_item">';
3683: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3684: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3685: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3686: foreach my $field (@{$fields}) {
3687: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3688: if (($field eq 'screenshot') || ($field eq 'cc')) {
3689: $datatable .= ' '.&mt('(logged-in users)');
3690: }
3691: $datatable .='</td><td>';
3692: my $clickaction;
3693: if ($field eq 'screenshot') {
3694: $clickaction = ' onclick="screenshotSize(this);"';
3695: }
3696: if (ref($possoptions->{$field}) eq 'ARRAY') {
3697: foreach my $option (@{$possoptions->{$field}}) {
3698: my $checked;
3699: if ($currfield{$field} eq $option) {
3700: $checked = ' checked="checked"';
3701: }
3702: $datatable .= '<span class="LC_nobreak"><label>'.
3703: '<input type="radio" name="helpform_'.$field.'" '.
3704: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3705: '</label></span>'.(' 'x2);
3706: }
3707: }
3708: if ($field eq 'screenshot') {
3709: my $display;
3710: if ($currfield{$field} eq 'no') {
3711: $display = ' style="display:none"';
3712: }
1.334 raeburn 3713: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 3714: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3715: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3716: }
3717: $datatable .= '</td></tr>';
3718: }
3719: $datatable .= '</table>';
3720: }
3721: $datatable .= '</td></tr>'."\n";
3722: $rownum ++;
3723: }
1.340 raeburn 3724: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 3725: foreach my $type (@mailings) {
3726: $css_class = $rownum%2?' class="LC_odd_row"':'';
3727: $datatable .= '<tr'.$css_class.'>'.
3728: '<td><span class="LC_nobreak">'.
3729: $titles->{$type}.': </span></td>'.
3730: '<td class="LC_left_item">';
3731: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3732: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3733: }
3734: $datatable .= '<span class="LC_nobreak">';
3735: foreach my $item (@contacts) {
3736: $datatable .= '<label>'.
3737: '<input type="checkbox" name="'.$type.'"'.
3738: $checked{$type}{$item}.
3739: ' value="'.$item.'" />'.$short_titles->{$item}.
3740: '</label> ';
3741: }
3742: $datatable .= '</span><br />'.&mt('Others').': '.
3743: '<input type="text" name="'.$type.'_others" '.
3744: 'value="'.$otheremails{$type}.'" />';
3745: my %locchecked;
3746: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3747: foreach my $loc ('s','b') {
3748: if ($includeloc{$type} eq $loc) {
3749: $locchecked{$loc} = ' checked="checked"';
3750: last;
3751: }
3752: }
3753: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3754: '<input type="text" name="'.$type.'_bcc" '.
3755: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3756: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3757: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 3758: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 3759: '<span class="LC_nobreak">'.&mt('Location:').' '.
3760: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3761: (' 'x2).
3762: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3763: '</span></fieldset>';
3764: }
3765: $datatable .= '</td></tr>'."\n";
3766: $rownum ++;
3767: }
1.28 raeburn 3768: }
1.286 raeburn 3769: if ($position eq 'middle') {
3770: my %choices;
1.340 raeburn 3771: my $corelink = &core_link_msu();
3772: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 3773: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 3774: $corelink);
3775: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
3776: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 3777: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 3778: 'reportupdates' => 'on',
3779: 'reportstatus' => 'on');
1.286 raeburn 3780: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3781: \%choices,$rownum);
3782: $datatable .= $reports;
1.340 raeburn 3783: } elsif ($position eq 'lower') {
3784: $css_class = $rownum%2?' class="LC_odd_row"':'';
3785: my ($threshold,$sysmail,%excluded,%weights);
3786: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
3787: if ($lonstatus{'threshold'} =~ /^\d+$/) {
3788: $threshold = $lonstatus{'threshold'};
3789: } else {
3790: $threshold = $defaults->{'threshold'};
3791: }
3792: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
3793: $sysmail = $lonstatus{'sysmail'};
3794: } else {
3795: $sysmail = $defaults->{'sysmail'};
3796: }
3797: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 3798: foreach my $type ('E','W','N','U') {
1.340 raeburn 3799: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
3800: $weights{$type} = $lonstatus{'weights'}{$type};
3801: } else {
3802: $weights{$type} = $defaults->{$type};
3803: }
3804: }
3805: } else {
1.341 raeburn 3806: foreach my $type ('E','W','N','U') {
1.340 raeburn 3807: $weights{$type} = $defaults->{$type};
3808: }
3809: }
3810: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
3811: if (@{$lonstatus{'excluded'}} > 0) {
3812: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
3813: }
3814: }
3815: $datatable .= '<tr'.$css_class.'>'.
3816: '<td class="LC_left_item"><span class="LC_nobreak">'.
3817: $titles->{'errorthreshold'}.
3818: '</span></td><td class="LC_left_item">'.
3819: '<input type="text" name="errorthreshold" value="'.
3820: $threshold.'" size="5" /></td></tr>';
3821: $rownum ++;
3822: $css_class = $rownum%2?' class="LC_odd_row"':'';
3823: $datatable .= '<tr'.$css_class.'>'.
3824: '<td class="LC_left_item">'.
3825: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
3826: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 3827: foreach my $type ('E','W','N','U') {
1.340 raeburn 3828: $datatable .= '<td>'.$names->{$type}.'<br />'.
3829: '<input type="text" name="errorweights_'.$type.'" value="'.
3830: $weights{$type}.'" size="5" /></td>';
3831: }
3832: $datatable .= '</tr></table></tr>';
3833: $rownum ++;
3834: $css_class = $rownum%2?' class="LC_odd_row"':'';
3835: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
3836: $titles->{'errorexcluded'}.'</td>'.
3837: '<td class="LC_left_item"><table>';
3838: my $numinrow = 4;
3839: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
3840: for (my $i=0; $i<@ids; $i++) {
3841: my $rem = $i%($numinrow);
3842: if ($rem == 0) {
3843: if ($i > 0) {
3844: $datatable .= '</tr>';
3845: }
3846: $datatable .= '<tr>';
3847: }
3848: my $check;
3849: if ($excluded{$ids[$i]}) {
3850: $check = ' checked="checked" ';
3851: }
3852: $datatable .= '<td class="LC_left_item">'.
3853: '<span class="LC_nobreak"><label>'.
3854: '<input type="checkbox" name="errorexcluded" '.
3855: 'value="'.$ids[$i].'"'.$check.' />'.
3856: $ids[$i].'</label></span></td>';
3857: }
3858: my $colsleft = $numinrow - @ids%($numinrow);
3859: if ($colsleft > 1 ) {
3860: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3861: ' </td>';
3862: } elsif ($colsleft == 1) {
3863: $datatable .= '<td class="LC_left_item"> </td>';
3864: }
3865: $datatable .= '</tr></table></td></tr>';
3866: $rownum ++;
3867: $css_class = $rownum%2?' class="LC_odd_row"':'';
3868: $datatable .= '<tr'.$css_class.'>'.
3869: '<td class="LC_left_item"><span class="LC_nobreak">'.
3870: $titles->{'errorsysmail'}.
3871: '</span></td><td class="LC_left_item">'.
3872: '<input type="text" name="errorsysmail" value="'.
3873: $sysmail.'" size="5" /></td></tr>';
3874: $rownum ++;
1.286 raeburn 3875: } elsif ($position eq 'bottom') {
1.315 raeburn 3876: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3877: my (@posstypes,%usertypeshash);
3878: if (ref($types) eq 'ARRAY') {
3879: @posstypes = @{$types};
3880: }
3881: if (@posstypes) {
3882: if (ref($usertypes) eq 'HASH') {
3883: %usertypeshash = %{$usertypes};
3884: }
3885: my @overridden;
3886: my $numinrow = 4;
3887: if (ref($settings) eq 'HASH') {
3888: if (ref($settings->{'overrides'}) eq 'HASH') {
3889: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3890: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3891: push(@overridden,$key);
3892: foreach my $item (@contacts) {
3893: if ($settings->{'overrides'}{$key}{$item}) {
3894: $checked{'override_'.$key}{$item} = ' checked="checked" ';
3895: }
3896: }
3897: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3898: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3899: $includeloc{'override_'.$key} = '';
3900: $includestr{'override_'.$key} = '';
3901: if ($settings->{'overrides'}{$key}{'include'} ne '') {
3902: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3903: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3904: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3905: }
1.286 raeburn 3906: }
3907: }
3908: }
1.315 raeburn 3909: }
3910: my $customclass = 'LC_helpdesk_override';
3911: my $optionsprefix = 'LC_options_helpdesk_';
3912:
3913: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3914:
3915: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3916: $numinrow,$othertitle,'overrides',
3917: \$rownum,$onclicktypes,$customclass);
3918: $rownum ++;
3919: $usertypeshash{'default'} = $othertitle;
3920: foreach my $status (@posstypes) {
3921: my $css_class;
3922: if ($rownum%2) {
3923: $css_class = 'LC_odd_row ';
3924: }
3925: $css_class .= $customclass;
3926: my $rowid = $optionsprefix.$status;
3927: my $hidden = 1;
3928: my $currstyle = 'display:none';
3929: if (grep(/^\Q$status\E$/,@overridden)) {
3930: $currstyle = 'display:table-row';
3931: $hidden = 0;
3932: }
3933: my $key = 'override_'.$status;
3934: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3935: $includeloc{$key},$includestr{$key},$status,$rowid,
3936: $usertypeshash{$status},$css_class,$currstyle,
3937: \@contacts,$short_titles);
3938: unless ($hidden) {
3939: $rownum ++;
1.286 raeburn 3940: }
3941: }
1.134 raeburn 3942: }
1.28 raeburn 3943: }
1.30 raeburn 3944: $$rowtotal += $rownum;
1.28 raeburn 3945: return $datatable;
3946: }
3947:
1.340 raeburn 3948: sub core_link_msu {
3949: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3950: &mt('LON-CAPA core group - MSU'),600,500);
3951: }
3952:
1.315 raeburn 3953: sub overridden_helpdesk {
3954: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3955: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3956: my $class = 'LC_left_item';
3957: if ($css_class) {
3958: $css_class = ' class="'.$css_class.'"';
3959: }
3960: if ($rowid) {
3961: $rowid = ' id="'.$rowid.'"';
3962: }
3963: if ($rowstyle) {
3964: $rowstyle = ' style="'.$rowstyle.'"';
3965: }
3966: my ($output,$description);
3967: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3968: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3969: "<td>$description</td>\n".
3970: '<td class="'.$class.'" colspan="2">'.
3971: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3972: '<span class="LC_nobreak">';
3973: if (ref($contacts) eq 'ARRAY') {
3974: foreach my $item (@{$contacts}) {
3975: my $check;
3976: if (ref($checked) eq 'HASH') {
3977: $check = $checked->{$item};
3978: }
3979: my $title;
3980: if (ref($short_titles) eq 'HASH') {
3981: $title = $short_titles->{$item};
3982: }
3983: $output .= '<label>'.
3984: '<input type="checkbox" name="override_'.$type.'"'.$check.
3985: ' value="'.$item.'" />'.$title.'</label> ';
3986: }
3987: }
3988: $output .= '</span><br />'.&mt('Others').': '.
3989: '<input type="text" name="override_'.$type.'_others" '.
3990: 'value="'.$otheremails.'" />';
3991: my %locchecked;
3992: foreach my $loc ('s','b') {
3993: if ($includeloc eq $loc) {
3994: $locchecked{$loc} = ' checked="checked"';
3995: last;
3996: }
3997: }
3998: $output .= '<br />'.&mt('Bcc:').(' 'x6).
3999: '<input type="text" name="override_'.$type.'_bcc" '.
4000: 'value="'.$bccemails.'" /></fieldset>'.
4001: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4002: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4003: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 4004: '<span class="LC_nobreak">'.&mt('Location:').' '.
4005: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4006: (' 'x2).
4007: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4008: '</span></fieldset>'.
4009: '</td></tr>'."\n";
4010: return $output;
4011: }
4012:
1.286 raeburn 4013: sub contacts_javascript {
4014: return <<"ENDSCRIPT";
4015:
4016: <script type="text/javascript">
4017: // <![CDATA[
4018:
4019: function screenshotSize(field) {
4020: if (document.getElementById('help_screenshotsize')) {
4021: if (field.value == 'no') {
1.289 raeburn 4022: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 4023: } else {
4024: document.getElementById('help_screenshotsize').style.display="";
4025: }
4026: }
4027: return;
4028: }
4029:
1.315 raeburn 4030: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4031: if (form.elements[checkbox].length != undefined) {
4032: var count = 0;
4033: if (docount) {
4034: for (var i=0; i<form.elements[checkbox].length; i++) {
4035: if (form.elements[checkbox][i].checked) {
4036: count ++;
4037: }
4038: }
4039: }
4040: for (var i=0; i<form.elements[checkbox].length; i++) {
4041: var type = form.elements[checkbox][i].value;
4042: if (document.getElementById(prefix+type)) {
4043: if (form.elements[checkbox][i].checked) {
4044: document.getElementById(prefix+type).style.display = 'table-row';
4045: if (count % 2 == 1) {
4046: document.getElementById(prefix+type).className = target+' LC_odd_row';
4047: } else {
4048: document.getElementById(prefix+type).className = target;
4049: }
4050: count ++;
4051: } else {
4052: document.getElementById(prefix+type).style.display = 'none';
4053: }
4054: }
4055: }
4056: }
4057: return;
4058: }
4059:
4060:
1.286 raeburn 4061: // ]]>
4062: </script>
4063:
4064: ENDSCRIPT
4065: }
4066:
1.118 jms 4067: sub print_helpsettings {
1.282 raeburn 4068: my ($position,$dom,$settings,$rowtotal) = @_;
4069: my $confname = $dom.'-domainconfig';
1.285 raeburn 4070: my $formname = 'display';
1.168 raeburn 4071: my ($datatable,$itemcount);
1.282 raeburn 4072: if ($position eq 'top') {
4073: $itemcount = 1;
4074: my (%choices,%defaultchecked,@toggles);
4075: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4076: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4077: &mt('LON-CAPA bug tracker'),600,500));
4078: %defaultchecked = ('submitbugs' => 'on');
4079: @toggles = ('submitbugs');
4080: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4081: \%choices,$itemcount);
4082: $$rowtotal ++;
4083: } else {
4084: my $css_class;
4085: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 4086: my (%customroles,%ordered,%current);
1.301 raeburn 4087: if (ref($settings) eq 'HASH') {
4088: if (ref($settings->{'adhoc'}) eq 'HASH') {
4089: %current = %{$settings->{'adhoc'}};
4090: }
1.285 raeburn 4091: }
4092: my $count = 0;
4093: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 4094: if ($key=~/^rolesdef\_(\w+)$/) {
4095: my $rolename = $1;
1.285 raeburn 4096: my (%privs,$order);
1.282 raeburn 4097: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4098: $customroles{$rolename} = \%privs;
1.285 raeburn 4099: if (ref($current{$rolename}) eq 'HASH') {
4100: $order = $current{$rolename}{'order'};
4101: }
4102: if ($order eq '') {
4103: $order = $count;
4104: }
4105: $ordered{$order} = $rolename;
4106: $count++;
4107: }
4108: }
4109: my $maxnum = scalar(keys(%ordered));
4110: my @roles_by_num = ();
4111: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4112: push(@roles_by_num,$item);
4113: }
4114: my $context = 'domprefs';
4115: my $crstype = 'Course';
4116: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 4117: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 4118: my ($numstatustypes,@jsarray);
4119: if (ref($types) eq 'ARRAY') {
4120: if (@{$types} > 0) {
4121: $numstatustypes = scalar(@{$types});
4122: push(@accesstypes,'status');
4123: @jsarray = ('bystatus');
1.282 raeburn 4124: }
4125: }
1.290 raeburn 4126: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 4127: if (keys(%domhelpdesk)) {
4128: push(@accesstypes,('inc','exc'));
4129: push(@jsarray,('notinc','notexc'));
4130: }
4131: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 4132: my $context = 'domprefs';
4133: my $crstype = 'Course';
1.285 raeburn 4134: my $prefix = 'helproles_';
4135: my $add_class = 'LC_hidden';
4136: foreach my $num (@roles_by_num) {
4137: my $role = $ordered{$num};
4138: my ($desc,$access,@statuses);
4139: if (ref($current{$role}) eq 'HASH') {
4140: $desc = $current{$role}{'desc'};
4141: $access = $current{$role}{'access'};
4142: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4143: @statuses = @{$current{$role}{'insttypes'}};
4144: }
4145: }
4146: if ($desc eq '') {
4147: $desc = $role;
4148: }
4149: my $identifier = 'custhelp'.$num;
1.282 raeburn 4150: my %full=();
4151: my %levels= (
4152: course => {},
4153: domain => {},
4154: system => {},
4155: );
4156: my %levelscurrent=(
4157: course => {},
4158: domain => {},
4159: system => {},
4160: );
4161: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4162: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4163: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 4164: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 4165: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 4166: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4167: for (my $k=0; $k<=$maxnum; $k++) {
4168: my $vpos = $k+1;
4169: my $selstr;
4170: if ($k == $num) {
4171: $selstr = ' selected="selected" ';
4172: }
4173: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4174: }
4175: $datatable .= '</select>'.(' 'x2).
4176: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4177: '</td>'.
4178: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4179: &mt('Name shown to users:').
4180: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4181: '</fieldset>'.
4182: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4183: $othertitle,$usertypes,$types,\%domhelpdesk).
4184: '<fieldset>'.
4185: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 4186: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 4187: \%levelscurrent,$identifier,
4188: 'LC_hidden',$prefix.$num.'_privs').
4189: '</fieldset></td>';
1.282 raeburn 4190: $itemcount ++;
4191: }
4192: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4193: my $newcust = 'custhelp'.$count;
4194: my (%privs,%levelscurrent);
4195: my %full=();
4196: my %levels= (
4197: course => {},
4198: domain => {},
4199: system => {},
4200: );
4201: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4202: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 4203: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 4204: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 4205: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4206: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4207: for (my $k=0; $k<$maxnum+1; $k++) {
4208: my $vpos = $k+1;
4209: my $selstr;
4210: if ($k == $maxnum) {
4211: $selstr = ' selected="selected" ';
4212: }
4213: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4214: }
4215: $datatable .= '</select> '."\n".
1.282 raeburn 4216: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4217: '</label></span></td>'.
1.285 raeburn 4218: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4219: '<span class="LC_nobreak">'.
4220: &mt('Internal name:').
4221: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4222: '</span>'.(' 'x4).
4223: '<span class="LC_nobreak">'.
4224: &mt('Name shown to users:').
4225: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4226: '</span></fieldset>'.
4227: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4228: $usertypes,$types,\%domhelpdesk).
4229: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 4230: &Apache::lonuserutils::custom_role_header($context,$crstype,
4231: \@templateroles,$newcust).
4232: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4233: \%levelscurrent,$newcust).
1.334 raeburn 4234: '</fieldset>'.
4235: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4236: '</td></tr>';
1.282 raeburn 4237: $count ++;
4238: $$rowtotal += $count;
4239: }
1.166 raeburn 4240: return $datatable;
1.121 raeburn 4241: }
4242:
1.285 raeburn 4243: sub adhocbutton {
4244: my ($prefix,$num,$field,$visibility) = @_;
4245: my %lt = &Apache::lonlocal::texthash(
4246: show => 'Show details',
4247: hide => 'Hide details',
4248: );
4249: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4250: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4251: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4252: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4253: }
4254:
4255: sub helpsettings_javascript {
4256: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4257: return unless(ref($roles_by_num) eq 'ARRAY');
4258: my %html_js_lt = &Apache::lonlocal::texthash(
4259: show => 'Show details',
4260: hide => 'Hide details',
4261: );
4262: &html_escape(\%html_js_lt);
4263: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4264: return <<"ENDSCRIPT";
4265: <script type="text/javascript">
4266: // <![CDATA[
4267:
4268: function reorderHelpRoles(form,item) {
4269: var changedVal;
4270: $jstext
4271: var newpos = 'helproles_${total}_pos';
4272: var maxh = 1 + $total;
4273: var current = new Array();
4274: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4275: if (item == newpos) {
4276: changedVal = newitemVal;
4277: } else {
4278: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4279: current[newitemVal] = newpos;
4280: }
4281: for (var i=0; i<helproles.length; i++) {
4282: var elementName = 'helproles_'+helproles[i]+'_pos';
4283: if (elementName != item) {
4284: if (form.elements[elementName]) {
4285: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4286: current[currVal] = elementName;
4287: }
4288: }
4289: }
4290: var oldVal;
4291: for (var j=0; j<maxh; j++) {
4292: if (current[j] == undefined) {
4293: oldVal = j;
4294: }
4295: }
4296: if (oldVal < changedVal) {
4297: for (var k=oldVal+1; k<=changedVal ; k++) {
4298: var elementName = current[k];
4299: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4300: }
4301: } else {
4302: for (var k=changedVal; k<oldVal; k++) {
4303: var elementName = current[k];
4304: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4305: }
4306: }
4307: return;
4308: }
4309:
4310: function helpdeskAccess(num) {
4311: var curraccess = null;
4312: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4313: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4314: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4315: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4316: }
4317: }
4318: }
4319: var shown = Array();
4320: var hidden = Array();
4321: if (curraccess == 'none') {
4322: hidden = Array('$hiddenstr');
4323: } else {
4324: if (curraccess == 'status') {
4325: shown = Array('bystatus');
4326: hidden = Array('notinc','notexc');
4327: } else {
4328: if (curraccess == 'exc') {
4329: shown = Array('notexc');
4330: hidden = Array('notinc','bystatus');
4331: }
4332: if (curraccess == 'inc') {
4333: shown = Array('notinc');
4334: hidden = Array('notexc','bystatus');
4335: }
1.293 raeburn 4336: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 4337: hidden = Array('notinc','notexc','bystatus');
4338: }
4339: }
4340: }
4341: if (hidden.length > 0) {
4342: for (var i=0; i<hidden.length; i++) {
4343: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4344: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4345: }
4346: }
4347: }
4348: if (shown.length > 0) {
4349: for (var i=0; i<shown.length; i++) {
4350: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4351: if (shown[i] == 'privs') {
4352: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4353: } else {
4354: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4355: }
4356: }
4357: }
4358: }
4359: return;
4360: }
4361:
4362: function toggleHelpdeskItem(num,field) {
4363: if (document.getElementById('helproles_'+num+'_'+field)) {
4364: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 4365: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 4366: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4367: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4368: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4369: }
4370: } else {
4371: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4372: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4373: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4374: }
4375: }
4376: }
4377: return;
4378: }
4379:
4380: // ]]>
4381: </script>
4382:
4383: ENDSCRIPT
4384: }
4385:
4386: sub helpdeskroles_access {
4387: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4388: $usertypes,$types,$domhelpdesk) = @_;
4389: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4390: my %lt = &Apache::lonlocal::texthash(
4391: 'rou' => 'Role usage',
4392: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 4393: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4394: 'dh' => 'All with domain helpdesk role',
4395: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 4396: 'none' => 'None',
4397: 'status' => 'Determined based on institutional status',
4398: 'inc' => 'Include all, but exclude specific personnel',
4399: 'exc' => 'Exclude all, but include specific personnel',
4400: );
4401: my %usecheck = (
4402: all => ' checked="checked"',
4403: );
4404: my %displaydiv = (
4405: status => 'none',
4406: inc => 'none',
4407: exc => 'none',
4408: priv => 'block',
4409: );
4410: my $output;
4411: if (ref($current) eq 'HASH') {
4412: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4413: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4414: $usecheck{$current->{access}} = $usecheck{'all'};
4415: delete($usecheck{'all'});
4416: if ($current->{access} =~ /^(status|inc|exc)$/) {
4417: my $access = $1;
4418: $displaydiv{$access} = 'inline';
4419: } elsif ($current->{access} eq 'none') {
4420: $displaydiv{'priv'} = 'none';
4421: }
4422: }
4423: }
4424: }
4425: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4426: '<p>'.$lt{'whi'}.'</p>';
4427: foreach my $access (@{$accesstypes}) {
4428: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4429: ' onclick="helpdeskAccess('."'$num'".');" />'.
4430: $lt{$access}.'</label>';
4431: if ($access eq 'status') {
4432: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4433: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4434: $othertitle,$usertypes,$types).
4435: '</div>';
4436: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4437: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4438: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4439: '</div>';
4440: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4441: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4442: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4443: '</div>';
4444: }
4445: $output .= '</p>';
4446: }
4447: $output .= '</fieldset>';
4448: return $output;
4449: }
4450:
1.121 raeburn 4451: sub radiobutton_prefs {
1.192 raeburn 4452: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 4453: $additional,$align) = @_;
1.121 raeburn 4454: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4455: (ref($choices) eq 'HASH'));
4456:
1.170 raeburn 4457: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 4458:
4459: foreach my $item (@{$toggles}) {
4460: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4461: $checkedon{$item} = ' checked="checked" ';
4462: $checkedoff{$item} = ' ';
1.121 raeburn 4463: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4464: $checkedoff{$item} = ' checked="checked" ';
4465: $checkedon{$item} = ' ';
4466: }
4467: }
4468: if (ref($settings) eq 'HASH') {
1.121 raeburn 4469: foreach my $item (@{$toggles}) {
1.118 jms 4470: if ($settings->{$item} eq '1') {
4471: $checkedon{$item} = ' checked="checked" ';
4472: $checkedoff{$item} = ' ';
4473: } elsif ($settings->{$item} eq '0') {
4474: $checkedoff{$item} = ' checked="checked" ';
4475: $checkedon{$item} = ' ';
4476: }
4477: }
1.121 raeburn 4478: }
1.192 raeburn 4479: if ($onclick) {
4480: $onclick = ' onclick="'.$onclick.'"';
4481: }
1.121 raeburn 4482: foreach my $item (@{$toggles}) {
1.118 jms 4483: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4484: $datatable .=
1.306 raeburn 4485: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 4486: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 4487: '</span></td>';
4488: if ($align eq 'left') {
4489: $datatable .= '<td class="LC_left_item">';
4490: } else {
4491: $datatable .= '<td class="LC_right_item">';
4492: }
1.289 raeburn 4493: $datatable .=
1.257 raeburn 4494: '<span class="LC_nobreak">'.
1.118 jms 4495: '<label><input type="radio" name="'.
1.192 raeburn 4496: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 4497: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 4498: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
4499: '</span>'.$additional.
4500: '</td>'.
1.118 jms 4501: '</tr>';
4502: $itemcount ++;
1.121 raeburn 4503: }
4504: return ($datatable,$itemcount);
4505: }
4506:
1.267 raeburn 4507: sub print_ltitools {
4508: my ($dom,$settings,$rowtotal) = @_;
4509: my $rownum = 0;
4510: my $css_class;
4511: my $itemcount = 1;
4512: my $maxnum = 0;
4513: my %ordered;
4514: if (ref($settings) eq 'HASH') {
4515: foreach my $item (keys(%{$settings})) {
4516: if (ref($settings->{$item}) eq 'HASH') {
4517: my $num = $settings->{$item}{'order'};
4518: $ordered{$num} = $item;
4519: }
4520: }
4521: }
4522: my $confname = $dom.'-domainconfig';
4523: my $switchserver = &check_switchserver($dom,$confname);
4524: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 4525: my $datatable;
1.267 raeburn 4526: my %lt = <itools_names();
4527: my @courseroles = ('cc','in','ta','ep','st');
4528: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.324 raeburn 4529: my @fields = ('fullname','firstname','lastname','email','roles','user');
1.267 raeburn 4530: if (keys(%ordered)) {
4531: my @items = sort { $a <=> $b } keys(%ordered);
4532: for (my $i=0; $i<@items; $i++) {
4533: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4534: my $item = $ordered{$items[$i]};
1.323 raeburn 4535: my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267 raeburn 4536: if (ref($settings->{$item}) eq 'HASH') {
4537: $title = $settings->{$item}->{'title'};
4538: $url = $settings->{$item}->{'url'};
4539: $key = $settings->{$item}->{'key'};
4540: $secret = $settings->{$item}->{'secret'};
1.322 raeburn 4541: $lifetime = $settings->{$item}->{'lifetime'};
1.267 raeburn 4542: my $image = $settings->{$item}->{'image'};
4543: if ($image ne '') {
4544: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
4545: }
1.323 raeburn 4546: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
4547: $sigsel{'HMAC-256'} = ' selected="selected"';
4548: } else {
4549: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
4550: }
1.267 raeburn 4551: }
1.319 raeburn 4552: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267 raeburn 4553: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4554: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
4555: for (my $k=0; $k<=$maxnum; $k++) {
4556: my $vpos = $k+1;
4557: my $selstr;
4558: if ($k == $i) {
4559: $selstr = ' selected="selected" ';
4560: }
4561: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4562: }
4563: $datatable .= '</select>'.(' 'x2).
4564: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4565: &mt('Delete?').'</label></span></td>'.
4566: '<td colspan="2">'.
4567: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4568: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267 raeburn 4569: (' 'x2).
4570: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4571: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4572: (' 'x2).
4573: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4574: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4575: (' 'x2).
4576: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
4577: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
4578: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267 raeburn 4579: '<br /><br />'.
1.323 raeburn 4580: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267 raeburn 4581: ' value="'.$url.'" /></span>'.
4582: (' 'x2).
1.319 raeburn 4583: '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267 raeburn 4584: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4585: (' 'x2).
1.322 raeburn 4586: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
4587: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
4588: (' 'x2).
1.267 raeburn 4589: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4590: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4591: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltitools_secret_'.$i.'.type='."'text'".' } else { this.form.ltitools_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
4592: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4593: '</fieldset>'.
4594: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4595: '<span class="LC_nobreak">'.&mt('Display target:');
4596: my %currdisp;
4597: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4598: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4599: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 4600: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4601: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 4602: } else {
4603: $currdisp{'iframe'} = ' checked="checked"';
4604: }
4605: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4606: $currdisp{'width'} = $1;
4607: }
4608: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4609: $currdisp{'height'} = $1;
4610: }
1.296 raeburn 4611: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4612: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 4613: } else {
4614: $currdisp{'iframe'} = ' checked="checked"';
4615: }
1.298 raeburn 4616: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4617: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4618: $lt{$disp}.'</label>'.(' 'x2);
4619: }
4620: $datatable .= (' 'x4);
4621: foreach my $dimen ('width','height') {
4622: $datatable .= '<label>'.$lt{$dimen}.' '.
4623: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4624: (' 'x2);
4625: }
1.334 raeburn 4626: $datatable .= '</span><br />'.
1.296 raeburn 4627: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 4628: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
1.296 raeburn 4629: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4630: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
4631: '</textarea></div><div style=""></div><br />';
1.319 raeburn 4632: my %units = (
4633: 'passback' => 'days',
4634: 'roster' => 'seconds',
4635: );
1.267 raeburn 4636: foreach my $extra ('passback','roster') {
1.319 raeburn 4637: my $validsty = 'none';
4638: my $currvalid;
1.267 raeburn 4639: my $checkedon = '';
4640: my $checkedoff = ' checked="checked"';
4641: if ($settings->{$item}->{$extra}) {
4642: $checkedon = $checkedoff;
4643: $checkedoff = '';
1.319 raeburn 4644: $validsty = 'inline-block';
4645: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
4646: $currvalid = $settings->{$item}->{$extra.'valid'};
4647: }
4648: }
4649: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
4650: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4651: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
4652: &mt('No').'</label>'.(' 'x2).
4653: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
4654: &mt('Yes').'</label></span></div>'.
4655: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
4656: '<span class="LC_nobreak">'.
4657: &mt("at least [_1] $units{$extra} after launch",
4658: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
4659: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4660: }
1.319 raeburn 4661: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
1.267 raeburn 4662: if ($imgsrc) {
4663: $datatable .= $imgsrc.
4664: '<label><input type="checkbox" name="ltitools_image_del"'.
4665: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
4666: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
4667: } else {
4668: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4669: }
4670: if ($switchserver) {
4671: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4672: } else {
4673: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
4674: }
4675: $datatable .= '</span></fieldset>';
1.324 raeburn 4676: my (%checkedfields,%rolemaps,$userincdom);
1.267 raeburn 4677: if (ref($settings->{$item}) eq 'HASH') {
4678: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
4679: %checkedfields = %{$settings->{$item}->{'fields'}};
4680: }
1.324 raeburn 4681: $userincdom = $settings->{$item}->{'incdom'};
1.267 raeburn 4682: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
4683: %rolemaps = %{$settings->{$item}->{'roles'}};
4684: $checkedfields{'roles'} = 1;
4685: }
4686: }
4687: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4688: '<span class="LC_nobreak">';
1.324 raeburn 4689: my $userfieldstyle = 'display:none;';
4690: my $seluserdom = '';
4691: my $unseluserdom = ' selected="selected"';
1.267 raeburn 4692: foreach my $field (@fields) {
1.324 raeburn 4693: my ($checked,$onclick,$id,$spacer);
1.267 raeburn 4694: if ($checkedfields{$field}) {
4695: $checked = ' checked="checked"';
4696: }
1.324 raeburn 4697: if ($field eq 'user') {
4698: $id = ' id="ltitools_user_field_'.$i.'"';
4699: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
4700: if ($checked) {
4701: $userfieldstyle = 'display:inline-block';
4702: if ($userincdom) {
4703: $seluserdom = $unseluserdom;
4704: $unseluserdom = '';
4705: }
4706: }
4707: } else {
4708: $spacer = (' ' x2);
4709: }
1.267 raeburn 4710: $datatable .= '<label>'.
1.324 raeburn 4711: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
4712: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4713: }
1.324 raeburn 4714: $datatable .= '</span>';
4715: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
4716: '<span class="LC_nobreak"> : '.
4717: '<select name="ltitools_userincdom_'.$i.'">'.
4718: '<option value="">'.&mt('Select').'</option>'.
4719: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
4720: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
4721: '</select></span></div>';
4722: $datatable .= '</fieldset>'.
1.267 raeburn 4723: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4724: foreach my $role (@courseroles) {
4725: my ($selected,$selectnone);
4726: if (!$rolemaps{$role}) {
4727: $selectnone = ' selected="selected"';
4728: }
1.306 raeburn 4729: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4730: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4731: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
4732: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4733: foreach my $ltirole (@ltiroles) {
4734: unless ($selectnone) {
4735: if ($rolemaps{$role} eq $ltirole) {
4736: $selected = ' selected="selected"';
4737: } else {
4738: $selected = '';
4739: }
4740: }
4741: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
4742: }
4743: $datatable .= '</select></td>';
4744: }
1.273 raeburn 4745: $datatable .= '</tr></table></fieldset>';
4746: my %courseconfig;
4747: if (ref($settings->{$item}) eq 'HASH') {
4748: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
4749: %courseconfig = %{$settings->{$item}->{'crsconf'}};
4750: }
4751: }
4752: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4753: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 4754: my $checked;
4755: if ($courseconfig{$item}) {
4756: $checked = ' checked="checked"';
4757: }
4758: $datatable .= '<label>'.
4759: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
1.372 raeburn 4760: $lt{'crs'.$item}.'</label> '."\n";
1.273 raeburn 4761: }
4762: $datatable .= '</span></fieldset>'.
1.267 raeburn 4763: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4764: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
4765: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
4766: my %custom = %{$settings->{$item}->{'custom'}};
4767: if (keys(%custom) > 0) {
4768: foreach my $key (sort(keys(%custom))) {
4769: $datatable .= '<tr><td><span class="LC_nobreak">'.
4770: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
4771: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
4772: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
4773: ' value="'.$custom{$key}.'" /></td></tr>';
4774: }
4775: }
4776: }
4777: $datatable .= '<tr><td><span class="LC_nobreak">'.
4778: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
4779: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
4780: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
4781: $datatable .= '</table></fieldset></td></tr>'."\n";
4782: $itemcount ++;
4783: }
4784: }
4785: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319 raeburn 4786: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267 raeburn 4787: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4788: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
4789: '<select name="ltitools_add_pos"'.$chgstr.'>';
4790: for (my $k=0; $k<$maxnum+1; $k++) {
4791: my $vpos = $k+1;
4792: my $selstr;
4793: if ($k == $maxnum) {
4794: $selstr = ' selected="selected" ';
4795: }
4796: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4797: }
4798: $datatable .= '</select> '."\n".
1.334 raeburn 4799: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.267 raeburn 4800: '<td colspan="2">'.
4801: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4802: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267 raeburn 4803: (' 'x2).
4804: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
4805: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4806: (' 'x2).
4807: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
4808: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4809: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
4810: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
4811: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267 raeburn 4812: '<br />'.
1.323 raeburn 4813: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267 raeburn 4814: (' 'x2).
4815: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
4816: (' 'x2).
1.322 raeburn 4817: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
4818: (' 'x2).
1.267 raeburn 4819: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
4820: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltitools_add_secret.type='."'text'".' } else { this.form.ltitools_add_secret.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n".
4821: '</fieldset>'.
4822: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4823: '<span class="LC_nobreak">'.&mt('Display target:');
4824: my %defaultdisp;
4825: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 4826: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4827: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
4828: $lt{$disp}.'</label>'.(' 'x2);
4829: }
4830: $datatable .= (' 'x4);
4831: foreach my $dimen ('width','height') {
4832: $datatable .= '<label>'.$lt{$dimen}.' '.
4833: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
4834: (' 'x2);
4835: }
1.334 raeburn 4836: $datatable .= '</span><br />'.
1.296 raeburn 4837: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 4838: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
1.296 raeburn 4839: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
1.334 raeburn 4840: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
1.296 raeburn 4841: '</div><div style=""></div><br />';
1.319 raeburn 4842: my %units = (
4843: 'passback' => 'days',
4844: 'roster' => 'seconds',
4845: );
4846: my %defaulttimes = (
4847: 'passback' => '7',
1.322 raeburn 4848: 'roster' => '300',
1.319 raeburn 4849: );
1.267 raeburn 4850: foreach my $extra ('passback','roster') {
1.319 raeburn 4851: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
4852: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4853: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
4854: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
4855: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
4856: &mt('Yes').'</label></span></div>'.
4857: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
4858: '<span class="LC_nobreak">'.
4859: &mt("at least [_1] $units{$extra} after launch",
4860: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
4861: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4862: }
1.319 raeburn 4863: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
1.267 raeburn 4864: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4865: if ($switchserver) {
4866: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4867: } else {
4868: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
4869: }
4870: $datatable .= '</span></fieldset>'.
4871: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4872: '<span class="LC_nobreak">';
4873: foreach my $field (@fields) {
1.324 raeburn 4874: my ($id,$onclick,$spacer);
4875: if ($field eq 'user') {
4876: $id = ' id="ltitools_user_field_add"';
4877: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
4878: } else {
4879: $spacer = (' ' x2);
4880: }
1.267 raeburn 4881: $datatable .= '<label>'.
1.324 raeburn 4882: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
4883: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4884: }
1.324 raeburn 4885: $datatable .= '</span>'.
4886: '<div style="display:none;" id="ltitools_user_div_add">'.
4887: '<span class="LC_nobreak"> : '.
4888: '<select name="ltitools_userincdom_add">'.
4889: '<option value="" selected="selected">'.&mt('Select').'</option>'.
4890: '<option value="0">'.&mt('username').'</option>'.
4891: '<option value="1">'.&mt('username:domain').'</option>'.
4892: '</select></span></div></fieldset>';
4893: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1.267 raeburn 4894: foreach my $role (@courseroles) {
4895: my ($checked,$checkednone);
1.306 raeburn 4896: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4897: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4898: '<select name="ltitools_add_roles_'.$role.'">'.
4899: '<option value="" selected="selected">'.&mt('Select').'</option>';
4900: foreach my $ltirole (@ltiroles) {
4901: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
4902: }
4903: $datatable .= '</select></td>';
4904: }
4905: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 4906: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4907: foreach my $item ('label','title','target','linktext','explanation','append') {
1.296 raeburn 4908: $datatable .= '<label>'.
4909: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4910: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 4911: }
4912: $datatable .= '</span></fieldset>'.
1.267 raeburn 4913: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4914: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4915: '<tr><td><span class="LC_nobreak">'.
4916: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4917: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4918: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
1.334 raeburn 4919: '</table></fieldset>'."\n".
1.267 raeburn 4920: '</td>'."\n".
4921: '</tr>'."\n";
4922: $itemcount ++;
4923: return $datatable;
4924: }
4925:
4926: sub ltitools_names {
4927: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 4928: 'title' => 'Title',
4929: 'version' => 'Version',
4930: 'msgtype' => 'Message Type',
1.323 raeburn 4931: 'sigmethod' => 'Signature Method',
1.296 raeburn 4932: 'url' => 'URL',
4933: 'key' => 'Key',
1.322 raeburn 4934: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 4935: 'secret' => 'Secret',
4936: 'icon' => 'Icon',
1.324 raeburn 4937: 'user' => 'User',
1.296 raeburn 4938: 'fullname' => 'Full Name',
4939: 'firstname' => 'First Name',
4940: 'lastname' => 'Last Name',
4941: 'email' => 'E-mail',
4942: 'roles' => 'Role',
1.298 raeburn 4943: 'window' => 'Window',
4944: 'tab' => 'Tab',
1.296 raeburn 4945: 'iframe' => 'iFrame',
4946: 'height' => 'Height',
4947: 'width' => 'Width',
4948: 'linktext' => 'Default Link Text',
4949: 'explanation' => 'Default Explanation',
4950: 'passback' => 'Tool can return grades:',
4951: 'roster' => 'Tool can retrieve roster:',
4952: 'crstarget' => 'Display target',
4953: 'crslabel' => 'Course label',
4954: 'crstitle' => 'Course title',
4955: 'crslinktext' => 'Link Text',
4956: 'crsexplanation' => 'Explanation',
1.318 raeburn 4957: 'crsappend' => 'Provider URL',
1.267 raeburn 4958: );
4959: return %lt;
4960: }
4961:
1.372 raeburn 4962: sub print_proctoring {
4963: my ($dom,$settings,$rowtotal) = @_;
4964: my $itemcount = 1;
4965: my (%ordered,%providernames,%current,%currentdef);
4966: my $confname = $dom.'-domainconfig';
4967: my $switchserver = &check_switchserver($dom,$confname);
4968: if (ref($settings) eq 'HASH') {
4969: foreach my $item (keys(%{$settings})) {
4970: if (ref($settings->{$item}) eq 'HASH') {
4971: my $num = $settings->{$item}{'order'};
4972: $ordered{$num} = $item;
4973: }
4974: }
4975: } else {
4976: %ordered = (
4977: 1 => 'proctorio',
4978: 2 => 'examity',
4979: );
4980: }
4981: %providernames = &proctoring_providernames();
4982: my $maxnum = scalar(keys(%ordered));
4983: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
4984: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
4985: if (ref($requref) eq 'HASH') {
4986: %requserfields = %{$requref};
4987: }
4988: if (ref($opturef) eq 'HASH') {
4989: %optuserfields = %{$opturef};
4990: }
4991: if (ref($defref) eq 'HASH') {
4992: %defaults = %{$defref};
4993: }
4994: if (ref($extref) eq 'HASH') {
4995: %extended = %{$extref};
4996: }
4997: if (ref($crsref) eq 'HASH') {
4998: %crsconf = %{$crsref};
4999: }
5000: if (ref($rolesref) eq 'ARRAY') {
5001: @courseroles = @{$rolesref};
5002: }
5003: if (ref($ltiref) eq 'ARRAY') {
5004: @ltiroles = @{$ltiref};
5005: }
5006: my $datatable;
5007: my $css_class;
5008: if (keys(%ordered)) {
5009: my @items = sort { $a <=> $b } keys(%ordered);
5010: for (my $i=0; $i<@items; $i++) {
5011: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5012: my $provider = $ordered{$items[$i]};
5013: my $optionsty = 'none';
5014: my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
5015: %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
5016: if (ref($settings) eq 'HASH') {
5017: if (ref($settings->{$provider}) eq 'HASH') {
5018: %current = %{$settings->{$provider}};
5019: if ($current{'available'}) {
5020: $optionsty = 'block';
5021: $available = 1;
5022: }
5023: if ($current{'lifetime'} =~ /^\d+$/) {
5024: $lifetime = $current{'lifetime'};
5025: }
5026: if ($current{'version'} =~ /^\d+\.\d+$/) {
5027: $version = $current{'version'};
5028: }
5029: if ($current{'image'} ne '') {
5030: $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
5031: }
5032: if (ref($current{'fields'}) eq 'ARRAY') {
5033: map { $checkedfields{$_} = 1; } @{$current{'fields'}};
5034: }
5035: $userincdom = $current{'incdom'};
5036: if (ref($current{'roles'}) eq 'HASH') {
5037: %rolemaps = %{$current{'roles'}};
5038: $checkedfields{'roles'} = 1;
5039: }
5040: if (ref($current{'defaults'}) eq 'ARRAY') {
5041: foreach my $val (@{$current{'defaults'}}) {
5042: if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
5043: $inuse{$val} = 1;
5044: } else {
5045: foreach my $poss (keys(%{$extended{$provider}})) {
5046: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5047: if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
5048: $inuse{$poss} = $val;
5049: last;
5050: }
5051: }
5052: }
5053: }
5054: }
5055: } elsif (ref($current{'defaults'}) eq 'HASH') {
5056: foreach my $key (keys(%{$current{'defaults'}})) {
5057: my $currval = $current{'defaults'}{$key};
5058: if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
5059: $inuse{$key} = 1;
5060: } else {
5061: my $match;
5062: foreach my $poss (keys(%{$extended{$provider}})) {
5063: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5064: if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
5065: $inuse{$poss} = $key;
5066: last;
5067: }
5068: } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
5069: foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
5070: if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
5071: if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
5072: $currentdef{$inner} = $currval;
5073: $match = 1;
5074: last;
5075: }
5076: } elsif ($inner eq $key) {
5077: $currentdef{$key} = $currval;
5078: $match = 1;
5079: last;
5080: }
5081: }
5082: }
5083: last if ($match);
5084: }
5085: }
5086: }
5087: }
5088: if (ref($current{'crsconf'}) eq 'ARRAY') {
5089: map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
5090: }
5091: }
5092: }
5093: my %lt = &proctoring_titles($provider);
5094: my %fieldtitles = &proctoring_fieldtitles($provider);
5095: my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
5096: my %checkedavailable = (
5097: yes => '',
5098: no => ' checked="checked"',
5099: );
5100: if ($available) {
5101: $checkedavailable{'yes'} = $checkedavailable{'no'};
5102: $checkedavailable{'no'} = '';
5103: }
5104: my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
5105: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5106: .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
5107: for (my $k=0; $k<$maxnum; $k++) {
5108: my $vpos = $k+1;
5109: my $selstr;
5110: if ($k == $i) {
5111: $selstr = ' selected="selected" ';
5112: }
5113: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5114: }
5115: if ($version eq '') {
5116: if ($provider eq 'proctorio') {
5117: $version = '1.0';
5118: } elsif ($provider eq 'examity') {
5119: $version = '1.1';
5120: }
5121: }
5122: if ($lifetime eq '') {
5123: $lifetime = '300';
5124: }
5125: $datatable .=
5126: '</select>'.(' 'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
5127: '<span class="LC_nobreak">'.$lt{'avai'}.' '.
5128: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label> '."\n".
5129: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
5130: '</td>'.
5131: '<td colspan="2">'.
5132: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
5133: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
5134: '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
5135: (' 'x2).
5136: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
5137: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5138: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5139: (' 'x2).
5140: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
5141: '<br />'.
5142: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
5143: '<br />'.
5144: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
5145: (' 'x2).
5146: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
5147: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.proctoring_'.$provider.'_secret.type='."'text'".' } else { this.form.proctoring_'.$provider.'_secret.type='."'password'".' }" />'.$lt{'visible'}.'</label></span><br />'."\n";
5148: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
5149: if ($imgsrc) {
5150: $datatable .= $imgsrc.
5151: '<label><input type="checkbox" name="proctoring_image_del"'.
5152: ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
5153: '<span class="LC_nobreak"> '.&mt('Replace:');
5154: }
5155: $datatable .= ' ';
5156: if ($switchserver) {
5157: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5158: } else {
5159: $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
5160: }
5161: unless ($imgsrc) {
5162: $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
5163: }
5164: $datatable .= '</fieldset>'."\n";
5165: if (ref($requserfields{$provider}) eq 'ARRAY') {
5166: if (@{$requserfields{$provider}} > 0) {
5167: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
5168: foreach my $field (@{$requserfields{$provider}}) {
5169: $datatable .= '<span class="LC_nobreak">'.
5170: '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
5171: $lt{$field}.'</label>';
5172: if ($field eq 'user') {
5173: my $seluserdom = '';
5174: my $unseluserdom = ' selected="selected"';
5175: if ($userincdom) {
5176: $seluserdom = $unseluserdom;
5177: $unseluserdom = '';
5178: }
5179: $datatable .= ': '.
5180: '<select name="proctoring_userincdom_'.$provider.'">'.
5181: '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
5182: '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
5183: '</select> ';
5184: } else {
5185: $datatable .= ' ';
5186: if ($field eq 'roles') {
5187: $showroles = 1;
5188: }
5189: }
5190: $datatable .= '</span> ';
5191: }
5192: }
5193: $datatable .= '</fieldset>'."\n";
5194: }
5195: if (ref($optuserfields{$provider}) eq 'ARRAY') {
5196: if (@{$optuserfields{$provider}} > 0) {
5197: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>';
5198: foreach my $field (@{$optuserfields{$provider}}) {
5199: my $checked;
5200: if ($checkedfields{$field}) {
5201: $checked = ' checked="checked"';
5202: }
5203: $datatable .= '<span class="LC_nobreak">'.
5204: '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span> ';
5205: }
5206: $datatable .= '</fieldset>'."\n";
5207: }
5208: }
5209: if (ref($defaults{$provider}) eq 'ARRAY') {
5210: if (@{$defaults{$provider}}) {
5211: my (%options,@selectboxes);
5212: if (ref($extended{$provider}) eq 'HASH') {
5213: %options = %{$extended{$provider}};
5214: }
5215: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
5216: my ($rem,$numinrow,$dropdowns);
5217: if ($provider eq 'proctorio') {
5218: $datatable .= '<table>';
5219: $numinrow = 4;
5220: }
5221: my $i = 0;
5222: foreach my $field (@{$defaults{$provider}}) {
5223: my $checked;
5224: if ($inuse{$field}) {
5225: $checked = ' checked="checked"';
5226: }
5227: if ($provider eq 'examity') {
5228: if ($field eq 'display') {
5229: $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
5230: foreach my $option ('iframe','tab','window') {
5231: my $checkdisp;
5232: if ($currentdef{'target'} eq $option) {
5233: $checkdisp = ' checked="checked"';
5234: }
5235: $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
5236: $fieldtitles{$option}.'</label>'.(' 'x2);
5237: }
5238: $datatable .= (' 'x4);
5239: foreach my $dimen ('width','height') {
5240: $datatable .= '<label>'.$fieldtitles{$dimen}.' '.
5241: '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
5242: 'value="'.$currentdef{$dimen}.'" /></label>'.
5243: (' 'x2);
5244: }
5245: $datatable .= '</span><br />'.
5246: '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
5247: '<input type="text" name="proctoring_linktext_'.$provider.'" '.
5248: 'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
5249: '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
5250: '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
5251: $currentdef{'explanation'}.
5252: '</textarea></div><div style=""></div><br />';
5253: }
5254: } else {
5255: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
5256: my ($output,$selnone);
5257: unless ($checked) {
5258: $selnone = ' selected="selected"';
5259: }
5260: $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
5261: '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
5262: '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>';
5263: foreach my $option (@{$options{$field}}) {
5264: my $sel;
5265: if ($inuse{$field} eq $option) {
5266: $sel = ' selected="selected"';
5267: }
5268: $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
5269: }
5270: $output .= '</select></span>';
5271: push(@selectboxes,$output);
5272: } else {
5273: $rem = $i%($numinrow);
5274: if ($rem == 0) {
5275: if ($i > 0) {
5276: $datatable .= '</tr>';
5277: }
5278: $datatable .= '<tr>';
5279: }
5280: $datatable .= '<td class="LC_left_item">'.
5281: '<span class="LC_nobreak">'.
5282: '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
5283: $fieldtitles{$field}.'</label></span></td>';
5284: $i++;
5285: }
5286: }
5287: }
5288: if ($provider eq 'proctorio') {
5289: if ($numinrow) {
5290: $rem = $i%$numinrow;
5291: }
5292: my $colsleft = $numinrow - $rem;
5293: if ($colsleft > 1) {
5294: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5295: } else {
5296: $datatable .= '<td class="LC_left_item">';
5297: }
5298: $datatable .= ' '.
5299: '</td></tr></table>';
5300: if (@selectboxes) {
5301: $datatable .= '<hr /><table>';
5302: $numinrow = 2;
5303: for (my $i=0; $i<@selectboxes; $i++) {
5304: $rem = $i%($numinrow);
5305: if ($rem == 0) {
5306: if ($i > 0) {
5307: $datatable .= '</tr>';
5308: }
5309: $datatable .= '<tr>';
5310: }
5311: $datatable .= '<td class="LC_left_item">'.
5312: $selectboxes[$i].'</td>';
5313: }
5314: if ($numinrow) {
5315: $rem = $i%$numinrow;
5316: }
5317: $colsleft = $numinrow - $rem;
5318: if ($colsleft > 1) {
5319: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5320: } else {
5321: $datatable .= '<td class="LC_left_item">';
5322: }
5323: $datatable .= ' '.
5324: '</td></tr></table>';
5325: }
5326: }
5327: $datatable .= '</fieldset>';
5328: }
5329: if (ref($crsconf{$provider}) eq 'ARRAY') {
5330: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5331: '<legend>'.&mt('Configurable in course').'</legend>';
5332: my ($rem,$numinrow);
5333: if ($provider eq 'proctorio') {
5334: $datatable .= '<table>';
5335: $numinrow = 4;
5336: }
5337: my $i = 0;
5338: foreach my $item (@{$crsconf{$provider}}) {
5339: my $name;
5340: if ($provider eq 'examity') {
5341: $name = $lt{'crs'.$item};
5342: } elsif ($provider eq 'proctorio') {
5343: $name = $fieldtitles{$item};
5344: $rem = $i%($numinrow);
5345: if ($rem == 0) {
5346: if ($i > 0) {
5347: $datatable .= '</tr>';
5348: }
5349: $datatable .= '<tr>';
5350: }
5351: $datatable .= '<td class="LC_left_item>';
5352: }
5353: my $checked;
5354: if ($crsconfig{$item}) {
5355: $checked = ' checked="checked"';
5356: }
5357: $datatable .= '<span class="LC_nobreak"><label>'.
5358: '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
5359: $name.'</label></span>';
5360: if ($provider eq 'examity') {
5361: $datatable .= ' ';
5362: }
5363: $datatable .= "\n";
5364: $i++;
5365: }
5366: if ($provider eq 'proctorio') {
5367: if ($numinrow) {
5368: $rem = $i%$numinrow;
5369: }
5370: my $colsleft = $numinrow - $rem;
5371: if ($colsleft > 1) {
5372: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5373: } else {
5374: $datatable .= '<td class="LC_left_item">';
5375: }
5376: $datatable .= ' '.
5377: '</td></tr></table>';
5378: }
5379: $datatable .= '</fieldset>';
5380: }
5381: if ($showroles) {
5382: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5383: '<legend>'.&mt('Role mapping').'</legend><table><tr>';
5384: foreach my $role (@courseroles) {
5385: my ($selected,$selectnone);
5386: if (!$rolemaps{$role}) {
5387: $selectnone = ' selected="selected"';
5388: }
5389: $datatable .= '<td style="text-align: center">'.
5390: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5391: '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
5392: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5393: foreach my $ltirole (@ltiroles) {
5394: unless ($selectnone) {
5395: if ($rolemaps{$role} eq $ltirole) {
5396: $selected = ' selected="selected"';
5397: } else {
5398: $selected = '';
5399: }
5400: }
5401: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5402: }
5403: $datatable .= '</select></td>';
5404: }
5405: $datatable .= '</tr></table></fieldset>'.
5406: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5407: '<legend>'.&mt('Custom items sent on launch').'</legend>'.
5408: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5409: '<tr><td></td><td>lms</td>'.
5410: '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
5411: ' value="Loncapa" disabled="disabled"/></td></tr>';
5412: if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
5413: (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
5414: my %custom = %{$settings->{$provider}->{'custom'}};
5415: if (keys(%custom) > 0) {
5416: foreach my $key (sort(keys(%custom))) {
5417: next if ($key eq 'lms');
5418: $datatable .= '<tr><td><span class="LC_nobreak">'.
5419: '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
5420: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
5421: '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
5422: ' value="'.$custom{$key}.'" /></td></tr>';
5423: }
5424: }
5425: }
5426: $datatable .= '<tr><td><span class="LC_nobreak">'.
5427: '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
5428: &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
5429: '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
5430: '</table></fieldset></td></tr>'."\n";
5431: }
5432: $datatable .= '</td></tr>';
5433: }
5434: $itemcount ++;
5435: }
5436: }
5437: return $datatable;
5438: }
5439:
5440: sub proctoring_data {
5441: my $requserfields = {
5442: proctorio => ['user'],
5443: examity => ['roles','user'],
5444: };
5445: my $optuserfields = {
5446: proctorio => ['fullname'],
5447: examity => ['fullname','firstname','lastname','email'],
5448: };
5449: my $defaults = {
5450: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
5451: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
5452: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
5453: 'closetabs','onescreen','print','downloads','cache','rightclick',
5454: 'reentry','calculator','whiteboard'],
5455: examity => ['display'],
5456: };
5457: my $extended = {
5458: proctorio => {
5459: verifyid => ['verifyidauto','verifyidlive'],
5460: fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
5461: tabslinks => ['notabs','linksonly'],
5462: reentry => ['noreentry','agentreentry'],
5463: calculator => ['calculatorbasic','calculatorsci'],
5464: },
5465: examity => {
5466: display => {
5467: target => ['iframe','tab','window'],
5468: width => '',
5469: height => '',
5470: linktext => '',
5471: explanation => '',
5472: },
5473: },
5474: };
5475: my $crsconf = {
5476: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
5477: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
5478: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
5479: 'closetabs','onescreen','print','downloads','cache','rightclick',
5480: 'reentry','calculator','whiteboard'],
5481: examity => ['label','title','target','linktext','explanation','append'],
5482: };
5483: my $courseroles = ['cc','in','ta','ep','st'];
5484: my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
5485: return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
5486: }
5487:
5488: sub proctoring_titles {
5489: my ($item) = @_;
5490: my (%common_lt,%custom_lt);
5491: %common_lt = &Apache::lonlocal::texthash (
5492: 'avai' => 'Available?',
5493: 'base' => 'Basic Settings',
5494: 'requ' => 'User data required to be sent on launch',
5495: 'optu' => 'User data optionally sent on launch',
5496: 'udsl' => 'User data sent on launch',
5497: 'defa' => 'Defaults for items configurable in course',
5498: 'sigmethod' => 'Signature Method',
5499: 'key' => 'Key',
5500: 'lifetime' => 'Nonce lifetime (s)',
5501: 'secret' => 'Secret',
5502: 'icon' => 'Icon',
5503: 'fullname' => 'Full Name',
5504: 'visible' => 'Visible input',
5505: 'username' => 'username',
5506: 'user' => 'User',
5507: );
5508: if ($item eq 'proctorio') {
5509: %custom_lt = &Apache::lonlocal::texthash (
5510: 'version' => 'OAuth version',
5511: 'url' => 'API URL',
5512: 'uname:dom' => 'username-domain',
5513: );
5514: } elsif ($item eq 'examity') {
5515: %custom_lt = &Apache::lonlocal::texthash (
5516: 'version' => 'LTI Version',
5517: 'url' => 'URL',
5518: 'uname:dom' => 'username:domain',
5519: 'msgtype' => 'Message Type',
5520: 'firstname' => 'First Name',
5521: 'lastname' => 'Last Name',
5522: 'email' => 'E-mail',
5523: 'roles' => 'Role',
5524: 'crstarget' => 'Display target',
5525: 'crslabel' => 'Course label',
5526: 'crstitle' => 'Course title',
5527: 'crslinktext' => 'Link Text',
5528: 'crsexplanation' => 'Explanation',
5529: 'crsappend' => 'Provider URL',
5530: );
5531: }
5532: my %lt = (%common_lt,%custom_lt);
5533: return %lt;
5534: }
5535:
5536: sub proctoring_fieldtitles {
5537: my ($item) = @_;
5538: if ($item eq 'proctorio') {
5539: return &Apache::lonlocal::texthash (
5540: 'recordvideo' => 'Record video',
5541: 'recordaudio' => 'Record audio',
5542: 'recordscreen' => 'Record screen',
5543: 'recordwebtraffic' => 'Record web traffic',
5544: 'recordroomstart' => 'Record room scan',
5545: 'verifyvideo' => 'Verify webcam',
5546: 'verifyaudio' => 'Verify microphone',
5547: 'verifydesktop' => 'Verify desktop recording',
5548: 'verifyid' => 'Photo ID verification',
5549: 'verifysignature' => 'Require signature',
5550: 'fullscreen' => 'Fullscreen',
5551: 'clipboard' => 'Disable copy/paste',
5552: 'tabslinks' => 'New tabs/windows',
5553: 'closetabs' => 'Close other tabs',
5554: 'onescreen' => 'Limit to single screen',
5555: 'print' => 'Disable Printing',
5556: 'downloads' => 'Disable Downloads',
5557: 'cache' => 'Empty cache after exam',
5558: 'rightclick' => 'Disable right click',
5559: 'reentry' => 'Re-entry to exam',
5560: 'calculator' => 'Onscreen calculator',
5561: 'whiteboard' => 'Onscreen whiteboard',
5562: 'verifyidauto' => 'Automated verification',
5563: 'verifyidlive' => 'Live agent verification',
5564: 'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
5565: 'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
5566: 'fullscreensever' => 'Forced, navigation away ends exam',
5567: 'notabs' => 'Disaallowed',
5568: 'linksonly' => 'Allowed from links in exam',
5569: 'noreentry' => 'Disallowed',
5570: 'agentreentry' => 'Agent required for re-entry',
5571: 'calculatorbasic' => 'Basic',
5572: 'calculatorsci' => 'Scientific',
5573: );
5574: } elsif ($item eq 'examity') {
5575: return &Apache::lonlocal::texthash (
5576: 'target' => 'Display target',
5577: 'window' => 'Window',
5578: 'tab' => 'Tab',
5579: 'iframe' => 'iFrame',
5580: 'height' => 'Height (pixels)',
5581: 'width' => 'Width (pixels)',
5582: 'linktext' => 'Default Link Text',
5583: 'explanation' => 'Default Explanation',
5584: 'append' => 'Provider URL',
5585: );
5586: }
5587: }
5588:
5589: sub proctoring_providernames {
5590: return (
5591: proctorio => 'Proctorio',
5592: examity => 'Examity',
5593: );
5594: }
5595:
1.320 raeburn 5596: sub print_lti {
5597: my ($dom,$settings,$rowtotal) = @_;
5598: my $itemcount = 1;
5599: my $maxnum = 0;
5600: my $css_class;
5601: my %ordered;
5602: if (ref($settings) eq 'HASH') {
5603: foreach my $item (keys(%{$settings})) {
5604: if (ref($settings->{$item}) eq 'HASH') {
5605: my $num = $settings->{$item}{'order'};
5606: $ordered{$num} = $item;
5607: }
5608: }
5609: }
5610: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 5611: my $datatable;
1.320 raeburn 5612: my %lt = <i_names();
5613: if (keys(%ordered)) {
5614: my @items = sort { $a <=> $b } keys(%ordered);
5615: for (my $i=0; $i<@items; $i++) {
5616: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5617: my $item = $ordered{$items[$i]};
1.345 raeburn 5618: my ($key,$secret,$lifetime,$consumer,$requser,$current);
1.320 raeburn 5619: if (ref($settings->{$item}) eq 'HASH') {
5620: $key = $settings->{$item}->{'key'};
5621: $secret = $settings->{$item}->{'secret'};
5622: $lifetime = $settings->{$item}->{'lifetime'};
5623: $consumer = $settings->{$item}->{'consumer'};
1.345 raeburn 5624: $requser = $settings->{$item}->{'requser'};
1.320 raeburn 5625: $current = $settings->{$item};
5626: }
1.345 raeburn 5627: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
5628: my %checkedrequser = (
5629: yes => ' checked="checked"',
5630: no => '',
5631: );
5632: if (!$requser) {
5633: $checkedrequser{'no'} = $checkedrequser{'yes'};
5634: $checkedrequser{'yes'} = '';
1.352 raeburn 5635: }
1.320 raeburn 5636: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
5637: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5638: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
5639: for (my $k=0; $k<=$maxnum; $k++) {
5640: my $vpos = $k+1;
5641: my $selstr;
5642: if ($k == $i) {
5643: $selstr = ' selected="selected" ';
5644: }
5645: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5646: }
5647: $datatable .= '</select>'.(' 'x2).
5648: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
5649: &mt('Delete?').'</label></span></td>'.
5650: '<td colspan="2">'.
5651: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5652: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 5653: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
1.320 raeburn 5654: (' 'x2).
5655: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
5656: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
5657: (' 'x2).
5658: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.345 raeburn 5659: 'value="'.$lifetime.'" size="3" /></span>'.
5660: (' 'x2).
5661: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
5662: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
5663: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 5664: '<br /><br />'.
5665: '<span class="LC_nobreak">'.$lt{'key'}.
5666: ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
5667: (' 'x2).
5668: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
5669: '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
5670: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.lti_secret_'.$i.'.type='."'text'".' } else { this.form.lti_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
5671: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
1.325 raeburn 5672: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
1.320 raeburn 5673: $itemcount ++;
5674: }
5675: }
5676: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5677: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
5678: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
5679: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
5680: '<select name="lti_pos_add"'.$chgstr.'>';
5681: for (my $k=0; $k<$maxnum+1; $k++) {
5682: my $vpos = $k+1;
5683: my $selstr;
5684: if ($k == $maxnum) {
5685: $selstr = ' selected="selected" ';
5686: }
5687: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5688: }
5689: $datatable .= '</select> '."\n".
1.334 raeburn 5690: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.320 raeburn 5691: '<td colspan="2">'.
5692: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5693: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 5694: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
1.320 raeburn 5695: (' 'x2).
5696: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
5697: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
5698: (' 'x2).
1.345 raeburn 5699: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span> '."\n".
5700: (' 'x2).
5701: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
5702: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
5703: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 5704: '<br /><br />'.
5705: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
5706: (' 'x2).
5707: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
5708: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.lti_secret_add.type='."'text'".' } else { this.form.lti_secret_add.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n".
1.325 raeburn 5709: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
1.320 raeburn 5710: '</td>'."\n".
5711: '</tr>'."\n";
5712: $$rowtotal ++;
5713: return $datatable;;
5714: }
5715:
5716: sub lti_names {
5717: my %lt = &Apache::lonlocal::texthash(
5718: 'version' => 'LTI Version',
5719: 'url' => 'URL',
5720: 'key' => 'Key',
1.322 raeburn 5721: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 5722: 'consumer' => 'Consumer',
1.320 raeburn 5723: 'secret' => 'Secret',
1.345 raeburn 5724: 'requser' => "User's identity sent",
1.320 raeburn 5725: 'email' => 'Email address',
5726: 'sourcedid' => 'User ID',
5727: 'other' => 'Other',
5728: 'passback' => 'Can return grades to Consumer:',
5729: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 5730: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 5731: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 5732: );
5733: return %lt;
5734: }
5735:
5736: sub lti_options {
1.325 raeburn 5737: my ($num,$current,$itemcount,%lt) = @_;
1.363 raeburn 5738: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320 raeburn 5739: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
5740: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
5741: $checked{'makecrs'}{'N'} = ' checked="checked"';
5742: $checked{'mapcrstype'} = {};
5743: $checked{'makeuser'} = {};
5744: $checked{'selfenroll'} = {};
5745: $checked{'crssec'} = {};
5746: $checked{'crssecsrc'} = {};
1.325 raeburn 5747: $checked{'lcauth'} = {};
1.326 raeburn 5748: $checked{'menuitem'} = {};
1.325 raeburn 5749: if ($num eq 'add') {
5750: $checked{'lcauth'}{'lti'} = ' checked="checked"';
5751: }
1.320 raeburn 5752: my $userfieldsty = 'none';
5753: my $crsfieldsty = 'none';
5754: my $crssecfieldsty = 'none';
5755: my $secsrcfieldsty = 'none';
1.363 raeburn 5756: my $callbacksty = 'none';
1.337 raeburn 5757: my $passbacksty = 'none';
1.345 raeburn 5758: my $optionsty = 'block';
1.325 raeburn 5759: my $lcauthparm;
5760: my $lcauthparmstyle = 'display:none';
5761: my $lcauthparmtext;
1.326 raeburn 5762: my $menusty;
1.325 raeburn 5763: my $numinrow = 4;
1.326 raeburn 5764: my %menutitles = <imenu_titles();
1.320 raeburn 5765:
5766: if (ref($current) eq 'HASH') {
1.345 raeburn 5767: if (!$current->{'requser'}) {
5768: $optionsty = 'none';
5769: }
1.320 raeburn 5770: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
5771: $checked{'mapuser'}{'sourcedid'} = '';
5772: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
5773: $checked{'mapuser'}{'email'} = ' checked="checked"';
5774: } else {
5775: $checked{'mapuser'}{'other'} = ' checked="checked"';
5776: $userfield = $current->{'mapuser'};
5777: $userfieldsty = 'inline-block';
5778: }
5779: }
5780: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
5781: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
5782: if ($current->{'mapcrs'} eq 'context_id') {
5783: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
5784: } else {
5785: $checked{'mapcrs'}{'other'} = ' checked="checked"';
5786: $cidfield = $current->{'mapcrs'};
5787: $crsfieldsty = 'inline-block';
5788: }
5789: }
5790: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
5791: foreach my $type (@{$current->{'mapcrstype'}}) {
5792: $checked{'mapcrstype'}{$type} = ' checked="checked"';
5793: }
5794: }
1.345 raeburn 5795: if ($current->{'makecrs'}) {
1.320 raeburn 5796: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 5797: }
1.320 raeburn 5798: if (ref($current->{'makeuser'}) eq 'ARRAY') {
5799: foreach my $role (@{$current->{'makeuser'}}) {
5800: $checked{'makeuser'}{$role} = ' checked="checked"';
5801: }
5802: }
1.325 raeburn 5803: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
5804: $checked{'lcauth'}{$1} = ' checked="checked"';
5805: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
5806: $lcauthparm = $current->{'lcauthparm'};
5807: $lcauthparmstyle = 'display:table-row';
5808: if ($current->{'lcauth'} eq 'localauth') {
5809: $lcauthparmtext = &mt('Local auth argument');
5810: } else {
5811: $lcauthparmtext = &mt('Kerberos domain');
5812: }
5813: }
5814: }
1.320 raeburn 5815: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
5816: foreach my $role (@{$current->{'selfenroll'}}) {
5817: $checked{'selfenroll'}{$role} = ' checked="checked"';
5818: }
5819: }
5820: if (ref($current->{'maproles'}) eq 'HASH') {
5821: %rolemaps = %{$current->{'maproles'}};
5822: }
5823: if ($current->{'section'} ne '') {
5824: $checked{'crssec'}{'Y'} = ' checked="checked"';
5825: $crssecfieldsty = 'inline-block';
5826: if ($current->{'section'} eq 'course_section_sourcedid') {
5827: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
5828: } else {
5829: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
5830: $crssecsrc = $current->{'section'};
5831: $secsrcfieldsty = 'inline-block';
5832: }
5833: } else {
5834: $checked{'crssec'}{'N'} = ' checked="checked"';
5835: }
1.363 raeburn 5836: if ($current->{'callback'} ne '') {
5837: $callback = $current->{'callback'};
5838: $checked{'callback'}{'Y'} = ' checked="checked"';
5839: $callbacksty = 'inline-block';
5840: } else {
5841: $checked{'callback'}{'N'} = ' checked="checked"';
5842: }
1.326 raeburn 5843: if ($current->{'topmenu'}) {
5844: $checked{'topmenu'}{'Y'} = ' checked="checked"';
5845: } else {
5846: $checked{'topmenu'}{'N'} = ' checked="checked"';
5847: }
5848: if ($current->{'inlinemenu'}) {
5849: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5850: } else {
5851: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
5852: }
5853: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
5854: $menusty = 'inline-block';
5855: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
5856: foreach my $item (@{$current->{'lcmenu'}}) {
5857: if (exists($menutitles{$item})) {
5858: $checked{'menuitem'}{$item} = ' checked="checked"';
5859: }
5860: }
5861: }
5862: } else {
5863: $menusty = 'none';
5864: }
1.320 raeburn 5865: } else {
5866: $checked{'makecrs'}{'N'} = ' checked="checked"';
5867: $checked{'crssec'}{'N'} = ' checked="checked"';
1.363 raeburn 5868: $checked{'callback'}{'N'} = ' checked="checked"';
1.326 raeburn 5869: $checked{'topmenu'}{'N'} = ' checked="checked"';
5870: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5871: $checked{'menuitem'}{'grades'} = ' checked="checked"';
5872: $menusty = 'inline-block';
1.320 raeburn 5873: }
1.325 raeburn 5874: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 5875: my %coursetypetitles = &Apache::lonlocal::texthash (
5876: official => 'Official',
5877: unofficial => 'Unofficial',
5878: community => 'Community',
5879: textbook => 'Textbook',
5880: placement => 'Placement Test',
1.325 raeburn 5881: lti => 'LTI Provider',
1.320 raeburn 5882: );
1.325 raeburn 5883: my @authtypes = ('internal','krb4','krb5','localauth');
5884: my %shortauth = (
5885: internal => 'int',
5886: krb4 => 'krb4',
5887: krb5 => 'krb5',
5888: localauth => 'loc'
5889: );
5890: my %authnames = &authtype_names();
1.320 raeburn 5891: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
5892: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
5893: my @courseroles = ('cc','in','ta','ep','st');
5894: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
5895: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
5896: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363 raeburn 5897: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320 raeburn 5898: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 5899: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 5900: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.345 raeburn 5901: my $output = '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 5902: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
5903: foreach my $option ('sourcedid','email','other') {
5904: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
5905: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
5906: ($option eq 'other' ? '' : (' 'x2) );
5907: }
5908: $output .= '</span></div>'.
5909: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
5910: '<input type="text" name="lti_customuser_'.$num.'" '.
1.372 raeburn 5911: 'value="'.$userfield.'" /></div></fieldset>'.
1.345 raeburn 5912: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
1.320 raeburn 5913: foreach my $ltirole (@lticourseroles) {
5914: my ($selected,$selectnone);
5915: if ($rolemaps{$ltirole} eq '') {
5916: $selectnone = ' selected="selected"';
5917: }
5918: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
5919: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
5920: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5921: foreach my $role (@courseroles) {
5922: unless ($selectnone) {
5923: if ($rolemaps{$ltirole} eq $role) {
5924: $selected = ' selected="selected"';
5925: } else {
5926: $selected = '';
5927: }
5928: }
5929: $output .= '<option value="'.$role.'"'.$selected.'>'.
5930: &Apache::lonnet::plaintext($role,'Course').
5931: '</option>';
5932: }
5933: $output .= '</select></td>';
5934: }
5935: $output .= '</tr></table></fieldset>'.
1.345 raeburn 5936: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 5937: foreach my $ltirole (@ltiroles) {
5938: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
5939: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
5940: }
5941: $output .= '</fieldset>'.
1.345 raeburn 5942: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 5943: '<table>'.
5944: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
5945: '</table>'.
5946: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
5947: '<td class="LC_left_item">';
5948: foreach my $auth ('lti',@authtypes) {
5949: my $authtext;
5950: if ($auth eq 'lti') {
5951: $authtext = &mt('None');
5952: } else {
5953: $authtext = $authnames{$shortauth{$auth}};
5954: }
5955: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
5956: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
5957: $authtext.'</label></span> ';
5958: }
5959: $output .= '</td></tr>'.
5960: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
5961: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
5962: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
5963: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
5964: '</table></fieldset>'.
1.345 raeburn 5965: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 5966: '<div class="LC_floatleft"><span class="LC_nobreak">'.
5967: &mt('Unique course identifier').': ';
5968: foreach my $option ('course_offering_sourcedid','context_id','other') {
5969: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
5970: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
5971: ($option eq 'other' ? '' : (' 'x2) );
5972: }
1.334 raeburn 5973: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 5974: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
5975: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
5976: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
5977: foreach my $type (@coursetypes) {
5978: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
5979: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
5980: (' 'x2);
5981: }
5982: $output .= '</span></fieldset>'.
1.345 raeburn 5983: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 5984: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
5985: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
5986: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
5987: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
5988: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
5989: '</fieldset>'.
1.345 raeburn 5990: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 5991: foreach my $lticrsrole (@lticourseroles) {
5992: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
5993: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
5994: }
5995: $output .= '</fieldset>'.
1.345 raeburn 5996: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 5997: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
5998: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
5999: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
6000: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 6001: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 6002: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
6003: '<span class="LC_nobreak">'.&mt('From').':<label>'.
6004: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
6005: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
6006: &mt('Standard field').'</label>'.(' 'x2).
6007: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
6008: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 6009: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 6010: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 6011: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6012: my ($pb1p1chk,$pb1p0chk,$onclickpb);
6013: foreach my $extra ('roster','passback') {
1.320 raeburn 6014: my $checkedon = '';
6015: my $checkedoff = ' checked="checked"';
1.337 raeburn 6016: if ($extra eq 'passback') {
6017: $pb1p1chk = ' checked="checked"';
6018: $pb1p0chk = '';
6019: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
6020: } else {
6021: $onclickpb = '';
6022: }
1.320 raeburn 6023: if (ref($current) eq 'HASH') {
6024: if (($current->{$extra})) {
6025: $checkedon = $checkedoff;
6026: $checkedoff = '';
1.337 raeburn 6027: if ($extra eq 'passback') {
6028: $passbacksty = 'inline-block';
6029: }
6030: if ($current->{'passbackformat'} eq '1.0') {
6031: $pb1p0chk = ' checked="checked"';
6032: $pb1p1chk = '';
6033: }
1.320 raeburn 6034: }
6035: }
6036: $output .= $lt{$extra}.' '.
1.337 raeburn 6037: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 6038: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 6039: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 6040: &mt('Yes').'</label><br />';
6041: }
1.337 raeburn 6042: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
6043: '<span class="LC_nobreak">'.&mt('Grade format').
6044: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
6045: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
6046: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363 raeburn 6047: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
6048: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6049: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback on logout').': '.
6050: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
6051: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
6052: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
6053: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
6054: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
6055: '<span class="LC_nobreak">'.&mt('Parameter').': '.
6056: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
6057: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
1.345 raeburn 6058: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Course defaults (Course Coordinator can override)').'</legend>'.
1.326 raeburn 6059: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
6060: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
6061: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6062: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
1.334 raeburn 6063: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
1.326 raeburn 6064: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6065: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
6066: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
6067: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6068: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
1.334 raeburn 6069: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
1.326 raeburn 6070: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6071: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
6072: '<span class="LC_nobreak">'.&mt('Menu items').': ';
6073: foreach my $type ('fullname','coursetitle','role','logout','grades') {
6074: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
6075: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
6076: (' 'x2);
6077: }
1.334 raeburn 6078: $output .= '</span></div></fieldset>';
1.320 raeburn 6079: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
6080: #
6081: # $output .= '</fieldset>'.
6082: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
6083: return $output;
6084: }
6085:
1.326 raeburn 6086: sub ltimenu_titles {
6087: return &Apache::lonlocal::texthash(
6088: fullname => 'Full name',
6089: coursetitle => 'Course title',
6090: role => 'Role',
6091: logout => 'Logout',
6092: grades => 'Grades',
6093: );
6094: }
6095:
1.121 raeburn 6096: sub print_coursedefaults {
1.139 raeburn 6097: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 6098: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 6099: my $itemcount = 1;
1.192 raeburn 6100: my %choices = &Apache::lonlocal::texthash (
6101: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 6102: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 6103: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6104: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 6105: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6106: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.314 raeburn 6107: texengine => 'Default method to display mathematics',
1.257 raeburn 6108: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 6109: canclone => "People who may clone a course (besides course's owner and coordinators)",
6110: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 6111: );
1.198 raeburn 6112: my %staticdefaults = (
6113: anonsurvey_threshold => 10,
6114: uploadquota => 500,
1.257 raeburn 6115: postsubmit => 60,
1.276 raeburn 6116: mysqltables => 172800,
1.198 raeburn 6117: );
1.139 raeburn 6118: if ($position eq 'top') {
1.257 raeburn 6119: %defaultchecked = (
6120: 'canuse_pdfforms' => 'off',
6121: 'uselcmath' => 'on',
6122: 'usejsme' => 'on',
1.289 raeburn 6123: 'canclone' => 'none',
1.257 raeburn 6124: );
6125: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.349 raeburn 6126: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 6127: if (ref($settings) eq 'HASH') {
6128: if ($settings->{'texengine'}) {
6129: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6130: $deftex = $settings->{'texengine'};
6131: }
6132: }
6133: }
6134: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6135: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6136: '<span class="LC_nobreak">'.$choices{'texengine'}.
6137: '</span></td><td class="LC_right_item">'.
6138: '<select name="texengine">'."\n";
6139: my %texoptions = (
6140: MathJax => 'MathJax',
6141: mimetex => &mt('Convert to Images'),
6142: tth => &mt('TeX to HTML'),
6143: );
6144: foreach my $renderer ('MathJax','mimetex','tth') {
6145: my $selected = '';
6146: if ($renderer eq $deftex) {
6147: $selected = ' selected="selected"';
6148: }
6149: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6150: }
6151: $mathdisp .= '</select></td></tr>'."\n";
6152: $itemcount ++;
1.139 raeburn 6153: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 6154: \%choices,$itemcount);
1.314 raeburn 6155: $datatable = $mathdisp.$datatable;
1.264 raeburn 6156: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6157: $datatable .=
1.306 raeburn 6158: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 6159: '<span class="LC_nobreak">'.$choices{'canclone'}.
6160: '</span></td><td class="LC_left_item">';
6161: my $currcanclone = 'none';
6162: my $onclick;
6163: my @cloneoptions = ('none','domain');
6164: my %clonetitles = (
6165: none => 'No additional course requesters',
6166: domain => "Any course requester in course's domain",
6167: instcode => 'Course requests for official courses ...',
6168: );
6169: my (%codedefaults,@code_order,@posscodes);
6170: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6171: \@code_order) eq 'ok') {
6172: if (@code_order > 0) {
6173: push(@cloneoptions,'instcode');
6174: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6175: }
6176: }
6177: if (ref($settings) eq 'HASH') {
6178: if ($settings->{'canclone'}) {
6179: if (ref($settings->{'canclone'}) eq 'HASH') {
6180: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6181: if (@code_order > 0) {
6182: $currcanclone = 'instcode';
6183: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6184: }
6185: }
6186: } elsif ($settings->{'canclone'} eq 'domain') {
6187: $currcanclone = $settings->{'canclone'};
6188: }
6189: }
1.289 raeburn 6190: }
1.264 raeburn 6191: foreach my $option (@cloneoptions) {
6192: my ($checked,$additional);
6193: if ($currcanclone eq $option) {
6194: $checked = ' checked="checked"';
6195: }
6196: if ($option eq 'instcode') {
6197: if (@code_order) {
6198: my $show = 'none';
6199: if ($checked) {
6200: $show = 'block';
6201: }
1.317 raeburn 6202: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 6203: &mt('Institutional codes for new and cloned course have identical:').
6204: '<br />';
6205: foreach my $item (@code_order) {
6206: my $codechk;
6207: if ($checked) {
6208: if (grep(/^\Q$item\E$/,@posscodes)) {
6209: $codechk = ' checked="checked"';
6210: }
6211: }
6212: $additional .= '<label>'.
6213: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
6214: $item.'</label>';
6215: }
6216: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
6217: }
6218: }
6219: $datatable .=
6220: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
6221: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
6222: '</label> '.$additional.'</span><br />';
6223: }
6224: $datatable .= '</td>'.
6225: '</tr>';
6226: $itemcount ++;
1.139 raeburn 6227: } else {
6228: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 6229: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 6230: my $currusecredits = 0;
1.257 raeburn 6231: my $postsubmitclient = 1;
1.271 raeburn 6232: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 6233: if (ref($settings) eq 'HASH') {
6234: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 6235: if (ref($settings->{'uploadquota'}) eq 'HASH') {
6236: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
6237: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
6238: }
6239: }
1.192 raeburn 6240: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 6241: foreach my $type (@types) {
6242: next if ($type eq 'community');
6243: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
6244: if ($defcredits{$type} ne '') {
6245: $currusecredits = 1;
6246: }
6247: }
6248: }
6249: if (ref($settings->{'postsubmit'}) eq 'HASH') {
6250: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
6251: $postsubmitclient = 0;
6252: foreach my $type (@types) {
6253: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6254: }
6255: } else {
6256: foreach my $type (@types) {
6257: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
6258: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 6259: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 6260: } else {
6261: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6262: }
6263: } else {
6264: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6265: }
6266: }
6267: }
6268: } else {
6269: foreach my $type (@types) {
6270: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 6271: }
6272: }
1.276 raeburn 6273: if (ref($settings->{'mysqltables'}) eq 'HASH') {
6274: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
6275: $currmysql{$type} = $settings->{'mysqltables'}{$type};
6276: }
6277: } else {
6278: foreach my $type (@types) {
6279: $currmysql{$type} = $staticdefaults{'mysqltables'};
6280: }
6281: }
1.258 raeburn 6282: } else {
6283: foreach my $type (@types) {
6284: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6285: }
1.139 raeburn 6286: }
6287: if (!$currdefresponder) {
1.198 raeburn 6288: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 6289: } elsif ($currdefresponder < 1) {
6290: $currdefresponder = 1;
6291: }
1.198 raeburn 6292: foreach my $type (@types) {
6293: if ($curruploadquota{$type} eq '') {
6294: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
6295: }
6296: }
1.139 raeburn 6297: $datatable .=
1.192 raeburn 6298: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6299: $choices{'anonsurvey_threshold'}.
1.139 raeburn 6300: '</span></td>'.
6301: '<td class="LC_right_item"><span class="LC_nobreak">'.
6302: '<input type="text" name="anonsurvey_threshold"'.
6303: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 6304: '</td></tr>'."\n";
6305: $itemcount ++;
6306: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6307: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6308: $choices{'uploadquota'}.
6309: '</span></td>'.
1.306 raeburn 6310: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 6311: '<table><tr>';
1.198 raeburn 6312: foreach my $type (@types) {
1.306 raeburn 6313: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 6314: '<input type="text" name="uploadquota_'.$type.'"'.
6315: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
6316: }
6317: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 6318: $itemcount ++;
1.236 raeburn 6319: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 6320: my $display = 'none';
1.192 raeburn 6321: if ($currusecredits) {
6322: $display = 'block';
6323: }
6324: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 6325: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
6326: foreach my $type (@types) {
6327: next if ($type eq 'community');
1.306 raeburn 6328: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 6329: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 6330: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 6331: }
6332: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 6333: %defaultchecked = ('coursecredits' => 'off');
6334: @toggles = ('coursecredits');
6335: my $current = {
6336: 'coursecredits' => $currusecredits,
6337: };
6338: (my $table,$itemcount) =
6339: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 6340: \%choices,$itemcount,$onclick,$additional,'left');
6341: $datatable .= $table;
6342: $onclick = "toggleDisplay(this.form,'studentsubmission');";
6343: my $display = 'none';
6344: if ($postsubmitclient) {
6345: $display = 'block';
6346: }
6347: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 6348: &mt('Number of seconds submit is disabled').'<br />'.
6349: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
6350: '<table><tr>';
1.257 raeburn 6351: foreach my $type (@types) {
1.306 raeburn 6352: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 6353: '<input type="text" name="'.$type.'_timeout" value="'.
6354: $deftimeout{$type}.'" size="5" /></td>';
6355: }
6356: $additional .= '</tr></table></div>'."\n";
6357: %defaultchecked = ('postsubmit' => 'on');
6358: @toggles = ('postsubmit');
1.280 raeburn 6359: $current = {
6360: 'postsubmit' => $postsubmitclient,
6361: };
1.257 raeburn 6362: ($table,$itemcount) =
6363: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
6364: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 6365: $datatable .= $table;
1.276 raeburn 6366: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6367: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6368: $choices{'mysqltables'}.
6369: '</span></td>'.
1.306 raeburn 6370: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 6371: '<table><tr>';
6372: foreach my $type (@types) {
1.306 raeburn 6373: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 6374: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 6375: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 6376: }
6377: $datatable .= '</tr></table></td></tr>'."\n";
6378: $itemcount ++;
6379:
1.139 raeburn 6380: }
1.192 raeburn 6381: $$rowtotal += $itemcount;
1.121 raeburn 6382: return $datatable;
1.118 jms 6383: }
6384:
1.231 raeburn 6385: sub print_selfenrollment {
6386: my ($position,$dom,$settings,$rowtotal) = @_;
6387: my ($css_class,$datatable);
6388: my $itemcount = 1;
1.271 raeburn 6389: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 6390: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 6391: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
6392: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 6393: my @rows;
6394: my $key;
6395: if ($position eq 'top') {
6396: $key = 'admin';
6397: if (ref($rowsref) eq 'ARRAY') {
6398: @rows = @{$rowsref};
6399: }
6400: } elsif ($position eq 'middle') {
6401: $key = 'default';
6402: @rows = ('types','registered','approval','limit');
6403: }
6404: foreach my $row (@rows) {
6405: if (defined($titlesref->{$row})) {
6406: $itemcount ++;
6407: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6408: $datatable .= '<tr'.$css_class.'>'.
6409: '<td>'.$titlesref->{$row}.'</td>'.
6410: '<td class="LC_left_item">'.
6411: '<table><tr>';
6412: my (%current,%currentcap);
6413: if (ref($settings) eq 'HASH') {
6414: if (ref($settings->{$key}) eq 'HASH') {
6415: foreach my $type (@types) {
6416: if (ref($settings->{$key}->{$type}) eq 'HASH') {
6417: $current{$type} = $settings->{$key}->{$type}->{$row};
6418: }
6419: if (($row eq 'limit') && ($key eq 'default')) {
6420: if (ref($settings->{$key}->{$type}) eq 'HASH') {
6421: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
6422: }
6423: }
6424: }
6425: }
6426: }
6427: my %roles = (
6428: '0' => &Apache::lonnet::plaintext('dc'),
6429: );
6430:
6431: foreach my $type (@types) {
6432: unless (($row eq 'registered') && ($key eq 'default')) {
6433: $datatable .= '<th>'.&mt($type).'</th>';
6434: }
6435: }
6436: unless (($row eq 'registered') && ($key eq 'default')) {
6437: $datatable .= '</tr><tr>';
6438: }
6439: foreach my $type (@types) {
6440: if ($type eq 'community') {
6441: $roles{'1'} = &mt('Community personnel');
6442: } else {
6443: $roles{'1'} = &mt('Course personnel');
6444: }
6445: $datatable .= '<td style="vertical-align: top">';
6446: if ($position eq 'top') {
6447: my %checked;
6448: if ($current{$type} eq '0') {
6449: $checked{'0'} = ' checked="checked"';
6450: } else {
6451: $checked{'1'} = ' checked="checked"';
6452: }
6453: foreach my $role ('1','0') {
6454: $datatable .= '<span class="LC_nobreak"><label>'.
6455: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
6456: 'value="'.$role.'"'.$checked{$role}.' />'.
6457: $roles{$role}.'</label></span> ';
6458: }
6459: } else {
6460: if ($row eq 'types') {
6461: my %checked;
6462: if ($current{$type} =~ /^(all|dom)$/) {
6463: $checked{$1} = ' checked="checked"';
6464: } else {
6465: $checked{''} = ' checked="checked"';
6466: }
6467: foreach my $val ('','dom','all') {
6468: $datatable .= '<span class="LC_nobreak"><label>'.
6469: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6470: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6471: }
6472: } elsif ($row eq 'registered') {
6473: my %checked;
6474: if ($current{$type} eq '1') {
6475: $checked{'1'} = ' checked="checked"';
6476: } else {
6477: $checked{'0'} = ' checked="checked"';
6478: }
6479: foreach my $val ('0','1') {
6480: $datatable .= '<span class="LC_nobreak"><label>'.
6481: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6482: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6483: }
6484: } elsif ($row eq 'approval') {
6485: my %checked;
6486: if ($current{$type} =~ /^([12])$/) {
6487: $checked{$1} = ' checked="checked"';
6488: } else {
6489: $checked{'0'} = ' checked="checked"';
6490: }
6491: for my $val (0..2) {
6492: $datatable .= '<span class="LC_nobreak"><label>'.
6493: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6494: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6495: }
6496: } elsif ($row eq 'limit') {
6497: my %checked;
6498: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
6499: $checked{$1} = ' checked="checked"';
6500: } else {
6501: $checked{'none'} = ' checked="checked"';
6502: }
6503: my $cap;
6504: if ($currentcap{$type} =~ /^\d+$/) {
6505: $cap = $currentcap{$type};
6506: }
6507: foreach my $val ('none','allstudents','selfenrolled') {
6508: $datatable .= '<span class="LC_nobreak"><label>'.
6509: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6510: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6511: }
6512: $datatable .= '<br />'.
6513: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
6514: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
6515: '</span>';
6516: }
6517: }
6518: $datatable .= '</td>';
6519: }
6520: $datatable .= '</tr>';
6521: }
6522: $datatable .= '</table></td></tr>';
6523: }
6524: } elsif ($position eq 'bottom') {
1.235 raeburn 6525: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
6526: }
6527: $$rowtotal += $itemcount;
6528: return $datatable;
6529: }
6530:
6531: sub print_validation_rows {
6532: my ($caller,$dom,$settings,$rowtotal) = @_;
6533: my ($itemsref,$namesref,$fieldsref);
6534: if ($caller eq 'selfenroll') {
6535: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
6536: } elsif ($caller eq 'requestcourses') {
6537: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
6538: }
6539: my %currvalidation;
6540: if (ref($settings) eq 'HASH') {
6541: if (ref($settings->{'validation'}) eq 'HASH') {
6542: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 6543: }
1.235 raeburn 6544: }
6545: my $datatable;
6546: my $itemcount = 0;
6547: foreach my $item (@{$itemsref}) {
6548: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6549: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6550: $namesref->{$item}.
6551: '</span></td>'.
6552: '<td class="LC_left_item">';
6553: if (($item eq 'url') || ($item eq 'button')) {
6554: $datatable .= '<span class="LC_nobreak">'.
6555: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
6556: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
6557: } elsif ($item eq 'fields') {
6558: my @currfields;
6559: if (ref($currvalidation{$item}) eq 'ARRAY') {
6560: @currfields = @{$currvalidation{$item}};
6561: }
6562: foreach my $field (@{$fieldsref}) {
6563: my $check = '';
6564: if (grep(/^\Q$field\E$/,@currfields)) {
6565: $check = ' checked="checked"';
6566: }
6567: $datatable .= '<span class="LC_nobreak"><label>'.
6568: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
6569: ' value="'.$field.'"'.$check.' />'.$field.
6570: '</label></span> ';
6571: }
6572: } elsif ($item eq 'markup') {
1.334 raeburn 6573: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 6574: $currvalidation{$item}.
1.231 raeburn 6575: '</textarea>';
1.235 raeburn 6576: }
6577: $datatable .= '</td></tr>'."\n";
6578: if (ref($rowtotal)) {
1.231 raeburn 6579: $itemcount ++;
6580: }
6581: }
1.235 raeburn 6582: if ($caller eq 'requestcourses') {
6583: my %currhash;
1.248 raeburn 6584: if (ref($settings) eq 'HASH') {
6585: if (ref($settings->{'validation'}) eq 'HASH') {
6586: if ($settings->{'validation'}{'dc'} ne '') {
6587: $currhash{$settings->{'validation'}{'dc'}} = 1;
6588: }
1.235 raeburn 6589: }
6590: }
6591: my $numinrow = 2;
6592: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
6593: 'validationdc',%currhash);
1.247 raeburn 6594: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 6595: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 6596: if ($numdc > 1) {
1.247 raeburn 6597: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 6598: } else {
1.247 raeburn 6599: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 6600: }
1.247 raeburn 6601: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 6602: $itemcount ++;
6603: }
6604: if (ref($rowtotal)) {
6605: $$rowtotal += $itemcount;
6606: }
1.231 raeburn 6607: return $datatable;
6608: }
6609:
1.357 raeburn 6610: sub print_privacy {
6611: my ($position,$dom,$settings,$rowtotal) = @_;
6612: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
6613: my $itemcount = 0;
6614: unless ($position eq 'top') {
6615: @items = ('domain','author','course','community');
6616: %names = &Apache::lonlocal::texthash (
6617: domain => 'Assigned domain role(s)',
6618: author => 'Assigned co-author role(s)',
6619: course => 'Assigned course role(s)',
6620: community => 'Assigned community role',
6621: );
6622: $numinrow = 4;
6623: ($othertitle,$usertypes,$types) =
6624: &Apache::loncommon::sorted_inst_types($dom);
6625: }
6626: if (($position eq 'top') || ($position eq 'middle')) {
6627: my (%by_ip,%by_location,@intdoms,@instdoms);
6628: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
6629: if ($position eq 'top') {
6630: my %curr;
6631: my @options = ('none','user','domain','auto');
6632: my %titles = &Apache::lonlocal::texthash (
6633: none => 'Not allowed',
6634: user => 'User authorizes',
6635: domain => 'DC authorizes',
6636: auto => 'Unrestricted',
6637: instdom => 'Other domain shares institution/provider',
6638: extdom => 'Other domain has different institution/provider',
6639: );
6640: my %names = &Apache::lonlocal::texthash (
6641: domain => 'Domain role',
6642: author => 'Co-author role',
6643: course => 'Course role',
6644: community => 'Community role',
6645: );
6646: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6647: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6648: foreach my $domtype ('instdom','extdom') {
6649: my (%checked,$skip);
6650: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6651: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
6652: '<td class="LC_left_item">';
6653: if ($domtype eq 'instdom') {
6654: unless (@instdoms > 1) {
6655: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
6656: $skip = 1;
6657: }
6658: } elsif ($domtype eq 'extdom') {
6659: if (keys(%by_location) == 0) {
6660: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
6661: $skip = 1;
6662: }
6663: }
6664: unless ($skip) {
6665: foreach my $roletype ('domain','author','course','community') {
6666: $checked{'auto'} = ' checked="checked"';
6667: if (ref($settings) eq 'HASH') {
6668: if (ref($settings->{approval}) eq 'HASH') {
6669: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
6670: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
6671: $checked{$1} = ' checked="checked"';
6672: $checked{'auto'} = '';
6673: }
6674: }
6675: }
6676: }
6677: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
6678: foreach my $option (@options) {
6679: $datatable .= '<span class="LC_nobreak"><label>'.
6680: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
6681: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
6682: '</label></span> ';
6683: }
6684: $datatable .= '</fieldset>';
6685: }
6686: }
6687: $datatable .= '</td></tr>';
6688: $itemcount ++;
6689: }
6690: } elsif ($position eq 'middle') {
6691: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
6692: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6693: foreach my $item (@{$types}) {
6694: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
6695: $numinrow,$itemcount,'','','','','',
6696: '',$usertypes->{$item});
6697: $itemcount ++;
6698: }
6699: }
6700: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
6701: $numinrow,$itemcount,'','','','','',
6702: '',$othertitle);
6703: $itemcount ++;
6704: } else {
1.360 raeburn 6705: my (@insttypes,%insttitles);
6706: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6707: @insttypes = @{$types};
6708: %insttitles = %{$usertypes};
6709: }
6710: foreach my $item (@insttypes,'default') {
6711: my $title;
6712: if ($item eq 'default') {
6713: $title = $othertitle;
6714: } else {
6715: $title = $insttitles{$item};
6716: }
6717: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6718: $datatable .= '<tr'.$css_class.'>'.
6719: '<td class="LC_left_item">'.$title.'</td>'.
6720: '<td class="LC_left_item">'.
6721: &mt('Nothing to set here, as there are no other domains').
6722: '</td></tr>';
6723: $itemcount ++;
6724: }
1.357 raeburn 6725: }
6726: }
6727: } else {
6728: my $prefix;
6729: if ($position eq 'lower') {
6730: $prefix = 'priv';
6731: } else {
6732: $prefix = 'unpriv';
6733: }
6734: foreach my $item (@items) {
6735: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
6736: $numinrow,$itemcount,'','','','','',
6737: '',$names{$item});
6738: $itemcount ++;
6739: }
6740: }
6741: if (ref($rowtotal)) {
6742: $$rowtotal += $itemcount;
6743: }
6744: return $datatable;
6745: }
6746:
1.354 raeburn 6747: sub print_passwords {
6748: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
6749: my ($datatable,$css_class);
6750: my $itemcount = 0;
6751: my %titles = &Apache::lonlocal::texthash (
6752: captcha => '"Forgot Password" CAPTCHA validation',
6753: link => 'Reset link expiration (hours)',
6754: case => 'Case-sensitive usernames/e-mail',
6755: prelink => 'Information required (form 1)',
6756: postlink => 'Information required (form 2)',
6757: emailsrc => 'LON-CAPA e-mail address type(s)',
6758: customtext => 'Domain specific text (HTML)',
6759: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
6760: intauth_check => 'Check bcrypt cost if authenticated',
6761: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
6762: permanent => 'Permanent e-mail address',
6763: critical => 'Critical notification address',
6764: notify => 'Notification address',
6765: min => 'Minimum password length',
6766: max => 'Maximum password length',
6767: chars => 'Required characters',
6768: expire => 'Password expiration (days)',
1.356 raeburn 6769: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 6770: );
6771: if ($position eq 'top') {
6772: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6773: my $shownlinklife = 2;
6774: my $prelink = 'both';
6775: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
6776: if (ref($settings) eq 'HASH') {
6777: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
6778: $shownlinklife = $settings->{resetlink};
6779: }
6780: if (ref($settings->{resetcase}) eq 'ARRAY') {
6781: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
6782: }
6783: if ($settings->{resetprelink} =~ /^(both|either)$/) {
6784: $prelink = $settings->{resetprelink};
6785: }
6786: if (ref($settings->{resetpostlink}) eq 'HASH') {
6787: %postlink = %{$settings->{resetpostlink}};
6788: }
6789: if (ref($settings->{resetemail}) eq 'ARRAY') {
6790: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
6791: }
6792: if ($settings->{resetremove}) {
6793: $nostdtext = 1;
6794: }
6795: if ($settings->{resetcustom}) {
6796: $customurl = $settings->{resetcustom};
6797: }
6798: } else {
6799: if (ref($types) eq 'ARRAY') {
6800: foreach my $item (@{$types}) {
6801: $casesens{$item} = 1;
6802: $postlink{$item} = ['username','email'];
6803: }
6804: }
6805: $casesens{'default'} = 1;
6806: $postlink{'default'} = ['username','email'];
6807: $prelink = 'both';
6808: %emailsrc = (
6809: permanent => 1,
6810: critical => 1,
6811: notify => 1,
6812: );
6813: }
6814: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
6815: $itemcount ++;
6816: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6817: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
6818: '<td class="LC_left_item">'.
6819: '<input type="textbox" value="'.$shownlinklife.'" '.
6820: 'name="passwords_link" size="3" /></td></tr>';
6821: $itemcount ++;
6822: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6823: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
6824: '<td class="LC_left_item">';
6825: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6826: foreach my $item (@{$types}) {
6827: my $checkedcase;
6828: if ($casesens{$item}) {
6829: $checkedcase = ' checked="checked"';
6830: }
6831: $datatable .= '<span class="LC_nobreak"><label>'.
6832: '<input type="checkbox" name="passwords_case_sensitive" value="'.
6833: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 6834: '</span> ';
1.354 raeburn 6835: }
6836: }
6837: my $checkedcase;
6838: if ($casesens{'default'}) {
6839: $checkedcase = ' checked="checked"';
6840: }
6841: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
6842: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
6843: $othertitle.'</label></span></td>';
6844: $itemcount ++;
6845: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6846: my %checkedpre = (
6847: both => ' checked="checked"',
6848: either => '',
6849: );
6850: if ($prelink eq 'either') {
6851: $checkedpre{either} = ' checked="checked"';
6852: $checkedpre{both} = '';
6853: }
6854: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
6855: '<td class="LC_left_item"><span class="LC_nobreak">'.
6856: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
6857: &mt('Both username and e-mail address').'</label></span> '.
6858: '<span class="LC_nobreak"><label>'.
6859: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
6860: &mt('Either username or e-mail address').'</label></span></td></tr>';
6861: $itemcount ++;
6862: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6863: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
6864: '<td class="LC_left_item">';
6865: my %postlinked;
6866: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6867: foreach my $item (@{$types}) {
6868: undef(%postlinked);
6869: $datatable .= '<fieldset style="display: inline-block;">'.
6870: '<legend>'.$usertypes->{$item}.'</legend>';
6871: if (ref($postlink{$item}) eq 'ARRAY') {
6872: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
6873: }
6874: foreach my $field ('email','username') {
6875: my $checked;
6876: if ($postlinked{$field}) {
6877: $checked = ' checked="checked"';
6878: }
6879: $datatable .= '<span class="LC_nobreak"><label>'.
6880: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
6881: $field.'"'.$checked.' />'.$field.'</label>'.
6882: '<span> ';
6883: }
6884: $datatable .= '</fieldset>';
6885: }
6886: }
6887: if (ref($postlink{'default'}) eq 'ARRAY') {
6888: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
6889: }
6890: $datatable .= '<fieldset style="display: inline-block;">'.
6891: '<legend>'.$othertitle.'</legend>';
6892: foreach my $field ('email','username') {
6893: my $checked;
6894: if ($postlinked{$field}) {
6895: $checked = ' checked="checked"';
6896: }
6897: $datatable .= '<span class="LC_nobreak"><label>'.
6898: '<input type="checkbox" name="passwords_postlink_default" value="'.
6899: $field.'"'.$checked.' />'.$field.'</label>'.
6900: '<span> ';
6901: }
6902: $datatable .= '</fieldset></td></tr>';
6903: $itemcount ++;
6904: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6905: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
6906: '<td class="LC_left_item">';
6907: foreach my $type ('permanent','critical','notify') {
6908: my $checkedemail;
6909: if ($emailsrc{$type}) {
6910: $checkedemail = ' checked="checked"';
6911: }
6912: $datatable .= '<span class="LC_nobreak"><label>'.
6913: '<input type="checkbox" name="passwords_emailsrc" value="'.
6914: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
6915: '<span> ';
6916: }
6917: $datatable .= '</td></tr>';
6918: $itemcount ++;
6919: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6920: my $switchserver = &check_switchserver($dom,$confname);
6921: my ($showstd,$noshowstd);
6922: if ($nostdtext) {
6923: $noshowstd = ' checked="checked"';
6924: } else {
6925: $showstd = ' checked="checked"';
6926: }
6927: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
6928: '<td class="LC_left_item"><span class="LC_nobreak">'.
6929: &mt('Retain standard text:').
6930: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
6931: &mt('Yes').'</label>'.' '.
6932: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
6933: &mt('No').'</label></span><br />'.
6934: '<span class="LC_fontsize_small">'.
6935: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
6936: &mt('Include custom text:');
6937: if ($customurl) {
1.369 raeburn 6938: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 6939: undef,undef,undef,undef,'background-color:#ffffff');
6940: $datatable .= '<span class="LC_nobreak"> '.$link.
6941: '<label><input type="checkbox" name="passwords_custom_del"'.
6942: ' value="1" />'.&mt('Delete?').'</label></span>'.
6943: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
6944: }
6945: if ($switchserver) {
6946: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
6947: } else {
6948: $datatable .='<span class="LC_nobreak"> '.
6949: '<input type="file" name="passwords_customfile" /></span>';
6950: }
6951: $datatable .= '</td></tr>';
6952: } elsif ($position eq 'middle') {
6953: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
6954: my @items = ('intauth_cost','intauth_check','intauth_switch');
6955: my %defaults;
6956: if (ref($domconf{'defaults'}) eq 'HASH') {
6957: %defaults = %{$domconf{'defaults'}};
6958: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
6959: $defaults{'intauth_cost'} = 10;
6960: }
6961: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
6962: $defaults{'intauth_check'} = 0;
6963: }
6964: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
6965: $defaults{'intauth_switch'} = 0;
6966: }
6967: } else {
6968: %defaults = (
6969: 'intauth_cost' => 10,
6970: 'intauth_check' => 0,
6971: 'intauth_switch' => 0,
6972: );
6973: }
6974: foreach my $item (@items) {
6975: if ($itemcount%2) {
6976: $css_class = '';
6977: } else {
6978: $css_class = ' class="LC_odd_row" ';
6979: }
6980: $datatable .= '<tr'.$css_class.'>'.
6981: '<td><span class="LC_nobreak">'.$titles{$item}.
6982: '</span></td><td class="LC_left_item" colspan="3">';
6983: if ($item eq 'intauth_switch') {
6984: my @options = (0,1,2);
6985: my %optiondesc = &Apache::lonlocal::texthash (
6986: 0 => 'No',
6987: 1 => 'Yes',
6988: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
6989: );
6990: $datatable .= '<table width="100%">';
6991: foreach my $option (@options) {
6992: my $checked = ' ';
6993: if ($defaults{$item} eq $option) {
6994: $checked = ' checked="checked"';
6995: }
6996: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6997: '<label><input type="radio" name="'.$item.
6998: '" value="'.$option.'"'.$checked.' />'.
6999: $optiondesc{$option}.'</label></span></td></tr>';
7000: }
7001: $datatable .= '</table>';
7002: } elsif ($item eq 'intauth_check') {
7003: my @options = (0,1,2);
7004: my %optiondesc = &Apache::lonlocal::texthash (
7005: 0 => 'No',
7006: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
7007: 2 => 'Yes, disallow login if stored cost is less than domain default',
7008: );
7009: $datatable .= '<table width="100%">';
7010: foreach my $option (@options) {
7011: my $checked = ' ';
7012: my $onclick;
7013: if ($defaults{$item} eq $option) {
7014: $checked = ' checked="checked"';
7015: }
7016: if ($option == 2) {
7017: $onclick = ' onclick="javascript:warnIntAuth(this);"';
7018: }
7019: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7020: '<label><input type="radio" name="'.$item.
7021: '" value="'.$option.'"'.$checked.$onclick.' />'.
7022: $optiondesc{$option}.'</label></span></td></tr>';
7023: }
7024: $datatable .= '</table>';
7025: } else {
7026: $datatable .= '<input type="text" name="'.$item.'" value="'.
7027: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
7028: }
7029: $datatable .= '</td></tr>';
7030: $itemcount ++;
7031: }
7032: } elsif ($position eq 'lower') {
1.356 raeburn 7033: my ($min,$max,%chars,$expire,$numsaved);
1.365 raeburn 7034: $min = $Apache::lonnet::passwdmin;
1.354 raeburn 7035: if (ref($settings) eq 'HASH') {
7036: if ($settings->{min}) {
7037: $min = $settings->{min};
7038: }
7039: if ($settings->{max}) {
7040: $max = $settings->{max};
7041: }
7042: if (ref($settings->{chars}) eq 'ARRAY') {
7043: map { $chars{$_} = 1; } (@{$settings->{chars}});
7044: }
7045: if ($settings->{expire}) {
7046: $expire = $settings->{expire};
7047: }
1.358 raeburn 7048: if ($settings->{numsaved}) {
7049: $numsaved = $settings->{numsaved};
1.356 raeburn 7050: }
1.354 raeburn 7051: }
7052: my %rulenames = &Apache::lonlocal::texthash(
7053: uc => 'At least one upper case letter',
7054: lc => 'At least one lower case letter',
7055: num => 'At least one number',
7056: spec => 'At least one non-alphanumeric',
7057: );
7058: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7059: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
7060: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 7061: '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
7062: 'onblur="javascript:warnIntPass(this);" />'.
7063: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
1.354 raeburn 7064: '</span></td></tr>';
7065: $itemcount ++;
7066: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7067: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
7068: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 7069: '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
7070: 'onblur="javascript:warnIntPass(this);" />'.
1.354 raeburn 7071: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
7072: '</span></td></tr>';
7073: $itemcount ++;
7074: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7075: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
7076: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
7077: '</span></td>';
7078: my $numinrow = 2;
7079: my @possrules = ('uc','lc','num','spec');
7080: $datatable .= '<td class="LC_left_item"><table>';
7081: for (my $i=0; $i<@possrules; $i++) {
7082: my ($rem,$checked);
7083: if ($chars{$possrules[$i]}) {
7084: $checked = ' checked="checked"';
7085: }
7086: $rem = $i%($numinrow);
7087: if ($rem == 0) {
7088: if ($i > 0) {
7089: $datatable .= '</tr>';
7090: }
7091: $datatable .= '<tr>';
7092: }
7093: $datatable .= '<td><span class="LC_nobreak"><label>'.
7094: '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
7095: $rulenames{$possrules[$i]}.'</label></span></td>';
7096: }
7097: my $rem = @possrules%($numinrow);
7098: my $colsleft = $numinrow - $rem;
7099: if ($colsleft > 1 ) {
7100: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7101: ' </td>';
7102: } elsif ($colsleft == 1) {
7103: $datatable .= '<td class="LC_left_item"> </td>';
7104: }
7105: $datatable .='</table></td></tr>';
7106: $itemcount ++;
7107: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7108: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
7109: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 7110: '<input type="text" name="passwords_expire" value="'.$expire.'" size="4" '.
7111: 'onblur="javascript:warnIntPass(this);" />'.
1.354 raeburn 7112: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
7113: '</span></td></tr>';
1.356 raeburn 7114: $itemcount ++;
7115: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7116: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
7117: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.367 raeburn 7118: '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
7119: 'onblur="javascript:warnIntPass(this);" />'.
1.356 raeburn 7120: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
7121: '</span></td></tr>';
1.354 raeburn 7122: } else {
1.359 raeburn 7123: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7124: my %ownerchg = (
7125: by => {},
7126: for => {},
7127: );
7128: my %ownertitles = &Apache::lonlocal::texthash (
7129: by => 'Course owner status(es) allowed',
7130: for => 'Student status(es) allowed',
7131: );
1.354 raeburn 7132: if (ref($settings) eq 'HASH') {
1.359 raeburn 7133: if (ref($settings->{crsownerchg}) eq 'HASH') {
7134: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
7135: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
7136: }
7137: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
7138: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
7139: }
1.354 raeburn 7140: }
7141: }
7142: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7143: $datatable .= '<tr '.$css_class.'>'.
7144: '<td>'.
7145: &mt('Requirements').'<ul>'.
1.359 raeburn 7146: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 7147: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
7148: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 7149: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 7150: '</ul>'.
7151: '</td>'.
1.359 raeburn 7152: '<td class="LC_left_item">';
7153: foreach my $item ('by','for') {
7154: $datatable .= '<fieldset style="display: inline-block;">'.
7155: '<legend>'.$ownertitles{$item}.'</legend>';
7156: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7157: foreach my $type (@{$types}) {
7158: my $checked;
7159: if ($ownerchg{$item}{$type}) {
7160: $checked = ' checked="checked"';
7161: }
7162: $datatable .= '<span class="LC_nobreak"><label>'.
7163: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
7164: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 7165: '</span> ';
1.359 raeburn 7166: }
7167: }
7168: my $checked;
7169: if ($ownerchg{$item}{'default'}) {
7170: $checked = ' checked="checked"';
7171: }
7172: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7173: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
7174: $othertitle.'</label></span></fieldset>';
7175: }
7176: $datatable .= '</td></tr>';
1.354 raeburn 7177: }
7178: return $datatable;
7179: }
7180:
1.373 ! raeburn 7181: sub print_wafproxy {
! 7182: my ($position,$dom,$settings,$rowtotal) = @_;
! 7183: my $css_class;
! 7184: my $itemcount = 0;
! 7185: my $datatable;
! 7186: my %servers = &Apache::lonnet::internet_dom_servers($dom);
! 7187: my (%othercontrol,%otherdoms,%aliases,%values,$setdom);
! 7188: foreach my $server (sort(keys(%servers))) {
! 7189: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
! 7190: my $serverdom;
! 7191: if ($serverhome ne $server) {
! 7192: $serverdom = &Apache::lonnet::host_domain($serverhome);
! 7193: $othercontrol{$server} = $serverdom;
! 7194: } else {
! 7195: $serverdom = &Apache::lonnet::host_domain($server);
! 7196: if ($serverdom ne $dom) {
! 7197: $othercontrol{$server} = $serverdom;
! 7198: } else {
! 7199: $setdom = 1;
! 7200: if (ref($settings) eq 'HASH') {
! 7201: %{$values{$dom}} = ();
! 7202: if (ref($settings->{'alias'}) eq 'HASH') {
! 7203: $aliases{$dom} = $settings->{'alias'};
! 7204: }
! 7205: foreach my $item ('ipheader','trusted','exempt') {
! 7206: $values{$dom}{$item} = $settings->{$item};
! 7207: }
! 7208: }
! 7209: }
! 7210: }
! 7211: }
! 7212: if (keys(%othercontrol)) {
! 7213: %otherdoms = reverse(%othercontrol);
! 7214: foreach my $domain (keys(%otherdoms)) {
! 7215: %{$values{$domain}} = ();
! 7216: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
! 7217: if (ref($config{$domain}) eq 'HASH') {
! 7218: if (ref($config{$domain}{'wafproxy'}) eq 'HASH') {
! 7219: $aliases{$domain} = $config{$domain}{'wafproxy'}{'alias'};
! 7220: foreach my $item ('exempt','trusted','ipheader') {
! 7221: $values{$domain}{$item} = $config{$domain}{'wafproxy'}{$item};
! 7222: }
! 7223: }
! 7224: }
! 7225: }
! 7226: }
! 7227: if ($position eq 'top') {
! 7228: my %servers = &Apache::lonnet::internet_dom_servers($dom);
! 7229: foreach my $server (sort(keys(%servers))) {
! 7230: $itemcount ++;
! 7231: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
! 7232: $datatable .= '<tr'.$css_class.'>'.
! 7233: '<td>'.&mt('Hostname').': '.
! 7234: &Apache::lonnet::hostname($server).'</td>'.
! 7235: '<td>';
! 7236: if ($othercontrol{$server}) {
! 7237: my $current;
! 7238: if (ref($aliases{$othercontrol{$server}}) eq 'HASH') {
! 7239: $current = $aliases{$othercontrol{$server}{$server}};
! 7240: }
! 7241: if ($current) {
! 7242: $datatable .= $current;
! 7243: } else {
! 7244: $datatable .= &mt('None in effect');
! 7245: }
! 7246: $datatable .= '<br /><span class="LC_small">('.
! 7247: &mt('WAF/Reverse Proxy controlled by domain: [_1]',
! 7248: '<b>'.$othercontrol{$server}.'</b>').'</span>';
! 7249: } else {
! 7250: my $current;
! 7251: if (ref($aliases{$dom}) eq 'HASH') {
! 7252: if ($aliases{$dom}{$server}) {
! 7253: $current = $aliases{$dom}{$server};
! 7254: }
! 7255: }
! 7256: $datatable .= '<input type="text" name="wafproxy_alias_'.$server.'" '.
! 7257: 'value="'.$current.'" size="20" />';
! 7258: }
! 7259: $datatable .= '</td></tr>';
! 7260: }
! 7261: } else {
! 7262: if ($setdom) {
! 7263: $itemcount ++;
! 7264: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
! 7265: $datatable .= '<tr'.$css_class.'>'.
! 7266: '<td>'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
! 7267: &mt('Format for comma separated IP blocks').':<br />'.
! 7268: &mt('A.B.C.D/N or A.B.C.D - E.F.G.H').'</td>'.
! 7269: '<td class="LC_left_item"><table>';
! 7270: foreach my $item ('ipheader','trusted','exempt') {
! 7271: $datatable .= '<tr>'.
! 7272: '<td>'.$lt{$item}.': '.
! 7273: '<input type="text" value="'.$values{$dom}{$item}.'" '.
! 7274: 'name="wafproxy_'.$item.'" /></td></tr>';
! 7275: }
! 7276: $datatable .= '</table></td></tr>';
! 7277: }
! 7278: if (keys(%otherdoms)) {
! 7279: foreach my $domain (sort(keys(%otherdoms))) {
! 7280: $itemcount ++;
! 7281: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
! 7282: $datatable .= '<tr'.$css_class.'>'.
! 7283: '<td>'.&mt('Domain: [_1]',$domain).
! 7284: '<table>';
! 7285: foreach my $item ('ipheader','trusted','exempt') {
! 7286: my $showval = &mt('None');
! 7287: if ($values{$domain}{$item}) {
! 7288: $showval = $values{$domain}{$item};
! 7289: }
! 7290: $datatable .= '<tr>'.
! 7291: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
! 7292: }
! 7293: $datatable .= '</table></td></tr>';
! 7294: }
! 7295: }
! 7296: }
! 7297: $$rowtotal += $itemcount;
! 7298: return $datatable;
! 7299: }
! 7300:
! 7301: sub wafproxy_titles {
! 7302: return &Apache::lonlocal::texthash(
! 7303: exempt => 'Exempt IP range(s)',
! 7304: trusted => 'Trusted IP range(s)',
! 7305: ipheader => 'Custom request header',
! 7306: );
! 7307: }
! 7308:
1.137 raeburn 7309: sub print_usersessions {
7310: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 7311: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 7312: my (%by_ip,%by_location,@intdoms,@instdoms);
7313: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 7314:
7315: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 7316: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 7317: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 7318: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 7319: if ($position eq 'top') {
1.152 raeburn 7320: if (keys(%serverhomes) > 1) {
1.145 raeburn 7321: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 7322: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 7323: if (ref($settings) eq 'HASH') {
7324: if (ref($settings->{'offloadnow'}) eq 'HASH') {
7325: $curroffloadnow = $settings->{'offloadnow'};
7326: }
1.371 raeburn 7327: if (ref($settings->{'offloadoth'}) eq 'HASH') {
7328: $curroffloadoth = $settings->{'offloadoth'};
7329: }
1.261 raeburn 7330: }
1.371 raeburn 7331: my $other_insts = scalar(keys(%by_location));
7332: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
7333: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 7334: } else {
1.140 raeburn 7335: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 7336: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
7337: '</td></tr>';
1.140 raeburn 7338: }
1.137 raeburn 7339: } else {
1.279 raeburn 7340: my %titles = &usersession_titles();
7341: my ($prefix,@types);
7342: if ($position eq 'bottom') {
7343: $prefix = 'remote';
7344: @types = ('version','excludedomain','includedomain');
1.145 raeburn 7345: } else {
1.279 raeburn 7346: $prefix = 'hosted';
7347: @types = ('excludedomain','includedomain');
7348: }
7349: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
7350: }
7351: $$rowtotal += $itemcount;
7352: return $datatable;
7353: }
7354:
7355: sub rules_by_location {
7356: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
7357: my ($datatable,$itemcount,$css_class);
7358: if (keys(%{$by_location}) == 0) {
7359: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7360: $datatable = '<tr'.$css_class.'><td colspan="2">'.
7361: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
7362: '</td></tr>';
7363: $itemcount = 1;
7364: } else {
7365: $itemcount = 0;
7366: my $numinrow = 5;
7367: my (%current,%checkedon,%checkedoff);
7368: my @locations = sort(keys(%{$by_location}));
7369: foreach my $type (@{$types}) {
7370: $checkedon{$type} = '';
7371: $checkedoff{$type} = ' checked="checked"';
7372: }
7373: if (ref($settings) eq 'HASH') {
7374: if (ref($settings->{$prefix}) eq 'HASH') {
7375: foreach my $key (keys(%{$settings->{$prefix}})) {
7376: $current{$key} = $settings->{$prefix}{$key};
7377: if ($key eq 'version') {
7378: if ($current{$key} ne '') {
1.145 raeburn 7379: $checkedon{$key} = ' checked="checked"';
7380: $checkedoff{$key} = '';
7381: }
1.279 raeburn 7382: } elsif (ref($current{$key}) eq 'ARRAY') {
7383: $checkedon{$key} = ' checked="checked"';
7384: $checkedoff{$key} = '';
1.137 raeburn 7385: }
7386: }
7387: }
1.279 raeburn 7388: }
7389: foreach my $type (@{$types}) {
7390: next if ($type ne 'version' && !@locations);
7391: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7392: $datatable .= '<tr'.$css_class.'>
7393: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
7394: <span class="LC_nobreak">
7395: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
7396: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
7397: if ($type eq 'version') {
7398: my @lcversions = &Apache::lonnet::all_loncaparevs();
7399: my $selector = '<select name="'.$prefix.'_version">';
7400: foreach my $version (@lcversions) {
7401: my $selected = '';
7402: if ($current{'version'} eq $version) {
7403: $selected = ' selected="selected"';
1.145 raeburn 7404: }
1.279 raeburn 7405: $selector .= ' <option value="'.$version.'"'.
7406: $selected.'>'.$version.'</option>';
7407: }
7408: $selector .= '</select> ';
7409: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
7410: } else {
7411: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
7412: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
7413: ' />'.(' 'x2).
7414: '<input type="button" value="'.&mt('uncheck all').'" '.
7415: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
7416: "\n".
7417: '</div><div><table>';
7418: my $rem;
7419: for (my $i=0; $i<@locations; $i++) {
7420: my ($showloc,$value,$checkedtype);
7421: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
7422: my $ip = $by_location->{$locations[$i]}->[0];
7423: if (ref($by_ip->{$ip}) eq 'ARRAY') {
7424: $value = join(':',@{$by_ip->{$ip}});
7425: $showloc = join(', ',@{$by_ip->{$ip}});
7426: if (ref($current{$type}) eq 'ARRAY') {
7427: foreach my $loc (@{$by_ip->{$ip}}) {
7428: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
7429: $checkedtype = ' checked="checked"';
7430: last;
1.145 raeburn 7431: }
1.138 raeburn 7432: }
7433: }
7434: }
1.137 raeburn 7435: }
1.279 raeburn 7436: $rem = $i%($numinrow);
7437: if ($rem == 0) {
7438: if ($i > 0) {
7439: $datatable .= '</tr>';
7440: }
7441: $datatable .= '<tr>';
7442: }
7443: $datatable .= '<td class="LC_left_item">'.
7444: '<span class="LC_nobreak"><label>'.
7445: '<input type="checkbox" name="'.$prefix.'_'.$type.
7446: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
7447: '</label></span></td>';
7448: }
7449: $rem = @locations%($numinrow);
7450: my $colsleft = $numinrow - $rem;
7451: if ($colsleft > 1 ) {
7452: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7453: ' </td>';
7454: } elsif ($colsleft == 1) {
7455: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 7456: }
1.279 raeburn 7457: $datatable .= '</tr></table>';
1.137 raeburn 7458: }
1.279 raeburn 7459: $datatable .= '</td></tr>';
7460: $itemcount ++;
1.137 raeburn 7461: }
7462: }
1.279 raeburn 7463: return ($datatable,$itemcount);
1.137 raeburn 7464: }
7465:
1.275 raeburn 7466: sub print_ssl {
7467: my ($position,$dom,$settings,$rowtotal) = @_;
7468: my ($css_class,$datatable);
7469: my $itemcount = 1;
7470: if ($position eq 'top') {
1.281 raeburn 7471: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7472: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7473: my $same_institution;
7474: if ($intdom ne '') {
7475: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
7476: if (ref($internet_names) eq 'ARRAY') {
7477: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
7478: $same_institution = 1;
7479: }
7480: }
7481: }
1.275 raeburn 7482: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 7483: $datatable = '<tr'.$css_class.'><td colspan="2">';
7484: if ($same_institution) {
7485: my %domservers = &Apache::lonnet::get_servers($dom);
7486: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
7487: } else {
7488: $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.");
7489: }
7490: $datatable .= '</td></tr>';
1.275 raeburn 7491: $itemcount ++;
7492: } else {
7493: my %titles = &ssl_titles();
7494: my (%by_ip,%by_location,@intdoms,@instdoms);
7495: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7496: my @alldoms = &Apache::lonnet::all_domains();
7497: my %serverhomes = %Apache::lonnet::serverhomeIDs;
7498: my @domservers = &Apache::lonnet::get_servers($dom);
7499: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7500: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 7501: if (($position eq 'connto') || ($position eq 'connfrom')) {
7502: my $legacy;
7503: unless (ref($settings) eq 'HASH') {
7504: my $name;
7505: if ($position eq 'connto') {
7506: $name = 'loncAllowInsecure';
7507: } else {
7508: $name = 'londAllowInsecure';
7509: }
7510: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
7511: my @ids=&Apache::lonnet::current_machine_ids();
7512: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
7513: my %what = (
7514: $name => 1,
7515: );
7516: my ($result,$returnhash) =
7517: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
7518: if ($result eq 'ok') {
7519: if (ref($returnhash) eq 'HASH') {
7520: $legacy = $returnhash->{$name};
7521: }
7522: }
7523: } else {
7524: $legacy = $Apache::lonnet::perlvar{$name};
7525: }
7526: }
1.275 raeburn 7527: foreach my $type ('dom','intdom','other') {
7528: my %checked;
7529: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7530: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
7531: '<td class="LC_right_item">';
7532: my $skip;
7533: if ($type eq 'dom') {
7534: unless (keys(%servers) > 1) {
7535: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
7536: $skip = 1;
7537: }
7538: }
7539: if ($type eq 'intdom') {
7540: unless (@instdoms > 1) {
7541: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
7542: $skip = 1;
7543: }
7544: } elsif ($type eq 'other') {
7545: if (keys(%by_location) == 0) {
7546: $datatable .= &mt('Nothing to set here, as there are no other institutions');
7547: $skip = 1;
7548: }
7549: }
7550: unless ($skip) {
7551: $checked{'yes'} = ' checked="checked"';
7552: if (ref($settings) eq 'HASH') {
1.293 raeburn 7553: if (ref($settings->{$position}) eq 'HASH') {
7554: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 7555: $checked{$1} = $checked{'yes'};
7556: delete($checked{'yes'});
7557: }
7558: }
1.293 raeburn 7559: } else {
7560: if ($legacy == 0) {
7561: $checked{'req'} = $checked{'yes'};
7562: delete($checked{'yes'});
7563: }
1.275 raeburn 7564: }
7565: foreach my $option ('no','yes','req') {
7566: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 7567: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 7568: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7569: '</label></span>'.(' 'x2);
7570: }
7571: }
7572: $datatable .= '</td></tr>';
7573: $itemcount ++;
7574: }
7575: } else {
7576: my $prefix = 'replication';
7577: my @types = ('certreq','nocertreq');
1.279 raeburn 7578: if (keys(%by_location) == 0) {
7579: $datatable .= '<tr'.$css_class.'><td>'.
7580: &mt('Nothing to set here, as there are no other institutions').
7581: '</td></tr>';
7582: $itemcount ++;
1.275 raeburn 7583: } else {
1.279 raeburn 7584: ($datatable,$itemcount) =
7585: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 7586: }
7587: }
7588: }
7589: $$rowtotal += $itemcount;
7590: return $datatable;
7591: }
7592:
7593: sub ssl_titles {
7594: return &Apache::lonlocal::texthash (
7595: dom => 'LON-CAPA servers/VMs from same domain',
7596: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
7597: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 7598: connto => 'Connections to other servers',
7599: connfrom => 'Connections from other servers',
1.275 raeburn 7600: replication => 'Replicating content to other institutions',
7601: certreq => 'Client certificate required, but specific domains exempt',
7602: nocertreq => 'No client certificate required, except for specific domains',
7603: no => 'SSL not used',
7604: yes => 'SSL Optional (used if available)',
7605: req => 'SSL Required',
7606: );
1.279 raeburn 7607: }
7608:
7609: sub print_trust {
7610: my ($prefix,$dom,$settings,$rowtotal) = @_;
7611: my ($css_class,$datatable,%checked,%choices);
7612: my (%by_ip,%by_location,@intdoms,@instdoms);
7613: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7614: my $itemcount = 1;
7615: my %titles = &trust_titles();
7616: my @types = ('exc','inc');
7617: if ($prefix eq 'top') {
7618: $prefix = 'content';
7619: } elsif ($prefix eq 'bottom') {
7620: $prefix = 'msg';
7621: }
7622: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
7623: $$rowtotal += $itemcount;
7624: return $datatable;
7625: }
7626:
7627: sub trust_titles {
7628: return &Apache::lonlocal::texthash(
7629: content => "Access to this domain's content by others",
7630: shared => "Access to other domain's content by this domain",
7631: enroll => "Enrollment in this domain's courses by others",
7632: othcoau => "Co-author roles in this domain for others",
7633: coaurem => "Co-author roles for this domain's users elsewhere",
7634: domroles => "Domain roles in this domain assignable to others",
7635: catalog => "Course Catalog for this domain displayed elsewhere",
7636: reqcrs => "Requests for creation of courses in this domain by others",
7637: msg => "Users in other domains can send messages to this domain",
7638: exc => "Allow all, but exclude specific domains",
7639: inc => "Deny all, but include specific domains",
7640: );
1.275 raeburn 7641: }
7642:
1.138 raeburn 7643: sub build_location_hashes {
1.275 raeburn 7644: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 7645: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 7646: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 7647: my %iphost = &Apache::lonnet::get_iphost();
7648: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
7649: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
7650: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
7651: foreach my $id (@{$iphost{$primary_ip}}) {
7652: my $intdom = &Apache::lonnet::internet_dom($id);
7653: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
7654: push(@{$intdoms},$intdom);
7655: }
7656: }
7657: }
7658: foreach my $ip (keys(%iphost)) {
7659: if (ref($iphost{$ip}) eq 'ARRAY') {
7660: foreach my $id (@{$iphost{$ip}}) {
7661: my $location = &Apache::lonnet::internet_dom($id);
7662: if ($location) {
1.275 raeburn 7663: if (grep(/^\Q$location\E$/,@{$intdoms})) {
7664: my $dom = &Apache::lonnet::host_domain($id);
7665: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
7666: push(@{$instdoms},$dom);
7667: }
7668: next;
7669: }
1.138 raeburn 7670: if (ref($by_ip->{$ip}) eq 'ARRAY') {
7671: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
7672: push(@{$by_ip->{$ip}},$location);
7673: }
7674: } else {
7675: $by_ip->{$ip} = [$location];
7676: }
7677: }
7678: }
7679: }
7680: }
7681: foreach my $ip (sort(keys(%{$by_ip}))) {
7682: if (ref($by_ip->{$ip}) eq 'ARRAY') {
7683: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
7684: my $first = $by_ip->{$ip}->[0];
7685: if (ref($by_location->{$first}) eq 'ARRAY') {
7686: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
7687: push(@{$by_location->{$first}},$ip);
7688: }
7689: } else {
7690: $by_location->{$first} = [$ip];
7691: }
7692: }
7693: }
7694: return;
7695: }
7696:
1.145 raeburn 7697: sub current_offloads_to {
7698: my ($dom,$settings,$servers) = @_;
7699: my (%spareid,%otherdomconfigs);
1.152 raeburn 7700: if (ref($servers) eq 'HASH') {
1.145 raeburn 7701: foreach my $lonhost (sort(keys(%{$servers}))) {
7702: my $gotspares;
1.152 raeburn 7703: if (ref($settings) eq 'HASH') {
7704: if (ref($settings->{'spares'}) eq 'HASH') {
7705: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
7706: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
7707: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
7708: $gotspares = 1;
7709: }
1.145 raeburn 7710: }
7711: }
7712: unless ($gotspares) {
7713: my $gotspares;
7714: my $serverhomeID =
7715: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
7716: my $serverhomedom =
7717: &Apache::lonnet::host_domain($serverhomeID);
7718: if ($serverhomedom ne $dom) {
7719: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
7720: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
7721: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
7722: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
7723: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
7724: $gotspares = 1;
7725: }
7726: }
7727: } else {
7728: $otherdomconfigs{$serverhomedom} =
7729: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
7730: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
7731: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
7732: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
7733: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
7734: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
7735: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
7736: $gotspares = 1;
7737: }
7738: }
7739: }
7740: }
7741: }
7742: }
7743: }
7744: unless ($gotspares) {
7745: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
7746: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
7747: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
7748: } else {
7749: my $server_hostname = &Apache::lonnet::hostname($lonhost);
7750: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
7751: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
7752: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
7753: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
7754: } else {
1.150 raeburn 7755: my %what = (
7756: spareid => 1,
7757: );
7758: my ($result,$returnhash) =
7759: &Apache::lonnet::get_remote_globals($lonhost,\%what);
7760: if ($result eq 'ok') {
7761: if (ref($returnhash) eq 'HASH') {
7762: if (ref($returnhash->{'spareid'}) eq 'HASH') {
7763: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
7764: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
7765: }
7766: }
1.145 raeburn 7767: }
7768: }
7769: }
7770: }
7771: }
7772: }
7773: return %spareid;
7774: }
7775:
7776: sub spares_row {
1.371 raeburn 7777: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
7778: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 7779: my $css_class;
7780: my $numinrow = 4;
7781: my $itemcount = 1;
7782: my $datatable;
1.152 raeburn 7783: my %typetitles = &sparestype_titles();
7784: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 7785: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 7786: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
7787: my ($othercontrol,$serverdom);
7788: if ($serverhome ne $server) {
7789: $serverdom = &Apache::lonnet::host_domain($serverhome);
7790: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
7791: } else {
7792: $serverdom = &Apache::lonnet::host_domain($server);
7793: if ($serverdom ne $dom) {
7794: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
7795: }
7796: }
7797: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 7798: my ($checkednow,$checkedoth);
1.261 raeburn 7799: if (ref($curroffloadnow) eq 'HASH') {
7800: if ($curroffloadnow->{$server}) {
7801: $checkednow = ' checked="checked"';
7802: }
7803: }
1.371 raeburn 7804: if (ref($curroffloadoth) eq 'HASH') {
7805: if ($curroffloadoth->{$server}) {
7806: $checkedoth = ' checked="checked"';
7807: }
7808: }
1.145 raeburn 7809: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7810: $datatable .= '<tr'.$css_class.'>
7811: <td rowspan="2">
1.183 bisitz 7812: <span class="LC_nobreak">'.
7813: &mt('[_1] when busy, offloads to:'
1.261 raeburn 7814: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 7815: '<span class="LC_nobreak">'."\n".
1.261 raeburn 7816: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 7817: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 7818: "\n";
1.371 raeburn 7819: if ($other_insts) {
7820: $datatable .= '<br />'.
7821: '<span class="LC_nobreak">'."\n".
7822: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
7823: ' '.&mt('Switch other institutions on next access').'</label></span>'.
7824: "\n";
7825: }
1.145 raeburn 7826: my (%current,%canselect);
1.152 raeburn 7827: my @choices =
7828: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
7829: foreach my $type ('primary','default') {
7830: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 7831: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
7832: my @spares = @{$spareid->{$server}{$type}};
7833: if (@spares > 0) {
1.152 raeburn 7834: if ($othercontrol) {
7835: $current{$type} = join(', ',@spares);
7836: } else {
7837: $current{$type} .= '<table>';
7838: my $numspares = scalar(@spares);
7839: for (my $i=0; $i<@spares; $i++) {
7840: my $rem = $i%($numinrow);
7841: if ($rem == 0) {
7842: if ($i > 0) {
7843: $current{$type} .= '</tr>';
7844: }
7845: $current{$type} .= '<tr>';
1.145 raeburn 7846: }
1.152 raeburn 7847: $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'".');" /> '.
7848: $spareid->{$server}{$type}[$i].
7849: '</label></td>'."\n";
7850: }
7851: my $rem = @spares%($numinrow);
7852: my $colsleft = $numinrow - $rem;
7853: if ($colsleft > 1 ) {
7854: $current{$type} .= '<td colspan="'.$colsleft.
7855: '" class="LC_left_item">'.
7856: ' </td>';
7857: } elsif ($colsleft == 1) {
7858: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 7859: }
1.152 raeburn 7860: $current{$type} .= '</tr></table>';
1.150 raeburn 7861: }
1.145 raeburn 7862: }
7863: }
7864: if ($current{$type} eq '') {
7865: $current{$type} = &mt('None specified');
7866: }
1.152 raeburn 7867: if ($othercontrol) {
7868: if ($type eq 'primary') {
7869: $canselect{$type} = $othercontrol;
7870: }
7871: } else {
7872: $canselect{$type} =
7873: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
7874: '<select name="newspare_'.$type.'_'.$server.'" '.
7875: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
7876: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
7877: if (@choices > 0) {
7878: foreach my $lonhost (@choices) {
7879: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
7880: }
7881: }
7882: $canselect{$type} .= '</select>'."\n";
7883: }
7884: } else {
7885: $current{$type} = &mt('Could not be determined');
7886: if ($type eq 'primary') {
7887: $canselect{$type} = $othercontrol;
7888: }
1.145 raeburn 7889: }
1.152 raeburn 7890: if ($type eq 'default') {
7891: $datatable .= '<tr'.$css_class.'>';
7892: }
7893: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
7894: '<td>'.$current{$type}.'</td>'."\n".
7895: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 7896: }
7897: $itemcount ++;
7898: }
7899: }
7900: $$rowtotal += $itemcount;
7901: return $datatable;
7902: }
7903:
1.152 raeburn 7904: sub possible_newspares {
7905: my ($server,$currspares,$serverhomes,$altids) = @_;
7906: my $serverhostname = &Apache::lonnet::hostname($server);
7907: my %excluded;
7908: if ($serverhostname ne '') {
7909: %excluded = (
7910: $serverhostname => 1,
7911: );
7912: }
7913: if (ref($currspares) eq 'HASH') {
7914: foreach my $type (keys(%{$currspares})) {
7915: if (ref($currspares->{$type}) eq 'ARRAY') {
7916: if (@{$currspares->{$type}} > 0) {
7917: foreach my $curr (@{$currspares->{$type}}) {
7918: my $hostname = &Apache::lonnet::hostname($curr);
7919: $excluded{$hostname} = 1;
7920: }
7921: }
7922: }
7923: }
7924: }
7925: my @choices;
7926: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
7927: if (keys(%{$serverhomes}) > 1) {
7928: foreach my $name (sort(keys(%{$serverhomes}))) {
7929: unless ($excluded{$name}) {
7930: if (exists($altids->{$serverhomes->{$name}})) {
7931: push(@choices,$altids->{$serverhomes->{$name}});
7932: } else {
7933: push(@choices,$serverhomes->{$name});
1.145 raeburn 7934: }
7935: }
7936: }
7937: }
7938: }
1.152 raeburn 7939: return sort(@choices);
1.145 raeburn 7940: }
7941:
1.150 raeburn 7942: sub print_loadbalancing {
7943: my ($dom,$settings,$rowtotal) = @_;
7944: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7945: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7946: my $numinrow = 1;
7947: my $datatable;
7948: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 7949: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 7950: if (ref($settings) eq 'HASH') {
7951: %existing = %{$settings};
7952: }
7953: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
7954: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 7955: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 7956: } else {
7957: return;
7958: }
7959: my ($othertitle,$usertypes,$types) =
7960: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 7961: my $rownum = 8;
1.150 raeburn 7962: if (ref($types) eq 'ARRAY') {
7963: $rownum += scalar(@{$types});
7964: }
1.171 raeburn 7965: my @css_class = ('LC_odd_row','LC_even_row');
7966: my $balnum = 0;
7967: my $islast;
7968: my (@toshow,$disabledtext);
7969: if (keys(%currbalancer) > 0) {
7970: @toshow = sort(keys(%currbalancer));
7971: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
7972: push(@toshow,'');
7973: }
7974: } else {
7975: @toshow = ('');
7976: $disabledtext = &mt('No existing load balancer');
7977: }
7978: foreach my $lonhost (@toshow) {
7979: if ($balnum == scalar(@toshow)-1) {
7980: $islast = 1;
7981: } else {
7982: $islast = 0;
7983: }
7984: my $cssidx = $balnum%2;
7985: my $targets_div_style = 'display: none';
7986: my $disabled_div_style = 'display: block';
7987: my $homedom_div_style = 'display: none';
7988: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 7989: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 7990: '<p>';
7991: if ($lonhost eq '') {
1.210 raeburn 7992: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 7993: if (keys(%currbalancer) > 0) {
7994: $datatable .= &mt('Add balancer:');
7995: } else {
7996: $datatable .= &mt('Enable balancer:');
7997: }
7998: $datatable .= ' '.
7999: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
8000: ' id="loadbalancing_lonhost_'.$balnum.'"'.
8001: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
8002: '<option value="" selected="selected">'.&mt('None').
8003: '</option>'."\n";
8004: foreach my $server (sort(keys(%servers))) {
8005: next if ($currbalancer{$server});
8006: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
8007: }
1.210 raeburn 8008: $datatable .=
1.171 raeburn 8009: '</select>'."\n".
8010: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
8011: } else {
8012: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
8013: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
8014: &mt('Stop balancing').'</label>'.
8015: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
8016: $targets_div_style = 'display: block';
8017: $disabled_div_style = 'display: none';
8018: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
8019: $homedom_div_style = 'display: block';
8020: }
8021: }
1.306 raeburn 8022: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 8023: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
8024: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
8025: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
8026: my ($numspares,@spares) = &count_servers($lonhost,%servers);
8027: my @sparestypes = ('primary','default');
8028: my %typetitles = &sparestype_titles();
1.284 raeburn 8029: my %hostherechecked = (
8030: no => ' checked="checked"',
8031: );
1.342 raeburn 8032: my %balcookiechecked = (
8033: no => ' checked="checked"',
8034: );
1.171 raeburn 8035: foreach my $sparetype (@sparestypes) {
8036: my $targettable;
8037: for (my $i=0; $i<$numspares; $i++) {
8038: my $checked;
8039: if (ref($currtargets{$lonhost}) eq 'HASH') {
8040: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
8041: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
8042: $checked = ' checked="checked"';
8043: }
8044: }
8045: }
8046: my ($chkboxval,$disabled);
8047: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
8048: $chkboxval = $spares[$i];
8049: }
8050: if (exists($currbalancer{$spares[$i]})) {
8051: $disabled = ' disabled="disabled"';
8052: }
1.210 raeburn 8053: $targettable .=
1.253 raeburn 8054: '<td><span class="LC_nobreak"><label>'.
8055: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 8056: $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 8057: '</span></label></span></td>';
1.171 raeburn 8058: my $rem = $i%($numinrow);
8059: if ($rem == 0) {
8060: if (($i > 0) && ($i < $numspares-1)) {
8061: $targettable .= '</tr>';
8062: }
8063: if ($i < $numspares-1) {
8064: $targettable .= '<tr>';
1.150 raeburn 8065: }
8066: }
8067: }
1.171 raeburn 8068: if ($targettable ne '') {
8069: my $rem = $numspares%($numinrow);
8070: my $colsleft = $numinrow - $rem;
8071: if ($colsleft > 1 ) {
8072: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8073: ' </td>';
8074: } elsif ($colsleft == 1) {
8075: $targettable .= '<td class="LC_left_item"> </td>';
8076: }
8077: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
8078: '<table><tr>'.$targettable.'</tr></table><br />';
8079: }
1.284 raeburn 8080: $hostherechecked{$sparetype} = '';
8081: if (ref($currtargets{$lonhost}) eq 'HASH') {
8082: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
8083: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
8084: $hostherechecked{$sparetype} = ' checked="checked"';
8085: $hostherechecked{'no'} = '';
8086: }
8087: }
8088: }
8089: }
1.342 raeburn 8090: if ($currcookies{$lonhost}) {
8091: %balcookiechecked = (
8092: yes => ' checked="checked"',
8093: );
8094: }
1.284 raeburn 8095: $datatable .= &mt('Hosting on balancer itself').'<br />'.
8096: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
8097: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
8098: foreach my $sparetype (@sparestypes) {
8099: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
8100: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
8101: '</i></label><br />';
1.171 raeburn 8102: }
1.342 raeburn 8103: $datatable .= &mt('Use balancer cookie').'<br />'.
8104: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
8105: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
8106: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
8107: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
8108: '</div></td></tr>'.
1.171 raeburn 8109: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
8110: $othertitle,$usertypes,$types,\%servers,
8111: \%currbalancer,$lonhost,
8112: $targets_div_style,$homedom_div_style,
8113: $css_class[$cssidx],$balnum,$islast);
8114: $$rowtotal += $rownum;
8115: $balnum ++;
8116: }
8117: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
8118: return $datatable;
8119: }
8120:
8121: sub get_loadbalancers_config {
1.342 raeburn 8122: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 8123: return unless ((ref($servers) eq 'HASH') &&
8124: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 8125: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
8126: (ref($currcookies) eq 'HASH'));
1.171 raeburn 8127: if (keys(%{$existing}) > 0) {
8128: my $oldlonhost;
8129: foreach my $key (sort(keys(%{$existing}))) {
8130: if ($key eq 'lonhost') {
8131: $oldlonhost = $existing->{'lonhost'};
8132: $currbalancer->{$oldlonhost} = 1;
8133: } elsif ($key eq 'targets') {
8134: if ($oldlonhost) {
8135: $currtargets->{$oldlonhost} = $existing->{'targets'};
8136: }
8137: } elsif ($key eq 'rules') {
8138: if ($oldlonhost) {
8139: $currrules->{$oldlonhost} = $existing->{'rules'};
8140: }
8141: } elsif (ref($existing->{$key}) eq 'HASH') {
8142: $currbalancer->{$key} = 1;
8143: $currtargets->{$key} = $existing->{$key}{'targets'};
8144: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 8145: if ($existing->{$key}{'cookie'}) {
8146: $currcookies->{$key} = 1;
8147: }
1.150 raeburn 8148: }
8149: }
1.171 raeburn 8150: } else {
8151: my ($balancerref,$targetsref) =
8152: &Apache::lonnet::get_lonbalancer_config($servers);
8153: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
8154: foreach my $server (sort(keys(%{$balancerref}))) {
8155: $currbalancer->{$server} = 1;
8156: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 8157: }
8158: }
8159: }
1.171 raeburn 8160: return;
1.150 raeburn 8161: }
8162:
8163: sub loadbalancing_rules {
8164: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 8165: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
8166: $css_class,$balnum,$islast) = @_;
1.150 raeburn 8167: my $output;
1.171 raeburn 8168: my $num = 0;
1.210 raeburn 8169: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 8170: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8171: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8172: foreach my $type (@{$alltypes}) {
1.171 raeburn 8173: $num ++;
1.150 raeburn 8174: my $current;
8175: if (ref($currrules) eq 'HASH') {
8176: $current = $currrules->{$type};
8177: }
1.253 raeburn 8178: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 8179: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 8180: $current = '';
8181: }
8182: }
8183: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 8184: $servers,$currbalancer,$lonhost,$dom,
8185: $targets_div_style,$homedom_div_style,
8186: $css_class,$balnum,$num,$islast);
1.150 raeburn 8187: }
8188: }
8189: return $output;
8190: }
8191:
8192: sub loadbalancing_titles {
8193: my ($dom,$intdom,$usertypes,$types) = @_;
8194: my %othertypes = (
8195: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
8196: '_LC_author' => &mt('Users from [_1] with author role',$dom),
8197: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
8198: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 8199: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
8200: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 8201: );
1.209 raeburn 8202: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 8203: my @available;
1.150 raeburn 8204: if (ref($types) eq 'ARRAY') {
1.302 raeburn 8205: @available = @{$types};
1.150 raeburn 8206: }
1.302 raeburn 8207: unless (grep(/^default$/,@available)) {
8208: push(@available,'default');
8209: }
8210: unshift(@alltypes,@available);
1.150 raeburn 8211: my %titles;
8212: foreach my $type (@alltypes) {
8213: if ($type =~ /^_LC_/) {
8214: $titles{$type} = $othertypes{$type};
8215: } elsif ($type eq 'default') {
8216: $titles{$type} = &mt('All users from [_1]',$dom);
8217: if (ref($types) eq 'ARRAY') {
8218: if (@{$types} > 0) {
8219: $titles{$type} = &mt('Other users from [_1]',$dom);
8220: }
8221: }
8222: } elsif (ref($usertypes) eq 'HASH') {
8223: $titles{$type} = $usertypes->{$type};
8224: }
8225: }
8226: return (\@alltypes,\%othertypes,\%titles);
8227: }
8228:
8229: sub loadbalance_rule_row {
1.171 raeburn 8230: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
8231: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 8232: my @rulenames;
1.150 raeburn 8233: my %ruletitles = &offloadtype_text();
1.209 raeburn 8234: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 8235: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 8236: } else {
1.209 raeburn 8237: @rulenames = ('default','homeserver');
8238: if ($type eq '_LC_external') {
8239: push(@rulenames,'externalbalancer');
8240: } else {
8241: push(@rulenames,'specific');
8242: }
8243: push(@rulenames,'none');
1.150 raeburn 8244: }
8245: my $style = $targets_div_style;
1.253 raeburn 8246: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 8247: $style = $homedom_div_style;
8248: }
1.171 raeburn 8249: my $space;
8250: if ($islast && $num == 1) {
1.317 raeburn 8251: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 8252: }
1.210 raeburn 8253: my $output =
1.306 raeburn 8254: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 8255: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
8256: '<td valaign="top">'.$space.
8257: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 8258: for (my $i=0; $i<@rulenames; $i++) {
8259: my $rule = $rulenames[$i];
8260: my ($checked,$extra);
8261: if ($rulenames[$i] eq 'default') {
8262: $rule = '';
8263: }
8264: if ($rulenames[$i] eq 'specific') {
8265: if (ref($servers) eq 'HASH') {
8266: my $default;
8267: if (($current ne '') && (exists($servers->{$current}))) {
8268: $checked = ' checked="checked"';
8269: }
8270: unless ($checked) {
8271: $default = ' selected="selected"';
8272: }
1.210 raeburn 8273: $extra =
1.171 raeburn 8274: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
8275: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
8276: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
8277: '<option value=""'.$default.'></option>'."\n";
8278: foreach my $server (sort(keys(%{$servers}))) {
8279: if (ref($currbalancer) eq 'HASH') {
8280: next if (exists($currbalancer->{$server}));
8281: }
1.150 raeburn 8282: my $selected;
1.171 raeburn 8283: if ($server eq $current) {
1.150 raeburn 8284: $selected = ' selected="selected"';
8285: }
1.171 raeburn 8286: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 8287: }
8288: $extra .= '</select>';
8289: }
8290: } elsif ($rule eq $current) {
8291: $checked = ' checked="checked"';
8292: }
8293: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 8294: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
8295: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
8296: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 8297: ')"'.$checked.' /> ';
8298: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
8299: $output .= $ruletitles{'particular'};
8300: } else {
8301: $output .= $ruletitles{$rulenames[$i]};
8302: }
8303: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 8304: }
8305: $output .= '</div></td></tr>'."\n";
8306: return $output;
8307: }
8308:
8309: sub offloadtype_text {
8310: my %ruletitles = &Apache::lonlocal::texthash (
8311: 'default' => 'Offloads to default destinations',
8312: 'homeserver' => "Offloads to user's home server",
8313: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
8314: 'specific' => 'Offloads to specific server',
1.161 raeburn 8315: 'none' => 'No offload',
1.209 raeburn 8316: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
8317: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 8318: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 8319: );
8320: return %ruletitles;
8321: }
8322:
8323: sub sparestype_titles {
8324: my %typestitles = &Apache::lonlocal::texthash (
8325: 'primary' => 'primary',
8326: 'default' => 'default',
8327: );
8328: return %typestitles;
8329: }
8330:
1.28 raeburn 8331: sub contact_titles {
8332: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 8333: 'supportemail' => 'Support E-mail address',
8334: 'adminemail' => 'Default Server Admin E-mail address',
8335: 'errormail' => 'Error reports to be e-mailed to',
8336: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 8337: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
8338: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 8339: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
8340: 'requestsmail' => 'E-mail from course requests requiring approval',
8341: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 8342: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 8343: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.340 raeburn 8344: 'errorthreshold' => 'Error/warning threshold for status e-mail',
8345: 'errorsysmail' => 'Error threshold for e-mail to core group',
8346: 'errorweights' => 'Weights used to compute error count',
8347: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 8348: );
8349: my %short_titles = &Apache::lonlocal::texthash (
8350: adminemail => 'Admin E-mail address',
8351: supportemail => 'Support E-mail',
8352: );
8353: return (\%titles,\%short_titles);
8354: }
8355:
1.286 raeburn 8356: sub helpform_fields {
8357: my %titles = &Apache::lonlocal::texthash (
8358: 'username' => 'Name',
8359: 'user' => 'Username/domain',
8360: 'phone' => 'Phone',
8361: 'cc' => 'Cc e-mail',
8362: 'course' => 'Course Details',
8363: 'section' => 'Sections',
1.289 raeburn 8364: 'screenshot' => 'File upload',
1.286 raeburn 8365: );
8366: my @fields = ('username','phone','user','course','section','cc','screenshot');
8367: my %possoptions = (
8368: username => ['yes','no','req'],
1.289 raeburn 8369: phone => ['yes','no','req'],
1.286 raeburn 8370: user => ['yes','no'],
1.289 raeburn 8371: cc => ['yes','no'],
1.286 raeburn 8372: course => ['yes','no'],
8373: section => ['yes','no'],
8374: screenshot => ['yes','no'],
8375: );
8376: my %fieldoptions = &Apache::lonlocal::texthash (
8377: 'yes' => 'Optional',
8378: 'req' => 'Required',
8379: 'no' => "Not shown",
8380: );
8381: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
8382: }
8383:
1.72 raeburn 8384: sub tool_titles {
8385: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 8386: aboutme => 'Personal web page',
1.86 raeburn 8387: blog => 'Blog',
1.162 raeburn 8388: webdav => 'WebDAV',
1.86 raeburn 8389: portfolio => 'Portfolio',
1.88 bisitz 8390: official => 'Official courses (with institutional codes)',
8391: unofficial => 'Unofficial courses',
1.98 raeburn 8392: community => 'Communities',
1.216 raeburn 8393: textbook => 'Textbook courses',
1.271 raeburn 8394: placement => 'Placement tests',
1.86 raeburn 8395: );
1.72 raeburn 8396: return %titles;
8397: }
8398:
1.101 raeburn 8399: sub courserequest_titles {
8400: my %titles = &Apache::lonlocal::texthash (
8401: official => 'Official',
8402: unofficial => 'Unofficial',
8403: community => 'Communities',
1.216 raeburn 8404: textbook => 'Textbook',
1.271 raeburn 8405: placement => 'Placement tests',
1.325 raeburn 8406: lti => 'LTI Provider',
1.101 raeburn 8407: norequest => 'Not allowed',
1.325 raeburn 8408: approval => 'Approval by DC',
1.101 raeburn 8409: validate => 'With validation',
8410: autolimit => 'Numerical limit',
1.103 raeburn 8411: unlimited => '(blank for unlimited)',
1.101 raeburn 8412: );
8413: return %titles;
8414: }
8415:
1.163 raeburn 8416: sub authorrequest_titles {
8417: my %titles = &Apache::lonlocal::texthash (
8418: norequest => 'Not allowed',
8419: approval => 'Approval by Dom. Coord.',
8420: automatic => 'Automatic approval',
8421: );
8422: return %titles;
1.210 raeburn 8423: }
1.163 raeburn 8424:
1.101 raeburn 8425: sub courserequest_conditions {
8426: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 8427: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 8428: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 8429: );
8430: return %conditions;
8431: }
8432:
8433:
1.27 raeburn 8434: sub print_usercreation {
1.30 raeburn 8435: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 8436: my $numinrow = 4;
1.28 raeburn 8437: my $datatable;
8438: if ($position eq 'top') {
1.30 raeburn 8439: $$rowtotal ++;
1.34 raeburn 8440: my $rowcount = 0;
1.32 raeburn 8441: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 8442: if (ref($rules) eq 'HASH') {
8443: if (keys(%{$rules}) > 0) {
1.32 raeburn 8444: $datatable .= &user_formats_row('username',$settings,$rules,
8445: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 8446: $$rowtotal ++;
1.32 raeburn 8447: $rowcount ++;
8448: }
8449: }
8450: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
8451: if (ref($idrules) eq 'HASH') {
8452: if (keys(%{$idrules}) > 0) {
8453: $datatable .= &user_formats_row('id',$settings,$idrules,
8454: $idruleorder,$numinrow,$rowcount);
8455: $$rowtotal ++;
8456: $rowcount ++;
1.28 raeburn 8457: }
8458: }
1.39 raeburn 8459: if ($rowcount == 0) {
8460: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
8461: $$rowtotal ++;
8462: $rowcount ++;
8463: }
1.34 raeburn 8464: } elsif ($position eq 'middle') {
1.224 raeburn 8465: my @creators = ('author','course','requestcrs');
1.37 raeburn 8466: my ($rules,$ruleorder) =
8467: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 8468: my %lt = &usercreation_types();
8469: my %checked;
8470: if (ref($settings) eq 'HASH') {
8471: if (ref($settings->{'cancreate'}) eq 'HASH') {
8472: foreach my $item (@creators) {
8473: $checked{$item} = $settings->{'cancreate'}{$item};
8474: }
8475: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
8476: foreach my $item (@creators) {
8477: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
8478: $checked{$item} = 'none';
8479: }
8480: }
8481: }
8482: }
8483: my $rownum = 0;
8484: foreach my $item (@creators) {
8485: $rownum ++;
1.224 raeburn 8486: if ($checked{$item} eq '') {
8487: $checked{$item} = 'any';
1.34 raeburn 8488: }
8489: my $css_class;
8490: if ($rownum%2) {
8491: $css_class = '';
8492: } else {
8493: $css_class = ' class="LC_odd_row" ';
8494: }
8495: $datatable .= '<tr'.$css_class.'>'.
8496: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 8497: '</span></td><td style="text-align: right">';
1.224 raeburn 8498: my @options = ('any');
8499: if (ref($rules) eq 'HASH') {
8500: if (keys(%{$rules}) > 0) {
8501: push(@options,('official','unofficial'));
1.37 raeburn 8502: }
8503: }
1.224 raeburn 8504: push(@options,'none');
1.37 raeburn 8505: foreach my $option (@options) {
1.50 raeburn 8506: my $type = 'radio';
1.34 raeburn 8507: my $check = ' ';
1.224 raeburn 8508: if ($checked{$item} eq $option) {
8509: $check = ' checked="checked" ';
1.34 raeburn 8510: }
8511: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 8512: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 8513: $item.'" value="'.$option.'"'.$check.'/> '.
8514: $lt{$option}.'</label> </span>';
8515: }
8516: $datatable .= '</td></tr>';
8517: }
1.28 raeburn 8518: } else {
8519: my @contexts = ('author','course','domain');
1.325 raeburn 8520: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 8521: my %checked;
8522: if (ref($settings) eq 'HASH') {
8523: if (ref($settings->{'authtypes'}) eq 'HASH') {
8524: foreach my $item (@contexts) {
8525: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
8526: foreach my $auth (@authtypes) {
8527: if ($settings->{'authtypes'}{$item}{$auth}) {
8528: $checked{$item}{$auth} = ' checked="checked" ';
8529: }
8530: }
8531: }
8532: }
1.27 raeburn 8533: }
1.35 raeburn 8534: } else {
8535: foreach my $item (@contexts) {
1.36 raeburn 8536: foreach my $auth (@authtypes) {
1.35 raeburn 8537: $checked{$item}{$auth} = ' checked="checked" ';
8538: }
8539: }
1.27 raeburn 8540: }
1.28 raeburn 8541: my %title = &context_names();
8542: my %authname = &authtype_names();
8543: my $rownum = 0;
8544: my $css_class;
8545: foreach my $item (@contexts) {
8546: if ($rownum%2) {
8547: $css_class = '';
8548: } else {
8549: $css_class = ' class="LC_odd_row" ';
8550: }
1.30 raeburn 8551: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 8552: '<td>'.$title{$item}.
8553: '</td><td class="LC_left_item">'.
8554: '<span class="LC_nobreak">';
8555: foreach my $auth (@authtypes) {
8556: $datatable .= '<label>'.
8557: '<input type="checkbox" name="'.$item.'_auth" '.
8558: $checked{$item}{$auth}.' value="'.$auth.'" />'.
8559: $authname{$auth}.'</label> ';
8560: }
8561: $datatable .= '</span></td></tr>';
8562: $rownum ++;
1.27 raeburn 8563: }
1.30 raeburn 8564: $$rowtotal += $rownum;
1.27 raeburn 8565: }
8566: return $datatable;
8567: }
8568:
1.224 raeburn 8569: sub print_selfcreation {
8570: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 8571: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
8572: $emaildomain,$datatable);
1.224 raeburn 8573: if (ref($settings) eq 'HASH') {
8574: if (ref($settings->{'cancreate'}) eq 'HASH') {
8575: $createsettings = $settings->{'cancreate'};
1.236 raeburn 8576: if (ref($createsettings) eq 'HASH') {
8577: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
8578: @selfcreate = @{$createsettings->{'selfcreate'}};
8579: } elsif ($createsettings->{'selfcreate'} ne '') {
8580: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
8581: @selfcreate = ('email','login','sso');
8582: } elsif ($createsettings->{'selfcreate'} ne 'none') {
8583: @selfcreate = ($createsettings->{'selfcreate'});
8584: }
8585: }
8586: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
8587: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 8588: }
1.305 raeburn 8589: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
8590: $emailoptions = $createsettings->{'emailoptions'};
8591: }
1.303 raeburn 8592: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
8593: $emailverified = $createsettings->{'emailverified'};
8594: }
8595: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
8596: $emaildomain = $createsettings->{'emaildomain'};
8597: }
1.224 raeburn 8598: }
8599: }
8600: }
8601: my %radiohash;
8602: my $numinrow = 4;
8603: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 8604: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 8605: if ($position eq 'top') {
8606: my %choices = &Apache::lonlocal::texthash (
8607: cancreate_login => 'Institutional Login',
8608: cancreate_sso => 'Institutional Single Sign On',
8609: );
8610: my @toggles = sort(keys(%choices));
8611: my %defaultchecked = (
8612: 'cancreate_login' => 'off',
8613: 'cancreate_sso' => 'off',
8614: );
1.228 raeburn 8615: my ($onclick,$itemcount);
1.224 raeburn 8616: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
8617: \%choices,$itemcount,$onclick);
1.228 raeburn 8618: $$rowtotal += $itemcount;
8619:
1.224 raeburn 8620: if (ref($usertypes) eq 'HASH') {
8621: if (keys(%{$usertypes}) > 0) {
8622: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
8623: $dom,$numinrow,$othertitle,
1.305 raeburn 8624: 'statustocreate',$rowtotal);
1.224 raeburn 8625: $$rowtotal ++;
8626: }
8627: }
1.240 raeburn 8628: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
8629: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8630: $fieldtitles{'inststatus'} = &mt('Institutional status');
8631: my $rem;
8632: my $numperrow = 2;
8633: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
8634: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 8635: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 8636: '<td class="LC_left_item">'."\n".
1.334 raeburn 8637: '<table>'."\n";
1.240 raeburn 8638: for (my $i=0; $i<@fields; $i++) {
8639: $rem = $i%($numperrow);
8640: if ($rem == 0) {
8641: if ($i > 0) {
8642: $datatable .= '</tr>';
8643: }
8644: $datatable .= '<tr>';
8645: }
8646: my $currval;
1.248 raeburn 8647: if (ref($createsettings) eq 'HASH') {
8648: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
8649: $currval = $createsettings->{'shibenv'}{$fields[$i]};
8650: }
1.240 raeburn 8651: }
8652: $datatable .= '<td class="LC_left_item">'.
8653: '<span class="LC_nobreak">'.
8654: '<input type="text" name="shibenv_'.$fields[$i].'" '.
8655: 'value="'.$currval.'" size="10" /> '.
8656: $fieldtitles{$fields[$i]}.'</span></td>';
8657: }
8658: my $colsleft = $numperrow - $rem;
8659: if ($colsleft > 1 ) {
8660: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8661: ' </td>';
8662: } elsif ($colsleft == 1) {
8663: $datatable .= '<td class="LC_left_item"> </td>';
8664: }
8665: $datatable .= '</tr></table></td></tr>';
8666: $$rowtotal ++;
1.224 raeburn 8667: } elsif ($position eq 'middle') {
8668: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 8669: my @posstypes;
1.224 raeburn 8670: if (ref($types) eq 'ARRAY') {
1.302 raeburn 8671: @posstypes = @{$types};
8672: }
8673: unless (grep(/^default$/,@posstypes)) {
8674: push(@posstypes,'default');
8675: }
8676: my %usertypeshash;
8677: if (ref($usertypes) eq 'HASH') {
8678: %usertypeshash = %{$usertypes};
8679: }
8680: $usertypeshash{'default'} = $othertitle;
8681: foreach my $status (@posstypes) {
8682: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
8683: $numinrow,$$rowtotal,\%usertypeshash);
8684: $$rowtotal ++;
1.224 raeburn 8685: }
8686: } else {
1.236 raeburn 8687: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 8688: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 8689: );
8690: my @toggles = sort(keys(%choices));
8691: my %defaultchecked = (
8692: 'cancreate_email' => 'off',
8693: );
1.305 raeburn 8694: my $customclass = 'LC_selfcreate_email';
8695: my $classprefix = 'LC_canmodify_emailusername_';
8696: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 8697: my $display = 'none';
1.305 raeburn 8698: my $rowstyle = 'display:none';
1.236 raeburn 8699: if (grep(/^\Qemail\E$/,@selfcreate)) {
8700: $display = 'block';
1.305 raeburn 8701: $rowstyle = 'display:table-row';
1.236 raeburn 8702: }
1.305 raeburn 8703: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
8704: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
8705: \%choices,$$rowtotal,$onclick);
8706: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
8707: $rowstyle);
8708: $$rowtotal ++;
8709: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
8710: $rowstyle);
8711: $$rowtotal ++;
8712: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 8713: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 8714: my ($emailrules,$emailruleorder) =
8715: &Apache::lonnet::inst_userrules($dom,'email');
8716: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8717: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8718: if (ref($types) eq 'ARRAY') {
8719: @posstypes = @{$types};
8720: }
8721: if (@posstypes) {
8722: unless (grep(/^default$/,@posstypes)) {
8723: push(@posstypes,'default');
1.302 raeburn 8724: }
8725: if (ref($usertypes) eq 'HASH') {
8726: %usertypeshash = %{$usertypes};
8727: }
1.305 raeburn 8728: my $currassign;
8729: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
8730: $currassign = {
8731: selfassign => $domdefaults{'inststatusguest'},
8732: };
8733: @ordered = @{$domdefaults{'inststatusguest'}};
8734: } else {
8735: $currassign = { selfassign => [] };
8736: }
8737: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
8738: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
8739: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
8740: $numinrow,$othertitle,'selfassign',
8741: $rowtotal,$onclicktypes,$customclass,
8742: $rowstyle);
8743: $$rowtotal ++;
1.302 raeburn 8744: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 8745: foreach my $status (@posstypes) {
8746: my $css_class;
8747: if ($$rowtotal%2) {
8748: $css_class = 'LC_odd_row ';
8749: }
8750: $css_class .= $customclass;
8751: my $rowid = $optionsprefix.$status;
8752: my $hidden = 1;
8753: my $currstyle = 'display:none';
8754: if (grep(/^\Q$status\E$/,@ordered)) {
8755: $currstyle = $rowstyle;
8756: $hidden = 0;
8757: }
8758: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
8759: $emailrules,$emailruleorder,$settings,$status,$rowid,
8760: $usertypeshash{$status},$css_class,$currstyle,$intdom);
8761: unless ($hidden) {
8762: $$rowtotal ++;
8763: }
1.224 raeburn 8764: }
1.302 raeburn 8765: } else {
1.305 raeburn 8766: my $css_class;
8767: if ($$rowtotal%2) {
8768: $css_class = 'LC_odd_row ';
8769: }
8770: $css_class .= $customclass;
1.302 raeburn 8771: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 8772: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
8773: $emailrules,$emailruleorder,$settings,'default','',
8774: $othertitle,$css_class,$rowstyle,$intdom);
8775: $$rowtotal ++;
1.224 raeburn 8776: }
8777: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 8778: $numinrow = 1;
1.305 raeburn 8779: if (@posstypes) {
8780: foreach my $status (@posstypes) {
8781: my $rowid = $classprefix.$status;
8782: my $datarowstyle = 'display:none';
8783: if (grep(/^\Q$status\E$/,@ordered)) {
8784: $datarowstyle = $rowstyle;
8785: }
8786: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
8787: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
8788: $infotitles,$rowid,$customclass,$datarowstyle);
8789: unless ($datarowstyle eq 'display:none') {
8790: $$rowtotal ++;
8791: }
1.224 raeburn 8792: }
1.305 raeburn 8793: } else {
8794: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
8795: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
8796: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 8797: }
8798: }
8799: return $datatable;
8800: }
8801:
1.305 raeburn 8802: sub selfcreate_javascript {
8803: return <<"ENDSCRIPT";
8804:
8805: <script type="text/javascript">
8806: // <![CDATA[
8807:
8808: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
8809: var x = document.getElementsByClassName(target);
8810: var insttypes = 0;
8811: var insttypeRegExp = new RegExp(prefix);
8812: if ((x.length != undefined) && (x.length > 0)) {
8813: if (form.elements[radio].length != undefined) {
8814: for (var i=0; i<form.elements[radio].length; i++) {
8815: if (form.elements[radio][i].checked) {
8816: if (form.elements[radio][i].value == 1) {
8817: for (var j=0; j<x.length; j++) {
8818: if (x[j].id == 'undefined') {
8819: x[j].style.display = 'table-row';
8820: } else if (insttypeRegExp.test(x[j].id)) {
8821: insttypes ++;
8822: } else {
8823: x[j].style.display = 'table-row';
8824: }
8825: }
8826: } else {
8827: for (var j=0; j<x.length; j++) {
8828: x[j].style.display = 'none';
8829: }
1.236 raeburn 8830: }
1.305 raeburn 8831: break;
8832: }
8833: }
8834: if (insttypes > 0) {
8835: toggleDataRow(form,checkbox,target,altprefix);
8836: toggleDataRow(form,checkbox,target,prefix,1);
8837: }
8838: }
8839: }
8840: return;
8841: }
8842:
8843: function toggleDataRow(form,checkbox,target,prefix,docount) {
8844: if (form.elements[checkbox].length != undefined) {
8845: var count = 0;
8846: if (docount) {
8847: for (var i=0; i<form.elements[checkbox].length; i++) {
8848: if (form.elements[checkbox][i].checked) {
8849: count ++;
1.236 raeburn 8850: }
1.305 raeburn 8851: }
8852: }
8853: for (var i=0; i<form.elements[checkbox].length; i++) {
8854: var type = form.elements[checkbox][i].value;
8855: if (document.getElementById(prefix+type)) {
8856: if (form.elements[checkbox][i].checked) {
8857: document.getElementById(prefix+type).style.display = 'table-row';
8858: if (count % 2 == 1) {
8859: document.getElementById(prefix+type).className = target+' LC_odd_row';
8860: } else {
8861: document.getElementById(prefix+type).className = target;
1.236 raeburn 8862: }
1.305 raeburn 8863: count ++;
1.236 raeburn 8864: } else {
1.305 raeburn 8865: document.getElementById(prefix+type).style.display = 'none';
8866: }
8867: }
8868: }
8869: }
8870: return;
8871: }
8872:
8873: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
8874: var caller = radio+'_'+status;
8875: if (form.elements[caller].length != undefined) {
8876: for (var i=0; i<form.elements[caller].length; i++) {
8877: if (form.elements[caller][i].checked) {
8878: if (document.getElementById(altprefix+'_inst_'+status)) {
8879: var curr = form.elements[caller][i].value;
8880: if (prefix) {
8881: document.getElementById(prefix+'_'+status).style.display = 'none';
8882: }
8883: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
8884: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
8885: if (curr == 'custom') {
8886: if (prefix) {
8887: document.getElementById(prefix+'_'+status).style.display = 'inline';
8888: }
8889: } else if (curr == 'inst') {
8890: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
8891: } else if (curr == 'noninst') {
8892: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 8893: }
1.305 raeburn 8894: break;
1.236 raeburn 8895: }
8896: }
8897: }
8898: }
8899: }
8900:
1.305 raeburn 8901: // ]]>
8902: </script>
8903:
8904: ENDSCRIPT
8905: }
8906:
8907: sub noninst_users {
8908: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
8909: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
8910: my $class = 'LC_left_item';
8911: if ($css_class) {
8912: $css_class = ' class="'.$css_class.'"';
8913: }
8914: if ($rowid) {
8915: $rowid = ' id="'.$rowid.'"';
8916: }
8917: if ($rowstyle) {
8918: $rowstyle = ' style="'.$rowstyle.'"';
8919: }
8920: my ($output,$description);
8921: if ($type eq 'default') {
8922: $description = &mt('Requests for: [_1]',$typetitle);
8923: } else {
8924: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
8925: }
8926: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
8927: "<td>$description</td>\n".
8928: '<td class="'.$class.'" colspan="2">'.
8929: '<table><tr>';
8930: my %headers = &Apache::lonlocal::texthash(
8931: approve => 'Processing',
8932: email => 'E-mail',
8933: username => 'Username',
8934: );
8935: foreach my $item ('approve','email','username') {
8936: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 8937: }
1.305 raeburn 8938: $output .= '</tr><tr>';
8939: foreach my $item ('approve','email','username') {
1.306 raeburn 8940: $output .= '<td style="vertical-align: top">';
1.305 raeburn 8941: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
8942: if ($item eq 'approve') {
8943: %choices = &Apache::lonlocal::texthash (
8944: automatic => 'Automatically approved',
8945: approval => 'Queued for approval',
8946: );
8947: @options = ('automatic','approval');
8948: $hashref = $processing;
8949: $defoption = 'automatic';
8950: $name = 'cancreate_emailprocess_'.$type;
8951: } elsif ($item eq 'email') {
8952: %choices = &Apache::lonlocal::texthash (
8953: any => 'Any e-mail',
8954: inst => 'Institutional only',
8955: noninst => 'Non-institutional only',
8956: custom => 'Custom restrictions',
8957: );
8958: @options = ('any','inst','noninst');
8959: my $showcustom;
8960: if (ref($emailrules) eq 'HASH') {
8961: if (keys(%{$emailrules}) > 0) {
8962: push(@options,'custom');
8963: $showcustom = 'cancreate_emailrule';
8964: if (ref($settings) eq 'HASH') {
8965: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
8966: foreach my $rule (@{$settings->{'email_rule'}}) {
8967: if (exists($emailrules->{$rule})) {
8968: $hascustom ++;
8969: }
8970: }
8971: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
8972: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
8973: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
8974: if (exists($emailrules->{$rule})) {
8975: $hascustom ++;
8976: }
8977: }
8978: }
8979: }
8980: }
8981: }
8982: }
8983: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
8984: "'cancreate_emaildomain','$type'".');"';
8985: $hashref = $emailoptions;
8986: $defoption = 'any';
8987: $name = 'cancreate_emailoptions_'.$type;
8988: } elsif ($item eq 'username') {
8989: %choices = &Apache::lonlocal::texthash (
8990: all => 'Same as e-mail',
8991: first => 'Omit @domain',
8992: free => 'Free to choose',
8993: );
8994: @options = ('all','first','free');
8995: $hashref = $emailverified;
8996: $defoption = 'all';
8997: $name = 'cancreate_usernameoptions_'.$type;
8998: }
8999: foreach my $option (@options) {
9000: my $checked;
9001: if (ref($hashref) eq 'HASH') {
9002: if ($type eq '') {
9003: if (!exists($hashref->{'default'})) {
9004: if ($option eq $defoption) {
9005: $checked = ' checked="checked"';
9006: }
9007: } else {
9008: if ($hashref->{'default'} eq $option) {
9009: $checked = ' checked="checked"';
9010: }
1.303 raeburn 9011: }
9012: } else {
1.305 raeburn 9013: if (!exists($hashref->{$type})) {
9014: if ($option eq $defoption) {
9015: $checked = ' checked="checked"';
9016: }
9017: } else {
9018: if ($hashref->{$type} eq $option) {
9019: $checked = ' checked="checked"';
9020: }
1.303 raeburn 9021: }
9022: }
1.305 raeburn 9023: } elsif (($item eq 'email') && ($hascustom)) {
9024: if ($option eq 'custom') {
9025: $checked = ' checked="checked"';
9026: }
9027: } elsif ($option eq $defoption) {
9028: $checked = ' checked="checked"';
9029: }
9030: $output .= '<span class="LC_nobreak"><label>'.
9031: '<input type="radio" name="'.$name.'"'.
9032: $checked.' value="'.$option.'"'.$onclick.' />'.
9033: $choices{$option}.'</label></span><br />';
9034: if ($item eq 'email') {
9035: if ($option eq 'custom') {
9036: my $id = 'cancreate_emailrule_'.$type;
9037: my $display = 'none';
9038: if ($checked) {
9039: $display = 'inline';
1.303 raeburn 9040: }
1.305 raeburn 9041: my $numinrow = 2;
9042: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
9043: '<legend>'.&mt('Disallow').'</legend><table>'.
9044: &user_formats_row('email',$settings,$emailrules,
9045: $emailruleorder,$numinrow,'',$type);
9046: '</table></fieldset>';
9047: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
9048: my %text = &Apache::lonlocal::texthash (
9049: inst => 'must end:',
9050: noninst => 'cannot end:',
9051: );
9052: my $value;
9053: if (ref($emaildomain) eq 'HASH') {
9054: if (ref($emaildomain->{$type}) eq 'HASH') {
9055: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 9056: }
9057: }
1.305 raeburn 9058: if ($value eq '') {
9059: $value = '@'.$intdom;
9060: }
9061: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
9062: my $display = 'none';
9063: if ($checked) {
9064: $display = 'inline';
9065: }
9066: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
9067: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
9068: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
9069: '</div>';
1.303 raeburn 9070: }
9071: }
9072: }
1.305 raeburn 9073: $output .= '</td>'."\n";
1.303 raeburn 9074: }
1.305 raeburn 9075: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 9076: return $output;
9077: }
9078:
1.165 raeburn 9079: sub captcha_choice {
1.305 raeburn 9080: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 9081: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
9082: $vertext,$currver);
1.165 raeburn 9083: my %lt = &captcha_phrases();
9084: $keyentry = 'hidden';
1.354 raeburn 9085: my $colspan=2;
1.165 raeburn 9086: if ($context eq 'cancreate') {
1.224 raeburn 9087: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 9088: } elsif ($context eq 'login') {
9089: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 9090: } elsif ($context eq 'passwords') {
9091: $rowname = &mt('"Forgot Password" CAPTCHA validation');
9092: $colspan=1;
1.165 raeburn 9093: }
9094: if (ref($settings) eq 'HASH') {
9095: if ($settings->{'captcha'}) {
9096: $checked{$settings->{'captcha'}} = ' checked="checked"';
9097: } else {
9098: $checked{'original'} = ' checked="checked"';
9099: }
9100: if ($settings->{'captcha'} eq 'recaptcha') {
9101: $pubtext = $lt{'pub'};
9102: $privtext = $lt{'priv'};
9103: $keyentry = 'text';
1.269 raeburn 9104: $vertext = $lt{'ver'};
9105: $currver = $settings->{'recaptchaversion'};
9106: if ($currver ne '2') {
9107: $currver = 1;
9108: }
1.165 raeburn 9109: }
9110: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
9111: $currpub = $settings->{'recaptchakeys'}{'public'};
9112: $currpriv = $settings->{'recaptchakeys'}{'private'};
9113: }
9114: } else {
9115: $checked{'original'} = ' checked="checked"';
9116: }
1.305 raeburn 9117: my $css_class;
9118: if ($itemcount%2) {
9119: $css_class = 'LC_odd_row';
9120: }
9121: if ($customcss) {
9122: $css_class .= " $customcss";
9123: }
9124: $css_class =~ s/^\s+//;
9125: if ($css_class) {
9126: $css_class = ' class="'.$css_class.'"';
9127: }
9128: if ($rowstyle) {
9129: $css_class .= ' style="'.$rowstyle.'"';
9130: }
1.169 raeburn 9131: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 9132: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 9133: '<table><tr><td>'."\n";
9134: foreach my $option ('original','recaptcha','notused') {
9135: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
9136: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
9137: $lt{$option}.'</label></span>';
9138: unless ($option eq 'notused') {
9139: $output .= (' 'x2)."\n";
9140: }
9141: }
9142: #
9143: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
9144: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 9145: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 9146: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 9147: #
1.165 raeburn 9148: $output .= '</td></tr>'."\n".
1.305 raeburn 9149: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 9150: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
9151: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
9152: $currpub.'" size="40" /></span><br />'."\n".
9153: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
9154: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 9155: $currpriv.'" size="40" /></span><br />'.
9156: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
9157: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
9158: $currver.'" size="3" /></span><br />'.
9159: '</td></tr></table>'."\n".
1.165 raeburn 9160: '</td></tr>';
9161: return $output;
9162: }
9163:
1.32 raeburn 9164: sub user_formats_row {
1.305 raeburn 9165: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 9166: my $output;
9167: my %text = (
9168: 'username' => 'new usernames',
9169: 'id' => 'IDs',
9170: );
1.305 raeburn 9171: unless ($type eq 'email') {
9172: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
9173: $output = '<tr '.$css_class.'>'.
9174: '<td><span class="LC_nobreak">'.
9175: &mt("Format rules to check for $text{$type}: ").
9176: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 9177: }
1.27 raeburn 9178: my $rem;
9179: if (ref($ruleorder) eq 'ARRAY') {
9180: for (my $i=0; $i<@{$ruleorder}; $i++) {
9181: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
9182: my $rem = $i%($numinrow);
9183: if ($rem == 0) {
9184: if ($i > 0) {
9185: $output .= '</tr>';
9186: }
9187: $output .= '<tr>';
9188: }
9189: my $check = ' ';
1.39 raeburn 9190: if (ref($settings) eq 'HASH') {
9191: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
9192: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
9193: $check = ' checked="checked" ';
9194: }
1.305 raeburn 9195: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
9196: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
9197: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
9198: $check = ' checked="checked" ';
9199: }
9200: }
1.27 raeburn 9201: }
9202: }
1.305 raeburn 9203: my $name = $type.'_rule';
9204: if ($type eq 'email') {
9205: $name .= '_'.$status;
9206: }
1.27 raeburn 9207: $output .= '<td class="LC_left_item">'.
9208: '<span class="LC_nobreak"><label>'.
1.311 raeburn 9209: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 9210: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
9211: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
9212: }
9213: }
9214: $rem = @{$ruleorder}%($numinrow);
9215: }
1.305 raeburn 9216: my $colsleft;
9217: if ($rem) {
9218: $colsleft = $numinrow - $rem;
9219: }
1.27 raeburn 9220: if ($colsleft > 1 ) {
9221: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9222: ' </td>';
9223: } elsif ($colsleft == 1) {
9224: $output .= '<td class="LC_left_item"> </td>';
9225: }
1.305 raeburn 9226: $output .= '</tr></table>';
9227: unless ($type eq 'email') {
9228: $output .= '</td></tr>';
9229: }
1.27 raeburn 9230: return $output;
9231: }
9232:
1.34 raeburn 9233: sub usercreation_types {
9234: my %lt = &Apache::lonlocal::texthash (
9235: author => 'When adding a co-author',
9236: course => 'When adding a user to a course',
1.100 raeburn 9237: requestcrs => 'When requesting a course',
1.34 raeburn 9238: any => 'Any',
9239: official => 'Institutional only ',
9240: unofficial => 'Non-institutional only',
9241: none => 'None',
9242: );
9243: return %lt;
1.48 raeburn 9244: }
1.34 raeburn 9245:
1.224 raeburn 9246: sub selfcreation_types {
9247: my %lt = &Apache::lonlocal::texthash (
9248: selfcreate => 'User creates own account',
9249: any => 'Any',
9250: official => 'Institutional only ',
9251: unofficial => 'Non-institutional only',
9252: email => 'E-mail address',
9253: login => 'Institutional Login',
9254: sso => 'SSO',
9255: );
9256: }
9257:
1.28 raeburn 9258: sub authtype_names {
9259: my %lt = &Apache::lonlocal::texthash(
9260: int => 'Internal',
9261: krb4 => 'Kerberos 4',
9262: krb5 => 'Kerberos 5',
9263: loc => 'Local',
1.325 raeburn 9264: lti => 'LTI',
1.28 raeburn 9265: );
9266: return %lt;
9267: }
9268:
9269: sub context_names {
9270: my %context_title = &Apache::lonlocal::texthash(
9271: author => 'Creating users when an Author',
9272: course => 'Creating users when in a course',
9273: domain => 'Creating users when a Domain Coordinator',
9274: );
9275: return %context_title;
9276: }
9277:
1.33 raeburn 9278: sub print_usermodification {
9279: my ($position,$dom,$settings,$rowtotal) = @_;
9280: my $numinrow = 4;
9281: my ($context,$datatable,$rowcount);
9282: if ($position eq 'top') {
9283: $rowcount = 0;
9284: $context = 'author';
9285: foreach my $role ('ca','aa') {
9286: $datatable .= &modifiable_userdata_row($context,$role,$settings,
9287: $numinrow,$rowcount);
9288: $$rowtotal ++;
9289: $rowcount ++;
9290: }
1.230 raeburn 9291: } elsif ($position eq 'bottom') {
1.33 raeburn 9292: $context = 'course';
9293: $rowcount = 0;
9294: foreach my $role ('st','ep','ta','in','cr') {
9295: $datatable .= &modifiable_userdata_row($context,$role,$settings,
9296: $numinrow,$rowcount);
9297: $$rowtotal ++;
9298: $rowcount ++;
9299: }
9300: }
9301: return $datatable;
9302: }
9303:
1.43 raeburn 9304: sub print_defaults {
1.236 raeburn 9305: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 9306: my $rownum = 0;
1.294 raeburn 9307: my ($datatable,$css_class,$titles);
9308: unless ($position eq 'bottom') {
9309: $titles = &defaults_titles($dom);
9310: }
1.236 raeburn 9311: if ($position eq 'top') {
9312: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
9313: 'datelocale_def','portal_def');
9314: my %defaults;
9315: if (ref($settings) eq 'HASH') {
9316: %defaults = %{$settings};
1.43 raeburn 9317: } else {
1.236 raeburn 9318: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9319: foreach my $item (@items) {
9320: $defaults{$item} = $domdefaults{$item};
9321: }
1.43 raeburn 9322: }
1.236 raeburn 9323: foreach my $item (@items) {
9324: if ($rownum%2) {
9325: $css_class = '';
9326: } else {
9327: $css_class = ' class="LC_odd_row" ';
9328: }
9329: $datatable .= '<tr'.$css_class.'>'.
9330: '<td><span class="LC_nobreak">'.$titles->{$item}.
9331: '</span></td><td class="LC_right_item" colspan="3">';
9332: if ($item eq 'auth_def') {
1.325 raeburn 9333: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 9334: my %shortauth = (
9335: internal => 'int',
9336: krb4 => 'krb4',
9337: krb5 => 'krb5',
1.325 raeburn 9338: localauth => 'loc',
9339: lti => 'lti',
1.236 raeburn 9340: );
9341: my %authnames = &authtype_names();
9342: foreach my $auth (@authtypes) {
9343: my $checked = ' ';
9344: if ($defaults{$item} eq $auth) {
9345: $checked = ' checked="checked" ';
9346: }
9347: $datatable .= '<label><input type="radio" name="'.$item.
9348: '" value="'.$auth.'"'.$checked.'/>'.
9349: $authnames{$shortauth{$auth}}.'</label> ';
9350: }
9351: } elsif ($item eq 'timezone_def') {
9352: my $includeempty = 1;
9353: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
9354: } elsif ($item eq 'datelocale_def') {
9355: my $includeempty = 1;
9356: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
9357: } elsif ($item eq 'lang_def') {
1.263 raeburn 9358: my $includeempty = 1;
9359: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 9360: } else {
9361: my $size;
9362: if ($item eq 'portal_def') {
9363: $size = ' size="25"';
9364: }
9365: $datatable .= '<input type="text" name="'.$item.'" value="'.
9366: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 9367: }
1.236 raeburn 9368: $datatable .= '</td></tr>';
9369: $rownum ++;
9370: }
1.354 raeburn 9371: } else {
1.294 raeburn 9372: my %defaults;
9373: if (ref($settings) eq 'HASH') {
1.354 raeburn 9374: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
9375: my $maxnum = @{$settings->{'inststatusorder'}};
9376: for (my $i=0; $i<$maxnum; $i++) {
9377: $css_class = $rownum%2?' class="LC_odd_row"':'';
9378: my $item = $settings->{'inststatusorder'}->[$i];
9379: my $title = $settings->{'inststatustypes'}->{$item};
9380: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
9381: $datatable .= '<tr'.$css_class.'>'.
9382: '<td><span class="LC_nobreak">'.
9383: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
9384: for (my $k=0; $k<=$maxnum; $k++) {
9385: my $vpos = $k+1;
9386: my $selstr;
9387: if ($k == $i) {
9388: $selstr = ' selected="selected" ';
9389: }
9390: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9391: }
9392: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
9393: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
9394: &mt('delete').'</span></td>'.
9395: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed:').
9396: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
9397: '</span></td></tr>';
9398: }
9399: $css_class = $rownum%2?' class="LC_odd_row"':'';
9400: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
9401: $datatable .= '<tr '.$css_class.'>'.
9402: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
9403: for (my $k=0; $k<=$maxnum; $k++) {
9404: my $vpos = $k+1;
9405: my $selstr;
9406: if ($k == $maxnum) {
9407: $selstr = ' selected="selected" ';
9408: }
9409: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9410: }
9411: $datatable .= '</select> '.&mt('Internal ID:').
9412: '<input type="text" size="10" name="addinststatus" value="" />'.
9413: ' '.&mt('(new)').
9414: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
9415: &mt('Name displayed:').
9416: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
9417: '</tr>'."\n";
9418: $rownum ++;
1.294 raeburn 9419: }
1.354 raeburn 9420: }
9421: }
9422: $$rowtotal += $rownum;
1.43 raeburn 9423: return $datatable;
9424: }
9425:
1.168 raeburn 9426: sub get_languages_hash {
9427: my %langchoices;
9428: foreach my $id (&Apache::loncommon::languageids()) {
9429: my $code = &Apache::loncommon::supportedlanguagecode($id);
9430: if ($code ne '') {
9431: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
9432: }
9433: }
9434: return %langchoices;
9435: }
9436:
1.43 raeburn 9437: sub defaults_titles {
1.141 raeburn 9438: my ($dom) = @_;
1.43 raeburn 9439: my %titles = &Apache::lonlocal::texthash (
9440: 'auth_def' => 'Default authentication type',
9441: 'auth_arg_def' => 'Default authentication argument',
9442: 'lang_def' => 'Default language',
1.54 raeburn 9443: 'timezone_def' => 'Default timezone',
1.68 raeburn 9444: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 9445: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 9446: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
9447: 'intauth_check' => 'Check bcrypt cost if authenticated',
9448: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 9449: );
1.141 raeburn 9450: if ($dom) {
9451: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
9452: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
9453: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
9454: $protocol = 'http' if ($protocol ne 'https');
9455: if ($uint_dom) {
9456: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
9457: $uint_dom);
9458: }
9459: }
1.43 raeburn 9460: return (\%titles);
9461: }
9462:
1.346 raeburn 9463: sub print_scantron {
9464: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
9465: if ($position eq 'top') {
9466: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
9467: } else {
9468: return &print_scantronconfig($dom,$settings,\$rowtotal);
9469: }
9470: }
9471:
9472: sub scantron_javascript {
9473: return <<"ENDSCRIPT";
9474:
9475: <script type="text/javascript">
9476: // <![CDATA[
9477:
9478: function toggleScantron(form) {
1.347 raeburn 9479: var csvfieldset = new Array();
1.346 raeburn 9480: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 9481: csvfieldset.push(document.getElementById('scantroncsv_cols'));
9482: }
9483: if (document.getElementById('scantroncsv_options')) {
9484: csvfieldset.push(document.getElementById('scantroncsv_options'));
9485: }
9486: if (csvfieldset.length) {
1.346 raeburn 9487: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 9488: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 9489: if (scantroncsv.checked) {
1.347 raeburn 9490: for (var i=0; i<csvfieldset.length; i++) {
9491: csvfieldset[i].style.display = 'block';
9492: }
1.346 raeburn 9493: } else {
1.347 raeburn 9494: for (var i=0; i<csvfieldset.length; i++) {
9495: csvfieldset[i].style.display = 'none';
9496: }
1.346 raeburn 9497: var csvselects = document.getElementsByClassName('scantronconfig_csv');
9498: if (csvselects.length) {
9499: for (var j=0; j<csvselects.length; j++) {
9500: csvselects[j].selectedIndex = 0;
9501: }
9502: }
9503: }
9504: }
9505: }
9506: return;
9507: }
9508: // ]]>
9509: </script>
9510:
9511: ENDSCRIPT
9512:
9513: }
9514:
1.46 raeburn 9515: sub print_scantronformat {
9516: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
9517: my $itemcount = 1;
1.60 raeburn 9518: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
9519: %confhash);
1.46 raeburn 9520: my $switchserver = &check_switchserver($dom,$confname);
9521: my %lt = &Apache::lonlocal::texthash (
1.95 www 9522: default => 'Default bubblesheet format file error',
9523: custom => 'Custom bubblesheet format file error',
1.46 raeburn 9524: );
9525: my %scantronfiles = (
9526: default => 'default.tab',
9527: custom => 'custom.tab',
9528: );
9529: foreach my $key (keys(%scantronfiles)) {
9530: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
9531: .$scantronfiles{$key};
9532: }
9533: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
9534: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
9535: if (!$switchserver) {
9536: my $servadm = $r->dir_config('lonAdmEMail');
9537: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
9538: if ($configuserok eq 'ok') {
9539: if ($author_ok eq 'ok') {
9540: my %legacyfile = (
1.346 raeburn 9541: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
9542: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 9543: );
9544: my %md5chk;
9545: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 9546: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
9547: chomp($md5chk{$type});
1.46 raeburn 9548: }
9549: if ($md5chk{'default'} ne $md5chk{'custom'}) {
9550: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 9551: ($scantronurls{$type},my $error) =
1.46 raeburn 9552: &legacy_scantronformat($r,$dom,$confname,
9553: $type,$legacyfile{$type},
9554: $scantronurls{$type},
9555: $scantronfiles{$type});
1.60 raeburn 9556: if ($error ne '') {
9557: $error{$type} = $error;
9558: }
9559: }
9560: if (keys(%error) == 0) {
9561: $is_custom = 1;
1.346 raeburn 9562: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 9563: $scantronurls{'custom'};
1.346 raeburn 9564: my $putresult =
1.60 raeburn 9565: &Apache::lonnet::put_dom('configuration',
9566: \%confhash,$dom);
9567: if ($putresult ne 'ok') {
1.346 raeburn 9568: $error{'custom'} =
1.60 raeburn 9569: '<span class="LC_error">'.
9570: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
9571: }
1.46 raeburn 9572: }
9573: } else {
1.60 raeburn 9574: ($scantronurls{'default'},my $error) =
1.46 raeburn 9575: &legacy_scantronformat($r,$dom,$confname,
9576: 'default',$legacyfile{'default'},
9577: $scantronurls{'default'},
9578: $scantronfiles{'default'});
1.60 raeburn 9579: if ($error eq '') {
9580: $confhash{'scantron'}{'scantronformat'} = '';
9581: my $putresult =
9582: &Apache::lonnet::put_dom('configuration',
9583: \%confhash,$dom);
9584: if ($putresult ne 'ok') {
9585: $error{'default'} =
9586: '<span class="LC_error">'.
9587: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
9588: }
9589: } else {
9590: $error{'default'} = $error;
9591: }
1.46 raeburn 9592: }
9593: }
9594: }
9595: } else {
1.95 www 9596: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 9597: }
9598: }
9599: if (ref($settings) eq 'HASH') {
9600: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
9601: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
9602: if ((!@info) || ($info[0] eq 'no_such_dir')) {
9603: $scantronurl = '';
9604: } else {
9605: $scantronurl = $settings->{'scantronformat'};
9606: }
9607: $is_custom = 1;
9608: } else {
9609: $scantronurl = $scantronurls{'default'};
9610: }
9611: } else {
1.60 raeburn 9612: if ($is_custom) {
9613: $scantronurl = $scantronurls{'custom'};
9614: } else {
9615: $scantronurl = $scantronurls{'default'};
9616: }
1.46 raeburn 9617: }
9618: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9619: $datatable .= '<tr'.$css_class.'>';
9620: if (!$is_custom) {
1.65 raeburn 9621: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
9622: '<span class="LC_nobreak">';
1.46 raeburn 9623: if ($scantronurl) {
1.199 raeburn 9624: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
9625: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 9626: } else {
9627: $datatable = &mt('File unavailable for display');
9628: }
1.65 raeburn 9629: $datatable .= '</span></td>';
1.60 raeburn 9630: if (keys(%error) == 0) {
1.306 raeburn 9631: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 9632: if (!$switchserver) {
9633: $datatable .= &mt('Upload:').'<br />';
9634: }
9635: } else {
9636: my $errorstr;
9637: foreach my $key (sort(keys(%error))) {
9638: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
9639: }
9640: $datatable .= '<td>'.$errorstr;
9641: }
1.46 raeburn 9642: } else {
9643: if (keys(%error) > 0) {
9644: my $errorstr;
9645: foreach my $key (sort(keys(%error))) {
9646: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
9647: }
1.60 raeburn 9648: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 9649: } elsif ($scantronurl) {
1.199 raeburn 9650: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
9651: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 9652: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 9653: $link.
9654: '<label><input type="checkbox" name="scantronformat_del"'.
9655: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 9656: '<td><span class="LC_nobreak"> '.
9657: &mt('Replace:').'</span><br />';
1.46 raeburn 9658: }
9659: }
9660: if (keys(%error) == 0) {
9661: if ($switchserver) {
9662: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
9663: } else {
1.65 raeburn 9664: $datatable .='<span class="LC_nobreak"> '.
9665: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 9666: }
9667: }
9668: $datatable .= '</td></tr>';
9669: $$rowtotal ++;
9670: return $datatable;
9671: }
9672:
9673: sub legacy_scantronformat {
9674: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
9675: my ($url,$error);
9676: my @statinfo = &Apache::lonnet::stat_file($newurl);
9677: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
9678: (my $result,$url) =
9679: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
9680: '','',$newfile);
9681: if ($result ne 'ok') {
1.130 raeburn 9682: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 9683: }
9684: }
9685: return ($url,$error);
9686: }
1.43 raeburn 9687:
1.346 raeburn 9688: sub print_scantronconfig {
9689: my ($dom,$settings,$rowtotal) = @_;
9690: my $itemcount = 2;
9691: my $is_checked = ' checked="checked"';
1.347 raeburn 9692: my %optionson = (
9693: hdr => ' checked="checked"',
9694: pad => ' checked="checked"',
9695: rem => ' checked="checked"',
9696: );
9697: my %optionsoff = (
9698: hdr => '',
9699: pad => '',
9700: rem => '',
9701: );
1.346 raeburn 9702: my $currcsvsty = 'none';
1.347 raeburn 9703: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 9704: my @fields = &scantroncsv_fields();
9705: my %titles = &scantronconfig_titles();
9706: if (ref($settings) eq 'HASH') {
9707: if (ref($settings->{config}) eq 'HASH') {
9708: if ($settings->{config}->{dat}) {
9709: $checked{'dat'} = $is_checked;
9710: }
9711: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 9712: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
9713: %csvfields = %{$settings->{config}->{csv}->{fields}};
9714: if (keys(%csvfields) > 0) {
9715: $checked{'csv'} = $is_checked;
9716: $currcsvsty = 'block';
9717: }
9718: }
9719: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
9720: %csvoptions = %{$settings->{config}->{csv}->{options}};
9721: foreach my $option (keys(%optionson)) {
9722: unless ($csvoptions{$option}) {
9723: $optionsoff{$option} = $optionson{$option};
9724: $optionson{$option} = '';
9725: }
9726: }
1.346 raeburn 9727: }
9728: }
9729: } else {
9730: $checked{'dat'} = $is_checked;
9731: }
9732: } else {
9733: $checked{'dat'} = $is_checked;
9734: }
9735: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
9736: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
9737: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
9738: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
9739: foreach my $item ('dat','csv') {
9740: my $id;
9741: if ($item eq 'csv') {
9742: $id = 'id="scantronconfcsv" ';
1.347 raeburn 9743: }
1.346 raeburn 9744: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
9745: $titles{$item}.'</label>'.(' 'x3);
9746: if ($item eq 'csv') {
9747: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
9748: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
9749: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
9750: foreach my $col (@fields) {
9751: my $selnone;
9752: if ($csvfields{$col} eq '') {
9753: $selnone = ' selected="selected"';
9754: }
9755: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
9756: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
9757: '<option value=""'.$selnone.'></option>';
9758: for (my $i=0; $i<20; $i++) {
9759: my $shown = $i+1;
9760: my $sel;
9761: unless ($selnone) {
9762: if (exists($csvfields{$col})) {
9763: if ($csvfields{$col} == $i) {
9764: $sel = ' selected="selected"';
9765: }
9766: }
9767: }
9768: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
9769: }
9770: $datatable .= '</select></td></tr>';
9771: }
1.347 raeburn 9772: $datatable .= '</table></fieldset>'.
9773: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
9774: '<legend>'.&mt('CSV Options').'</legend>';
9775: foreach my $option ('hdr','pad','rem') {
9776: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
9777: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
9778: &mt('Yes').'</label>'.(' 'x2)."\n".
9779: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
9780: }
9781: $datatable .= '</fieldset>';
1.346 raeburn 9782: $itemcount ++;
9783: }
9784: }
9785: $datatable .= '</td></tr>';
9786: $$rowtotal ++;
9787: return $datatable;
9788: }
9789:
9790: sub scantronconfig_titles {
9791: return &Apache::lonlocal::texthash(
9792: dat => 'Standard format (.dat)',
9793: csv => 'Comma separated values (.csv)',
1.347 raeburn 9794: hdr => 'Remove first line in file (contains column titles)',
9795: pad => 'Prepend 0s to PaperID',
1.348 raeburn 9796: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 9797: CODE => 'CODE',
9798: ID => 'Student ID',
9799: PaperID => 'Paper ID',
9800: FirstName => 'First Name',
9801: LastName => 'Last Name',
9802: FirstQuestion => 'First Question Response',
9803: Section => 'Section',
9804: );
9805: }
9806:
9807: sub scantroncsv_fields {
9808: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
9809: }
9810:
1.49 raeburn 9811: sub print_coursecategories {
1.57 raeburn 9812: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
9813: my $datatable;
9814: if ($position eq 'top') {
1.238 raeburn 9815: my (%checked);
9816: my @catitems = ('unauth','auth');
9817: my @cattypes = ('std','domonly','codesrch','none');
9818: $checked{'unauth'} = 'std';
9819: $checked{'auth'} = 'std';
9820: if (ref($settings) eq 'HASH') {
9821: foreach my $type (@cattypes) {
9822: if ($type eq $settings->{'unauth'}) {
9823: $checked{'unauth'} = $type;
9824: }
9825: if ($type eq $settings->{'auth'}) {
9826: $checked{'auth'} = $type;
9827: }
9828: }
9829: }
9830: my %lt = &Apache::lonlocal::texthash (
9831: unauth => 'Catalog type for unauthenticated users',
9832: auth => 'Catalog type for authenticated users',
9833: none => 'No catalog',
9834: std => 'Standard catalog',
9835: domonly => 'Domain-only catalog',
9836: codesrch => "Code search form",
9837: );
9838: my $itemcount = 0;
9839: foreach my $item (@catitems) {
9840: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
9841: $datatable .= '<tr '.$css_class.'>'.
9842: '<td>'.$lt{$item}.'</td>'.
9843: '<td class="LC_right_item"><span class="LC_nobreak">';
9844: foreach my $type (@cattypes) {
9845: my $ischecked;
9846: if ($checked{$item} eq $type) {
9847: $ischecked=' checked="checked"';
9848: }
9849: $datatable .= '<label>'.
9850: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
9851: ' />'.$lt{$type}.'</label> ';
9852: }
1.327 raeburn 9853: $datatable .= '</span></td></tr>';
1.238 raeburn 9854: $itemcount ++;
9855: }
9856: $$rowtotal += $itemcount;
9857: } elsif ($position eq 'middle') {
1.57 raeburn 9858: my $toggle_cats_crs = ' ';
9859: my $toggle_cats_dom = ' checked="checked" ';
9860: my $can_cat_crs = ' ';
9861: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 9862: my $toggle_catscomm_comm = ' ';
9863: my $toggle_catscomm_dom = ' checked="checked" ';
9864: my $can_catcomm_comm = ' ';
9865: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 9866: my $toggle_catsplace_place = ' ';
9867: my $toggle_catsplace_dom = ' checked="checked" ';
9868: my $can_catplace_place = ' ';
9869: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 9870:
1.57 raeburn 9871: if (ref($settings) eq 'HASH') {
9872: if ($settings->{'togglecats'} eq 'crs') {
9873: $toggle_cats_crs = $toggle_cats_dom;
9874: $toggle_cats_dom = ' ';
9875: }
9876: if ($settings->{'categorize'} eq 'crs') {
9877: $can_cat_crs = $can_cat_dom;
9878: $can_cat_dom = ' ';
9879: }
1.120 raeburn 9880: if ($settings->{'togglecatscomm'} eq 'comm') {
9881: $toggle_catscomm_comm = $toggle_catscomm_dom;
9882: $toggle_catscomm_dom = ' ';
9883: }
9884: if ($settings->{'categorizecomm'} eq 'comm') {
9885: $can_catcomm_comm = $can_catcomm_dom;
9886: $can_catcomm_dom = ' ';
9887: }
1.272 raeburn 9888: if ($settings->{'togglecatsplace'} eq 'place') {
9889: $toggle_catsplace_place = $toggle_catsplace_dom;
9890: $toggle_catsplace_dom = ' ';
9891: }
9892: if ($settings->{'categorizeplace'} eq 'place') {
9893: $can_catplace_place = $can_catplace_dom;
9894: $can_catplace_dom = ' ';
9895: }
1.57 raeburn 9896: }
9897: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 9898: togglecats => 'Show/Hide a course in catalog',
9899: togglecatscomm => 'Show/Hide a community in catalog',
9900: togglecatsplace => 'Show/Hide a placement test in catalog',
9901: categorize => 'Assign a category to a course',
9902: categorizecomm => 'Assign a category to a community',
9903: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 9904: );
9905: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 9906: dom => 'Set in Domain',
9907: crs => 'Set in Course',
9908: comm => 'Set in Community',
9909: place => 'Set in Placement Test',
1.57 raeburn 9910: );
9911: $datatable = '<tr class="LC_odd_row">'.
9912: '<td>'.$title{'togglecats'}.'</td>'.
9913: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
9914: '<input type="radio" name="togglecats"'.
9915: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9916: '<label><input type="radio" name="togglecats"'.
9917: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
9918: '</tr><tr>'.
9919: '<td>'.$title{'categorize'}.'</td>'.
9920: '<td class="LC_right_item"><span class="LC_nobreak">'.
9921: '<label><input type="radio" name="categorize"'.
9922: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9923: '<label><input type="radio" name="categorize"'.
9924: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 9925: '</tr><tr class="LC_odd_row">'.
9926: '<td>'.$title{'togglecatscomm'}.'</td>'.
9927: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
9928: '<input type="radio" name="togglecatscomm"'.
9929: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9930: '<label><input type="radio" name="togglecatscomm"'.
9931: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
9932: '</tr><tr>'.
9933: '<td>'.$title{'categorizecomm'}.'</td>'.
9934: '<td class="LC_right_item"><span class="LC_nobreak">'.
9935: '<label><input type="radio" name="categorizecomm"'.
9936: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9937: '<label><input type="radio" name="categorizecomm"'.
9938: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 9939: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 9940: '<td>'.$title{'togglecatsplace'}.'</td>'.
9941: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
9942: '<input type="radio" name="togglecatsplace"'.
9943: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9944: '<label><input type="radio" name="togglecatscomm"'.
9945: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
9946: '</tr><tr>'.
9947: '<td>'.$title{'categorizeplace'}.'</td>'.
9948: '<td class="LC_right_item"><span class="LC_nobreak">'.
9949: '<label><input type="radio" name="categorizeplace"'.
9950: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9951: '<label><input type="radio" name="categorizeplace"'.
9952: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 9953: '</tr>';
1.272 raeburn 9954: $$rowtotal += 6;
1.57 raeburn 9955: } else {
9956: my $css_class;
9957: my $itemcount = 1;
9958: my $cathash;
9959: if (ref($settings) eq 'HASH') {
9960: $cathash = $settings->{'cats'};
9961: }
9962: if (ref($cathash) eq 'HASH') {
9963: my (@cats,@trails,%allitems,%idx,@jsarray);
9964: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
9965: \%allitems,\%idx,\@jsarray);
9966: my $maxdepth = scalar(@cats);
9967: my $colattrib = '';
9968: if ($maxdepth > 2) {
9969: $colattrib = ' colspan="2" ';
9970: }
9971: my @path;
9972: if (@cats > 0) {
9973: if (ref($cats[0]) eq 'ARRAY') {
9974: my $numtop = @{$cats[0]};
9975: my $maxnum = $numtop;
1.120 raeburn 9976: my %default_names = (
9977: instcode => &mt('Official courses'),
9978: communities => &mt('Communities'),
1.272 raeburn 9979: placement => &mt('Placement Tests'),
1.120 raeburn 9980: );
9981:
9982: if ((!grep(/^instcode$/,@{$cats[0]})) ||
9983: ($cathash->{'instcode::0'} eq '') ||
9984: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 9985: ($cathash->{'communities::0'} eq '') ||
9986: (!grep(/^placement$/,@{$cats[0]})) ||
9987: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 9988: $maxnum ++;
9989: }
9990: my $lastidx;
9991: for (my $i=0; $i<$numtop; $i++) {
9992: my $parent = $cats[0][$i];
9993: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9994: my $item = &escape($parent).'::0';
9995: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
9996: $lastidx = $idx{$item};
9997: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
9998: .'<select name="'.$item.'"'.$chgstr.'>';
9999: for (my $k=0; $k<=$maxnum; $k++) {
10000: my $vpos = $k+1;
10001: my $selstr;
10002: if ($k == $i) {
10003: $selstr = ' selected="selected" ';
10004: }
10005: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10006: }
1.214 raeburn 10007: $datatable .= '</select></span></td><td>';
1.272 raeburn 10008: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 10009: $datatable .= '<span class="LC_nobreak">'
10010: .$default_names{$parent}.'</span>';
10011: if ($parent eq 'instcode') {
10012: $datatable .= '<br /><span class="LC_nobreak">('
10013: .&mt('with institutional codes')
10014: .')</span></td><td'.$colattrib.'>';
10015: } else {
10016: $datatable .= '<table><tr><td>';
10017: }
10018: $datatable .= '<span class="LC_nobreak">'
10019: .'<label><input type="radio" name="'
10020: .$parent.'" value="1" checked="checked" />'
10021: .&mt('Display').'</label>';
10022: if ($parent eq 'instcode') {
10023: $datatable .= ' ';
10024: } else {
10025: $datatable .= '</span></td></tr><tr><td>'
10026: .'<span class="LC_nobreak">';
10027: }
10028: $datatable .= '<label><input type="radio" name="'
10029: .$parent.'" value="0" />'
10030: .&mt('Do not display').'</label></span>';
1.272 raeburn 10031: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 10032: $datatable .= '</td></tr></table>';
10033: }
10034: $datatable .= '</td>';
1.57 raeburn 10035: } else {
10036: $datatable .= $parent
1.214 raeburn 10037: .' <span class="LC_nobreak"><label>'
10038: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 10039: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
10040: }
10041: my $depth = 1;
10042: push(@path,$parent);
10043: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
10044: pop(@path);
10045: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
10046: $itemcount ++;
10047: }
1.48 raeburn 10048: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 10049: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
10050: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 10051: for (my $k=0; $k<=$maxnum; $k++) {
10052: my $vpos = $k+1;
10053: my $selstr;
1.57 raeburn 10054: if ($k == $numtop) {
1.48 raeburn 10055: $selstr = ' selected="selected" ';
10056: }
10057: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10058: }
1.59 bisitz 10059: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 10060: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
10061: .'</tr>'."\n";
1.48 raeburn 10062: $itemcount ++;
1.272 raeburn 10063: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 10064: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
10065: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10066: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
10067: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
10068: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
10069: for (my $k=0; $k<=$maxnum; $k++) {
10070: my $vpos = $k+1;
10071: my $selstr;
10072: if ($k == $maxnum) {
10073: $selstr = ' selected="selected" ';
10074: }
10075: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 10076: }
1.120 raeburn 10077: $datatable .= '</select></span></td>'.
10078: '<td><span class="LC_nobreak">'.
10079: $default_names{$default}.'</span>';
10080: if ($default eq 'instcode') {
10081: $datatable .= '<br /><span class="LC_nobreak">('
10082: .&mt('with institutional codes').')</span>';
10083: }
10084: $datatable .= '</td>'
10085: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
10086: .&mt('Display').'</label> '
10087: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
10088: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 10089: }
10090: }
10091: }
1.57 raeburn 10092: } else {
10093: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 10094: }
10095: } else {
1.327 raeburn 10096: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 10097: .&initialize_categories($itemcount);
1.48 raeburn 10098: }
1.57 raeburn 10099: $$rowtotal += $itemcount;
1.48 raeburn 10100: }
10101: return $datatable;
10102: }
10103:
1.69 raeburn 10104: sub print_serverstatuses {
10105: my ($dom,$settings,$rowtotal) = @_;
10106: my $datatable;
10107: my @pages = &serverstatus_pages();
10108: my (%namedaccess,%machineaccess);
10109: foreach my $type (@pages) {
10110: $namedaccess{$type} = '';
10111: $machineaccess{$type}= '';
10112: }
10113: if (ref($settings) eq 'HASH') {
10114: foreach my $type (@pages) {
10115: if (exists($settings->{$type})) {
10116: if (ref($settings->{$type}) eq 'HASH') {
10117: foreach my $key (keys(%{$settings->{$type}})) {
10118: if ($key eq 'namedusers') {
10119: $namedaccess{$type} = $settings->{$type}->{$key};
10120: } elsif ($key eq 'machines') {
10121: $machineaccess{$type} = $settings->{$type}->{$key};
10122: }
10123: }
10124: }
10125: }
10126: }
10127: }
1.81 raeburn 10128: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 10129: my $rownum = 0;
10130: my $css_class;
10131: foreach my $type (@pages) {
10132: $rownum ++;
10133: $css_class = $rownum%2?' class="LC_odd_row"':'';
10134: $datatable .= '<tr'.$css_class.'>'.
10135: '<td><span class="LC_nobreak">'.
10136: $titles->{$type}.'</span></td>'.
10137: '<td class="LC_left_item">'.
10138: '<input type="text" name="'.$type.'_namedusers" '.
10139: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
10140: '<td class="LC_right_item">'.
10141: '<span class="LC_nobreak">'.
10142: '<input type="text" name="'.$type.'_machines" '.
10143: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 10144: '</span></td></tr>'."\n";
1.69 raeburn 10145: }
10146: $$rowtotal += $rownum;
10147: return $datatable;
10148: }
10149:
10150: sub serverstatus_pages {
10151: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 10152: 'checksums','clusterstatus','certstatus','metadata_keywords',
10153: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
10154: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 10155: }
10156:
1.236 raeburn 10157: sub defaults_javascript {
10158: my ($settings) = @_;
1.354 raeburn 10159: return unless (ref($settings) eq 'HASH');
1.236 raeburn 10160: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10161: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
10162: if ($maxnum eq '') {
10163: $maxnum = 0;
10164: }
10165: $maxnum ++;
1.249 raeburn 10166: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 10167: return <<"ENDSCRIPT";
10168: <script type="text/javascript">
10169: // <![CDATA[
10170: function reorderTypes(form,caller) {
10171: var changedVal;
10172: $jstext
10173: var newpos = 'addinststatus_pos';
10174: var current = new Array;
10175: var maxh = $maxnum;
10176: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
10177: var oldVal;
10178: if (caller == newpos) {
10179: changedVal = newitemVal;
10180: } else {
10181: var curritem = 'inststatus_pos_'+caller;
10182: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
10183: current[newitemVal] = newpos;
10184: }
10185: for (var i=0; i<inststatuses.length; i++) {
10186: if (inststatuses[i] != caller) {
10187: var elementName = 'inststatus_pos_'+inststatuses[i];
10188: if (form.elements[elementName]) {
10189: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
10190: current[currVal] = elementName;
10191: }
10192: }
10193: }
10194: for (var j=0; j<maxh; j++) {
10195: if (current[j] == undefined) {
10196: oldVal = j;
10197: }
10198: }
10199: if (oldVal < changedVal) {
10200: for (var k=oldVal+1; k<=changedVal ; k++) {
10201: var elementName = current[k];
10202: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
10203: }
10204: } else {
10205: for (var k=changedVal; k<oldVal; k++) {
10206: var elementName = current[k];
10207: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
10208: }
10209: }
10210: return;
10211: }
10212:
10213: // ]]>
10214: </script>
10215:
10216: ENDSCRIPT
10217: }
1.354 raeburn 10218: return;
10219: }
10220:
10221: sub passwords_javascript {
1.365 raeburn 10222: my %intalert = &Apache::lonlocal::texthash (
10223: 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.',
10224: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
10225: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
10226: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
10227: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
10228: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
10229: );
10230: &js_escape(\%intalert);
10231: my $defmin = $Apache::lonnet::passwdmin;
1.354 raeburn 10232: my $intauthjs = <<"ENDSCRIPT";
10233:
10234: function warnIntAuth(field) {
10235: if (field.name == 'intauth_check') {
10236: if (field.value == '2') {
1.365 raeburn 10237: alert('$intalert{authcheck}');
1.354 raeburn 10238: }
10239: }
10240: if (field.name == 'intauth_cost') {
10241: field.value.replace(/\s/g,'');
10242: if (field.value != '') {
10243: var regexdigit=/^\\d+\$/;
10244: if (!regexdigit.test(field.value)) {
1.365 raeburn 10245: alert('$intalert{authcost}');
10246: }
10247: }
10248: }
10249: return;
10250: }
10251:
10252: function warnIntPass(field) {
10253: field.value.replace(/^\s+/,'');
10254: field.value.replace(/\s+\$/,'');
10255: var regexdigit=/^\\d+\$/;
10256: if (field.name == 'passwords_min') {
10257: if (field.value == '') {
10258: alert('$intalert{passmin}');
10259: field.value = '$defmin';
10260: } else {
10261: if (!regexdigit.test(field.value)) {
10262: alert('$intalert{passmin}');
10263: field.value = '$defmin';
10264: }
1.366 raeburn 10265: var minval = parseInt(field.value,10);
1.365 raeburn 10266: if (minval < $defmin) {
10267: alert('$intalert{passmin}');
10268: field.value = '$defmin';
10269: }
10270: }
10271: } else {
10272: if (field.value == '0') {
10273: field.value = '';
10274: }
10275: if (field.value != '') {
10276: if (field.name == 'passwords_expire') {
10277: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
10278: if (!regexpposnum.test(field.value)) {
10279: alert('$intalert{passexp}');
10280: field.value = '';
10281: } else {
10282: var expval = parseFloat(field.value);
10283: if (expval == 0) {
10284: alert('$intalert{passexp}');
10285: field.value = '';
10286: }
10287: }
10288: } else {
10289: if (!regexdigit.test(field.value)) {
10290: if (field.name == 'passwords_max') {
10291: alert('$intalert{passmax}');
10292: } else {
10293: if (field.name == 'passwords_numsaved') {
10294: alert('$intalert{passnum}');
10295: }
10296: }
1.370 raeburn 10297: field.value = '';
1.365 raeburn 10298: }
1.354 raeburn 10299: }
10300: }
10301: }
10302: return;
10303: }
10304:
10305: ENDSCRIPT
10306: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 10307: }
10308:
1.49 raeburn 10309: sub coursecategories_javascript {
10310: my ($settings) = @_;
1.57 raeburn 10311: my ($output,$jstext,$cathash);
1.49 raeburn 10312: if (ref($settings) eq 'HASH') {
1.57 raeburn 10313: $cathash = $settings->{'cats'};
10314: }
10315: if (ref($cathash) eq 'HASH') {
1.49 raeburn 10316: my (@cats,@jsarray,%idx);
1.57 raeburn 10317: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 10318: if (@jsarray > 0) {
10319: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
10320: for (my $i=0; $i<@jsarray; $i++) {
10321: if (ref($jsarray[$i]) eq 'ARRAY') {
10322: my $catstr = join('","',@{$jsarray[$i]});
10323: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
10324: }
10325: }
10326: }
10327: } else {
10328: $jstext = ' var categories = Array(1);'."\n".
10329: ' categories[0] = Array("instcode_pos");'."\n";
10330: }
1.237 bisitz 10331: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
10332: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 10333: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 10334: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
10335: &js_escape(\$instcode_reserved);
10336: &js_escape(\$communities_reserved);
1.272 raeburn 10337: &js_escape(\$placement_reserved);
1.265 damieng 10338: &js_escape(\$choose_again);
1.49 raeburn 10339: $output = <<"ENDSCRIPT";
10340: <script type="text/javascript">
1.109 raeburn 10341: // <![CDATA[
1.49 raeburn 10342: function reorderCats(form,parent,item,idx) {
10343: var changedVal;
10344: $jstext
10345: var newpos = 'addcategory_pos';
10346: if (parent == '') {
10347: var has_instcode = 0;
10348: var maxtop = categories[idx].length;
10349: for (var j=0; j<maxtop; j++) {
10350: if (categories[idx][j] == 'instcode::0') {
10351: has_instcode == 1;
10352: }
10353: }
10354: if (has_instcode == 0) {
10355: categories[idx][maxtop] = 'instcode_pos';
10356: }
10357: } else {
10358: newpos += '_'+parent;
10359: }
10360: var maxh = 1 + categories[idx].length;
10361: var current = new Array;
10362: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
10363: if (item == newpos) {
10364: changedVal = newitemVal;
10365: } else {
10366: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
10367: current[newitemVal] = newpos;
10368: }
10369: for (var i=0; i<categories[idx].length; i++) {
10370: var elementName = categories[idx][i];
10371: if (elementName != item) {
10372: if (form.elements[elementName]) {
10373: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
10374: current[currVal] = elementName;
10375: }
10376: }
10377: }
10378: var oldVal;
10379: for (var j=0; j<maxh; j++) {
10380: if (current[j] == undefined) {
10381: oldVal = j;
10382: }
10383: }
10384: if (oldVal < changedVal) {
10385: for (var k=oldVal+1; k<=changedVal ; k++) {
10386: var elementName = current[k];
10387: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
10388: }
10389: } else {
10390: for (var k=changedVal; k<oldVal; k++) {
10391: var elementName = current[k];
10392: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
10393: }
10394: }
10395: return;
10396: }
1.120 raeburn 10397:
10398: function categoryCheck(form) {
10399: if (form.elements['addcategory_name'].value == 'instcode') {
10400: alert('$instcode_reserved\\n$choose_again');
10401: return false;
10402: }
10403: if (form.elements['addcategory_name'].value == 'communities') {
10404: alert('$communities_reserved\\n$choose_again');
10405: return false;
10406: }
1.272 raeburn 10407: if (form.elements['addcategory_name'].value == 'placement') {
10408: alert('$placement_reserved\\n$choose_again');
10409: return false;
10410: }
1.120 raeburn 10411: return true;
10412: }
10413:
1.109 raeburn 10414: // ]]>
1.49 raeburn 10415: </script>
10416:
10417: ENDSCRIPT
10418: return $output;
10419: }
10420:
1.48 raeburn 10421: sub initialize_categories {
10422: my ($itemcount) = @_;
1.120 raeburn 10423: my ($datatable,$css_class,$chgstr);
10424: my %default_names = (
10425: instcode => 'Official courses (with institutional codes)',
10426: communities => 'Communities',
1.272 raeburn 10427: placement => 'Placement Tests',
1.120 raeburn 10428: );
1.328 raeburn 10429: my %selnum = (
10430: instcode => '0',
10431: communities => '1',
10432: placement => '2',
10433: );
10434: my %selected;
1.272 raeburn 10435: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 10436: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 10437: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 10438: map { $selected{$selnum{$_}} = '' } keys(%selnum);
10439: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 10440: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 10441: .'<select name="'.$default.'_pos"'.$chgstr.'>'
10442: .'<option value="0"'.$selected{'0'}.'>1</option>'
10443: .'<option value="1"'.$selected{'1'}.'>2</option>'
10444: .'<option value="2"'.$selected{'2'}.'>3</option>'
10445: .'<option value="3">4</option></select> '
1.120 raeburn 10446: .$default_names{$default}
10447: .'</span></td><td><span class="LC_nobreak">'
10448: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
10449: .&mt('Display').'</label> <label>'
10450: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 10451: .'</label></span></td></tr>';
1.120 raeburn 10452: $itemcount ++;
10453: }
1.48 raeburn 10454: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 10455: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 10456: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 10457: .'<select name="addcategory_pos"'.$chgstr.'>'
10458: .'<option value="0">1</option>'
10459: .'<option value="1">2</option>'
1.328 raeburn 10460: .'<option value="2">3</option>'
10461: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 10462: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
10463: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
10464: .'</td></tr>';
1.48 raeburn 10465: return $datatable;
10466: }
10467:
10468: sub build_category_rows {
1.49 raeburn 10469: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
10470: my ($text,$name,$item,$chgstr);
1.48 raeburn 10471: if (ref($cats) eq 'ARRAY') {
10472: my $maxdepth = scalar(@{$cats});
10473: if (ref($cats->[$depth]) eq 'HASH') {
10474: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
10475: my $numchildren = @{$cats->[$depth]{$parent}};
10476: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 10477: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 10478: my ($idxnum,$parent_name,$parent_item);
10479: my $higher = $depth - 1;
10480: if ($higher == 0) {
10481: $parent_name = &escape($parent).'::'.$higher;
10482: } else {
10483: if (ref($path) eq 'ARRAY') {
10484: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
10485: }
10486: }
10487: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 10488: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 10489: if ($j < $numchildren) {
1.48 raeburn 10490: $name = $cats->[$depth]{$parent}[$j];
10491: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 10492: $idxnum = $idx->{$item};
10493: } else {
10494: $name = $parent_name;
10495: $item = $parent_item;
1.48 raeburn 10496: }
1.49 raeburn 10497: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
10498: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 10499: for (my $i=0; $i<=$numchildren; $i++) {
10500: my $vpos = $i+1;
10501: my $selstr;
10502: if ($j == $i) {
10503: $selstr = ' selected="selected" ';
10504: }
10505: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
10506: }
10507: $text .= '</select> ';
10508: if ($j < $numchildren) {
10509: my $deeper = $depth+1;
10510: $text .= $name.' '
10511: .'<label><input type="checkbox" name="deletecategory" value="'
10512: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
10513: if(ref($path) eq 'ARRAY') {
10514: push(@{$path},$name);
1.49 raeburn 10515: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 10516: pop(@{$path});
10517: }
10518: } else {
1.330 raeburn 10519: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 10520: if ($j == $numchildren) {
10521: $text .= $name;
10522: } else {
10523: $text .= $item;
10524: }
10525: $text .= '" value="" />';
10526: }
10527: $text .= '</td></tr>';
10528: }
10529: $text .= '</table></td>';
10530: } else {
10531: my $higher = $depth-1;
10532: if ($higher == 0) {
10533: $name = &escape($parent).'::'.$higher;
10534: } else {
10535: if (ref($path) eq 'ARRAY') {
10536: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
10537: }
10538: }
10539: my $colspan;
10540: if ($parent ne 'instcode') {
10541: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 10542: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 10543: }
10544: }
10545: }
10546: }
10547: return $text;
10548: }
10549:
1.33 raeburn 10550: sub modifiable_userdata_row {
1.305 raeburn 10551: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 10552: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 10553: my ($role,$rolename,$statustype);
10554: $role = $item;
1.224 raeburn 10555: if ($context eq 'cancreate') {
1.305 raeburn 10556: if ($item =~ /^(emailusername)_(.+)$/) {
10557: $role = $1;
10558: $statustype = $2;
1.228 raeburn 10559: if (ref($usertypes) eq 'HASH') {
10560: if ($usertypes->{$statustype}) {
10561: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
10562: } else {
10563: $rolename = &mt('Data provided by user');
10564: }
10565: }
1.224 raeburn 10566: }
10567: } elsif ($context eq 'selfcreate') {
1.63 raeburn 10568: if (ref($usertypes) eq 'HASH') {
10569: $rolename = $usertypes->{$role};
10570: } else {
10571: $rolename = $role;
10572: }
1.325 raeburn 10573: } elsif ($context eq 'lti') {
10574: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 10575: } elsif ($context eq 'privacy') {
10576: $rolename = $itemdesc;
1.33 raeburn 10577: } else {
1.63 raeburn 10578: if ($role eq 'cr') {
10579: $rolename = &mt('Custom role');
10580: } else {
10581: $rolename = &Apache::lonnet::plaintext($role);
10582: }
1.33 raeburn 10583: }
1.224 raeburn 10584: my (@fields,%fieldtitles);
10585: if (ref($fieldsref) eq 'ARRAY') {
10586: @fields = @{$fieldsref};
10587: } else {
10588: @fields = ('lastname','firstname','middlename','generation',
10589: 'permanentemail','id');
10590: }
10591: if ((ref($titlesref) eq 'HASH')) {
10592: %fieldtitles = %{$titlesref};
10593: } else {
10594: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10595: }
1.33 raeburn 10596: my $output;
1.305 raeburn 10597: my $css_class;
10598: if ($rowcount%2) {
10599: $css_class = 'LC_odd_row';
10600: }
10601: if ($customcss) {
10602: $css_class .= " $customcss";
10603: }
10604: $css_class =~ s/^\s+//;
10605: if ($css_class) {
10606: $css_class = ' class="'.$css_class.'"';
10607: }
10608: if ($rowstyle) {
10609: $css_class .= ' style="'.$rowstyle.'"';
10610: }
10611: if ($rowid) {
10612: $rowid = ' id="'.$rowid.'"';
10613: }
10614: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 10615: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
10616: '<td class="LC_left_item" colspan="2"><table>';
10617: my $rem;
10618: my %checks;
1.325 raeburn 10619: my %current;
1.33 raeburn 10620: if (ref($settings) eq 'HASH') {
1.325 raeburn 10621: my $hashref;
10622: if ($context eq 'lti') {
10623: if (ref($settings) eq 'HASH') {
10624: $hashref = $settings->{'instdata'};
10625: }
1.357 raeburn 10626: } elsif ($context eq 'privacy') {
10627: my ($key,$inner) = split(/_/,$role);
10628: if (ref($settings) eq 'HASH') {
10629: if (ref($settings->{$key}) eq 'HASH') {
10630: $hashref = $settings->{$key}->{$inner};
10631: }
10632: }
1.325 raeburn 10633: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 10634: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 10635: $hashref = $settings->{'lti_instdata'};
10636: }
10637: if ($role eq 'emailusername') {
10638: if ($statustype) {
10639: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
10640: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 10641: }
1.325 raeburn 10642: }
10643: }
10644: }
10645: if (ref($hashref) eq 'HASH') {
10646: foreach my $field (@fields) {
10647: if ($hashref->{$field}) {
10648: if ($role eq 'emailusername') {
10649: $checks{$field} = $hashref->{$field};
10650: } else {
10651: $checks{$field} = ' checked="checked" ';
1.33 raeburn 10652: }
10653: }
10654: }
10655: }
10656: }
1.305 raeburn 10657:
10658: my $total = scalar(@fields);
10659: for (my $i=0; $i<$total; $i++) {
10660: $rem = $i%($numinrow);
1.33 raeburn 10661: if ($rem == 0) {
10662: if ($i > 0) {
10663: $output .= '</tr>';
10664: }
10665: $output .= '<tr>';
10666: }
10667: my $check = ' ';
1.228 raeburn 10668: unless ($role eq 'emailusername') {
10669: if (exists($checks{$fields[$i]})) {
1.354 raeburn 10670: $check = $checks{$fields[$i]};
1.357 raeburn 10671: } elsif ($context eq 'privacy') {
10672: if ($role =~ /^priv_(domain|course)$/) {
10673: if (ref($settings) ne 'HASH') {
10674: $check = ' checked="checked" ';
10675: }
10676: } elsif ($role =~ /^priv_(author|community)$/) {
10677: if (ref($settings) ne 'HASH') {
10678: unless ($fields[$i] eq 'id') {
10679: $check = ' checked="checked" ';
10680: }
10681: }
10682: } elsif ($role =~ /^(unpriv|othdom)_/) {
10683: if (ref($settings) ne 'HASH') {
10684: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
10685: $check = ' checked="checked" ';
10686: }
10687: }
10688: }
1.325 raeburn 10689: } elsif ($context ne 'lti') {
1.228 raeburn 10690: if ($role eq 'st') {
10691: if (ref($settings) ne 'HASH') {
10692: $check = ' checked="checked" ';
10693: }
1.33 raeburn 10694: }
10695: }
10696: }
10697: $output .= '<td class="LC_left_item">'.
1.228 raeburn 10698: '<span class="LC_nobreak">';
1.325 raeburn 10699: my $prefix = 'canmodify';
1.228 raeburn 10700: if ($role eq 'emailusername') {
10701: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
10702: $checks{$fields[$i]} = 'omit';
10703: }
10704: foreach my $option ('required','optional','omit') {
10705: my $checked='';
10706: if ($checks{$fields[$i]} eq $option) {
10707: $checked='checked="checked" ';
10708: }
10709: $output .= '<label>'.
1.325 raeburn 10710: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 10711: &mt($option).'</label>'.(' ' x2);
10712: }
10713: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
10714: } else {
1.325 raeburn 10715: if ($context eq 'lti') {
10716: $prefix = 'lti';
1.357 raeburn 10717: } elsif ($context eq 'privacy') {
10718: $prefix = 'privacy';
1.325 raeburn 10719: }
1.228 raeburn 10720: $output .= '<label>'.
1.325 raeburn 10721: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 10722: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
10723: '</label>';
10724: }
10725: $output .= '</span></td>';
1.33 raeburn 10726: }
1.305 raeburn 10727: $rem = $total%$numinrow;
10728: my $colsleft;
10729: if ($rem) {
10730: $colsleft = $numinrow - $rem;
10731: }
10732: if ($colsleft > 1) {
1.33 raeburn 10733: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10734: ' </td>';
10735: } elsif ($colsleft == 1) {
10736: $output .= '<td class="LC_left_item"> </td>';
10737: }
10738: $output .= '</tr></table></td></tr>';
10739: return $output;
10740: }
1.28 raeburn 10741:
1.93 raeburn 10742: sub insttypes_row {
1.305 raeburn 10743: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
10744: $customcss,$rowstyle) = @_;
1.93 raeburn 10745: my %lt = &Apache::lonlocal::texthash (
10746: cansearch => 'Users allowed to search',
10747: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 10748: lockablenames => 'User preference to lock name',
1.305 raeburn 10749: selfassign => 'Self-reportable affiliations',
1.315 raeburn 10750: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 10751: );
10752: my $showdom;
10753: if ($context eq 'cansearch') {
10754: $showdom = ' ('.$dom.')';
10755: }
1.165 raeburn 10756: my $class = 'LC_left_item';
10757: if ($context eq 'statustocreate') {
10758: $class = 'LC_right_item';
10759: }
1.305 raeburn 10760: my $css_class;
10761: if ($$rowtotal%2) {
10762: $css_class = 'LC_odd_row';
10763: }
10764: if ($customcss) {
10765: $css_class .= ' '.$customcss;
10766: }
10767: $css_class =~ s/^\s+//;
10768: if ($css_class) {
10769: $css_class = ' class="'.$css_class.'"';
10770: }
10771: if ($rowstyle) {
10772: $css_class .= ' style="'.$rowstyle.'"';
10773: }
10774: if ($onclick) {
10775: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 10776: }
10777: my $output = '<tr'.$css_class.'>'.
10778: '<td>'.$lt{$context}.$showdom.
10779: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 10780: my $rem;
10781: if (ref($types) eq 'ARRAY') {
10782: for (my $i=0; $i<@{$types}; $i++) {
10783: if (defined($usertypes->{$types->[$i]})) {
10784: my $rem = $i%($numinrow);
10785: if ($rem == 0) {
10786: if ($i > 0) {
10787: $output .= '</tr>';
10788: }
10789: $output .= '<tr>';
1.23 raeburn 10790: }
1.26 raeburn 10791: my $check = ' ';
1.99 raeburn 10792: if (ref($settings) eq 'HASH') {
10793: if (ref($settings->{$context}) eq 'ARRAY') {
10794: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
10795: $check = ' checked="checked" ';
10796: }
1.315 raeburn 10797: } elsif (ref($settings->{$context}) eq 'HASH') {
10798: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
10799: $check = ' checked="checked" ';
10800: }
1.99 raeburn 10801: } elsif ($context eq 'statustocreate') {
1.26 raeburn 10802: $check = ' checked="checked" ';
10803: }
1.23 raeburn 10804: }
1.26 raeburn 10805: $output .= '<td class="LC_left_item">'.
10806: '<span class="LC_nobreak"><label>'.
1.93 raeburn 10807: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 10808: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 10809: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 10810: }
10811: }
1.26 raeburn 10812: $rem = @{$types}%($numinrow);
1.23 raeburn 10813: }
10814: my $colsleft = $numinrow - $rem;
1.315 raeburn 10815: if ($context eq 'overrides') {
10816: if ($colsleft > 1) {
10817: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
10818: } else {
10819: $output .= '<td class="LC_left_item">';
10820: }
10821: $output .= ' ';
1.23 raeburn 10822: } else {
1.334 raeburn 10823: if ($rem == 0) {
1.315 raeburn 10824: $output .= '<tr>';
10825: }
10826: if ($colsleft > 1) {
10827: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
10828: } else {
10829: $output .= '<td class="LC_left_item">';
10830: }
10831: my $defcheck = ' ';
10832: if (ref($settings) eq 'HASH') {
10833: if (ref($settings->{$context}) eq 'ARRAY') {
10834: if (grep(/^default$/,@{$settings->{$context}})) {
10835: $defcheck = ' checked="checked" ';
10836: }
10837: } elsif ($context eq 'statustocreate') {
1.99 raeburn 10838: $defcheck = ' checked="checked" ';
10839: }
1.26 raeburn 10840: }
1.315 raeburn 10841: $output .= '<span class="LC_nobreak"><label>'.
10842: '<input type="checkbox" name="'.$context.'" '.
10843: 'value="default"'.$defcheck.$onclick.' />'.
10844: $othertitle.'</label></span>';
1.23 raeburn 10845: }
1.315 raeburn 10846: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 10847: return $output;
1.23 raeburn 10848: }
10849:
10850: sub sorted_searchtitles {
10851: my %searchtitles = &Apache::lonlocal::texthash(
10852: 'uname' => 'username',
10853: 'lastname' => 'last name',
10854: 'lastfirst' => 'last name, first name',
10855: );
10856: my @titleorder = ('uname','lastname','lastfirst');
10857: return (\%searchtitles,\@titleorder);
10858: }
10859:
1.25 raeburn 10860: sub sorted_searchtypes {
10861: my %srchtypes_desc = (
10862: exact => 'is exact match',
10863: contains => 'contains ..',
10864: begins => 'begins with ..',
10865: );
10866: my @srchtypeorder = ('exact','begins','contains');
10867: return (\%srchtypes_desc,\@srchtypeorder);
10868: }
10869:
1.3 raeburn 10870: sub usertype_update_row {
10871: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
10872: my $datatable;
10873: my $numinrow = 4;
10874: foreach my $type (@{$types}) {
10875: if (defined($usertypes->{$type})) {
10876: $$rownums ++;
10877: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
10878: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
10879: '</td><td class="LC_left_item"><table>';
10880: for (my $i=0; $i<@{$fields}; $i++) {
10881: my $rem = $i%($numinrow);
10882: if ($rem == 0) {
10883: if ($i > 0) {
10884: $datatable .= '</tr>';
10885: }
10886: $datatable .= '<tr>';
10887: }
10888: my $check = ' ';
1.39 raeburn 10889: if (ref($settings) eq 'HASH') {
10890: if (ref($settings->{'fields'}) eq 'HASH') {
10891: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
10892: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
10893: $check = ' checked="checked" ';
10894: }
1.3 raeburn 10895: }
10896: }
10897: }
10898:
10899: if ($i == @{$fields}-1) {
10900: my $colsleft = $numinrow - $rem;
10901: if ($colsleft > 1) {
10902: $datatable .= '<td colspan="'.$colsleft.'">';
10903: } else {
10904: $datatable .= '<td>';
10905: }
10906: } else {
10907: $datatable .= '<td>';
10908: }
1.8 raeburn 10909: $datatable .= '<span class="LC_nobreak"><label>'.
10910: '<input type="checkbox" name="updateable_'.$type.
10911: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
10912: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 10913: }
10914: $datatable .= '</tr></table></td></tr>';
10915: }
10916: }
10917: return $datatable;
1.1 raeburn 10918: }
10919:
10920: sub modify_login {
1.205 raeburn 10921: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 10922: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
10923: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
10924: %title = ( coursecatalog => 'Display course catalog',
10925: adminmail => 'Display administrator E-mail address',
1.188 raeburn 10926: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 10927: newuser => 'Link for visitors to create a user account',
10928: loginheader => 'Log-in box header');
10929: @offon = ('off','on');
1.112 raeburn 10930: if (ref($domconfig{login}) eq 'HASH') {
10931: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
10932: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
10933: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
10934: }
10935: }
10936: }
1.9 raeburn 10937: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
10938: \%domconfig,\%loginhash);
1.188 raeburn 10939: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 10940: foreach my $item (@toggles) {
10941: $loginhash{login}{$item} = $env{'form.'.$item};
10942: }
1.41 raeburn 10943: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 10944: if (ref($colchanges{'login'}) eq 'HASH') {
10945: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
10946: \%loginhash);
10947: }
1.110 raeburn 10948:
1.149 raeburn 10949: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 10950: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 10951: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 10952: if (keys(%servers) > 1) {
10953: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 10954: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
10955: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
10956: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
10957: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
10958: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
10959: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
10960: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
10961: $changes{'loginvia'}{$lonhost} = 1;
10962: } else {
10963: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
10964: $changes{'loginvia'}{$lonhost} = 1;
10965: }
10966: } else {
10967: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
10968: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
10969: $changes{'loginvia'}{$lonhost} = 1;
10970: }
10971: }
10972: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
10973: foreach my $item (@loginvia_attribs) {
10974: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
10975: }
10976: } else {
10977: foreach my $item (@loginvia_attribs) {
10978: my $new = $env{'form.'.$lonhost.'_'.$item};
10979: if (($item eq 'serverpath') && ($new eq 'custom')) {
10980: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
10981: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
10982: $new = '/';
10983: }
10984: }
10985: if (($item eq 'custompath') &&
10986: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
10987: $new = '';
10988: }
10989: if ($new ne $curr_loginvia{$lonhost}{$item}) {
10990: $changes{'loginvia'}{$lonhost} = 1;
10991: }
10992: if ($item eq 'exempt') {
1.256 raeburn 10993: $new = &check_exempt_addresses($new);
1.128 raeburn 10994: }
10995: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
10996: }
10997: }
1.112 raeburn 10998: } else {
1.128 raeburn 10999: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11000: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 11001: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 11002: foreach my $item (@loginvia_attribs) {
11003: my $new = $env{'form.'.$lonhost.'_'.$item};
11004: if (($item eq 'serverpath') && ($new eq 'custom')) {
11005: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
11006: $new = '/';
11007: }
11008: }
11009: if (($item eq 'custompath') &&
11010: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
11011: $new = '';
11012: }
11013: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
11014: }
1.110 raeburn 11015: }
11016: }
11017: }
11018: }
1.119 raeburn 11019:
1.168 raeburn 11020: my $servadm = $r->dir_config('lonAdmEMail');
11021: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
11022: if (ref($domconfig{'login'}) eq 'HASH') {
11023: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
11024: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
11025: if ($lang eq 'nolang') {
11026: push(@currlangs,$lang);
11027: } elsif (defined($langchoices{$lang})) {
11028: push(@currlangs,$lang);
11029: } else {
11030: next;
11031: }
11032: }
11033: }
11034: }
11035: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
11036: if (@currlangs > 0) {
11037: foreach my $lang (@currlangs) {
11038: if (grep(/^\Q$lang\E$/,@delurls)) {
11039: $changes{'helpurl'}{$lang} = 1;
11040: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
11041: $changes{'helpurl'}{$lang} = 1;
11042: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
11043: push(@newlangs,$lang);
11044: } else {
11045: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
11046: }
11047: }
11048: }
11049: unless (grep(/^nolang$/,@currlangs)) {
11050: if ($env{'form.loginhelpurl_nolang.filename'}) {
11051: $changes{'helpurl'}{'nolang'} = 1;
11052: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
11053: push(@newlangs,'nolang');
11054: }
11055: }
11056: if ($env{'form.loginhelpurl_add_lang'}) {
11057: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
11058: ($env{'form.loginhelpurl_add_file.filename'})) {
11059: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
11060: $addedfile = $env{'form.loginhelpurl_add_lang'};
11061: }
11062: }
11063: if ((@newlangs > 0) || ($addedfile)) {
11064: my $error;
11065: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11066: if ($configuserok eq 'ok') {
11067: if ($switchserver) {
11068: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
11069: } elsif ($author_ok eq 'ok') {
11070: my @allnew = @newlangs;
11071: if ($addedfile ne '') {
11072: push(@allnew,$addedfile);
11073: }
11074: foreach my $lang (@allnew) {
11075: my $formelem = 'loginhelpurl_'.$lang;
11076: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
11077: $formelem = 'loginhelpurl_add_file';
11078: }
11079: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
11080: "help/$lang",'','',$newfile{$lang});
11081: if ($result eq 'ok') {
11082: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
11083: $changes{'helpurl'}{$lang} = 1;
11084: } else {
11085: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
11086: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 11087: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 11088: (!grep(/^\Q$lang\E$/,@delurls))) {
11089: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
11090: }
11091: }
11092: }
11093: } else {
11094: $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);
11095: }
11096: } else {
11097: $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);
11098: }
11099: if ($error) {
11100: &Apache::lonnet::logthis($error);
11101: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11102: }
11103: }
1.256 raeburn 11104:
11105: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
11106: if (ref($domconfig{'login'}) eq 'HASH') {
11107: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
11108: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
11109: if ($domservers{$lonhost}) {
11110: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
11111: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 11112: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 11113: }
11114: }
11115: }
11116: }
11117: }
11118: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
11119: foreach my $lonhost (sort(keys(%domservers))) {
11120: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
11121: $changes{'headtag'}{$lonhost} = 1;
11122: } else {
11123: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
11124: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
11125: }
11126: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
11127: push(@newhosts,$lonhost);
11128: } elsif ($currheadtagurls{$lonhost}) {
11129: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
11130: if ($currexempt{$lonhost}) {
1.289 raeburn 11131: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 11132: $changes{'headtag'}{$lonhost} = 1;
11133: }
11134: } elsif ($possexempt{$lonhost}) {
11135: $changes{'headtag'}{$lonhost} = 1;
11136: }
11137: if ($possexempt{$lonhost}) {
11138: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
11139: }
11140: }
11141: }
11142: }
11143: if (@newhosts) {
11144: my $error;
11145: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11146: if ($configuserok eq 'ok') {
11147: if ($switchserver) {
11148: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
11149: } elsif ($author_ok eq 'ok') {
11150: foreach my $lonhost (@newhosts) {
11151: my $formelem = 'loginheadtag_'.$lonhost;
11152: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
11153: "login/headtag/$lonhost",'','',
11154: $env{'form.loginheadtag_'.$lonhost.'.filename'});
11155: if ($result eq 'ok') {
11156: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
11157: $changes{'headtag'}{$lonhost} = 1;
11158: if ($possexempt{$lonhost}) {
11159: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
11160: }
11161: } else {
11162: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
11163: $newheadtagurls{$lonhost},$result);
11164: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
11165: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
11166: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
11167: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
11168: }
11169: }
11170: }
11171: } else {
11172: $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);
11173: }
11174: } else {
11175: $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);
11176: }
11177: if ($error) {
11178: &Apache::lonnet::logthis($error);
11179: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11180: }
11181: }
1.169 raeburn 11182: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 11183:
11184: my $defaulthelpfile = '/adm/loginproblems.html';
11185: my $defaulttext = &mt('Default in use');
11186:
1.1 raeburn 11187: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
11188: $dom);
11189: if ($putresult eq 'ok') {
1.188 raeburn 11190: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 11191: my %defaultchecked = (
11192: 'coursecatalog' => 'on',
1.188 raeburn 11193: 'helpdesk' => 'on',
1.42 raeburn 11194: 'adminmail' => 'off',
1.43 raeburn 11195: 'newuser' => 'off',
1.42 raeburn 11196: );
1.55 raeburn 11197: if (ref($domconfig{'login'}) eq 'HASH') {
11198: foreach my $item (@toggles) {
11199: if ($defaultchecked{$item} eq 'on') {
11200: if (($domconfig{'login'}{$item} eq '0') &&
11201: ($env{'form.'.$item} eq '1')) {
11202: $changes{$item} = 1;
11203: } elsif (($domconfig{'login'}{$item} eq '' ||
11204: $domconfig{'login'}{$item} eq '1') &&
11205: ($env{'form.'.$item} eq '0')) {
11206: $changes{$item} = 1;
11207: }
11208: } elsif ($defaultchecked{$item} eq 'off') {
11209: if (($domconfig{'login'}{$item} eq '1') &&
11210: ($env{'form.'.$item} eq '0')) {
11211: $changes{$item} = 1;
11212: } elsif (($domconfig{'login'}{$item} eq '' ||
11213: $domconfig{'login'}{$item} eq '0') &&
11214: ($env{'form.'.$item} eq '1')) {
11215: $changes{$item} = 1;
11216: }
1.42 raeburn 11217: }
11218: }
1.41 raeburn 11219: }
1.6 raeburn 11220: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 11221: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 11222: if (ref($lastactref) eq 'HASH') {
11223: $lastactref->{'domainconfig'} = 1;
11224: }
1.1 raeburn 11225: $resulttext = &mt('Changes made:').'<ul>';
11226: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 11227: if ($item eq 'loginvia') {
1.112 raeburn 11228: if (ref($changes{$item}) eq 'HASH') {
11229: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
11230: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 11231: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
11232: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
11233: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
11234: $protocol = 'http' if ($protocol ne 'https');
11235: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
11236:
11237: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
11238: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
11239: } else {
11240: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
11241: }
11242: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
11243: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
11244: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
11245: }
11246: $resulttext .= '</li>';
11247: } else {
11248: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
11249: }
1.112 raeburn 11250: } else {
1.128 raeburn 11251: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 11252: }
11253: }
1.128 raeburn 11254: $resulttext .= '</ul></li>';
1.112 raeburn 11255: }
1.168 raeburn 11256: } elsif ($item eq 'helpurl') {
11257: if (ref($changes{$item}) eq 'HASH') {
11258: foreach my $lang (sort(keys(%{$changes{$item}}))) {
11259: if (grep(/^\Q$lang\E$/,@delurls)) {
11260: my ($chg,$link);
11261: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
11262: if ($lang eq 'nolang') {
11263: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
11264: } else {
11265: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
11266: }
11267: $resulttext .= '<li>'.$chg.'</li>';
11268: } else {
11269: my $chg;
11270: if ($lang eq 'nolang') {
11271: $chg = &mt('custom log-in help file for no preferred language');
11272: } else {
11273: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
11274: }
11275: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
11276: $loginhash{'login'}{'helpurl'}{$lang}.
11277: '?inhibitmenu=yes',$chg,600,500).
11278: '</li>';
11279: }
11280: }
11281: }
1.256 raeburn 11282: } elsif ($item eq 'headtag') {
11283: if (ref($changes{$item}) eq 'HASH') {
11284: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
11285: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
11286: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
11287: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
11288: $resulttext .= '<li><a href="'.
11289: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
11290: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
11291: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
11292: if ($possexempt{$lonhost}) {
11293: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
11294: } else {
11295: $resulttext .= &mt('included for any client IP');
11296: }
11297: $resulttext .= '</li>';
11298: }
11299: }
11300: }
1.169 raeburn 11301: } elsif ($item eq 'captcha') {
11302: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 11303: my $chgtxt;
1.169 raeburn 11304: if ($loginhash{'login'}{$item} eq 'notused') {
11305: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
11306: } else {
11307: my %captchas = &captcha_phrases();
11308: if ($captchas{$loginhash{'login'}{$item}}) {
11309: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
11310: } else {
11311: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
11312: }
11313: }
11314: $resulttext .= '<li>'.$chgtxt.'</li>';
11315: }
11316: } elsif ($item eq 'recaptchakeys') {
11317: if (ref($loginhash{'login'}) eq 'HASH') {
11318: my ($privkey,$pubkey);
11319: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
11320: $pubkey = $loginhash{'login'}{$item}{'public'};
11321: $privkey = $loginhash{'login'}{$item}{'private'};
11322: }
11323: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
11324: if (!$pubkey) {
11325: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
11326: } else {
11327: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
11328: }
11329: if (!$privkey) {
11330: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
11331: } else {
1.251 raeburn 11332: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 11333: }
11334: $chgtxt .= '</ul>';
11335: $resulttext .= '<li>'.$chgtxt.'</li>';
11336: }
1.269 raeburn 11337: } elsif ($item eq 'recaptchaversion') {
11338: if (ref($loginhash{'login'}) eq 'HASH') {
11339: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 11340: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 11341: '</li>';
11342: }
11343: }
1.41 raeburn 11344: } else {
11345: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
11346: }
1.1 raeburn 11347: }
1.6 raeburn 11348: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 11349: } else {
11350: $resulttext = &mt('No changes made to log-in page settings');
11351: }
11352: } else {
1.11 albertel 11353: $resulttext = '<span class="LC_error">'.
11354: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11355: }
1.6 raeburn 11356: if ($errors) {
1.9 raeburn 11357: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 11358: $errors.'</ul>';
11359: }
11360: return $resulttext;
11361: }
11362:
1.256 raeburn 11363: sub check_exempt_addresses {
11364: my ($iplist) = @_;
11365: $iplist =~ s/^\s+//;
11366: $iplist =~ s/\s+$//;
11367: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
11368: my (@okips,$new);
11369: foreach my $ip (@poss_ips) {
11370: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
11371: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
11372: push(@okips,$ip);
11373: }
11374: }
11375: }
11376: if (@okips > 0) {
11377: $new = join(',',@okips);
11378: } else {
11379: $new = '';
11380: }
11381: return $new;
11382: }
11383:
1.6 raeburn 11384: sub color_font_choices {
11385: my %choices =
11386: &Apache::lonlocal::texthash (
11387: img => "Header",
11388: bgs => "Background colors",
11389: links => "Link colors",
1.55 raeburn 11390: images => "Images",
1.6 raeburn 11391: font => "Font color",
1.201 raeburn 11392: fontmenu => "Font menu",
1.76 raeburn 11393: pgbg => "Page",
1.6 raeburn 11394: tabbg => "Header",
11395: sidebg => "Border",
11396: link => "Link",
11397: alink => "Active link",
11398: vlink => "Visited link",
11399: );
11400: return %choices;
11401: }
11402:
11403: sub modify_rolecolors {
1.205 raeburn 11404: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 11405: my ($resulttext,%rolehash);
11406: $rolehash{'rolecolors'} = {};
1.55 raeburn 11407: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
11408: if ($domconfig{'rolecolors'} eq '') {
11409: $domconfig{'rolecolors'} = {};
11410: }
11411: }
1.9 raeburn 11412: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 11413: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
11414: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
11415: $dom);
11416: if ($putresult eq 'ok') {
11417: if (keys(%changes) > 0) {
1.41 raeburn 11418: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 11419: if (ref($lastactref) eq 'HASH') {
11420: $lastactref->{'domainconfig'} = 1;
11421: }
1.6 raeburn 11422: $resulttext = &display_colorchgs($dom,\%changes,$roles,
11423: $rolehash{'rolecolors'});
11424: } else {
11425: $resulttext = &mt('No changes made to default color schemes');
11426: }
11427: } else {
1.11 albertel 11428: $resulttext = '<span class="LC_error">'.
11429: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 11430: }
11431: if ($errors) {
11432: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11433: $errors.'</ul>';
11434: }
11435: return $resulttext;
11436: }
11437:
11438: sub modify_colors {
1.9 raeburn 11439: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 11440: my (%changes,%choices);
1.51 raeburn 11441: my @bgs;
1.6 raeburn 11442: my @links = ('link','alink','vlink');
1.41 raeburn 11443: my @logintext;
1.6 raeburn 11444: my @images;
11445: my $servadm = $r->dir_config('lonAdmEMail');
11446: my $errors;
1.200 raeburn 11447: my %defaults;
1.6 raeburn 11448: foreach my $role (@{$roles}) {
11449: if ($role eq 'login') {
1.12 raeburn 11450: %choices = &login_choices();
1.41 raeburn 11451: @logintext = ('textcol','bgcol');
1.12 raeburn 11452: } else {
11453: %choices = &color_font_choices();
11454: }
11455: if ($role eq 'login') {
1.41 raeburn 11456: @images = ('img','logo','domlogo','login');
1.51 raeburn 11457: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 11458: } else {
11459: @images = ('img');
1.200 raeburn 11460: @bgs = ('pgbg','tabbg','sidebg');
11461: }
11462: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
11463: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
11464: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
11465: }
11466: if ($role eq 'login') {
11467: foreach my $item (@logintext) {
1.234 raeburn 11468: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
11469: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
11470: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
11471: }
11472: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 11473: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
11474: }
11475: }
11476: } else {
1.234 raeburn 11477: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
11478: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
11479: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
11480: }
11481: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 11482: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
11483: }
1.6 raeburn 11484: }
1.200 raeburn 11485: foreach my $item (@bgs) {
1.234 raeburn 11486: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
11487: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
11488: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
11489: }
11490: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 11491: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
11492: }
11493: }
11494: foreach my $item (@links) {
1.234 raeburn 11495: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
11496: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
11497: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
11498: }
11499: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 11500: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
11501: }
1.6 raeburn 11502: }
1.46 raeburn 11503: my ($configuserok,$author_ok,$switchserver) =
11504: &config_check($dom,$confname,$servadm);
1.9 raeburn 11505: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 11506: if (ref($domconfig->{$role}) ne 'HASH') {
11507: $domconfig->{$role} = {};
11508: }
1.8 raeburn 11509: foreach my $img (@images) {
1.70 raeburn 11510: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
11511: if (defined($env{'form.login_showlogo_'.$img})) {
11512: $confhash->{$role}{'showlogo'}{$img} = 1;
11513: } else {
11514: $confhash->{$role}{'showlogo'}{$img} = 0;
11515: }
11516: }
1.18 albertel 11517: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
11518: && !defined($domconfig->{$role}{$img})
11519: && !$env{'form.'.$role.'_del_'.$img}
11520: && $env{'form.'.$role.'_import_'.$img}) {
11521: # import the old configured image from the .tab setting
11522: # if they haven't provided a new one
11523: $domconfig->{$role}{$img} =
11524: $env{'form.'.$role.'_import_'.$img};
11525: }
1.6 raeburn 11526: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 11527: my $error;
1.6 raeburn 11528: if ($configuserok eq 'ok') {
1.9 raeburn 11529: if ($switchserver) {
1.12 raeburn 11530: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 11531: } else {
11532: if ($author_ok eq 'ok') {
11533: my ($result,$logourl) =
11534: &publishlogo($r,'upload',$role.'_'.$img,
11535: $dom,$confname,$img,$width,$height);
11536: if ($result eq 'ok') {
11537: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 11538: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 11539: } else {
1.12 raeburn 11540: $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 11541: }
11542: } else {
1.46 raeburn 11543: $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 11544: }
11545: }
11546: } else {
1.46 raeburn 11547: $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 11548: }
11549: if ($error) {
1.8 raeburn 11550: &Apache::lonnet::logthis($error);
1.11 albertel 11551: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 11552: }
11553: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 11554: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
11555: my $error;
11556: if ($configuserok eq 'ok') {
11557: # is confname an author?
11558: if ($switchserver eq '') {
11559: if ($author_ok eq 'ok') {
11560: my ($result,$logourl) =
11561: &publishlogo($r,'copy',$domconfig->{$role}{$img},
11562: $dom,$confname,$img,$width,$height);
11563: if ($result eq 'ok') {
11564: $confhash->{$role}{$img} = $logourl;
1.18 albertel 11565: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 11566: }
11567: }
11568: }
11569: }
1.6 raeburn 11570: }
11571: }
11572: }
11573: if (ref($domconfig) eq 'HASH') {
11574: if (ref($domconfig->{$role}) eq 'HASH') {
11575: foreach my $img (@images) {
11576: if ($domconfig->{$role}{$img} ne '') {
11577: if ($env{'form.'.$role.'_del_'.$img}) {
11578: $confhash->{$role}{$img} = '';
1.12 raeburn 11579: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 11580: } else {
1.9 raeburn 11581: if ($confhash->{$role}{$img} eq '') {
11582: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
11583: }
1.6 raeburn 11584: }
11585: } else {
11586: if ($env{'form.'.$role.'_del_'.$img}) {
11587: $confhash->{$role}{$img} = '';
1.12 raeburn 11588: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 11589: }
11590: }
1.70 raeburn 11591: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
11592: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
11593: if ($confhash->{$role}{'showlogo'}{$img} ne
11594: $domconfig->{$role}{'showlogo'}{$img}) {
11595: $changes{$role}{'showlogo'}{$img} = 1;
11596: }
11597: } else {
11598: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
11599: $changes{$role}{'showlogo'}{$img} = 1;
11600: }
11601: }
11602: }
11603: }
1.6 raeburn 11604: if ($domconfig->{$role}{'font'} ne '') {
11605: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
11606: $changes{$role}{'font'} = 1;
11607: }
11608: } else {
11609: if ($confhash->{$role}{'font'}) {
11610: $changes{$role}{'font'} = 1;
11611: }
11612: }
1.107 raeburn 11613: if ($role ne 'login') {
11614: if ($domconfig->{$role}{'fontmenu'} ne '') {
11615: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
11616: $changes{$role}{'fontmenu'} = 1;
11617: }
11618: } else {
11619: if ($confhash->{$role}{'fontmenu'}) {
11620: $changes{$role}{'fontmenu'} = 1;
11621: }
1.97 tempelho 11622: }
11623: }
1.6 raeburn 11624: foreach my $item (@bgs) {
11625: if ($domconfig->{$role}{$item} ne '') {
11626: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11627: $changes{$role}{'bgs'}{$item} = 1;
11628: }
11629: } else {
11630: if ($confhash->{$role}{$item}) {
11631: $changes{$role}{'bgs'}{$item} = 1;
11632: }
11633: }
11634: }
11635: foreach my $item (@links) {
11636: if ($domconfig->{$role}{$item} ne '') {
11637: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11638: $changes{$role}{'links'}{$item} = 1;
11639: }
11640: } else {
11641: if ($confhash->{$role}{$item}) {
11642: $changes{$role}{'links'}{$item} = 1;
11643: }
11644: }
11645: }
1.41 raeburn 11646: foreach my $item (@logintext) {
11647: if ($domconfig->{$role}{$item} ne '') {
11648: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11649: $changes{$role}{'logintext'}{$item} = 1;
11650: }
11651: } else {
11652: if ($confhash->{$role}{$item}) {
11653: $changes{$role}{'logintext'}{$item} = 1;
11654: }
11655: }
11656: }
1.6 raeburn 11657: } else {
11658: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 11659: \@logintext,$confhash,\%changes);
1.6 raeburn 11660: }
11661: } else {
11662: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 11663: \@logintext,$confhash,\%changes);
1.6 raeburn 11664: }
11665: }
11666: return ($errors,%changes);
11667: }
11668:
1.46 raeburn 11669: sub config_check {
11670: my ($dom,$confname,$servadm) = @_;
11671: my ($configuserok,$author_ok,$switchserver,%currroles);
11672: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
11673: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
11674: $confname,$servadm);
11675: if ($configuserok eq 'ok') {
11676: $switchserver = &check_switchserver($dom,$confname);
11677: if ($switchserver eq '') {
11678: $author_ok = &check_authorstatus($dom,$confname,%currroles);
11679: }
11680: }
11681: return ($configuserok,$author_ok,$switchserver);
11682: }
11683:
1.6 raeburn 11684: sub default_change_checker {
1.41 raeburn 11685: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 11686: foreach my $item (@{$links}) {
11687: if ($confhash->{$role}{$item}) {
11688: $changes->{$role}{'links'}{$item} = 1;
11689: }
11690: }
11691: foreach my $item (@{$bgs}) {
11692: if ($confhash->{$role}{$item}) {
11693: $changes->{$role}{'bgs'}{$item} = 1;
11694: }
11695: }
1.41 raeburn 11696: foreach my $item (@{$logintext}) {
11697: if ($confhash->{$role}{$item}) {
11698: $changes->{$role}{'logintext'}{$item} = 1;
11699: }
11700: }
1.6 raeburn 11701: foreach my $img (@{$images}) {
11702: if ($env{'form.'.$role.'_del_'.$img}) {
11703: $confhash->{$role}{$img} = '';
1.12 raeburn 11704: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 11705: }
1.70 raeburn 11706: if ($role eq 'login') {
11707: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
11708: $changes->{$role}{'showlogo'}{$img} = 1;
11709: }
11710: }
1.6 raeburn 11711: }
11712: if ($confhash->{$role}{'font'}) {
11713: $changes->{$role}{'font'} = 1;
11714: }
1.48 raeburn 11715: }
1.6 raeburn 11716:
11717: sub display_colorchgs {
11718: my ($dom,$changes,$roles,$confhash) = @_;
11719: my (%choices,$resulttext);
11720: if (!grep(/^login$/,@{$roles})) {
11721: $resulttext = &mt('Changes made:').'<br />';
11722: }
11723: foreach my $role (@{$roles}) {
11724: if ($role eq 'login') {
11725: %choices = &login_choices();
11726: } else {
11727: %choices = &color_font_choices();
11728: }
11729: if (ref($changes->{$role}) eq 'HASH') {
11730: if ($role ne 'login') {
11731: $resulttext .= '<h4>'.&mt($role).'</h4>';
11732: }
11733: foreach my $key (sort(keys(%{$changes->{$role}}))) {
11734: if ($role ne 'login') {
11735: $resulttext .= '<ul>';
11736: }
11737: if (ref($changes->{$role}{$key}) eq 'HASH') {
11738: if ($role ne 'login') {
11739: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
11740: }
11741: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 11742: if (($role eq 'login') && ($key eq 'showlogo')) {
11743: if ($confhash->{$role}{$key}{$item}) {
11744: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
11745: } else {
11746: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
11747: }
11748: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 11749: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
11750: } else {
1.12 raeburn 11751: my $newitem = $confhash->{$role}{$item};
11752: if ($key eq 'images') {
1.306 raeburn 11753: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 11754: }
11755: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 11756: }
11757: }
11758: if ($role ne 'login') {
11759: $resulttext .= '</ul></li>';
11760: }
11761: } else {
11762: if ($confhash->{$role}{$key} eq '') {
11763: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
11764: } else {
11765: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
11766: }
11767: }
11768: if ($role ne 'login') {
11769: $resulttext .= '</ul>';
11770: }
11771: }
11772: }
11773: }
1.3 raeburn 11774: return $resulttext;
1.1 raeburn 11775: }
11776:
1.9 raeburn 11777: sub thumb_dimensions {
11778: return ('200','50');
11779: }
11780:
1.16 raeburn 11781: sub check_dimensions {
11782: my ($inputfile) = @_;
11783: my ($fullwidth,$fullheight);
11784: if ($inputfile =~ m|^[/\w.\-]+$|) {
11785: if (open(PIPE,"identify $inputfile 2>&1 |")) {
11786: my $imageinfo = <PIPE>;
11787: if (!close(PIPE)) {
11788: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
11789: }
11790: chomp($imageinfo);
11791: my ($fullsize) =
1.21 raeburn 11792: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 11793: if ($fullsize) {
11794: ($fullwidth,$fullheight) = split(/x/,$fullsize);
11795: }
11796: }
11797: }
11798: return ($fullwidth,$fullheight);
11799: }
11800:
1.9 raeburn 11801: sub check_configuser {
11802: my ($uhome,$dom,$confname,$servadm) = @_;
11803: my ($configuserok,%currroles);
11804: if ($uhome eq 'no_host') {
11805: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 11806: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 11807: $configuserok =
11808: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
11809: $configpass,'','','','','',undef,$servadm);
11810: } else {
11811: $configuserok = 'ok';
11812: %currroles =
11813: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
11814: }
11815: return ($configuserok,%currroles);
11816: }
11817:
11818: sub check_authorstatus {
11819: my ($dom,$confname,%currroles) = @_;
11820: my $author_ok;
1.40 raeburn 11821: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 11822: my $start = time;
11823: my $end = 0;
11824: $author_ok =
11825: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 11826: 'au',$end,$start,'','','domconfig');
1.9 raeburn 11827: } else {
11828: $author_ok = 'ok';
11829: }
11830: return $author_ok;
11831: }
11832:
11833: sub publishlogo {
1.46 raeburn 11834: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 11835: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 11836: if ($action eq 'upload') {
11837: $fname=$env{'form.'.$formname.'.filename'};
11838: chop($env{'form.'.$formname});
11839: } else {
11840: ($fname) = ($formname =~ /([^\/]+)$/);
11841: }
1.46 raeburn 11842: if ($savefileas ne '') {
11843: $fname = $savefileas;
11844: }
1.9 raeburn 11845: $fname=&Apache::lonnet::clean_filename($fname);
11846: # See if there is anything left
11847: unless ($fname) { return ('error: no uploaded file'); }
11848: $fname="$subdir/$fname";
1.210 raeburn 11849: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 11850: my $filepath="$docroot/priv";
11851: my $relpath = "$dom/$confname";
1.9 raeburn 11852: my ($fnamepath,$file,$fetchthumb);
11853: $file=$fname;
11854: if ($fname=~m|/|) {
11855: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
11856: }
1.164 raeburn 11857: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 11858: my $count;
1.164 raeburn 11859: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 11860: $filepath.="/$parts[$count]";
11861: if ((-e $filepath)!=1) {
11862: mkdir($filepath,02770);
11863: }
11864: }
11865: # Check for bad extension and disallow upload
11866: if ($file=~/\.(\w+)$/ &&
11867: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
11868: $output =
1.207 bisitz 11869: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 11870: } elsif ($file=~/\.(\w+)$/ &&
11871: !defined(&Apache::loncommon::fileembstyle($1))) {
11872: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
11873: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 11874: $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 11875: } elsif (-d "$filepath/$file") {
1.195 bisitz 11876: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 11877: } else {
11878: my $source = $filepath.'/'.$file;
11879: my $logfile;
1.316 raeburn 11880: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 11881: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 11882: }
11883: print $logfile
11884: "\n================= Publish ".localtime()." ================\n".
11885: $env{'user.name'}.':'.$env{'user.domain'}."\n";
11886: # Save the file
1.316 raeburn 11887: if (!open(FH,">",$source)) {
1.9 raeburn 11888: &Apache::lonnet::logthis('Failed to create '.$source);
11889: return (&mt('Failed to create file'));
11890: }
11891: if ($action eq 'upload') {
11892: if (!print FH ($env{'form.'.$formname})) {
11893: &Apache::lonnet::logthis('Failed to write to '.$source);
11894: return (&mt('Failed to write file'));
11895: }
11896: } else {
11897: my $original = &Apache::lonnet::filelocation('',$formname);
11898: if(!copy($original,$source)) {
11899: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
11900: return (&mt('Failed to write file'));
11901: }
11902: }
11903: close(FH);
11904: chmod(0660, $source); # Permissions to rw-rw---.
11905:
11906: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
11907: my $copyfile=$targetdir.'/'.$file;
11908:
11909: my @parts=split(/\//,$targetdir);
11910: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
11911: for (my $count=5;$count<=$#parts;$count++) {
11912: $path.="/$parts[$count]";
11913: if (!-e $path) {
11914: print $logfile "\nCreating directory ".$path;
11915: mkdir($path,02770);
11916: }
11917: }
11918: my $versionresult;
11919: if (-e $copyfile) {
11920: $versionresult = &logo_versioning($targetdir,$file,$logfile);
11921: } else {
11922: $versionresult = 'ok';
11923: }
11924: if ($versionresult eq 'ok') {
11925: if (copy($source,$copyfile)) {
11926: print $logfile "\nCopied original source to ".$copyfile."\n";
11927: $output = 'ok';
11928: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 11929: push(@{$modified_urls},[$copyfile,$source]);
11930: my $metaoutput =
11931: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
11932: unless ($registered_cleanup) {
11933: my $handlers = $r->get_handlers('PerlCleanupHandler');
11934: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
11935: $registered_cleanup=1;
11936: }
1.9 raeburn 11937: } else {
11938: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
11939: $output = &mt('Failed to copy file to RES space').", $!";
11940: }
11941: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
11942: my $inputfile = $filepath.'/'.$file;
11943: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 11944: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
11945: if ($fullwidth ne '' && $fullheight ne '') {
11946: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
11947: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 11948: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
11949: system({$args[0]} @args);
1.16 raeburn 11950: chmod(0660, $filepath.'/tn-'.$file);
11951: if (-e $outfile) {
11952: my $copyfile=$targetdir.'/tn-'.$file;
11953: if (copy($outfile,$copyfile)) {
11954: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 11955: my $thumb_metaoutput =
11956: &write_metadata($dom,$confname,$formname,
11957: $targetdir,'tn-'.$file,$logfile);
11958: push(@{$modified_urls},[$copyfile,$outfile]);
11959: unless ($registered_cleanup) {
11960: my $handlers = $r->get_handlers('PerlCleanupHandler');
11961: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
11962: $registered_cleanup=1;
11963: }
1.267 raeburn 11964: $madethumb = 1;
1.16 raeburn 11965: } else {
11966: print $logfile "\nUnable to write ".$copyfile.
11967: ':'.$!."\n";
11968: }
11969: }
1.9 raeburn 11970: }
11971: }
11972: }
11973: } else {
11974: $output = $versionresult;
11975: }
11976: }
1.267 raeburn 11977: return ($output,$logourl,$madethumb);
1.9 raeburn 11978: }
11979:
11980: sub logo_versioning {
11981: my ($targetdir,$file,$logfile) = @_;
11982: my $target = $targetdir.'/'.$file;
11983: my ($maxversion,$fn,$extn,$output);
11984: $maxversion = 0;
11985: if ($file =~ /^(.+)\.(\w+)$/) {
11986: $fn=$1;
11987: $extn=$2;
11988: }
11989: opendir(DIR,$targetdir);
11990: while (my $filename=readdir(DIR)) {
11991: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
11992: $maxversion=($1>$maxversion)?$1:$maxversion;
11993: }
11994: }
11995: $maxversion++;
11996: print $logfile "\nCreating old version ".$maxversion."\n";
11997: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
11998: if (copy($target,$copyfile)) {
11999: print $logfile "Copied old target to ".$copyfile."\n";
12000: $copyfile=$copyfile.'.meta';
12001: if (copy($target.'.meta',$copyfile)) {
12002: print $logfile "Copied old target metadata to ".$copyfile."\n";
12003: $output = 'ok';
12004: } else {
12005: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
12006: $output = &mt('Failed to copy old meta').", $!, ";
12007: }
12008: } else {
12009: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
12010: $output = &mt('Failed to copy old target').", $!, ";
12011: }
12012: return $output;
12013: }
12014:
12015: sub write_metadata {
12016: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
12017: my (%metadatafields,%metadatakeys,$output);
12018: $metadatafields{'title'}=$formname;
12019: $metadatafields{'creationdate'}=time;
12020: $metadatafields{'lastrevisiondate'}=time;
12021: $metadatafields{'copyright'}='public';
12022: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
12023: $env{'user.domain'};
12024: $metadatafields{'authorspace'}=$confname.':'.$dom;
12025: $metadatafields{'domain'}=$dom;
12026: {
12027: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
12028: my $mfh;
1.316 raeburn 12029: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 12030: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 12031: unless ($_=~/\./) {
12032: my $unikey=$_;
12033: $unikey=~/^([A-Za-z]+)/;
12034: my $tag=$1;
12035: $tag=~tr/A-Z/a-z/;
12036: print $mfh "\n\<$tag";
12037: foreach (split(/\,/,$metadatakeys{$unikey})) {
12038: my $value=$metadatafields{$unikey.'.'.$_};
12039: $value=~s/\"/\'\'/g;
12040: print $mfh ' '.$_.'="'.$value.'"';
12041: }
12042: print $mfh '>'.
12043: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
12044: .'</'.$tag.'>';
12045: }
12046: }
12047: $output = 'ok';
12048: print $logfile "\nWrote metadata";
12049: close($mfh);
12050: } else {
12051: print $logfile "\nFailed to open metadata file";
1.9 raeburn 12052: $output = &mt('Could not write metadata');
12053: }
12054: }
1.155 raeburn 12055: return $output;
12056: }
12057:
12058: sub notifysubscribed {
12059: foreach my $targetsource (@{$modified_urls}){
12060: next unless (ref($targetsource) eq 'ARRAY');
12061: my ($target,$source)=@{$targetsource};
12062: if ($source ne '') {
1.316 raeburn 12063: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 12064: print $logfh "\nCleanup phase: Notifications\n";
12065: my @subscribed=&subscribed_hosts($target);
12066: foreach my $subhost (@subscribed) {
12067: print $logfh "\nNotifying host ".$subhost.':';
12068: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
12069: print $logfh $reply;
12070: }
12071: my @subscribedmeta=&subscribed_hosts("$target.meta");
12072: foreach my $subhost (@subscribedmeta) {
12073: print $logfh "\nNotifying host for metadata only ".$subhost.':';
12074: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
12075: $subhost);
12076: print $logfh $reply;
12077: }
12078: print $logfh "\n============ Done ============\n";
1.160 raeburn 12079: close($logfh);
1.155 raeburn 12080: }
12081: }
12082: }
12083: return OK;
12084: }
12085:
12086: sub subscribed_hosts {
12087: my ($target) = @_;
12088: my @subscribed;
1.316 raeburn 12089: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 12090: while (my $subline=<$fh>) {
12091: if ($subline =~ /^($match_lonid):/) {
12092: my $host = $1;
12093: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
12094: unless (grep(/^\Q$host\E$/,@subscribed)) {
12095: push(@subscribed,$host);
12096: }
12097: }
12098: }
12099: }
12100: }
12101: return @subscribed;
1.9 raeburn 12102: }
12103:
12104: sub check_switchserver {
12105: my ($dom,$confname) = @_;
12106: my ($allowed,$switchserver);
12107: my $home = &Apache::lonnet::homeserver($confname,$dom);
12108: if ($home eq 'no_host') {
12109: $home = &Apache::lonnet::domain($dom,'primary');
12110: }
12111: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 12112: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
12113: if (!$allowed) {
1.180 raeburn 12114: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 12115: }
12116: return $switchserver;
12117: }
12118:
1.1 raeburn 12119: sub modify_quotas {
1.216 raeburn 12120: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 12121: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 12122: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 12123: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
12124: $validationfieldsref);
1.86 raeburn 12125: if ($action eq 'quotas') {
12126: $context = 'tools';
1.163 raeburn 12127: } else {
1.86 raeburn 12128: $context = $action;
12129: }
12130: if ($context eq 'requestcourses') {
1.325 raeburn 12131: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 12132: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 12133: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
12134: %titles = &courserequest_titles();
12135: $toolregexp = join('|',@usertools);
12136: %conditions = &courserequest_conditions();
1.216 raeburn 12137: $confname = $dom.'-domainconfig';
12138: my $servadm = $r->dir_config('lonAdmEMail');
12139: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 12140: ($validationitemsref,$validationnamesref,$validationfieldsref) =
12141: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 12142: } elsif ($context eq 'requestauthor') {
12143: @usertools = ('author');
12144: %titles = &authorrequest_titles();
1.86 raeburn 12145: } else {
1.162 raeburn 12146: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 12147: %titles = &tool_titles();
1.86 raeburn 12148: }
1.212 raeburn 12149: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 12150: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 12151: foreach my $key (keys(%env)) {
1.101 raeburn 12152: if ($context eq 'requestcourses') {
12153: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
12154: my $item = $1;
12155: my $type = $2;
12156: if ($type =~ /^limit_(.+)/) {
12157: $limithash{$item}{$1} = $env{$key};
12158: } else {
12159: $confhash{$item}{$type} = $env{$key};
12160: }
12161: }
1.163 raeburn 12162: } elsif ($context eq 'requestauthor') {
12163: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
12164: $confhash{$1} = $env{$key};
12165: }
1.101 raeburn 12166: } else {
1.86 raeburn 12167: if ($key =~ /^form\.quota_(.+)$/) {
12168: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 12169: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
12170: $confhash{'authorquota'}{$1} = $env{$key};
12171: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 12172: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
12173: }
1.72 raeburn 12174: }
12175: }
1.163 raeburn 12176: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 12177: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 12178: @approvalnotify = sort(@approvalnotify);
12179: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 12180: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 12181: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
12182: foreach my $type (@hasuniquecode) {
12183: if (grep(/^\Q$type\E$/,@crstypes)) {
12184: $confhash{'uniquecode'}{$type} = 1;
12185: }
1.216 raeburn 12186: }
1.242 raeburn 12187: my (%newbook,%allpos);
1.216 raeburn 12188: if ($context eq 'requestcourses') {
1.242 raeburn 12189: foreach my $type ('textbooks','templates') {
12190: @{$allpos{$type}} = ();
12191: my $invalid;
12192: if ($type eq 'textbooks') {
12193: $invalid = &mt('Invalid LON-CAPA course for textbook');
12194: } else {
12195: $invalid = &mt('Invalid LON-CAPA course for template');
12196: }
12197: if ($env{'form.'.$type.'_addbook'}) {
12198: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
12199: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
12200: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
12201: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
12202: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
12203: } else {
12204: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
12205: my $position = $env{'form.'.$type.'_addbook_pos'};
12206: $position =~ s/\D+//g;
12207: if ($position ne '') {
12208: $allpos{$type}[$position] = $newbook{$type};
12209: }
1.216 raeburn 12210: }
1.242 raeburn 12211: } else {
12212: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 12213: }
12214: }
1.242 raeburn 12215: }
1.216 raeburn 12216: }
1.102 raeburn 12217: if (ref($domconfig{$action}) eq 'HASH') {
12218: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
12219: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
12220: $changes{'notify'}{'approval'} = 1;
12221: }
12222: } else {
1.144 raeburn 12223: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 12224: $changes{'notify'}{'approval'} = 1;
12225: }
12226: }
1.218 raeburn 12227: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
12228: if (ref($confhash{'uniquecode'}) eq 'HASH') {
12229: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
12230: unless ($confhash{'uniquecode'}{$crstype}) {
12231: $changes{'uniquecode'} = 1;
12232: }
12233: }
12234: unless ($changes{'uniquecode'}) {
12235: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
12236: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
12237: $changes{'uniquecode'} = 1;
12238: }
12239: }
12240: }
12241: } else {
12242: $changes{'uniquecode'} = 1;
12243: }
12244: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
12245: $changes{'uniquecode'} = 1;
1.216 raeburn 12246: }
12247: if ($context eq 'requestcourses') {
1.242 raeburn 12248: foreach my $type ('textbooks','templates') {
12249: if (ref($domconfig{$action}{$type}) eq 'HASH') {
12250: my %deletions;
12251: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
12252: if (@todelete) {
12253: map { $deletions{$_} = 1; } @todelete;
12254: }
12255: my %imgdeletions;
12256: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
12257: if (@todeleteimages) {
12258: map { $imgdeletions{$_} = 1; } @todeleteimages;
12259: }
12260: my $maxnum = $env{'form.'.$type.'_maxnum'};
12261: for (my $i=0; $i<=$maxnum; $i++) {
12262: my $itemid = $env{'form.'.$type.'_id_'.$i};
12263: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
12264: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
12265: if ($deletions{$key}) {
12266: if ($domconfig{$action}{$type}{$key}{'image'}) {
12267: #FIXME need to obsolete item in RES space
12268: }
12269: next;
12270: } else {
12271: my $newpos = $env{'form.'.$itemid};
12272: $newpos =~ s/\D+//g;
1.243 raeburn 12273: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 12274: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 12275: ($type eq 'templates'));
1.242 raeburn 12276: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
12277: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
12278: $changes{$type}{$key} = 1;
12279: }
12280: }
12281: $allpos{$type}[$newpos] = $key;
12282: }
12283: if ($imgdeletions{$key}) {
12284: $changes{$type}{$key} = 1;
1.216 raeburn 12285: #FIXME need to obsolete item in RES space
1.242 raeburn 12286: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
12287: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 12288: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
12289: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
12290: } else {
12291: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
12292: $cdom,$cnum,$type,$configuserok,
12293: $switchserver,$author_ok);
12294: if ($imgurl) {
12295: $confhash{$type}{$key}{'image'} = $imgurl;
12296: $changes{$type}{$key} = 1;
12297: }
12298: if ($error) {
12299: &Apache::lonnet::logthis($error);
12300: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12301: }
12302: }
1.242 raeburn 12303: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
12304: $confhash{$type}{$key}{'image'} =
12305: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 12306: }
12307: }
12308: }
12309: }
12310: }
12311: }
1.102 raeburn 12312: } else {
1.144 raeburn 12313: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 12314: $changes{'notify'}{'approval'} = 1;
12315: }
1.218 raeburn 12316: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 12317: $changes{'uniquecode'} = 1;
12318: }
12319: }
12320: if ($context eq 'requestcourses') {
1.242 raeburn 12321: foreach my $type ('textbooks','templates') {
12322: if ($newbook{$type}) {
12323: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 12324: foreach my $item ('subject','title','publisher','author') {
12325: next if ((($item eq 'author') || ($item eq 'publisher')) &&
12326: ($type eq 'template'));
1.242 raeburn 12327: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
12328: if ($env{'form.'.$type.'_addbook_'.$item}) {
12329: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
12330: }
12331: }
12332: if ($type eq 'textbooks') {
12333: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
12334: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 12335: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
12336: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
12337: } else {
12338: my ($imageurl,$error) =
12339: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
12340: $configuserok,$switchserver,$author_ok);
12341: if ($imageurl) {
12342: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
12343: }
12344: if ($error) {
12345: &Apache::lonnet::logthis($error);
12346: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12347: }
1.242 raeburn 12348: }
12349: }
1.216 raeburn 12350: }
12351: }
1.242 raeburn 12352: if (@{$allpos{$type}} > 0) {
12353: my $idx = 0;
12354: foreach my $item (@{$allpos{$type}}) {
12355: if ($item ne '') {
12356: $confhash{$type}{$item}{'order'} = $idx;
12357: if (ref($domconfig{$action}) eq 'HASH') {
12358: if (ref($domconfig{$action}{$type}) eq 'HASH') {
12359: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
12360: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
12361: $changes{$type}{$item} = 1;
12362: }
1.216 raeburn 12363: }
12364: }
12365: }
1.242 raeburn 12366: $idx ++;
1.216 raeburn 12367: }
12368: }
12369: }
12370: }
1.235 raeburn 12371: if (ref($validationitemsref) eq 'ARRAY') {
12372: foreach my $item (@{$validationitemsref}) {
12373: if ($item eq 'fields') {
12374: my @changed;
12375: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
12376: if (@{$confhash{'validation'}{$item}} > 0) {
12377: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
12378: }
1.266 raeburn 12379: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12380: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12381: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
12382: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
12383: $domconfig{'requestcourses'}{'validation'}{$item});
12384: } else {
12385: @changed = @{$confhash{'validation'}{$item}};
12386: }
1.235 raeburn 12387: } else {
12388: @changed = @{$confhash{'validation'}{$item}};
12389: }
12390: } else {
12391: @changed = @{$confhash{'validation'}{$item}};
12392: }
12393: if (@changed) {
12394: if ($confhash{'validation'}{$item}) {
12395: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
12396: } else {
12397: $changes{'validation'}{$item} = &mt('None');
12398: }
12399: }
12400: } else {
12401: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
12402: if ($item eq 'markup') {
12403: if ($env{'form.requestcourses_validation_'.$item}) {
12404: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
12405: }
12406: }
1.266 raeburn 12407: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12408: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12409: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
12410: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
12411: }
12412: } else {
12413: if ($confhash{'validation'}{$item} ne '') {
12414: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
12415: }
1.235 raeburn 12416: }
12417: } else {
12418: if ($confhash{'validation'}{$item} ne '') {
12419: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
12420: }
12421: }
12422: }
12423: }
12424: }
12425: if ($env{'form.validationdc'}) {
12426: my $newval = $env{'form.validationdc'};
1.285 raeburn 12427: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 12428: if (exists($domcoords{$newval})) {
12429: $confhash{'validation'}{'dc'} = $newval;
12430: }
12431: }
12432: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 12433: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12434: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12435: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
12436: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
12437: if ($confhash{'validation'}{'dc'} eq '') {
12438: $changes{'validation'}{'dc'} = &mt('None');
12439: } else {
12440: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
12441: }
1.235 raeburn 12442: }
1.266 raeburn 12443: } elsif ($confhash{'validation'}{'dc'} ne '') {
12444: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 12445: }
12446: } elsif ($confhash{'validation'}{'dc'} ne '') {
12447: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
12448: }
12449: } elsif ($confhash{'validation'}{'dc'} ne '') {
12450: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 12451: }
1.266 raeburn 12452: } else {
12453: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12454: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12455: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
12456: $changes{'validation'}{'dc'} = &mt('None');
12457: }
12458: }
1.235 raeburn 12459: }
12460: }
1.102 raeburn 12461: }
12462: } else {
1.86 raeburn 12463: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 12464: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 12465: }
1.72 raeburn 12466: foreach my $item (@usertools) {
12467: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 12468: my $unset;
1.101 raeburn 12469: if ($context eq 'requestcourses') {
1.104 raeburn 12470: $unset = '0';
12471: if ($type eq '_LC_adv') {
12472: $unset = '';
12473: }
1.101 raeburn 12474: if ($confhash{$item}{$type} eq 'autolimit') {
12475: $confhash{$item}{$type} .= '=';
12476: unless ($limithash{$item}{$type} =~ /\D/) {
12477: $confhash{$item}{$type} .= $limithash{$item}{$type};
12478: }
12479: }
1.163 raeburn 12480: } elsif ($context eq 'requestauthor') {
12481: $unset = '0';
12482: if ($type eq '_LC_adv') {
12483: $unset = '';
12484: }
1.72 raeburn 12485: } else {
1.101 raeburn 12486: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
12487: $confhash{$item}{$type} = 1;
12488: } else {
12489: $confhash{$item}{$type} = 0;
12490: }
1.72 raeburn 12491: }
1.86 raeburn 12492: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 12493: if ($action eq 'requestauthor') {
12494: if ($domconfig{$action}{$type} ne $confhash{$type}) {
12495: $changes{$type} = 1;
12496: }
12497: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 12498: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
12499: $changes{$item}{$type} = 1;
12500: }
12501: } else {
12502: if ($context eq 'requestcourses') {
1.104 raeburn 12503: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 12504: $changes{$item}{$type} = 1;
12505: }
12506: } else {
12507: if (!$confhash{$item}{$type}) {
12508: $changes{$item}{$type} = 1;
12509: }
12510: }
12511: }
12512: } else {
12513: if ($context eq 'requestcourses') {
1.104 raeburn 12514: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 12515: $changes{$item}{$type} = 1;
12516: }
1.163 raeburn 12517: } elsif ($context eq 'requestauthor') {
12518: if ($confhash{$type} ne $unset) {
12519: $changes{$type} = 1;
12520: }
1.72 raeburn 12521: } else {
12522: if (!$confhash{$item}{$type}) {
12523: $changes{$item}{$type} = 1;
12524: }
12525: }
12526: }
1.1 raeburn 12527: }
12528: }
1.163 raeburn 12529: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 12530: if (ref($domconfig{'quotas'}) eq 'HASH') {
12531: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
12532: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
12533: if (exists($confhash{'defaultquota'}{$key})) {
12534: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
12535: $changes{'defaultquota'}{$key} = 1;
12536: }
12537: } else {
12538: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 12539: }
12540: }
1.86 raeburn 12541: } else {
12542: foreach my $key (keys(%{$domconfig{'quotas'}})) {
12543: if (exists($confhash{'defaultquota'}{$key})) {
12544: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
12545: $changes{'defaultquota'}{$key} = 1;
12546: }
12547: } else {
12548: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 12549: }
1.1 raeburn 12550: }
12551: }
1.197 raeburn 12552: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
12553: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
12554: if (exists($confhash{'authorquota'}{$key})) {
12555: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
12556: $changes{'authorquota'}{$key} = 1;
12557: }
12558: } else {
12559: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
12560: }
12561: }
12562: }
1.1 raeburn 12563: }
1.86 raeburn 12564: if (ref($confhash{'defaultquota'}) eq 'HASH') {
12565: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
12566: if (ref($domconfig{'quotas'}) eq 'HASH') {
12567: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
12568: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
12569: $changes{'defaultquota'}{$key} = 1;
12570: }
12571: } else {
12572: if (!exists($domconfig{'quotas'}{$key})) {
12573: $changes{'defaultquota'}{$key} = 1;
12574: }
1.72 raeburn 12575: }
12576: } else {
1.86 raeburn 12577: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 12578: }
1.1 raeburn 12579: }
12580: }
1.197 raeburn 12581: if (ref($confhash{'authorquota'}) eq 'HASH') {
12582: foreach my $key (keys(%{$confhash{'authorquota'}})) {
12583: if (ref($domconfig{'quotas'}) eq 'HASH') {
12584: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
12585: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
12586: $changes{'authorquota'}{$key} = 1;
12587: }
12588: } else {
12589: $changes{'authorquota'}{$key} = 1;
12590: }
12591: } else {
12592: $changes{'authorquota'}{$key} = 1;
12593: }
12594: }
12595: }
1.1 raeburn 12596: }
1.72 raeburn 12597:
1.163 raeburn 12598: if ($context eq 'requestauthor') {
12599: $domdefaults{'requestauthor'} = \%confhash;
12600: } else {
12601: foreach my $key (keys(%confhash)) {
1.242 raeburn 12602: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 12603: $domdefaults{$key} = $confhash{$key};
12604: }
1.163 raeburn 12605: }
1.72 raeburn 12606: }
1.163 raeburn 12607:
1.1 raeburn 12608: my %quotahash = (
1.86 raeburn 12609: $action => { %confhash }
1.1 raeburn 12610: );
12611: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
12612: $dom);
12613: if ($putresult eq 'ok') {
12614: if (keys(%changes) > 0) {
1.72 raeburn 12615: my $cachetime = 24*60*60;
12616: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 12617: if (ref($lastactref) eq 'HASH') {
12618: $lastactref->{'domdefaults'} = 1;
12619: }
1.1 raeburn 12620: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 12621: unless (($context eq 'requestcourses') ||
1.163 raeburn 12622: ($context eq 'requestauthor')) {
1.86 raeburn 12623: if (ref($changes{'defaultquota'}) eq 'HASH') {
12624: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
12625: foreach my $type (@{$types},'default') {
12626: if (defined($changes{'defaultquota'}{$type})) {
12627: my $typetitle = $usertypes->{$type};
12628: if ($type eq 'default') {
12629: $typetitle = $othertitle;
12630: }
1.213 raeburn 12631: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 12632: }
12633: }
1.86 raeburn 12634: $resulttext .= '</ul></li>';
1.72 raeburn 12635: }
1.197 raeburn 12636: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 12637: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 12638: foreach my $type (@{$types},'default') {
12639: if (defined($changes{'authorquota'}{$type})) {
12640: my $typetitle = $usertypes->{$type};
12641: if ($type eq 'default') {
12642: $typetitle = $othertitle;
12643: }
1.213 raeburn 12644: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 12645: }
12646: }
12647: $resulttext .= '</ul></li>';
12648: }
1.72 raeburn 12649: }
1.80 raeburn 12650: my %newenv;
1.72 raeburn 12651: foreach my $item (@usertools) {
1.163 raeburn 12652: my (%haschgs,%inconf);
12653: if ($context eq 'requestauthor') {
12654: %haschgs = %changes;
1.210 raeburn 12655: %inconf = %confhash;
1.163 raeburn 12656: } else {
12657: if (ref($changes{$item}) eq 'HASH') {
12658: %haschgs = %{$changes{$item}};
12659: }
12660: if (ref($confhash{$item}) eq 'HASH') {
12661: %inconf = %{$confhash{$item}};
12662: }
12663: }
12664: if (keys(%haschgs) > 0) {
1.80 raeburn 12665: my $newacc =
12666: &Apache::lonnet::usertools_access($env{'user.name'},
12667: $env{'user.domain'},
1.86 raeburn 12668: $item,'reload',$context);
1.210 raeburn 12669: if (($context eq 'requestcourses') ||
1.163 raeburn 12670: ($context eq 'requestauthor')) {
1.108 raeburn 12671: if ($env{'environment.canrequest.'.$item} ne $newacc) {
12672: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 12673: }
12674: } else {
12675: if ($env{'environment.availabletools.'.$item} ne $newacc) {
12676: $newenv{'environment.availabletools.'.$item} = $newacc;
12677: }
1.80 raeburn 12678: }
1.163 raeburn 12679: unless ($context eq 'requestauthor') {
12680: $resulttext .= '<li>'.$titles{$item}.'<ul>';
12681: }
1.72 raeburn 12682: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 12683: if ($haschgs{$type}) {
1.72 raeburn 12684: my $typetitle = $usertypes->{$type};
12685: if ($type eq 'default') {
12686: $typetitle = $othertitle;
12687: } elsif ($type eq '_LC_adv') {
12688: $typetitle = 'LON-CAPA Advanced Users';
12689: }
1.163 raeburn 12690: if ($inconf{$type}) {
1.101 raeburn 12691: if ($context eq 'requestcourses') {
12692: my $cond;
1.163 raeburn 12693: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 12694: if ($1 eq '') {
12695: $cond = &mt('(Automatic processing of any request).');
12696: } else {
12697: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
12698: }
12699: } else {
1.163 raeburn 12700: $cond = $conditions{$inconf{$type}};
1.101 raeburn 12701: }
12702: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 12703: } elsif ($context eq 'requestauthor') {
12704: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
12705: $titles{$inconf{$type}},$typetitle);
12706:
1.101 raeburn 12707: } else {
12708: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
12709: }
1.72 raeburn 12710: } else {
1.104 raeburn 12711: if ($type eq '_LC_adv') {
1.163 raeburn 12712: if ($inconf{$type} eq '0') {
1.104 raeburn 12713: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
12714: } else {
12715: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
12716: }
12717: } else {
12718: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
12719: }
1.72 raeburn 12720: }
12721: }
1.26 raeburn 12722: }
1.163 raeburn 12723: unless ($context eq 'requestauthor') {
12724: $resulttext .= '</ul></li>';
12725: }
1.26 raeburn 12726: }
1.1 raeburn 12727: }
1.163 raeburn 12728: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 12729: if (ref($changes{'notify'}) eq 'HASH') {
12730: if ($changes{'notify'}{'approval'}) {
12731: if (ref($confhash{'notify'}) eq 'HASH') {
12732: if ($confhash{'notify'}{'approval'}) {
12733: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
12734: } else {
1.163 raeburn 12735: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 12736: }
12737: }
12738: }
12739: }
12740: }
1.216 raeburn 12741: if ($action eq 'requestcourses') {
12742: my @offon = ('off','on');
12743: if ($changes{'uniquecode'}) {
1.218 raeburn 12744: if (ref($confhash{'uniquecode'}) eq 'HASH') {
12745: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
12746: $resulttext .= '<li>'.
12747: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
12748: '</li>';
12749: } else {
12750: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
12751: '</li>';
12752: }
1.216 raeburn 12753: }
1.242 raeburn 12754: foreach my $type ('textbooks','templates') {
12755: if (ref($changes{$type}) eq 'HASH') {
12756: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
12757: foreach my $key (sort(keys(%{$changes{$type}}))) {
12758: my %coursehash = &Apache::lonnet::coursedescription($key);
12759: my $coursetitle = $coursehash{'description'};
12760: my $position = $confhash{$type}{$key}{'order'} + 1;
12761: $resulttext .= '<li>';
1.243 raeburn 12762: foreach my $item ('subject','title','publisher','author') {
12763: next if ((($item eq 'author') || ($item eq 'publisher')) &&
12764: ($type eq 'templates'));
1.242 raeburn 12765: my $name = $item.':';
12766: $name =~ s/^(\w)/\U$1/;
12767: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
12768: }
12769: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
12770: if ($type eq 'textbooks') {
12771: if ($confhash{$type}{$key}{'image'}) {
12772: $resulttext .= ' '.&mt('Image: [_1]',
12773: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
12774: ' alt="Textbook cover" />').'<br />';
12775: }
12776: }
12777: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 12778: }
1.242 raeburn 12779: $resulttext .= '</ul></li>';
1.216 raeburn 12780: }
12781: }
1.235 raeburn 12782: if (ref($changes{'validation'}) eq 'HASH') {
12783: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
12784: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
12785: foreach my $item (@{$validationitemsref}) {
12786: if (exists($changes{'validation'}{$item})) {
12787: if ($item eq 'markup') {
12788: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
12789: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
12790: } else {
12791: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
12792: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
12793: }
12794: }
12795: }
12796: if (exists($changes{'validation'}{'dc'})) {
12797: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
12798: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
12799: }
12800: }
12801: }
1.216 raeburn 12802: }
1.1 raeburn 12803: $resulttext .= '</ul>';
1.80 raeburn 12804: if (keys(%newenv)) {
12805: &Apache::lonnet::appenv(\%newenv);
12806: }
1.1 raeburn 12807: } else {
1.86 raeburn 12808: if ($context eq 'requestcourses') {
12809: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 12810: } elsif ($context eq 'requestauthor') {
12811: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 12812: } else {
1.90 weissno 12813: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 12814: }
1.1 raeburn 12815: }
12816: } else {
1.11 albertel 12817: $resulttext = '<span class="LC_error">'.
12818: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12819: }
1.216 raeburn 12820: if ($errors) {
12821: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
12822: '<ul>'.$errors.'</ul></p>';
12823: }
1.3 raeburn 12824: return $resulttext;
1.1 raeburn 12825: }
12826:
1.216 raeburn 12827: sub process_textbook_image {
1.242 raeburn 12828: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 12829: my $filename = $env{'form.'.$caller.'.filename'};
12830: my ($error,$url);
12831: my ($width,$height) = (50,50);
12832: if ($configuserok eq 'ok') {
12833: if ($switchserver) {
12834: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
12835: $switchserver);
12836: } elsif ($author_ok eq 'ok') {
12837: my ($result,$imageurl) =
12838: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 12839: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 12840: if ($result eq 'ok') {
12841: $url = $imageurl;
12842: } else {
12843: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
12844: }
12845: } else {
12846: $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);
12847: }
12848: } else {
12849: $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);
12850: }
12851: return ($url,$error);
12852: }
12853:
1.267 raeburn 12854: sub modify_ltitools {
12855: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
12856: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 12857: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 12858: my $confname = $dom.'-domainconfig';
12859: my $servadm = $r->dir_config('lonAdmEMail');
12860: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12861: my (%posslti,%possfield);
12862: my @courseroles = ('cc','in','ta','ep','st');
12863: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
12864: map { $posslti{$_} = 1; } @ltiroles;
12865: my @allfields = ('fullname','firstname','lastname','email','user','roles');
12866: map { $possfield{$_} = 1; } @allfields;
12867: my %lt = <itools_names();
12868: if ($env{'form.ltitools_add'}) {
12869: my $title = $env{'form.ltitools_add_title'};
12870: $title =~ s/(`)/'/g;
12871: ($newid,my $error) = &get_ltitools_id($dom,$title);
12872: if ($newid) {
12873: my $position = $env{'form.ltitools_add_pos'};
12874: $position =~ s/\D+//g;
12875: if ($position ne '') {
12876: $allpos[$position] = $newid;
12877: }
12878: $changes{$newid} = 1;
1.322 raeburn 12879: foreach my $item ('title','url','key','secret','lifetime') {
1.267 raeburn 12880: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322 raeburn 12881: if ($item eq 'lifetime') {
12882: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
12883: }
1.267 raeburn 12884: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 12885: if (($item eq 'key') || ($item eq 'secret')) {
12886: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
12887: } else {
12888: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
12889: }
1.267 raeburn 12890: }
12891: }
12892: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
12893: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
12894: }
12895: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
12896: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
12897: }
1.323 raeburn 12898: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
12899: $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
12900: } else {
12901: $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
12902: }
1.296 raeburn 12903: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 12904: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
12905: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 12906: if (($item eq 'width') || ($item eq 'height')) {
12907: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
12908: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
12909: }
12910: } else {
12911: if ($env{'form.ltitools_add_'.$item} ne '') {
12912: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
12913: }
1.267 raeburn 12914: }
12915: }
12916: if ($env{'form.ltitools_add_target'} eq 'window') {
12917: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 12918: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
12919: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 12920: } else {
12921: $confhash{$newid}{'display'}{'target'} = 'iframe';
12922: }
12923: foreach my $item ('passback','roster') {
1.319 raeburn 12924: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 12925: $confhash{$newid}{$item} = 1;
1.319 raeburn 12926: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
12927: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
12928: $lifetime =~ s/^\s+|\s+$//g;
12929: if ($lifetime =~ /^\d+\.?\d*$/) {
12930: $confhash{$newid}{$item.'valid'} = $lifetime;
12931: }
12932: }
1.267 raeburn 12933: }
12934: }
12935: if ($env{'form.ltitools_add_image.filename'} ne '') {
12936: my ($imageurl,$error) =
1.307 raeburn 12937: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 12938: $configuserok,$switchserver,$author_ok);
12939: if ($imageurl) {
12940: $confhash{$newid}{'image'} = $imageurl;
12941: }
12942: if ($error) {
12943: &Apache::lonnet::logthis($error);
12944: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12945: }
12946: }
12947: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
12948: foreach my $field (@fields) {
12949: if ($possfield{$field}) {
12950: if ($field eq 'roles') {
12951: foreach my $role (@courseroles) {
12952: my $choice = $env{'form.ltitools_add_roles_'.$role};
12953: if (($choice ne '') && ($posslti{$choice})) {
12954: $confhash{$newid}{'roles'}{$role} = $choice;
12955: if ($role eq 'cc') {
12956: $confhash{$newid}{'roles'}{'co'} = $choice;
12957: }
12958: }
12959: }
12960: } else {
12961: $confhash{$newid}{'fields'}{$field} = 1;
12962: }
12963: }
12964: }
1.324 raeburn 12965: if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
12966: if ($confhash{$newid}{'fields'}{'user'}) {
12967: if ($env{'form.ltitools_userincdom_add'}) {
12968: $confhash{$newid}{'incdom'} = 1;
12969: }
12970: }
12971: }
1.273 raeburn 12972: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
12973: foreach my $item (@courseconfig) {
12974: $confhash{$newid}{'crsconf'}{$item} = 1;
12975: }
1.267 raeburn 12976: if ($env{'form.ltitools_add_custom'}) {
12977: my $name = $env{'form.ltitools_add_custom_name'};
12978: my $value = $env{'form.ltitools_add_custom_value'};
12979: $value =~ s/(`)/'/g;
12980: $name =~ s/(`)/'/g;
12981: $confhash{$newid}{'custom'}{$name} = $value;
12982: }
12983: } else {
12984: my $error = &mt('Failed to acquire unique ID for new external tool');
12985: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12986: }
12987: }
12988: if (ref($domconfig{$action}) eq 'HASH') {
12989: my %deletions;
12990: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
12991: if (@todelete) {
12992: map { $deletions{$_} = 1; } @todelete;
12993: }
12994: my %customadds;
12995: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
12996: if (@newcustom) {
12997: map { $customadds{$_} = 1; } @newcustom;
12998: }
12999: my %imgdeletions;
13000: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
13001: if (@todeleteimages) {
13002: map { $imgdeletions{$_} = 1; } @todeleteimages;
13003: }
13004: my $maxnum = $env{'form.ltitools_maxnum'};
13005: for (my $i=0; $i<=$maxnum; $i++) {
13006: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 13007: $itemid =~ s/\D+//g;
1.267 raeburn 13008: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
13009: if ($deletions{$itemid}) {
13010: if ($domconfig{$action}{$itemid}{'image'}) {
13011: #FIXME need to obsolete item in RES space
13012: }
13013: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
13014: next;
13015: } else {
13016: my $newpos = $env{'form.ltitools_'.$itemid};
13017: $newpos =~ s/\D+//g;
1.322 raeburn 13018: foreach my $item ('title','url','lifetime') {
1.267 raeburn 13019: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
13020: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
13021: $changes{$itemid} = 1;
13022: }
13023: }
1.297 raeburn 13024: foreach my $item ('key','secret') {
13025: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
13026: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
13027: $changes{$itemid} = 1;
13028: }
13029: }
1.267 raeburn 13030: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
13031: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
13032: }
13033: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
13034: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
13035: }
1.323 raeburn 13036: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
13037: $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
13038: } else {
13039: $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
13040: }
13041: if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
13042: if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
13043: $changes{$itemid} = 1;
13044: }
13045: } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
13046: $changes{$itemid} = 1;
13047: }
1.267 raeburn 13048: foreach my $size ('width','height') {
13049: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
13050: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
13051: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
13052: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
13053: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13054: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
13055: $changes{$itemid} = 1;
13056: }
13057: } else {
13058: $changes{$itemid} = 1;
13059: }
1.296 raeburn 13060: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13061: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
13062: $changes{$itemid} = 1;
13063: }
13064: }
13065: }
13066: foreach my $item ('linktext','explanation') {
13067: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
13068: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
13069: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
13070: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
13071: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13072: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
13073: $changes{$itemid} = 1;
13074: }
13075: } else {
13076: $changes{$itemid} = 1;
13077: }
13078: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13079: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
13080: $changes{$itemid} = 1;
13081: }
1.267 raeburn 13082: }
13083: }
13084: if ($env{'form.ltitools_target_'.$i} eq 'window') {
13085: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 13086: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
13087: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 13088: } else {
13089: $confhash{$itemid}{'display'}{'target'} = 'iframe';
13090: }
13091: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13092: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
13093: $changes{$itemid} = 1;
13094: }
13095: } else {
13096: $changes{$itemid} = 1;
13097: }
13098: foreach my $extra ('passback','roster') {
13099: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
13100: $confhash{$itemid}{$extra} = 1;
1.319 raeburn 13101: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
1.338 raeburn 13102: my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
1.319 raeburn 13103: $lifetime =~ s/^\s+|\s+$//g;
13104: if ($lifetime =~ /^\d+\.?\d*$/) {
13105: $confhash{$itemid}{$extra.'valid'} = $lifetime;
13106: }
13107: }
1.267 raeburn 13108: }
13109: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
13110: $changes{$itemid} = 1;
13111: }
1.319 raeburn 13112: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
13113: $changes{$itemid} = 1;
13114: }
1.267 raeburn 13115: }
1.273 raeburn 13116: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 13117: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 13118: if (grep(/^\Q$item\E$/,@courseconfig)) {
13119: $confhash{$itemid}{'crsconf'}{$item} = 1;
13120: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
13121: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
13122: $changes{$itemid} = 1;
13123: }
13124: } else {
13125: $changes{$itemid} = 1;
13126: }
13127: }
13128: }
1.267 raeburn 13129: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
13130: foreach my $field (@fields) {
13131: if ($possfield{$field}) {
13132: if ($field eq 'roles') {
13133: foreach my $role (@courseroles) {
13134: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
13135: if (($choice ne '') && ($posslti{$choice})) {
13136: $confhash{$itemid}{'roles'}{$role} = $choice;
13137: if ($role eq 'cc') {
13138: $confhash{$itemid}{'roles'}{'co'} = $choice;
13139: }
13140: }
13141: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
13142: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
13143: $changes{$itemid} = 1;
13144: }
13145: } elsif ($confhash{$itemid}{'roles'}{$role}) {
13146: $changes{$itemid} = 1;
13147: }
13148: }
13149: } else {
13150: $confhash{$itemid}{'fields'}{$field} = 1;
13151: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
13152: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
13153: $changes{$itemid} = 1;
13154: }
13155: } else {
13156: $changes{$itemid} = 1;
13157: }
13158: }
13159: }
13160: }
1.324 raeburn 13161: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
13162: if ($confhash{$itemid}{'fields'}{'user'}) {
13163: if ($env{'form.ltitools_userincdom_'.$i}) {
13164: $confhash{$itemid}{'incdom'} = 1;
13165: }
13166: if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
13167: $changes{$itemid} = 1;
13168: }
13169: }
13170: }
1.267 raeburn 13171: $allpos[$newpos] = $itemid;
13172: }
13173: if ($imgdeletions{$itemid}) {
13174: $changes{$itemid} = 1;
13175: #FIXME need to obsolete item in RES space
13176: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
13177: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
13178: $itemid,$configuserok,$switchserver,
13179: $author_ok);
13180: if ($imgurl) {
13181: $confhash{$itemid}{'image'} = $imgurl;
13182: $changes{$itemid} = 1;
13183: }
13184: if ($error) {
13185: &Apache::lonnet::logthis($error);
13186: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13187: }
13188: } elsif ($domconfig{$action}{$itemid}{'image'}) {
13189: $confhash{$itemid}{'image'} =
13190: $domconfig{$action}{$itemid}{'image'};
13191: }
13192: if ($customadds{$i}) {
13193: my $name = $env{'form.ltitools_custom_name_'.$i};
13194: $name =~ s/(`)/'/g;
13195: $name =~ s/^\s+//;
13196: $name =~ s/\s+$//;
13197: my $value = $env{'form.ltitools_custom_value_'.$i};
13198: $value =~ s/(`)/'/g;
13199: $value =~ s/^\s+//;
13200: $value =~ s/\s+$//;
13201: if ($name ne '') {
13202: $confhash{$itemid}{'custom'}{$name} = $value;
13203: $changes{$itemid} = 1;
13204: }
13205: }
13206: my %customdels;
13207: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
13208: if (@customdeletions) {
13209: $changes{$itemid} = 1;
13210: }
13211: map { $customdels{$_} = 1; } @customdeletions;
13212: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
13213: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
13214: unless ($customdels{$key}) {
13215: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
13216: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
13217: }
13218: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
13219: $changes{$itemid} = 1;
13220: }
13221: }
13222: }
13223: }
13224: unless ($changes{$itemid}) {
13225: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
13226: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
13227: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
13228: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
13229: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
13230: $changes{$itemid} = 1;
13231: last;
13232: }
13233: }
13234: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
13235: $changes{$itemid} = 1;
13236: }
13237: }
13238: last if ($changes{$itemid});
13239: }
13240: }
13241: }
13242: }
13243: }
13244: if (@allpos > 0) {
13245: my $idx = 0;
13246: foreach my $itemid (@allpos) {
13247: if ($itemid ne '') {
13248: $confhash{$itemid}{'order'} = $idx;
13249: if (ref($domconfig{$action}) eq 'HASH') {
13250: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
13251: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
13252: $changes{$itemid} = 1;
13253: }
13254: }
13255: }
13256: $idx ++;
13257: }
13258: }
13259: }
13260: my %ltitoolshash = (
13261: $action => { %confhash }
13262: );
13263: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
13264: $dom);
13265: if ($putresult eq 'ok') {
1.297 raeburn 13266: my %ltienchash = (
13267: $action => { %encconfig }
13268: );
13269: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267 raeburn 13270: if (keys(%changes) > 0) {
13271: my $cachetime = 24*60*60;
1.297 raeburn 13272: my %ltiall = %confhash;
13273: foreach my $id (keys(%ltiall)) {
13274: if (ref($encconfig{$id}) eq 'HASH') {
13275: foreach my $item ('key','secret') {
13276: $ltiall{$id}{$item} = $encconfig{$id}{$item};
13277: }
13278: }
13279: }
13280: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 13281: if (ref($lastactref) eq 'HASH') {
13282: $lastactref->{'ltitools'} = 1;
13283: }
13284: $resulttext = &mt('Changes made:').'<ul>';
13285: my %bynum;
13286: foreach my $itemid (sort(keys(%changes))) {
13287: my $position = $confhash{$itemid}{'order'};
13288: $bynum{$position} = $itemid;
13289: }
13290: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13291: my $itemid = $bynum{$pos};
13292: if (ref($confhash{$itemid}) ne 'HASH') {
13293: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
13294: } else {
13295: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
13296: if ($confhash{$itemid}{'image'}) {
13297: $resulttext .= ' '.
13298: '<img src="'.$confhash{$itemid}{'image'}.'"'.
13299: ' alt="'.&mt('Tool Provider icon').'" />';
13300: }
13301: $resulttext .= '</li><ul>';
13302: my $position = $pos + 1;
13303: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323 raeburn 13304: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267 raeburn 13305: if ($confhash{$itemid}{$item} ne '') {
13306: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
13307: }
13308: }
1.297 raeburn 13309: if ($encconfig{$itemid}{'key'} ne '') {
13310: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
13311: }
13312: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 13313: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 13314: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 13315: $resulttext .= ('*'x$num).'</li>';
13316: }
1.273 raeburn 13317: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 13318: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 13319: my $numconfig = 0;
13320: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
13321: foreach my $item (@possconfig) {
13322: if ($confhash{$itemid}{'crsconf'}{$item}) {
13323: $numconfig ++;
1.296 raeburn 13324: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 13325: }
13326: }
13327: }
13328: if (!$numconfig) {
1.372 raeburn 13329: $resulttext .= ' '.&mt('None');
1.273 raeburn 13330: }
13331: $resulttext .= '</li>';
1.267 raeburn 13332: foreach my $item ('passback','roster') {
13333: $resulttext .= '<li>'.$lt{$item}.' ';
13334: if ($confhash{$itemid}{$item}) {
13335: $resulttext .= &mt('Yes');
1.319 raeburn 13336: if ($confhash{$itemid}{$item.'valid'}) {
13337: if ($item eq 'passback') {
13338: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
13339: $confhash{$itemid}{$item.'valid'});
13340: } else {
13341: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
13342: $confhash{$itemid}{$item.'valid'});
13343: }
13344: }
1.267 raeburn 13345: } else {
13346: $resulttext .= &mt('No');
13347: }
13348: $resulttext .= '</li>';
13349: }
13350: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
13351: my $displaylist;
13352: if ($confhash{$itemid}{'display'}{'target'}) {
13353: $displaylist = &mt('Display target').': '.
13354: $confhash{$itemid}{'display'}{'target'}.',';
13355: }
13356: foreach my $size ('width','height') {
13357: if ($confhash{$itemid}{'display'}{$size}) {
13358: $displaylist .= (' 'x2).$lt{$size}.': '.
13359: $confhash{$itemid}{'display'}{$size}.',';
13360: }
13361: }
13362: if ($displaylist) {
13363: $displaylist =~ s/,$//;
13364: $resulttext .= '<li>'.$displaylist.'</li>';
13365: }
1.296 raeburn 13366: foreach my $item ('linktext','explanation') {
13367: if ($confhash{$itemid}{'display'}{$item}) {
13368: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
13369: }
13370: }
13371: }
1.267 raeburn 13372: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
13373: my $fieldlist;
13374: foreach my $field (@allfields) {
13375: if ($confhash{$itemid}{'fields'}{$field}) {
13376: $fieldlist .= (' 'x2).$lt{$field}.',';
13377: }
13378: }
13379: if ($fieldlist) {
13380: $fieldlist =~ s/,$//;
1.324 raeburn 13381: if ($confhash{$itemid}{'fields'}{'user'}) {
13382: if ($confhash{$itemid}{'incdom'}) {
13383: $fieldlist .= ' ('.&mt('username:domain').')';
13384: } else {
13385: $fieldlist .= ' ('.&mt('username').')';
13386: }
13387: }
1.267 raeburn 13388: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
13389: }
13390: }
13391: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
13392: my $rolemaps;
13393: foreach my $role (@courseroles) {
13394: if ($confhash{$itemid}{'roles'}{$role}) {
13395: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
13396: $confhash{$itemid}{'roles'}{$role}.',';
13397: }
13398: }
13399: if ($rolemaps) {
13400: $rolemaps =~ s/,$//;
13401: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
13402: }
13403: }
13404: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
13405: my $customlist;
13406: if (keys(%{$confhash{$itemid}{'custom'}})) {
13407: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
13408: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
13409: }
13410: }
13411: if ($customlist) {
1.317 raeburn 13412: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 13413: }
13414: }
13415: $resulttext .= '</ul></li>';
13416: }
13417: }
13418: $resulttext .= '</ul>';
13419: } else {
13420: $resulttext = &mt('No changes made.');
13421: }
13422: } else {
13423: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13424: }
13425: if ($errors) {
13426: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13427: $errors.'</ul>';
13428: }
13429: return $resulttext;
13430: }
13431:
13432: sub process_ltitools_image {
13433: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
13434: my $filename = $env{'form.'.$caller.'.filename'};
13435: my ($error,$url);
13436: my ($width,$height) = (21,21);
13437: if ($configuserok eq 'ok') {
13438: if ($switchserver) {
13439: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
13440: $switchserver);
13441: } elsif ($author_ok eq 'ok') {
13442: my ($result,$imageurl,$madethumb) =
13443: &publishlogo($r,'upload',$caller,$dom,$confname,
13444: "ltitools/$itemid/icon",$width,$height);
13445: if ($result eq 'ok') {
13446: if ($madethumb) {
13447: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
13448: my $imagethumb = "$path/tn-".$imagefile;
13449: $url = $imagethumb;
13450: } else {
13451: $url = $imageurl;
13452: }
13453: } else {
13454: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
13455: }
13456: } else {
13457: $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);
13458: }
13459: } else {
13460: $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);
13461: }
13462: return ($url,$error);
13463: }
13464:
13465: sub get_ltitools_id {
13466: my ($cdom,$title) = @_;
13467: # get lock on ltitools db
13468: my $lockhash = {
13469: lock => $env{'user.name'}.
13470: ':'.$env{'user.domain'},
13471: };
13472: my $tries = 0;
13473: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
13474: my ($id,$error);
13475:
13476: while (($gotlock ne 'ok') && ($tries<10)) {
13477: $tries ++;
13478: sleep (0.1);
13479: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
13480: }
13481: if ($gotlock eq 'ok') {
13482: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
13483: if ($currids{'lock'}) {
13484: delete($currids{'lock'});
13485: if (keys(%currids)) {
13486: my @curr = sort { $a <=> $b } keys(%currids);
13487: if ($curr[-1] =~ /^\d+$/) {
13488: $id = 1 + $curr[-1];
13489: }
13490: } else {
13491: $id = 1;
13492: }
13493: if ($id) {
13494: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
13495: $error = 'nostore';
13496: }
13497: } else {
13498: $error = 'nonumber';
13499: }
13500: }
13501: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
13502: } else {
13503: $error = 'nolock';
13504: }
13505: return ($id,$error);
13506: }
13507:
1.372 raeburn 13508: sub modify_proctoring {
13509: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
13510: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13511: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
13512: my $confname = $dom.'-domainconfig';
13513: my $servadm = $r->dir_config('lonAdmEMail');
13514: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
13515: my %providernames = &proctoring_providernames();
13516: my $maxnum = scalar(keys(%providernames));
13517:
13518: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
13519: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
13520: if (ref($requref) eq 'HASH') {
13521: %requserfields = %{$requref};
13522: }
13523: if (ref($opturef) eq 'HASH') {
13524: %optuserfields = %{$opturef};
13525: }
13526: if (ref($defref) eq 'HASH') {
13527: %defaults = %{$defref};
13528: }
13529: if (ref($extref) eq 'HASH') {
13530: %extended = %{$extref};
13531: }
13532: if (ref($crsref) eq 'HASH') {
13533: %crsconf = %{$crsref};
13534: }
13535: if (ref($rolesref) eq 'ARRAY') {
13536: @courseroles = @{$rolesref};
13537: }
13538: if (ref($ltiref) eq 'ARRAY') {
13539: @ltiroles = @{$ltiref};
13540: }
13541:
13542: if (ref($domconfig{$action}) eq 'HASH') {
13543: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
13544: if (@todeleteimages) {
13545: map { $imgdeletions{$_} = 1; } @todeleteimages;
13546: }
13547: }
13548: my %customadds;
13549: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
13550: if (@newcustom) {
13551: map { $customadds{$_} = 1; } @newcustom;
13552: }
13553: foreach my $provider (sort(keys(%providernames))) {
13554: $confhash{$provider} = {};
13555: my $pos = $env{'form.proctoring_pos_'.$provider};
13556: $pos =~ s/\D+//g;
13557: $allpos[$pos] = $provider;
13558: my (%current,%currentenc);
13559: my $showroles = 0;
13560: if (ref($domconfig{$action}) eq 'HASH') {
13561: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
13562: %current = %{$domconfig{$action}{$provider}};
13563: foreach my $item ('key','secret') {
13564: $currentenc{$item} = $current{$item};
13565: delete($current{$item});
13566: }
13567: }
13568: }
13569: if ($env{'form.proctoring_available_'.$provider}) {
13570: $confhash{$provider}{'available'} = 1;
13571: unless ($current{'available'}) {
13572: $changes{$provider} = 1;
13573: }
13574: } else {
13575: %{$confhash{$provider}} = %current;
13576: %{$encconfhash{$provider}} = %currentenc;
13577: $confhash{$provider}{'available'} = 0;
13578: if ($current{'available'}) {
13579: $changes{$provider} = 1;
13580: }
13581: }
13582: if ($confhash{$provider}{'available'}) {
13583: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
13584: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
13585: if ($field eq 'lifetime') {
13586: if ($possval =~ /^\d+$/) {
13587: $confhash{$provider}{$field} = $possval;
13588: }
13589: } elsif ($field eq 'version') {
13590: if ($possval =~ /^\d+\.\d+$/) {
13591: $confhash{$provider}{$field} = $possval;
13592: }
13593: } elsif ($field eq 'sigmethod') {
13594: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
13595: $confhash{$provider}{$field} = $possval;
13596: }
13597: } elsif ($field eq 'url') {
13598: $confhash{$provider}{$field} = $possval;
13599: } elsif (($field eq 'key') || ($field eq 'secret')) {
13600: $encconfhash{$provider}{$field} = $possval;
13601: unless ($currentenc{$field} eq $possval) {
13602: $changes{$provider} = 1;
13603: }
13604: }
13605: unless (($field eq 'key') || ($field eq 'secret')) {
13606: unless ($current{$field} eq $confhash{$provider}{$field}) {
13607: $changes{$provider} = 1;
13608: }
13609: }
13610: }
13611: if ($imgdeletions{$provider}) {
13612: $changes{$provider} = 1;
13613: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
13614: my ($imageurl,$error) =
13615: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
13616: $configuserok,$switchserver,$author_ok);
13617: if ($imageurl) {
13618: $confhash{$provider}{'image'} = $imageurl;
13619: $changes{$provider} = 1;
13620: }
13621: if ($error) {
13622: &Apache::lonnet::logthis($error);
13623: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13624: }
13625: } elsif (exists($current{'image'})) {
13626: $confhash{$provider}{'image'} = $current{'image'};
13627: }
13628: if (ref($requserfields{$provider}) eq 'ARRAY') {
13629: if (@{$requserfields{$provider}} > 0) {
13630: if (grep(/^user$/,@{$requserfields{$provider}})) {
13631: if ($env{'form.proctoring_userincdom_'.$provider}) {
13632: $confhash{$provider}{'incdom'} = 1;
13633: }
13634: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
13635: $changes{$provider} = 1;
13636: }
13637: }
13638: if (grep(/^roles$/,@{$requserfields{$provider}})) {
13639: $showroles = 1;
13640: }
13641: }
13642: }
13643: $confhash{$provider}{'fields'} = [];
13644: if (ref($optuserfields{$provider}) eq 'ARRAY') {
13645: if (@{$optuserfields{$provider}} > 0) {
13646: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
13647: foreach my $field (@{$optuserfields{$provider}}) {
13648: if (grep(/^\Q$field\E$/,@optfields)) {
13649: push(@{$confhash{$provider}{'fields'}},$field);
13650: }
13651: }
13652: }
13653: if (ref($current{'fields'}) eq 'ARRAY') {
13654: unless ($changes{$provider}) {
13655: my @new = sort(@{$confhash{$provider}{'fields'}});
13656: my @old = sort(@{$current{'fields'}});
13657: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
13658: if (@diffs) {
13659: $changes{$provider} = 1;
13660: }
13661: }
13662: } elsif (@{$confhash{$provider}{'fields'}}) {
13663: $changes{$provider} = 1;
13664: }
13665: }
13666: if (ref($defaults{$provider}) eq 'ARRAY') {
13667: if (@{$defaults{$provider}} > 0) {
13668: my %options;
13669: if (ref($extended{$provider}) eq 'HASH') {
13670: %options = %{$extended{$provider}};
13671: }
13672: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
13673: foreach my $field (@{$defaults{$provider}}) {
13674: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
13675: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
13676: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
13677: push(@{$confhash{$provider}{'defaults'}},$poss);
13678: }
13679: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
13680: foreach my $inner (keys(%{$options{$field}})) {
13681: if (ref($options{$field}{$inner}) eq 'ARRAY') {
13682: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
13683: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
13684: $confhash{$provider}{'defaults'}{$inner} = $poss;
13685: }
13686: } else {
13687: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
13688: }
13689: }
13690: } else {
13691: if (grep(/^\Q$field\E$/,@checked)) {
13692: push(@{$confhash{$provider}{'defaults'}},$field);
13693: }
13694: }
13695: }
13696: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
13697: if (ref($current{'defaults'}) eq 'ARRAY') {
13698: unless ($changes{$provider}) {
13699: my @new = sort(@{$confhash{$provider}{'defaults'}});
13700: my @old = sort(@{$current{'defaults'}});
13701: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
13702: if (@diffs) {
13703: $changes{$provider} = 1;
13704: }
13705: }
13706: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
13707: if (@{$current{'defaults'}}) {
13708: $changes{$provider} = 1;
13709: }
13710: }
13711: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
13712: if (ref($current{'defaults'}) eq 'HASH') {
13713: unless ($changes{$provider}) {
13714: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
13715: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
13716: $changes{$provider} = 1;
13717: last;
13718: }
13719: }
13720: }
13721: unless ($changes{$provider}) {
13722: foreach my $key (keys(%{$current{'defaults'}})) {
13723: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
13724: $changes{$provider} = 1;
13725: last;
13726: }
13727: }
13728: }
13729: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
13730: $changes{$provider} = 1;
13731: }
13732: }
13733: }
13734: }
13735: if (ref($crsconf{$provider}) eq 'ARRAY') {
13736: if (@{$crsconf{$provider}} > 0) {
13737: $confhash{$provider}{'crsconf'} = [];
13738: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
13739: foreach my $crsfield (@{$crsconf{$provider}}) {
13740: if (grep(/^\Q$crsfield\E$/,@checked)) {
13741: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
13742: }
13743: }
13744: if (ref($current{'crsconf'}) eq 'ARRAY') {
13745: unless ($changes{$provider}) {
13746: my @new = sort(@{$confhash{$provider}{'crsconf'}});
13747: my @old = sort(@{$current{'crsconf'}});
13748: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
13749: if (@diffs) {
13750: $changes{$provider} = 1;
13751: }
13752: }
13753: } elsif (@{$confhash{$provider}{'crsconf'}}) {
13754: $changes{$provider} = 1;
13755: }
13756: }
13757: }
13758: if ($showroles) {
13759: $confhash{$provider}{'roles'} = {};
13760: foreach my $role (@courseroles) {
13761: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
13762: if (grep(/^\Q$poss\E$/,@ltiroles)) {
13763: $confhash{$provider}{'roles'}{$role} = $poss;
13764: }
13765: }
13766: unless ($changes{$provider}) {
13767: if (ref($current{'roles'}) eq 'HASH') {
13768: foreach my $role (keys(%{$current{'roles'}})) {
13769: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
13770: $changes{$provider} = 1;
13771: last
13772: }
13773: }
13774: unless ($changes{$provider}) {
13775: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
13776: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
13777: $changes{$provider} = 1;
13778: last;
13779: }
13780: }
13781: }
13782: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
13783: $changes{$provider} = 1;
13784: }
13785: }
13786: }
13787: if (ref($current{'custom'}) eq 'HASH') {
13788: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
13789: foreach my $key (keys(%{$current{'custom'}})) {
13790: if (grep(/^\Q$key\E$/,@customdels)) {
13791: $changes{$provider} = 1;
13792: } else {
13793: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
13794: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
13795: $changes{$provider} = 1;
13796: }
13797: }
13798: }
13799: }
13800: if ($customadds{$provider}) {
13801: my $name = $env{'form.proctoring_custom_name_'.$provider};
13802: $name =~ s/(`)/'/g;
13803: $name =~ s/^\s+//;
13804: $name =~ s/\s+$//;
13805: my $value = $env{'form.proctoring_custom_value_'.$provider};
13806: $value =~ s/(`)/'/g;
13807: $value =~ s/^\s+//;
13808: $value =~ s/\s+$//;
13809: if ($name ne '') {
13810: $confhash{$provider}{'custom'}{$name} = $value;
13811: $changes{$provider} = 1;
13812: }
13813: }
13814: }
13815: }
13816: if (@allpos > 0) {
13817: my $idx = 0;
13818: foreach my $provider (@allpos) {
13819: if ($provider ne '') {
13820: $confhash{$provider}{'order'} = $idx;
13821: unless ($changes{$provider}) {
13822: if (ref($domconfig{$action}) eq 'HASH') {
13823: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
13824: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
13825: $changes{$provider} = 1;
13826: }
13827: }
13828: }
13829: }
13830: $idx ++;
13831: }
13832: }
13833: }
13834: my %proc_hash = (
13835: $action => { %confhash }
13836: );
13837: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
13838: $dom);
13839: if ($putresult eq 'ok') {
13840: my %proc_enchash = (
13841: $action => { %encconfhash }
13842: );
13843: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom);
13844: if (keys(%changes) > 0) {
13845: my $cachetime = 24*60*60;
13846: my %procall = %confhash;
13847: foreach my $provider (keys(%procall)) {
13848: if (ref($encconfhash{$provider}) eq 'HASH') {
13849: foreach my $key ('key','secret') {
13850: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
13851: }
13852: }
13853: }
13854: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
13855: if (ref($lastactref) eq 'HASH') {
13856: $lastactref->{'proctoring'} = 1;
13857: }
13858: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
13859: my %bynum;
13860: foreach my $provider (sort(keys(%changes))) {
13861: my $position = $confhash{$provider}{'order'};
13862: $bynum{$position} = $provider;
13863: }
13864: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13865: my $provider = $bynum{$pos};
13866: my %lt = &proctoring_titles($provider);
13867: my %fieldtitles = &proctoring_fieldtitles($provider);
13868: if (!$confhash{$provider}{'available'}) {
13869: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
13870: } else {
13871: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
13872: if ($confhash{$provider}{'image'}) {
13873: $resulttext .= ' '.
13874: '<img src="'.$confhash{$provider}{'image'}.'"'.
13875: ' alt="'.&mt('Proctoring icon').'" />';
13876: }
13877: $resulttext .= '<ul>';
13878: my $position = $pos + 1;
13879: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
13880: foreach my $key ('version','sigmethod','url','lifetime') {
13881: if ($confhash{$provider}{$key} ne '') {
13882: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
13883: }
13884: }
13885: if ($encconfhash{$provider}{'key'} ne '') {
13886: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
13887: }
13888: if ($encconfhash{$provider}{'secret'} ne '') {
13889: $resulttext .= '<li>'.$lt{'secret'}.': ';
13890: my $num = length($encconfhash{$provider}{'secret'});
13891: $resulttext .= ('*'x$num).'</li>';
13892: }
13893: my (@fields,$showroles);
13894: if (ref($requserfields{$provider}) eq 'ARRAY') {
13895: push(@fields,@{$requserfields{$provider}});
13896: }
13897: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
13898: push(@fields,@{$confhash{$provider}{'fields'}});
13899: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
13900: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
13901: }
13902: if (@fields) {
13903: if (grep(/^roles$/,@fields)) {
13904: $showroles = 1;
13905: }
13906: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
13907: join('", "', map { $lt{$_}; } @fields).'"</li>';
13908: }
13909: if (ref($requserfields{$provider}) eq 'ARRAY') {
13910: if (grep(/^user$/,@{$requserfields{$provider}})) {
13911: if ($confhash{$provider}{'incdom'}) {
13912: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
13913: } else {
13914: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
13915: }
13916: }
13917: }
13918: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
13919: if (@{$confhash{$provider}{'defaults'}} > 0) {
13920: $resulttext .= '<li>'.$lt{'defa'};
13921: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
13922: $resulttext .= ' "'.$fieldtitles{$field}.'",';
13923: }
13924: $resulttext =~ s/,$//;
13925: $resulttext .= '</li>';
13926: }
13927: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
13928: if (keys(%{$confhash{$provider}{'defaults'}})) {
13929: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
13930: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
13931: if ($confhash{$provider}{'defaults'}{$key} ne '') {
13932: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
13933: }
13934: }
13935: $resulttext .= '</ul></li>';
13936: }
13937: }
13938: if (ref($crsconf{$provider}) eq 'ARRAY') {
13939: if (@{$crsconf{$provider}} > 0) {
13940: $resulttext .= '<li>'.&mt('Configurable in course:');
13941: my $numconfig = 0;
13942: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
13943: if (@{$confhash{$provider}{'crsconf'}} > 0) {
13944: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
13945: $numconfig ++;
13946: if ($provider eq 'examity') {
13947: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
13948: } else {
13949: $resulttext .= ' "'.$fieldtitles{$field}.'",';
13950: }
13951: }
13952: $resulttext =~ s/,$//;
13953: }
13954: }
13955: if (!$numconfig) {
13956: $resulttext .= ' '.&mt('None');
13957: }
13958: $resulttext .= '</li>';
13959: }
13960: }
13961: if ($showroles) {
13962: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
13963: my $rolemaps;
13964: foreach my $role (@courseroles) {
13965: if ($confhash{$provider}{'roles'}{$role}) {
13966: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
13967: $confhash{$provider}{'roles'}{$role}.',';
13968: }
13969: }
13970: if ($rolemaps) {
13971: $rolemaps =~ s/,$//;
13972: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
13973: }
13974: }
13975: }
13976: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
13977: my $customlist;
13978: if (keys(%{$confhash{$provider}{'custom'}})) {
13979: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
13980: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
13981: }
13982: $customlist =~ s/,$//;
13983: }
13984: if ($customlist) {
13985: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
13986: }
13987: }
13988: $resulttext .= '</ul></li>';
13989: }
13990: }
13991: $resulttext .= '</ul>';
13992: } else {
13993: $resulttext = &mt('No changes made.');
13994: }
13995: } else {
13996: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13997: }
13998: if ($errors) {
13999: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14000: $errors.'</ul>';
14001: }
14002: return $resulttext;
14003: }
14004:
14005: sub process_proctoring_image {
14006: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
14007: my $filename = $env{'form.'.$caller.'.filename'};
14008: my ($error,$url);
14009: my ($width,$height) = (21,21);
14010: if ($configuserok eq 'ok') {
14011: if ($switchserver) {
14012: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
14013: $switchserver);
14014: } elsif ($author_ok eq 'ok') {
14015: my ($result,$imageurl,$madethumb) =
14016: &publishlogo($r,'upload',$caller,$dom,$confname,
14017: "proctoring/$provider/icon",$width,$height);
14018: if ($result eq 'ok') {
14019: if ($madethumb) {
14020: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
14021: my $imagethumb = "$path/tn-".$imagefile;
14022: $url = $imagethumb;
14023: } else {
14024: $url = $imageurl;
14025: }
14026: } else {
14027: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14028: }
14029: } else {
14030: $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);
14031: }
14032: } else {
14033: $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);
14034: }
14035: return ($url,$error);
14036: }
14037:
1.320 raeburn 14038: sub modify_lti {
14039: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
14040: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14041: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
14042: my (%posslti,%posslticrs,%posscrstype);
14043: my @courseroles = ('cc','in','ta','ep','st');
14044: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
14045: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
14046: my @coursetypes = ('official','unofficial','community','textbook','placement');
14047: my %coursetypetitles = &Apache::lonlocal::texthash (
14048: official => 'Official',
14049: unofficial => 'Unofficial',
14050: community => 'Community',
14051: textbook => 'Textbook',
14052: placement => 'Placement Test',
14053: );
1.325 raeburn 14054: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 14055: my %lt = <i_names();
14056: map { $posslti{$_} = 1; } @ltiroles;
14057: map { $posslticrs{$_} = 1; } @lticourseroles;
14058: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 14059:
1.326 raeburn 14060: my %menutitles = <imenu_titles();
14061:
1.320 raeburn 14062: my (@items,%deletions,%itemids);
14063: if ($env{'form.lti_add'}) {
14064: my $consumer = $env{'form.lti_consumer_add'};
14065: $consumer =~ s/(`)/'/g;
14066: ($newid,my $error) = &get_lti_id($dom,$consumer);
14067: if ($newid) {
14068: $itemids{'add'} = $newid;
14069: push(@items,'add');
14070: $changes{$newid} = 1;
14071: } else {
14072: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
14073: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14074: }
14075: }
14076: if (ref($domconfig{$action}) eq 'HASH') {
14077: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
14078: if (@todelete) {
14079: map { $deletions{$_} = 1; } @todelete;
14080: }
14081: my $maxnum = $env{'form.lti_maxnum'};
14082: for (my $i=0; $i<=$maxnum; $i++) {
14083: my $itemid = $env{'form.lti_id_'.$i};
14084: $itemid =~ s/\D+//g;
14085: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14086: if ($deletions{$itemid}) {
14087: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
14088: } else {
14089: push(@items,$i);
14090: $itemids{$i} = $itemid;
14091: }
14092: }
14093: }
14094: }
14095: foreach my $idx (@items) {
14096: my $itemid = $itemids{$idx};
14097: next unless ($itemid);
14098: my $position = $env{'form.lti_pos_'.$idx};
14099: $position =~ s/\D+//g;
14100: if ($position ne '') {
14101: $allpos[$position] = $itemid;
14102: }
1.345 raeburn 14103: foreach my $item ('consumer','key','secret','lifetime','requser') {
1.320 raeburn 14104: my $formitem = 'form.lti_'.$item.'_'.$idx;
14105: $env{$formitem} =~ s/(`)/'/g;
14106: if ($item eq 'lifetime') {
14107: $env{$formitem} =~ s/[^\d.]//g;
14108: }
14109: if ($env{$formitem} ne '') {
14110: if (($item eq 'key') || ($item eq 'secret')) {
14111: $encconfig{$itemid}{$item} = $env{$formitem};
14112: } else {
14113: $confhash{$itemid}{$item} = $env{$formitem};
14114: unless (($idx eq 'add') || ($changes{$itemid})) {
14115: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
14116: $changes{$itemid} = 1;
14117: }
14118: }
14119: }
14120: }
14121: }
14122: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
14123: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
14124: }
1.345 raeburn 14125: if ($confhash{$itemid}{'requser'}) {
14126: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
14127: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
14128: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
14129: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
14130: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
14131: my $mapuser = $env{'form.lti_customuser_'.$idx};
14132: $mapuser =~ s/(`)/'/g;
14133: $mapuser =~ s/^\s+|\s+$//g;
14134: $confhash{$itemid}{'mapuser'} = $mapuser;
14135: }
14136: foreach my $ltirole (@lticourseroles) {
14137: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
14138: if (grep(/^\Q$possrole\E$/,@courseroles)) {
14139: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
14140: }
14141: }
14142: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
14143: my @makeuser;
14144: foreach my $ltirole (sort(@possmakeuser)) {
14145: if ($posslti{$ltirole}) {
14146: push(@makeuser,$ltirole);
14147: }
14148: }
14149: $confhash{$itemid}{'makeuser'} = \@makeuser;
14150: if (@makeuser) {
14151: my $lcauth = $env{'form.lti_lcauth_'.$idx};
14152: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
14153: $confhash{$itemid}{'lcauth'} = $lcauth;
14154: if ($lcauth ne 'internal') {
14155: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
14156: $lcauthparm =~ s/^(\s+|\s+)$//g;
14157: $lcauthparm =~ s/`//g;
14158: if ($lcauthparm ne '') {
14159: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
14160: }
14161: }
14162: } else {
14163: $confhash{$itemid}{'lcauth'} = 'lti';
14164: }
1.320 raeburn 14165: }
1.345 raeburn 14166: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
14167: if (@possinstdata) {
14168: foreach my $field (@possinstdata) {
14169: if (exists($fieldtitles{$field})) {
14170: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 14171: }
14172: }
14173: }
1.345 raeburn 14174: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
14175: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
14176: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
14177: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
14178: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
14179: $mapcrs =~ s/(`)/'/g;
14180: $mapcrs =~ s/^\s+|\s+$//g;
14181: $confhash{$itemid}{'mapcrs'} = $mapcrs;
14182: }
14183: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
14184: my @crstypes;
14185: foreach my $type (sort(@posstypes)) {
14186: if ($posscrstype{$type}) {
14187: push(@crstypes,$type);
1.325 raeburn 14188: }
14189: }
1.345 raeburn 14190: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
14191: if ($env{'form.lti_makecrs_'.$idx}) {
14192: $confhash{$itemid}{'makecrs'} = 1;
1.320 raeburn 14193: }
1.345 raeburn 14194: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
14195: my @selfenroll;
14196: foreach my $type (sort(@possenroll)) {
14197: if ($posslticrs{$type}) {
14198: push(@selfenroll,$type);
14199: }
1.320 raeburn 14200: }
1.345 raeburn 14201: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
14202: if ($env{'form.lti_crssec_'.$idx}) {
14203: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
14204: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
14205: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
14206: my $section = $env{'form.lti_customsection_'.$idx};
14207: $section =~ s/(`)/'/g;
14208: $section =~ s/^\s+|\s+$//g;
14209: if ($section ne '') {
14210: $confhash{$itemid}{'section'} = $section;
14211: }
1.320 raeburn 14212: }
14213: }
1.363 raeburn 14214: if ($env{'form.lti_callback_'.$idx}) {
14215: if ($env{'form.lti_callbackparam_'.$idx}) {
14216: my $callback = $env{'form.lti_callbackparam_'.$idx};
14217: $callback =~ s/^\s+|\s+$//g;
14218: $confhash{$itemid}{'callback'} = $callback;
14219: }
14220: }
1.345 raeburn 14221: foreach my $field ('passback','roster','topmenu','inlinemenu') {
14222: if ($env{'form.lti_'.$field.'_'.$idx}) {
14223: $confhash{$itemid}{$field} = 1;
14224: }
1.320 raeburn 14225: }
1.345 raeburn 14226: if ($env{'form.lti_passback_'.$idx}) {
14227: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
14228: $confhash{$itemid}{'passbackformat'} = '1.0';
14229: } else {
14230: $confhash{$itemid}{'passbackformat'} = '1.1';
14231: }
1.337 raeburn 14232: }
1.345 raeburn 14233: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
14234: $confhash{$itemid}{lcmenu} = [];
14235: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
14236: foreach my $field (@possmenu) {
14237: if (exists($menutitles{$field})) {
14238: if ($field eq 'grades') {
14239: next unless ($env{'form.lti_inlinemenu_'.$idx});
14240: }
14241: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 14242: }
14243: }
14244: }
1.345 raeburn 14245: unless (($idx eq 'add') || ($changes{$itemid})) {
1.363 raeburn 14246: foreach my $field ('mapuser','mapcrs','makecrs','section','passback','roster','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
1.345 raeburn 14247: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.337 raeburn 14248: $changes{$itemid} = 1;
14249: }
14250: }
1.320 raeburn 14251: unless ($changes{$itemid}) {
1.345 raeburn 14252: if ($domconfig{$action}{$itemid}{'passback'} eq $confhash{$itemid}{'passback'}) {
14253: if ($domconfig{$action}{$itemid}{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 14254: $changes{$itemid} = 1;
14255: }
1.345 raeburn 14256: }
1.320 raeburn 14257: }
1.345 raeburn 14258: foreach my $field ('makeuser','mapcrstype','selfenroll','instdata','lcmenu') {
14259: unless ($changes{$itemid}) {
14260: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
14261: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
14262: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
14263: $confhash{$itemid}{$field});
14264: if (@diffs) {
14265: $changes{$itemid} = 1;
14266: }
14267: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
14268: $changes{$itemid} = 1;
14269: }
14270: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
14271: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 14272: $changes{$itemid} = 1;
14273: }
14274: }
1.345 raeburn 14275: }
14276: }
14277: unless ($changes{$itemid}) {
14278: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
14279: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
14280: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
14281: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
14282: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.320 raeburn 14283: $changes{$itemid} = 1;
14284: last;
14285: }
14286: }
1.345 raeburn 14287: unless ($changes{$itemid}) {
14288: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
14289: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
14290: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
14291: $changes{$itemid} = 1;
14292: last;
14293: }
14294: }
14295: }
14296: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
14297: $changes{$itemid} = 1;
1.320 raeburn 14298: }
1.345 raeburn 14299: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
14300: unless ($changes{$itemid}) {
14301: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
14302: $changes{$itemid} = 1;
14303: }
1.320 raeburn 14304: }
14305: }
14306: }
14307: }
14308: }
14309: }
14310: if (@allpos > 0) {
14311: my $idx = 0;
14312: foreach my $itemid (@allpos) {
14313: if ($itemid ne '') {
14314: $confhash{$itemid}{'order'} = $idx;
14315: if (ref($domconfig{$action}) eq 'HASH') {
14316: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14317: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
14318: $changes{$itemid} = 1;
14319: }
14320: }
14321: }
14322: $idx ++;
14323: }
14324: }
14325: }
14326: my %ltihash = (
14327: $action => { %confhash }
14328: );
14329: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
14330: $dom);
14331: if ($putresult eq 'ok') {
14332: my %ltienchash = (
14333: $action => { %encconfig }
14334: );
14335: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
14336: if (keys(%changes) > 0) {
14337: my $cachetime = 24*60*60;
14338: my %ltiall = %confhash;
14339: foreach my $id (keys(%ltiall)) {
14340: if (ref($encconfig{$id}) eq 'HASH') {
14341: foreach my $item ('key','secret') {
14342: $ltiall{$id}{$item} = $encconfig{$id}{$item};
14343: }
14344: }
14345: }
14346: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
14347: if (ref($lastactref) eq 'HASH') {
14348: $lastactref->{'lti'} = 1;
14349: }
14350: $resulttext = &mt('Changes made:').'<ul>';
14351: my %bynum;
14352: foreach my $itemid (sort(keys(%changes))) {
14353: my $position = $confhash{$itemid}{'order'};
14354: $bynum{$position} = $itemid;
14355: }
14356: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
14357: my $itemid = $bynum{$pos};
14358: if (ref($confhash{$itemid}) ne 'HASH') {
14359: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
14360: } else {
14361: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b></li><ul>';
14362: my $position = $pos + 1;
14363: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
14364: foreach my $item ('version','lifetime') {
14365: if ($confhash{$itemid}{$item} ne '') {
14366: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
14367: }
14368: }
14369: if ($encconfig{$itemid}{'key'} ne '') {
14370: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
14371: }
14372: if ($encconfig{$itemid}{'secret'} ne '') {
14373: $resulttext .= '<li>'.$lt{'secret'}.': ';
14374: my $num = length($encconfig{$itemid}{'secret'});
14375: $resulttext .= ('*'x$num).'</li>';
14376: }
1.345 raeburn 14377: if ($confhash{$itemid}{'requser'}) {
14378: if ($confhash{$itemid}{'mapuser'}) {
14379: my $shownmapuser;
14380: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
14381: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
14382: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
14383: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
14384: } else {
14385: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 14386: }
1.345 raeburn 14387: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 14388: }
1.345 raeburn 14389: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
14390: my $rolemaps;
14391: foreach my $role (@ltiroles) {
14392: if ($confhash{$itemid}{'maproles'}{$role}) {
14393: $rolemaps .= (' 'x2).$role.'='.
14394: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
14395: 'Course').',';
14396: }
14397: }
14398: if ($rolemaps) {
14399: $rolemaps =~ s/,$//;
14400: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
14401: }
14402: }
14403: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
14404: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
14405: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
14406: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
14407: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
14408: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
14409: } else {
14410: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
14411: $confhash{$itemid}{'lcauth'});
14412: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
14413: $resulttext .= '; '.&mt('a randomly generated password will be created');
14414: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
14415: if ($confhash{$itemid}{'lcauthparm'} ne '') {
14416: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
14417: }
14418: } else {
14419: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
14420: }
14421: }
14422: $resulttext .= '</li>';
14423: } else {
14424: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
14425: }
1.320 raeburn 14426: }
1.345 raeburn 14427: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
14428: if (@{$confhash{$itemid}{'instdata'}} > 0) {
14429: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
14430: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 14431: } else {
1.345 raeburn 14432: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 14433: }
1.320 raeburn 14434: }
1.345 raeburn 14435: if ($confhash{$itemid}{'mapcrs'}) {
14436: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
14437: }
14438: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
14439: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
14440: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
14441: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
14442: '</li>';
14443: } else {
14444: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
14445: }
1.325 raeburn 14446: }
1.345 raeburn 14447: if ($confhash{$itemid}{'makecrs'}) {
14448: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
1.320 raeburn 14449: } else {
1.345 raeburn 14450: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
1.320 raeburn 14451: }
1.345 raeburn 14452: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
14453: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
14454: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
14455: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
14456: '</li>';
14457: } else {
14458: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
14459: }
1.320 raeburn 14460: }
1.345 raeburn 14461: if ($confhash{$itemid}{'section'}) {
14462: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
14463: $resulttext .= '<li>'.&mt('User section from standard field:').
14464: ' (course_section_sourcedid)'.'</li>';
14465: } else {
14466: $resulttext .= '<li>'.&mt('User section from:').' '.
14467: $confhash{$itemid}{'section'}.'</li>';
14468: }
1.320 raeburn 14469: } else {
1.345 raeburn 14470: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
1.320 raeburn 14471: }
1.363 raeburn 14472: if ($confhash{$itemid}{'callback'}) {
14473: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
14474: } else {
14475: $resulttext .= '<li>'.&mt('No callback to logout LON-CAPA session when user logs out of Comsumer');
14476: }
1.345 raeburn 14477: foreach my $item ('passback','roster','topmenu','inlinemenu') {
14478: $resulttext .= '<li>'.$lt{$item}.': ';
14479: if ($confhash{$itemid}{$item}) {
14480: $resulttext .= &mt('Yes');
14481: if ($item eq 'passback') {
14482: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
14483: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
14484: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
14485: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
14486: }
1.337 raeburn 14487: }
1.345 raeburn 14488: } else {
14489: $resulttext .= &mt('No');
1.337 raeburn 14490: }
1.345 raeburn 14491: $resulttext .= '</li>';
1.320 raeburn 14492: }
1.345 raeburn 14493: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
14494: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
14495: $resulttext .= '<li>'.&mt('Menu items:').' '.
14496: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
14497: } else {
14498: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
14499: }
1.326 raeburn 14500: }
14501: }
1.320 raeburn 14502: $resulttext .= '</ul></li>';
14503: }
14504: }
14505: $resulttext .= '</ul>';
14506: } else {
14507: $resulttext = &mt('No changes made.');
14508: }
14509: } else {
14510: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14511: }
14512: if ($errors) {
14513: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14514: $errors.'</ul>';
14515: }
14516: return $resulttext;
14517: }
14518:
14519: sub get_lti_id {
14520: my ($domain,$consumer) = @_;
14521: # get lock on lti db
14522: my $lockhash = {
14523: lock => $env{'user.name'}.
14524: ':'.$env{'user.domain'},
14525: };
14526: my $tries = 0;
14527: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
14528: my ($id,$error);
14529:
14530: while (($gotlock ne 'ok') && ($tries<10)) {
14531: $tries ++;
14532: sleep (0.1);
14533: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
14534: }
14535: if ($gotlock eq 'ok') {
14536: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
14537: if ($currids{'lock'}) {
14538: delete($currids{'lock'});
14539: if (keys(%currids)) {
14540: my @curr = sort { $a <=> $b } keys(%currids);
14541: if ($curr[-1] =~ /^\d+$/) {
14542: $id = 1 + $curr[-1];
14543: }
14544: } else {
14545: $id = 1;
14546: }
14547: if ($id) {
14548: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
14549: $error = 'nostore';
14550: }
14551: } else {
14552: $error = 'nonumber';
14553: }
14554: }
14555: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
14556: } else {
14557: $error = 'nolock';
14558: }
14559: return ($id,$error);
14560: }
14561:
1.3 raeburn 14562: sub modify_autoenroll {
1.205 raeburn 14563: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 14564: my ($resulttext,%changes);
14565: my %currautoenroll;
14566: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
14567: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
14568: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
14569: }
14570: }
14571: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
14572: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 14573: sender => 'Sender for notification messages',
1.274 raeburn 14574: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
14575: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 14576: my @offon = ('off','on');
1.17 raeburn 14577: my $sender_uname = $env{'form.sender_uname'};
14578: my $sender_domain = $env{'form.sender_domain'};
14579: if ($sender_domain eq '') {
14580: $sender_uname = '';
14581: } elsif ($sender_uname eq '') {
14582: $sender_domain = '';
14583: }
1.129 raeburn 14584: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 14585: my $failsafe = $env{'form.autoenroll_failsafe'};
14586: $failsafe =~ s{^\s+|\s+$}{}g;
14587: if ($failsafe =~ /\D/) {
14588: undef($failsafe);
14589: }
1.1 raeburn 14590: my %autoenrollhash = (
1.129 raeburn 14591: autoenroll => { 'run' => $env{'form.autoenroll_run'},
14592: 'sender_uname' => $sender_uname,
14593: 'sender_domain' => $sender_domain,
14594: 'co-owners' => $coowners,
1.274 raeburn 14595: 'autofailsafe' => $failsafe,
1.1 raeburn 14596: }
14597: );
1.4 raeburn 14598: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
14599: $dom);
1.1 raeburn 14600: if ($putresult eq 'ok') {
14601: if (exists($currautoenroll{'run'})) {
14602: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
14603: $changes{'run'} = 1;
14604: }
14605: } elsif ($autorun) {
14606: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 14607: $changes{'run'} = 1;
1.1 raeburn 14608: }
14609: }
1.17 raeburn 14610: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 14611: $changes{'sender'} = 1;
14612: }
1.17 raeburn 14613: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 14614: $changes{'sender'} = 1;
14615: }
1.129 raeburn 14616: if ($currautoenroll{'co-owners'} ne '') {
14617: if ($currautoenroll{'co-owners'} ne $coowners) {
14618: $changes{'coowners'} = 1;
14619: }
14620: } elsif ($coowners) {
14621: $changes{'coowners'} = 1;
1.274 raeburn 14622: }
14623: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
14624: $changes{'autofailsafe'} = 1;
14625: }
1.1 raeburn 14626: if (keys(%changes) > 0) {
14627: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 14628: if ($changes{'run'}) {
1.1 raeburn 14629: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
14630: }
14631: if ($changes{'sender'}) {
1.17 raeburn 14632: if ($sender_uname eq '' || $sender_domain eq '') {
14633: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
14634: } else {
14635: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
14636: }
1.1 raeburn 14637: }
1.129 raeburn 14638: if ($changes{'coowners'}) {
14639: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
14640: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 14641: if (ref($lastactref) eq 'HASH') {
14642: $lastactref->{'domainconfig'} = 1;
14643: }
1.129 raeburn 14644: }
1.274 raeburn 14645: if ($changes{'autofailsafe'}) {
14646: if ($failsafe ne '') {
1.299 raeburn 14647: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 14648: } else {
1.299 raeburn 14649: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 14650: }
14651: &Apache::lonnet::get_domain_defaults($dom,1);
14652: if (ref($lastactref) eq 'HASH') {
14653: $lastactref->{'domdefaults'} = 1;
14654: }
14655: }
1.1 raeburn 14656: $resulttext .= '</ul>';
14657: } else {
14658: $resulttext = &mt('No changes made to auto-enrollment settings');
14659: }
14660: } else {
1.11 albertel 14661: $resulttext = '<span class="LC_error">'.
14662: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14663: }
1.3 raeburn 14664: return $resulttext;
1.1 raeburn 14665: }
14666:
14667: sub modify_autoupdate {
1.3 raeburn 14668: my ($dom,%domconfig) = @_;
1.1 raeburn 14669: my ($resulttext,%currautoupdate,%fields,%changes);
14670: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
14671: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
14672: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
14673: }
14674: }
14675: my @offon = ('off','on');
14676: my %title = &Apache::lonlocal::texthash (
14677: run => 'Auto-update:',
14678: classlists => 'Updates to user information in classlists?'
14679: );
1.44 raeburn 14680: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 14681: my %fieldtitles = &Apache::lonlocal::texthash (
14682: id => 'Student/Employee ID',
1.20 raeburn 14683: permanentemail => 'E-mail address',
1.1 raeburn 14684: lastname => 'Last Name',
14685: firstname => 'First Name',
14686: middlename => 'Middle Name',
1.132 raeburn 14687: generation => 'Generation',
1.1 raeburn 14688: );
1.142 raeburn 14689: $othertitle = &mt('All users');
1.1 raeburn 14690: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 14691: $othertitle = &mt('Other users');
1.1 raeburn 14692: }
14693: foreach my $key (keys(%env)) {
14694: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 14695: my ($usertype,$item) = ($1,$2);
14696: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
14697: if ($usertype eq 'default') {
14698: push(@{$fields{$1}},$2);
14699: } elsif (ref($types) eq 'ARRAY') {
14700: if (grep(/^\Q$usertype\E$/,@{$types})) {
14701: push(@{$fields{$1}},$2);
14702: }
14703: }
14704: }
1.1 raeburn 14705: }
14706: }
1.131 raeburn 14707: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
14708: @lockablenames = sort(@lockablenames);
14709: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
14710: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
14711: if (@changed) {
14712: $changes{'lockablenames'} = 1;
14713: }
14714: } else {
14715: if (@lockablenames) {
14716: $changes{'lockablenames'} = 1;
14717: }
14718: }
1.1 raeburn 14719: my %updatehash = (
14720: autoupdate => { run => $env{'form.autoupdate_run'},
14721: classlists => $env{'form.classlists'},
14722: fields => {%fields},
1.131 raeburn 14723: lockablenames => \@lockablenames,
1.1 raeburn 14724: }
14725: );
14726: foreach my $key (keys(%currautoupdate)) {
14727: if (($key eq 'run') || ($key eq 'classlists')) {
14728: if (exists($updatehash{autoupdate}{$key})) {
14729: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
14730: $changes{$key} = 1;
14731: }
14732: }
14733: } elsif ($key eq 'fields') {
14734: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 14735: foreach my $item (@{$types},'default') {
1.1 raeburn 14736: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
14737: my $change = 0;
14738: foreach my $type (@{$currautoupdate{$key}{$item}}) {
14739: if (!exists($fields{$item})) {
14740: $change = 1;
1.132 raeburn 14741: last;
1.1 raeburn 14742: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 14743: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 14744: $change = 1;
1.132 raeburn 14745: last;
1.1 raeburn 14746: }
14747: }
14748: }
14749: if ($change) {
14750: push(@{$changes{$key}},$item);
14751: }
1.26 raeburn 14752: }
1.1 raeburn 14753: }
14754: }
1.131 raeburn 14755: } elsif ($key eq 'lockablenames') {
14756: if (ref($currautoupdate{$key}) eq 'ARRAY') {
14757: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
14758: if (@changed) {
14759: $changes{'lockablenames'} = 1;
14760: }
14761: } else {
14762: if (@lockablenames) {
14763: $changes{'lockablenames'} = 1;
14764: }
14765: }
14766: }
14767: }
14768: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
14769: if (@lockablenames) {
14770: $changes{'lockablenames'} = 1;
1.1 raeburn 14771: }
14772: }
1.26 raeburn 14773: foreach my $item (@{$types},'default') {
14774: if (defined($fields{$item})) {
14775: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 14776: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
14777: my $change = 0;
14778: if (ref($fields{$item}) eq 'ARRAY') {
14779: foreach my $type (@{$fields{$item}}) {
14780: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
14781: $change = 1;
14782: last;
14783: }
14784: }
14785: }
14786: if ($change) {
14787: push(@{$changes{'fields'}},$item);
14788: }
14789: } else {
1.26 raeburn 14790: push(@{$changes{'fields'}},$item);
14791: }
14792: } else {
14793: push(@{$changes{'fields'}},$item);
1.1 raeburn 14794: }
14795: }
14796: }
14797: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
14798: $dom);
14799: if ($putresult eq 'ok') {
14800: if (keys(%changes) > 0) {
14801: $resulttext = &mt('Changes made:').'<ul>';
14802: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 14803: if ($key eq 'lockablenames') {
14804: $resulttext .= '<li>';
14805: if (@lockablenames) {
14806: $usertypes->{'default'} = $othertitle;
14807: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
14808: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
14809: } else {
14810: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
14811: }
14812: $resulttext .= '</li>';
14813: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 14814: foreach my $item (@{$changes{$key}}) {
14815: my @newvalues;
14816: foreach my $type (@{$fields{$item}}) {
14817: push(@newvalues,$fieldtitles{$type});
14818: }
1.3 raeburn 14819: my $newvaluestr;
14820: if (@newvalues > 0) {
14821: $newvaluestr = join(', ',@newvalues);
14822: } else {
14823: $newvaluestr = &mt('none');
1.6 raeburn 14824: }
1.1 raeburn 14825: if ($item eq 'default') {
1.26 raeburn 14826: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 14827: } else {
1.26 raeburn 14828: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 14829: }
14830: }
14831: } else {
14832: my $newvalue;
14833: if ($key eq 'run') {
14834: $newvalue = $offon[$env{'form.autoupdate_run'}];
14835: } else {
14836: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 14837: }
1.1 raeburn 14838: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
14839: }
14840: }
14841: $resulttext .= '</ul>';
14842: } else {
1.3 raeburn 14843: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 14844: }
14845: } else {
1.11 albertel 14846: $resulttext = '<span class="LC_error">'.
14847: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14848: }
1.3 raeburn 14849: return $resulttext;
1.1 raeburn 14850: }
14851:
1.125 raeburn 14852: sub modify_autocreate {
14853: my ($dom,%domconfig) = @_;
14854: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
14855: if (ref($domconfig{'autocreate'}) eq 'HASH') {
14856: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
14857: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
14858: }
14859: }
14860: my %title= ( xml => 'Auto-creation of courses in XML course description files',
14861: req => 'Auto-creation of validated requests for official courses',
14862: xmldc => 'Identity of course creator of courses from XML files',
14863: );
14864: my @types = ('xml','req');
14865: foreach my $item (@types) {
14866: $newvals{$item} = $env{'form.autocreate_'.$item};
14867: $newvals{$item} =~ s/\D//g;
14868: $newvals{$item} = 0 if ($newvals{$item} eq '');
14869: }
14870: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 14871: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 14872: unless (exists($domcoords{$newvals{'xmldc'}})) {
14873: $newvals{'xmldc'} = '';
14874: }
14875: %autocreatehash = (
14876: autocreate => { xml => $newvals{'xml'},
14877: req => $newvals{'req'},
14878: }
14879: );
14880: if ($newvals{'xmldc'} ne '') {
14881: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
14882: }
14883: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
14884: $dom);
14885: if ($putresult eq 'ok') {
14886: my @items = @types;
14887: if ($newvals{'xml'}) {
14888: push(@items,'xmldc');
14889: }
14890: foreach my $item (@items) {
14891: if (exists($currautocreate{$item})) {
14892: if ($currautocreate{$item} ne $newvals{$item}) {
14893: $changes{$item} = 1;
14894: }
14895: } elsif ($newvals{$item}) {
14896: $changes{$item} = 1;
14897: }
14898: }
14899: if (keys(%changes) > 0) {
14900: my @offon = ('off','on');
14901: $resulttext = &mt('Changes made:').'<ul>';
14902: foreach my $item (@types) {
14903: if ($changes{$item}) {
14904: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 14905: $resulttext .= '<li>'.
14906: &mt("$title{$item} set to [_1]$newtxt [_2]",
14907: '<b>','</b>').
14908: '</li>';
1.125 raeburn 14909: }
14910: }
14911: if ($changes{'xmldc'}) {
14912: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
14913: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 14914: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 14915: }
14916: $resulttext .= '</ul>';
14917: } else {
14918: $resulttext = &mt('No changes made to auto-creation settings');
14919: }
14920: } else {
14921: $resulttext = '<span class="LC_error">'.
14922: &mt('An error occurred: [_1]',$putresult).'</span>';
14923: }
14924: return $resulttext;
14925: }
14926:
1.23 raeburn 14927: sub modify_directorysrch {
1.295 raeburn 14928: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 14929: my ($resulttext,%changes);
14930: my %currdirsrch;
14931: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
14932: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
14933: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
14934: }
14935: }
1.277 raeburn 14936: my %title = ( available => 'Institutional directory search available',
14937: localonly => 'Other domains can search institution',
14938: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 14939: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 14940: searchby => 'Search types',
14941: searchtypes => 'Search latitude');
14942: my @offon = ('off','on');
1.24 raeburn 14943: my @otherdoms = ('Yes','No');
1.23 raeburn 14944:
1.25 raeburn 14945: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 14946: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
14947: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
14948:
1.44 raeburn 14949: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 14950: if (keys(%{$usertypes}) == 0) {
14951: @cansearch = ('default');
14952: } else {
14953: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
14954: foreach my $type (@{$currdirsrch{'cansearch'}}) {
14955: if (!grep(/^\Q$type\E$/,@cansearch)) {
14956: push(@{$changes{'cansearch'}},$type);
14957: }
1.23 raeburn 14958: }
1.26 raeburn 14959: foreach my $type (@cansearch) {
14960: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
14961: push(@{$changes{'cansearch'}},$type);
14962: }
1.23 raeburn 14963: }
1.26 raeburn 14964: } else {
14965: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 14966: }
14967: }
14968:
14969: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
14970: foreach my $by (@{$currdirsrch{'searchby'}}) {
14971: if (!grep(/^\Q$by\E$/,@searchby)) {
14972: push(@{$changes{'searchby'}},$by);
14973: }
14974: }
14975: foreach my $by (@searchby) {
14976: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
14977: push(@{$changes{'searchby'}},$by);
14978: }
14979: }
14980: } else {
14981: push(@{$changes{'searchby'}},@searchby);
14982: }
1.25 raeburn 14983:
14984: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
14985: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
14986: if (!grep(/^\Q$type\E$/,@searchtypes)) {
14987: push(@{$changes{'searchtypes'}},$type);
14988: }
14989: }
14990: foreach my $type (@searchtypes) {
14991: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
14992: push(@{$changes{'searchtypes'}},$type);
14993: }
14994: }
14995: } else {
14996: if (exists($currdirsrch{'searchtypes'})) {
14997: foreach my $type (@searchtypes) {
14998: if ($type ne $currdirsrch{'searchtypes'}) {
14999: push(@{$changes{'searchtypes'}},$type);
15000: }
15001: }
15002: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
15003: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
15004: }
15005: } else {
15006: push(@{$changes{'searchtypes'}},@searchtypes);
15007: }
15008: }
15009:
1.23 raeburn 15010: my %dirsrch_hash = (
15011: directorysrch => { available => $env{'form.dirsrch_available'},
15012: cansearch => \@cansearch,
1.277 raeburn 15013: localonly => $env{'form.dirsrch_instlocalonly'},
15014: lclocalonly => $env{'form.dirsrch_domlocalonly'},
15015: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 15016: searchby => \@searchby,
1.25 raeburn 15017: searchtypes => \@searchtypes,
1.23 raeburn 15018: }
15019: );
15020: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
15021: $dom);
15022: if ($putresult eq 'ok') {
15023: if (exists($currdirsrch{'available'})) {
15024: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
15025: $changes{'available'} = 1;
15026: }
15027: } else {
15028: if ($env{'form.dirsrch_available'} eq '1') {
15029: $changes{'available'} = 1;
15030: }
15031: }
1.277 raeburn 15032: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 15033: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
15034: $changes{'lcavailable'} = 1;
15035: }
1.277 raeburn 15036: } else {
15037: if ($env{'form.dirsrch_lcavailable'} eq '1') {
15038: $changes{'lcavailable'} = 1;
15039: }
15040: }
1.24 raeburn 15041: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 15042: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
15043: $changes{'localonly'} = 1;
15044: }
1.24 raeburn 15045: } else {
1.277 raeburn 15046: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 15047: $changes{'localonly'} = 1;
15048: }
15049: }
1.277 raeburn 15050: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 15051: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
15052: $changes{'lclocalonly'} = 1;
15053: }
1.277 raeburn 15054: } else {
15055: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
15056: $changes{'lclocalonly'} = 1;
15057: }
15058: }
1.23 raeburn 15059: if (keys(%changes) > 0) {
15060: $resulttext = &mt('Changes made:').'<ul>';
15061: if ($changes{'available'}) {
15062: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
15063: }
1.277 raeburn 15064: if ($changes{'lcavailable'}) {
15065: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
15066: }
1.24 raeburn 15067: if ($changes{'localonly'}) {
1.277 raeburn 15068: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 15069: }
1.277 raeburn 15070: if ($changes{'lclocalonly'}) {
15071: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 15072: }
1.23 raeburn 15073: if (ref($changes{'cansearch'}) eq 'ARRAY') {
15074: my $chgtext;
1.26 raeburn 15075: if (ref($usertypes) eq 'HASH') {
15076: if (keys(%{$usertypes}) > 0) {
15077: foreach my $type (@{$types}) {
15078: if (grep(/^\Q$type\E$/,@cansearch)) {
15079: $chgtext .= $usertypes->{$type}.'; ';
15080: }
15081: }
15082: if (grep(/^default$/,@cansearch)) {
15083: $chgtext .= $othertitle;
15084: } else {
15085: $chgtext =~ s/\; $//;
15086: }
1.210 raeburn 15087: $resulttext .=
1.178 raeburn 15088: '<li>'.
15089: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
15090: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
15091: '</li>';
1.23 raeburn 15092: }
15093: }
15094: }
15095: if (ref($changes{'searchby'}) eq 'ARRAY') {
15096: my ($searchtitles,$titleorder) = &sorted_searchtitles();
15097: my $chgtext;
15098: foreach my $type (@{$titleorder}) {
15099: if (grep(/^\Q$type\E$/,@searchby)) {
15100: if (defined($searchtitles->{$type})) {
15101: $chgtext .= $searchtitles->{$type}.'; ';
15102: }
15103: }
15104: }
15105: $chgtext =~ s/\; $//;
15106: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
15107: }
1.25 raeburn 15108: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
15109: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
15110: my $chgtext;
15111: foreach my $type (@{$srchtypeorder}) {
15112: if (grep(/^\Q$type\E$/,@searchtypes)) {
15113: if (defined($srchtypes_desc->{$type})) {
15114: $chgtext .= $srchtypes_desc->{$type}.'; ';
15115: }
15116: }
15117: }
15118: $chgtext =~ s/\; $//;
1.178 raeburn 15119: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 15120: }
15121: $resulttext .= '</ul>';
1.295 raeburn 15122: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
15123: if (ref($lastactref) eq 'HASH') {
15124: $lastactref->{'directorysrch'} = 1;
15125: }
1.23 raeburn 15126: } else {
1.277 raeburn 15127: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 15128: }
15129: } else {
15130: $resulttext = '<span class="LC_error">'.
1.27 raeburn 15131: &mt('An error occurred: [_1]',$putresult).'</span>';
15132: }
15133: return $resulttext;
15134: }
15135:
1.28 raeburn 15136: sub modify_contacts {
1.205 raeburn 15137: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 15138: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
15139: if (ref($domconfig{'contacts'}) eq 'HASH') {
15140: foreach my $key (keys(%{$domconfig{'contacts'}})) {
15141: $currsetting{$key} = $domconfig{'contacts'}{$key};
15142: }
15143: }
1.286 raeburn 15144: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 15145: my @contacts = ('supportemail','adminemail');
1.286 raeburn 15146: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 15147: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 15148: my @toggles = ('reporterrors','reportupdates','reportstatus');
15149: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 15150: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 15151: foreach my $type (@mailings) {
15152: @{$newsetting{$type}} =
15153: &Apache::loncommon::get_env_multiple('form.'.$type);
15154: foreach my $item (@contacts) {
15155: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
15156: $contacts_hash{contacts}{$type}{$item} = 1;
15157: } else {
15158: $contacts_hash{contacts}{$type}{$item} = 0;
15159: }
1.289 raeburn 15160: }
1.28 raeburn 15161: $others{$type} = $env{'form.'.$type.'_others'};
15162: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 15163: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15164: $bcc{$type} = $env{'form.'.$type.'_bcc'};
15165: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 15166: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
15167: $includestr{$type} = $env{'form.'.$type.'_includestr'};
15168: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
15169: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
15170: }
1.134 raeburn 15171: }
1.28 raeburn 15172: }
15173: foreach my $item (@contacts) {
15174: $to{$item} = $env{'form.'.$item};
15175: $contacts_hash{'contacts'}{$item} = $to{$item};
15176: }
1.203 raeburn 15177: foreach my $item (@toggles) {
15178: if ($env{'form.'.$item} =~ /^(0|1)$/) {
15179: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
15180: }
15181: }
1.340 raeburn 15182: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
15183: foreach my $item (@lonstatus) {
15184: if ($item eq 'excluded') {
15185: my (%serverhomes,@excluded);
15186: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
15187: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
15188: if (@possexcluded) {
15189: foreach my $id (sort(@possexcluded)) {
15190: if ($serverhomes{$id}) {
15191: push(@excluded,$id);
15192: }
15193: }
15194: }
15195: if (@excluded) {
15196: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
15197: }
15198: } elsif ($item eq 'weights') {
15199: foreach my $type ('E','W','N') {
15200: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
15201: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
15202: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
15203: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
15204: $env{'form.error'.$item.'_'.$type};
15205: }
15206: }
15207: }
15208: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
15209: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
15210: if ($env{'form.error'.$item} =~ /^\d+$/) {
15211: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
15212: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
15213: }
15214: }
15215: }
15216: }
1.286 raeburn 15217: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
15218: foreach my $field (@{$fields}) {
15219: if (ref($possoptions->{$field}) eq 'ARRAY') {
15220: my $value = $env{'form.helpform_'.$field};
15221: $value =~ s/^\s+|\s+$//g;
15222: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 15223: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 15224: if ($field eq 'screenshot') {
15225: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
15226: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 15227: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 15228: }
15229: }
15230: }
15231: }
15232: }
15233: }
1.315 raeburn 15234: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
15235: my (@statuses,%usertypeshash,@overrides);
15236: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
15237: @statuses = @{$types};
15238: if (ref($usertypes) eq 'HASH') {
15239: %usertypeshash = %{$usertypes};
15240: }
15241: }
15242: if (@statuses) {
15243: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
15244: foreach my $type (@possoverrides) {
15245: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
15246: push(@overrides,$type);
15247: }
15248: }
15249: if (@overrides) {
15250: foreach my $type (@overrides) {
15251: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
15252: foreach my $item (@contacts) {
15253: if (grep(/^\Q$item\E$/,@standard)) {
15254: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
15255: $newsetting{'override_'.$type}{$item} = 1;
15256: } else {
15257: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
15258: $newsetting{'override_'.$type}{$item} = 0;
15259: }
15260: }
15261: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
15262: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
15263: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
15264: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
15265: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
15266: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
15267: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
15268: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
15269: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
15270: }
15271: }
15272: }
15273: }
1.28 raeburn 15274: if (keys(%currsetting) > 0) {
15275: foreach my $item (@contacts) {
15276: if ($to{$item} ne $currsetting{$item}) {
15277: $changes{$item} = 1;
15278: }
15279: }
15280: foreach my $type (@mailings) {
15281: foreach my $item (@contacts) {
15282: if (ref($currsetting{$type}) eq 'HASH') {
15283: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
15284: push(@{$changes{$type}},$item);
15285: }
15286: } else {
15287: push(@{$changes{$type}},@{$newsetting{$type}});
15288: }
15289: }
15290: if ($others{$type} ne $currsetting{$type}{'others'}) {
15291: push(@{$changes{$type}},'others');
15292: }
1.289 raeburn 15293: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15294: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
15295: push(@{$changes{$type}},'bcc');
15296: }
1.286 raeburn 15297: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
15298: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
15299: push(@{$changes{$type}},'include');
15300: }
15301: }
15302: }
15303: if (ref($fields) eq 'ARRAY') {
15304: if (ref($currsetting{'helpform'}) eq 'HASH') {
15305: foreach my $field (@{$fields}) {
15306: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
15307: push(@{$changes{'helpform'}},$field);
15308: }
15309: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
15310: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
15311: push(@{$changes{'helpform'}},'maxsize');
15312: }
15313: }
15314: }
15315: } else {
15316: foreach my $field (@{$fields}) {
15317: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
15318: push(@{$changes{'helpform'}},$field);
15319: }
15320: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
15321: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
15322: push(@{$changes{'helpform'}},'maxsize');
15323: }
15324: }
15325: }
1.134 raeburn 15326: }
1.28 raeburn 15327: }
1.315 raeburn 15328: if (@statuses) {
15329: if (ref($currsetting{'overrides'}) eq 'HASH') {
15330: foreach my $key (keys(%{$currsetting{'overrides'}})) {
15331: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
15332: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
15333: foreach my $item (@contacts,'bcc','others','include') {
15334: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
15335: push(@{$changes{'overrides'}},$key);
15336: last;
15337: }
15338: }
15339: } else {
15340: push(@{$changes{'overrides'}},$key);
15341: }
15342: }
15343: }
15344: foreach my $key (@overrides) {
15345: unless (exists($currsetting{'overrides'}{$key})) {
15346: push(@{$changes{'overrides'}},$key);
15347: }
15348: }
15349: } else {
15350: foreach my $key (@overrides) {
15351: push(@{$changes{'overrides'}},$key);
15352: }
15353: }
15354: }
1.340 raeburn 15355: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
15356: foreach my $key ('excluded','weights','threshold','sysmail') {
15357: if ($key eq 'excluded') {
15358: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
15359: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
15360: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
15361: (@{$currsetting{'lonstatus'}{$key}})) {
15362: my @diffs =
15363: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
15364: $currsetting{'lonstatus'}{$key});
15365: if (@diffs) {
15366: push(@{$changes{'lonstatus'}},$key);
15367: }
15368: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
15369: push(@{$changes{'lonstatus'}},$key);
15370: }
15371: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
15372: (@{$currsetting{'lonstatus'}{$key}})) {
15373: push(@{$changes{'lonstatus'}},$key);
15374: }
15375: } elsif ($key eq 'weights') {
15376: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
15377: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
15378: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 15379: foreach my $type ('E','W','N','U') {
1.340 raeburn 15380: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
15381: $currsetting{'lonstatus'}{$key}{$type}) {
15382: push(@{$changes{'lonstatus'}},$key);
15383: last;
15384: }
15385: }
15386: } else {
1.341 raeburn 15387: foreach my $type ('E','W','N','U') {
1.340 raeburn 15388: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
15389: push(@{$changes{'lonstatus'}},$key);
15390: last;
15391: }
15392: }
15393: }
15394: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 15395: foreach my $type ('E','W','N','U') {
1.340 raeburn 15396: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
15397: push(@{$changes{'lonstatus'}},$key);
15398: last;
15399: }
15400: }
15401: }
15402: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
15403: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
15404: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
15405: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
15406: push(@{$changes{'lonstatus'}},$key);
15407: }
15408: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
15409: push(@{$changes{'lonstatus'}},$key);
15410: }
15411: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
15412: push(@{$changes{'lonstatus'}},$key);
15413: }
15414: }
15415: }
15416: } else {
15417: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
15418: foreach my $key ('excluded','weights','threshold','sysmail') {
15419: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
15420: push(@{$changes{'lonstatus'}},$key);
15421: }
15422: }
15423: }
15424: }
1.28 raeburn 15425: } else {
15426: my %default;
15427: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
15428: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
15429: $default{'errormail'} = 'adminemail';
15430: $default{'packagesmail'} = 'adminemail';
15431: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 15432: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 15433: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 15434: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 15435: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 15436: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 15437: foreach my $item (@contacts) {
15438: if ($to{$item} ne $default{$item}) {
1.286 raeburn 15439: $changes{$item} = 1;
1.203 raeburn 15440: }
1.28 raeburn 15441: }
15442: foreach my $type (@mailings) {
15443: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
15444: push(@{$changes{$type}},@{$newsetting{$type}});
15445: }
15446: if ($others{$type} ne '') {
15447: push(@{$changes{$type}},'others');
1.134 raeburn 15448: }
1.286 raeburn 15449: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15450: if ($bcc{$type} ne '') {
15451: push(@{$changes{$type}},'bcc');
15452: }
1.286 raeburn 15453: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
15454: push(@{$changes{$type}},'include');
15455: }
1.134 raeburn 15456: }
1.28 raeburn 15457: }
1.286 raeburn 15458: if (ref($fields) eq 'ARRAY') {
15459: foreach my $field (@{$fields}) {
15460: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
15461: push(@{$changes{'helpform'}},$field);
15462: }
15463: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
15464: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
15465: push(@{$changes{'helpform'}},'maxsize');
15466: }
15467: }
15468: }
1.289 raeburn 15469: }
1.340 raeburn 15470: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
15471: foreach my $key ('excluded','weights','threshold','sysmail') {
15472: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
15473: push(@{$changes{'lonstatus'}},$key);
15474: }
15475: }
15476: }
1.28 raeburn 15477: }
1.203 raeburn 15478: foreach my $item (@toggles) {
15479: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
15480: $changes{$item} = 1;
15481: } elsif ((!$env{'form.'.$item}) &&
15482: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
15483: $changes{$item} = 1;
15484: }
15485: }
1.28 raeburn 15486: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
15487: $dom);
15488: if ($putresult eq 'ok') {
15489: if (keys(%changes) > 0) {
1.205 raeburn 15490: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 15491: if (ref($lastactref) eq 'HASH') {
15492: $lastactref->{'domainconfig'} = 1;
15493: }
1.28 raeburn 15494: my ($titles,$short_titles) = &contact_titles();
15495: $resulttext = &mt('Changes made:').'<ul>';
15496: foreach my $item (@contacts) {
15497: if ($changes{$item}) {
15498: $resulttext .= '<li>'.$titles->{$item}.
15499: &mt(' set to: ').
15500: '<span class="LC_cusr_emph">'.
15501: $to{$item}.'</span></li>';
15502: }
15503: }
15504: foreach my $type (@mailings) {
15505: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 15506: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 15507: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 15508: } else {
15509: $resulttext .= '<li>'.$titles->{$type}.': ';
15510: }
1.28 raeburn 15511: my @text;
15512: foreach my $item (@{$newsetting{$type}}) {
15513: push(@text,$short_titles->{$item});
15514: }
15515: if ($others{$type} ne '') {
15516: push(@text,$others{$type});
15517: }
1.286 raeburn 15518: if (@text) {
15519: $resulttext .= '<span class="LC_cusr_emph">'.
15520: join(', ',@text).'</span>';
15521: }
15522: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15523: if ($bcc{$type} ne '') {
1.286 raeburn 15524: my $bcctext;
15525: if (@text) {
1.289 raeburn 15526: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 15527: } else {
15528: $bcctext = '(Bcc)';
15529: }
15530: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
15531: } elsif (!@text) {
15532: $resulttext .= &mt('No one');
15533: }
1.289 raeburn 15534: if ($includestr{$type} ne '') {
1.286 raeburn 15535: if ($includeloc{$type} eq 'b') {
15536: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
15537: } elsif ($includeloc{$type} eq 's') {
15538: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
15539: }
1.134 raeburn 15540: }
1.286 raeburn 15541: } elsif (!@text) {
15542: $resulttext .= &mt('No recipients');
1.134 raeburn 15543: }
15544: $resulttext .= '</li>';
1.28 raeburn 15545: }
15546: }
1.315 raeburn 15547: if (ref($changes{'overrides'}) eq 'ARRAY') {
15548: my @deletions;
15549: foreach my $type (@{$changes{'overrides'}}) {
15550: if ($usertypeshash{$type}) {
15551: if (grep(/^\Q$type\E/,@overrides)) {
15552: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
15553: $usertypeshash{$type}).'<ul><li>';
15554: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
15555: my @text;
15556: foreach my $item (@contacts) {
15557: if ($newsetting{'override_'.$type}{$item}) {
15558: push(@text,$short_titles->{$item});
15559: }
15560: }
15561: if ($newsetting{'override_'.$type}{'others'} ne '') {
15562: push(@text,$newsetting{'override_'.$type}{'others'});
15563: }
15564:
15565: if (@text) {
15566: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
15567: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
15568: }
15569: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
15570: my $bcctext;
15571: if (@text) {
15572: $bcctext = ' '.&mt('with Bcc to');
15573: } else {
15574: $bcctext = '(Bcc)';
15575: }
15576: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
15577: } elsif (!@text) {
15578: $resulttext .= &mt('Helpdesk e-mail sent to no one');
15579: }
15580: $resulttext .= '</li>';
15581: if ($newsetting{'override_'.$type}{'include'} ne '') {
15582: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
15583: if ($loc eq 'b') {
15584: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
15585: } elsif ($loc eq 's') {
15586: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
15587: }
15588: }
15589: }
15590: $resulttext .= '</li></ul></li>';
15591: } else {
15592: push(@deletions,$usertypeshash{$type});
15593: }
15594: }
15595: }
15596: if (@deletions) {
15597: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
15598: join(', ',@deletions)).'</li>';
15599: }
15600: }
1.203 raeburn 15601: my @offon = ('off','on');
1.340 raeburn 15602: my $corelink = &core_link_msu();
1.203 raeburn 15603: if ($changes{'reporterrors'}) {
15604: $resulttext .= '<li>'.
15605: &mt('E-mail error reports to [_1] set to "'.
15606: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 15607: $corelink).
1.203 raeburn 15608: '</li>';
15609: }
15610: if ($changes{'reportupdates'}) {
15611: $resulttext .= '<li>'.
15612: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
15613: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 15614: $corelink).
1.203 raeburn 15615: '</li>';
15616: }
1.340 raeburn 15617: if ($changes{'reportstatus'}) {
15618: $resulttext .= '<li>'.
15619: &mt('E-mail status if errors above threshold to [_1] set to "'.
15620: $offon[$env{'form.reportstatus'}].'".',
15621: $corelink).
15622: '</li>';
15623: }
15624: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
15625: $resulttext .= '<li>'.
15626: &mt('Nightly status check e-mail settings').':<ul>';
15627: my (%defval,%use_def,%shown);
15628: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
15629: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
15630: $defval{'weights'} =
1.341 raeburn 15631: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 15632: $defval{'excluded'} = &mt('None');
15633: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
15634: foreach my $item ('threshold','sysmail','weights','excluded') {
15635: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
15636: if (($item eq 'threshold') || ($item eq 'sysmail')) {
15637: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
15638: } elsif ($item eq 'weights') {
15639: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 15640: foreach my $type ('E','W','N','U') {
1.340 raeburn 15641: $shown{$item} .= $lonstatus_names->{$type}.'=';
15642: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
15643: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
15644: } else {
15645: $shown{$item} .= $lonstatus_defs->{$type};
15646: }
15647: $shown{$item} .= ', ';
15648: }
15649: $shown{$item} =~ s/, $//;
15650: } else {
15651: $shown{$item} = $defval{$item};
15652: }
15653: } elsif ($item eq 'excluded') {
15654: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
15655: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
15656: } else {
15657: $shown{$item} = $defval{$item};
15658: }
15659: }
15660: } else {
15661: $shown{$item} = $defval{$item};
15662: }
15663: }
15664: } else {
15665: foreach my $item ('threshold','weights','excluded','sysmail') {
15666: $shown{$item} = $defval{$item};
15667: }
15668: }
15669: foreach my $item ('threshold','weights','excluded','sysmail') {
15670: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
15671: $shown{$item}).'</li>';
15672: }
15673: $resulttext .= '</ul></li>';
15674: }
1.286 raeburn 15675: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
15676: my (@optional,@required,@unused,$maxsizechg);
15677: foreach my $field (@{$changes{'helpform'}}) {
15678: if ($field eq 'maxsize') {
15679: $maxsizechg = 1;
15680: next;
15681: }
15682: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 15683: push(@optional,$field);
1.286 raeburn 15684: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
15685: push(@unused,$field);
15686: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 15687: push(@required,$field);
1.286 raeburn 15688: }
15689: }
15690: if (@optional) {
15691: $resulttext .= '<li>'.
15692: &mt('Help form fields changed to "Optional": [_1].',
15693: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
15694: '</li>';
15695: }
15696: if (@required) {
15697: $resulttext .= '<li>'.
15698: &mt('Help form fields changed to "Required": [_1].',
15699: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
15700: '</li>';
15701: }
15702: if (@unused) {
15703: $resulttext .= '<li>'.
15704: &mt('Help form fields changed to "Not shown": [_1].',
15705: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
15706: '</li>';
15707: }
15708: if ($maxsizechg) {
15709: $resulttext .= '<li>'.
15710: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
15711: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
15712: '</li>';
15713: }
15714: }
1.28 raeburn 15715: $resulttext .= '</ul>';
15716: } else {
1.288 raeburn 15717: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 15718: }
15719: } else {
15720: $resulttext = '<span class="LC_error">'.
15721: &mt('An error occurred: [_1].',$putresult).'</span>';
15722: }
15723: return $resulttext;
15724: }
15725:
1.357 raeburn 15726: sub modify_privacy {
15727: my ($dom,%domconfig) = @_;
15728: my ($resulttext,%current,%changes);
15729: if (ref($domconfig{'privacy'}) eq 'HASH') {
15730: %current = %{$domconfig{'privacy'}};
15731: }
15732: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
15733: my @items = ('domain','author','course','community');
15734: my %names = &Apache::lonlocal::texthash (
15735: domain => 'Assigned domain role(s)',
15736: author => 'Assigned co-author role(s)',
15737: course => 'Assigned course role(s)',
15738: community => 'Assigned community role',
15739: );
15740: my %roles = &Apache::lonlocal::texthash (
15741: domain => 'Domain role',
15742: author => 'Co-author role',
15743: course => 'Course role',
15744: community => 'Community role',
15745: );
15746: my %titles = &Apache::lonlocal::texthash (
15747: approval => 'Approval for role in different domain',
15748: othdom => 'User information available in other domain',
15749: priv => 'Information viewable by privileged user in same domain',
15750: unpriv => 'Information viewable by unprivileged user in same domain',
15751: instdom => 'Other domain shares institution/provider',
15752: extdom => 'Other domain has different institution/provider',
15753: none => 'Not allowed',
15754: user => 'User authorizes',
15755: domain => 'Domain Coordinator authorizes',
15756: auto => 'Unrestricted',
15757: );
15758: my %fieldnames = &Apache::lonlocal::texthash (
15759: id => 'Student/Employee ID',
15760: permanentemail => 'E-mail address',
15761: lastname => 'Last Name',
15762: firstname => 'First Name',
15763: middlename => 'Middle Name',
15764: generation => 'Generation',
15765: );
15766: my ($othertitle,$usertypes,$types) =
15767: &Apache::loncommon::sorted_inst_types($dom);
15768: my (%by_ip,%by_location,@intdoms,@instdoms);
15769: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
15770:
15771: my %privacyhash = (
15772: 'approval' => {
15773: instdom => {},
15774: extdom => {},
15775: },
15776: 'othdom' => {},
15777: 'priv' => {},
15778: 'unpriv' => {},
15779: );
15780: foreach my $item (@items) {
15781: if (@instdoms > 1) {
15782: if ($env{'form.privacy_approval_instdom'.$item} =~ /^(none|user|domain|auto)$/) {
15783: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
15784: }
15785: if (ref($current{'approval'}) eq 'HASH') {
15786: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
15787: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
15788: $changes{'approval'} = 1;
15789: }
15790: }
15791: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
15792: $changes{'approval'} = 1;
15793: }
15794: }
15795: if (keys(%by_location) > 0) {
15796: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
15797: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
15798: }
15799: if (ref($current{'approval'}) eq 'HASH') {
15800: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
15801: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
15802: $changes{'approval'} = 1;
15803: }
15804: }
15805: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
15806: $changes{'approval'} = 1;
15807: }
15808: }
15809: foreach my $status ('priv','unpriv') {
15810: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
15811: my @newvalues;
15812: foreach my $field (@possibles) {
15813: if (grep(/^\Q$field\E$/,@fields)) {
15814: $privacyhash{$status}{$item}{$field} = 1;
15815: push(@newvalues,$field);
15816: }
15817: }
15818: @newvalues = sort(@newvalues);
15819: if (ref($current{$status}) eq 'HASH') {
15820: if (ref($current{$status}{$item}) eq 'HASH') {
15821: my @currvalues = sort(keys(%{$current{$status}{$item}}));
15822: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
15823: if (@diffs > 0) {
15824: $changes{$status} = 1;
15825: }
15826: }
15827: } else {
15828: my @stdfields;
15829: foreach my $field (@fields) {
15830: if ($field eq 'id') {
15831: next if ($status eq 'unpriv');
15832: next if (($status eq 'priv') && ($item eq 'community'));
15833: }
15834: push(@stdfields,$field);
15835: }
15836: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
15837: if (@diffs > 0) {
15838: $changes{$status} = 1;
15839: }
15840: }
15841: }
15842: }
15843: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
15844: my @statuses;
15845: if (ref($types) eq 'ARRAY') {
15846: @statuses = @{$types};
15847: }
15848: foreach my $type (@statuses,'default') {
15849: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
15850: my @newvalues;
15851: foreach my $field (sort(@possfields)) {
15852: if (grep(/^\Q$field\E$/,@fields)) {
15853: $privacyhash{'othdom'}{$type}{$field} = 1;
15854: push(@newvalues,$field);
15855: }
15856: }
15857: @newvalues = sort(@newvalues);
15858: if (ref($current{'othdom'}) eq 'HASH') {
15859: if (ref($current{'othdom'}{$type}) eq 'HASH') {
15860: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
15861: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
15862: if (@diffs > 0) {
15863: $changes{'othdom'} = 1;
15864: }
15865: }
15866: } else {
15867: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
15868: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
15869: if (@diffs > 0) {
15870: $changes{'othdom'} = 1;
15871: }
15872: }
15873: }
15874: }
15875: my %confighash = (
15876: privacy => \%privacyhash,
15877: );
15878: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
15879: if ($putresult eq 'ok') {
15880: if (keys(%changes) > 0) {
15881: $resulttext = &mt('Changes made: ').'<ul>';
15882: foreach my $key ('approval','othdom','priv','unpriv') {
15883: if ($changes{$key}) {
15884: $resulttext .= '<li>'.$titles{$key}.':<ul>';
15885: if ($key eq 'approval') {
15886: if (keys(%{$privacyhash{$key}{instdom}})) {
15887: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
15888: foreach my $item (@items) {
15889: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
15890: }
15891: $resulttext .= '</ul></li>';
15892: }
15893: if (keys(%{$privacyhash{$key}{extdom}})) {
15894: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
15895: foreach my $item (@items) {
15896: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
15897: }
15898: $resulttext .= '</ul></li>';
15899: }
15900: } elsif ($key eq 'othdom') {
15901: my @statuses;
15902: if (ref($types) eq 'ARRAY') {
15903: @statuses = @{$types};
15904: }
15905: if (ref($privacyhash{$key}) eq 'HASH') {
15906: foreach my $status (@statuses,'default') {
15907: if ($status eq 'default') {
15908: $resulttext .= '<li>'.$othertitle.': ';
15909: } elsif (ref($usertypes) eq 'HASH') {
15910: $resulttext .= '<li>'.$usertypes->{$status}.': ';
15911: } else {
15912: next;
15913: }
15914: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
15915: if (keys(%{$privacyhash{$key}{$status}})) {
15916: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
15917: } else {
15918: $resulttext .= &mt('none');
15919: }
15920: }
15921: $resulttext .= '</li>';
15922: }
15923: }
15924: } else {
15925: foreach my $item (@items) {
15926: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
15927: $resulttext .= '<li>'.$names{$item}.': ';
15928: if (keys(%{$privacyhash{$key}{$item}})) {
15929: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
15930: } else {
15931: $resulttext .= &mt('none');
15932: }
15933: $resulttext .= '</li>';
15934: }
15935: }
15936: }
15937: $resulttext .= '</ul></li>';
15938: }
15939: }
15940: } else {
15941: $resulttext = &mt('No changes made to user information settings');
15942: }
15943: } else {
15944: $resulttext = '<span class="LC_error">'.
15945: &mt('An error occurred: [_1]',$putresult).'</span>';
15946: }
15947: return $resulttext;
15948: }
15949:
1.354 raeburn 15950: sub modify_passwords {
15951: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 15952: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
15953: $updatedefaults,$updateconf);
1.354 raeburn 15954: my $customfn = 'resetpw.html';
15955: if (ref($domconfig{'passwords'}) eq 'HASH') {
15956: %current = %{$domconfig{'passwords'}};
15957: }
15958: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15959: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
15960: if (ref($types) eq 'ARRAY') {
15961: @oktypes = @{$types};
15962: }
15963: push(@oktypes,'default');
15964:
15965: my %titles = &Apache::lonlocal::texthash (
15966: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
15967: intauth_check => 'Check bcrypt cost if authenticated',
15968: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
15969: permanent => 'Permanent e-mail address',
15970: critical => 'Critical notification address',
15971: notify => 'Notification address',
15972: min => 'Minimum password length',
15973: max => 'Maximum password length',
15974: chars => 'Required characters',
15975: expire => 'Password expiration (days)',
1.356 raeburn 15976: numsaved => 'Number of previous passwords to save',
1.354 raeburn 15977: reset => 'Resetting Forgotten Password',
15978: intauth => 'Encryption of Stored Passwords (Internal Auth)',
15979: rules => 'Rules for LON-CAPA Passwords',
15980: crsownerchg => 'Course Owner Changing Student Passwords',
15981: username => 'Username',
15982: email => 'E-mail address',
15983: );
15984:
15985: #
15986: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
15987: #
15988: my (%curr_defaults,%save_defaults);
15989: if (ref($domconfig{'defaults'}) eq 'HASH') {
15990: foreach my $key (keys(%{$domconfig{'defaults'}})) {
15991: if ($key =~ /^intauth_(cost|check|switch)$/) {
15992: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
15993: } else {
15994: $save_defaults{$key} = $domconfig{'defaults'}{$key};
15995: }
15996: }
15997: }
15998: my %staticdefaults = (
15999: 'resetlink' => 2,
16000: 'resetcase' => \@oktypes,
16001: 'resetprelink' => 'both',
16002: 'resetemail' => ['critical','notify','permanent'],
16003: 'intauth_cost' => 10,
16004: 'intauth_check' => 0,
16005: 'intauth_switch' => 0,
16006: );
1.365 raeburn 16007: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 16008: foreach my $type (@oktypes) {
16009: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
16010: }
16011: my $linklife = $env{'form.passwords_link'};
16012: $linklife =~ s/^\s+|\s+$//g;
16013: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
16014: $newvalues{'resetlink'} = $linklife;
16015: if ($current{'resetlink'}) {
16016: if ($current{'resetlink'} ne $linklife) {
16017: $changes{'reset'} = 1;
16018: }
1.368 raeburn 16019: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16020: if ($staticdefaults{'resetlink'} ne $linklife) {
16021: $changes{'reset'} = 1;
16022: }
16023: }
16024: } elsif ($current{'resetlink'}) {
16025: $changes{'reset'} = 1;
16026: }
16027: my @casesens;
16028: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
16029: foreach my $case (sort(@posscase)) {
16030: if (grep(/^\Q$case\E$/,@oktypes)) {
16031: push(@casesens,$case);
16032: }
16033: }
16034: $newvalues{'resetcase'} = \@casesens;
16035: if (ref($current{'resetcase'}) eq 'ARRAY') {
16036: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
16037: if (@diffs > 0) {
16038: $changes{'reset'} = 1;
16039: }
1.368 raeburn 16040: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16041: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
16042: if (@diffs > 0) {
16043: $changes{'reset'} = 1;
16044: }
16045: }
16046: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
16047: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
16048: if (exists($current{'resetprelink'})) {
16049: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
16050: $changes{'reset'} = 1;
16051: }
1.368 raeburn 16052: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16053: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
16054: $changes{'reset'} = 1;
16055: }
16056: }
16057: } elsif ($current{'resetprelink'}) {
16058: $changes{'reset'} = 1;
16059: }
16060: foreach my $type (@oktypes) {
16061: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
16062: my @postlink;
16063: foreach my $item (sort(@possplink)) {
16064: if ($item =~ /^(email|username)$/) {
16065: push(@postlink,$item);
16066: }
16067: }
16068: $newvalues{'resetpostlink'}{$type} = \@postlink;
16069: unless ($changes{'reset'}) {
16070: if (ref($current{'resetpostlink'}) eq 'HASH') {
16071: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
16072: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
16073: if (@diffs > 0) {
16074: $changes{'reset'} = 1;
16075: }
16076: } else {
16077: $changes{'reset'} = 1;
16078: }
1.368 raeburn 16079: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16080: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
16081: if (@diffs > 0) {
16082: $changes{'reset'} = 1;
16083: }
16084: }
16085: }
16086: }
16087: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
16088: my @resetemail;
16089: foreach my $item (sort(@possemailsrc)) {
16090: if ($item =~ /^(permanent|critical|notify)$/) {
16091: push(@resetemail,$item);
16092: }
16093: }
16094: $newvalues{'resetemail'} = \@resetemail;
16095: unless ($changes{'reset'}) {
16096: if (ref($current{'resetemail'}) eq 'ARRAY') {
16097: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
16098: if (@diffs > 0) {
16099: $changes{'reset'} = 1;
16100: }
1.368 raeburn 16101: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16102: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
16103: if (@diffs > 0) {
16104: $changes{'reset'} = 1;
16105: }
16106: }
16107: }
16108: if ($env{'form.passwords_stdtext'} == 0) {
16109: $newvalues{'resetremove'} = 1;
16110: unless ($current{'resetremove'}) {
16111: $changes{'reset'} = 1;
16112: }
16113: } elsif ($current{'resetremove'}) {
16114: $changes{'reset'} = 1;
16115: }
16116: if ($env{'form.passwords_customfile.filename'} ne '') {
16117: my $servadm = $r->dir_config('lonAdmEMail');
16118: my ($configuserok,$author_ok,$switchserver) =
16119: &config_check($dom,$confname,$servadm);
16120: my $error;
16121: if ($configuserok eq 'ok') {
16122: if ($switchserver) {
16123: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
16124: } else {
16125: if ($author_ok eq 'ok') {
16126: my ($result,$customurl) =
16127: &publishlogo($r,'upload','passwords_customfile',$dom,
16128: $confname,'customtext/resetpw','','',$customfn);
16129: if ($result eq 'ok') {
16130: $newvalues{'resetcustom'} = $customurl;
16131: $changes{'reset'} = 1;
16132: } else {
16133: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
16134: }
16135: } else {
16136: $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);
16137: }
16138: }
16139: } else {
16140: $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);
16141: }
16142: if ($error) {
16143: &Apache::lonnet::logthis($error);
16144: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
16145: }
16146: } elsif ($current{'resetcustom'}) {
16147: if ($env{'form.passwords_custom_del'}) {
16148: $changes{'reset'} = 1;
16149: } else {
16150: $newvalues{'resetcustom'} = $current{'resetcustom'};
16151: }
16152: }
16153: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
16154: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
16155: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
16156: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
16157: $changes{'intauth'} = 1;
16158: }
16159: } else {
16160: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
16161: }
16162: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
16163: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
16164: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
16165: $changes{'intauth'} = 1;
16166: }
16167: } else {
16168: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
16169: }
16170: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
16171: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
16172: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
16173: $changes{'intauth'} = 1;
16174: }
16175: } else {
16176: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
16177: }
16178: foreach my $item ('cost','check','switch') {
16179: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
16180: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
16181: $updatedefaults = 1;
16182: }
16183: }
1.356 raeburn 16184: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 16185: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.356 raeburn 16186: my $ruleok;
16187: if ($rule eq 'expire') {
1.365 raeburn 16188: if (($env{'form.passwords_'.$rule} =~ /^\d+(|\.\d*)$/) &&
16189: ($env{'form.passwords_'.$rule} ne '0')) {
1.359 raeburn 16190: $ruleok = 1;
1.356 raeburn 16191: }
1.365 raeburn 16192: } elsif ($rule eq 'min') {
16193: if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
16194: if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
16195: $ruleok = 1;
16196: }
16197: }
16198: } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
16199: ($env{'form.passwords_'.$rule} ne '0')) {
1.356 raeburn 16200: $ruleok = 1;
16201: }
16202: if ($ruleok) {
1.354 raeburn 16203: $newvalues{$rule} = $env{'form.passwords_'.$rule};
16204: if (exists($current{$rule})) {
16205: if ($newvalues{$rule} ne $current{$rule}) {
16206: $changes{'rules'} = 1;
16207: }
16208: } elsif ($rule eq 'min') {
16209: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
16210: $changes{'rules'} = 1;
16211: }
1.370 raeburn 16212: } else {
16213: $changes{'rules'} = 1;
1.354 raeburn 16214: }
16215: } elsif (exists($current{$rule})) {
16216: $changes{'rules'} = 1;
16217: }
16218: }
16219: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
16220: my @chars;
16221: foreach my $item (sort(@posschars)) {
16222: if ($item =~ /^(uc|lc|num|spec)$/) {
16223: push(@chars,$item);
16224: }
16225: }
16226: $newvalues{'chars'} = \@chars;
16227: unless ($changes{'rules'}) {
16228: if (ref($current{'chars'}) eq 'ARRAY') {
16229: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
16230: if (@diffs > 0) {
16231: $changes{'rules'} = 1;
16232: }
16233: } else {
16234: if (@chars > 0) {
16235: $changes{'rules'} = 1;
16236: }
16237: }
16238: }
1.359 raeburn 16239: my %crsownerchg = (
16240: by => [],
16241: for => [],
16242: );
16243: foreach my $item ('by','for') {
16244: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
16245: foreach my $type (sort(@posstypes)) {
16246: if (grep(/^\Q$type\E$/,@oktypes)) {
16247: push(@{$crsownerchg{$item}},$type);
16248: }
16249: }
16250: }
16251: $newvalues{'crsownerchg'} = \%crsownerchg;
16252: if (ref($current{'crsownerchg'}) eq 'HASH') {
16253: foreach my $item ('by','for') {
16254: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
16255: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
16256: if (@diffs > 0) {
16257: $changes{'crsownerchg'} = 1;
16258: last;
16259: }
16260: }
16261: }
1.368 raeburn 16262: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 16263: foreach my $item ('by','for') {
16264: if (@{$crsownerchg{$item}} > 0) {
16265: $changes{'crsownerchg'} = 1;
16266: last;
16267: }
1.354 raeburn 16268: }
16269: }
16270:
16271: my %confighash = (
16272: defaults => \%save_defaults,
16273: passwords => \%newvalues,
16274: );
16275: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
16276:
16277: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
16278: if ($putresult eq 'ok') {
16279: if (keys(%changes) > 0) {
16280: $resulttext = &mt('Changes made: ').'<ul>';
16281: foreach my $key ('reset','intauth','rules','crsownerchg') {
16282: if ($changes{$key}) {
1.355 raeburn 16283: unless ($key eq 'intauth') {
16284: $updateconf = 1;
16285: }
1.354 raeburn 16286: $resulttext .= '<li>'.$titles{$key}.':<ul>';
16287: if ($key eq 'reset') {
16288: if ($confighash{'passwords'}{'captcha'} eq 'original') {
16289: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
16290: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
16291: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 16292: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
16293: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
16294: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
16295: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
16296: }
1.354 raeburn 16297: } else {
16298: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
16299: }
16300: if ($confighash{'passwords'}{'resetlink'}) {
16301: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
16302: } else {
16303: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
16304: &mt('Will default to 2 hours').'</li>';
16305: }
16306: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
16307: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
16308: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
16309: } else {
16310: my $casesens;
16311: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
16312: if ($type eq 'default') {
16313: $casesens .= $othertitle.', ';
16314: } elsif ($usertypes->{$type} ne '') {
16315: $casesens .= $usertypes->{$type}.', ';
16316: }
16317: }
16318: $casesens =~ s/\Q, \E$//;
16319: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
16320: }
16321: } else {
16322: $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>';
16323: }
16324: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
16325: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
16326: } else {
16327: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
16328: }
16329: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
16330: my $output;
16331: if (ref($types) eq 'ARRAY') {
16332: foreach my $type (@{$types}) {
16333: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
16334: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
16335: $output .= $usertypes->{$type}.' -- '.&mt('none');
16336: } else {
16337: $output .= $usertypes->{$type}.' -- '.
16338: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
16339: }
16340: }
16341: }
16342: }
16343: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
16344: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
16345: $output .= $othertitle.' -- '.&mt('none');
16346: } else {
16347: $output .= $othertitle.' -- '.
16348: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
16349: }
16350: }
16351: if ($output) {
16352: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
16353: } else {
16354: $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>';
16355: }
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: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
16360: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
16361: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
16362: } else {
16363: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
16364: }
16365: } else {
16366: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA usedfor verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
16367: }
16368: if ($confighash{'passwords'}{'resetremove'}) {
16369: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
16370: } else {
16371: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
16372: }
16373: if ($confighash{'passwords'}{'resetcustom'}) {
16374: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 16375: &mt('custom text'),600,500,undef,undef,
16376: undef,undef,'background-color:#ffffff');
16377: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 16378: } else {
16379: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
16380: }
16381: } elsif ($key eq 'intauth') {
16382: foreach my $item ('cost','switch','check') {
16383: my $value = $save_defaults{$key.'_'.$item};
16384: if ($item eq 'switch') {
16385: my %optiondesc = &Apache::lonlocal::texthash (
16386: 0 => 'No',
16387: 1 => 'Yes',
16388: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
16389: );
16390: if ($value =~ /^(0|1|2)$/) {
16391: $value = $optiondesc{$value};
16392: } else {
16393: $value = &mt('none -- defaults to No');
16394: }
16395: } elsif ($item eq 'check') {
16396: my %optiondesc = &Apache::lonlocal::texthash (
16397: 0 => 'No',
16398: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
16399: 2 => 'Yes, disallow login if stored cost is less than domain default',
16400: );
16401: if ($value =~ /^(0|1|2)$/) {
16402: $value = $optiondesc{$value};
16403: } else {
16404: $value = &mt('none -- defaults to No');
16405: }
16406: }
16407: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
16408: }
16409: } elsif ($key eq 'rules') {
1.356 raeburn 16410: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 16411: if ($confighash{'passwords'}{$rule} eq '') {
16412: if ($rule eq 'min') {
1.356 raeburn 16413: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 16414: ' '.&mt('Default of [_1] will be used',
16415: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 16416: } else {
16417: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 16418: }
16419: } else {
16420: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
16421: }
16422: }
1.370 raeburn 16423: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
16424: if (@{$confighash{'passwords'}{'chars'}} > 0) {
16425: my %rulenames = &Apache::lonlocal::texthash(
16426: uc => 'At least one upper case letter',
16427: lc => 'At least one lower case letter',
16428: num => 'At least one number',
16429: spec => 'At least one non-alphanumeric',
16430: );
16431: my $needed = '<ul><li>'.
16432: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
16433: '</li></ul>';
16434: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
16435: } else {
16436: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
16437: }
16438: } else {
16439: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
16440: }
1.354 raeburn 16441: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 16442: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
16443: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
16444: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
16445: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
16446: } else {
16447: my %crsownerstr;
16448: foreach my $item ('by','for') {
16449: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
16450: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
16451: if ($type eq 'default') {
16452: $crsownerstr{$item} .= $othertitle.', ';
16453: } elsif ($usertypes->{$type} ne '') {
16454: $crsownerstr{$item} .= $usertypes->{$type}.', ';
16455: }
16456: }
16457: $crsownerstr{$item} =~ s/\Q, \E$//;
16458: }
16459: }
16460: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
16461: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
16462: }
1.354 raeburn 16463: } else {
1.359 raeburn 16464: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 16465: }
16466: }
16467: $resulttext .= '</ul></li>';
16468: }
16469: }
16470: $resulttext .= '</ul>';
16471: } else {
16472: $resulttext = &mt('No changes made to password settings');
16473: }
1.355 raeburn 16474: my $cachetime = 24*60*60;
1.354 raeburn 16475: if ($updatedefaults) {
16476: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16477: if (ref($lastactref) eq 'HASH') {
16478: $lastactref->{'domdefaults'} = 1;
16479: }
16480: }
1.355 raeburn 16481: if ($updateconf) {
16482: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
16483: if (ref($lastactref) eq 'HASH') {
16484: $lastactref->{'passwdconf'} = 1;
16485: }
16486: }
1.354 raeburn 16487: } else {
16488: $resulttext = '<span class="LC_error">'.
16489: &mt('An error occurred: [_1]',$putresult).'</span>';
16490: }
16491: if ($errors) {
16492: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
16493: $errors.'</ul></p>';
16494: }
16495: return $resulttext;
16496: }
16497:
1.28 raeburn 16498: sub modify_usercreation {
1.27 raeburn 16499: my ($dom,%domconfig) = @_;
1.224 raeburn 16500: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 16501: my $warningmsg;
1.27 raeburn 16502: if (ref($domconfig{'usercreation'}) eq 'HASH') {
16503: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 16504: if ($key eq 'cancreate') {
16505: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
16506: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 16507: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
16508: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
16509: } else {
1.224 raeburn 16510: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
16511: }
16512: }
16513: }
16514: } elsif ($key eq 'email_rule') {
16515: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
16516: } else {
16517: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
16518: }
1.27 raeburn 16519: }
16520: }
16521: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 16522: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 16523: my @contexts = ('author','course','requestcrs');
1.34 raeburn 16524: foreach my $item(@contexts) {
1.224 raeburn 16525: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 16526: }
1.34 raeburn 16527: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
16528: foreach my $item (@contexts) {
1.224 raeburn 16529: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
16530: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 16531: }
1.27 raeburn 16532: }
1.34 raeburn 16533: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
16534: foreach my $item (@contexts) {
1.43 raeburn 16535: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 16536: if ($cancreate{$item} ne 'any') {
16537: push(@{$changes{'cancreate'}},$item);
16538: }
16539: } else {
16540: if ($cancreate{$item} ne 'none') {
16541: push(@{$changes{'cancreate'}},$item);
16542: }
1.27 raeburn 16543: }
16544: }
16545: } else {
1.43 raeburn 16546: foreach my $item (@contexts) {
1.34 raeburn 16547: push(@{$changes{'cancreate'}},$item);
16548: }
1.27 raeburn 16549: }
1.34 raeburn 16550:
1.27 raeburn 16551: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
16552: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
16553: if (!grep(/^\Q$type\E$/,@username_rule)) {
16554: push(@{$changes{'username_rule'}},$type);
16555: }
16556: }
16557: foreach my $type (@username_rule) {
16558: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
16559: push(@{$changes{'username_rule'}},$type);
16560: }
16561: }
16562: } else {
16563: push(@{$changes{'username_rule'}},@username_rule);
16564: }
16565:
1.32 raeburn 16566: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
16567: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
16568: if (!grep(/^\Q$type\E$/,@id_rule)) {
16569: push(@{$changes{'id_rule'}},$type);
16570: }
16571: }
16572: foreach my $type (@id_rule) {
16573: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
16574: push(@{$changes{'id_rule'}},$type);
16575: }
16576: }
16577: } else {
16578: push(@{$changes{'id_rule'}},@id_rule);
16579: }
16580:
1.43 raeburn 16581: my @authen_contexts = ('author','course','domain');
1.325 raeburn 16582: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 16583: my %authhash;
1.43 raeburn 16584: foreach my $item (@authen_contexts) {
1.28 raeburn 16585: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
16586: foreach my $auth (@authtypes) {
16587: if (grep(/^\Q$auth\E$/,@authallowed)) {
16588: $authhash{$item}{$auth} = 1;
16589: } else {
16590: $authhash{$item}{$auth} = 0;
16591: }
16592: }
16593: }
16594: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 16595: foreach my $item (@authen_contexts) {
1.28 raeburn 16596: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
16597: foreach my $auth (@authtypes) {
16598: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
16599: push(@{$changes{'authtypes'}},$item);
16600: last;
16601: }
16602: }
16603: }
16604: }
16605: } else {
1.43 raeburn 16606: foreach my $item (@authen_contexts) {
1.28 raeburn 16607: push(@{$changes{'authtypes'}},$item);
16608: }
16609: }
16610:
1.224 raeburn 16611: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
16612: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
16613: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
16614: $save_usercreate{'id_rule'} = \@id_rule;
16615: $save_usercreate{'username_rule'} = \@username_rule,
16616: $save_usercreate{'authtypes'} = \%authhash;
16617:
1.27 raeburn 16618: my %usercreation_hash = (
1.224 raeburn 16619: usercreation => \%save_usercreate,
16620: );
1.27 raeburn 16621:
16622: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
16623: $dom);
1.50 raeburn 16624:
1.224 raeburn 16625: if ($putresult eq 'ok') {
16626: if (keys(%changes) > 0) {
16627: $resulttext = &mt('Changes made:').'<ul>';
16628: if (ref($changes{'cancreate'}) eq 'ARRAY') {
16629: my %lt = &usercreation_types();
16630: foreach my $type (@{$changes{'cancreate'}}) {
16631: my $chgtext = $lt{$type}.', ';
16632: if ($cancreate{$type} eq 'none') {
16633: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
16634: } elsif ($cancreate{$type} eq 'any') {
16635: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
16636: } elsif ($cancreate{$type} eq 'official') {
16637: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
16638: } elsif ($cancreate{$type} eq 'unofficial') {
16639: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
16640: }
16641: $resulttext .= '<li>'.$chgtext.'</li>';
16642: }
16643: }
16644: if (ref($changes{'username_rule'}) eq 'ARRAY') {
16645: my ($rules,$ruleorder) =
16646: &Apache::lonnet::inst_userrules($dom,'username');
16647: my $chgtext = '<ul>';
16648: foreach my $type (@username_rule) {
16649: if (ref($rules->{$type}) eq 'HASH') {
16650: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
16651: }
16652: }
16653: $chgtext .= '</ul>';
16654: if (@username_rule > 0) {
16655: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
16656: } else {
16657: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
16658: }
16659: }
16660: if (ref($changes{'id_rule'}) eq 'ARRAY') {
16661: my ($idrules,$idruleorder) =
16662: &Apache::lonnet::inst_userrules($dom,'id');
16663: my $chgtext = '<ul>';
16664: foreach my $type (@id_rule) {
16665: if (ref($idrules->{$type}) eq 'HASH') {
16666: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
16667: }
16668: }
16669: $chgtext .= '</ul>';
16670: if (@id_rule > 0) {
16671: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
16672: } else {
16673: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
16674: }
16675: }
16676: my %authname = &authtype_names();
16677: my %context_title = &context_names();
16678: if (ref($changes{'authtypes'}) eq 'ARRAY') {
16679: my $chgtext = '<ul>';
16680: foreach my $type (@{$changes{'authtypes'}}) {
16681: my @allowed;
16682: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
16683: foreach my $auth (@authtypes) {
16684: if ($authhash{$type}{$auth}) {
16685: push(@allowed,$authname{$auth});
16686: }
16687: }
16688: if (@allowed > 0) {
16689: $chgtext .= join(', ',@allowed).'</li>';
16690: } else {
16691: $chgtext .= &mt('none').'</li>';
16692: }
16693: }
16694: $chgtext .= '</ul>';
16695: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
16696: $resulttext .= '</li>';
16697: }
16698: $resulttext .= '</ul>';
16699: } else {
16700: $resulttext = &mt('No changes made to user creation settings');
16701: }
16702: } else {
16703: $resulttext = '<span class="LC_error">'.
16704: &mt('An error occurred: [_1]',$putresult).'</span>';
16705: }
16706: if ($warningmsg ne '') {
16707: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
16708: }
16709: return $resulttext;
16710: }
16711:
16712: sub modify_selfcreation {
1.305 raeburn 16713: my ($dom,$lastactref,%domconfig) = @_;
16714: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
16715: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
16716: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 16717: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
16718: if (ref($typesref) eq 'ARRAY') {
16719: @types = @{$typesref};
16720: }
16721: if (ref($usertypesref) eq 'HASH') {
16722: %usertypes = %{$usertypesref};
1.228 raeburn 16723: }
1.303 raeburn 16724: $usertypes{'default'} = $othertitle;
1.224 raeburn 16725: #
16726: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
16727: #
16728: if (ref($domconfig{'usercreation'}) eq 'HASH') {
16729: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
16730: if ($key eq 'cancreate') {
16731: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
16732: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
16733: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 16734: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
16735: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
16736: ($item eq 'emailusername') || ($item eq 'shibenv') ||
16737: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 16738: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 16739: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
16740: } else {
16741: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
16742: }
16743: }
16744: }
16745: } elsif ($key eq 'email_rule') {
16746: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
16747: } else {
16748: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
16749: }
16750: }
16751: }
16752: #
16753: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
16754: #
16755: if (ref($domconfig{'usermodification'}) eq 'HASH') {
16756: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
16757: if ($key eq 'selfcreate') {
16758: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
16759: } else {
16760: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
16761: }
16762: }
16763: }
1.305 raeburn 16764: #
16765: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
16766: #
16767: if (ref($domconfig{'inststatus'}) eq 'HASH') {
16768: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
16769: if ($key eq 'inststatusguest') {
16770: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
16771: } else {
16772: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
16773: }
16774: }
16775: }
1.224 raeburn 16776:
16777: my @contexts = ('selfcreate');
16778: @{$cancreate{'selfcreate'}} = ();
16779: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 16780: if (@types) {
16781: @{$cancreate{'statustocreate'}} = ();
16782: }
1.236 raeburn 16783: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 16784: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 16785: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 16786: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 16787: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 16788: my %selfcreatetypes = (
16789: sso => 'users authenticated by institutional single sign on',
16790: login => 'users authenticated by institutional log-in',
1.303 raeburn 16791: email => 'users verified by e-mail',
1.50 raeburn 16792: );
1.224 raeburn 16793: #
16794: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
16795: # is permitted.
16796: #
1.305 raeburn 16797: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 16798:
1.305 raeburn 16799: my (@statuses,%email_rule);
1.228 raeburn 16800: foreach my $item ('login','sso','email') {
1.224 raeburn 16801: if ($item eq 'email') {
1.236 raeburn 16802: if ($env{'form.cancreate_email'}) {
1.305 raeburn 16803: if (@types) {
16804: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
16805: foreach my $status (@poss_statuses) {
16806: if (grep(/^\Q$status\E$/,(@types,'default'))) {
16807: push(@statuses,$status);
16808: }
16809: }
16810: $save_inststatus{'inststatusguest'} = \@statuses;
16811: } else {
16812: push(@statuses,'default');
16813: }
16814: if (@statuses) {
16815: my %curr_rule;
16816: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
16817: foreach my $type (@statuses) {
16818: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 16819: }
1.305 raeburn 16820: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
16821: foreach my $type (@statuses) {
16822: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
16823: }
16824: }
16825: push(@{$cancreate{'selfcreate'}},'email');
16826: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
16827: my %curremaildom;
16828: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
16829: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
16830: }
16831: foreach my $type (@statuses) {
16832: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
16833: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
16834: }
16835: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
16836: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
16837: }
16838: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
16839: #
16840: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
16841: #
16842: my $chosen = $1;
16843: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
16844: my $emaildom;
16845: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
16846: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
16847: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
16848: if (ref($curremaildom{$type}) eq 'HASH') {
16849: if (exists($curremaildom{$type}{$chosen})) {
16850: if ($curremaildom{$type}{$chosen} ne $emaildom) {
16851: push(@{$changes{'cancreate'}},'emaildomain');
16852: }
16853: } elsif ($emaildom ne '') {
16854: push(@{$changes{'cancreate'}},'emaildomain');
16855: }
16856: } elsif ($emaildom ne '') {
16857: push(@{$changes{'cancreate'}},'emaildomain');
16858: }
16859: }
16860: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
16861: } elsif ($chosen eq 'custom') {
16862: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
16863: $email_rule{$type} = [];
16864: if (ref($emailrules) eq 'HASH') {
16865: foreach my $rule (@possemail_rules) {
16866: if (exists($emailrules->{$rule})) {
16867: push(@{$email_rule{$type}},$rule);
16868: }
16869: }
16870: }
16871: if (@{$email_rule{$type}}) {
16872: $cancreate{'emailoptions'}{$type} = 'custom';
16873: if (ref($curr_rule{$type}) eq 'ARRAY') {
16874: if (@{$curr_rule{$type}} > 0) {
16875: foreach my $rule (@{$curr_rule{$type}}) {
16876: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
16877: push(@{$changes{'email_rule'}},$type);
16878: }
16879: }
16880: }
16881: foreach my $type (@{$email_rule{$type}}) {
16882: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
16883: push(@{$changes{'email_rule'}},$type);
16884: }
16885: }
16886: } else {
16887: push(@{$changes{'email_rule'}},$type);
16888: }
16889: }
16890: } else {
16891: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
16892: }
16893: }
16894: }
16895: if (@types) {
16896: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
16897: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
16898: if (@changed) {
16899: push(@{$changes{'inststatus'}},'inststatusguest');
16900: }
16901: } else {
16902: push(@{$changes{'inststatus'}},'inststatusguest');
16903: }
16904: }
16905: } else {
16906: delete($env{'form.cancreate_email'});
16907: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
16908: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
16909: push(@{$changes{'inststatus'}},'inststatusguest');
16910: }
16911: }
16912: }
16913: } else {
16914: $save_inststatus{'inststatusguest'} = [];
16915: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
16916: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
16917: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 16918: }
16919: }
1.224 raeburn 16920: }
16921: } else {
16922: if ($env{'form.cancreate_'.$item}) {
16923: push(@{$cancreate{'selfcreate'}},$item);
16924: }
16925: }
16926: }
1.305 raeburn 16927: my (%userinfo,%savecaptcha);
1.224 raeburn 16928: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
16929: #
1.228 raeburn 16930: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
16931: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 16932: #
1.236 raeburn 16933:
1.244 raeburn 16934: if ($env{'form.cancreate_email'}) {
1.228 raeburn 16935: push(@contexts,'emailusername');
1.305 raeburn 16936: if (@statuses) {
16937: foreach my $type (@statuses) {
1.228 raeburn 16938: if (ref($infofields) eq 'ARRAY') {
16939: foreach my $field (@{$infofields}) {
16940: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
16941: $cancreate{'emailusername'}{$type}{$field} = $1;
16942: }
16943: }
1.224 raeburn 16944: }
16945: }
16946: }
16947: #
16948: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 16949: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 16950: #
16951:
16952: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
16953: @approvalnotify = sort(@approvalnotify);
16954: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
16955: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
16956: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
16957: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
16958: push(@{$changes{'cancreate'}},'notify');
16959: }
16960: } else {
16961: if ($cancreate{'notify'}{'approval'}) {
16962: push(@{$changes{'cancreate'}},'notify');
16963: }
16964: }
16965: } elsif ($cancreate{'notify'}{'approval'}) {
16966: push(@{$changes{'cancreate'}},'notify');
16967: }
16968:
16969: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
16970: }
16971: #
1.236 raeburn 16972: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 16973: # institutional log-in.
16974: #
16975: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
16976: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
16977: ($domdefaults{'auth_def'} eq 'localauth'))) {
16978: $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.').' '.
16979: &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.');
16980: }
16981: }
16982: my @fields = ('lastname','firstname','middlename','generation',
16983: 'permanentemail','id');
1.240 raeburn 16984: my @shibfields = (@fields,'inststatus');
1.224 raeburn 16985: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
16986: #
16987: # Where usernames may created for institutional log-in and/or institutional single sign on:
16988: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
16989: # may self-create accounts
16990: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
16991: # which the user may supply, if institutional data is unavailable.
16992: #
16993: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 16994: if (@types) {
1.305 raeburn 16995: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
16996: push(@contexts,'statustocreate');
1.303 raeburn 16997: foreach my $type (@types) {
1.224 raeburn 16998: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
16999: foreach my $field (@fields) {
17000: if (grep(/^\Q$field\E$/,@modifiable)) {
17001: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
17002: } else {
17003: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
17004: }
17005: }
17006: }
17007: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 17008: foreach my $type (@types) {
1.224 raeburn 17009: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
17010: foreach my $field (@fields) {
17011: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
17012: $curr_usermodify{'selfcreate'}{$type}{$field}) {
17013: push(@{$changes{'selfcreate'}},$type);
17014: last;
17015: }
17016: }
17017: }
17018: }
17019: } else {
1.303 raeburn 17020: foreach my $type (@types) {
1.224 raeburn 17021: push(@{$changes{'selfcreate'}},$type);
17022: }
17023: }
17024: }
1.240 raeburn 17025: foreach my $field (@shibfields) {
17026: if ($env{'form.shibenv_'.$field} ne '') {
17027: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
17028: }
17029: }
17030: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
17031: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
17032: foreach my $field (@shibfields) {
17033: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
17034: push(@{$changes{'cancreate'}},'shibenv');
17035: }
17036: }
17037: } else {
17038: foreach my $field (@shibfields) {
17039: if ($env{'form.shibenv_'.$field}) {
17040: push(@{$changes{'cancreate'}},'shibenv');
17041: last;
17042: }
17043: }
17044: }
17045: }
1.224 raeburn 17046: }
17047: foreach my $item (@contexts) {
17048: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
17049: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
17050: if (ref($cancreate{$item}) eq 'ARRAY') {
17051: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
17052: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17053: push(@{$changes{'cancreate'}},$item);
17054: }
17055: }
17056: }
17057: }
17058: if (ref($cancreate{$item}) eq 'ARRAY') {
17059: foreach my $type (@{$cancreate{$item}}) {
17060: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
17061: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17062: push(@{$changes{'cancreate'}},$item);
17063: }
17064: }
17065: }
17066: }
17067: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
17068: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 17069: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
17070: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
17071: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
17072: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 17073: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17074: push(@{$changes{'cancreate'}},$item);
17075: }
17076: }
17077: }
1.305 raeburn 17078: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17079: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 17080: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17081: push(@{$changes{'cancreate'}},$item);
17082: }
1.224 raeburn 17083: }
17084: }
17085: }
1.305 raeburn 17086: foreach my $type (keys(%{$cancreate{$item}})) {
17087: if (ref($cancreate{$item}{$type}) eq 'HASH') {
17088: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
17089: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
17090: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 17091: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17092: push(@{$changes{'cancreate'}},$item);
17093: }
17094: }
17095: } else {
17096: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17097: push(@{$changes{'cancreate'}},$item);
17098: }
17099: }
17100: }
1.305 raeburn 17101: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17102: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 17103: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17104: push(@{$changes{'cancreate'}},$item);
17105: }
1.224 raeburn 17106: }
17107: }
17108: }
17109: }
17110: } elsif ($curr_usercreation{'cancreate'}{$item}) {
17111: if (ref($cancreate{$item}) eq 'ARRAY') {
17112: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
17113: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17114: push(@{$changes{'cancreate'}},$item);
17115: }
17116: }
1.305 raeburn 17117: }
17118: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17119: if (ref($cancreate{$item}) eq 'HASH') {
17120: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17121: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 17122: }
17123: }
17124: } elsif ($item eq 'emailusername') {
1.228 raeburn 17125: if (ref($cancreate{$item}) eq 'HASH') {
17126: foreach my $type (keys(%{$cancreate{$item}})) {
17127: if (ref($cancreate{$item}{$type}) eq 'HASH') {
17128: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
17129: if ($cancreate{$item}{$type}{$field}) {
17130: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17131: push(@{$changes{'cancreate'}},$item);
17132: }
17133: last;
17134: }
17135: }
17136: }
17137: }
1.224 raeburn 17138: }
17139: }
17140: }
17141: #
17142: # Populate %save_usercreate hash with updates to self-creation configuration.
17143: #
17144: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
17145: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 17146: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 17147: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
17148: if (ref($cancreate{'notify'}) eq 'HASH') {
17149: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
17150: }
1.236 raeburn 17151: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
17152: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
17153: }
1.303 raeburn 17154: if (ref($cancreate{'emailverified'}) eq 'HASH') {
17155: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
17156: }
1.305 raeburn 17157: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
17158: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
17159: }
1.303 raeburn 17160: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
17161: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
17162: }
1.224 raeburn 17163: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
17164: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
17165: }
1.240 raeburn 17166: if (ref($cancreate{'shibenv'}) eq 'HASH') {
17167: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
17168: }
1.224 raeburn 17169: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 17170: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 17171:
17172: my %userconfig_hash = (
17173: usercreation => \%save_usercreate,
17174: usermodification => \%save_usermodify,
1.305 raeburn 17175: inststatus => \%save_inststatus,
1.224 raeburn 17176: );
1.305 raeburn 17177:
1.224 raeburn 17178: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
17179: $dom);
17180: #
1.305 raeburn 17181: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 17182: #
1.27 raeburn 17183: if ($putresult eq 'ok') {
17184: if (keys(%changes) > 0) {
17185: $resulttext = &mt('Changes made:').'<ul>';
17186: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 17187: my %lt = &selfcreation_types();
1.34 raeburn 17188: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 17189: my $chgtext = '';
1.45 raeburn 17190: if ($type eq 'selfcreate') {
1.50 raeburn 17191: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 17192: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 17193: } else {
1.224 raeburn 17194: $chgtext .= &mt('Self-creation of a new account is permitted for:').
17195: '<ul>';
1.50 raeburn 17196: foreach my $case (@{$cancreate{$type}}) {
17197: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
17198: }
17199: $chgtext .= '</ul>';
1.100 raeburn 17200: if (ref($cancreate{$type}) eq 'ARRAY') {
17201: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
17202: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
17203: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 17204: $chgtext .= '<span class="LC_warning">'.
17205: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
17206: '</span><br />';
17207: }
17208: }
17209: }
17210: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 17211: if (!@statuses) {
17212: $chgtext .= '<span class="LC_warning">'.
17213: &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.").
17214: '</span><br />';
1.303 raeburn 17215:
1.100 raeburn 17216: }
17217: }
17218: }
1.43 raeburn 17219: }
1.240 raeburn 17220: } elsif ($type eq 'shibenv') {
17221: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 17222: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 17223: } else {
17224: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
17225: '<ul>';
17226: foreach my $field (@shibfields) {
17227: next if ($cancreate{$type}{$field} eq '');
17228: if ($field eq 'inststatus') {
17229: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
17230: } else {
17231: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
17232: }
17233: }
17234: $chgtext .= '</ul>';
1.303 raeburn 17235: }
1.93 raeburn 17236: } elsif ($type eq 'statustocreate') {
1.96 raeburn 17237: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
17238: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
17239: if (@{$cancreate{'selfcreate'}} > 0) {
17240: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 17241: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 17242: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 17243: $chgtext .= '<br />'.
17244: '<span class="LC_warning">'.
17245: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
17246: '</span>';
17247: }
1.303 raeburn 17248: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 17249: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 17250: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
17251: } else {
17252: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
17253: }
17254: $chgtext .= '<ul>';
17255: foreach my $case (@{$cancreate{$type}}) {
17256: if ($case eq 'default') {
17257: $chgtext .= '<li>'.$othertitle.'</li>';
17258: } else {
1.303 raeburn 17259: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 17260: }
17261: }
1.100 raeburn 17262: $chgtext .= '</ul>';
17263: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 17264: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 17265: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
17266: '</span>';
1.100 raeburn 17267: }
17268: }
17269: } else {
17270: if (@{$cancreate{$type}} == 0) {
17271: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
17272: } else {
17273: $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 17274: }
17275: }
1.303 raeburn 17276: $chgtext .= '<br />';
1.93 raeburn 17277: }
1.236 raeburn 17278: } elsif ($type eq 'selfcreateprocessing') {
17279: my %choices = &Apache::lonlocal::texthash (
17280: automatic => 'Automatic approval',
17281: approval => 'Queued for approval',
17282: );
1.305 raeburn 17283: if (@types) {
17284: if (@statuses) {
1.303 raeburn 17285: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 17286: '<ul>';
1.305 raeburn 17287: foreach my $status (@statuses) {
17288: if ($status eq 'default') {
17289: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 17290: } else {
1.305 raeburn 17291: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 17292: }
17293: }
17294: $chgtext .= '</ul>';
17295: }
17296: } else {
17297: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
17298: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
17299: }
17300: } elsif ($type eq 'emailverified') {
17301: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 17302: all => 'Same as e-mail',
17303: first => 'Omit @domain',
17304: free => 'Free to choose',
1.303 raeburn 17305: );
1.305 raeburn 17306: if (@types) {
17307: if (@statuses) {
1.303 raeburn 17308: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
17309: '<ul>';
1.305 raeburn 17310: foreach my $status (@statuses) {
1.362 raeburn 17311: if ($status eq 'default') {
1.305 raeburn 17312: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 17313: } else {
1.305 raeburn 17314: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 17315: }
17316: }
17317: $chgtext .= '</ul>';
17318: }
17319: } else {
1.305 raeburn 17320: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 17321: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 17322: }
1.305 raeburn 17323: } elsif ($type eq 'emailoptions') {
17324: my %options = &Apache::lonlocal::texthash (
17325: any => 'Any e-mail',
17326: inst => 'Institutional only',
17327: noninst => 'Non-institutional only',
17328: custom => 'Custom restrictions',
17329: );
17330: if (@types) {
17331: if (@statuses) {
17332: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
17333: '<ul>';
17334: foreach my $status (@statuses) {
17335: if ($type eq 'default') {
17336: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
17337: } else {
17338: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 17339: }
17340: }
1.305 raeburn 17341: $chgtext .= '</ul>';
17342: }
17343: } else {
17344: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
17345: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
17346: } else {
17347: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
17348: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 17349: }
1.305 raeburn 17350: }
17351: } elsif ($type eq 'emaildomain') {
17352: my $output;
17353: if (@statuses) {
17354: foreach my $type (@statuses) {
17355: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
17356: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
17357: if ($type eq 'default') {
17358: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17359: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
17360: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
17361: } else {
17362: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
17363: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
17364: }
1.303 raeburn 17365: } else {
1.305 raeburn 17366: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17367: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
17368: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
17369: } else {
17370: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
17371: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
17372: }
1.303 raeburn 17373: }
1.305 raeburn 17374: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
17375: if ($type eq 'default') {
17376: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17377: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
17378: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
17379: } else {
17380: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
17381: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
17382: }
1.303 raeburn 17383: } else {
1.305 raeburn 17384: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17385: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
17386: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
17387: } else {
17388: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
17389: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
17390: }
1.303 raeburn 17391: }
17392: }
17393: }
17394: }
1.305 raeburn 17395: }
17396: if ($output ne '') {
17397: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
17398: '<ul>'.$output.'</ul>';
1.236 raeburn 17399: }
1.165 raeburn 17400: } elsif ($type eq 'captcha') {
1.224 raeburn 17401: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 17402: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
17403: } else {
17404: my %captchas = &captcha_phrases();
1.224 raeburn 17405: if ($captchas{$savecaptcha{$type}}) {
17406: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 17407: } else {
1.210 raeburn 17408: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 17409: }
17410: }
17411: } elsif ($type eq 'recaptchakeys') {
17412: my ($privkey,$pubkey);
1.224 raeburn 17413: if (ref($savecaptcha{$type}) eq 'HASH') {
17414: $pubkey = $savecaptcha{$type}{'public'};
17415: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 17416: }
17417: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
17418: if (!$pubkey) {
17419: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
17420: } else {
17421: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
17422: }
17423: if (!$privkey) {
17424: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
17425: } else {
17426: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
17427: }
17428: $chgtext .= '</ul>';
1.269 raeburn 17429: } elsif ($type eq 'recaptchaversion') {
17430: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 17431: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 17432: }
1.224 raeburn 17433: } elsif ($type eq 'emailusername') {
17434: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 17435: if (@statuses) {
17436: foreach my $type (@statuses) {
1.228 raeburn 17437: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
17438: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 17439: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 17440: '<ul>';
17441: foreach my $field (@{$infofields}) {
17442: if ($cancreate{'emailusername'}{$type}{$field}) {
17443: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
17444: }
17445: }
1.245 raeburn 17446: $chgtext .= '</ul>';
17447: } else {
1.303 raeburn 17448: $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 17449: }
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.224 raeburn 17452: }
17453: }
17454: }
17455: }
17456: } elsif ($type eq 'notify') {
1.303 raeburn 17457: my $numapprove = 0;
1.224 raeburn 17458: if (ref($changes{'cancreate'}) eq 'ARRAY') {
17459: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
17460: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 17461: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
17462: $numapprove ++;
1.224 raeburn 17463: }
17464: }
1.43 raeburn 17465: }
1.303 raeburn 17466: unless ($numapprove) {
17467: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
17468: }
1.34 raeburn 17469: }
1.224 raeburn 17470: if ($chgtext) {
17471: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 17472: }
17473: }
17474: }
1.305 raeburn 17475: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 17476: my ($emailrules,$emailruleorder) =
17477: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 17478: foreach my $type (@{$changes{'email_rule'}}) {
17479: if (ref($email_rule{$type}) eq 'ARRAY') {
17480: my $chgtext = '<ul>';
17481: foreach my $rule (@{$email_rule{$type}}) {
17482: if (ref($emailrules->{$rule}) eq 'HASH') {
17483: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
17484: }
17485: }
17486: $chgtext .= '</ul>';
1.310 raeburn 17487: my $typename;
1.305 raeburn 17488: if (@types) {
17489: if ($type eq 'default') {
17490: $typename = $othertitle;
17491: } else {
17492: $typename = $usertypes{$type};
17493: }
17494: $chgtext .= &mt('(Affiliation: [_1])',$typename);
17495: }
17496: if (@{$email_rule{$type}} > 0) {
17497: $resulttext .= '<li>'.
17498: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
17499: $usertypes{$type}).
17500: $chgtext.
17501: '</li>';
17502: } else {
17503: $resulttext .= '<li>'.
1.310 raeburn 17504: &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 17505: '</li>'.
1.310 raeburn 17506: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 17507: }
1.43 raeburn 17508: }
17509: }
1.305 raeburn 17510: }
17511: if (ref($changes{'inststatus'}) eq 'ARRAY') {
17512: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
17513: if (@{$save_inststatus{'inststatusguest'}} > 0) {
17514: my $chgtext = '<ul>';
17515: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
17516: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
17517: }
17518: $chgtext .= '</ul>';
17519: $resulttext .= '<li>'.
17520: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
17521: $chgtext.
17522: '</li>';
17523: } else {
17524: $resulttext .= '<li>'.
17525: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
17526: '</li>';
17527: }
1.43 raeburn 17528: }
17529: }
1.224 raeburn 17530: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
17531: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
17532: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
17533: foreach my $type (@{$changes{'selfcreate'}}) {
17534: my $typename = $type;
1.303 raeburn 17535: if (keys(%usertypes) > 0) {
17536: if ($usertypes{$type} ne '') {
17537: $typename = $usertypes{$type};
1.224 raeburn 17538: }
17539: }
17540: my @modifiable;
17541: $resulttext .= '<li>'.
17542: &mt('Self-creation of account by users with status: [_1]',
17543: '<span class="LC_cusr_emph">'.$typename.'</span>').
17544: ' - '.&mt('modifiable fields (if institutional data blank): ');
17545: foreach my $field (@fields) {
17546: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
17547: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 17548: }
17549: }
1.224 raeburn 17550: if (@modifiable > 0) {
17551: $resulttext .= join(', ',@modifiable);
1.43 raeburn 17552: } else {
1.224 raeburn 17553: $resulttext .= &mt('none');
1.43 raeburn 17554: }
1.224 raeburn 17555: $resulttext .= '</li>';
1.28 raeburn 17556: }
1.224 raeburn 17557: $resulttext .= '</ul></li>';
1.28 raeburn 17558: }
1.27 raeburn 17559: $resulttext .= '</ul>';
1.305 raeburn 17560: my $cachetime = 24*60*60;
17561: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
17562: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17563: if (ref($lastactref) eq 'HASH') {
17564: $lastactref->{'domdefaults'} = 1;
17565: }
1.27 raeburn 17566: } else {
1.224 raeburn 17567: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 17568: }
17569: } else {
17570: $resulttext = '<span class="LC_error">'.
1.23 raeburn 17571: &mt('An error occurred: [_1]',$putresult).'</span>';
17572: }
1.43 raeburn 17573: if ($warningmsg ne '') {
17574: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
17575: }
1.23 raeburn 17576: return $resulttext;
17577: }
17578:
1.165 raeburn 17579: sub process_captcha {
1.369 raeburn 17580: my ($container,$changes,$newsettings,$currsettings) = @_;
17581: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 17582: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
17583: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
17584: $newsettings->{'captcha'} = 'original';
17585: }
1.369 raeburn 17586: my %current;
17587: if (ref($currsettings) eq 'HASH') {
17588: %current = %{$currsettings};
17589: }
17590: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 17591: if ($container eq 'cancreate') {
1.169 raeburn 17592: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
17593: push(@{$changes->{'cancreate'}},'captcha');
17594: } elsif (!defined($changes->{'cancreate'})) {
17595: $changes->{'cancreate'} = ['captcha'];
17596: }
1.368 raeburn 17597: } elsif ($container eq 'passwords') {
17598: $changes->{'reset'} = 1;
1.169 raeburn 17599: } else {
17600: $changes->{'captcha'} = 1;
1.165 raeburn 17601: }
17602: }
1.269 raeburn 17603: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 17604: if ($newsettings->{'captcha'} eq 'recaptcha') {
17605: $newpub = $env{'form.'.$container.'_recaptchapub'};
17606: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 17607: $newpub =~ s/[^\w\-]//g;
17608: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 17609: $newsettings->{'recaptchakeys'} = {
17610: public => $newpub,
17611: private => $newpriv,
17612: };
1.269 raeburn 17613: $newversion = $env{'form.'.$container.'_recaptchaversion'};
17614: $newversion =~ s/\D//g;
17615: if ($newversion ne '2') {
17616: $newversion = 1;
17617: }
17618: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 17619: }
1.369 raeburn 17620: if (ref($current{'recaptchakeys'}) eq 'HASH') {
17621: $currpub = $current{'recaptchakeys'}{'public'};
17622: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 17623: unless ($newsettings->{'captcha'} eq 'recaptcha') {
17624: $newsettings->{'recaptchakeys'} = {
17625: public => '',
17626: private => '',
17627: }
17628: }
1.165 raeburn 17629: }
1.369 raeburn 17630: if ($current{'captcha'} eq 'recaptcha') {
17631: $currversion = $current{'recaptchaversion'};
1.269 raeburn 17632: if ($currversion ne '2') {
17633: $currversion = 1;
17634: }
17635: }
17636: if ($currversion ne $newversion) {
17637: if ($container eq 'cancreate') {
17638: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
17639: push(@{$changes->{'cancreate'}},'recaptchaversion');
17640: } elsif (!defined($changes->{'cancreate'})) {
17641: $changes->{'cancreate'} = ['recaptchaversion'];
17642: }
1.368 raeburn 17643: } elsif ($container eq 'passwords') {
17644: $changes->{'reset'} = 1;
1.269 raeburn 17645: } else {
17646: $changes->{'recaptchaversion'} = 1;
17647: }
17648: }
1.165 raeburn 17649: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 17650: if ($container eq 'cancreate') {
17651: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
17652: push(@{$changes->{'cancreate'}},'recaptchakeys');
17653: } elsif (!defined($changes->{'cancreate'})) {
17654: $changes->{'cancreate'} = ['recaptchakeys'];
17655: }
1.368 raeburn 17656: } elsif ($container eq 'passwords') {
17657: $changes->{'reset'} = 1;
1.169 raeburn 17658: } else {
1.210 raeburn 17659: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 17660: }
17661: }
17662: return;
17663: }
17664:
1.33 raeburn 17665: sub modify_usermodification {
17666: my ($dom,%domconfig) = @_;
1.224 raeburn 17667: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 17668: if (ref($domconfig{'usermodification'}) eq 'HASH') {
17669: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 17670: if ($key eq 'selfcreate') {
17671: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
17672: } else {
17673: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
17674: }
1.33 raeburn 17675: }
17676: }
1.224 raeburn 17677: my @contexts = ('author','course');
1.33 raeburn 17678: my %context_title = (
17679: author => 'In author context',
17680: course => 'In course context',
17681: );
17682: my @fields = ('lastname','firstname','middlename','generation',
17683: 'permanentemail','id');
17684: my %roles = (
17685: author => ['ca','aa'],
17686: course => ['st','ep','ta','in','cr'],
17687: );
17688: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
17689: foreach my $context (@contexts) {
17690: foreach my $role (@{$roles{$context}}) {
17691: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
17692: foreach my $item (@fields) {
17693: if (grep(/^\Q$item\E$/,@modifiable)) {
17694: $modifyhash{$context}{$role}{$item} = 1;
17695: } else {
17696: $modifyhash{$context}{$role}{$item} = 0;
17697: }
17698: }
17699: }
17700: if (ref($curr_usermodification{$context}) eq 'HASH') {
17701: foreach my $role (@{$roles{$context}}) {
17702: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
17703: foreach my $field (@fields) {
17704: if ($modifyhash{$context}{$role}{$field} ne
17705: $curr_usermodification{$context}{$role}{$field}) {
17706: push(@{$changes{$context}},$role);
17707: last;
17708: }
17709: }
17710: }
17711: }
17712: } else {
17713: foreach my $context (@contexts) {
17714: foreach my $role (@{$roles{$context}}) {
17715: push(@{$changes{$context}},$role);
17716: }
17717: }
17718: }
17719: }
17720: my %usermodification_hash = (
17721: usermodification => \%modifyhash,
17722: );
17723: my $putresult = &Apache::lonnet::put_dom('configuration',
17724: \%usermodification_hash,$dom);
17725: if ($putresult eq 'ok') {
17726: if (keys(%changes) > 0) {
17727: $resulttext = &mt('Changes made: ').'<ul>';
17728: foreach my $context (@contexts) {
17729: if (ref($changes{$context}) eq 'ARRAY') {
17730: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
17731: if (ref($changes{$context}) eq 'ARRAY') {
17732: foreach my $role (@{$changes{$context}}) {
17733: my $rolename;
1.224 raeburn 17734: if ($role eq 'cr') {
17735: $rolename = &mt('Custom');
1.33 raeburn 17736: } else {
1.224 raeburn 17737: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 17738: }
17739: my @modifiable;
1.224 raeburn 17740: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 17741: foreach my $field (@fields) {
17742: if ($modifyhash{$context}{$role}{$field}) {
17743: push(@modifiable,$fieldtitles{$field});
17744: }
17745: }
17746: if (@modifiable > 0) {
17747: $resulttext .= join(', ',@modifiable);
17748: } else {
17749: $resulttext .= &mt('none');
17750: }
17751: $resulttext .= '</li>';
17752: }
17753: $resulttext .= '</ul></li>';
17754: }
17755: }
17756: }
17757: $resulttext .= '</ul>';
17758: } else {
17759: $resulttext = &mt('No changes made to user modification settings');
17760: }
17761: } else {
17762: $resulttext = '<span class="LC_error">'.
17763: &mt('An error occurred: [_1]',$putresult).'</span>';
17764: }
17765: return $resulttext;
17766: }
17767:
1.43 raeburn 17768: sub modify_defaults {
1.212 raeburn 17769: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 17770: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 17771: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 17772: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 17773: 'portal_def');
1.325 raeburn 17774: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 17775: foreach my $item (@items) {
17776: $newvalues{$item} = $env{'form.'.$item};
17777: if ($item eq 'auth_def') {
17778: if ($newvalues{$item} ne '') {
17779: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
17780: push(@errors,$item);
17781: }
17782: }
17783: } elsif ($item eq 'lang_def') {
17784: if ($newvalues{$item} ne '') {
17785: if ($newvalues{$item} =~ /^(\w+)/) {
17786: my $langcode = $1;
1.103 raeburn 17787: if ($langcode ne 'x_chef') {
17788: if (code2language($langcode) eq '') {
17789: push(@errors,$item);
17790: }
1.43 raeburn 17791: }
17792: } else {
17793: push(@errors,$item);
17794: }
17795: }
1.54 raeburn 17796: } elsif ($item eq 'timezone_def') {
17797: if ($newvalues{$item} ne '') {
1.62 raeburn 17798: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 17799: push(@errors,$item);
17800: }
17801: }
1.68 raeburn 17802: } elsif ($item eq 'datelocale_def') {
17803: if ($newvalues{$item} ne '') {
17804: my @datelocale_ids = DateTime::Locale->ids();
17805: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
17806: push(@errors,$item);
17807: }
17808: }
1.141 raeburn 17809: } elsif ($item eq 'portal_def') {
17810: if ($newvalues{$item} ne '') {
17811: 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])\/?$/) {
17812: push(@errors,$item);
17813: }
17814: }
1.43 raeburn 17815: }
17816: if (grep(/^\Q$item\E$/,@errors)) {
17817: $newvalues{$item} = $domdefaults{$item};
17818: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
17819: $changes{$item} = 1;
17820: }
1.72 raeburn 17821: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 17822: }
1.354 raeburn 17823: my %staticdefaults = (
17824: 'intauth_cost' => 10,
17825: 'intauth_check' => 0,
17826: 'intauth_switch' => 0,
17827: );
17828: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
17829: if (exists($domdefaults{$item})) {
17830: $newvalues{$item} = $domdefaults{$item};
17831: } else {
17832: $newvalues{$item} = $staticdefaults{$item};
17833: }
17834: }
1.43 raeburn 17835: my %defaults_hash = (
1.72 raeburn 17836: defaults => \%newvalues,
17837: );
1.43 raeburn 17838: my $title = &defaults_titles();
1.236 raeburn 17839:
17840: my $currinststatus;
17841: if (ref($domconfig{'inststatus'}) eq 'HASH') {
17842: $currinststatus = $domconfig{'inststatus'};
17843: } else {
17844: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17845: $currinststatus = {
17846: inststatustypes => $usertypes,
17847: inststatusorder => $types,
17848: inststatusguest => [],
17849: };
17850: }
17851: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
17852: my @allpos;
17853: my %alltypes;
1.305 raeburn 17854: my @inststatusguest;
17855: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
17856: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
17857: unless (grep(/^\Q$type\E$/,@todelete)) {
17858: push(@inststatusguest,$type);
17859: }
17860: }
17861: }
17862: my ($currtitles,$currorder);
1.236 raeburn 17863: if (ref($currinststatus) eq 'HASH') {
17864: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
17865: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
17866: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
17867: if ($currinststatus->{inststatustypes}->{$type} ne '') {
17868: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
17869: }
17870: }
17871: unless (grep(/^\Q$type\E$/,@todelete)) {
17872: my $position = $env{'form.inststatus_pos_'.$type};
17873: $position =~ s/\D+//g;
17874: $allpos[$position] = $type;
17875: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
17876: $alltypes{$type} =~ s/`//g;
17877: }
17878: }
17879: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
17880: $currtitles =~ s/,$//;
17881: }
17882: }
17883: if ($env{'form.addinststatus'}) {
17884: my $newtype = $env{'form.addinststatus'};
17885: $newtype =~ s/\W//g;
17886: unless (exists($alltypes{$newtype})) {
17887: $alltypes{$newtype} = $env{'form.addinststatus_title'};
17888: $alltypes{$newtype} =~ s/`//g;
17889: my $position = $env{'form.addinststatus_pos'};
17890: $position =~ s/\D+//g;
17891: if ($position ne '') {
17892: $allpos[$position] = $newtype;
17893: }
17894: }
17895: }
1.305 raeburn 17896: my @orderedstatus;
1.236 raeburn 17897: foreach my $type (@allpos) {
17898: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
17899: push(@orderedstatus,$type);
17900: }
17901: }
17902: foreach my $type (keys(%alltypes)) {
17903: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
17904: delete($alltypes{$type});
17905: }
17906: }
17907: $defaults_hash{'inststatus'} = {
17908: inststatustypes => \%alltypes,
17909: inststatusorder => \@orderedstatus,
1.305 raeburn 17910: inststatusguest => \@inststatusguest,
1.236 raeburn 17911: };
17912: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
17913: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
17914: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
17915: }
17916: }
17917: if ($currorder ne join(',',@orderedstatus)) {
17918: $changes{'inststatus'}{'inststatusorder'} = 1;
17919: }
17920: my $newtitles;
17921: foreach my $item (@orderedstatus) {
17922: $newtitles .= $alltypes{$item}.',';
17923: }
17924: $newtitles =~ s/,$//;
17925: if ($currtitles ne $newtitles) {
17926: $changes{'inststatus'}{'inststatustypes'} = 1;
17927: }
1.43 raeburn 17928: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
17929: $dom);
17930: if ($putresult eq 'ok') {
17931: if (keys(%changes) > 0) {
17932: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 17933: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 17934: 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";
17935: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 17936: if ($item eq 'inststatus') {
17937: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 17938: if (@orderedstatus) {
1.236 raeburn 17939: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
17940: foreach my $type (@orderedstatus) {
17941: $resulttext .= $alltypes{$type}.', ';
17942: }
17943: $resulttext =~ s/, $//;
17944: $resulttext .= '</li>';
1.305 raeburn 17945: } else {
17946: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 17947: }
17948: }
17949: } else {
17950: my $value = $env{'form.'.$item};
17951: if ($value eq '') {
17952: $value = &mt('none');
17953: } elsif ($item eq 'auth_def') {
17954: my %authnames = &authtype_names();
17955: my %shortauth = (
17956: internal => 'int',
17957: krb4 => 'krb4',
17958: krb5 => 'krb5',
17959: localauth => 'loc',
1.325 raeburn 17960: lti => 'lti',
1.236 raeburn 17961: );
17962: $value = $authnames{$shortauth{$value}};
17963: }
17964: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
17965: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 17966: }
17967: }
17968: $resulttext .= '</ul>';
17969: $mailmsgtext .= "\n";
17970: my $cachetime = 24*60*60;
1.72 raeburn 17971: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 17972: if (ref($lastactref) eq 'HASH') {
17973: $lastactref->{'domdefaults'} = 1;
17974: }
1.68 raeburn 17975: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 17976: my $notify = 1;
17977: if (ref($domconfig{'contacts'}) eq 'HASH') {
17978: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
17979: $notify = 0;
17980: }
17981: }
17982: if ($notify) {
17983: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
17984: "LON-CAPA Domain Settings Change - $dom",
17985: $mailmsgtext);
17986: }
1.54 raeburn 17987: }
1.43 raeburn 17988: } else {
1.54 raeburn 17989: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 17990: }
17991: } else {
17992: $resulttext = '<span class="LC_error">'.
17993: &mt('An error occurred: [_1]',$putresult).'</span>';
17994: }
17995: if (@errors > 0) {
17996: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
17997: foreach my $item (@errors) {
17998: $resulttext .= ' "'.$title->{$item}.'",';
17999: }
18000: $resulttext =~ s/,$//;
18001: }
18002: return $resulttext;
18003: }
18004:
1.46 raeburn 18005: sub modify_scantron {
1.205 raeburn 18006: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 18007: my ($resulttext,%confhash,%changes,$errors);
18008: my $custom = 'custom.tab';
18009: my $default = 'default.tab';
18010: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 18011: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 18012: &config_check($dom,$confname,$servadm);
18013: if ($env{'form.scantronformat.filename'} ne '') {
18014: my $error;
18015: if ($configuserok eq 'ok') {
18016: if ($switchserver) {
1.130 raeburn 18017: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 18018: } else {
18019: if ($author_ok eq 'ok') {
18020: my ($result,$scantronurl) =
18021: &publishlogo($r,'upload','scantronformat',$dom,
18022: $confname,'scantron','','',$custom);
18023: if ($result eq 'ok') {
18024: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 18025: $changes{'scantronformat'} = 1;
1.46 raeburn 18026: } else {
18027: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
18028: }
18029: } else {
18030: $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);
18031: }
18032: }
18033: } else {
18034: $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);
18035: }
18036: if ($error) {
18037: &Apache::lonnet::logthis($error);
18038: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18039: }
18040: }
1.48 raeburn 18041: if (ref($domconfig{'scantron'}) eq 'HASH') {
18042: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
18043: if ($env{'form.scantronformat_del'}) {
18044: $confhash{'scantron'}{'scantronformat'} = '';
18045: $changes{'scantronformat'} = 1;
1.347 raeburn 18046: } else {
18047: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 18048: }
18049: }
18050: }
1.347 raeburn 18051: my @options = ('hdr','pad','rem');
1.346 raeburn 18052: my @fields = &scantroncsv_fields();
18053: my %titles = &scantronconfig_titles();
1.347 raeburn 18054: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 18055: my ($newdat,$currdat,%newcol,%currcol);
18056: if (grep(/^dat$/,@formats)) {
18057: $confhash{'scantron'}{config}{dat} = 1;
18058: $newdat = 1;
18059: } else {
18060: $newdat = 0;
18061: }
18062: if (grep(/^csv$/,@formats)) {
18063: my %bynum;
18064: foreach my $field (@fields) {
18065: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
18066: my $posscol = $1;
18067: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 18068: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 18069: $bynum{$posscol} = $field;
18070: $newcol{$field} = $posscol;
18071: }
18072: }
18073: }
1.347 raeburn 18074: if (keys(%newcol)) {
18075: foreach my $option (@options) {
18076: if ($env{'form.scantroncsv_'.$option}) {
18077: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
18078: }
18079: }
18080: }
1.346 raeburn 18081: }
18082: $currdat = 1;
18083: if (ref($domconfig{'scantron'}) eq 'HASH') {
18084: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 18085: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 18086: $currdat = 0;
18087: }
18088: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 18089: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
18090: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
18091: }
1.346 raeburn 18092: }
18093: }
18094: }
18095: if ($currdat != $newdat) {
18096: $changes{'config'} = 1;
18097: } else {
18098: foreach my $field (@fields) {
18099: if ($currcol{$field} ne '') {
18100: if ($currcol{$field} ne $newcol{$field}) {
18101: $changes{'config'} = 1;
18102: last;
1.347 raeburn 18103: }
1.346 raeburn 18104: } elsif ($newcol{$field} ne '') {
18105: $changes{'config'} = 1;
18106: last;
18107: }
18108: }
18109: }
1.46 raeburn 18110: if (keys(%confhash) > 0) {
18111: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
18112: $dom);
18113: if ($putresult eq 'ok') {
18114: if (keys(%changes) > 0) {
1.48 raeburn 18115: if (ref($confhash{'scantron'}) eq 'HASH') {
18116: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 18117: if ($changes{'scantronformat'}) {
18118: if ($confhash{'scantron'}{'scantronformat'} eq '') {
18119: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
18120: } else {
18121: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
18122: }
18123: }
1.347 raeburn 18124: if ($changes{'config'}) {
1.346 raeburn 18125: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
18126: if ($confhash{'scantron'}{'config'}{'dat'}) {
18127: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
18128: }
18129: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 18130: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
18131: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
18132: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
18133: foreach my $field (@fields) {
18134: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
18135: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
18136: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
18137: }
18138: }
18139: $resulttext .= '</ul></li>';
18140: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
18141: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
18142: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
18143: foreach my $option (@options) {
18144: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
18145: $resulttext .= '<li>'.$titles{$option}.'</li>';
18146: }
18147: }
18148: $resulttext .= '</ul></li>';
18149: }
1.346 raeburn 18150: }
18151: }
18152: }
18153: }
18154: } else {
18155: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
18156: }
1.46 raeburn 18157: }
1.48 raeburn 18158: $resulttext .= '</ul>';
18159: } else {
1.130 raeburn 18160: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 18161: }
18162: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 18163: if (ref($lastactref) eq 'HASH') {
18164: $lastactref->{'domainconfig'} = 1;
18165: }
1.46 raeburn 18166: } else {
1.346 raeburn 18167: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 18168: }
18169: } else {
18170: $resulttext = '<span class="LC_error">'.
18171: &mt('An error occurred: [_1]',$putresult).'</span>';
18172: }
18173: } else {
1.130 raeburn 18174: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 18175: }
18176: if ($errors) {
1.353 raeburn 18177: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18178: $errors.'</ul></p>';
1.46 raeburn 18179: }
18180: return $resulttext;
18181: }
18182:
1.48 raeburn 18183: sub modify_coursecategories {
1.239 raeburn 18184: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 18185: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
18186: $cathash);
1.48 raeburn 18187: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 18188: my @catitems = ('unauth','auth');
18189: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 18190: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 18191: $cathash = $domconfig{'coursecategories'}{'cats'};
18192: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
18193: $changes{'togglecats'} = 1;
18194: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
18195: }
18196: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
18197: $changes{'categorize'} = 1;
18198: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
18199: }
1.120 raeburn 18200: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
18201: $changes{'togglecatscomm'} = 1;
18202: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
18203: }
18204: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
18205: $changes{'categorizecomm'} = 1;
18206: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 18207:
18208: }
18209: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
18210: $changes{'togglecatsplace'} = 1;
18211: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
18212: }
18213: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
18214: $changes{'categorizeplace'} = 1;
18215: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 18216: }
1.238 raeburn 18217: foreach my $item (@catitems) {
18218: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
18219: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
18220: $changes{$item} = 1;
18221: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
18222: }
18223: }
18224: }
1.57 raeburn 18225: } else {
18226: $changes{'togglecats'} = 1;
18227: $changes{'categorize'} = 1;
1.124 raeburn 18228: $changes{'togglecatscomm'} = 1;
18229: $changes{'categorizecomm'} = 1;
1.272 raeburn 18230: $changes{'togglecatsplace'} = 1;
18231: $changes{'categorizeplace'} = 1;
1.87 raeburn 18232: $domconfig{'coursecategories'} = {
18233: togglecats => $env{'form.togglecats'},
18234: categorize => $env{'form.categorize'},
1.124 raeburn 18235: togglecatscomm => $env{'form.togglecatscomm'},
18236: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 18237: togglecatsplace => $env{'form.togglecatsplace'},
18238: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 18239: };
1.238 raeburn 18240: foreach my $item (@catitems) {
18241: if ($env{'form.coursecat_'.$item} ne 'std') {
18242: $changes{$item} = 1;
18243: }
18244: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
18245: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
18246: }
18247: }
1.57 raeburn 18248: }
18249: if (ref($cathash) eq 'HASH') {
18250: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 18251: push (@deletecategory,'instcode::0');
18252: }
1.120 raeburn 18253: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
18254: push(@deletecategory,'communities::0');
18255: }
1.272 raeburn 18256: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
18257: push(@deletecategory,'placement::0');
18258: }
1.48 raeburn 18259: }
1.57 raeburn 18260: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
18261: if (ref($cathash) eq 'HASH') {
1.48 raeburn 18262: if (@deletecategory > 0) {
18263: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 18264: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 18265: foreach my $item (@deletecategory) {
1.57 raeburn 18266: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
18267: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 18268: $deletions{$item} = 1;
1.57 raeburn 18269: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 18270: }
18271: }
18272: }
1.57 raeburn 18273: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 18274: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 18275: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 18276: $reorderings{$item} = 1;
1.57 raeburn 18277: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 18278: }
18279: if ($env{'form.addcategory_name_'.$item} ne '') {
18280: my $newcat = $env{'form.addcategory_name_'.$item};
18281: my $newdepth = $depth+1;
18282: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 18283: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 18284: $adds{$newitem} = 1;
18285: }
18286: if ($env{'form.subcat_'.$item} ne '') {
18287: my $newcat = $env{'form.subcat_'.$item};
18288: my $newdepth = $depth+1;
18289: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 18290: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 18291: $adds{$newitem} = 1;
18292: }
18293: }
18294: }
18295: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 18296: if (ref($cathash) eq 'HASH') {
1.48 raeburn 18297: my $newitem = 'instcode::0';
1.57 raeburn 18298: if ($cathash->{$newitem} eq '') {
18299: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 18300: $adds{$newitem} = 1;
18301: }
18302: } else {
18303: my $newitem = 'instcode::0';
1.57 raeburn 18304: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 18305: $adds{$newitem} = 1;
18306: }
18307: }
1.120 raeburn 18308: if ($env{'form.communities'} eq '1') {
18309: if (ref($cathash) eq 'HASH') {
18310: my $newitem = 'communities::0';
18311: if ($cathash->{$newitem} eq '') {
18312: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
18313: $adds{$newitem} = 1;
18314: }
18315: } else {
18316: my $newitem = 'communities::0';
18317: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
18318: $adds{$newitem} = 1;
18319: }
18320: }
1.272 raeburn 18321: if ($env{'form.placement'} eq '1') {
18322: if (ref($cathash) eq 'HASH') {
18323: my $newitem = 'placement::0';
18324: if ($cathash->{$newitem} eq '') {
18325: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
18326: $adds{$newitem} = 1;
18327: }
18328: } else {
18329: my $newitem = 'placement::0';
18330: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
18331: $adds{$newitem} = 1;
18332: }
18333: }
1.48 raeburn 18334: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 18335: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 18336: ($env{'form.addcategory_name'} ne 'communities') &&
18337: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 18338: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
18339: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
18340: $adds{$newitem} = 1;
18341: }
1.48 raeburn 18342: }
1.57 raeburn 18343: my $putresult;
1.48 raeburn 18344: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
18345: if (keys(%deletions) > 0) {
18346: foreach my $key (keys(%deletions)) {
18347: if ($predelallitems{$key} ne '') {
18348: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
18349: }
18350: }
18351: }
18352: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 18353: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 18354: if (ref($chkcats[0]) eq 'ARRAY') {
18355: my $depth = 0;
18356: my $chg = 0;
18357: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
18358: my $name = $chkcats[0][$i];
18359: my $item;
18360: if ($name eq '') {
18361: $chg ++;
18362: } else {
18363: $item = &escape($name).'::0';
18364: if ($chg) {
1.57 raeburn 18365: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 18366: }
18367: $depth ++;
1.57 raeburn 18368: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 18369: $depth --;
18370: }
18371: }
18372: }
1.57 raeburn 18373: }
18374: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
18375: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 18376: if ($putresult eq 'ok') {
1.57 raeburn 18377: my %title = (
1.120 raeburn 18378: togglecats => 'Show/Hide a course in catalog',
18379: categorize => 'Assign a category to a course',
18380: togglecatscomm => 'Show/Hide a community in catalog',
18381: categorizecomm => 'Assign a category to a community',
1.57 raeburn 18382: );
18383: my %level = (
1.120 raeburn 18384: dom => 'set in Domain ("Modify Course/Community")',
18385: crs => 'set in Course ("Course Configuration")',
18386: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 18387: none => 'No catalog',
18388: std => 'Standard catalog',
18389: domonly => 'Domain-only catalog',
18390: codesrch => 'Code search form',
1.57 raeburn 18391: );
1.48 raeburn 18392: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 18393: if ($changes{'togglecats'}) {
18394: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
18395: }
18396: if ($changes{'categorize'}) {
18397: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 18398: }
1.120 raeburn 18399: if ($changes{'togglecatscomm'}) {
18400: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
18401: }
18402: if ($changes{'categorizecomm'}) {
18403: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
18404: }
1.238 raeburn 18405: if ($changes{'unauth'}) {
18406: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
18407: }
18408: if ($changes{'auth'}) {
18409: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
18410: }
1.57 raeburn 18411: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
18412: my $cathash;
18413: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
18414: $cathash = $domconfig{'coursecategories'}{'cats'};
18415: } else {
18416: $cathash = {};
18417: }
18418: my (@cats,@trails,%allitems);
18419: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
18420: if (keys(%deletions) > 0) {
18421: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
18422: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
18423: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
18424: }
18425: $resulttext .= '</ul></li>';
18426: }
18427: if (keys(%reorderings) > 0) {
18428: my %sort_by_trail;
18429: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
18430: foreach my $key (keys(%reorderings)) {
18431: if ($allitems{$key} ne '') {
18432: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
18433: }
1.48 raeburn 18434: }
1.57 raeburn 18435: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
18436: $resulttext .= '<li>'.$trails[$trail].'</li>';
18437: }
18438: $resulttext .= '</ul></li>';
1.48 raeburn 18439: }
1.57 raeburn 18440: if (keys(%adds) > 0) {
18441: my %sort_by_trail;
18442: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
18443: foreach my $key (keys(%adds)) {
18444: if ($allitems{$key} ne '') {
18445: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
18446: }
18447: }
18448: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
18449: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 18450: }
1.57 raeburn 18451: $resulttext .= '</ul></li>';
1.48 raeburn 18452: }
1.364 raeburn 18453: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
18454: if (ref($lastactref) eq 'HASH') {
18455: $lastactref->{'cats'} = 1;
18456: }
1.48 raeburn 18457: }
18458: $resulttext .= '</ul>';
1.239 raeburn 18459: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 18460: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
18461: if ($changes{'auth'}) {
18462: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
18463: }
18464: if ($changes{'unauth'}) {
18465: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
18466: }
18467: my $cachetime = 24*60*60;
18468: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 18469: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 18470: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 18471: }
18472: }
1.48 raeburn 18473: } else {
18474: $resulttext = '<span class="LC_error">'.
1.57 raeburn 18475: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 18476: }
18477: } else {
1.120 raeburn 18478: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 18479: }
18480: return $resulttext;
18481: }
18482:
1.69 raeburn 18483: sub modify_serverstatuses {
18484: my ($dom,%domconfig) = @_;
18485: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
18486: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
18487: %currserverstatus = %{$domconfig{'serverstatuses'}};
18488: }
18489: my @pages = &serverstatus_pages();
18490: foreach my $type (@pages) {
18491: $newserverstatus{$type}{'namedusers'} = '';
18492: $newserverstatus{$type}{'machines'} = '';
18493: if (defined($env{'form.'.$type.'_namedusers'})) {
18494: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
18495: my @okusers;
18496: foreach my $user (@users) {
18497: my ($uname,$udom) = split(/:/,$user);
18498: if (($udom =~ /^$match_domain$/) &&
18499: (&Apache::lonnet::domain($udom)) &&
18500: ($uname =~ /^$match_username$/)) {
18501: if (!grep(/^\Q$user\E/,@okusers)) {
18502: push(@okusers,$user);
18503: }
18504: }
18505: }
18506: if (@okusers > 0) {
18507: @okusers = sort(@okusers);
18508: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
18509: }
18510: }
18511: if (defined($env{'form.'.$type.'_machines'})) {
18512: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
18513: my @okmachines;
18514: foreach my $ip (@machines) {
18515: my @parts = split(/\./,$ip);
18516: next if (@parts < 4);
18517: my $badip = 0;
18518: for (my $i=0; $i<4; $i++) {
18519: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
18520: $badip = 1;
18521: last;
18522: }
18523: }
18524: if (!$badip) {
18525: push(@okmachines,$ip);
18526: }
18527: }
18528: @okmachines = sort(@okmachines);
18529: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
18530: }
18531: }
18532: my %serverstatushash = (
18533: serverstatuses => \%newserverstatus,
18534: );
18535: foreach my $type (@pages) {
1.83 raeburn 18536: foreach my $setting ('namedusers','machines') {
1.84 raeburn 18537: my (@current,@new);
1.83 raeburn 18538: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 18539: if ($currserverstatus{$type}{$setting} ne '') {
18540: @current = split(/,/,$currserverstatus{$type}{$setting});
18541: }
18542: }
18543: if ($newserverstatus{$type}{$setting} ne '') {
18544: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 18545: }
18546: if (@current > 0) {
18547: if (@new > 0) {
18548: foreach my $item (@current) {
18549: if (!grep(/^\Q$item\E$/,@new)) {
18550: $changes{$type}{$setting} = 1;
1.82 raeburn 18551: last;
18552: }
18553: }
1.84 raeburn 18554: foreach my $item (@new) {
18555: if (!grep(/^\Q$item\E$/,@current)) {
18556: $changes{$type}{$setting} = 1;
18557: last;
1.82 raeburn 18558: }
18559: }
18560: } else {
1.83 raeburn 18561: $changes{$type}{$setting} = 1;
1.69 raeburn 18562: }
1.83 raeburn 18563: } elsif (@new > 0) {
18564: $changes{$type}{$setting} = 1;
1.69 raeburn 18565: }
18566: }
18567: }
18568: if (keys(%changes) > 0) {
1.81 raeburn 18569: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 18570: my $putresult = &Apache::lonnet::put_dom('configuration',
18571: \%serverstatushash,$dom);
18572: if ($putresult eq 'ok') {
18573: $resulttext .= &mt('Changes made:').'<ul>';
18574: foreach my $type (@pages) {
1.84 raeburn 18575: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 18576: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 18577: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 18578: if ($newserverstatus{$type}{'namedusers'} eq '') {
18579: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
18580: } else {
18581: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
18582: }
1.84 raeburn 18583: }
18584: if ($changes{$type}{'machines'}) {
1.69 raeburn 18585: if ($newserverstatus{$type}{'machines'} eq '') {
18586: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
18587: } else {
18588: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
18589: }
18590:
18591: }
18592: $resulttext .= '</ul></li>';
18593: }
18594: }
18595: $resulttext .= '</ul>';
18596: } else {
18597: $resulttext = '<span class="LC_error">'.
18598: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
18599:
18600: }
18601: } else {
18602: $resulttext = &mt('No changes made to access to server status pages');
18603: }
18604: return $resulttext;
18605: }
18606:
1.118 jms 18607: sub modify_helpsettings {
1.285 raeburn 18608: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 18609: my ($resulttext,$errors,%changes,%helphash);
18610: my %defaultchecked = ('submitbugs' => 'on');
18611: my @offon = ('off','on');
1.118 jms 18612: my @toggles = ('submitbugs');
1.285 raeburn 18613: my %current = ('submitbugs' => '',
18614: 'adhoc' => {},
18615: );
1.118 jms 18616: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 18617: %current = %{$domconfig{'helpsettings'}};
18618: }
1.285 raeburn 18619: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 18620: foreach my $item (@toggles) {
18621: if ($defaultchecked{$item} eq 'on') {
18622: if ($current{$item} eq '') {
18623: if ($env{'form.'.$item} eq '0') {
18624: $changes{$item} = 1;
18625: }
18626: } elsif ($current{$item} ne $env{'form.'.$item}) {
18627: $changes{$item} = 1;
18628: }
18629: } elsif ($defaultchecked{$item} eq 'off') {
18630: if ($current{$item} eq '') {
18631: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 18632: $changes{$item} = 1;
18633: }
1.282 raeburn 18634: } elsif ($current{$item} ne $env{'form.'.$item}) {
18635: $changes{$item} = 1;
18636: }
18637: }
18638: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
18639: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
18640: }
18641: }
1.285 raeburn 18642: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 18643: my $confname = $dom.'-domainconfig';
18644: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 18645: my (@allpos,%newsettings,%changedprivs,$newrole);
18646: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 18647: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 18648: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 18649: my %lt = &Apache::lonlocal::texthash(
18650: s => 'system',
18651: d => 'domain',
18652: order => 'Display order',
18653: access => 'Role usage',
1.291 raeburn 18654: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 18655: dh => 'All with domain helpdesk role',
18656: da => 'All with domain helpdesk assistant role',
1.285 raeburn 18657: none => 'None',
18658: status => 'Determined based on institutional status',
18659: inc => 'Include all, but exclude specific personnel',
18660: exc => 'Exclude all, but include specific personnel',
18661: );
18662: for (my $num=0; $num<=$maxnum; $num++) {
18663: my ($prefix,$identifier,$rolename,%curr);
18664: if ($num == $maxnum) {
18665: next unless ($env{'form.newcusthelp'} == $maxnum);
18666: $identifier = 'custhelp'.$num;
18667: $prefix = 'helproles_'.$num;
18668: $rolename = $env{'form.custhelpname'.$num};
18669: $rolename=~s/[^A-Za-z0-9]//gs;
18670: next if ($rolename eq '');
18671: next if (exists($existing{'rolesdef_'.$rolename}));
18672: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
18673: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
18674: $newprivs{'c'},$confname,$dom);
18675: if ($result ne 'ok') {
18676: $errors .= '<li><span class="LC_error">'.
18677: &mt('An error occurred storing the new custom role: [_1]',
18678: $result).'</span></li>';
18679: next;
18680: } else {
18681: $changedprivs{$rolename} = \%newprivs;
18682: $newrole = $rolename;
18683: }
18684: } else {
18685: $prefix = 'helproles_'.$num;
18686: $rolename = $env{'form.'.$prefix};
18687: next if ($rolename eq '');
18688: next unless (exists($existing{'rolesdef_'.$rolename}));
18689: $identifier = 'custhelp'.$num;
18690: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
18691: my %currprivs;
1.289 raeburn 18692: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 18693: split(/\_/,$existing{'rolesdef_'.$rolename});
18694: foreach my $level ('c','d','s') {
18695: if ($newprivs{$level} ne $currprivs{$level}) {
18696: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
18697: $newprivs{'c'},$confname,$dom);
18698: if ($result ne 'ok') {
18699: $errors .= '<li><span class="LC_error">'.
18700: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
18701: $rolename,$result).'</span></li>';
18702: } else {
18703: $changedprivs{$rolename} = \%newprivs;
18704: }
18705: last;
18706: }
18707: }
18708: if (ref($current{'adhoc'}) eq 'HASH') {
18709: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
18710: %curr = %{$current{'adhoc'}{$rolename}};
18711: }
18712: }
18713: }
18714: my $newpos = $env{'form.'.$prefix.'_pos'};
18715: $newpos =~ s/\D+//g;
18716: $allpos[$newpos] = $rolename;
18717: my $newdesc = $env{'form.'.$prefix.'_desc'};
18718: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
18719: if ($curr{'desc'}) {
18720: if ($curr{'desc'} ne $newdesc) {
18721: $changes{'customrole'}{$rolename}{'desc'} = 1;
18722: $newsettings{$rolename}{'desc'} = $newdesc;
18723: }
18724: } elsif ($newdesc ne '') {
18725: $changes{'customrole'}{$rolename}{'desc'} = 1;
18726: $newsettings{$rolename}{'desc'} = $newdesc;
18727: }
18728: my $access = $env{'form.'.$prefix.'_access'};
18729: if (grep(/^\Q$access\E$/,@accesstypes)) {
18730: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
18731: if ($access eq 'status') {
18732: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
18733: if (scalar(@statuses) == 0) {
1.289 raeburn 18734: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 18735: } else {
18736: my (@shownstatus,$numtypes);
18737: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
18738: if (ref($types) eq 'ARRAY') {
18739: $numtypes = scalar(@{$types});
18740: foreach my $type (sort(@statuses)) {
18741: if ($type eq 'default') {
18742: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
18743: } elsif (grep(/^\Q$type\E$/,@{$types})) {
18744: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
18745: push(@shownstatus,$usertypes->{$type});
18746: }
18747: }
18748: }
18749: if (grep(/^default$/,@statuses)) {
18750: push(@shownstatus,$othertitle);
18751: }
18752: if (scalar(@shownstatus) == 1+$numtypes) {
18753: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
18754: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
18755: } else {
18756: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
18757: if (ref($curr{'status'}) eq 'ARRAY') {
18758: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
18759: if (@diffs) {
18760: $changes{'customrole'}{$rolename}{$access} = 1;
18761: }
18762: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
18763: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 18764: }
1.166 raeburn 18765: }
18766: }
1.285 raeburn 18767: } elsif (($access eq 'inc') || ($access eq 'exc')) {
18768: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
18769: my @newspecstaff;
18770: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
18771: foreach my $person (sort(@personnel)) {
18772: if ($domhelpdesk{$person}) {
18773: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
18774: }
18775: }
18776: if (ref($curr{$access}) eq 'ARRAY') {
18777: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
18778: if (@diffs) {
18779: $changes{'customrole'}{$rolename}{$access} = 1;
18780: }
18781: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
18782: $changes{'customrole'}{$rolename}{$access} = 1;
18783: }
18784: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
18785: my ($uname,$udom) = split(/:/,$person);
18786: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
18787: }
18788: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 18789: }
1.285 raeburn 18790: } else {
18791: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
18792: }
18793: unless ($curr{'access'} eq $access) {
18794: $changes{'customrole'}{$rolename}{'access'} = 1;
18795: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 18796: }
18797: }
1.285 raeburn 18798: if (@allpos > 0) {
18799: my $idx = 0;
18800: foreach my $rolename (@allpos) {
18801: if ($rolename ne '') {
18802: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
18803: if (ref($current{'adhoc'}) eq 'HASH') {
18804: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
18805: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
18806: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 18807: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 18808: }
18809: }
1.282 raeburn 18810: }
1.285 raeburn 18811: $idx ++;
1.166 raeburn 18812: }
18813: }
1.118 jms 18814: }
1.123 jms 18815: my $putresult;
18816: if (keys(%changes) > 0) {
1.166 raeburn 18817: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 18818: if ($putresult eq 'ok') {
1.285 raeburn 18819: if (ref($helphash{'helpsettings'}) eq 'HASH') {
18820: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
18821: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
18822: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
18823: }
18824: }
18825: my $cachetime = 24*60*60;
18826: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18827: if (ref($lastactref) eq 'HASH') {
18828: $lastactref->{'domdefaults'} = 1;
18829: }
18830: } else {
18831: $errors .= '<li><span class="LC_error">'.
18832: &mt('An error occurred storing the settings: [_1]',
18833: $putresult).'</span></li>';
18834: }
18835: }
18836: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
18837: $resulttext = &mt('Changes made:').'<ul>';
18838: my (%shownprivs,@levelorder);
18839: @levelorder = ('c','d','s');
18840: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 18841: foreach my $item (sort(keys(%changes))) {
18842: if ($item eq 'submitbugs') {
18843: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
18844: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
18845: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 18846: } elsif ($item eq 'customrole') {
18847: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 18848: my @keyorder = ('order','desc','access','status','exc','inc');
18849: my %keytext = &Apache::lonlocal::texthash(
18850: order => 'Order',
18851: desc => 'Role description',
18852: access => 'Role usage',
1.300 droeschl 18853: status => 'Allowed institutional types',
1.285 raeburn 18854: exc => 'Allowed personnel',
18855: inc => 'Disallowed personnel',
18856: );
1.282 raeburn 18857: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 18858: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
18859: if ($role eq $newrole) {
18860: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
18861: $role).'<ul>';
18862: } else {
18863: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
18864: $role).'<ul>';
18865: }
18866: foreach my $key (@keyorder) {
18867: if ($changes{'customrole'}{$role}{$key}) {
18868: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
18869: $keytext{$key},$newsettings{$role}{$key}).
18870: '</li>';
18871: }
18872: }
18873: if (ref($changedprivs{$role}) eq 'HASH') {
18874: $shownprivs{$role} = 1;
18875: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
18876: foreach my $level (@levelorder) {
18877: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
18878: next if ($item eq '');
18879: my ($priv) = split(/\&/,$item,2);
18880: if (&Apache::lonnet::plaintext($priv)) {
18881: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
18882: unless ($level eq 'c') {
18883: $resulttext .= ' ('.$lt{$level}.')';
18884: }
18885: $resulttext .= '</li>';
18886: }
18887: }
18888: }
18889: $resulttext .= '</ul>';
18890: }
18891: $resulttext .= '</ul></li>';
18892: }
18893: }
18894: }
18895: }
18896: }
18897: }
18898: if (keys(%changedprivs)) {
18899: foreach my $role (sort(keys(%changedprivs))) {
18900: unless ($shownprivs{$role}) {
18901: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
18902: $role).'<ul>'.
18903: '<li>'.&mt('Privileges set to :').'<ul>';
18904: foreach my $level (@levelorder) {
18905: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
18906: next if ($item eq '');
18907: my ($priv) = split(/\&/,$item,2);
18908: if (&Apache::lonnet::plaintext($priv)) {
18909: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
18910: unless ($level eq 'c') {
18911: $resulttext .= ' ('.$lt{$level}.')';
18912: }
18913: $resulttext .= '</li>';
18914: }
1.282 raeburn 18915: }
18916: }
1.285 raeburn 18917: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 18918: }
18919: }
18920: }
1.285 raeburn 18921: $resulttext .= '</ul>';
18922: } else {
18923: $resulttext = &mt('No changes made to help settings');
1.118 jms 18924: }
18925: if ($errors) {
1.168 raeburn 18926: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 18927: $errors.'</ul>';
1.118 jms 18928: }
18929: return $resulttext;
18930: }
18931:
1.121 raeburn 18932: sub modify_coursedefaults {
1.212 raeburn 18933: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 18934: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 18935: my %defaultchecked = (
18936: 'canuse_pdfforms' => 'off',
18937: 'uselcmath' => 'on',
18938: 'usejsme' => 'on'
18939: );
18940: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 18941: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 18942: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
18943: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
18944: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 18945: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 18946: my %staticdefaults = (
18947: anonsurvey_threshold => 10,
18948: uploadquota => 500,
1.257 raeburn 18949: postsubmit => 60,
1.276 raeburn 18950: mysqltables => 172800,
1.198 raeburn 18951: );
1.314 raeburn 18952: my %texoptions = (
18953: MathJax => 'MathJax',
18954: mimetex => &mt('Convert to Images'),
18955: tth => &mt('TeX to HTML'),
18956: );
1.121 raeburn 18957: $defaultshash{'coursedefaults'} = {};
18958:
18959: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
18960: if ($domconfig{'coursedefaults'} eq '') {
18961: $domconfig{'coursedefaults'} = {};
18962: }
18963: }
18964:
18965: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
18966: foreach my $item (@toggles) {
18967: if ($defaultchecked{$item} eq 'on') {
18968: if (($domconfig{'coursedefaults'}{$item} eq '') &&
18969: ($env{'form.'.$item} eq '0')) {
18970: $changes{$item} = 1;
1.192 raeburn 18971: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 18972: $changes{$item} = 1;
18973: }
18974: } elsif ($defaultchecked{$item} eq 'off') {
18975: if (($domconfig{'coursedefaults'}{$item} eq '') &&
18976: ($env{'form.'.$item} eq '1')) {
18977: $changes{$item} = 1;
18978: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
18979: $changes{$item} = 1;
18980: }
18981: }
18982: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
18983: }
1.198 raeburn 18984: foreach my $item (@numbers) {
18985: my ($currdef,$newdef);
1.208 raeburn 18986: $newdef = $env{'form.'.$item};
1.198 raeburn 18987: if ($item eq 'anonsurvey_threshold') {
18988: $currdef = $domconfig{'coursedefaults'}{$item};
18989: $newdef =~ s/\D//g;
18990: if ($newdef eq '' || $newdef < 1) {
18991: $newdef = 1;
18992: }
18993: $defaultshash{'coursedefaults'}{$item} = $newdef;
18994: } else {
1.276 raeburn 18995: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
18996: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
18997: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 18998: }
18999: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 19000: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 19001: }
19002: if ($currdef ne $newdef) {
19003: if ($item eq 'anonsurvey_threshold') {
19004: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
19005: $changes{$item} = 1;
19006: }
1.276 raeburn 19007: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 19008: my $setting = $1;
1.276 raeburn 19009: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
19010: $changes{$setting} = 1;
1.198 raeburn 19011: }
19012: }
1.139 raeburn 19013: }
19014: }
1.314 raeburn 19015: my $texengine;
19016: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
19017: $texengine = $env{'form.texengine'};
1.349 raeburn 19018: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
19019: if ($currdef eq '') {
19020: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 19021: $changes{'texengine'} = 1;
19022: }
1.349 raeburn 19023: } elsif ($currdef ne $texengine) {
1.314 raeburn 19024: $changes{'texengine'} = 1;
19025: }
19026: }
19027: if ($texengine ne '') {
19028: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
19029: }
1.264 raeburn 19030: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
19031: my @currclonecode;
19032: if (ref($currclone) eq 'HASH') {
19033: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
19034: @currclonecode = @{$currclone->{'instcode'}};
19035: }
19036: }
19037: my $newclone;
1.289 raeburn 19038: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 19039: $newclone = $env{'form.canclone'};
19040: }
19041: if ($newclone eq 'instcode') {
19042: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
19043: my (%codedefaults,@code_order,@clonecode);
19044: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
19045: \@code_order);
19046: foreach my $item (@code_order) {
19047: if (grep(/^\Q$item\E$/,@newcodes)) {
19048: push(@clonecode,$item);
19049: }
19050: }
19051: if (@clonecode) {
19052: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
19053: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
19054: if (@diffs) {
19055: $changes{'canclone'} = 1;
19056: }
19057: } else {
19058: $newclone eq '';
19059: }
19060: } elsif ($newclone ne '') {
1.289 raeburn 19061: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
19062: }
1.264 raeburn 19063: if ($newclone ne $currclone) {
19064: $changes{'canclone'} = 1;
19065: }
1.257 raeburn 19066: my %credits;
19067: foreach my $type (@types) {
19068: unless ($type eq 'community') {
19069: $credits{$type} = $env{'form.'.$type.'_credits'};
19070: $credits{$type} =~ s/[^\d.]+//g;
19071: }
19072: }
19073: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
19074: ($env{'form.coursecredits'} eq '1')) {
19075: $changes{'coursecredits'} = 1;
19076: foreach my $type (keys(%credits)) {
19077: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
19078: }
19079: } else {
1.289 raeburn 19080: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 19081: foreach my $type (@types) {
19082: unless ($type eq 'community') {
1.289 raeburn 19083: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 19084: $changes{'coursecredits'} = 1;
19085: }
19086: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
19087: }
19088: }
19089: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
19090: foreach my $type (@types) {
19091: unless ($type eq 'community') {
19092: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
19093: $changes{'coursecredits'} = 1;
19094: last;
19095: }
19096: }
19097: }
19098: }
19099: }
19100: if ($env{'form.postsubmit'} eq '1') {
19101: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
19102: my %currtimeout;
19103: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19104: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
19105: $changes{'postsubmit'} = 1;
19106: }
19107: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19108: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
19109: }
19110: } else {
19111: $changes{'postsubmit'} = 1;
19112: }
19113: foreach my $type (@types) {
19114: my $timeout = $env{'form.'.$type.'_timeout'};
19115: $timeout =~ s/\D//g;
19116: if ($timeout == $staticdefaults{'postsubmit'}) {
19117: $timeout = '';
19118: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
19119: $timeout = '0';
19120: }
19121: unless ($timeout eq '') {
19122: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
19123: }
19124: if (exists($currtimeout{$type})) {
19125: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 19126: $changes{'postsubmit'} = 1;
1.257 raeburn 19127: }
19128: } elsif ($timeout ne '') {
19129: $changes{'postsubmit'} = 1;
19130: }
19131: }
19132: } else {
19133: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
19134: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19135: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
19136: $changes{'postsubmit'} = 1;
19137: }
19138: } else {
19139: $changes{'postsubmit'} = 1;
19140: }
1.192 raeburn 19141: }
1.121 raeburn 19142: }
19143: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
19144: $dom);
19145: if ($putresult eq 'ok') {
19146: if (keys(%changes) > 0) {
1.213 raeburn 19147: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 19148: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 19149: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314 raeburn 19150: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
19151: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257 raeburn 19152: if ($changes{$item}) {
19153: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
19154: }
1.289 raeburn 19155: }
1.192 raeburn 19156: if ($changes{'coursecredits'}) {
19157: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 19158: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
19159: $domdefaults{$type.'credits'} =
19160: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
19161: }
19162: }
19163: }
19164: if ($changes{'postsubmit'}) {
19165: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19166: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
19167: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19168: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
19169: $domdefaults{$type.'postsubtimeout'} =
19170: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
19171: }
19172: }
1.192 raeburn 19173: }
19174: }
1.198 raeburn 19175: if ($changes{'uploadquota'}) {
19176: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
19177: foreach my $type (@types) {
19178: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
19179: }
19180: }
19181: }
1.264 raeburn 19182: if ($changes{'canclone'}) {
19183: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
19184: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
19185: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
19186: if (@clonecodes) {
19187: $domdefaults{'canclone'} = join('+',@clonecodes);
19188: }
19189: }
19190: } else {
19191: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
19192: }
19193: }
1.121 raeburn 19194: my $cachetime = 24*60*60;
19195: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 19196: if (ref($lastactref) eq 'HASH') {
19197: $lastactref->{'domdefaults'} = 1;
19198: }
1.121 raeburn 19199: }
19200: $resulttext = &mt('Changes made:').'<ul>';
19201: foreach my $item (sort(keys(%changes))) {
19202: if ($item eq 'canuse_pdfforms') {
19203: if ($env{'form.'.$item} eq '1') {
19204: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
19205: } else {
19206: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
19207: }
1.257 raeburn 19208: } elsif ($item eq 'uselcmath') {
19209: if ($env{'form.'.$item} eq '1') {
19210: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
19211: } else {
19212: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
19213: }
19214: } elsif ($item eq 'usejsme') {
19215: if ($env{'form.'.$item} eq '1') {
19216: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
19217: } else {
1.289 raeburn 19218: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 19219: }
1.314 raeburn 19220: } elsif ($item eq 'texengine') {
19221: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
19222: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
19223: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
19224: }
1.139 raeburn 19225: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 19226: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 19227: } elsif ($item eq 'uploadquota') {
19228: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
19229: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
19230: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
19231: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 19232: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 19233: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 19234: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
19235: '</ul>'.
19236: '</li>';
19237: } else {
19238: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
19239: }
1.276 raeburn 19240: } elsif ($item eq 'mysqltables') {
19241: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
19242: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
19243: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
19244: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
19245: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
19246: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
19247: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
19248: '</ul>'.
19249: '</li>';
19250: } else {
19251: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
19252: }
1.257 raeburn 19253: } elsif ($item eq 'postsubmit') {
19254: if ($domdefaults{'postsubmit'} eq 'off') {
19255: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
19256: } else {
19257: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 19258: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 19259: $resulttext .= &mt('durations:').'<ul>';
19260: foreach my $type (@types) {
19261: $resulttext .= '<li>';
19262: my $timeout;
19263: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19264: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
19265: }
19266: my $display;
19267: if ($timeout eq '0') {
19268: $display = &mt('unlimited');
19269: } elsif ($timeout eq '') {
19270: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
19271: } else {
19272: $display = &mt('[quant,_1,second]',$timeout);
19273: }
19274: if ($type eq 'community') {
19275: $resulttext .= &mt('Communities');
19276: } elsif ($type eq 'official') {
19277: $resulttext .= &mt('Official courses');
19278: } elsif ($type eq 'unofficial') {
19279: $resulttext .= &mt('Unofficial courses');
19280: } elsif ($type eq 'textbook') {
19281: $resulttext .= &mt('Textbook courses');
1.271 raeburn 19282: } elsif ($type eq 'placement') {
19283: $resulttext .= &mt('Placement tests');
1.257 raeburn 19284: }
19285: $resulttext .= ' -- '.$display.'</li>';
19286: }
19287: $resulttext .= '</ul>';
19288: }
1.289 raeburn 19289: $resulttext .= '</li>';
1.257 raeburn 19290: }
1.192 raeburn 19291: } elsif ($item eq 'coursecredits') {
19292: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
19293: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 19294: ($domdefaults{'unofficialcredits'} eq '') &&
19295: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 19296: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
19297: } else {
19298: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
19299: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
19300: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 19301: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 19302: '</ul>'.
19303: '</li>';
19304: }
19305: } else {
19306: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
19307: }
1.264 raeburn 19308: } elsif ($item eq 'canclone') {
19309: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
19310: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
19311: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
19312: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
19313: }
19314: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
19315: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
19316: } else {
1.289 raeburn 19317: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 19318: }
1.140 raeburn 19319: }
1.121 raeburn 19320: }
19321: $resulttext .= '</ul>';
19322: } else {
19323: $resulttext = &mt('No changes made to course defaults');
19324: }
19325: } else {
19326: $resulttext = '<span class="LC_error">'.
19327: &mt('An error occurred: [_1]',$putresult).'</span>';
19328: }
19329: return $resulttext;
19330: }
19331:
1.231 raeburn 19332: sub modify_selfenrollment {
19333: my ($dom,$lastactref,%domconfig) = @_;
19334: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 19335: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 19336: my %titles = &tool_titles();
1.232 raeburn 19337: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
19338: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 19339: $ordered{'default'} = ['types','registered','approval','limit'];
19340:
19341: my (%roles,%shown,%toplevel);
19342: $roles{'0'} = &Apache::lonnet::plaintext('dc');
19343:
19344: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
19345: if ($domconfig{'selfenrollment'} eq '') {
19346: $domconfig{'selfenrollment'} = {};
19347: }
19348: }
19349: %toplevel = (
19350: admin => 'Configuration Rights',
19351: default => 'Default settings',
19352: validation => 'Validation of self-enrollment requests',
19353: );
1.233 raeburn 19354: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 19355:
19356: if (ref($ordered{'admin'}) eq 'ARRAY') {
19357: foreach my $item (@{$ordered{'admin'}}) {
19358: foreach my $type (@types) {
19359: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
19360: $selfenrollhash{'admin'}{$type}{$item} = 1;
19361: } else {
19362: $selfenrollhash{'admin'}{$type}{$item} = 0;
19363: }
19364: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
19365: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
19366: if ($selfenrollhash{'admin'}{$type}{$item} ne
19367: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
19368: push(@{$changes{'admin'}{$type}},$item);
19369: }
19370: } else {
19371: if (!$selfenrollhash{'admin'}{$type}{$item}) {
19372: push(@{$changes{'admin'}{$type}},$item);
19373: }
19374: }
19375: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
19376: push(@{$changes{'admin'}{$type}},$item);
19377: }
19378: }
19379: }
19380: }
19381:
19382: foreach my $item (@{$ordered{'default'}}) {
19383: foreach my $type (@types) {
19384: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
19385: if ($item eq 'types') {
19386: unless (($value eq 'all') || ($value eq 'dom')) {
19387: $value = '';
19388: }
19389: } elsif ($item eq 'registered') {
19390: unless ($value eq '1') {
19391: $value = 0;
19392: }
19393: } elsif ($item eq 'approval') {
19394: unless ($value =~ /^[012]$/) {
19395: $value = 0;
19396: }
19397: } else {
19398: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
19399: $value = 'none';
19400: }
19401: }
19402: $selfenrollhash{'default'}{$type}{$item} = $value;
19403: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
19404: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
19405: if ($selfenrollhash{'default'}{$type}{$item} ne
19406: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
19407: push(@{$changes{'default'}{$type}},$item);
19408: }
19409: } else {
19410: push(@{$changes{'default'}{$type}},$item);
19411: }
19412: } else {
19413: push(@{$changes{'default'}{$type}},$item);
19414: }
19415: if ($item eq 'limit') {
19416: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
19417: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
19418: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
19419: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
19420: }
19421: } else {
19422: $selfenrollhash{'default'}{$type}{'cap'} = '';
19423: }
19424: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
19425: if ($selfenrollhash{'default'}{$type}{'cap'} ne
19426: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
19427: push(@{$changes{'default'}{$type}},'cap');
19428: }
19429: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
19430: push(@{$changes{'default'}{$type}},'cap');
19431: }
19432: }
19433: }
19434: }
19435:
19436: foreach my $item (@{$itemsref}) {
19437: if ($item eq 'fields') {
19438: my @changed;
19439: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
19440: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
19441: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
19442: }
19443: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
19444: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
19445: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
19446: $domconfig{'selfenrollment'}{'validation'}{$item});
19447: } else {
19448: @changed = @{$selfenrollhash{'validation'}{$item}};
19449: }
19450: } else {
19451: @changed = @{$selfenrollhash{'validation'}{$item}};
19452: }
19453: if (@changed) {
19454: if ($selfenrollhash{'validation'}{$item}) {
19455: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
19456: } else {
19457: $changes{'validation'}{$item} = &mt('None');
19458: }
19459: }
19460: } else {
19461: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
19462: if ($item eq 'markup') {
19463: if ($env{'form.selfenroll_validation_'.$item}) {
19464: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
19465: }
19466: }
19467: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
19468: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
19469: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
19470: }
19471: }
19472: }
19473: }
19474:
19475: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
19476: $dom);
19477: if ($putresult eq 'ok') {
19478: if (keys(%changes) > 0) {
19479: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
19480: $resulttext = &mt('Changes made:').'<ul>';
19481: foreach my $key ('admin','default','validation') {
19482: if (ref($changes{$key}) eq 'HASH') {
19483: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
19484: if ($key eq 'validation') {
19485: foreach my $item (@{$itemsref}) {
19486: if (exists($changes{$key}{$item})) {
19487: if ($item eq 'markup') {
19488: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
19489: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
19490: } else {
19491: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
19492: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
19493: }
19494: }
19495: }
19496: } else {
19497: foreach my $type (@types) {
19498: if ($type eq 'community') {
19499: $roles{'1'} = &mt('Community personnel');
19500: } else {
19501: $roles{'1'} = &mt('Course personnel');
19502: }
19503: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 19504: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
19505: if ($key eq 'admin') {
19506: my @mgrdc = ();
19507: if (ref($ordered{$key}) eq 'ARRAY') {
19508: foreach my $item (@{$ordered{'admin'}}) {
19509: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
19510: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
19511: push(@mgrdc,$item);
19512: }
19513: }
19514: }
19515: if (@mgrdc) {
19516: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
19517: } else {
19518: delete($domdefaults{$type.'selfenrolladmdc'});
19519: }
19520: }
19521: } else {
19522: if (ref($ordered{$key}) eq 'ARRAY') {
19523: foreach my $item (@{$ordered{$key}}) {
19524: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
19525: $domdefaults{$type.'selfenroll'.$item} =
19526: $selfenrollhash{$key}{$type}{$item};
19527: }
19528: }
19529: }
19530: }
19531: }
1.231 raeburn 19532: $resulttext .= '<li>'.$titles{$type}.'<ul>';
19533: foreach my $item (@{$ordered{$key}}) {
19534: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
19535: $resulttext .= '<li>';
19536: if ($key eq 'admin') {
19537: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
19538: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
19539: } else {
19540: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
19541: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
19542: }
19543: $resulttext .= '</li>';
19544: }
19545: }
19546: $resulttext .= '</ul></li>';
19547: }
19548: }
19549: $resulttext .= '</ul></li>';
19550: }
19551: }
1.305 raeburn 19552: }
19553: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
19554: my $cachetime = 24*60*60;
19555: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19556: if (ref($lastactref) eq 'HASH') {
19557: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 19558: }
1.231 raeburn 19559: }
19560: $resulttext .= '</ul>';
19561: } else {
19562: $resulttext = &mt('No changes made to self-enrollment settings');
19563: }
19564: } else {
19565: $resulttext = '<span class="LC_error">'.
19566: &mt('An error occurred: [_1]',$putresult).'</span>';
19567: }
19568: return $resulttext;
19569: }
19570:
1.373 ! raeburn 19571: sub modify_wafproxy {
! 19572: my ($dom,$action,$lastactref,%domconfig) = @_;
! 19573: my %servers = &Apache::lonnet::internet_dom_servers($dom);
! 19574: my (%othercontrol,%canset,%values,%curralias,%currvalue,@warnings,%wafproxy,
! 19575: %changes,%expirecache);
! 19576: foreach my $server (sort(keys(%servers))) {
! 19577: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
! 19578: if ($serverhome eq $server) {
! 19579: my $serverdom = &Apache::lonnet::host_domain($server);
! 19580: if ($serverdom eq $dom) {
! 19581: $canset{$server} = 1;
! 19582: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
! 19583: %{$values{$dom}} = ();
! 19584: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
! 19585: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
! 19586: }
! 19587: foreach my $item ('ipheader','trusted','exempt') {
! 19588: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
! 19589: }
! 19590: }
! 19591: }
! 19592: }
! 19593: }
! 19594: my $output;
! 19595: if (keys(%canset)) {
! 19596: %{$wafproxy{'alias'}} = ();
! 19597: foreach my $key (sort(keys(%canset))) {
! 19598: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
! 19599: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
! 19600: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
! 19601: $changes{'alias'} = 1;
! 19602: }
! 19603: if ($wafproxy{'alias'}{$key} eq '') {
! 19604: if ($curralias{$key}) {
! 19605: $expirecache{$key} = 1;
! 19606: }
! 19607: delete($wafproxy{'alias'}{$key});
! 19608: }
! 19609: }
! 19610: unless (keys(%{$wafproxy{'alias'}})) {
! 19611: delete($wafproxy{'alias'});
! 19612: }
! 19613: # Localization for values in %warn occus in &mt() calls separately.
! 19614: my %warn = (
! 19615: trusted => 'trusted IP range(s)',
! 19616: exempt => 'exempt IP range(s)',
! 19617: );
! 19618: foreach my $item ('ipheader','trusted','exempt') {
! 19619: my $possible = $env{'form.wafproxy_'.$item};
! 19620: $possible =~ s/^\s+|\s+$//g;
! 19621: if ($possible ne '') {
! 19622: if ($item eq 'ipheader') {
! 19623: $wafproxy{$item} = $possible;
! 19624: } else {
! 19625: my (@ok,$count);
! 19626: $possible =~ s/[\r\n]+/\s/g;
! 19627: $possible =~ s/\s*-\s*/-/g;
! 19628: $possible =~ s/\s+/,/g;
! 19629: $count = 0;
! 19630: if ($possible) {
! 19631: foreach my $poss (split(/\,/,$possible)) {
! 19632: $count ++;
! 19633: if (&validate_ip_pattern($poss)) {
! 19634: push(@ok,$poss);
! 19635: }
! 19636: }
! 19637: if (@ok) {
! 19638: $wafproxy{$item} = join(',',@ok);
! 19639: }
! 19640: my $diff = $count - scalar(@ok);
! 19641: if ($diff) {
! 19642: push(@warnings,'<li>'.
! 19643: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
! 19644: $diff,$warn{$item}).
! 19645: '</li>');
! 19646: }
! 19647: if ($wafproxy{$item} ne $currvalue{$item}) {
! 19648: $changes{$item} = 1;
! 19649: }
! 19650: }
! 19651: }
! 19652: } else {
! 19653: if ($currvalue{$item}) {
! 19654: $changes{$item} = 1;
! 19655: }
! 19656: }
! 19657: }
! 19658: }
! 19659: if (keys(%changes)) {
! 19660: my %defaultshash = (
! 19661: wafproxy => \%wafproxy,
! 19662: );
! 19663: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
! 19664: $dom);
! 19665: if ($putresult eq 'ok') {
! 19666: my $cachetime = 24*60*60;
! 19667: my (%domdefaults,$updatedomdefs);
! 19668: foreach my $item ('ipheader','trusted','exempt') {
! 19669: if ($changes{$item}) {
! 19670: unless ($updatedomdefs) {
! 19671: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
! 19672: $updatedomdefs = 1;
! 19673: }
! 19674: if ($wafproxy{$item}) {
! 19675: $domdefaults{'waf_'.$item} = $wafproxy{$item};
! 19676: } elsif (exists($domdefaults{'waf_'.$item})) {
! 19677: delete($domdefaults{'waf_'.$item});
! 19678: }
! 19679: }
! 19680: }
! 19681: if ($updatedomdefs) {
! 19682: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
! 19683: if (ref($lastactref) eq 'HASH') {
! 19684: $lastactref->{'domdefaults'} = 1;
! 19685: }
! 19686: }
! 19687: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
! 19688: my %updates = %expirecache;
! 19689: foreach my $key (keys(%expirecache)) {
! 19690: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
! 19691: }
! 19692: if (ref($wafproxy{'alias'}) eq 'HASH') {
! 19693: my $cachetime = 24*60*60;
! 19694: foreach my $key (keys(%{$wafproxy{'alias'}})) {
! 19695: $updates{$key} = 1;
! 19696: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
! 19697: $cachetime);
! 19698: }
! 19699: }
! 19700: if (ref($lastactref) eq 'HASH') {
! 19701: $lastactref->{'proxyalias'} = \%updates;
! 19702: }
! 19703: }
! 19704: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
! 19705: foreach my $item ('alias','ipheader','trusted','exempt') {
! 19706: if ($changes{$item}) {
! 19707: if ($item eq 'alias') {
! 19708: my $numaliased = 0;
! 19709: if (ref($wafproxy{'alias'}) eq 'HASH') {
! 19710: my $shown;
! 19711: if (keys(%{$wafproxy{'alias'}})) {
! 19712: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
! 19713: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
! 19714: &Apache::lonnet::hostname($server),
! 19715: $wafproxy{'alias'}{$server}).'</li>';
! 19716: $numaliased ++;
! 19717: }
! 19718: if ($numaliased) {
! 19719: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
! 19720: '<ul>'.$shown.'</ul>').'</li>';
! 19721: }
! 19722: }
! 19723: }
! 19724: unless ($numaliased) {
! 19725: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
! 19726: }
! 19727: } else {
! 19728: if ($item eq 'ipheader') {
! 19729: if ($wafproxy{$item}) {
! 19730: $output .= '<li>'.&mt('Custom request header set to [_1]',
! 19731: $wafproxy{$item}).'</li>';
! 19732: } else {
! 19733: $output .= '<li>'.&mt('Custom request header deleted').'</li>';
! 19734: }
! 19735: } elsif ($item eq 'trusted') {
! 19736: if ($wafproxy{$item}) {
! 19737: $output .= '<li>'.&mt('Trusted IP range(s) set to [_1]',
! 19738: $wafproxy{$item}).'</li>';
! 19739: } else {
! 19740: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
! 19741: }
! 19742: } elsif ($item eq 'exempt') {
! 19743: if ($wafproxy{$item}) {
! 19744: $output .= '<li>'.&mt('Exempt IP range(s) set to [_1]',
! 19745: $wafproxy{$item}).'</li>';
! 19746: } else {
! 19747: $output .= '<li>'.&mt('Exempt IP range(s) deleted').'</li>';
! 19748: }
! 19749: }
! 19750: }
! 19751: }
! 19752: }
! 19753: } else {
! 19754: $output = '<span class="LC_error">'.
! 19755: &mt('An error occurred: [_1]',$putresult).'</span>';
! 19756: }
! 19757: } elsif (keys(%canset)) {
! 19758: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
! 19759: }
! 19760: if (@warnings) {
! 19761: $output .= '<br />'.&mt('Warnings:').'<ul>'.
! 19762: join("\n",@warnings).'</ul>';
! 19763: }
! 19764: return $output;
! 19765: }
! 19766:
! 19767: sub validate_ip_pattern {
! 19768: my ($pattern) = @_;
! 19769: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
! 19770: my ($start,$end) = ($1,$2);
! 19771: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
! 19772: return 1;
! 19773: }
! 19774: } elsif (&Net::CIDR::cidrvalidate($pattern)) {
! 19775: return 1;
! 19776: }
! 19777: return
! 19778: }
! 19779:
1.137 raeburn 19780: sub modify_usersessions {
1.212 raeburn 19781: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 19782: my @hostingtypes = ('version','excludedomain','includedomain');
19783: my @offloadtypes = ('primary','default');
19784: my %types = (
19785: remote => \@hostingtypes,
19786: hosted => \@hostingtypes,
19787: spares => \@offloadtypes,
19788: );
19789: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 19790: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 19791: my (%by_ip,%by_location,@intdoms,@instdoms);
19792: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 19793: my @locations = sort(keys(%by_location));
1.137 raeburn 19794: my (%defaultshash,%changes);
19795: foreach my $prefix (@prefixes) {
19796: $defaultshash{'usersessions'}{$prefix} = {};
19797: }
1.212 raeburn 19798: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 19799: my $resulttext;
1.138 raeburn 19800: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 19801: foreach my $prefix (@prefixes) {
1.145 raeburn 19802: next if ($prefix eq 'spares');
19803: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 19804: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
19805: if ($type eq 'version') {
19806: my $value = $env{'form.'.$prefix.'_'.$type};
19807: my $okvalue;
19808: if ($value ne '') {
19809: if (grep(/^\Q$value\E$/,@lcversions)) {
19810: $okvalue = $value;
19811: }
19812: }
19813: if (ref($domconfig{'usersessions'}) eq 'HASH') {
19814: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
19815: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
19816: if ($inuse == 0) {
19817: $changes{$prefix}{$type} = 1;
19818: } else {
19819: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
19820: $changes{$prefix}{$type} = 1;
19821: }
19822: if ($okvalue ne '') {
19823: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
19824: }
19825: }
19826: } else {
19827: if (($inuse == 1) && ($okvalue ne '')) {
19828: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
19829: $changes{$prefix}{$type} = 1;
19830: }
19831: }
19832: } else {
19833: if (($inuse == 1) && ($okvalue ne '')) {
19834: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
19835: $changes{$prefix}{$type} = 1;
19836: }
19837: }
19838: } else {
19839: if (($inuse == 1) && ($okvalue ne '')) {
19840: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
19841: $changes{$prefix}{$type} = 1;
19842: }
19843: }
19844: } else {
19845: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
19846: my @okvals;
19847: foreach my $val (@vals) {
1.138 raeburn 19848: if ($val =~ /:/) {
19849: my @items = split(/:/,$val);
19850: foreach my $item (@items) {
19851: if (ref($by_location{$item}) eq 'ARRAY') {
19852: push(@okvals,$item);
19853: }
19854: }
19855: } else {
19856: if (ref($by_location{$val}) eq 'ARRAY') {
19857: push(@okvals,$val);
19858: }
1.137 raeburn 19859: }
19860: }
19861: @okvals = sort(@okvals);
19862: if (ref($domconfig{'usersessions'}) eq 'HASH') {
19863: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
19864: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
19865: if ($inuse == 0) {
19866: $changes{$prefix}{$type} = 1;
19867: } else {
19868: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
19869: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
19870: if (@changed > 0) {
19871: $changes{$prefix}{$type} = 1;
19872: }
19873: }
19874: } else {
19875: if ($inuse == 1) {
19876: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
19877: $changes{$prefix}{$type} = 1;
19878: }
19879: }
19880: } else {
19881: if ($inuse == 1) {
19882: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
19883: $changes{$prefix}{$type} = 1;
19884: }
19885: }
19886: } else {
19887: if ($inuse == 1) {
19888: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
19889: $changes{$prefix}{$type} = 1;
19890: }
19891: }
19892: }
19893: }
19894: }
1.145 raeburn 19895:
19896: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 19897: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 19898: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
19899: my $savespares;
19900:
19901: foreach my $lonhost (sort(keys(%servers))) {
19902: my $serverhomeID =
19903: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 19904: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 19905: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
19906: my %spareschg;
19907: foreach my $type (@{$types{'spares'}}) {
19908: my @okspares;
19909: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
19910: foreach my $server (@checked) {
1.152 raeburn 19911: if (&Apache::lonnet::hostname($server) ne '') {
19912: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
19913: unless (grep(/^\Q$server\E$/,@okspares)) {
19914: push(@okspares,$server);
19915: }
1.145 raeburn 19916: }
19917: }
19918: }
19919: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
19920: my $newspare;
1.152 raeburn 19921: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
19922: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 19923: $newspare = $new;
19924: }
19925: }
1.152 raeburn 19926: my @spares;
19927: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
19928: @spares = sort(@okspares,$newspare);
19929: } else {
19930: @spares = sort(@okspares);
19931: }
19932: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 19933: if (ref($spareid{$lonhost}) eq 'HASH') {
19934: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 19935: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 19936: if (@diffs > 0) {
19937: $spareschg{$type} = 1;
19938: }
19939: }
19940: }
19941: }
19942: if (keys(%spareschg) > 0) {
19943: $changes{'spares'}{$lonhost} = \%spareschg;
19944: }
19945: }
1.261 raeburn 19946: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 19947: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 19948: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
19949: my @okoffload;
19950: if (@offloadnow) {
19951: foreach my $server (@offloadnow) {
19952: if (&Apache::lonnet::hostname($server) ne '') {
19953: unless (grep(/^\Q$server\E$/,@okoffload)) {
19954: push(@okoffload,$server);
19955: }
19956: }
19957: }
19958: if (@okoffload) {
19959: foreach my $lonhost (@okoffload) {
19960: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
19961: }
19962: }
19963: }
1.371 raeburn 19964: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
19965: my @okoffloadoth;
19966: if (@offloadoth) {
19967: foreach my $server (@offloadoth) {
19968: if (&Apache::lonnet::hostname($server) ne '') {
19969: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
19970: push(@okoffloadoth,$server);
19971: }
19972: }
19973: }
19974: if (@okoffloadoth) {
19975: foreach my $lonhost (@okoffloadoth) {
19976: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
19977: }
19978: }
19979: }
1.145 raeburn 19980: if (ref($domconfig{'usersessions'}) eq 'HASH') {
19981: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
19982: if (ref($changes{'spares'}) eq 'HASH') {
19983: if (keys(%{$changes{'spares'}}) > 0) {
19984: $savespares = 1;
19985: }
19986: }
19987: } else {
19988: $savespares = 1;
19989: }
1.371 raeburn 19990: foreach my $offload ('offloadnow','offloadoth') {
19991: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
19992: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
19993: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
19994: $changes{$offload} = 1;
19995: last;
19996: }
1.261 raeburn 19997: }
1.371 raeburn 19998: unless ($changes{$offload}) {
19999: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
20000: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
20001: $changes{$offload} = 1;
20002: last;
20003: }
1.261 raeburn 20004: }
20005: }
1.371 raeburn 20006: } else {
20007: if (($offload eq 'offloadnow') && (@okoffload)) {
20008: $changes{'offloadnow'} = 1;
20009: }
20010: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
20011: $changes{'offloadoth'} = 1;
20012: }
20013: }
20014: }
20015: } else {
20016: if (@okoffload) {
1.261 raeburn 20017: $changes{'offloadnow'} = 1;
20018: }
1.371 raeburn 20019: if (@okoffloadoth) {
20020: $changes{'offloadoth'} = 1;
20021: }
1.145 raeburn 20022: }
1.147 raeburn 20023: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
20024: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 20025: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20026: $dom);
20027: if ($putresult eq 'ok') {
20028: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
20029: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
20030: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
20031: }
20032: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
20033: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
20034: }
1.261 raeburn 20035: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
20036: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
20037: }
1.371 raeburn 20038: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
20039: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
20040: }
1.137 raeburn 20041: }
20042: my $cachetime = 24*60*60;
20043: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 20044: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 20045: if (ref($lastactref) eq 'HASH') {
20046: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 20047: $lastactref->{'usersessions'} = 1;
1.212 raeburn 20048: }
1.147 raeburn 20049: if (keys(%changes) > 0) {
20050: my %lt = &usersession_titles();
20051: $resulttext = &mt('Changes made:').'<ul>';
20052: foreach my $prefix (@prefixes) {
20053: if (ref($changes{$prefix}) eq 'HASH') {
20054: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
20055: if ($prefix eq 'spares') {
20056: if (ref($changes{$prefix}) eq 'HASH') {
20057: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
20058: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 20059: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 20060: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
20061: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 20062: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
20063: foreach my $type (@{$types{$prefix}}) {
20064: if ($changes{$prefix}{$lonhost}{$type}) {
20065: my $offloadto = &mt('None');
20066: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
20067: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
20068: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
20069: }
1.145 raeburn 20070: }
1.147 raeburn 20071: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 20072: }
1.137 raeburn 20073: }
20074: }
1.147 raeburn 20075: $resulttext .= '</li>';
1.137 raeburn 20076: }
20077: }
1.147 raeburn 20078: } else {
20079: foreach my $type (@{$types{$prefix}}) {
20080: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 20081: my ($newvalue,$notinuse);
1.147 raeburn 20082: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
20083: if (ref($defaultshash{'usersessions'}{$prefix})) {
20084: if ($type eq 'version') {
20085: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 20086: } else {
20087: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
20088: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
20089: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
20090: }
20091: } else {
20092: $notinuse = 1;
1.147 raeburn 20093: }
1.145 raeburn 20094: }
20095: }
20096: }
1.147 raeburn 20097: if ($newvalue eq '') {
20098: if ($type eq 'version') {
20099: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 20100: } elsif ($notinuse) {
20101: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 20102: } else {
20103: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
20104: }
1.145 raeburn 20105: } else {
1.147 raeburn 20106: if ($type eq 'version') {
1.344 raeburn 20107: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 20108: }
20109: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 20110: }
1.137 raeburn 20111: }
20112: }
20113: }
1.147 raeburn 20114: $resulttext .= '</ul>';
1.137 raeburn 20115: }
20116: }
1.261 raeburn 20117: if ($changes{'offloadnow'}) {
20118: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
20119: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 20120: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 20121: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
20122: $resulttext .= '<li>'.$lonhost.'</li>';
20123: }
20124: $resulttext .= '</ul>';
20125: } else {
1.371 raeburn 20126: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
20127: }
20128: } else {
20129: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
20130: }
20131: }
20132: if ($changes{'offloadoth'}) {
20133: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
20134: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
20135: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
20136: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
20137: $resulttext .= '<li>'.$lonhost.'</li>';
20138: }
20139: $resulttext .= '</ul>';
20140: } else {
20141: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 20142: }
20143: } else {
1.371 raeburn 20144: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 20145: }
20146: }
1.147 raeburn 20147: $resulttext .= '</ul>';
20148: } else {
20149: $resulttext = $nochgmsg;
1.137 raeburn 20150: }
20151: } else {
20152: $resulttext = '<span class="LC_error">'.
20153: &mt('An error occurred: [_1]',$putresult).'</span>';
20154: }
20155: } else {
1.147 raeburn 20156: $resulttext = $nochgmsg;
1.137 raeburn 20157: }
20158: return $resulttext;
20159: }
20160:
1.275 raeburn 20161: sub modify_ssl {
20162: my ($dom,$lastactref,%domconfig) = @_;
20163: my (%by_ip,%by_location,@intdoms,@instdoms);
20164: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
20165: my @locations = sort(keys(%by_location));
20166: my %servers = &Apache::lonnet::internet_dom_servers($dom);
20167: my (%defaultshash,%changes);
20168: my $action = 'ssl';
1.293 raeburn 20169: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 20170: foreach my $prefix (@prefixes) {
20171: $defaultshash{$action}{$prefix} = {};
20172: }
20173: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
20174: my $resulttext;
20175: my %iphost = &Apache::lonnet::get_iphost();
20176: my @reptypes = ('certreq','nocertreq');
20177: my @connecttypes = ('dom','intdom','other');
20178: my %types = (
1.293 raeburn 20179: connto => \@connecttypes,
20180: connfrom => \@connecttypes,
20181: replication => \@reptypes,
1.275 raeburn 20182: );
20183: foreach my $prefix (sort(keys(%types))) {
20184: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 20185: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 20186: my $value = 'yes';
20187: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
20188: $value = $env{'form.'.$prefix.'_'.$type};
20189: }
1.335 raeburn 20190: if (ref($domconfig{$action}) eq 'HASH') {
20191: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
20192: if ($domconfig{$action}{$prefix}{$type} ne '') {
20193: if ($value ne $domconfig{$action}{$prefix}{$type}) {
20194: $changes{$prefix}{$type} = 1;
20195: }
20196: $defaultshash{$action}{$prefix}{$type} = $value;
20197: } else {
20198: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 20199: $changes{$prefix}{$type} = 1;
20200: }
20201: } else {
20202: $defaultshash{$action}{$prefix}{$type} = $value;
20203: $changes{$prefix}{$type} = 1;
20204: }
20205: } else {
20206: $defaultshash{$action}{$prefix}{$type} = $value;
20207: $changes{$prefix}{$type} = 1;
20208: }
20209: if (($type eq 'dom') && (keys(%servers) == 1)) {
20210: delete($changes{$prefix}{$type});
20211: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
20212: delete($changes{$prefix}{$type});
20213: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
20214: delete($changes{$prefix}{$type});
20215: }
20216: } elsif ($prefix eq 'replication') {
20217: if (@locations > 0) {
20218: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
20219: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
20220: my @okvals;
20221: foreach my $val (@vals) {
20222: if ($val =~ /:/) {
20223: my @items = split(/:/,$val);
20224: foreach my $item (@items) {
20225: if (ref($by_location{$item}) eq 'ARRAY') {
20226: push(@okvals,$item);
20227: }
20228: }
20229: } else {
20230: if (ref($by_location{$val}) eq 'ARRAY') {
20231: push(@okvals,$val);
20232: }
20233: }
20234: }
20235: @okvals = sort(@okvals);
20236: if (ref($domconfig{$action}) eq 'HASH') {
20237: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
20238: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
20239: if ($inuse == 0) {
20240: $changes{$prefix}{$type} = 1;
20241: } else {
20242: $defaultshash{$action}{$prefix}{$type} = \@okvals;
20243: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
20244: if (@changed > 0) {
20245: $changes{$prefix}{$type} = 1;
20246: }
20247: }
20248: } else {
20249: if ($inuse == 1) {
20250: $defaultshash{$action}{$prefix}{$type} = \@okvals;
20251: $changes{$prefix}{$type} = 1;
20252: }
20253: }
20254: } else {
20255: if ($inuse == 1) {
20256: $defaultshash{$action}{$prefix}{$type} = \@okvals;
20257: $changes{$prefix}{$type} = 1;
20258: }
20259: }
20260: } else {
20261: if ($inuse == 1) {
20262: $defaultshash{$action}{$prefix}{$type} = \@okvals;
20263: $changes{$prefix}{$type} = 1;
20264: }
20265: }
20266: }
20267: }
20268: }
20269: }
1.336 raeburn 20270: if (keys(%changes)) {
20271: foreach my $prefix (keys(%changes)) {
20272: if (ref($changes{$prefix}) eq 'HASH') {
20273: if (scalar(keys(%{$changes{$prefix}})) == 0) {
20274: delete($changes{$prefix});
20275: }
20276: } else {
20277: delete($changes{$prefix});
20278: }
20279: }
20280: }
1.275 raeburn 20281: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
20282: if (keys(%changes) > 0) {
20283: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20284: $dom);
20285: if ($putresult eq 'ok') {
20286: if (ref($defaultshash{$action}) eq 'HASH') {
20287: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
20288: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
20289: }
1.293 raeburn 20290: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 20291: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 20292: }
20293: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 20294: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 20295: }
20296: }
20297: my $cachetime = 24*60*60;
20298: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20299: if (ref($lastactref) eq 'HASH') {
20300: $lastactref->{'domdefaults'} = 1;
20301: }
20302: if (keys(%changes) > 0) {
20303: my %titles = &ssl_titles();
20304: $resulttext = &mt('Changes made:').'<ul>';
20305: foreach my $prefix (@prefixes) {
20306: if (ref($changes{$prefix}) eq 'HASH') {
20307: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
20308: foreach my $type (@{$types{$prefix}}) {
20309: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 20310: my ($newvalue,$notinuse);
1.275 raeburn 20311: if (ref($defaultshash{$action}) eq 'HASH') {
20312: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 20313: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 20314: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 20315: } else {
20316: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
20317: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
20318: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
20319: }
20320: } else {
20321: $notinuse = 1;
1.275 raeburn 20322: }
20323: }
20324: }
1.344 raeburn 20325: if ($notinuse) {
20326: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
20327: } elsif ($newvalue eq '') {
1.275 raeburn 20328: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
20329: } else {
20330: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
20331: }
20332: }
20333: }
20334: }
20335: $resulttext .= '</ul>';
20336: }
20337: }
20338: } else {
20339: $resulttext = $nochgmsg;
20340: }
20341: } else {
20342: $resulttext = '<span class="LC_error">'.
20343: &mt('An error occurred: [_1]',$putresult).'</span>';
20344: }
20345: } else {
20346: $resulttext = $nochgmsg;
20347: }
20348: return $resulttext;
20349: }
20350:
1.279 raeburn 20351: sub modify_trust {
20352: my ($dom,$lastactref,%domconfig) = @_;
20353: my (%by_ip,%by_location,@intdoms,@instdoms);
20354: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
20355: my @locations = sort(keys(%by_location));
20356: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
20357: my @types = ('exc','inc');
20358: my (%defaultshash,%changes);
20359: foreach my $prefix (@prefixes) {
20360: $defaultshash{'trust'}{$prefix} = {};
20361: }
20362: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
20363: my $resulttext;
20364: foreach my $prefix (@prefixes) {
20365: foreach my $type (@types) {
20366: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
20367: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
20368: my @okvals;
20369: foreach my $val (@vals) {
20370: if ($val =~ /:/) {
20371: my @items = split(/:/,$val);
20372: foreach my $item (@items) {
20373: if (ref($by_location{$item}) eq 'ARRAY') {
20374: push(@okvals,$item);
20375: }
20376: }
20377: } else {
20378: if (ref($by_location{$val}) eq 'ARRAY') {
20379: push(@okvals,$val);
20380: }
20381: }
20382: }
20383: @okvals = sort(@okvals);
20384: if (ref($domconfig{'trust'}) eq 'HASH') {
20385: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
20386: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
20387: if ($inuse == 0) {
20388: $changes{$prefix}{$type} = 1;
20389: } else {
20390: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
20391: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
20392: if (@changed > 0) {
20393: $changes{$prefix}{$type} = 1;
20394: }
20395: }
20396: } else {
20397: if ($inuse == 1) {
20398: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
20399: $changes{$prefix}{$type} = 1;
20400: }
20401: }
20402: } else {
20403: if ($inuse == 1) {
20404: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
20405: $changes{$prefix}{$type} = 1;
20406: }
20407: }
20408: } else {
20409: if ($inuse == 1) {
20410: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
20411: $changes{$prefix}{$type} = 1;
20412: }
20413: }
20414: }
20415: }
20416: my $nochgmsg = &mt('No changes made to trust settings.');
20417: if (keys(%changes) > 0) {
20418: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20419: $dom);
20420: if ($putresult eq 'ok') {
20421: if (ref($defaultshash{'trust'}) eq 'HASH') {
20422: foreach my $prefix (@prefixes) {
20423: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
20424: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
20425: }
20426: }
20427: }
20428: my $cachetime = 24*60*60;
20429: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20430: if (ref($lastactref) eq 'HASH') {
20431: $lastactref->{'domdefaults'} = 1;
20432: }
20433: if (keys(%changes) > 0) {
20434: my %lt = &trust_titles();
20435: $resulttext = &mt('Changes made:').'<ul>';
20436: foreach my $prefix (@prefixes) {
20437: if (ref($changes{$prefix}) eq 'HASH') {
20438: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
20439: foreach my $type (@types) {
20440: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 20441: my ($newvalue,$notinuse);
1.279 raeburn 20442: if (ref($defaultshash{'trust'}) eq 'HASH') {
20443: if (ref($defaultshash{'trust'}{$prefix})) {
20444: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
20445: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
20446: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
20447: }
1.344 raeburn 20448: } else {
20449: $notinuse = 1;
1.279 raeburn 20450: }
20451: }
20452: }
1.344 raeburn 20453: if ($notinuse) {
20454: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
20455: } elsif ($newvalue eq '') {
1.279 raeburn 20456: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
20457: } else {
20458: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
20459: }
20460: }
20461: }
20462: $resulttext .= '</ul>';
20463: }
20464: }
20465: $resulttext .= '</ul>';
20466: } else {
20467: $resulttext = $nochgmsg;
20468: }
20469: } else {
20470: $resulttext = '<span class="LC_error">'.
20471: &mt('An error occurred: [_1]',$putresult).'</span>';
20472: }
20473: } else {
20474: $resulttext = $nochgmsg;
20475: }
20476: return $resulttext;
20477: }
20478:
1.150 raeburn 20479: sub modify_loadbalancing {
20480: my ($dom,%domconfig) = @_;
20481: my $primary_id = &Apache::lonnet::domain($dom,'primary');
20482: my $intdom = &Apache::lonnet::internet_dom($primary_id);
20483: my ($othertitle,$usertypes,$types) =
20484: &Apache::loncommon::sorted_inst_types($dom);
20485: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 20486: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 20487: my @sparestypes = ('primary','default');
20488: my %typetitles = &sparestype_titles();
20489: my $resulttext;
1.342 raeburn 20490: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 20491: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
20492: %existing = %{$domconfig{'loadbalancing'}};
20493: }
20494: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 20495: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 20496: my ($saveloadbalancing,%defaultshash,%changes);
20497: my ($alltypes,$othertypes,$titles) =
20498: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
20499: my %ruletitles = &offloadtype_text();
20500: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
20501: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
20502: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
20503: if ($balancer eq '') {
20504: next;
20505: }
1.210 raeburn 20506: if (!exists($servers{$balancer})) {
1.171 raeburn 20507: if (exists($currbalancer{$balancer})) {
20508: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 20509: }
1.171 raeburn 20510: next;
20511: }
20512: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
20513: push(@{$changes{'delete'}},$balancer);
20514: next;
20515: }
20516: if (!exists($currbalancer{$balancer})) {
20517: push(@{$changes{'add'}},$balancer);
20518: }
20519: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
20520: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
20521: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
20522: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
20523: $saveloadbalancing = 1;
20524: }
20525: foreach my $sparetype (@sparestypes) {
20526: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
20527: my @offloadto;
20528: foreach my $target (@targets) {
20529: if (($servers{$target}) && ($target ne $balancer)) {
20530: if ($sparetype eq 'default') {
20531: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
20532: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 20533: }
20534: }
1.171 raeburn 20535: unless(grep(/^\Q$target\E$/,@offloadto)) {
20536: push(@offloadto,$target);
20537: }
1.150 raeburn 20538: }
20539: }
1.284 raeburn 20540: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
20541: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
20542: push(@offloadto,$balancer);
20543: }
20544: }
20545: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 20546: }
1.342 raeburn 20547: if ($env{'form.loadbalancing_cookie_'.$i}) {
20548: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
20549: if (exists($currbalancer{$balancer})) {
20550: unless ($currcookies{$balancer}) {
20551: $changes{'curr'}{$balancer}{'cookie'} = 1;
20552: }
20553: }
20554: } elsif (exists($currbalancer{$balancer})) {
20555: if ($currcookies{$balancer}) {
20556: $changes{'curr'}{$balancer}{'cookie'} = 1;
20557: }
20558: }
1.171 raeburn 20559: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 20560: foreach my $sparetype (@sparestypes) {
1.171 raeburn 20561: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
20562: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 20563: if (@targetdiffs > 0) {
1.171 raeburn 20564: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 20565: }
1.171 raeburn 20566: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20567: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
20568: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 20569: }
20570: }
20571: }
20572: } else {
1.171 raeburn 20573: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 20574: foreach my $sparetype (@sparestypes) {
1.171 raeburn 20575: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20576: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
20577: $changes{'curr'}{$balancer}{'targets'} = 1;
20578: }
1.150 raeburn 20579: }
20580: }
1.210 raeburn 20581: }
1.150 raeburn 20582: }
20583: my $ishomedom;
1.171 raeburn 20584: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
20585: $ishomedom = 1;
1.150 raeburn 20586: }
20587: if (ref($alltypes) eq 'ARRAY') {
20588: foreach my $type (@{$alltypes}) {
20589: my $rule;
1.210 raeburn 20590: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 20591: (!$ishomedom)) {
1.171 raeburn 20592: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
20593: }
20594: if ($rule eq 'specific') {
1.255 raeburn 20595: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 20596: if (exists($servers{$specifiedhost})) {
1.255 raeburn 20597: $rule = $specifiedhost;
20598: }
1.150 raeburn 20599: }
1.171 raeburn 20600: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
20601: if (ref($currrules{$balancer}) eq 'HASH') {
20602: if ($rule ne $currrules{$balancer}{$type}) {
20603: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 20604: }
20605: } elsif ($rule ne '') {
1.171 raeburn 20606: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 20607: }
20608: }
20609: }
1.171 raeburn 20610: }
20611: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
20612: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
20613: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
20614: $defaultshash{'loadbalancing'} = {};
20615: }
20616: my $putresult = &Apache::lonnet::put_dom('configuration',
20617: \%defaultshash,$dom);
20618: if ($putresult eq 'ok') {
20619: if (keys(%changes) > 0) {
1.252 raeburn 20620: my %toupdate;
1.171 raeburn 20621: if (ref($changes{'delete'}) eq 'ARRAY') {
20622: foreach my $balancer (sort(@{$changes{'delete'}})) {
20623: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 20624: $toupdate{$balancer} = 1;
1.150 raeburn 20625: }
1.171 raeburn 20626: }
20627: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 20628: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 20629: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 20630: $toupdate{$balancer} = 1;
1.171 raeburn 20631: }
20632: }
20633: if (ref($changes{'curr'}) eq 'HASH') {
20634: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 20635: $toupdate{$balancer} = 1;
1.171 raeburn 20636: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
20637: if ($changes{'curr'}{$balancer}{'targets'}) {
20638: my %offloadstr;
20639: foreach my $sparetype (@sparestypes) {
20640: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20641: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
20642: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
20643: }
20644: }
1.150 raeburn 20645: }
1.171 raeburn 20646: if (keys(%offloadstr) == 0) {
20647: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 20648: } else {
1.171 raeburn 20649: my $showoffload;
20650: foreach my $sparetype (@sparestypes) {
20651: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
20652: if (defined($offloadstr{$sparetype})) {
20653: $showoffload .= $offloadstr{$sparetype};
20654: } else {
20655: $showoffload .= &mt('None');
20656: }
20657: $showoffload .= (' 'x3);
20658: }
20659: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 20660: }
20661: }
20662: }
1.171 raeburn 20663: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
20664: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
20665: foreach my $type (@{$alltypes}) {
20666: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
20667: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
20668: my $balancetext;
20669: if ($rule eq '') {
20670: $balancetext = $ruletitles{'default'};
1.209 raeburn 20671: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 20672: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 20673: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 20674: foreach my $sparetype (@sparestypes) {
20675: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20676: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
20677: }
20678: }
1.253 raeburn 20679: foreach my $item (@{$alltypes}) {
20680: next if ($item =~ /^_LC_ipchange/);
20681: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
20682: if ($hasrule eq 'homeserver') {
20683: map { $toupdate{$_} = 1; } (keys(%libraryservers));
20684: } else {
20685: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
20686: if ($servers{$hasrule}) {
20687: $toupdate{$hasrule} = 1;
20688: }
20689: }
20690: }
20691: }
1.254 raeburn 20692: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
20693: $balancetext = $ruletitles{$rule};
20694: } else {
20695: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
20696: $balancetext = $ruletitles{'particular'}.' '.$receiver;
20697: if ($receiver) {
20698: $toupdate{$receiver};
20699: }
20700: }
20701: } else {
20702: $balancetext = $ruletitles{$rule};
1.252 raeburn 20703: }
1.171 raeburn 20704: } else {
20705: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
20706: }
1.210 raeburn 20707: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 20708: }
20709: }
20710: }
20711: }
1.342 raeburn 20712: if ($changes{'curr'}{$balancer}{'cookie'}) {
20713: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
20714: $balancer).'</li>';
20715: }
1.252 raeburn 20716: if (keys(%toupdate)) {
20717: my %thismachine;
20718: my $updatedhere;
20719: my $cachetime = 60*60*24;
20720: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
20721: foreach my $lonhost (keys(%toupdate)) {
20722: if ($thismachine{$lonhost}) {
20723: unless ($updatedhere) {
20724: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
20725: $defaultshash{'loadbalancing'},
20726: $cachetime);
20727: $updatedhere = 1;
20728: }
20729: } else {
20730: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
20731: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
20732: }
20733: }
20734: }
1.150 raeburn 20735: }
1.171 raeburn 20736: }
20737: if ($resulttext ne '') {
20738: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 20739: } else {
20740: $resulttext = $nochgmsg;
20741: }
20742: } else {
1.171 raeburn 20743: $resulttext = $nochgmsg;
1.150 raeburn 20744: }
20745: } else {
1.171 raeburn 20746: $resulttext = '<span class="LC_error">'.
20747: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 20748: }
20749: } else {
1.171 raeburn 20750: $resulttext = $nochgmsg;
1.150 raeburn 20751: }
20752: return $resulttext;
20753: }
20754:
1.48 raeburn 20755: sub recurse_check {
20756: my ($chkcats,$categories,$depth,$name) = @_;
20757: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
20758: my $chg = 0;
20759: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
20760: my $category = $chkcats->[$depth]{$name}[$j];
20761: my $item;
20762: if ($category eq '') {
20763: $chg ++;
20764: } else {
20765: my $deeper = $depth + 1;
20766: $item = &escape($category).':'.&escape($name).':'.$depth;
20767: if ($chg) {
20768: $categories->{$item} -= $chg;
20769: }
20770: &recurse_check($chkcats,$categories,$deeper,$category);
20771: $deeper --;
20772: }
20773: }
20774: }
20775: return;
20776: }
20777:
20778: sub recurse_cat_deletes {
20779: my ($item,$coursecategories,$deletions) = @_;
20780: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
20781: my $subdepth = $depth + 1;
20782: if (ref($coursecategories) eq 'HASH') {
20783: foreach my $subitem (keys(%{$coursecategories})) {
20784: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
20785: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
20786: delete($coursecategories->{$subitem});
20787: $deletions->{$subitem} = 1;
20788: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 20789: }
1.48 raeburn 20790: }
20791: }
20792: return;
20793: }
20794:
1.125 raeburn 20795: sub active_dc_picker {
1.191 raeburn 20796: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 20797: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 20798: my @domcoord = keys(%domcoords);
20799: if (keys(%currhash)) {
20800: foreach my $dc (keys(%currhash)) {
20801: unless (exists($domcoords{$dc})) {
20802: push(@domcoord,$dc);
20803: }
20804: }
20805: }
20806: @domcoord = sort(@domcoord);
1.210 raeburn 20807: my $numdcs = scalar(@domcoord);
1.191 raeburn 20808: my $rows = 0;
20809: my $table;
1.125 raeburn 20810: if ($numdcs > 1) {
1.191 raeburn 20811: $table = '<table>';
20812: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 20813: my $rem = $i%($numinrow);
20814: if ($rem == 0) {
20815: if ($i > 0) {
1.191 raeburn 20816: $table .= '</tr>';
1.125 raeburn 20817: }
1.191 raeburn 20818: $table .= '<tr>';
20819: $rows ++;
1.125 raeburn 20820: }
1.191 raeburn 20821: my $check = '';
20822: if ($inputtype eq 'radio') {
20823: if (keys(%currhash) == 0) {
20824: if (!$i) {
20825: $check = ' checked="checked"';
20826: }
20827: } elsif (exists($currhash{$domcoord[$i]})) {
20828: $check = ' checked="checked"';
20829: }
20830: } else {
20831: if (exists($currhash{$domcoord[$i]})) {
20832: $check = ' checked="checked"';
1.125 raeburn 20833: }
20834: }
1.191 raeburn 20835: if ($i == @domcoord - 1) {
1.125 raeburn 20836: my $colsleft = $numinrow - $rem;
20837: if ($colsleft > 1) {
1.191 raeburn 20838: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 20839: } else {
1.191 raeburn 20840: $table .= '<td class="LC_left_item">';
1.125 raeburn 20841: }
20842: } else {
1.191 raeburn 20843: $table .= '<td class="LC_left_item">';
20844: }
20845: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
20846: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
20847: $table .= '<span class="LC_nobreak"><label>'.
20848: '<input type="'.$inputtype.'" name="'.$name.'"'.
20849: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
20850: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 20851: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 20852: }
1.219 raeburn 20853: $table .= '</label></span></td>';
1.191 raeburn 20854: }
20855: $table .= '</tr></table>';
20856: } elsif ($numdcs == 1) {
1.219 raeburn 20857: my ($dcname,$dcdom) = split(':',$domcoord[0]);
20858: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 20859: if ($inputtype eq 'radio') {
1.247 raeburn 20860: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 20861: if ($user ne $dcname.':'.$dcdom) {
20862: $table .= ' ('.$dcname.':'.$dcdom.')';
20863: }
1.191 raeburn 20864: } else {
20865: my $check;
20866: if (exists($currhash{$domcoord[0]})) {
20867: $check = ' checked="checked"';
1.125 raeburn 20868: }
1.247 raeburn 20869: $table = '<span class="LC_nobreak"><label>'.
20870: '<input type="checkbox" name="'.$name.'" '.
20871: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 20872: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 20873: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 20874: }
1.220 raeburn 20875: $table .= '</label></span>';
1.191 raeburn 20876: $rows ++;
1.125 raeburn 20877: }
20878: }
1.191 raeburn 20879: return ($numdcs,$table,$rows);
1.125 raeburn 20880: }
20881:
1.137 raeburn 20882: sub usersession_titles {
20883: return &Apache::lonlocal::texthash(
20884: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
20885: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 20886: spares => 'Servers offloaded to, when busy',
1.137 raeburn 20887: version => 'LON-CAPA version requirement',
1.138 raeburn 20888: excludedomain => 'Allow all, but exclude specific domains',
20889: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 20890: primary => 'Primary (checked first)',
1.154 raeburn 20891: default => 'Default',
1.137 raeburn 20892: );
20893: }
20894:
1.152 raeburn 20895: sub id_for_thisdom {
20896: my (%servers) = @_;
20897: my %altids;
20898: foreach my $server (keys(%servers)) {
20899: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
20900: if ($serverhome ne $server) {
20901: $altids{$serverhome} = $server;
20902: }
20903: }
20904: return %altids;
20905: }
20906:
1.150 raeburn 20907: sub count_servers {
20908: my ($currbalancer,%servers) = @_;
20909: my (@spares,$numspares);
20910: foreach my $lonhost (sort(keys(%servers))) {
20911: next if ($currbalancer eq $lonhost);
20912: push(@spares,$lonhost);
20913: }
20914: if ($currbalancer) {
20915: $numspares = scalar(@spares);
20916: } else {
20917: $numspares = scalar(@spares) - 1;
20918: }
20919: return ($numspares,@spares);
20920: }
20921:
20922: sub lonbalance_targets_js {
1.171 raeburn 20923: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 20924: my $select = &mt('Select');
20925: my ($alltargets,$allishome,$allinsttypes,@alltypes);
20926: if (ref($servers) eq 'HASH') {
20927: $alltargets = join("','",sort(keys(%{$servers})));
20928: my @homedoms;
20929: foreach my $server (sort(keys(%{$servers}))) {
20930: if (&Apache::lonnet::host_domain($server) eq $dom) {
20931: push(@homedoms,'1');
20932: } else {
20933: push(@homedoms,'0');
20934: }
20935: }
20936: $allishome = join("','",@homedoms);
20937: }
20938: if (ref($types) eq 'ARRAY') {
20939: if (@{$types} > 0) {
20940: @alltypes = @{$types};
20941: }
20942: }
20943: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
20944: $allinsttypes = join("','",@alltypes);
1.342 raeburn 20945: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 20946: if (ref($settings) eq 'HASH') {
20947: %existing = %{$settings};
20948: }
20949: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 20950: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 20951: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 20952: return <<"END";
20953:
20954: <script type="text/javascript">
20955: // <![CDATA[
20956:
1.171 raeburn 20957: currBalancers = new Array('$balancers');
20958:
20959: function toggleTargets(balnum) {
20960: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
20961: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
20962: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
20963: var prevbalancer = prevhostitem.value;
20964: var baltotal = document.getElementById('loadbalancing_total').value;
20965: prevhostitem.value = balancer;
20966: if (prevbalancer != '') {
20967: var prevIdx = currBalancers.indexOf(prevbalancer);
20968: if (prevIdx != -1) {
20969: currBalancers.splice(prevIdx,1);
20970: }
20971: }
1.150 raeburn 20972: if (balancer == '') {
1.171 raeburn 20973: hideSpares(balnum);
1.150 raeburn 20974: } else {
1.171 raeburn 20975: var currIdx = currBalancers.indexOf(balancer);
20976: if (currIdx == -1) {
20977: currBalancers.push(balancer);
20978: }
1.150 raeburn 20979: var homedoms = new Array('$allishome');
1.171 raeburn 20980: var ishomedom = homedoms[lonhostitem.selectedIndex];
20981: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 20982: }
1.171 raeburn 20983: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 20984: return;
20985: }
20986:
1.171 raeburn 20987: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 20988: var alltargets = new Array('$alltargets');
20989: var insttypes = new Array('$allinsttypes');
1.151 raeburn 20990: var offloadtypes = new Array('primary','default');
20991:
1.171 raeburn 20992: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
20993: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 20994:
1.151 raeburn 20995: for (var i=0; i<offloadtypes.length; i++) {
20996: var count = 0;
20997: for (var j=0; j<alltargets.length; j++) {
20998: if (alltargets[j] != balancer) {
1.171 raeburn 20999: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
21000: item.value = alltargets[j];
21001: item.style.textAlign='left';
21002: item.style.textFace='normal';
21003: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
21004: if (currBalancers.indexOf(alltargets[j]) == -1) {
21005: item.disabled = '';
21006: } else {
21007: item.disabled = 'disabled';
21008: item.checked = false;
21009: }
1.151 raeburn 21010: count ++;
21011: }
1.150 raeburn 21012: }
21013: }
1.151 raeburn 21014: for (var k=0; k<insttypes.length; k++) {
21015: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 21016: if (ishomedom == 1) {
1.171 raeburn 21017: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
21018: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 21019: } else {
1.171 raeburn 21020: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
21021: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 21022: }
21023: } else {
1.171 raeburn 21024: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
21025: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 21026: }
1.151 raeburn 21027: if ((insttypes[k] != '_LC_external') &&
21028: ((insttypes[k] != '_LC_internetdom') ||
21029: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 21030: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
21031: item.options.length = 0;
21032: item.options[0] = new Option("","",true,true);
1.210 raeburn 21033: var idx = 0;
1.151 raeburn 21034: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 21035: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
21036: idx ++;
21037: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 21038: }
21039: }
21040: }
21041: }
21042: return;
21043: }
21044:
1.171 raeburn 21045: function hideSpares(balnum) {
1.150 raeburn 21046: var alltargets = new Array('$alltargets');
21047: var insttypes = new Array('$allinsttypes');
21048: var offloadtypes = new Array('primary','default');
21049:
1.171 raeburn 21050: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
21051: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 21052:
21053: var total = alltargets.length - 1;
21054: for (var i=0; i<offloadtypes; i++) {
21055: for (var j=0; j<total; j++) {
1.171 raeburn 21056: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
21057: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
21058: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 21059: }
1.150 raeburn 21060: }
21061: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 21062: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
21063: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 21064: if (insttypes[k] != '_LC_external') {
1.171 raeburn 21065: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
21066: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 21067: }
21068: }
21069: return;
21070: }
21071:
1.171 raeburn 21072: function checkOffloads(item,balnum,type) {
1.150 raeburn 21073: var alltargets = new Array('$alltargets');
21074: var offloadtypes = new Array('primary','default');
21075: if (item.checked) {
21076: var total = alltargets.length - 1;
21077: var other;
21078: if (type == offloadtypes[0]) {
1.151 raeburn 21079: other = offloadtypes[1];
1.150 raeburn 21080: } else {
1.151 raeburn 21081: other = offloadtypes[0];
1.150 raeburn 21082: }
21083: for (var i=0; i<total; i++) {
1.171 raeburn 21084: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 21085: if (server == item.value) {
1.171 raeburn 21086: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
21087: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 21088: }
21089: }
21090: }
21091: }
21092: return;
21093: }
21094:
1.171 raeburn 21095: function singleServerToggle(balnum,type) {
21096: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 21097: if (offloadtoSelIdx == 0) {
1.171 raeburn 21098: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
21099: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 21100:
21101: } else {
1.171 raeburn 21102: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
21103: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 21104: }
21105: return;
21106: }
21107:
1.171 raeburn 21108: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 21109: if (type == '_LC_external') {
1.171 raeburn 21110: return;
1.150 raeburn 21111: }
1.171 raeburn 21112: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 21113: for (var i=0; i<typesRules.length; i++) {
21114: if (formname.elements[typesRules[i]].checked) {
21115: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 21116: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
21117: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 21118: } else {
1.171 raeburn 21119: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
21120: }
21121: }
21122: }
21123: return;
21124: }
21125:
21126: function balancerDeleteChange(balnum) {
21127: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
21128: var baltotal = document.getElementById('loadbalancing_total').value;
21129: var addtarget;
21130: var removetarget;
21131: var action = 'delete';
21132: if (document.getElementById('loadbalancing_delete_'+balnum)) {
21133: var lonhost = hostitem.value;
21134: var currIdx = currBalancers.indexOf(lonhost);
21135: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
21136: if (currIdx != -1) {
21137: currBalancers.splice(currIdx,1);
21138: }
21139: addtarget = lonhost;
21140: } else {
21141: if (currIdx == -1) {
21142: currBalancers.push(lonhost);
21143: }
21144: removetarget = lonhost;
21145: action = 'undelete';
21146: }
21147: balancerChange(balnum,baltotal,action,addtarget,removetarget);
21148: }
21149: return;
21150: }
21151:
21152: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
21153: if (baltotal > 1) {
21154: var offloadtypes = new Array('primary','default');
21155: var alltargets = new Array('$alltargets');
21156: var insttypes = new Array('$allinsttypes');
21157: for (var i=0; i<baltotal; i++) {
21158: if (i != balnum) {
21159: for (var j=0; j<offloadtypes.length; j++) {
21160: var total = alltargets.length - 1;
21161: for (var k=0; k<total; k++) {
21162: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
21163: var server = serveritem.value;
21164: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
21165: if (server == addtarget) {
21166: serveritem.disabled = '';
21167: }
21168: }
21169: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
21170: if (server == removetarget) {
21171: serveritem.disabled = 'disabled';
21172: serveritem.checked = false;
21173: }
21174: }
21175: }
21176: }
21177: for (var j=0; j<insttypes.length; j++) {
21178: if (insttypes[j] != '_LC_external') {
21179: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
21180: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
21181: var currSel = singleserver.selectedIndex;
21182: var currVal = singleserver.options[currSel].value;
21183: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
21184: var numoptions = singleserver.options.length;
21185: var needsnew = 1;
21186: for (var k=0; k<numoptions; k++) {
21187: if (singleserver.options[k] == addtarget) {
21188: needsnew = 0;
21189: break;
21190: }
21191: }
21192: if (needsnew == 1) {
21193: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
21194: }
21195: }
21196: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
21197: singleserver.options.length = 0;
21198: if ((currVal) && (currVal != removetarget)) {
21199: singleserver.options[0] = new Option("","",false,false);
21200: } else {
21201: singleserver.options[0] = new Option("","",true,true);
21202: }
21203: var idx = 0;
21204: for (var m=0; m<alltargets.length; m++) {
21205: if (currBalancers.indexOf(alltargets[m]) == -1) {
21206: idx ++;
21207: if (currVal == alltargets[m]) {
21208: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
21209: } else {
21210: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
21211: }
21212: }
21213: }
21214: }
21215: }
21216: }
21217: }
1.150 raeburn 21218: }
21219: }
21220: }
21221: return;
21222: }
21223:
1.152 raeburn 21224: // ]]>
21225: </script>
21226:
21227: END
21228: }
21229:
1.372 raeburn 21230:
1.152 raeburn 21231: sub new_spares_js {
21232: my @sparestypes = ('primary','default');
21233: my $types = join("','",@sparestypes);
21234: my $select = &mt('Select');
21235: return <<"END";
21236:
21237: <script type="text/javascript">
21238: // <![CDATA[
21239:
21240: function updateNewSpares(formname,lonhost) {
21241: var types = new Array('$types');
21242: var include = new Array();
21243: var exclude = new Array();
21244: for (var i=0; i<types.length; i++) {
21245: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
21246: for (var j=0; j<spareboxes.length; j++) {
21247: if (formname.elements[spareboxes[j]].checked) {
21248: exclude.push(formname.elements[spareboxes[j]].value);
21249: } else {
21250: include.push(formname.elements[spareboxes[j]].value);
21251: }
21252: }
21253: }
21254: for (var i=0; i<types.length; i++) {
21255: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
21256: var selIdx = newSpare.selectedIndex;
21257: var currnew = newSpare.options[selIdx].value;
21258: var okSpares = new Array();
21259: for (var j=0; j<newSpare.options.length; j++) {
21260: var possible = newSpare.options[j].value;
21261: if (possible != '') {
21262: if (exclude.indexOf(possible) == -1) {
21263: okSpares.push(possible);
21264: } else {
21265: if (currnew == possible) {
21266: selIdx = 0;
21267: }
21268: }
21269: }
21270: }
21271: for (var k=0; k<include.length; k++) {
21272: if (okSpares.indexOf(include[k]) == -1) {
21273: okSpares.push(include[k]);
21274: }
21275: }
21276: okSpares.sort();
21277: newSpare.options.length = 0;
21278: if (selIdx == 0) {
21279: newSpare.options[0] = new Option("$select","",true,true);
21280: } else {
21281: newSpare.options[0] = new Option("$select","",false,false);
21282: }
21283: for (var m=0; m<okSpares.length; m++) {
21284: var idx = m+1;
21285: var selThis = 0;
21286: if (selIdx != 0) {
21287: if (okSpares[m] == currnew) {
21288: selThis = 1;
21289: }
21290: }
21291: if (selThis == 1) {
21292: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
21293: } else {
21294: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
21295: }
21296: }
21297: }
21298: return;
21299: }
21300:
21301: function checkNewSpares(lonhost,type) {
21302: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
21303: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 21304: if (chosen != '') {
1.152 raeburn 21305: var othertype;
21306: var othernewSpare;
21307: if (type == 'primary') {
21308: othernewSpare = document.getElementById('newspare_default_'+lonhost);
21309: }
21310: if (type == 'default') {
21311: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
21312: }
21313: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
21314: othernewSpare.selectedIndex = 0;
21315: }
21316: }
21317: return;
21318: }
21319:
21320: // ]]>
21321: </script>
21322:
21323: END
21324:
21325: }
21326:
21327: sub common_domprefs_js {
21328: return <<"END";
21329:
21330: <script type="text/javascript">
21331: // <![CDATA[
21332:
1.150 raeburn 21333: function getIndicesByName(formname,item) {
1.152 raeburn 21334: var group = new Array();
1.150 raeburn 21335: for (var i=0;i<formname.elements.length;i++) {
21336: if (formname.elements[i].name == item) {
1.152 raeburn 21337: group.push(formname.elements[i].id);
1.150 raeburn 21338: }
21339: }
1.152 raeburn 21340: return group;
1.150 raeburn 21341: }
21342:
21343: // ]]>
21344: </script>
21345:
21346: END
1.152 raeburn 21347:
1.150 raeburn 21348: }
21349:
1.165 raeburn 21350: sub recaptcha_js {
21351: my %lt = &captcha_phrases();
21352: return <<"END";
21353:
21354: <script type="text/javascript">
21355: // <![CDATA[
21356:
21357: function updateCaptcha(caller,context) {
21358: var privitem;
21359: var pubitem;
21360: var privtext;
21361: var pubtext;
1.269 raeburn 21362: var versionitem;
21363: var versiontext;
1.165 raeburn 21364: if (document.getElementById(context+'_recaptchapub')) {
21365: pubitem = document.getElementById(context+'_recaptchapub');
21366: } else {
21367: return;
21368: }
21369: if (document.getElementById(context+'_recaptchapriv')) {
21370: privitem = document.getElementById(context+'_recaptchapriv');
21371: } else {
21372: return;
21373: }
21374: if (document.getElementById(context+'_recaptchapubtxt')) {
21375: pubtext = document.getElementById(context+'_recaptchapubtxt');
21376: } else {
21377: return;
21378: }
21379: if (document.getElementById(context+'_recaptchaprivtxt')) {
21380: privtext = document.getElementById(context+'_recaptchaprivtxt');
21381: } else {
21382: return;
21383: }
1.269 raeburn 21384: if (document.getElementById(context+'_recaptchaversion')) {
21385: versionitem = document.getElementById(context+'_recaptchaversion');
21386: } else {
21387: return;
21388: }
21389: if (document.getElementById(context+'_recaptchavertxt')) {
21390: versiontext = document.getElementById(context+'_recaptchavertxt');
21391: } else {
21392: return;
21393: }
1.165 raeburn 21394: if (caller.checked) {
21395: if (caller.value == 'recaptcha') {
21396: pubitem.type = 'text';
21397: privitem.type = 'text';
21398: pubitem.size = '40';
21399: privitem.size = '40';
21400: pubtext.innerHTML = "$lt{'pub'}";
21401: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 21402: versionitem.type = 'text';
21403: versionitem.size = '3';
1.289 raeburn 21404: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 21405: } else {
21406: pubitem.type = 'hidden';
21407: privitem.type = 'hidden';
1.269 raeburn 21408: versionitem.type = 'hidden';
1.165 raeburn 21409: pubtext.innerHTML = '';
21410: privtext.innerHTML = '';
1.269 raeburn 21411: versiontext.innerHTML = '';
1.165 raeburn 21412: }
21413: }
21414: return;
21415: }
21416:
21417: // ]]>
21418: </script>
21419:
21420: END
21421:
21422: }
21423:
1.236 raeburn 21424: sub toggle_display_js {
1.192 raeburn 21425: return <<"END";
21426:
21427: <script type="text/javascript">
21428: // <![CDATA[
21429:
1.236 raeburn 21430: function toggleDisplay(domForm,caller) {
21431: if (document.getElementById(caller)) {
21432: var divitem = document.getElementById(caller);
21433: var optionsElement = domForm.coursecredits;
1.264 raeburn 21434: var checkval = 1;
21435: var dispval = 'block';
1.303 raeburn 21436: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 21437: if (caller == 'emailoptions') {
1.372 raeburn 21438: optionsElement = domForm.cancreate_email;
1.236 raeburn 21439: }
1.257 raeburn 21440: if (caller == 'studentsubmission') {
21441: optionsElement = domForm.postsubmit;
21442: }
1.264 raeburn 21443: if (caller == 'cloneinstcode') {
21444: optionsElement = domForm.canclone;
21445: checkval = 'instcode';
21446: }
1.303 raeburn 21447: if (selfcreateRegExp.test(caller)) {
21448: optionsElement = domForm.elements[caller];
21449: checkval = 'other';
21450: dispval = 'inline'
21451: }
1.236 raeburn 21452: if (optionsElement.length) {
1.192 raeburn 21453: var currval;
1.236 raeburn 21454: for (var i=0; i<optionsElement.length; i++) {
21455: if (optionsElement[i].checked) {
21456: currval = optionsElement[i].value;
1.192 raeburn 21457: }
21458: }
1.264 raeburn 21459: if (currval == checkval) {
21460: divitem.style.display = dispval;
1.192 raeburn 21461: } else {
1.236 raeburn 21462: divitem.style.display = 'none';
1.192 raeburn 21463: }
21464: }
21465: }
21466: return;
21467: }
21468:
21469: // ]]>
21470: </script>
21471:
21472: END
21473:
21474: }
21475:
1.165 raeburn 21476: sub captcha_phrases {
21477: return &Apache::lonlocal::texthash (
21478: priv => 'Private key',
21479: pub => 'Public key',
21480: original => 'original (CAPTCHA)',
21481: recaptcha => 'successor (ReCAPTCHA)',
21482: notused => 'unused',
1.289 raeburn 21483: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 21484: );
21485: }
21486:
1.205 raeburn 21487: sub devalidate_remote_domconfs {
1.212 raeburn 21488: my ($dom,$cachekeys) = @_;
21489: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 21490: my %servers = &Apache::lonnet::internet_dom_servers($dom);
21491: my %thismachine;
21492: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 21493: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.373 ! raeburn 21494: 'directorysrch','passwdconf','cats','proxyalias');
1.260 raeburn 21495: if (keys(%servers)) {
1.205 raeburn 21496: foreach my $server (keys(%servers)) {
21497: next if ($thismachine{$server});
1.212 raeburn 21498: my @cached;
21499: foreach my $name (@posscached) {
21500: if ($cachekeys->{$name}) {
1.373 ! raeburn 21501: if ($name eq 'proxyalias') {
! 21502: if (ref($cachekeys->{$name}) eq 'HASH') {
! 21503: foreach my $key (keys(%{$cachekeys->{$name}})) {
! 21504: push(@cached,&escape($name).':'.&escape($key));
! 21505: }
! 21506: }
! 21507: } else {
! 21508: push(@cached,&escape($name).':'.&escape($dom));
! 21509: }
1.212 raeburn 21510: }
21511: }
21512: if (@cached) {
21513: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
21514: }
1.205 raeburn 21515: }
21516: }
21517: return;
21518: }
21519:
1.3 raeburn 21520: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>