Annotation of loncom/interface/domainprefs.pm, revision 1.382
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.382 ! raeburn 4: # $Id: domainprefs.pm,v 1.381 2021/04/18 02:08:46 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
1.286 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
1.297 raeburn 30: ###############################################################
1.1 raeburn 31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.210 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.197 raeburn 98: used by course owners to request creation of a course, and to display/store
1.223 bisitz 99: default quota sizes for Authoring Spaces.
1.101 raeburn 100:
101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
1.325 raeburn 107: (official, unofficial, community, textbook, placement, and lti).
1.271 raeburn 108: In each case the radio buttons allow the selection of one of four values:
1.101 raeburn 109:
1.104 raeburn 110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
1.104 raeburn 121: approval
1.101 raeburn 122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
1.143 raeburn 145: - course requests will be processed automatically up to a limit of
1.101 raeburn 146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
1.1 raeburn 158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
1.43 raeburn 166: use Apache::lonmsg();
1.91 raeburn 167: use Apache::lonconfigsettings;
1.232 raeburn 168: use Apache::lonuserutils();
1.235 raeburn 169: use Apache::loncoursequeueadmin();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.275 raeburn 173: use LONCAPA::SSL;
1.9 raeburn 174: use File::Copy;
1.43 raeburn 175: use Locale::Language;
1.62 raeburn 176: use DateTime::TimeZone;
1.68 raeburn 177: use DateTime::Locale;
1.267 raeburn 178: use Time::HiRes qw( sleep );
1.373 raeburn 179: use Net::CIDR;
1.1 raeburn 180:
1.155 raeburn 181: my $registered_cleanup;
182: my $modified_urls;
183:
1.1 raeburn 184: sub handler {
185: my $r=shift;
186: if ($r->header_only) {
187: &Apache::loncommon::content_type($r,'text/html');
188: $r->send_http_header;
189: return OK;
190: }
191:
1.91 raeburn 192: my $context = 'domain';
1.1 raeburn 193: my $dom = $env{'request.role.domain'};
1.5 albertel 194: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 195: if (&Apache::lonnet::allowed('mau',$dom)) {
196: &Apache::loncommon::content_type($r,'text/html');
197: $r->send_http_header;
198: } else {
199: $env{'user.error.msg'}=
200: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
201: return HTTP_NOT_ACCEPTABLE;
202: }
1.155 raeburn 203:
204: $registered_cleanup=0;
205: @{$modified_urls}=();
206:
1.1 raeburn 207: &Apache::lonhtmlcommon::clear_breadcrumbs();
208: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 209: ['phase','actions']);
1.30 raeburn 210: my $phase = 'pickactions';
1.3 raeburn 211: if ( exists($env{'form.phase'}) ) {
212: $phase = $env{'form.phase'};
213: }
1.150 raeburn 214: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 215: my %domconfig =
1.6 raeburn 216: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 217: 'quotas','autoenroll','autoupdate','autocreate',
218: 'directorysrch','usercreation','usermodification',
219: 'contacts','defaults','scantron','coursecategories',
220: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 221: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 222: 'requestauthor','selfenrollment','inststatus',
1.372 raeburn 223: 'ltitools','ssl','trust','lti','privacy','passwords',
1.373 raeburn 224: 'proctoring','wafproxy'],$dom);
1.320 raeburn 225: my %encconfig =
1.372 raeburn 226: &Apache::lonnet::get_dom('encconfig',['ltitools','lti','proctoring'],$dom);
1.297 raeburn 227: if (ref($domconfig{'ltitools'}) eq 'HASH') {
228: if (ref($encconfig{'ltitools'}) eq 'HASH') {
229: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
1.320 raeburn 230: if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
231: (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
1.297 raeburn 232: foreach my $item ('key','secret') {
233: $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
234: }
235: }
236: }
237: }
238: }
1.320 raeburn 239: if (ref($domconfig{'lti'}) eq 'HASH') {
240: if (ref($encconfig{'lti'}) eq 'HASH') {
241: foreach my $id (keys(%{$domconfig{'lti'}})) {
242: if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
243: (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
244: foreach my $item ('key','secret') {
245: $domconfig{'lti'}{$id}{$item} = $encconfig{'lti'}{$id}{$item};
246: }
247: }
248: }
249: }
250: }
1.372 raeburn 251: if (ref($domconfig{'proctoring'}) eq 'HASH') {
252: if (ref($encconfig{'proctoring'}) eq 'HASH') {
253: foreach my $provider (keys(%{$domconfig{'proctoring'}})) {
254: if ((ref($domconfig{'proctoring'}{$provider}) eq 'HASH') &&
255: (ref($encconfig{'proctoring'}{$provider}) eq 'HASH')) {
256: foreach my $item ('key','secret') {
257: $domconfig{'proctoring'}{$provider}{$item} = $encconfig{'proctoring'}{$provider}{$item};
258: }
259: }
260: }
261: }
262: }
1.373 raeburn 263: my @prefs_order = ('rolecolors','login','defaults','wafproxy','passwords','quotas',
264: 'autoenroll','autoupdate','autocreate','directorysrch',
265: 'contacts','privacy','usercreation','selfcreation',
1.374 raeburn 266: 'usermodification','scantron','requestcourses','requestauthor',
1.373 raeburn 267: 'coursecategories','serverstatuses','helpsettings','coursedefaults',
1.372 raeburn 268: 'ltitools','proctoring','selfenrollment','usersessions','ssl',
269: 'trust','lti');
1.171 raeburn 270: my %existing;
271: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
272: %existing = %{$domconfig{'loadbalancing'}};
273: }
274: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 275: push(@prefs_order,'loadbalancing');
276: }
1.30 raeburn 277: my %prefs = (
278: 'rolecolors' =>
279: { text => 'Default color schemes',
1.67 raeburn 280: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 281: header => [{col1 => 'Student Settings',
282: col2 => '',},
283: {col1 => 'Coordinator Settings',
284: col2 => '',},
285: {col1 => 'Author Settings',
286: col2 => '',},
287: {col1 => 'Administrator Settings',
288: col2 => '',}],
1.230 raeburn 289: print => \&print_rolecolors,
290: modify => \&modify_rolecolors,
1.30 raeburn 291: },
1.110 raeburn 292: 'login' =>
1.30 raeburn 293: { text => 'Log-in page options',
1.67 raeburn 294: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 295: header => [{col1 => 'Log-in Page Items',
296: col2 => '',},
297: {col1 => 'Log-in Help',
1.256 raeburn 298: col2 => 'Value'},
299: {col1 => 'Custom HTML in document head',
1.168 raeburn 300: col2 => 'Value'}],
1.230 raeburn 301: print => \&print_login,
302: modify => \&modify_login,
1.30 raeburn 303: },
1.43 raeburn 304: 'defaults' =>
1.236 raeburn 305: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 306: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 307: header => [{col1 => 'Setting',
1.236 raeburn 308: col2 => 'Value'},
309: {col1 => 'Institutional user types',
1.305 raeburn 310: col2 => 'Name displayed'}],
1.230 raeburn 311: print => \&print_defaults,
312: modify => \&modify_defaults,
1.43 raeburn 313: },
1.381 raeburn 314: 'wafproxy' =>
315: { text => 'Web Application Firewall/Reverse Proxy',
1.373 raeburn 316: help => 'Domain_Configuration_WAF_Proxy',
1.381 raeburn 317: header => [{col1 => 'Domain(s)',
318: col2 => 'Servers and WAF/Reverse Proxy alias(es)',
1.373 raeburn 319: },
1.381 raeburn 320: {col1 => 'Domain(s)',
321: col2 => 'WAF Configuration',}],
1.373 raeburn 322: print => \&print_wafproxy,
1.381 raeburn 323: modify => \&modify_wafproxy,
1.373 raeburn 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.381 raeburn 858: } elsif ($action eq 'wafproxy') {
859: $output .= &wafproxy_javascript($dom);
1.91 raeburn 860: }
1.236 raeburn 861: $output .=
1.30 raeburn 862: '<table class="LC_nested_outer">
1.3 raeburn 863: <tr>
1.306 raeburn 864: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 865: &mt($item->{text}).' '.
866: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
867: '</tr>';
1.30 raeburn 868: $rowtotal ++;
1.110 raeburn 869: my $numheaders = 1;
870: if (ref($item->{'header'}) eq 'ARRAY') {
871: $numheaders = scalar(@{$item->{'header'}});
872: }
873: if ($numheaders > 1) {
1.64 raeburn 874: my $colspan = '';
1.145 raeburn 875: my $rightcolspan = '';
1.369 raeburn 876: my $leftnobr = '';
1.238 raeburn 877: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 878: ($action eq 'directorysrch') ||
1.256 raeburn 879: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 880: $colspan = ' colspan="2"';
881: }
1.145 raeburn 882: if ($action eq 'usersessions') {
883: $rightcolspan = ' colspan="3"';
884: }
1.369 raeburn 885: if ($action eq 'passwords') {
886: $leftnobr = ' LC_nobreak';
887: }
1.30 raeburn 888: $output .= '
1.3 raeburn 889: <tr>
890: <td>
891: <table class="LC_nested">
892: <tr class="LC_info_row">
1.369 raeburn 893: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 894: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 895: </tr>';
1.69 raeburn 896: $rowtotal ++;
1.230 raeburn 897: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 898: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 899: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 900: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.373 raeburn 901: ($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'wafproxy')) {
1.230 raeburn 902: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354 raeburn 903: } elsif ($action eq 'passwords') {
904: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 905: } elsif ($action eq 'coursecategories') {
1.230 raeburn 906: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346 raeburn 907: } elsif ($action eq 'scantron') {
908: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 909: } elsif ($action eq 'login') {
1.256 raeburn 910: if ($numheaders == 4) {
1.168 raeburn 911: $colspan = ' colspan="2"';
912: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
913: } else {
914: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
915: }
1.230 raeburn 916: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 917: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 918: } elsif ($action eq 'rolecolors') {
1.30 raeburn 919: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 920: }
1.30 raeburn 921: $output .= '
1.6 raeburn 922: </table>
923: </td>
924: </tr>
925: <tr>
926: <td>
927: <table class="LC_nested">
928: <tr class="LC_info_row">
1.230 raeburn 929: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 930: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 931: </tr>';
932: $rowtotal ++;
1.230 raeburn 933: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
934: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 935: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.357 raeburn 936: ($action eq 'trust') || ($action eq 'contacts') ||
937: ($action eq 'privacy') || ($action eq 'passwords')) {
1.238 raeburn 938: if ($action eq 'coursecategories') {
939: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
940: $colspan = ' colspan="2"';
1.279 raeburn 941: } elsif ($action eq 'trust') {
942: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354 raeburn 943: } elsif ($action eq 'passwords') {
944: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.238 raeburn 945: } else {
946: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
947: }
1.279 raeburn 948: if ($action eq 'trust') {
949: $output .= '
950: </table>
951: </td>
952: </tr>';
953: my @trusthdrs = qw(2 3 4 5 6 7);
954: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
955: for (my $i=0; $i<@trusthdrs; $i++) {
956: $output .= '
957: <tr>
958: <td>
959: <table class="LC_nested">
960: <tr class="LC_info_row">
961: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
962: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
963: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
964: </table>
965: </td>
966: </tr>';
967: }
968: $output .= '
969: <tr>
970: <td>
971: <table class="LC_nested">
972: <tr class="LC_info_row">
973: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
974: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
975: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
976: } else {
977: $output .= '
1.63 raeburn 978: </table>
979: </td>
980: </tr>
981: <tr>
982: <td>
983: <table class="LC_nested">
984: <tr class="LC_info_row">
985: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 986: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 987: </tr>'."\n";
1.279 raeburn 988: if ($action eq 'coursecategories') {
989: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.357 raeburn 990: } elsif (($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'passwords')) {
1.354 raeburn 991: if ($action eq 'passwords') {
992: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
993: } else {
994: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
995: }
996: $output .= '
1.340 raeburn 997: </tr>
998: </table>
999: </td>
1000: </tr>
1001: <tr>
1002: <td>
1003: <table class="LC_nested">
1004: <tr class="LC_info_row">
1.369 raeburn 1005: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.354 raeburn 1006: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
1007: if ($action eq 'passwords') {
1008: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
1009: } else {
1010: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1011: }
1012: $output .= '
1.340 raeburn 1013: </table>
1014: </td>
1015: </tr>
1016: <tr>';
1.279 raeburn 1017: } else {
1018: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1019: }
1.238 raeburn 1020: }
1.63 raeburn 1021: $rowtotal ++;
1.236 raeburn 1022: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282 raeburn 1023: ($action eq 'defaults') || ($action eq 'directorysrch') ||
1.373 raeburn 1024: ($action eq 'helpsettings') || ($action eq 'wafproxy')) {
1.230 raeburn 1025: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346 raeburn 1026: } elsif ($action eq 'scantron') {
1027: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293 raeburn 1028: } elsif ($action eq 'ssl') {
1029: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
1030: </table>
1031: </td>
1032: </tr>
1033: <tr>
1034: <td>
1035: <table class="LC_nested">
1036: <tr class="LC_info_row">
1037: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1038: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1039: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
1040: </table>
1041: </td>
1042: </tr>
1043: <tr>
1044: <td>
1045: <table class="LC_nested">
1046: <tr class="LC_info_row">
1047: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1048: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
1049: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 1050: } elsif ($action eq 'login') {
1.256 raeburn 1051: if ($numheaders == 4) {
1.168 raeburn 1052: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
1053: </table>
1054: </td>
1055: </tr>
1056: <tr>
1057: <td>
1058: <table class="LC_nested">
1059: <tr class="LC_info_row">
1060: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 1061: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 1062: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1063: $rowtotal ++;
1064: } else {
1065: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1066: }
1.256 raeburn 1067: $output .= '
1068: </table>
1069: </td>
1070: </tr>
1071: <tr>
1072: <td>
1073: <table class="LC_nested">
1074: <tr class="LC_info_row">';
1075: if ($numheaders == 4) {
1076: $output .= '
1077: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1078: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1079: </tr>';
1080: } else {
1081: $output .= '
1082: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1083: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1084: </tr>';
1085: }
1086: $rowtotal ++;
1087: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1088: } elsif ($action eq 'requestcourses') {
1.247 raeburn 1089: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1090: $rowtotal ++;
1091: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 1092: </table>
1093: </td>
1094: </tr>
1095: <tr>
1096: <td>
1097: <table class="LC_nested">
1098: <tr class="LC_info_row">
1099: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1100: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 1101: &textbookcourses_javascript($settings).
1102: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1103: </table>
1104: </td>
1105: </tr>
1106: <tr>
1107: <td>
1108: <table class="LC_nested">
1109: <tr class="LC_info_row">
1110: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1111: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1112: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 1113: </table>
1114: </td>
1115: </tr>
1116: <tr>
1117: <td>
1118: <table class="LC_nested">
1119: <tr class="LC_info_row">
1.306 raeburn 1120: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1121: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1122: </tr>'.
1123: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1124: } elsif ($action eq 'requestauthor') {
1125: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1126: $rowtotal ++;
1.122 jms 1127: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1128: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1129: </table>
1130: </td>
1131: </tr>
1132: <tr>
1133: <td>
1134: <table class="LC_nested">
1135: <tr class="LC_info_row">
1.306 raeburn 1136: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1137: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1138: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1139: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1140: </tr>'.
1.30 raeburn 1141: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1142: </table>
1143: </td>
1144: </tr>
1145: <tr>
1146: <td>
1147: <table class="LC_nested">
1148: <tr class="LC_info_row">
1.59 bisitz 1149: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1150: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1151: </tr>'.
1.30 raeburn 1152: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1153: $rowtotal += 2;
1.6 raeburn 1154: }
1.3 raeburn 1155: } else {
1.30 raeburn 1156: $output .= '
1.3 raeburn 1157: <tr>
1158: <td>
1159: <table class="LC_nested">
1.30 raeburn 1160: <tr class="LC_info_row">';
1.277 raeburn 1161: if ($action eq 'login') {
1.30 raeburn 1162: $output .= '
1.59 bisitz 1163: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1164: } elsif ($action eq 'serverstatuses') {
1165: $output .= '
1.306 raeburn 1166: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1167: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1168:
1.6 raeburn 1169: } else {
1.30 raeburn 1170: $output .= '
1.306 raeburn 1171: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1172: }
1.72 raeburn 1173: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1174: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1175: &mt($item->{'header'}->[0]->{'col2'});
1176: if ($action eq 'serverstatuses') {
1177: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1178: }
1.69 raeburn 1179: } else {
1.306 raeburn 1180: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1181: &mt($item->{'header'}->[0]->{'col2'});
1182: }
1183: $output .= '</td>';
1184: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1185: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1186: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1187: &mt($item->{'header'}->[0]->{'col3'});
1188: } else {
1.306 raeburn 1189: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1190: &mt($item->{'header'}->[0]->{'col3'});
1191: }
1.69 raeburn 1192: if ($action eq 'serverstatuses') {
1193: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1194: }
1195: $output .= '</td>';
1.6 raeburn 1196: }
1.150 raeburn 1197: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1198: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1199: &mt($item->{'header'}->[0]->{'col4'});
1200: }
1.69 raeburn 1201: $output .= '</tr>';
1.48 raeburn 1202: $rowtotal ++;
1.168 raeburn 1203: if ($action eq 'quotas') {
1.86 raeburn 1204: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1205: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1206: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.372 raeburn 1207: ($action eq 'ltitools') || ($action eq 'lti') ||
1208: ($action eq 'proctoring')) {
1.230 raeburn 1209: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1210: }
1.3 raeburn 1211: }
1.30 raeburn 1212: $output .= '
1.3 raeburn 1213: </table>
1214: </td>
1215: </tr>
1.30 raeburn 1216: </table><br />';
1217: return ($output,$rowtotal);
1.1 raeburn 1218: }
1219:
1.3 raeburn 1220: sub print_login {
1.168 raeburn 1221: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 1222: my ($css_class,$datatable);
1.6 raeburn 1223: my %choices = &login_choices();
1.110 raeburn 1224:
1.168 raeburn 1225: if ($caller eq 'service') {
1.149 raeburn 1226: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1227: my $choice = $choices{'disallowlogin'};
1228: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1229: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1230: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1231: '<th>'.$choices{'server'}.'</th>'.
1232: '<th>'.$choices{'serverpath'}.'</th>'.
1233: '<th>'.$choices{'custompath'}.'</th>'.
1234: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1235: my %disallowed;
1236: if (ref($settings) eq 'HASH') {
1237: if (ref($settings->{'loginvia'}) eq 'HASH') {
1238: %disallowed = %{$settings->{'loginvia'}};
1239: }
1240: }
1241: foreach my $lonhost (sort(keys(%servers))) {
1242: my $direct = 'selected="selected"';
1.128 raeburn 1243: if (ref($disallowed{$lonhost}) eq 'HASH') {
1244: if ($disallowed{$lonhost}{'server'} ne '') {
1245: $direct = '';
1246: }
1.110 raeburn 1247: }
1.115 raeburn 1248: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1249: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1250: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1251: '</option>';
1.184 raeburn 1252: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1253: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1254: my $selected = '';
1.128 raeburn 1255: if (ref($disallowed{$lonhost}) eq 'HASH') {
1256: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1257: $selected = 'selected="selected"';
1258: }
1.110 raeburn 1259: }
1260: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1261: $servers{$hostid}.'</option>';
1262: }
1.128 raeburn 1263: $datatable .= '</select></td>'.
1264: '<td><select name="'.$lonhost.'_serverpath">';
1265: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1266: my $pathname = $path;
1267: if ($path eq 'custom') {
1268: $pathname = &mt('Custom Path').' ->';
1269: }
1270: my $selected = '';
1271: if (ref($disallowed{$lonhost}) eq 'HASH') {
1272: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1273: $selected = 'selected="selected"';
1274: }
1275: } elsif ($path eq '') {
1276: $selected = 'selected="selected"';
1277: }
1278: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1279: }
1280: $datatable .= '</select></td>';
1281: my ($custom,$exempt);
1282: if (ref($disallowed{$lonhost}) eq 'HASH') {
1283: $custom = $disallowed{$lonhost}{'custompath'};
1284: $exempt = $disallowed{$lonhost}{'exempt'};
1285: }
1286: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1287: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1288: '</tr>';
1.110 raeburn 1289: }
1290: $datatable .= '</table></td></tr>';
1291: return $datatable;
1.168 raeburn 1292: } elsif ($caller eq 'page') {
1293: my %defaultchecked = (
1294: 'coursecatalog' => 'on',
1.188 raeburn 1295: 'helpdesk' => 'on',
1.168 raeburn 1296: 'adminmail' => 'off',
1297: 'newuser' => 'off',
1298: );
1.188 raeburn 1299: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1300: my (%checkedon,%checkedoff);
1.42 raeburn 1301: foreach my $item (@toggles) {
1.168 raeburn 1302: if ($defaultchecked{$item} eq 'on') {
1303: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1304: $checkedoff{$item} = ' ';
1.168 raeburn 1305: } elsif ($defaultchecked{$item} eq 'off') {
1306: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1307: $checkedon{$item} = ' ';
1308: }
1.1 raeburn 1309: }
1.168 raeburn 1310: my @images = ('img','logo','domlogo','login');
1311: my @logintext = ('textcol','bgcol');
1312: my @bgs = ('pgbg','mainbg','sidebg');
1313: my @links = ('link','alink','vlink');
1314: my %designhash = &Apache::loncommon::get_domainconf($dom);
1315: my %defaultdesign = %Apache::loncommon::defaultdesign;
1316: my (%is_custom,%designs);
1317: my %defaults = (
1318: font => $defaultdesign{'login.font'},
1319: );
1.6 raeburn 1320: foreach my $item (@images) {
1.168 raeburn 1321: $defaults{$item} = $defaultdesign{'login.'.$item};
1322: $defaults{'showlogo'}{$item} = 1;
1323: }
1324: foreach my $item (@bgs) {
1325: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1326: }
1.41 raeburn 1327: foreach my $item (@logintext) {
1.168 raeburn 1328: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1329: }
1.168 raeburn 1330: foreach my $item (@links) {
1331: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1332: }
1.168 raeburn 1333: if (ref($settings) eq 'HASH') {
1334: foreach my $item (@toggles) {
1335: if ($settings->{$item} eq '1') {
1336: $checkedon{$item} = ' checked="checked" ';
1337: $checkedoff{$item} = ' ';
1338: } elsif ($settings->{$item} eq '0') {
1339: $checkedoff{$item} = ' checked="checked" ';
1340: $checkedon{$item} = ' ';
1341: }
1342: }
1343: foreach my $item (@images) {
1344: if (defined($settings->{$item})) {
1345: $designs{$item} = $settings->{$item};
1346: $is_custom{$item} = 1;
1347: }
1348: if (defined($settings->{'showlogo'}{$item})) {
1349: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1350: }
1351: }
1352: foreach my $item (@logintext) {
1353: if ($settings->{$item} ne '') {
1354: $designs{'logintext'}{$item} = $settings->{$item};
1355: $is_custom{$item} = 1;
1356: }
1357: }
1358: if ($settings->{'font'} ne '') {
1359: $designs{'font'} = $settings->{'font'};
1360: $is_custom{'font'} = 1;
1361: }
1362: foreach my $item (@bgs) {
1363: if ($settings->{$item} ne '') {
1364: $designs{'bgs'}{$item} = $settings->{$item};
1365: $is_custom{$item} = 1;
1366: }
1367: }
1368: foreach my $item (@links) {
1369: if ($settings->{$item} ne '') {
1370: $designs{'links'}{$item} = $settings->{$item};
1371: $is_custom{$item} = 1;
1372: }
1373: }
1374: } else {
1375: if ($designhash{$dom.'.login.font'} ne '') {
1376: $designs{'font'} = $designhash{$dom.'.login.font'};
1377: $is_custom{'font'} = 1;
1378: }
1379: foreach my $item (@images) {
1380: if ($designhash{$dom.'.login.'.$item} ne '') {
1381: $designs{$item} = $designhash{$dom.'.login.'.$item};
1382: $is_custom{$item} = 1;
1383: }
1384: }
1385: foreach my $item (@bgs) {
1386: if ($designhash{$dom.'.login.'.$item} ne '') {
1387: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1388: $is_custom{$item} = 1;
1389: }
1.6 raeburn 1390: }
1.168 raeburn 1391: foreach my $item (@links) {
1392: if ($designhash{$dom.'.login.'.$item} ne '') {
1393: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1394: $is_custom{$item} = 1;
1395: }
1.6 raeburn 1396: }
1397: }
1.168 raeburn 1398: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1399: logo => 'Institution Logo',
1400: domlogo => 'Domain Logo',
1401: login => 'Login box');
1402: my $itemcount = 1;
1403: foreach my $item (@toggles) {
1404: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1405: $datatable .=
1406: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1407: '</td><td>'.
1408: '<span class="LC_nobreak"><label><input type="radio" name="'.
1409: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1410: '</label> <label><input type="radio" name="'.$item.'"'.
1411: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1412: '</tr>';
1413: $itemcount ++;
1.6 raeburn 1414: }
1.168 raeburn 1415: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1416: $datatable .= '</tr></table></td></tr>';
1417: } elsif ($caller eq 'help') {
1418: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1419: my $switchserver = &check_switchserver($dom,$confname);
1420: my $itemcount = 1;
1421: $defaulturl = '/adm/loginproblems.html';
1422: $defaulttype = 'default';
1423: %lt = &Apache::lonlocal::texthash (
1424: del => 'Delete?',
1425: rep => 'Replace:',
1426: upl => 'Upload:',
1427: default => 'Default',
1428: custom => 'Custom',
1429: );
1430: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1431: my @currlangs;
1432: if (ref($settings) eq 'HASH') {
1433: if (ref($settings->{'helpurl'}) eq 'HASH') {
1434: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1435: next if ($settings->{'helpurl'}{$key} eq '');
1436: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1437: $type{$key} = 'custom';
1438: unless ($key eq 'nolang') {
1439: push(@currlangs,$key);
1440: }
1441: }
1442: } elsif ($settings->{'helpurl'} ne '') {
1443: $type{'nolang'} = 'custom';
1444: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1445: }
1446: }
1.168 raeburn 1447: foreach my $lang ('nolang',sort(@currlangs)) {
1448: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1449: $datatable .= '<tr'.$css_class.'>';
1450: if ($url{$lang} eq '') {
1451: $url{$lang} = $defaulturl;
1452: }
1453: if ($type{$lang} eq '') {
1454: $type{$lang} = $defaulttype;
1455: }
1456: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1457: if ($lang eq 'nolang') {
1458: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1459: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1460: } else {
1461: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1462: $langchoices{$lang},
1463: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1464: }
1465: $datatable .= '</span></td>'."\n".
1466: '<td class="LC_left_item">';
1467: if ($type{$lang} eq 'custom') {
1468: $datatable .= '<span class="LC_nobreak"><label>'.
1469: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1470: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1471: } else {
1472: $datatable .= $lt{'upl'};
1473: }
1474: $datatable .='<br />';
1475: if ($switchserver) {
1476: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1477: } else {
1478: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1479: }
1.168 raeburn 1480: $datatable .= '</td></tr>';
1481: $itemcount ++;
1.6 raeburn 1482: }
1.168 raeburn 1483: my @addlangs;
1484: foreach my $lang (sort(keys(%langchoices))) {
1485: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1486: push(@addlangs,$lang);
1487: }
1488: if (@addlangs > 0) {
1489: my %toadd;
1490: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1491: $toadd{''} = &mt('Select');
1492: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1493: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1494: &mt('Add log-in help page for a specific language:').' '.
1495: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1496: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1497: if ($switchserver) {
1498: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1499: } else {
1500: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1501: }
1.168 raeburn 1502: $datatable .= '</td></tr>';
1.169 raeburn 1503: $itemcount ++;
1.6 raeburn 1504: }
1.169 raeburn 1505: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1506: } elsif ($caller eq 'headtag') {
1507: my %domservers = &Apache::lonnet::get_servers($dom);
1508: my $choice = $choices{'headtag'};
1509: $css_class = ' class="LC_odd_row"';
1510: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1511: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1512: '<th>'.$choices{'current'}.'</th>'.
1513: '<th>'.$choices{'action'}.'</th>'.
1514: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1515: my (%currurls,%currexempt);
1516: if (ref($settings) eq 'HASH') {
1517: if (ref($settings->{'headtag'}) eq 'HASH') {
1518: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1519: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1520: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1521: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1522: }
1523: }
1524: }
1525: }
1526: my %lt = &Apache::lonlocal::texthash(
1527: del => 'Delete?',
1528: rep => 'Replace:',
1529: upl => 'Upload:',
1530: curr => 'View contents',
1531: none => 'None',
1532: );
1533: my $switchserver = &check_switchserver($dom,$confname);
1534: foreach my $lonhost (sort(keys(%domservers))) {
1535: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1536: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1537: if ($currurls{$lonhost}) {
1538: $datatable .= '<td class="LC_right_item"><a href="'.
1539: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1540: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1541: '">'.$lt{'curr'}.'</a></td>'.
1542: '<td><span class="LC_nobreak"><label>'.
1543: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1544: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1545: } else {
1546: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1547: }
1548: $datatable .='<br />';
1549: if ($switchserver) {
1550: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1551: } else {
1552: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1553: }
1.330 raeburn 1554: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1555: }
1556: $datatable .= '</table></td></tr>';
1.1 raeburn 1557: }
1.6 raeburn 1558: return $datatable;
1559: }
1560:
1561: sub login_choices {
1562: my %choices =
1563: &Apache::lonlocal::texthash (
1.116 bisitz 1564: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1565: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1566: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1567: disallowlogin => "Login page requests redirected",
1568: hostid => "Server",
1.128 raeburn 1569: server => "Redirect to:",
1570: serverpath => "Path",
1571: custompath => "Custom",
1572: exempt => "Exempt IP(s)",
1.110 raeburn 1573: directlogin => "No redirect",
1574: newuser => "Link to create a user account",
1575: img => "Header",
1576: logo => "Main Logo",
1577: domlogo => "Domain Logo",
1578: login => "Log-in Header",
1579: textcol => "Text color",
1580: bgcol => "Box color",
1581: bgs => "Background colors",
1582: links => "Link colors",
1583: font => "Font color",
1584: pgbg => "Header",
1585: mainbg => "Page",
1586: sidebg => "Login box",
1587: link => "Link",
1588: alink => "Active link",
1589: vlink => "Visited link",
1.256 raeburn 1590: headtag => "Custom markup",
1591: action => "Action",
1592: current => "Current",
1.6 raeburn 1593: );
1594: return %choices;
1595: }
1596:
1597: sub print_rolecolors {
1.30 raeburn 1598: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1599: my %choices = &color_font_choices();
1600: my @bgs = ('pgbg','tabbg','sidebg');
1601: my @links = ('link','alink','vlink');
1602: my @images = ('img');
1603: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1604: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1605: my %defaultdesign = %Apache::loncommon::defaultdesign;
1606: my (%is_custom,%designs);
1.200 raeburn 1607: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1608: if (ref($settings) eq 'HASH') {
1609: if (ref($settings->{$role}) eq 'HASH') {
1610: if ($settings->{$role}->{'img'} ne '') {
1611: $designs{'img'} = $settings->{$role}->{'img'};
1612: $is_custom{'img'} = 1;
1613: }
1614: if ($settings->{$role}->{'font'} ne '') {
1615: $designs{'font'} = $settings->{$role}->{'font'};
1616: $is_custom{'font'} = 1;
1617: }
1.97 tempelho 1618: if ($settings->{$role}->{'fontmenu'} ne '') {
1619: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1620: $is_custom{'fontmenu'} = 1;
1621: }
1.6 raeburn 1622: foreach my $item (@bgs) {
1623: if ($settings->{$role}->{$item} ne '') {
1624: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1625: $is_custom{$item} = 1;
1626: }
1627: }
1628: foreach my $item (@links) {
1629: if ($settings->{$role}->{$item} ne '') {
1630: $designs{'links'}{$item} = $settings->{$role}->{$item};
1631: $is_custom{$item} = 1;
1632: }
1633: }
1634: }
1635: } else {
1636: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1637: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1638: $is_custom{'img'} = 1;
1639: }
1.97 tempelho 1640: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1641: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1642: $is_custom{'fontmenu'} = 1;
1643: }
1.6 raeburn 1644: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1645: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1646: $is_custom{'font'} = 1;
1647: }
1648: foreach my $item (@bgs) {
1649: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1650: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1651: $is_custom{$item} = 1;
1652:
1653: }
1654: }
1655: foreach my $item (@links) {
1656: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1657: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1658: $is_custom{$item} = 1;
1659: }
1660: }
1661: }
1662: my $itemcount = 1;
1.30 raeburn 1663: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1664: $datatable .= '</tr></table></td></tr>';
1665: return $datatable;
1666: }
1667:
1.200 raeburn 1668: sub role_defaults {
1669: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1670: my %defaults;
1671: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1672: return %defaults;
1673: }
1674: my %defaultdesign = %Apache::loncommon::defaultdesign;
1675: if ($role eq 'login') {
1676: %defaults = (
1677: font => $defaultdesign{$role.'.font'},
1678: );
1679: if (ref($logintext) eq 'ARRAY') {
1680: foreach my $item (@{$logintext}) {
1681: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1682: }
1683: }
1684: foreach my $item (@{$images}) {
1685: $defaults{'showlogo'}{$item} = 1;
1686: }
1687: } else {
1688: %defaults = (
1689: img => $defaultdesign{$role.'.img'},
1690: font => $defaultdesign{$role.'.font'},
1691: fontmenu => $defaultdesign{$role.'.fontmenu'},
1692: );
1693: }
1694: foreach my $item (@{$bgs}) {
1695: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1696: }
1697: foreach my $item (@{$links}) {
1698: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1699: }
1700: foreach my $item (@{$images}) {
1701: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1702: }
1703: return %defaults;
1704: }
1705:
1.6 raeburn 1706: sub display_color_options {
1.9 raeburn 1707: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1708: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1709: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1710: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1711: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1712: '<td>'.$choices->{'font'}.'</td>';
1713: if (!$is_custom->{'font'}) {
1.329 raeburn 1714: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1715: } else {
1716: $datatable .= '<td> </td>';
1717: }
1.174 foxr 1718: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1719:
1.8 raeburn 1720: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1721: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1722: ' value="'.$current_color.'" /> '.
1.329 raeburn 1723: ' </span></td></tr>';
1.107 raeburn 1724: unless ($role eq 'login') {
1725: $datatable .= '<tr'.$css_class.'>'.
1726: '<td>'.$choices->{'fontmenu'}.'</td>';
1727: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 1728: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1729: } else {
1730: $datatable .= '<td> </td>';
1731: }
1.202 raeburn 1732: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1733: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1734: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1735: '<input class="colorchooser" type="text" size="10" name="'
1736: .$role.'_fontmenu"'.
1737: ' value="'.$current_color.'" /> '.
1.329 raeburn 1738: ' </span></td></tr>';
1.97 tempelho 1739: }
1.9 raeburn 1740: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1741: foreach my $img (@{$images}) {
1.18 albertel 1742: $itemcount ++;
1.6 raeburn 1743: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1744: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1745: '<td>'.$choices->{$img};
1.41 raeburn 1746: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1747: if ($role eq 'login') {
1748: if ($img eq 'login') {
1749: $login_hdr_pick =
1.135 bisitz 1750: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1751: $logincolors =
1752: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1753: $designs,$defaults);
1.70 raeburn 1754: } elsif ($img ne 'domlogo') {
1755: $datatable.= &logo_display_options($img,$defaults,$designs);
1756: }
1757: }
1758: $datatable .= '</td>';
1.6 raeburn 1759: if ($designs->{$img} ne '') {
1760: $imgfile = $designs->{$img};
1.18 albertel 1761: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1762: } else {
1763: $imgfile = $defaults->{$img};
1764: }
1765: if ($imgfile) {
1.9 raeburn 1766: my ($showfile,$fullsize);
1767: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1768: my $urldir = $1;
1769: my $filename = $2;
1770: my @info = &Apache::lonnet::stat_file($designs->{$img});
1771: if (@info) {
1772: my $thumbfile = 'tn-'.$filename;
1773: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1774: if (@thumb) {
1775: $showfile = $urldir.'/'.$thumbfile;
1776: } else {
1777: $showfile = $imgfile;
1778: }
1779: } else {
1780: $showfile = '';
1781: }
1782: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1783: $showfile = $imgfile;
1.6 raeburn 1784: my $imgdir = $1;
1785: my $filename = $2;
1.159 raeburn 1786: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1787: $showfile = "/$imgdir/tn-".$filename;
1788: } else {
1.159 raeburn 1789: my $input = $londocroot.$imgfile;
1790: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1791: if (!-e $output) {
1.9 raeburn 1792: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1793: my ($fullwidth,$fullheight) = &check_dimensions($input);
1794: if ($fullwidth ne '' && $fullheight ne '') {
1795: if ($fullwidth > $width && $fullheight > $height) {
1796: my $size = $width.'x'.$height;
1.316 raeburn 1797: my @args = ('convert','-sample',$size,$input,$output);
1798: system({$args[0]} @args);
1.159 raeburn 1799: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1800: }
1801: }
1.6 raeburn 1802: }
1803: }
1.16 raeburn 1804: }
1.6 raeburn 1805: if ($showfile) {
1.40 raeburn 1806: if ($showfile =~ m{^/(adm|res)/}) {
1807: if ($showfile =~ m{^/res/}) {
1808: my $local_showfile =
1809: &Apache::lonnet::filelocation('',$showfile);
1810: &Apache::lonnet::repcopy($local_showfile);
1811: }
1812: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1813: }
1814: if ($imgfile) {
1815: if ($imgfile =~ m{^/(adm|res)/}) {
1816: if ($imgfile =~ m{^/res/}) {
1817: my $local_imgfile =
1818: &Apache::lonnet::filelocation('',$imgfile);
1819: &Apache::lonnet::repcopy($local_imgfile);
1820: }
1821: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1822: } else {
1823: $fullsize = $imgfile;
1824: }
1825: }
1.41 raeburn 1826: $datatable .= '<td>';
1827: if ($img eq 'login') {
1.135 bisitz 1828: $datatable .= $login_hdr_pick;
1829: }
1.41 raeburn 1830: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1831: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1832: } else {
1.201 raeburn 1833: $datatable .= '<td> </td><td class="LC_left_item">'.
1834: &mt('Upload:').'<br />';
1.6 raeburn 1835: }
1836: } else {
1.201 raeburn 1837: $datatable .= '<td> </td><td class="LC_left_item">'.
1838: &mt('Upload:').'<br />';
1.6 raeburn 1839: }
1.9 raeburn 1840: if ($switchserver) {
1841: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1842: } else {
1.135 bisitz 1843: if ($img ne 'login') { # suppress file selection for Log-in header
1844: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1845: }
1.9 raeburn 1846: }
1847: $datatable .= '</td></tr>';
1.6 raeburn 1848: }
1849: $itemcount ++;
1850: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1851: $datatable .= '<tr'.$css_class.'>'.
1852: '<td>'.$choices->{'bgs'}.'</td>';
1853: my $bgs_def;
1854: foreach my $item (@{$bgs}) {
1855: if (!$is_custom->{$item}) {
1.329 raeburn 1856: $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 1857: }
1858: }
1859: if ($bgs_def) {
1.8 raeburn 1860: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1861: } else {
1862: $datatable .= '<td> </td>';
1863: }
1864: $datatable .= '<td class="LC_right_item">'.
1865: '<table border="0"><tr>';
1.174 foxr 1866:
1.6 raeburn 1867: foreach my $item (@{$bgs}) {
1.306 raeburn 1868: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 1869: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1870: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1871: $datatable .= ' ';
1.6 raeburn 1872: }
1.174 foxr 1873: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1874: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1875: }
1876: $datatable .= '</tr></table></td></tr>';
1877: $itemcount ++;
1878: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1879: $datatable .= '<tr'.$css_class.'>'.
1880: '<td>'.$choices->{'links'}.'</td>';
1881: my $links_def;
1882: foreach my $item (@{$links}) {
1883: if (!$is_custom->{$item}) {
1.329 raeburn 1884: $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 1885: }
1886: }
1887: if ($links_def) {
1.8 raeburn 1888: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1889: } else {
1890: $datatable .= '<td> </td>';
1891: }
1892: $datatable .= '<td class="LC_right_item">'.
1893: '<table border="0"><tr>';
1894: foreach my $item (@{$links}) {
1.234 raeburn 1895: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 1896: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 1897: if ($designs->{'links'}{$item}) {
1.174 foxr 1898: $datatable.=' ';
1.6 raeburn 1899: }
1.174 foxr 1900: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1901: '" /></td>';
1902: }
1.30 raeburn 1903: $$rowtotal += $itemcount;
1.3 raeburn 1904: return $datatable;
1905: }
1906:
1.70 raeburn 1907: sub logo_display_options {
1908: my ($img,$defaults,$designs) = @_;
1909: my $checkedon;
1910: if (ref($defaults) eq 'HASH') {
1911: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1912: if ($defaults->{'showlogo'}{$img}) {
1913: $checkedon = 'checked="checked" ';
1914: }
1915: }
1916: }
1917: if (ref($designs) eq 'HASH') {
1918: if (ref($designs->{'showlogo'}) eq 'HASH') {
1919: if (defined($designs->{'showlogo'}{$img})) {
1920: if ($designs->{'showlogo'}{$img} == 0) {
1921: $checkedon = '';
1922: } elsif ($designs->{'showlogo'}{$img} == 1) {
1923: $checkedon = 'checked="checked" ';
1924: }
1925: }
1926: }
1927: }
1928: return '<br /><label> <input type="checkbox" name="'.
1929: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1930: &mt('show').'</label>'."\n";
1931: }
1932:
1.41 raeburn 1933: sub login_header_options {
1.135 bisitz 1934: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1935: my $output = '';
1.41 raeburn 1936: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1937: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1938: if (!$is_custom->{'textcol'}) {
1939: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1940: ' ';
1941: }
1942: if (!$is_custom->{'bgcol'}) {
1943: $output .= $choices->{'bgcol'}.': '.
1944: '<span id="css_'.$role.'_font" style="background-color: '.
1945: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1946: }
1947: $output .= '<br />';
1948: }
1949: $output .='<br />';
1950: return $output;
1951: }
1952:
1953: sub login_text_colors {
1.201 raeburn 1954: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1955: my $color_menu = '<table border="0"><tr>';
1956: foreach my $item (@{$logintext}) {
1.306 raeburn 1957: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 1958: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1959: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1960: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1961: }
1962: $color_menu .= '</tr></table><br />';
1963: return $color_menu;
1964: }
1965:
1966: sub image_changes {
1967: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1968: my $output;
1.135 bisitz 1969: if ($img eq 'login') {
1.331 raeburn 1970: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 1971: } elsif (!$is_custom) {
1.70 raeburn 1972: if ($img ne 'domlogo') {
1.331 raeburn 1973: $output = &mt('Default image:').'<br />';
1.41 raeburn 1974: } else {
1.331 raeburn 1975: $output = &mt('Default in use:').'<br />';
1.41 raeburn 1976: }
1977: }
1.331 raeburn 1978: if ($img ne 'login') {
1.135 bisitz 1979: if ($img_import) {
1980: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1981: }
1982: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1983: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1984: if ($is_custom) {
1985: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1986: '<input type="checkbox" name="'.
1987: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1988: '</label> '.&mt('Replace:').'</span><br />';
1989: } else {
1.306 raeburn 1990: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1991: }
1.41 raeburn 1992: }
1993: return $output;
1994: }
1995:
1.3 raeburn 1996: sub print_quotas {
1.86 raeburn 1997: my ($dom,$settings,$rowtotal,$action) = @_;
1998: my $context;
1999: if ($action eq 'quotas') {
2000: $context = 'tools';
2001: } else {
2002: $context = $action;
2003: }
1.197 raeburn 2004: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 2005: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2006: my $typecount = 0;
1.101 raeburn 2007: my ($css_class,%titles);
1.86 raeburn 2008: if ($context eq 'requestcourses') {
1.325 raeburn 2009: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 2010: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2011: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2012: %titles = &courserequest_titles();
1.163 raeburn 2013: } elsif ($context eq 'requestauthor') {
2014: @usertools = ('author');
2015: @options = ('norequest','approval','automatic');
1.210 raeburn 2016: %titles = &authorrequest_titles();
1.86 raeburn 2017: } else {
1.162 raeburn 2018: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 2019: %titles = &tool_titles();
1.86 raeburn 2020: }
1.26 raeburn 2021: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2022: foreach my $type (@{$types}) {
1.197 raeburn 2023: my ($currdefquota,$currauthorquota);
1.163 raeburn 2024: unless (($context eq 'requestcourses') ||
2025: ($context eq 'requestauthor')) {
1.86 raeburn 2026: if (ref($settings) eq 'HASH') {
2027: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 2028: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2029: } else {
2030: $currdefquota = $settings->{$type};
2031: }
1.197 raeburn 2032: if (ref($settings->{authorquota}) eq 'HASH') {
2033: $currauthorquota = $settings->{authorquota}->{$type};
2034: }
1.78 raeburn 2035: }
1.72 raeburn 2036: }
1.3 raeburn 2037: if (defined($usertypes->{$type})) {
2038: $typecount ++;
2039: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2040: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2041: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2042: '<td class="LC_left_item">';
1.101 raeburn 2043: if ($context eq 'requestcourses') {
2044: $datatable .= '<table><tr>';
2045: }
2046: my %cell;
1.72 raeburn 2047: foreach my $item (@usertools) {
1.101 raeburn 2048: if ($context eq 'requestcourses') {
2049: my ($curroption,$currlimit);
2050: if (ref($settings) eq 'HASH') {
2051: if (ref($settings->{$item}) eq 'HASH') {
2052: $curroption = $settings->{$item}->{$type};
2053: if ($curroption =~ /^autolimit=(\d*)$/) {
2054: $currlimit = $1;
2055: }
2056: }
2057: }
2058: if (!$curroption) {
2059: $curroption = 'norequest';
2060: }
2061: $datatable .= '<th>'.$titles{$item}.'</th>';
2062: foreach my $option (@options) {
2063: my $val = $option;
2064: if ($option eq 'norequest') {
2065: $val = 0;
2066: }
2067: if ($option eq 'validate') {
2068: my $canvalidate = 0;
2069: if (ref($validations{$item}) eq 'HASH') {
2070: if ($validations{$item}{$type}) {
2071: $canvalidate = 1;
2072: }
2073: }
2074: next if (!$canvalidate);
2075: }
2076: my $checked = '';
2077: if ($option eq $curroption) {
2078: $checked = ' checked="checked"';
2079: } elsif ($option eq 'autolimit') {
2080: if ($curroption =~ /^autolimit/) {
2081: $checked = ' checked="checked"';
2082: }
2083: }
2084: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2085: '<input type="radio" name="crsreq_'.$item.
2086: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2087: $titles{$option}.'</label>';
1.101 raeburn 2088: if ($option eq 'autolimit') {
1.127 raeburn 2089: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2090: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2091: 'value="'.$currlimit.'" />';
1.101 raeburn 2092: }
1.127 raeburn 2093: $cell{$item} .= '</span> ';
1.103 raeburn 2094: if ($option eq 'autolimit') {
1.127 raeburn 2095: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2096: }
1.101 raeburn 2097: }
1.163 raeburn 2098: } elsif ($context eq 'requestauthor') {
2099: my $curroption;
2100: if (ref($settings) eq 'HASH') {
2101: $curroption = $settings->{$type};
2102: }
2103: if (!$curroption) {
2104: $curroption = 'norequest';
2105: }
2106: foreach my $option (@options) {
2107: my $val = $option;
2108: if ($option eq 'norequest') {
2109: $val = 0;
2110: }
2111: my $checked = '';
2112: if ($option eq $curroption) {
2113: $checked = ' checked="checked"';
2114: }
2115: $datatable .= '<span class="LC_nobreak"><label>'.
2116: '<input type="radio" name="authorreq_'.$type.
2117: '" value="'.$val.'"'.$checked.' />'.
2118: $titles{$option}.'</label></span> ';
2119: }
1.101 raeburn 2120: } else {
2121: my $checked = 'checked="checked" ';
2122: if (ref($settings) eq 'HASH') {
2123: if (ref($settings->{$item}) eq 'HASH') {
2124: if ($settings->{$item}->{$type} == 0) {
2125: $checked = '';
2126: } elsif ($settings->{$item}->{$type} == 1) {
2127: $checked = 'checked="checked" ';
2128: }
1.78 raeburn 2129: }
1.72 raeburn 2130: }
1.101 raeburn 2131: $datatable .= '<span class="LC_nobreak"><label>'.
2132: '<input type="checkbox" name="'.$context.'_'.$item.
2133: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2134: '</label></span> ';
1.72 raeburn 2135: }
1.101 raeburn 2136: }
2137: if ($context eq 'requestcourses') {
2138: $datatable .= '</tr><tr>';
2139: foreach my $item (@usertools) {
1.106 raeburn 2140: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2141: }
2142: $datatable .= '</tr></table>';
1.72 raeburn 2143: }
1.86 raeburn 2144: $datatable .= '</td>';
1.163 raeburn 2145: unless (($context eq 'requestcourses') ||
2146: ($context eq 'requestauthor')) {
1.86 raeburn 2147: $datatable .=
1.197 raeburn 2148: '<td class="LC_right_item">'.
2149: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2150: '<input type="text" name="quota_'.$type.
1.72 raeburn 2151: '" value="'.$currdefquota.
1.197 raeburn 2152: '" size="5" /></span>'.(' ' x 2).
2153: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2154: '<input type="text" name="authorquota_'.$type.
2155: '" value="'.$currauthorquota.
2156: '" size="5" /></span></td>';
1.86 raeburn 2157: }
2158: $datatable .= '</tr>';
1.3 raeburn 2159: }
2160: }
2161: }
1.163 raeburn 2162: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2163: $defaultquota = '20';
1.197 raeburn 2164: $authorquota = '500';
1.86 raeburn 2165: if (ref($settings) eq 'HASH') {
2166: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2167: $defaultquota = $settings->{'defaultquota'}->{'default'};
2168: } elsif (defined($settings->{'default'})) {
2169: $defaultquota = $settings->{'default'};
2170: }
1.197 raeburn 2171: if (ref($settings->{'authorquota'}) eq 'HASH') {
2172: $authorquota = $settings->{'authorquota'}->{'default'};
2173: }
1.3 raeburn 2174: }
2175: }
2176: $typecount ++;
2177: $css_class = $typecount%2?' class="LC_odd_row"':'';
2178: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2179: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2180: '<td class="LC_left_item">';
1.101 raeburn 2181: if ($context eq 'requestcourses') {
2182: $datatable .= '<table><tr>';
2183: }
2184: my %defcell;
1.72 raeburn 2185: foreach my $item (@usertools) {
1.101 raeburn 2186: if ($context eq 'requestcourses') {
2187: my ($curroption,$currlimit);
2188: if (ref($settings) eq 'HASH') {
2189: if (ref($settings->{$item}) eq 'HASH') {
2190: $curroption = $settings->{$item}->{'default'};
2191: if ($curroption =~ /^autolimit=(\d*)$/) {
2192: $currlimit = $1;
2193: }
2194: }
2195: }
2196: if (!$curroption) {
2197: $curroption = 'norequest';
2198: }
2199: $datatable .= '<th>'.$titles{$item}.'</th>';
2200: foreach my $option (@options) {
2201: my $val = $option;
2202: if ($option eq 'norequest') {
2203: $val = 0;
2204: }
2205: if ($option eq 'validate') {
2206: my $canvalidate = 0;
2207: if (ref($validations{$item}) eq 'HASH') {
2208: if ($validations{$item}{'default'}) {
2209: $canvalidate = 1;
2210: }
2211: }
2212: next if (!$canvalidate);
2213: }
2214: my $checked = '';
2215: if ($option eq $curroption) {
2216: $checked = ' checked="checked"';
2217: } elsif ($option eq 'autolimit') {
2218: if ($curroption =~ /^autolimit/) {
2219: $checked = ' checked="checked"';
2220: }
2221: }
2222: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2223: '<input type="radio" name="crsreq_'.$item.
2224: '_default" value="'.$val.'"'.$checked.' />'.
2225: $titles{$option}.'</label>';
2226: if ($option eq 'autolimit') {
1.127 raeburn 2227: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2228: $item.'_limit_default" size="1" '.
2229: 'value="'.$currlimit.'" />';
2230: }
1.127 raeburn 2231: $defcell{$item} .= '</span> ';
1.104 raeburn 2232: if ($option eq 'autolimit') {
1.127 raeburn 2233: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2234: }
1.101 raeburn 2235: }
1.163 raeburn 2236: } elsif ($context eq 'requestauthor') {
2237: my $curroption;
2238: if (ref($settings) eq 'HASH') {
1.172 raeburn 2239: $curroption = $settings->{'default'};
1.163 raeburn 2240: }
2241: if (!$curroption) {
2242: $curroption = 'norequest';
2243: }
2244: foreach my $option (@options) {
2245: my $val = $option;
2246: if ($option eq 'norequest') {
2247: $val = 0;
2248: }
2249: my $checked = '';
2250: if ($option eq $curroption) {
2251: $checked = ' checked="checked"';
2252: }
2253: $datatable .= '<span class="LC_nobreak"><label>'.
2254: '<input type="radio" name="authorreq_default"'.
2255: ' value="'.$val.'"'.$checked.' />'.
2256: $titles{$option}.'</label></span> ';
2257: }
1.101 raeburn 2258: } else {
2259: my $checked = 'checked="checked" ';
2260: if (ref($settings) eq 'HASH') {
2261: if (ref($settings->{$item}) eq 'HASH') {
2262: if ($settings->{$item}->{'default'} == 0) {
2263: $checked = '';
2264: } elsif ($settings->{$item}->{'default'} == 1) {
2265: $checked = 'checked="checked" ';
2266: }
1.78 raeburn 2267: }
1.72 raeburn 2268: }
1.101 raeburn 2269: $datatable .= '<span class="LC_nobreak"><label>'.
2270: '<input type="checkbox" name="'.$context.'_'.$item.
2271: '" value="default" '.$checked.'/>'.$titles{$item}.
2272: '</label></span> ';
2273: }
2274: }
2275: if ($context eq 'requestcourses') {
2276: $datatable .= '</tr><tr>';
2277: foreach my $item (@usertools) {
1.106 raeburn 2278: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2279: }
1.101 raeburn 2280: $datatable .= '</tr></table>';
1.72 raeburn 2281: }
1.86 raeburn 2282: $datatable .= '</td>';
1.163 raeburn 2283: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2284: $datatable .= '<td class="LC_right_item">'.
2285: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2286: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2287: $defaultquota.'" size="5" /></span>'.(' ' x2).
2288: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2289: '<input type="text" name="authorquota" value="'.
2290: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2291: }
2292: $datatable .= '</tr>';
1.72 raeburn 2293: $typecount ++;
2294: $css_class = $typecount%2?' class="LC_odd_row"':'';
2295: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2296: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2297: if ($context eq 'requestcourses') {
1.109 raeburn 2298: $datatable .= &mt('(overrides affiliation, if set)').
2299: '</td>'.
2300: '<td class="LC_left_item">'.
2301: '<table><tr>';
1.101 raeburn 2302: } else {
1.109 raeburn 2303: $datatable .= &mt('(overrides affiliation, if checked)').
2304: '</td>'.
2305: '<td class="LC_left_item" colspan="2">'.
2306: '<br />';
1.101 raeburn 2307: }
2308: my %advcell;
1.72 raeburn 2309: foreach my $item (@usertools) {
1.101 raeburn 2310: if ($context eq 'requestcourses') {
2311: my ($curroption,$currlimit);
2312: if (ref($settings) eq 'HASH') {
2313: if (ref($settings->{$item}) eq 'HASH') {
2314: $curroption = $settings->{$item}->{'_LC_adv'};
2315: if ($curroption =~ /^autolimit=(\d*)$/) {
2316: $currlimit = $1;
2317: }
2318: }
2319: }
2320: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2321: my $checked = '';
2322: if ($curroption eq '') {
2323: $checked = ' checked="checked"';
2324: }
2325: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2326: '<input type="radio" name="crsreq_'.$item.
2327: '__LC_adv" value=""'.$checked.' />'.
2328: &mt('No override set').'</label></span> ';
1.101 raeburn 2329: foreach my $option (@options) {
2330: my $val = $option;
2331: if ($option eq 'norequest') {
2332: $val = 0;
2333: }
2334: if ($option eq 'validate') {
2335: my $canvalidate = 0;
2336: if (ref($validations{$item}) eq 'HASH') {
2337: if ($validations{$item}{'_LC_adv'}) {
2338: $canvalidate = 1;
2339: }
2340: }
2341: next if (!$canvalidate);
2342: }
2343: my $checked = '';
1.104 raeburn 2344: if ($val eq $curroption) {
1.101 raeburn 2345: $checked = ' checked="checked"';
2346: } elsif ($option eq 'autolimit') {
2347: if ($curroption =~ /^autolimit/) {
2348: $checked = ' checked="checked"';
2349: }
2350: }
2351: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2352: '<input type="radio" name="crsreq_'.$item.
2353: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2354: $titles{$option}.'</label>';
2355: if ($option eq 'autolimit') {
1.127 raeburn 2356: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2357: $item.'_limit__LC_adv" size="1" '.
2358: 'value="'.$currlimit.'" />';
2359: }
1.127 raeburn 2360: $advcell{$item} .= '</span> ';
1.104 raeburn 2361: if ($option eq 'autolimit') {
1.127 raeburn 2362: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2363: }
1.101 raeburn 2364: }
1.163 raeburn 2365: } elsif ($context eq 'requestauthor') {
2366: my $curroption;
2367: if (ref($settings) eq 'HASH') {
2368: $curroption = $settings->{'_LC_adv'};
2369: }
2370: my $checked = '';
2371: if ($curroption eq '') {
2372: $checked = ' checked="checked"';
2373: }
2374: $datatable .= '<span class="LC_nobreak"><label>'.
2375: '<input type="radio" name="authorreq__LC_adv"'.
2376: ' value=""'.$checked.' />'.
2377: &mt('No override set').'</label></span> ';
2378: foreach my $option (@options) {
2379: my $val = $option;
2380: if ($option eq 'norequest') {
2381: $val = 0;
2382: }
2383: my $checked = '';
2384: if ($val eq $curroption) {
2385: $checked = ' checked="checked"';
2386: }
2387: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2388: '<input type="radio" name="authorreq__LC_adv"'.
2389: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2390: $titles{$option}.'</label></span> ';
2391: }
1.101 raeburn 2392: } else {
2393: my $checked = 'checked="checked" ';
2394: if (ref($settings) eq 'HASH') {
2395: if (ref($settings->{$item}) eq 'HASH') {
2396: if ($settings->{$item}->{'_LC_adv'} == 0) {
2397: $checked = '';
2398: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2399: $checked = 'checked="checked" ';
2400: }
1.79 raeburn 2401: }
1.72 raeburn 2402: }
1.101 raeburn 2403: $datatable .= '<span class="LC_nobreak"><label>'.
2404: '<input type="checkbox" name="'.$context.'_'.$item.
2405: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2406: '</label></span> ';
2407: }
2408: }
2409: if ($context eq 'requestcourses') {
2410: $datatable .= '</tr><tr>';
2411: foreach my $item (@usertools) {
1.106 raeburn 2412: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2413: }
1.101 raeburn 2414: $datatable .= '</tr></table>';
1.72 raeburn 2415: }
1.98 raeburn 2416: $datatable .= '</td></tr>';
1.30 raeburn 2417: $$rowtotal += $typecount;
1.3 raeburn 2418: return $datatable;
2419: }
2420:
1.163 raeburn 2421: sub print_requestmail {
1.305 raeburn 2422: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2423: my ($now,$datatable,%currapp);
1.102 raeburn 2424: $now = time;
2425: if (ref($settings) eq 'HASH') {
2426: if (ref($settings->{'notify'}) eq 'HASH') {
2427: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2428: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2429: }
2430: }
2431: }
1.191 raeburn 2432: my $numinrow = 2;
1.224 raeburn 2433: my $css_class;
1.305 raeburn 2434: if ($$rowtotal%2) {
2435: $css_class = 'LC_odd_row';
2436: }
2437: if ($customcss) {
2438: $css_class .= " $customcss";
2439: }
2440: $css_class =~ s/^\s+//;
2441: if ($css_class) {
2442: $css_class = ' class="'.$css_class.'"';
2443: }
2444: if ($rowstyle) {
2445: $css_class .= ' style="'.$rowstyle.'"';
2446: }
1.163 raeburn 2447: my $text;
2448: if ($action eq 'requestcourses') {
2449: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2450: } elsif ($action eq 'requestauthor') {
2451: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2452: } else {
1.224 raeburn 2453: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2454: }
1.224 raeburn 2455: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2456: ' <td>'.$text.'</td>'.
1.102 raeburn 2457: ' <td class="LC_left_item">';
1.191 raeburn 2458: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2459: $action.'notifyapproval',%currapp);
1.191 raeburn 2460: if ($numdc > 0) {
2461: $datatable .= $table;
1.102 raeburn 2462: } else {
2463: $datatable .= &mt('There are no active Domain Coordinators');
2464: }
2465: $datatable .='</td></tr>';
2466: return $datatable;
2467: }
2468:
1.216 raeburn 2469: sub print_studentcode {
2470: my ($settings,$rowtotal) = @_;
2471: my $rownum = 0;
1.218 raeburn 2472: my ($output,%current);
1.325 raeburn 2473: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2474: if (ref($settings) eq 'HASH') {
2475: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2476: foreach my $type (@crstypes) {
2477: $current{$type} = $settings->{'uniquecode'}{$type};
2478: }
1.218 raeburn 2479: }
2480: }
2481: $output .= '<tr>'.
2482: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2483: '<td class="LC_left_item">';
2484: foreach my $type (@crstypes) {
2485: my $check = ' ';
2486: if ($current{$type}) {
2487: $check = ' checked="checked" ';
2488: }
2489: $output .= '<span class="LC_nobreak"><label>'.
2490: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2491: &mt($type).'</label></span>'.(' 'x2).' ';
2492: }
2493: $output .= '</td></tr>';
2494: $$rowtotal ++;
2495: return $output;
1.216 raeburn 2496: }
2497:
2498: sub print_textbookcourses {
1.242 raeburn 2499: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2500: my $rownum = 0;
2501: my $css_class;
2502: my $itemcount = 1;
2503: my $maxnum = 0;
2504: my $bookshash;
2505: if (ref($settings) eq 'HASH') {
1.242 raeburn 2506: $bookshash = $settings->{$type};
1.216 raeburn 2507: }
2508: my %ordered;
2509: if (ref($bookshash) eq 'HASH') {
2510: foreach my $item (keys(%{$bookshash})) {
2511: if (ref($bookshash->{$item}) eq 'HASH') {
2512: my $num = $bookshash->{$item}{'order'};
2513: $ordered{$num} = $item;
2514: }
2515: }
2516: }
2517: my $confname = $dom.'-domainconfig';
2518: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2519: my $maxnum = scalar(keys(%ordered));
2520: my $datatable;
1.216 raeburn 2521: if (keys(%ordered)) {
2522: my @items = sort { $a <=> $b } keys(%ordered);
2523: for (my $i=0; $i<@items; $i++) {
2524: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2525: my $key = $ordered{$items[$i]};
2526: my %coursehash=&Apache::lonnet::coursedescription($key);
2527: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2528: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2529: if (ref($bookshash->{$key}) eq 'HASH') {
2530: $subject = $bookshash->{$key}->{'subject'};
2531: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2532: if ($type eq 'textbooks') {
1.243 raeburn 2533: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2534: $author = $bookshash->{$key}->{'author'};
2535: $image = $bookshash->{$key}->{'image'};
2536: if ($image ne '') {
2537: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2538: my $imagethumb = "$path/tn-".$imagefile;
2539: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2540: }
1.216 raeburn 2541: }
2542: }
1.242 raeburn 2543: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2544: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2545: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2546: for (my $k=0; $k<=$maxnum; $k++) {
2547: my $vpos = $k+1;
2548: my $selstr;
2549: if ($k == $i) {
2550: $selstr = ' selected="selected" ';
2551: }
2552: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2553: }
2554: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2555: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2556: &mt('Delete?').'</label></span></td>'.
2557: '<td colspan="2">'.
1.242 raeburn 2558: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2559: (' 'x2).
1.242 raeburn 2560: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2561: if ($type eq 'textbooks') {
2562: $datatable .= (' 'x2).
1.243 raeburn 2563: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2564: (' 'x2).
1.242 raeburn 2565: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2566: (' 'x2).
2567: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2568: if ($image) {
1.267 raeburn 2569: $datatable .= $imgsrc.
1.242 raeburn 2570: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2571: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2572: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2573: }
2574: if ($switchserver) {
2575: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2576: } else {
2577: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2578: }
1.216 raeburn 2579: }
1.242 raeburn 2580: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2581: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2582: $coursetitle.'</span></td></tr>'."\n";
2583: $itemcount ++;
2584: }
2585: }
2586: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2587: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2588: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2589: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2590: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2591: for (my $k=0; $k<$maxnum+1; $k++) {
2592: my $vpos = $k+1;
2593: my $selstr;
2594: if ($k == $maxnum) {
2595: $selstr = ' selected="selected" ';
2596: }
2597: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2598: }
2599: $datatable .= '</select> '."\n".
1.334 raeburn 2600: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 2601: '<td colspan="2">'.
1.242 raeburn 2602: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2603: (' 'x2).
1.242 raeburn 2604: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2605: (' 'x2);
2606: if ($type eq 'textbooks') {
1.243 raeburn 2607: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2608: (' 'x2).
2609: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2610: (' 'x2).
2611: '<span class="LC_nobreak">'.&mt('Image:').' ';
2612: if ($switchserver) {
2613: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2614: } else {
2615: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2616: }
1.334 raeburn 2617: $datatable .= '</span>'."\n";
1.216 raeburn 2618: }
1.334 raeburn 2619: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2620: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2621: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2622: &Apache::loncommon::selectcourse_link
1.334 raeburn 2623: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 2624: '</span></td>'."\n".
2625: '</tr>'."\n";
2626: $itemcount ++;
2627: return $datatable;
2628: }
2629:
1.217 raeburn 2630: sub textbookcourses_javascript {
1.242 raeburn 2631: my ($settings) = @_;
2632: return unless(ref($settings) eq 'HASH');
2633: my (%ordered,%total,%jstext);
2634: foreach my $type ('textbooks','templates') {
2635: $total{$type} = 0;
2636: if (ref($settings->{$type}) eq 'HASH') {
2637: foreach my $item (keys(%{$settings->{$type}})) {
2638: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2639: my $num = $settings->{$type}->{$item}{'order'};
2640: $ordered{$type}{$num} = $item;
2641: }
2642: }
2643: $total{$type} = scalar(keys(%{$settings->{$type}}));
2644: }
2645: my @jsarray = ();
2646: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2647: push(@jsarray,$ordered{$type}{$item});
2648: }
2649: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2650: }
2651: return <<"ENDSCRIPT";
2652: <script type="text/javascript">
2653: // <![CDATA[
1.242 raeburn 2654: function reorderBooks(form,item,caller) {
1.217 raeburn 2655: var changedVal;
1.242 raeburn 2656: $jstext{'textbooks'};
2657: $jstext{'templates'};
2658: var newpos;
2659: var maxh;
2660: if (caller == 'textbooks') {
2661: newpos = 'textbooks_addbook_pos';
2662: maxh = 1 + $total{'textbooks'};
2663: } else {
2664: newpos = 'templates_addbook_pos';
2665: maxh = 1 + $total{'templates'};
2666: }
1.217 raeburn 2667: var current = new Array;
2668: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2669: if (item == newpos) {
2670: changedVal = newitemVal;
2671: } else {
2672: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2673: current[newitemVal] = newpos;
2674: }
1.242 raeburn 2675: if (caller == 'textbooks') {
2676: for (var i=0; i<textbooks.length; i++) {
2677: var elementName = 'textbooks_'+textbooks[i];
2678: if (elementName != item) {
2679: if (form.elements[elementName]) {
2680: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2681: current[currVal] = elementName;
2682: }
2683: }
2684: }
2685: }
2686: if (caller == 'templates') {
2687: for (var i=0; i<templates.length; i++) {
2688: var elementName = 'templates_'+templates[i];
2689: if (elementName != item) {
2690: if (form.elements[elementName]) {
2691: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2692: current[currVal] = elementName;
2693: }
1.217 raeburn 2694: }
2695: }
2696: }
2697: var oldVal;
2698: for (var j=0; j<maxh; j++) {
2699: if (current[j] == undefined) {
2700: oldVal = j;
2701: }
2702: }
2703: if (oldVal < changedVal) {
2704: for (var k=oldVal+1; k<=changedVal ; k++) {
2705: var elementName = current[k];
2706: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2707: }
2708: } else {
2709: for (var k=changedVal; k<oldVal; k++) {
2710: var elementName = current[k];
2711: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2712: }
2713: }
2714: return;
2715: }
2716:
2717: // ]]>
2718: </script>
2719:
2720: ENDSCRIPT
2721: }
2722:
1.267 raeburn 2723: sub ltitools_javascript {
2724: my ($settings) = @_;
1.319 raeburn 2725: my $togglejs = <itools_toggle_js();
2726: unless (ref($settings) eq 'HASH') {
2727: return $togglejs;
2728: }
1.267 raeburn 2729: my (%ordered,$total,%jstext);
2730: $total = 0;
2731: foreach my $item (keys(%{$settings})) {
2732: if (ref($settings->{$item}) eq 'HASH') {
2733: my $num = $settings->{$item}{'order'};
2734: $ordered{$num} = $item;
2735: }
2736: }
2737: $total = scalar(keys(%{$settings}));
2738: my @jsarray = ();
2739: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2740: push(@jsarray,$ordered{$item});
2741: }
2742: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2743: return <<"ENDSCRIPT";
2744: <script type="text/javascript">
2745: // <![CDATA[
1.319 raeburn 2746: function reorderLTITools(form,item) {
1.267 raeburn 2747: var changedVal;
2748: $jstext
2749: var newpos = 'ltitools_add_pos';
2750: var maxh = 1 + $total;
2751: var current = new Array;
2752: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2753: if (item == newpos) {
2754: changedVal = newitemVal;
2755: } else {
2756: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2757: current[newitemVal] = newpos;
2758: }
2759: for (var i=0; i<ltitools.length; i++) {
2760: var elementName = 'ltitools_'+ltitools[i];
2761: if (elementName != item) {
2762: if (form.elements[elementName]) {
2763: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2764: current[currVal] = elementName;
2765: }
2766: }
2767: }
2768: var oldVal;
2769: for (var j=0; j<maxh; j++) {
2770: if (current[j] == undefined) {
2771: oldVal = j;
2772: }
2773: }
2774: if (oldVal < changedVal) {
2775: for (var k=oldVal+1; k<=changedVal ; k++) {
2776: var elementName = current[k];
2777: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2778: }
2779: } else {
2780: for (var k=changedVal; k<oldVal; k++) {
2781: var elementName = current[k];
2782: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2783: }
2784: }
2785: return;
2786: }
2787:
2788: // ]]>
2789: </script>
2790:
1.319 raeburn 2791: $togglejs
2792:
2793: ENDSCRIPT
2794: }
2795:
2796: sub ltitools_toggle_js {
2797: return <<"ENDSCRIPT";
2798: <script type="text/javascript">
2799: // <![CDATA[
2800:
2801: function toggleLTITools(form,setting,item) {
2802: var radioname = '';
2803: var divid = '';
2804: if ((setting == 'passback') || (setting == 'roster')) {
2805: radioname = 'ltitools_'+setting+'_'+item;
2806: divid = 'ltitools_'+setting+'time_'+item;
2807: var num = form.elements[radioname].length;
2808: if (num) {
2809: var setvis = '';
2810: for (var i=0; i<num; i++) {
2811: if (form.elements[radioname][i].checked) {
2812: if (form.elements[radioname][i].value == '1') {
2813: if (document.getElementById(divid)) {
2814: document.getElementById(divid).style.display = 'inline-block';
2815: }
2816: setvis = 1;
2817: }
2818: break;
2819: }
2820: }
2821: }
2822: if (!setvis) {
2823: if (document.getElementById(divid)) {
2824: document.getElementById(divid).style.display = 'none';
2825: }
2826: }
2827: }
1.324 raeburn 2828: if (setting == 'user') {
2829: divid = 'ltitools_'+setting+'_div_'+item;
2830: var checkid = 'ltitools_'+setting+'_field_'+item;
2831: if (document.getElementById(divid)) {
2832: if (document.getElementById(checkid)) {
2833: if (document.getElementById(checkid).checked) {
2834: document.getElementById(divid).style.display = 'inline-block';
2835: } else {
2836: document.getElementById(divid).style.display = 'none';
2837: }
2838: }
2839: }
2840: }
1.319 raeburn 2841: return;
2842: }
2843: // ]]>
2844: </script>
2845:
1.267 raeburn 2846: ENDSCRIPT
2847: }
2848:
1.381 raeburn 2849: sub wafproxy_javascript {
2850: my ($dom) = @_;
2851: return <<"ENDSCRIPT";
2852: <script type="text/javascript">
2853: // <![CDATA[
2854: function updateWAF() {
2855: if (document.getElementById('wafproxy_remoteip')) {
2856: var wafremote = 0;
2857: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
2858: wafremote = 1;
2859: }
2860: var fields = new Array('header','trust');
2861: for (var i=0; i<fields.length; i++) {
2862: if (document.getElementById('wafproxy_'+fields[i])) {
2863: if (wafremote == 1) {
2864: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
2865: }
2866: else {
2867: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
2868: }
2869: }
2870: }
2871: if (document.getElementById('wafproxyranges_$dom')) {
2872: if (wafremote == 1) {
2873: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
2874: } else {
2875: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
2876: if (document.display.wafproxy_vpnaccess[i].checked) {
2877: if (document.display.wafproxy_vpnaccess[i].value == 0) {
2878: document.getElementById('wafproxyranges_$dom').style.display = 'none';
2879: }
2880: }
2881: }
2882: }
2883: }
2884: }
2885: return;
2886: }
2887:
2888: function checkWAF() {
2889: if (document.getElementById('wafproxy_remoteip')) {
2890: var wafvpn = 0;
2891: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
2892: if (document.display.wafproxy_vpnaccess[i].checked) {
2893: if (document.display.wafproxy_vpnaccess[i].value == 1) {
2894: wafvpn = 1;
2895: }
2896: break;
2897: }
2898: }
2899: var vpn = new Array('vpnint','vpnext');
2900: for (var i=0; i<vpn.length; i++) {
2901: if (document.getElementById('wafproxy_show_'+vpn[i])) {
2902: if (wafvpn == 1) {
2903: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
2904: }
2905: else {
2906: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
2907: }
2908: }
2909: }
2910: if (document.getElementById('wafproxyranges_$dom')) {
2911: if (wafvpn == 1) {
2912: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
2913: }
2914: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
2915: document.getElementById('wafproxyranges_$dom').style.display = 'none';
2916: }
2917: }
2918: }
2919: return;
2920: }
2921:
2922: function toggleWAF() {
2923: if (document.getElementById('wafproxy_table')) {
2924: var wafproxy = 0;
2925: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
2926: if (document.display.wafproxy_${dom}[i].checked) {
2927: if (document.display.wafproxy_${dom}[i].value == 1) {
2928: wafproxy = 1;
2929: break;
2930: }
2931: }
2932: }
2933: if (wafproxy == 1) {
2934: document.getElementById('wafproxy_table').style.display='inline';
2935: }
2936: else {
2937: document.getElementById('wafproxy_table').style.display='none';
2938: }
2939: if (document.getElementById('wafproxyrow_${dom}')) {
2940: if (wafproxy == 1) {
2941: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
2942: }
2943: else {
2944: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
2945: }
2946: }
2947: if (document.getElementById('nowafproxyrow_$dom')) {
2948: if (wafproxy == 1) {
2949: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
2950: }
2951: else {
2952: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
2953: }
2954: }
2955: }
2956: return;
2957: }
2958: // ]]>
2959: </script>
2960:
2961: ENDSCRIPT
2962: }
2963:
1.372 raeburn 2964: sub proctoring_javascript {
2965: my ($settings) = @_;
2966: my (%ordered,$total,%jstext);
2967: $total = 0;
2968: if (ref($settings) eq 'HASH') {
2969: foreach my $item (keys(%{$settings})) {
2970: if (ref($settings->{$item}) eq 'HASH') {
2971: my $num = $settings->{$item}{'order'};
2972: $ordered{$num} = $item;
2973: }
2974: }
2975: $total = scalar(keys(%{$settings}));
2976: } else {
2977: %ordered = (
2978: 0 => 'proctorio',
2979: 1 => 'examity',
2980: );
2981: $total = 2;
2982: }
2983: my @jsarray = ();
2984: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2985: push(@jsarray,$ordered{$item});
2986: }
2987: my $jstext = ' var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
2988: return <<"ENDSCRIPT";
2989: <script type="text/javascript">
2990: // <![CDATA[
2991: function reorderProctoring(form,item) {
2992: var changedVal;
2993: $jstext
2994: var maxh = $total;
2995: var current = new Array;
2996: var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2997: for (var i=0; i<proctors.length; i++) {
2998: var elementName = 'proctoring_pos_'+proctors[i];
2999: if (elementName != item) {
3000: if (form.elements[elementName]) {
3001: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3002: current[currVal] = elementName;
3003: }
3004: }
3005: }
3006: var oldVal;
3007: for (var j=0; j<maxh; j++) {
3008: if (current[j] == undefined) {
3009: oldVal = j;
3010: }
3011: }
3012: if (oldVal < changedVal) {
3013: for (var k=oldVal+1; k<=changedVal ; k++) {
3014: var elementName = current[k];
3015: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3016: }
3017: } else {
3018: for (var k=changedVal; k<oldVal; k++) {
3019: var elementName = current[k];
3020: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3021: }
3022: }
3023: return;
3024: }
3025:
3026: function toggleProctoring(form,item) {
3027: var fieldsets = document.getElementsByClassName('proctoring_'+item);
3028: if (fieldsets.length) {
3029: var radioname = 'proctoring_available_'+item;
3030: var num = form.elements[radioname].length;
3031: if (num) {
3032: var setvis = '';
3033: for (var i=0; i<num; i++) {
3034: if (form.elements[radioname][i].checked) {
3035: if (form.elements[radioname][i].value == '1') {
3036: setvis = 1;
3037: break;
3038: }
3039: }
3040: }
3041: for (var j=0; j<fieldsets.length; j++) {
3042: if (setvis) {
3043: fieldsets[j].style.display = 'block';
3044: } else {
3045: fieldsets[j].style.display = 'none';
3046: }
3047: }
3048: }
3049: }
3050: return;
3051: }
3052:
3053: // ]]>
3054: </script>
3055:
3056: ENDSCRIPT
3057: }
3058:
3059:
1.320 raeburn 3060: sub lti_javascript {
3061: my ($settings) = @_;
3062: my $togglejs = <i_toggle_js();
3063: unless (ref($settings) eq 'HASH') {
3064: return $togglejs;
3065: }
3066: my (%ordered,$total,%jstext);
3067: $total = 0;
3068: foreach my $item (keys(%{$settings})) {
3069: if (ref($settings->{$item}) eq 'HASH') {
3070: my $num = $settings->{$item}{'order'};
3071: $ordered{$num} = $item;
3072: }
3073: }
3074: $total = scalar(keys(%{$settings}));
3075: my @jsarray = ();
3076: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3077: push(@jsarray,$ordered{$item});
3078: }
3079: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
3080: return <<"ENDSCRIPT";
3081: <script type="text/javascript">
3082: // <![CDATA[
3083: function reorderLTI(form,item) {
3084: var changedVal;
3085: $jstext
3086: var newpos = 'lti_pos_add';
3087: var maxh = 1 + $total;
3088: var current = new Array;
3089: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3090: if (item == newpos) {
3091: changedVal = newitemVal;
3092: } else {
3093: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3094: current[newitemVal] = newpos;
3095: }
3096: for (var i=0; i<lti.length; i++) {
3097: var elementName = 'lti_pos_'+lti[i];
3098: if (elementName != item) {
3099: if (form.elements[elementName]) {
3100: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3101: current[currVal] = elementName;
3102: }
3103: }
3104: }
3105: var oldVal;
3106: for (var j=0; j<maxh; j++) {
3107: if (current[j] == undefined) {
3108: oldVal = j;
3109: }
3110: }
3111: if (oldVal < changedVal) {
3112: for (var k=oldVal+1; k<=changedVal ; k++) {
3113: var elementName = current[k];
3114: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3115: }
3116: } else {
3117: for (var k=changedVal; k<oldVal; k++) {
3118: var elementName = current[k];
3119: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3120: }
3121: }
3122: return;
3123: }
3124: // ]]>
3125: </script>
3126:
3127: $togglejs
3128:
3129: ENDSCRIPT
3130: }
3131:
3132: sub lti_toggle_js {
1.325 raeburn 3133: my %lcauthparmtext = &Apache::lonlocal::texthash (
3134: localauth => 'Local auth argument',
3135: krb => 'Kerberos domain',
3136: );
1.320 raeburn 3137: return <<"ENDSCRIPT";
3138: <script type="text/javascript">
3139: // <![CDATA[
3140:
3141: function toggleLTI(form,setting,item) {
1.345 raeburn 3142: if (setting == 'requser') {
3143: var fieldsets = document.getElementsByClassName('ltioption_'+item);
3144: if (fieldsets.length) {
3145: var radioname = 'lti_'+setting+'_'+item;
3146: var num = form.elements[radioname].length;
3147: if (num) {
3148: var setvis = '';
3149: for (var i=0; i<num; i++) {
3150: if (form.elements[radioname][i].checked) {
3151: if (form.elements[radioname][i].value == '1') {
3152: setvis = 1;
3153: break;
3154: }
3155: }
3156: }
1.352 raeburn 3157: for (var j=0; j<fieldsets.length; j++) {
1.345 raeburn 3158: if (setvis) {
3159: fieldsets[j].style.display = 'block';
3160: } else {
3161: fieldsets[j].style.display = 'none';
3162: }
3163: }
3164: }
3165: }
1.363 raeburn 3166: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320 raeburn 3167: var radioname = '';
3168: var divid = '';
3169: if (setting == 'user') {
3170: radioname = 'lti_mapuser_'+item;
3171: divid = 'lti_userfield_'+item;
1.343 raeburn 3172: } else if (setting == 'crs') {
1.320 raeburn 3173: radioname = 'lti_mapcrs_'+item;
3174: divid = 'lti_crsfield_'+item;
1.363 raeburn 3175: } else if (setting == 'callback') {
3176: radioname = 'lti_callback_'+item;
3177: divid = 'lti_callbackfield_'+item;
1.337 raeburn 3178: } else {
1.351 raeburn 3179: radioname = 'lti_passback_'+item;
1.337 raeburn 3180: divid = 'lti_passback_'+item;
1.320 raeburn 3181: }
3182: var num = form.elements[radioname].length;
3183: if (num) {
3184: var setvis = '';
3185: for (var i=0; i<num; i++) {
3186: if (form.elements[radioname][i].checked) {
1.363 raeburn 3187: if ((setting == 'passback') || (setting == 'callback')) {
1.337 raeburn 3188: if (form.elements[radioname][i].value == '1') {
3189: if (document.getElementById(divid)) {
3190: document.getElementById(divid).style.display = 'inline-block';
3191: }
3192: setvis = 1;
3193: break;
3194: }
3195: } else {
3196: if (form.elements[radioname][i].value == 'other') {
3197: if (document.getElementById(divid)) {
3198: document.getElementById(divid).style.display = 'inline-block';
3199: }
3200: setvis = 1;
3201: break;
1.320 raeburn 3202: }
3203: }
3204: }
3205: }
3206: if (!setvis) {
3207: if (document.getElementById(divid)) {
3208: document.getElementById(divid).style.display = 'none';
3209: }
3210: }
3211: }
3212: } else if ((setting == 'sec') || (setting == 'secsrc')) {
3213: var numsec = form.elements['lti_crssec_'+item].length;
3214: if (numsec) {
3215: var setvis = '';
3216: for (var i=0; i<numsec; i++) {
3217: if (form.elements['lti_crssec_'+item][i].checked) {
3218: if (form.elements['lti_crssec_'+item][i].value == '1') {
3219: if (document.getElementById('lti_crssecfield_'+item)) {
3220: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3221: setvis = 1;
3222: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3223: if (numsrcsec) {
3224: var setsrcvis = '';
3225: for (var j=0; j<numsrcsec; j++) {
3226: if (form.elements['lti_crssecsrc_'+item][j].checked) {
3227: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3228: if (document.getElementById('lti_secsrcfield_'+item)) {
3229: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3230: setsrcvis = 1;
3231: }
3232: }
3233: }
3234: }
3235: if (!setsrcvis) {
3236: if (document.getElementById('lti_secsrcfield_'+item)) {
3237: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3238: }
3239: }
3240: }
3241: }
3242: }
3243: }
3244: }
3245: if (!setvis) {
3246: if (document.getElementById('lti_crssecfield_'+item)) {
3247: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3248: }
3249: if (document.getElementById('lti_secsrcfield_'+item)) {
3250: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3251: }
3252: }
3253: }
1.325 raeburn 3254: } else if (setting == 'lcauth') {
3255: var numauth = form.elements['lti_lcauth_'+item].length;
3256: if (numauth) {
3257: for (var i=0; i<numauth; i++) {
3258: if (form.elements['lti_lcauth_'+item][i].checked) {
3259: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3260: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3261: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3262: } else {
3263: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3264: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3265: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3266: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3267: } else {
3268: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3269: }
3270: }
3271: }
3272: }
3273: }
3274: }
3275: }
1.326 raeburn 3276: } else if (setting == 'lcmenu') {
3277: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3278: var divid = 'lti_menufield_'+item;
3279: var setvis = '';
3280: for (var i=0; i<menus.length; i++) {
3281: var radioname = menus[i];
3282: var num = form.elements[radioname].length;
3283: if (num) {
3284: for (var j=0; j<num; j++) {
3285: if (form.elements[radioname][j].checked) {
3286: if (form.elements[radioname][j].value == '1') {
3287: if (document.getElementById(divid)) {
3288: document.getElementById(divid).style.display = 'inline-block';
3289: }
3290: setvis = 1;
3291: break;
3292: }
3293: }
3294: }
3295: }
3296: if (setvis == 1) {
3297: break;
3298: }
3299: }
3300: if (!setvis) {
3301: if (document.getElementById(divid)) {
3302: document.getElementById(divid).style.display = 'none';
3303: }
3304: }
1.320 raeburn 3305: }
3306: return;
3307: }
3308: // ]]>
3309: </script>
3310:
3311: ENDSCRIPT
3312: }
3313:
1.3 raeburn 3314: sub print_autoenroll {
1.30 raeburn 3315: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3316: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 3317: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 3318: if (ref($settings) eq 'HASH') {
3319: if (exists($settings->{'run'})) {
3320: if ($settings->{'run'} eq '0') {
3321: $runoff = ' checked="checked" ';
3322: $runon = ' ';
3323: } else {
3324: $runon = ' checked="checked" ';
3325: $runoff = ' ';
3326: }
3327: } else {
3328: if ($autorun) {
3329: $runon = ' checked="checked" ';
3330: $runoff = ' ';
3331: } else {
3332: $runoff = ' checked="checked" ';
3333: $runon = ' ';
3334: }
3335: }
1.129 raeburn 3336: if (exists($settings->{'co-owners'})) {
3337: if ($settings->{'co-owners'} eq '0') {
3338: $coownersoff = ' checked="checked" ';
3339: $coownerson = ' ';
3340: } else {
3341: $coownerson = ' checked="checked" ';
3342: $coownersoff = ' ';
3343: }
3344: } else {
3345: $coownersoff = ' checked="checked" ';
3346: $coownerson = ' ';
3347: }
1.3 raeburn 3348: if (exists($settings->{'sender_domain'})) {
3349: $defdom = $settings->{'sender_domain'};
3350: }
1.274 raeburn 3351: if (exists($settings->{'autofailsafe'})) {
3352: $failsafe = $settings->{'autofailsafe'};
3353: }
1.14 raeburn 3354: } else {
3355: if ($autorun) {
3356: $runon = ' checked="checked" ';
3357: $runoff = ' ';
3358: } else {
3359: $runoff = ' checked="checked" ';
3360: $runon = ' ';
3361: }
1.3 raeburn 3362: }
3363: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3364: my $notif_sender;
3365: if (ref($settings) eq 'HASH') {
3366: $notif_sender = $settings->{'sender_uname'};
3367: }
1.3 raeburn 3368: my $datatable='<tr class="LC_odd_row">'.
3369: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3370: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3371: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3372: $runon.' value="1" />'.&mt('Yes').'</label> '.
3373: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3374: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3375: '</tr><tr>'.
3376: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3377: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3378: &mt('username').': '.
3379: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3380: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3381: ': '.$domform.'</span></td></tr>'.
3382: '<tr class="LC_odd_row">'.
3383: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3384: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3385: '<input type="radio" name="autoassign_coowners"'.
3386: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3387: '<label><input type="radio" name="autoassign_coowners"'.
3388: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 3389: '</tr><tr>'.
3390: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
3391: '<td class="LC_right_item"><span class="LC_nobreak">'.
3392: '<input type="text" name="autoenroll_failsafe"'.
1.333 raeburn 3393: ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.274 raeburn 3394: $$rowtotal += 4;
1.3 raeburn 3395: return $datatable;
3396: }
3397:
3398: sub print_autoupdate {
1.30 raeburn 3399: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 3400: my $datatable;
3401: if ($position eq 'top') {
3402: my $updateon = ' ';
3403: my $updateoff = ' checked="checked" ';
3404: my $classlistson = ' ';
3405: my $classlistsoff = ' checked="checked" ';
3406: if (ref($settings) eq 'HASH') {
3407: if ($settings->{'run'} eq '1') {
3408: $updateon = $updateoff;
3409: $updateoff = ' ';
3410: }
3411: if ($settings->{'classlists'} eq '1') {
3412: $classlistson = $classlistsoff;
3413: $classlistsoff = ' ';
3414: }
3415: }
3416: my %title = (
3417: run => 'Auto-update active?',
3418: classlists => 'Update information in classlists?',
3419: );
3420: $datatable = '<tr class="LC_odd_row">'.
3421: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 3422: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3423: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 3424: $updateon.' value="1" />'.&mt('Yes').'</label> '.
3425: '<label><input type="radio" name="autoupdate_run"'.
3426: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3427: '</tr><tr>'.
3428: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 3429: '<td class="LC_right_item"><span class="LC_nobreak">'.
3430: '<label><input type="radio" name="classlists"'.
3431: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
3432: '<label><input type="radio" name="classlists"'.
3433: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3434: '</tr>';
1.30 raeburn 3435: $$rowtotal += 2;
1.131 raeburn 3436: } elsif ($position eq 'middle') {
3437: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3438: my $numinrow = 3;
3439: my $locknamesettings;
3440: $datatable .= &insttypes_row($settings,$types,$usertypes,
3441: $dom,$numinrow,$othertitle,
1.305 raeburn 3442: 'lockablenames',$rowtotal);
1.131 raeburn 3443: $$rowtotal ++;
1.3 raeburn 3444: } else {
1.44 raeburn 3445: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3446: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3447: 'permanentemail','id');
1.33 raeburn 3448: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3449: my $numrows = 0;
1.26 raeburn 3450: if (ref($types) eq 'ARRAY') {
3451: if (@{$types} > 0) {
3452: $datatable =
3453: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3454: \@fields,$types,\$numrows);
1.30 raeburn 3455: $$rowtotal += @{$types};
1.26 raeburn 3456: }
1.3 raeburn 3457: }
3458: $datatable .=
3459: &usertype_update_row($settings,{'default' => $othertitle},
3460: \%fieldtitles,\@fields,['default'],
3461: \$numrows);
1.30 raeburn 3462: $$rowtotal ++;
1.3 raeburn 3463: }
3464: return $datatable;
3465: }
3466:
1.125 raeburn 3467: sub print_autocreate {
3468: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 3469: my (%createon,%createoff,%currhash);
1.125 raeburn 3470: my @types = ('xml','req');
3471: if (ref($settings) eq 'HASH') {
3472: foreach my $item (@types) {
3473: $createoff{$item} = ' checked="checked" ';
3474: $createon{$item} = ' ';
3475: if (exists($settings->{$item})) {
3476: if ($settings->{$item}) {
3477: $createon{$item} = ' checked="checked" ';
3478: $createoff{$item} = ' ';
3479: }
3480: }
3481: }
1.210 raeburn 3482: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 3483: $currhash{$settings->{'xmldc'}} = 1;
3484: }
1.125 raeburn 3485: } else {
3486: foreach my $item (@types) {
3487: $createoff{$item} = ' checked="checked" ';
3488: $createon{$item} = ' ';
3489: }
3490: }
3491: $$rowtotal += 2;
1.191 raeburn 3492: my $numinrow = 2;
1.125 raeburn 3493: my $datatable='<tr class="LC_odd_row">'.
3494: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3495: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3496: '<input type="radio" name="autocreate_xml"'.
3497: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3498: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3499: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3500: '</td></tr><tr>'.
3501: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3502: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3503: '<input type="radio" name="autocreate_req"'.
3504: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3505: '<label><input type="radio" name="autocreate_req"'.
3506: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 3507: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3508: 'autocreate_xmldc',%currhash);
1.247 raeburn 3509: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3510: if ($numdc > 1) {
1.247 raeburn 3511: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3512: '</td><td class="LC_left_item">';
1.125 raeburn 3513: } else {
1.247 raeburn 3514: $datatable .= &mt('Course creation processed as:').
3515: '</td><td class="LC_right_item">';
1.125 raeburn 3516: }
1.247 raeburn 3517: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 3518: $$rowtotal += $rows;
1.125 raeburn 3519: return $datatable;
3520: }
3521:
1.23 raeburn 3522: sub print_directorysrch {
1.277 raeburn 3523: my ($position,$dom,$settings,$rowtotal) = @_;
3524: my $datatable;
3525: if ($position eq 'top') {
3526: my $instsrchon = ' ';
3527: my $instsrchoff = ' checked="checked" ';
3528: my ($exacton,$containson,$beginson);
3529: my $instlocalon = ' ';
3530: my $instlocaloff = ' checked="checked" ';
3531: if (ref($settings) eq 'HASH') {
3532: if ($settings->{'available'} eq '1') {
3533: $instsrchon = $instsrchoff;
3534: $instsrchoff = ' ';
3535: }
3536: if ($settings->{'localonly'} eq '1') {
3537: $instlocalon = $instlocaloff;
3538: $instlocaloff = ' ';
3539: }
3540: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3541: foreach my $type (@{$settings->{'searchtypes'}}) {
3542: if ($type eq 'exact') {
3543: $exacton = ' checked="checked" ';
3544: } elsif ($type eq 'contains') {
3545: $containson = ' checked="checked" ';
3546: } elsif ($type eq 'begins') {
3547: $beginson = ' checked="checked" ';
3548: }
3549: }
3550: } else {
3551: if ($settings->{'searchtypes'} eq 'exact') {
3552: $exacton = ' checked="checked" ';
3553: } elsif ($settings->{'searchtypes'} eq 'contains') {
3554: $containson = ' checked="checked" ';
3555: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 3556: $exacton = ' checked="checked" ';
3557: $containson = ' checked="checked" ';
3558: }
3559: }
1.277 raeburn 3560: }
3561: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3562: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3563:
3564: my $numinrow = 4;
3565: my $cansrchrow = 0;
3566: $datatable='<tr class="LC_odd_row">'.
3567: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3568: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3569: '<input type="radio" name="dirsrch_available"'.
3570: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3571: '<label><input type="radio" name="dirsrch_available"'.
3572: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3573: '</tr><tr>'.
3574: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3575: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3576: '<input type="radio" name="dirsrch_instlocalonly"'.
3577: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3578: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3579: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3580: '</tr>';
3581: $$rowtotal += 2;
3582: if (ref($usertypes) eq 'HASH') {
3583: if (keys(%{$usertypes}) > 0) {
3584: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 3585: $numinrow,$othertitle,'cansearch',
3586: $rowtotal);
1.277 raeburn 3587: $cansrchrow = 1;
1.25 raeburn 3588: }
1.23 raeburn 3589: }
1.277 raeburn 3590: if ($cansrchrow) {
3591: $$rowtotal ++;
3592: $datatable .= '<tr>';
3593: } else {
3594: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 3595: }
1.277 raeburn 3596: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3597: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3598: foreach my $title (@{$titleorder}) {
3599: if (defined($searchtitles->{$title})) {
3600: my $check = ' ';
3601: if (ref($settings) eq 'HASH') {
3602: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3603: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3604: $check = ' checked="checked" ';
3605: }
1.39 raeburn 3606: }
1.25 raeburn 3607: }
1.277 raeburn 3608: $datatable .= '<td class="LC_left_item">'.
3609: '<span class="LC_nobreak"><label>'.
3610: '<input type="checkbox" name="searchby" '.
3611: 'value="'.$title.'"'.$check.'/>'.
3612: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 3613: }
3614: }
1.277 raeburn 3615: $datatable .= '</tr></table></td></tr>';
3616: $$rowtotal ++;
3617: if ($cansrchrow) {
3618: $datatable .= '<tr class="LC_odd_row">';
3619: } else {
3620: $datatable .= '<tr>';
3621: }
3622: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3623: '<td class="LC_left_item" colspan="2">'.
3624: '<span class="LC_nobreak"><label>'.
3625: '<input type="checkbox" name="searchtypes" '.
3626: $exacton.' value="exact" />'.&mt('Exact match').
3627: '</label> '.
3628: '<label><input type="checkbox" name="searchtypes" '.
3629: $beginson.' value="begins" />'.&mt('Begins with').
3630: '</label> '.
3631: '<label><input type="checkbox" name="searchtypes" '.
3632: $containson.' value="contains" />'.&mt('Contains').
3633: '</label></span></td></tr>';
3634: $$rowtotal ++;
1.26 raeburn 3635: } else {
1.277 raeburn 3636: my $domsrchon = ' checked="checked" ';
3637: my $domsrchoff = ' ';
3638: my $domlocalon = ' ';
3639: my $domlocaloff = ' checked="checked" ';
3640: if (ref($settings) eq 'HASH') {
3641: if ($settings->{'lclocalonly'} eq '1') {
3642: $domlocalon = $domlocaloff;
3643: $domlocaloff = ' ';
3644: }
3645: if ($settings->{'lcavailable'} eq '0') {
3646: $domsrchoff = $domsrchon;
3647: $domsrchon = ' ';
3648: }
3649: }
3650: $datatable='<tr class="LC_odd_row">'.
3651: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3652: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3653: '<input type="radio" name="dirsrch_domavailable"'.
3654: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3655: '<label><input type="radio" name="dirsrch_domavailable"'.
3656: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3657: '</tr><tr>'.
3658: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3659: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3660: '<input type="radio" name="dirsrch_domlocalonly"'.
3661: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3662: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3663: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3664: '</tr>';
3665: $$rowtotal += 2;
1.26 raeburn 3666: }
1.25 raeburn 3667: return $datatable;
3668: }
3669:
1.28 raeburn 3670: sub print_contacts {
1.286 raeburn 3671: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3672: my $datatable;
3673: my @contacts = ('adminemail','supportemail');
1.286 raeburn 3674: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 3675: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 3676: if ($position eq 'top') {
3677: if (ref($settings) eq 'HASH') {
3678: foreach my $item (@contacts) {
3679: if (exists($settings->{$item})) {
3680: $to{$item} = $settings->{$item};
3681: }
3682: }
3683: }
3684: } elsif ($position eq 'middle') {
3685: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 3686: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 3687: foreach my $type (@mailings) {
3688: $otheremails{$type} = '';
3689: }
1.340 raeburn 3690: } elsif ($position eq 'lower') {
3691: if (ref($settings) eq 'HASH') {
3692: if (ref($settings->{'lonstatus'}) eq 'HASH') {
3693: %lonstatus = %{$settings->{'lonstatus'}};
3694: }
3695: }
1.286 raeburn 3696: } else {
3697: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 3698: foreach my $type (@mailings) {
3699: $otheremails{$type} = '';
3700: }
1.286 raeburn 3701: $bccemails{'helpdeskmail'} = '';
3702: $bccemails{'otherdomsmail'} = '';
3703: $includestr{'helpdeskmail'} = '';
3704: $includestr{'otherdomsmail'} = '';
3705: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3706: }
1.28 raeburn 3707: if (ref($settings) eq 'HASH') {
1.340 raeburn 3708: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 3709: foreach my $type (@mailings) {
3710: if (exists($settings->{$type})) {
3711: if (ref($settings->{$type}) eq 'HASH') {
3712: foreach my $item (@contacts) {
3713: if ($settings->{$type}{$item}) {
3714: $checked{$type}{$item} = ' checked="checked" ';
3715: }
3716: }
3717: $otheremails{$type} = $settings->{$type}{'others'};
3718: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3719: $bccemails{$type} = $settings->{$type}{'bcc'};
3720: if ($settings->{$type}{'include'} ne '') {
3721: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3722: $includestr{$type} = &unescape($includestr{$type});
3723: }
3724: }
3725: }
3726: } elsif ($type eq 'lonstatusmail') {
3727: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3728: }
1.28 raeburn 3729: }
3730: }
1.286 raeburn 3731: if ($position eq 'bottom') {
3732: foreach my $type (@mailings) {
3733: $bccemails{$type} = $settings->{$type}{'bcc'};
3734: if ($settings->{$type}{'include'} ne '') {
3735: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3736: $includestr{$type} = &unescape($includestr{$type});
3737: }
3738: }
3739: if (ref($settings->{'helpform'}) eq 'HASH') {
3740: if (ref($fields) eq 'ARRAY') {
3741: foreach my $field (@{$fields}) {
3742: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3743: }
1.286 raeburn 3744: }
3745: if (exists($settings->{'helpform'}{'maxsize'})) {
3746: $maxsize = $settings->{'helpform'}{'maxsize'};
3747: } else {
1.289 raeburn 3748: $maxsize = '1.0';
1.286 raeburn 3749: }
3750: } else {
3751: if (ref($fields) eq 'ARRAY') {
3752: foreach my $field (@{$fields}) {
3753: $currfield{$field} = 'yes';
1.134 raeburn 3754: }
1.28 raeburn 3755: }
1.286 raeburn 3756: $maxsize = '1.0';
1.28 raeburn 3757: }
3758: }
3759: } else {
1.286 raeburn 3760: if ($position eq 'top') {
3761: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3762: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3763: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3764: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 3765: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3766: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3767: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3768: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 3769: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3770: } elsif ($position eq 'bottom') {
3771: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3772: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3773: if (ref($fields) eq 'ARRAY') {
3774: foreach my $field (@{$fields}) {
3775: $currfield{$field} = 'yes';
3776: }
3777: }
3778: $maxsize = '1.0';
3779: }
1.28 raeburn 3780: }
3781: my ($titles,$short_titles) = &contact_titles();
3782: my $rownum = 0;
3783: my $css_class;
1.286 raeburn 3784: if ($position eq 'top') {
3785: foreach my $item (@contacts) {
3786: $css_class = $rownum%2?' class="LC_odd_row"':'';
3787: $datatable .= '<tr'.$css_class.'>'.
3788: '<td><span class="LC_nobreak">'.$titles->{$item}.
3789: '</span></td><td class="LC_right_item">'.
3790: '<input type="text" name="'.$item.'" value="'.
3791: $to{$item}.'" /></td></tr>';
3792: $rownum ++;
3793: }
1.315 raeburn 3794: } elsif ($position eq 'bottom') {
3795: $css_class = $rownum%2?' class="LC_odd_row"':'';
3796: $datatable .= '<tr'.$css_class.'>'.
3797: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3798: &mt('(e-mail, subject, and description always shown)').
3799: '</td><td class="LC_left_item">';
3800: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3801: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3802: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3803: foreach my $field (@{$fields}) {
3804: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3805: if (($field eq 'screenshot') || ($field eq 'cc')) {
3806: $datatable .= ' '.&mt('(logged-in users)');
3807: }
3808: $datatable .='</td><td>';
3809: my $clickaction;
3810: if ($field eq 'screenshot') {
3811: $clickaction = ' onclick="screenshotSize(this);"';
3812: }
3813: if (ref($possoptions->{$field}) eq 'ARRAY') {
3814: foreach my $option (@{$possoptions->{$field}}) {
3815: my $checked;
3816: if ($currfield{$field} eq $option) {
3817: $checked = ' checked="checked"';
3818: }
3819: $datatable .= '<span class="LC_nobreak"><label>'.
3820: '<input type="radio" name="helpform_'.$field.'" '.
3821: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3822: '</label></span>'.(' 'x2);
3823: }
3824: }
3825: if ($field eq 'screenshot') {
3826: my $display;
3827: if ($currfield{$field} eq 'no') {
3828: $display = ' style="display:none"';
3829: }
1.334 raeburn 3830: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 3831: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3832: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3833: }
3834: $datatable .= '</td></tr>';
3835: }
3836: $datatable .= '</table>';
3837: }
3838: $datatable .= '</td></tr>'."\n";
3839: $rownum ++;
3840: }
1.340 raeburn 3841: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 3842: foreach my $type (@mailings) {
3843: $css_class = $rownum%2?' class="LC_odd_row"':'';
3844: $datatable .= '<tr'.$css_class.'>'.
3845: '<td><span class="LC_nobreak">'.
3846: $titles->{$type}.': </span></td>'.
3847: '<td class="LC_left_item">';
3848: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3849: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3850: }
3851: $datatable .= '<span class="LC_nobreak">';
3852: foreach my $item (@contacts) {
3853: $datatable .= '<label>'.
3854: '<input type="checkbox" name="'.$type.'"'.
3855: $checked{$type}{$item}.
3856: ' value="'.$item.'" />'.$short_titles->{$item}.
3857: '</label> ';
3858: }
3859: $datatable .= '</span><br />'.&mt('Others').': '.
3860: '<input type="text" name="'.$type.'_others" '.
3861: 'value="'.$otheremails{$type}.'" />';
3862: my %locchecked;
3863: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3864: foreach my $loc ('s','b') {
3865: if ($includeloc{$type} eq $loc) {
3866: $locchecked{$loc} = ' checked="checked"';
3867: last;
3868: }
3869: }
3870: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3871: '<input type="text" name="'.$type.'_bcc" '.
3872: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3873: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3874: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 3875: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 3876: '<span class="LC_nobreak">'.&mt('Location:').' '.
3877: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3878: (' 'x2).
3879: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3880: '</span></fieldset>';
3881: }
3882: $datatable .= '</td></tr>'."\n";
3883: $rownum ++;
3884: }
1.28 raeburn 3885: }
1.286 raeburn 3886: if ($position eq 'middle') {
3887: my %choices;
1.340 raeburn 3888: my $corelink = &core_link_msu();
3889: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 3890: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 3891: $corelink);
3892: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
3893: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 3894: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 3895: 'reportupdates' => 'on',
3896: 'reportstatus' => 'on');
1.286 raeburn 3897: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3898: \%choices,$rownum);
3899: $datatable .= $reports;
1.340 raeburn 3900: } elsif ($position eq 'lower') {
1.378 raeburn 3901: my (%current,%excluded,%weights);
1.340 raeburn 3902: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
3903: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378 raeburn 3904: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340 raeburn 3905: } else {
1.378 raeburn 3906: $current{'errorthreshold'} = $defaults->{'threshold'};
1.340 raeburn 3907: }
3908: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378 raeburn 3909: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340 raeburn 3910: } else {
1.378 raeburn 3911: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340 raeburn 3912: }
3913: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 3914: foreach my $type ('E','W','N','U') {
1.340 raeburn 3915: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
3916: $weights{$type} = $lonstatus{'weights'}{$type};
3917: } else {
3918: $weights{$type} = $defaults->{$type};
3919: }
3920: }
3921: } else {
1.341 raeburn 3922: foreach my $type ('E','W','N','U') {
1.340 raeburn 3923: $weights{$type} = $defaults->{$type};
3924: }
3925: }
3926: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
3927: if (@{$lonstatus{'excluded'}} > 0) {
3928: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
3929: }
3930: }
1.378 raeburn 3931: foreach my $item ('errorthreshold','errorsysmail') {
3932: $css_class = $rownum%2?' class="LC_odd_row"':'';
3933: $datatable .= '<tr'.$css_class.'>'.
3934: '<td class="LC_left_item"><span class="LC_nobreak">'.
3935: $titles->{$item}.
3936: '</span></td><td class="LC_left_item">'.
3937: '<input type="text" name="'.$item.'" value="'.
3938: $current{$item}.'" size="5" /></td></tr>';
3939: $rownum ++;
3940: }
1.340 raeburn 3941: $css_class = $rownum%2?' class="LC_odd_row"':'';
3942: $datatable .= '<tr'.$css_class.'>'.
3943: '<td class="LC_left_item">'.
3944: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
3945: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 3946: foreach my $type ('E','W','N','U') {
1.340 raeburn 3947: $datatable .= '<td>'.$names->{$type}.'<br />'.
3948: '<input type="text" name="errorweights_'.$type.'" value="'.
3949: $weights{$type}.'" size="5" /></td>';
3950: }
3951: $datatable .= '</tr></table></tr>';
3952: $rownum ++;
3953: $css_class = $rownum%2?' class="LC_odd_row"':'';
3954: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
3955: $titles->{'errorexcluded'}.'</td>'.
3956: '<td class="LC_left_item"><table>';
3957: my $numinrow = 4;
3958: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
3959: for (my $i=0; $i<@ids; $i++) {
3960: my $rem = $i%($numinrow);
3961: if ($rem == 0) {
3962: if ($i > 0) {
3963: $datatable .= '</tr>';
3964: }
3965: $datatable .= '<tr>';
3966: }
3967: my $check;
3968: if ($excluded{$ids[$i]}) {
3969: $check = ' checked="checked" ';
3970: }
3971: $datatable .= '<td class="LC_left_item">'.
3972: '<span class="LC_nobreak"><label>'.
3973: '<input type="checkbox" name="errorexcluded" '.
3974: 'value="'.$ids[$i].'"'.$check.' />'.
3975: $ids[$i].'</label></span></td>';
3976: }
3977: my $colsleft = $numinrow - @ids%($numinrow);
3978: if ($colsleft > 1 ) {
3979: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3980: ' </td>';
3981: } elsif ($colsleft == 1) {
3982: $datatable .= '<td class="LC_left_item"> </td>';
3983: }
3984: $datatable .= '</tr></table></td></tr>';
3985: $rownum ++;
1.286 raeburn 3986: } elsif ($position eq 'bottom') {
1.315 raeburn 3987: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3988: my (@posstypes,%usertypeshash);
3989: if (ref($types) eq 'ARRAY') {
3990: @posstypes = @{$types};
3991: }
3992: if (@posstypes) {
3993: if (ref($usertypes) eq 'HASH') {
3994: %usertypeshash = %{$usertypes};
3995: }
3996: my @overridden;
3997: my $numinrow = 4;
3998: if (ref($settings) eq 'HASH') {
3999: if (ref($settings->{'overrides'}) eq 'HASH') {
4000: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4001: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4002: push(@overridden,$key);
4003: foreach my $item (@contacts) {
4004: if ($settings->{'overrides'}{$key}{$item}) {
4005: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4006: }
4007: }
4008: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4009: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4010: $includeloc{'override_'.$key} = '';
4011: $includestr{'override_'.$key} = '';
4012: if ($settings->{'overrides'}{$key}{'include'} ne '') {
4013: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
4014: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4015: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4016: }
1.286 raeburn 4017: }
4018: }
4019: }
1.315 raeburn 4020: }
4021: my $customclass = 'LC_helpdesk_override';
4022: my $optionsprefix = 'LC_options_helpdesk_';
4023:
4024: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4025:
4026: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4027: $numinrow,$othertitle,'overrides',
4028: \$rownum,$onclicktypes,$customclass);
4029: $rownum ++;
4030: $usertypeshash{'default'} = $othertitle;
4031: foreach my $status (@posstypes) {
4032: my $css_class;
4033: if ($rownum%2) {
4034: $css_class = 'LC_odd_row ';
4035: }
4036: $css_class .= $customclass;
4037: my $rowid = $optionsprefix.$status;
4038: my $hidden = 1;
4039: my $currstyle = 'display:none';
4040: if (grep(/^\Q$status\E$/,@overridden)) {
4041: $currstyle = 'display:table-row';
4042: $hidden = 0;
4043: }
4044: my $key = 'override_'.$status;
4045: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4046: $includeloc{$key},$includestr{$key},$status,$rowid,
4047: $usertypeshash{$status},$css_class,$currstyle,
4048: \@contacts,$short_titles);
4049: unless ($hidden) {
4050: $rownum ++;
1.286 raeburn 4051: }
4052: }
1.134 raeburn 4053: }
1.28 raeburn 4054: }
1.30 raeburn 4055: $$rowtotal += $rownum;
1.28 raeburn 4056: return $datatable;
4057: }
4058:
1.340 raeburn 4059: sub core_link_msu {
4060: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4061: &mt('LON-CAPA core group - MSU'),600,500);
4062: }
4063:
1.315 raeburn 4064: sub overridden_helpdesk {
4065: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4066: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4067: my $class = 'LC_left_item';
4068: if ($css_class) {
4069: $css_class = ' class="'.$css_class.'"';
4070: }
4071: if ($rowid) {
4072: $rowid = ' id="'.$rowid.'"';
4073: }
4074: if ($rowstyle) {
4075: $rowstyle = ' style="'.$rowstyle.'"';
4076: }
4077: my ($output,$description);
4078: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4079: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4080: "<td>$description</td>\n".
4081: '<td class="'.$class.'" colspan="2">'.
4082: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4083: '<span class="LC_nobreak">';
4084: if (ref($contacts) eq 'ARRAY') {
4085: foreach my $item (@{$contacts}) {
4086: my $check;
4087: if (ref($checked) eq 'HASH') {
4088: $check = $checked->{$item};
4089: }
4090: my $title;
4091: if (ref($short_titles) eq 'HASH') {
4092: $title = $short_titles->{$item};
4093: }
4094: $output .= '<label>'.
4095: '<input type="checkbox" name="override_'.$type.'"'.$check.
4096: ' value="'.$item.'" />'.$title.'</label> ';
4097: }
4098: }
4099: $output .= '</span><br />'.&mt('Others').': '.
4100: '<input type="text" name="override_'.$type.'_others" '.
4101: 'value="'.$otheremails.'" />';
4102: my %locchecked;
4103: foreach my $loc ('s','b') {
4104: if ($includeloc eq $loc) {
4105: $locchecked{$loc} = ' checked="checked"';
4106: last;
4107: }
4108: }
4109: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4110: '<input type="text" name="override_'.$type.'_bcc" '.
4111: 'value="'.$bccemails.'" /></fieldset>'.
4112: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4113: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4114: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 4115: '<span class="LC_nobreak">'.&mt('Location:').' '.
4116: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4117: (' 'x2).
4118: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4119: '</span></fieldset>'.
4120: '</td></tr>'."\n";
4121: return $output;
4122: }
4123:
1.286 raeburn 4124: sub contacts_javascript {
4125: return <<"ENDSCRIPT";
4126:
4127: <script type="text/javascript">
4128: // <![CDATA[
4129:
4130: function screenshotSize(field) {
4131: if (document.getElementById('help_screenshotsize')) {
4132: if (field.value == 'no') {
1.289 raeburn 4133: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 4134: } else {
4135: document.getElementById('help_screenshotsize').style.display="";
4136: }
4137: }
4138: return;
4139: }
4140:
1.315 raeburn 4141: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4142: if (form.elements[checkbox].length != undefined) {
4143: var count = 0;
4144: if (docount) {
4145: for (var i=0; i<form.elements[checkbox].length; i++) {
4146: if (form.elements[checkbox][i].checked) {
4147: count ++;
4148: }
4149: }
4150: }
4151: for (var i=0; i<form.elements[checkbox].length; i++) {
4152: var type = form.elements[checkbox][i].value;
4153: if (document.getElementById(prefix+type)) {
4154: if (form.elements[checkbox][i].checked) {
4155: document.getElementById(prefix+type).style.display = 'table-row';
4156: if (count % 2 == 1) {
4157: document.getElementById(prefix+type).className = target+' LC_odd_row';
4158: } else {
4159: document.getElementById(prefix+type).className = target;
4160: }
4161: count ++;
4162: } else {
4163: document.getElementById(prefix+type).style.display = 'none';
4164: }
4165: }
4166: }
4167: }
4168: return;
4169: }
4170:
4171:
1.286 raeburn 4172: // ]]>
4173: </script>
4174:
4175: ENDSCRIPT
4176: }
4177:
1.118 jms 4178: sub print_helpsettings {
1.282 raeburn 4179: my ($position,$dom,$settings,$rowtotal) = @_;
4180: my $confname = $dom.'-domainconfig';
1.285 raeburn 4181: my $formname = 'display';
1.168 raeburn 4182: my ($datatable,$itemcount);
1.282 raeburn 4183: if ($position eq 'top') {
4184: $itemcount = 1;
4185: my (%choices,%defaultchecked,@toggles);
4186: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4187: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4188: &mt('LON-CAPA bug tracker'),600,500));
4189: %defaultchecked = ('submitbugs' => 'on');
4190: @toggles = ('submitbugs');
4191: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4192: \%choices,$itemcount);
4193: $$rowtotal ++;
4194: } else {
4195: my $css_class;
4196: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 4197: my (%customroles,%ordered,%current);
1.301 raeburn 4198: if (ref($settings) eq 'HASH') {
4199: if (ref($settings->{'adhoc'}) eq 'HASH') {
4200: %current = %{$settings->{'adhoc'}};
4201: }
1.285 raeburn 4202: }
4203: my $count = 0;
4204: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 4205: if ($key=~/^rolesdef\_(\w+)$/) {
4206: my $rolename = $1;
1.285 raeburn 4207: my (%privs,$order);
1.282 raeburn 4208: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4209: $customroles{$rolename} = \%privs;
1.285 raeburn 4210: if (ref($current{$rolename}) eq 'HASH') {
4211: $order = $current{$rolename}{'order'};
4212: }
4213: if ($order eq '') {
4214: $order = $count;
4215: }
4216: $ordered{$order} = $rolename;
4217: $count++;
4218: }
4219: }
4220: my $maxnum = scalar(keys(%ordered));
4221: my @roles_by_num = ();
4222: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4223: push(@roles_by_num,$item);
4224: }
4225: my $context = 'domprefs';
4226: my $crstype = 'Course';
4227: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 4228: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 4229: my ($numstatustypes,@jsarray);
4230: if (ref($types) eq 'ARRAY') {
4231: if (@{$types} > 0) {
4232: $numstatustypes = scalar(@{$types});
4233: push(@accesstypes,'status');
4234: @jsarray = ('bystatus');
1.282 raeburn 4235: }
4236: }
1.290 raeburn 4237: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 4238: if (keys(%domhelpdesk)) {
4239: push(@accesstypes,('inc','exc'));
4240: push(@jsarray,('notinc','notexc'));
4241: }
4242: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 4243: my $context = 'domprefs';
4244: my $crstype = 'Course';
1.285 raeburn 4245: my $prefix = 'helproles_';
4246: my $add_class = 'LC_hidden';
4247: foreach my $num (@roles_by_num) {
4248: my $role = $ordered{$num};
4249: my ($desc,$access,@statuses);
4250: if (ref($current{$role}) eq 'HASH') {
4251: $desc = $current{$role}{'desc'};
4252: $access = $current{$role}{'access'};
4253: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4254: @statuses = @{$current{$role}{'insttypes'}};
4255: }
4256: }
4257: if ($desc eq '') {
4258: $desc = $role;
4259: }
4260: my $identifier = 'custhelp'.$num;
1.282 raeburn 4261: my %full=();
4262: my %levels= (
4263: course => {},
4264: domain => {},
4265: system => {},
4266: );
4267: my %levelscurrent=(
4268: course => {},
4269: domain => {},
4270: system => {},
4271: );
4272: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4273: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4274: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 4275: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 4276: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 4277: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4278: for (my $k=0; $k<=$maxnum; $k++) {
4279: my $vpos = $k+1;
4280: my $selstr;
4281: if ($k == $num) {
4282: $selstr = ' selected="selected" ';
4283: }
4284: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4285: }
4286: $datatable .= '</select>'.(' 'x2).
4287: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4288: '</td>'.
4289: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4290: &mt('Name shown to users:').
4291: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4292: '</fieldset>'.
4293: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4294: $othertitle,$usertypes,$types,\%domhelpdesk).
4295: '<fieldset>'.
4296: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 4297: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 4298: \%levelscurrent,$identifier,
4299: 'LC_hidden',$prefix.$num.'_privs').
4300: '</fieldset></td>';
1.282 raeburn 4301: $itemcount ++;
4302: }
4303: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4304: my $newcust = 'custhelp'.$count;
4305: my (%privs,%levelscurrent);
4306: my %full=();
4307: my %levels= (
4308: course => {},
4309: domain => {},
4310: system => {},
4311: );
4312: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4313: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 4314: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 4315: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 4316: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4317: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4318: for (my $k=0; $k<$maxnum+1; $k++) {
4319: my $vpos = $k+1;
4320: my $selstr;
4321: if ($k == $maxnum) {
4322: $selstr = ' selected="selected" ';
4323: }
4324: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4325: }
4326: $datatable .= '</select> '."\n".
1.282 raeburn 4327: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4328: '</label></span></td>'.
1.285 raeburn 4329: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4330: '<span class="LC_nobreak">'.
4331: &mt('Internal name:').
4332: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4333: '</span>'.(' 'x4).
4334: '<span class="LC_nobreak">'.
4335: &mt('Name shown to users:').
4336: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4337: '</span></fieldset>'.
4338: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4339: $usertypes,$types,\%domhelpdesk).
4340: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 4341: &Apache::lonuserutils::custom_role_header($context,$crstype,
4342: \@templateroles,$newcust).
4343: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4344: \%levelscurrent,$newcust).
1.334 raeburn 4345: '</fieldset>'.
4346: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4347: '</td></tr>';
1.282 raeburn 4348: $count ++;
4349: $$rowtotal += $count;
4350: }
1.166 raeburn 4351: return $datatable;
1.121 raeburn 4352: }
4353:
1.285 raeburn 4354: sub adhocbutton {
4355: my ($prefix,$num,$field,$visibility) = @_;
4356: my %lt = &Apache::lonlocal::texthash(
4357: show => 'Show details',
4358: hide => 'Hide details',
4359: );
4360: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4361: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4362: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4363: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4364: }
4365:
4366: sub helpsettings_javascript {
4367: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4368: return unless(ref($roles_by_num) eq 'ARRAY');
4369: my %html_js_lt = &Apache::lonlocal::texthash(
4370: show => 'Show details',
4371: hide => 'Hide details',
4372: );
4373: &html_escape(\%html_js_lt);
4374: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4375: return <<"ENDSCRIPT";
4376: <script type="text/javascript">
4377: // <![CDATA[
4378:
4379: function reorderHelpRoles(form,item) {
4380: var changedVal;
4381: $jstext
4382: var newpos = 'helproles_${total}_pos';
4383: var maxh = 1 + $total;
4384: var current = new Array();
4385: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4386: if (item == newpos) {
4387: changedVal = newitemVal;
4388: } else {
4389: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4390: current[newitemVal] = newpos;
4391: }
4392: for (var i=0; i<helproles.length; i++) {
4393: var elementName = 'helproles_'+helproles[i]+'_pos';
4394: if (elementName != item) {
4395: if (form.elements[elementName]) {
4396: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4397: current[currVal] = elementName;
4398: }
4399: }
4400: }
4401: var oldVal;
4402: for (var j=0; j<maxh; j++) {
4403: if (current[j] == undefined) {
4404: oldVal = j;
4405: }
4406: }
4407: if (oldVal < changedVal) {
4408: for (var k=oldVal+1; k<=changedVal ; k++) {
4409: var elementName = current[k];
4410: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4411: }
4412: } else {
4413: for (var k=changedVal; k<oldVal; k++) {
4414: var elementName = current[k];
4415: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4416: }
4417: }
4418: return;
4419: }
4420:
4421: function helpdeskAccess(num) {
4422: var curraccess = null;
4423: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4424: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4425: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4426: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4427: }
4428: }
4429: }
4430: var shown = Array();
4431: var hidden = Array();
4432: if (curraccess == 'none') {
4433: hidden = Array('$hiddenstr');
4434: } else {
4435: if (curraccess == 'status') {
4436: shown = Array('bystatus');
4437: hidden = Array('notinc','notexc');
4438: } else {
4439: if (curraccess == 'exc') {
4440: shown = Array('notexc');
4441: hidden = Array('notinc','bystatus');
4442: }
4443: if (curraccess == 'inc') {
4444: shown = Array('notinc');
4445: hidden = Array('notexc','bystatus');
4446: }
1.293 raeburn 4447: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 4448: hidden = Array('notinc','notexc','bystatus');
4449: }
4450: }
4451: }
4452: if (hidden.length > 0) {
4453: for (var i=0; i<hidden.length; i++) {
4454: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4455: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4456: }
4457: }
4458: }
4459: if (shown.length > 0) {
4460: for (var i=0; i<shown.length; i++) {
4461: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4462: if (shown[i] == 'privs') {
4463: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4464: } else {
4465: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4466: }
4467: }
4468: }
4469: }
4470: return;
4471: }
4472:
4473: function toggleHelpdeskItem(num,field) {
4474: if (document.getElementById('helproles_'+num+'_'+field)) {
4475: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 4476: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 4477: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4478: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4479: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4480: }
4481: } else {
4482: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4483: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4484: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4485: }
4486: }
4487: }
4488: return;
4489: }
4490:
4491: // ]]>
4492: </script>
4493:
4494: ENDSCRIPT
4495: }
4496:
4497: sub helpdeskroles_access {
4498: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4499: $usertypes,$types,$domhelpdesk) = @_;
4500: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4501: my %lt = &Apache::lonlocal::texthash(
4502: 'rou' => 'Role usage',
4503: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 4504: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4505: 'dh' => 'All with domain helpdesk role',
4506: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 4507: 'none' => 'None',
4508: 'status' => 'Determined based on institutional status',
4509: 'inc' => 'Include all, but exclude specific personnel',
4510: 'exc' => 'Exclude all, but include specific personnel',
4511: );
4512: my %usecheck = (
4513: all => ' checked="checked"',
4514: );
4515: my %displaydiv = (
4516: status => 'none',
4517: inc => 'none',
4518: exc => 'none',
4519: priv => 'block',
4520: );
4521: my $output;
4522: if (ref($current) eq 'HASH') {
4523: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4524: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4525: $usecheck{$current->{access}} = $usecheck{'all'};
4526: delete($usecheck{'all'});
4527: if ($current->{access} =~ /^(status|inc|exc)$/) {
4528: my $access = $1;
4529: $displaydiv{$access} = 'inline';
4530: } elsif ($current->{access} eq 'none') {
4531: $displaydiv{'priv'} = 'none';
4532: }
4533: }
4534: }
4535: }
4536: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4537: '<p>'.$lt{'whi'}.'</p>';
4538: foreach my $access (@{$accesstypes}) {
4539: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4540: ' onclick="helpdeskAccess('."'$num'".');" />'.
4541: $lt{$access}.'</label>';
4542: if ($access eq 'status') {
4543: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4544: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4545: $othertitle,$usertypes,$types).
4546: '</div>';
4547: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4548: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4549: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4550: '</div>';
4551: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4552: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4553: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4554: '</div>';
4555: }
4556: $output .= '</p>';
4557: }
4558: $output .= '</fieldset>';
4559: return $output;
4560: }
4561:
1.121 raeburn 4562: sub radiobutton_prefs {
1.192 raeburn 4563: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 4564: $additional,$align) = @_;
1.121 raeburn 4565: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4566: (ref($choices) eq 'HASH'));
4567:
1.170 raeburn 4568: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 4569:
4570: foreach my $item (@{$toggles}) {
4571: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4572: $checkedon{$item} = ' checked="checked" ';
4573: $checkedoff{$item} = ' ';
1.121 raeburn 4574: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4575: $checkedoff{$item} = ' checked="checked" ';
4576: $checkedon{$item} = ' ';
4577: }
4578: }
4579: if (ref($settings) eq 'HASH') {
1.121 raeburn 4580: foreach my $item (@{$toggles}) {
1.118 jms 4581: if ($settings->{$item} eq '1') {
4582: $checkedon{$item} = ' checked="checked" ';
4583: $checkedoff{$item} = ' ';
4584: } elsif ($settings->{$item} eq '0') {
4585: $checkedoff{$item} = ' checked="checked" ';
4586: $checkedon{$item} = ' ';
4587: }
4588: }
1.121 raeburn 4589: }
1.192 raeburn 4590: if ($onclick) {
4591: $onclick = ' onclick="'.$onclick.'"';
4592: }
1.121 raeburn 4593: foreach my $item (@{$toggles}) {
1.118 jms 4594: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4595: $datatable .=
1.306 raeburn 4596: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 4597: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 4598: '</span></td>';
4599: if ($align eq 'left') {
4600: $datatable .= '<td class="LC_left_item">';
4601: } else {
4602: $datatable .= '<td class="LC_right_item">';
4603: }
1.289 raeburn 4604: $datatable .=
1.257 raeburn 4605: '<span class="LC_nobreak">'.
1.118 jms 4606: '<label><input type="radio" name="'.
1.192 raeburn 4607: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 4608: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 4609: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
4610: '</span>'.$additional.
4611: '</td>'.
1.118 jms 4612: '</tr>';
4613: $itemcount ++;
1.121 raeburn 4614: }
4615: return ($datatable,$itemcount);
4616: }
4617:
1.267 raeburn 4618: sub print_ltitools {
4619: my ($dom,$settings,$rowtotal) = @_;
4620: my $rownum = 0;
4621: my $css_class;
4622: my $itemcount = 1;
4623: my $maxnum = 0;
4624: my %ordered;
4625: if (ref($settings) eq 'HASH') {
4626: foreach my $item (keys(%{$settings})) {
4627: if (ref($settings->{$item}) eq 'HASH') {
4628: my $num = $settings->{$item}{'order'};
4629: $ordered{$num} = $item;
4630: }
4631: }
4632: }
4633: my $confname = $dom.'-domainconfig';
4634: my $switchserver = &check_switchserver($dom,$confname);
4635: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 4636: my $datatable;
1.267 raeburn 4637: my %lt = <itools_names();
4638: my @courseroles = ('cc','in','ta','ep','st');
4639: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.324 raeburn 4640: my @fields = ('fullname','firstname','lastname','email','roles','user');
1.267 raeburn 4641: if (keys(%ordered)) {
4642: my @items = sort { $a <=> $b } keys(%ordered);
4643: for (my $i=0; $i<@items; $i++) {
4644: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4645: my $item = $ordered{$items[$i]};
1.323 raeburn 4646: my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267 raeburn 4647: if (ref($settings->{$item}) eq 'HASH') {
4648: $title = $settings->{$item}->{'title'};
4649: $url = $settings->{$item}->{'url'};
4650: $key = $settings->{$item}->{'key'};
4651: $secret = $settings->{$item}->{'secret'};
1.322 raeburn 4652: $lifetime = $settings->{$item}->{'lifetime'};
1.267 raeburn 4653: my $image = $settings->{$item}->{'image'};
4654: if ($image ne '') {
4655: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
4656: }
1.323 raeburn 4657: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
4658: $sigsel{'HMAC-256'} = ' selected="selected"';
4659: } else {
4660: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
4661: }
1.267 raeburn 4662: }
1.319 raeburn 4663: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267 raeburn 4664: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4665: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
4666: for (my $k=0; $k<=$maxnum; $k++) {
4667: my $vpos = $k+1;
4668: my $selstr;
4669: if ($k == $i) {
4670: $selstr = ' selected="selected" ';
4671: }
4672: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4673: }
4674: $datatable .= '</select>'.(' 'x2).
4675: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4676: &mt('Delete?').'</label></span></td>'.
4677: '<td colspan="2">'.
4678: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4679: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267 raeburn 4680: (' 'x2).
4681: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4682: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4683: (' 'x2).
4684: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4685: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4686: (' 'x2).
4687: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
4688: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
4689: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267 raeburn 4690: '<br /><br />'.
1.323 raeburn 4691: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267 raeburn 4692: ' value="'.$url.'" /></span>'.
4693: (' 'x2).
1.319 raeburn 4694: '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267 raeburn 4695: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4696: (' 'x2).
1.322 raeburn 4697: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
4698: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
4699: (' 'x2).
1.267 raeburn 4700: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4701: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4702: '<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>'.
4703: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4704: '</fieldset>'.
4705: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4706: '<span class="LC_nobreak">'.&mt('Display target:');
4707: my %currdisp;
4708: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4709: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4710: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 4711: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4712: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 4713: } else {
4714: $currdisp{'iframe'} = ' checked="checked"';
4715: }
4716: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4717: $currdisp{'width'} = $1;
4718: }
4719: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4720: $currdisp{'height'} = $1;
4721: }
1.296 raeburn 4722: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4723: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 4724: } else {
4725: $currdisp{'iframe'} = ' checked="checked"';
4726: }
1.298 raeburn 4727: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4728: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4729: $lt{$disp}.'</label>'.(' 'x2);
4730: }
4731: $datatable .= (' 'x4);
4732: foreach my $dimen ('width','height') {
4733: $datatable .= '<label>'.$lt{$dimen}.' '.
4734: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4735: (' 'x2);
4736: }
1.334 raeburn 4737: $datatable .= '</span><br />'.
1.296 raeburn 4738: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 4739: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
1.296 raeburn 4740: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4741: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
4742: '</textarea></div><div style=""></div><br />';
1.319 raeburn 4743: my %units = (
4744: 'passback' => 'days',
4745: 'roster' => 'seconds',
4746: );
1.267 raeburn 4747: foreach my $extra ('passback','roster') {
1.319 raeburn 4748: my $validsty = 'none';
4749: my $currvalid;
1.267 raeburn 4750: my $checkedon = '';
4751: my $checkedoff = ' checked="checked"';
4752: if ($settings->{$item}->{$extra}) {
4753: $checkedon = $checkedoff;
4754: $checkedoff = '';
1.319 raeburn 4755: $validsty = 'inline-block';
4756: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
4757: $currvalid = $settings->{$item}->{$extra.'valid'};
4758: }
4759: }
4760: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
4761: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4762: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
4763: &mt('No').'</label>'.(' 'x2).
4764: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
4765: &mt('Yes').'</label></span></div>'.
4766: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
4767: '<span class="LC_nobreak">'.
4768: &mt("at least [_1] $units{$extra} after launch",
4769: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
4770: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4771: }
1.319 raeburn 4772: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
1.267 raeburn 4773: if ($imgsrc) {
4774: $datatable .= $imgsrc.
4775: '<label><input type="checkbox" name="ltitools_image_del"'.
4776: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
4777: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
4778: } else {
4779: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4780: }
4781: if ($switchserver) {
4782: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4783: } else {
4784: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
4785: }
4786: $datatable .= '</span></fieldset>';
1.324 raeburn 4787: my (%checkedfields,%rolemaps,$userincdom);
1.267 raeburn 4788: if (ref($settings->{$item}) eq 'HASH') {
4789: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
4790: %checkedfields = %{$settings->{$item}->{'fields'}};
4791: }
1.324 raeburn 4792: $userincdom = $settings->{$item}->{'incdom'};
1.267 raeburn 4793: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
4794: %rolemaps = %{$settings->{$item}->{'roles'}};
4795: $checkedfields{'roles'} = 1;
4796: }
4797: }
4798: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4799: '<span class="LC_nobreak">';
1.324 raeburn 4800: my $userfieldstyle = 'display:none;';
4801: my $seluserdom = '';
4802: my $unseluserdom = ' selected="selected"';
1.267 raeburn 4803: foreach my $field (@fields) {
1.324 raeburn 4804: my ($checked,$onclick,$id,$spacer);
1.267 raeburn 4805: if ($checkedfields{$field}) {
4806: $checked = ' checked="checked"';
4807: }
1.324 raeburn 4808: if ($field eq 'user') {
4809: $id = ' id="ltitools_user_field_'.$i.'"';
4810: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
4811: if ($checked) {
4812: $userfieldstyle = 'display:inline-block';
4813: if ($userincdom) {
4814: $seluserdom = $unseluserdom;
4815: $unseluserdom = '';
4816: }
4817: }
4818: } else {
4819: $spacer = (' ' x2);
4820: }
1.267 raeburn 4821: $datatable .= '<label>'.
1.324 raeburn 4822: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
4823: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4824: }
1.324 raeburn 4825: $datatable .= '</span>';
4826: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
4827: '<span class="LC_nobreak"> : '.
4828: '<select name="ltitools_userincdom_'.$i.'">'.
4829: '<option value="">'.&mt('Select').'</option>'.
4830: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
4831: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
4832: '</select></span></div>';
4833: $datatable .= '</fieldset>'.
1.267 raeburn 4834: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4835: foreach my $role (@courseroles) {
4836: my ($selected,$selectnone);
4837: if (!$rolemaps{$role}) {
4838: $selectnone = ' selected="selected"';
4839: }
1.306 raeburn 4840: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4841: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4842: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
4843: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4844: foreach my $ltirole (@ltiroles) {
4845: unless ($selectnone) {
4846: if ($rolemaps{$role} eq $ltirole) {
4847: $selected = ' selected="selected"';
4848: } else {
4849: $selected = '';
4850: }
4851: }
4852: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
4853: }
4854: $datatable .= '</select></td>';
4855: }
1.273 raeburn 4856: $datatable .= '</tr></table></fieldset>';
4857: my %courseconfig;
4858: if (ref($settings->{$item}) eq 'HASH') {
4859: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
4860: %courseconfig = %{$settings->{$item}->{'crsconf'}};
4861: }
4862: }
4863: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4864: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 4865: my $checked;
4866: if ($courseconfig{$item}) {
4867: $checked = ' checked="checked"';
4868: }
4869: $datatable .= '<label>'.
4870: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
1.372 raeburn 4871: $lt{'crs'.$item}.'</label> '."\n";
1.273 raeburn 4872: }
4873: $datatable .= '</span></fieldset>'.
1.267 raeburn 4874: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4875: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
4876: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
4877: my %custom = %{$settings->{$item}->{'custom'}};
4878: if (keys(%custom) > 0) {
4879: foreach my $key (sort(keys(%custom))) {
4880: $datatable .= '<tr><td><span class="LC_nobreak">'.
4881: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
4882: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
4883: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
4884: ' value="'.$custom{$key}.'" /></td></tr>';
4885: }
4886: }
4887: }
4888: $datatable .= '<tr><td><span class="LC_nobreak">'.
4889: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
4890: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
4891: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
4892: $datatable .= '</table></fieldset></td></tr>'."\n";
4893: $itemcount ++;
4894: }
4895: }
4896: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319 raeburn 4897: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267 raeburn 4898: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4899: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
4900: '<select name="ltitools_add_pos"'.$chgstr.'>';
4901: for (my $k=0; $k<$maxnum+1; $k++) {
4902: my $vpos = $k+1;
4903: my $selstr;
4904: if ($k == $maxnum) {
4905: $selstr = ' selected="selected" ';
4906: }
4907: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4908: }
4909: $datatable .= '</select> '."\n".
1.334 raeburn 4910: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.267 raeburn 4911: '<td colspan="2">'.
4912: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4913: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267 raeburn 4914: (' 'x2).
4915: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
4916: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4917: (' 'x2).
4918: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
4919: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4920: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
4921: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
4922: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267 raeburn 4923: '<br />'.
1.323 raeburn 4924: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267 raeburn 4925: (' 'x2).
4926: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
4927: (' 'x2).
1.322 raeburn 4928: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
4929: (' 'x2).
1.267 raeburn 4930: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
4931: '<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".
4932: '</fieldset>'.
4933: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4934: '<span class="LC_nobreak">'.&mt('Display target:');
4935: my %defaultdisp;
4936: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 4937: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4938: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
4939: $lt{$disp}.'</label>'.(' 'x2);
4940: }
4941: $datatable .= (' 'x4);
4942: foreach my $dimen ('width','height') {
4943: $datatable .= '<label>'.$lt{$dimen}.' '.
4944: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
4945: (' 'x2);
4946: }
1.334 raeburn 4947: $datatable .= '</span><br />'.
1.296 raeburn 4948: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 4949: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
1.296 raeburn 4950: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
1.334 raeburn 4951: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
1.296 raeburn 4952: '</div><div style=""></div><br />';
1.319 raeburn 4953: my %units = (
4954: 'passback' => 'days',
4955: 'roster' => 'seconds',
4956: );
4957: my %defaulttimes = (
4958: 'passback' => '7',
1.322 raeburn 4959: 'roster' => '300',
1.319 raeburn 4960: );
1.267 raeburn 4961: foreach my $extra ('passback','roster') {
1.319 raeburn 4962: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
4963: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4964: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
4965: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
4966: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
4967: &mt('Yes').'</label></span></div>'.
4968: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
4969: '<span class="LC_nobreak">'.
4970: &mt("at least [_1] $units{$extra} after launch",
4971: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
4972: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4973: }
1.319 raeburn 4974: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
1.267 raeburn 4975: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4976: if ($switchserver) {
4977: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4978: } else {
4979: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
4980: }
4981: $datatable .= '</span></fieldset>'.
4982: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4983: '<span class="LC_nobreak">';
4984: foreach my $field (@fields) {
1.324 raeburn 4985: my ($id,$onclick,$spacer);
4986: if ($field eq 'user') {
4987: $id = ' id="ltitools_user_field_add"';
4988: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
4989: } else {
4990: $spacer = (' ' x2);
4991: }
1.267 raeburn 4992: $datatable .= '<label>'.
1.324 raeburn 4993: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
4994: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4995: }
1.324 raeburn 4996: $datatable .= '</span>'.
4997: '<div style="display:none;" id="ltitools_user_div_add">'.
4998: '<span class="LC_nobreak"> : '.
4999: '<select name="ltitools_userincdom_add">'.
5000: '<option value="" selected="selected">'.&mt('Select').'</option>'.
5001: '<option value="0">'.&mt('username').'</option>'.
5002: '<option value="1">'.&mt('username:domain').'</option>'.
5003: '</select></span></div></fieldset>';
5004: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1.267 raeburn 5005: foreach my $role (@courseroles) {
5006: my ($checked,$checkednone);
1.306 raeburn 5007: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 5008: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5009: '<select name="ltitools_add_roles_'.$role.'">'.
5010: '<option value="" selected="selected">'.&mt('Select').'</option>';
5011: foreach my $ltirole (@ltiroles) {
5012: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
5013: }
5014: $datatable .= '</select></td>';
5015: }
5016: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 5017: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 5018: foreach my $item ('label','title','target','linktext','explanation','append') {
1.296 raeburn 5019: $datatable .= '<label>'.
5020: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
5021: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 5022: }
5023: $datatable .= '</span></fieldset>'.
1.267 raeburn 5024: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
5025: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5026: '<tr><td><span class="LC_nobreak">'.
5027: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
5028: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
5029: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
1.334 raeburn 5030: '</table></fieldset>'."\n".
1.267 raeburn 5031: '</td>'."\n".
5032: '</tr>'."\n";
5033: $itemcount ++;
5034: return $datatable;
5035: }
5036:
5037: sub ltitools_names {
5038: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 5039: 'title' => 'Title',
5040: 'version' => 'Version',
5041: 'msgtype' => 'Message Type',
1.323 raeburn 5042: 'sigmethod' => 'Signature Method',
1.296 raeburn 5043: 'url' => 'URL',
5044: 'key' => 'Key',
1.322 raeburn 5045: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 5046: 'secret' => 'Secret',
5047: 'icon' => 'Icon',
1.324 raeburn 5048: 'user' => 'User',
1.296 raeburn 5049: 'fullname' => 'Full Name',
5050: 'firstname' => 'First Name',
5051: 'lastname' => 'Last Name',
5052: 'email' => 'E-mail',
5053: 'roles' => 'Role',
1.298 raeburn 5054: 'window' => 'Window',
5055: 'tab' => 'Tab',
1.296 raeburn 5056: 'iframe' => 'iFrame',
5057: 'height' => 'Height',
5058: 'width' => 'Width',
5059: 'linktext' => 'Default Link Text',
5060: 'explanation' => 'Default Explanation',
5061: 'passback' => 'Tool can return grades:',
5062: 'roster' => 'Tool can retrieve roster:',
5063: 'crstarget' => 'Display target',
5064: 'crslabel' => 'Course label',
5065: 'crstitle' => 'Course title',
5066: 'crslinktext' => 'Link Text',
5067: 'crsexplanation' => 'Explanation',
1.318 raeburn 5068: 'crsappend' => 'Provider URL',
1.267 raeburn 5069: );
5070: return %lt;
5071: }
5072:
1.372 raeburn 5073: sub print_proctoring {
5074: my ($dom,$settings,$rowtotal) = @_;
5075: my $itemcount = 1;
5076: my (%ordered,%providernames,%current,%currentdef);
5077: my $confname = $dom.'-domainconfig';
5078: my $switchserver = &check_switchserver($dom,$confname);
5079: if (ref($settings) eq 'HASH') {
5080: foreach my $item (keys(%{$settings})) {
5081: if (ref($settings->{$item}) eq 'HASH') {
5082: my $num = $settings->{$item}{'order'};
5083: $ordered{$num} = $item;
5084: }
5085: }
5086: } else {
5087: %ordered = (
5088: 1 => 'proctorio',
5089: 2 => 'examity',
5090: );
5091: }
5092: %providernames = &proctoring_providernames();
5093: my $maxnum = scalar(keys(%ordered));
5094: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
5095: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
5096: if (ref($requref) eq 'HASH') {
5097: %requserfields = %{$requref};
5098: }
5099: if (ref($opturef) eq 'HASH') {
5100: %optuserfields = %{$opturef};
5101: }
5102: if (ref($defref) eq 'HASH') {
5103: %defaults = %{$defref};
5104: }
5105: if (ref($extref) eq 'HASH') {
5106: %extended = %{$extref};
5107: }
5108: if (ref($crsref) eq 'HASH') {
5109: %crsconf = %{$crsref};
5110: }
5111: if (ref($rolesref) eq 'ARRAY') {
5112: @courseroles = @{$rolesref};
5113: }
5114: if (ref($ltiref) eq 'ARRAY') {
5115: @ltiroles = @{$ltiref};
5116: }
5117: my $datatable;
5118: my $css_class;
5119: if (keys(%ordered)) {
5120: my @items = sort { $a <=> $b } keys(%ordered);
5121: for (my $i=0; $i<@items; $i++) {
5122: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5123: my $provider = $ordered{$items[$i]};
5124: my $optionsty = 'none';
5125: my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
5126: %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
5127: if (ref($settings) eq 'HASH') {
5128: if (ref($settings->{$provider}) eq 'HASH') {
5129: %current = %{$settings->{$provider}};
5130: if ($current{'available'}) {
5131: $optionsty = 'block';
5132: $available = 1;
5133: }
5134: if ($current{'lifetime'} =~ /^\d+$/) {
5135: $lifetime = $current{'lifetime'};
5136: }
5137: if ($current{'version'} =~ /^\d+\.\d+$/) {
5138: $version = $current{'version'};
5139: }
5140: if ($current{'image'} ne '') {
5141: $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
5142: }
5143: if (ref($current{'fields'}) eq 'ARRAY') {
5144: map { $checkedfields{$_} = 1; } @{$current{'fields'}};
5145: }
5146: $userincdom = $current{'incdom'};
5147: if (ref($current{'roles'}) eq 'HASH') {
5148: %rolemaps = %{$current{'roles'}};
5149: $checkedfields{'roles'} = 1;
5150: }
5151: if (ref($current{'defaults'}) eq 'ARRAY') {
5152: foreach my $val (@{$current{'defaults'}}) {
5153: if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
5154: $inuse{$val} = 1;
5155: } else {
5156: foreach my $poss (keys(%{$extended{$provider}})) {
5157: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5158: if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
5159: $inuse{$poss} = $val;
5160: last;
5161: }
5162: }
5163: }
5164: }
5165: }
5166: } elsif (ref($current{'defaults'}) eq 'HASH') {
5167: foreach my $key (keys(%{$current{'defaults'}})) {
5168: my $currval = $current{'defaults'}{$key};
5169: if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
5170: $inuse{$key} = 1;
5171: } else {
5172: my $match;
5173: foreach my $poss (keys(%{$extended{$provider}})) {
5174: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5175: if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
5176: $inuse{$poss} = $key;
5177: last;
5178: }
5179: } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
5180: foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
5181: if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
5182: if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
5183: $currentdef{$inner} = $currval;
5184: $match = 1;
5185: last;
5186: }
5187: } elsif ($inner eq $key) {
5188: $currentdef{$key} = $currval;
5189: $match = 1;
5190: last;
5191: }
5192: }
5193: }
5194: last if ($match);
5195: }
5196: }
5197: }
5198: }
5199: if (ref($current{'crsconf'}) eq 'ARRAY') {
5200: map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
5201: }
5202: }
5203: }
5204: my %lt = &proctoring_titles($provider);
5205: my %fieldtitles = &proctoring_fieldtitles($provider);
5206: my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
5207: my %checkedavailable = (
5208: yes => '',
5209: no => ' checked="checked"',
5210: );
5211: if ($available) {
5212: $checkedavailable{'yes'} = $checkedavailable{'no'};
5213: $checkedavailable{'no'} = '';
5214: }
5215: my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
5216: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5217: .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
5218: for (my $k=0; $k<$maxnum; $k++) {
5219: my $vpos = $k+1;
5220: my $selstr;
5221: if ($k == $i) {
5222: $selstr = ' selected="selected" ';
5223: }
5224: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5225: }
5226: if ($version eq '') {
5227: if ($provider eq 'proctorio') {
5228: $version = '1.0';
5229: } elsif ($provider eq 'examity') {
5230: $version = '1.1';
5231: }
5232: }
5233: if ($lifetime eq '') {
5234: $lifetime = '300';
5235: }
5236: $datatable .=
5237: '</select>'.(' 'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
5238: '<span class="LC_nobreak">'.$lt{'avai'}.' '.
5239: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label> '."\n".
5240: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
5241: '</td>'.
5242: '<td colspan="2">'.
5243: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
5244: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
5245: '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
5246: (' 'x2).
5247: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
5248: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5249: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5250: (' 'x2).
5251: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
5252: '<br />'.
5253: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
5254: '<br />'.
5255: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
5256: (' 'x2).
5257: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
5258: '<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";
5259: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
5260: if ($imgsrc) {
5261: $datatable .= $imgsrc.
5262: '<label><input type="checkbox" name="proctoring_image_del"'.
5263: ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
5264: '<span class="LC_nobreak"> '.&mt('Replace:');
5265: }
5266: $datatable .= ' ';
5267: if ($switchserver) {
5268: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5269: } else {
5270: $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
5271: }
5272: unless ($imgsrc) {
5273: $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
5274: }
5275: $datatable .= '</fieldset>'."\n";
5276: if (ref($requserfields{$provider}) eq 'ARRAY') {
5277: if (@{$requserfields{$provider}} > 0) {
5278: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
5279: foreach my $field (@{$requserfields{$provider}}) {
5280: $datatable .= '<span class="LC_nobreak">'.
5281: '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
5282: $lt{$field}.'</label>';
5283: if ($field eq 'user') {
5284: my $seluserdom = '';
5285: my $unseluserdom = ' selected="selected"';
5286: if ($userincdom) {
5287: $seluserdom = $unseluserdom;
5288: $unseluserdom = '';
5289: }
5290: $datatable .= ': '.
5291: '<select name="proctoring_userincdom_'.$provider.'">'.
5292: '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
5293: '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
5294: '</select> ';
5295: } else {
5296: $datatable .= ' ';
5297: if ($field eq 'roles') {
5298: $showroles = 1;
5299: }
5300: }
5301: $datatable .= '</span> ';
5302: }
5303: }
5304: $datatable .= '</fieldset>'."\n";
5305: }
5306: if (ref($optuserfields{$provider}) eq 'ARRAY') {
5307: if (@{$optuserfields{$provider}} > 0) {
5308: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>';
5309: foreach my $field (@{$optuserfields{$provider}}) {
5310: my $checked;
5311: if ($checkedfields{$field}) {
5312: $checked = ' checked="checked"';
5313: }
5314: $datatable .= '<span class="LC_nobreak">'.
5315: '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span> ';
5316: }
5317: $datatable .= '</fieldset>'."\n";
5318: }
5319: }
5320: if (ref($defaults{$provider}) eq 'ARRAY') {
5321: if (@{$defaults{$provider}}) {
5322: my (%options,@selectboxes);
5323: if (ref($extended{$provider}) eq 'HASH') {
5324: %options = %{$extended{$provider}};
5325: }
5326: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
5327: my ($rem,$numinrow,$dropdowns);
5328: if ($provider eq 'proctorio') {
5329: $datatable .= '<table>';
5330: $numinrow = 4;
5331: }
5332: my $i = 0;
5333: foreach my $field (@{$defaults{$provider}}) {
5334: my $checked;
5335: if ($inuse{$field}) {
5336: $checked = ' checked="checked"';
5337: }
5338: if ($provider eq 'examity') {
5339: if ($field eq 'display') {
5340: $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
5341: foreach my $option ('iframe','tab','window') {
5342: my $checkdisp;
5343: if ($currentdef{'target'} eq $option) {
5344: $checkdisp = ' checked="checked"';
5345: }
5346: $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
5347: $fieldtitles{$option}.'</label>'.(' 'x2);
5348: }
5349: $datatable .= (' 'x4);
5350: foreach my $dimen ('width','height') {
5351: $datatable .= '<label>'.$fieldtitles{$dimen}.' '.
5352: '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
5353: 'value="'.$currentdef{$dimen}.'" /></label>'.
5354: (' 'x2);
5355: }
5356: $datatable .= '</span><br />'.
5357: '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
5358: '<input type="text" name="proctoring_linktext_'.$provider.'" '.
5359: 'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
5360: '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
5361: '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
5362: $currentdef{'explanation'}.
5363: '</textarea></div><div style=""></div><br />';
5364: }
5365: } else {
5366: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
5367: my ($output,$selnone);
5368: unless ($checked) {
5369: $selnone = ' selected="selected"';
5370: }
5371: $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
5372: '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
5373: '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>';
5374: foreach my $option (@{$options{$field}}) {
5375: my $sel;
5376: if ($inuse{$field} eq $option) {
5377: $sel = ' selected="selected"';
5378: }
5379: $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
5380: }
5381: $output .= '</select></span>';
5382: push(@selectboxes,$output);
5383: } else {
5384: $rem = $i%($numinrow);
5385: if ($rem == 0) {
5386: if ($i > 0) {
5387: $datatable .= '</tr>';
5388: }
5389: $datatable .= '<tr>';
5390: }
5391: $datatable .= '<td class="LC_left_item">'.
5392: '<span class="LC_nobreak">'.
5393: '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
5394: $fieldtitles{$field}.'</label></span></td>';
5395: $i++;
5396: }
5397: }
5398: }
5399: if ($provider eq 'proctorio') {
5400: if ($numinrow) {
5401: $rem = $i%$numinrow;
5402: }
5403: my $colsleft = $numinrow - $rem;
5404: if ($colsleft > 1) {
5405: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5406: } else {
5407: $datatable .= '<td class="LC_left_item">';
5408: }
5409: $datatable .= ' '.
5410: '</td></tr></table>';
5411: if (@selectboxes) {
5412: $datatable .= '<hr /><table>';
5413: $numinrow = 2;
5414: for (my $i=0; $i<@selectboxes; $i++) {
5415: $rem = $i%($numinrow);
5416: if ($rem == 0) {
5417: if ($i > 0) {
5418: $datatable .= '</tr>';
5419: }
5420: $datatable .= '<tr>';
5421: }
5422: $datatable .= '<td class="LC_left_item">'.
5423: $selectboxes[$i].'</td>';
5424: }
5425: if ($numinrow) {
5426: $rem = $i%$numinrow;
5427: }
5428: $colsleft = $numinrow - $rem;
5429: if ($colsleft > 1) {
5430: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5431: } else {
5432: $datatable .= '<td class="LC_left_item">';
5433: }
5434: $datatable .= ' '.
5435: '</td></tr></table>';
5436: }
5437: }
5438: $datatable .= '</fieldset>';
5439: }
5440: if (ref($crsconf{$provider}) eq 'ARRAY') {
5441: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5442: '<legend>'.&mt('Configurable in course').'</legend>';
5443: my ($rem,$numinrow);
5444: if ($provider eq 'proctorio') {
5445: $datatable .= '<table>';
5446: $numinrow = 4;
5447: }
5448: my $i = 0;
5449: foreach my $item (@{$crsconf{$provider}}) {
5450: my $name;
5451: if ($provider eq 'examity') {
5452: $name = $lt{'crs'.$item};
5453: } elsif ($provider eq 'proctorio') {
5454: $name = $fieldtitles{$item};
5455: $rem = $i%($numinrow);
5456: if ($rem == 0) {
5457: if ($i > 0) {
5458: $datatable .= '</tr>';
5459: }
5460: $datatable .= '<tr>';
5461: }
5462: $datatable .= '<td class="LC_left_item>';
5463: }
5464: my $checked;
5465: if ($crsconfig{$item}) {
5466: $checked = ' checked="checked"';
5467: }
5468: $datatable .= '<span class="LC_nobreak"><label>'.
5469: '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
5470: $name.'</label></span>';
5471: if ($provider eq 'examity') {
5472: $datatable .= ' ';
5473: }
5474: $datatable .= "\n";
5475: $i++;
5476: }
5477: if ($provider eq 'proctorio') {
5478: if ($numinrow) {
5479: $rem = $i%$numinrow;
5480: }
5481: my $colsleft = $numinrow - $rem;
5482: if ($colsleft > 1) {
5483: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5484: } else {
5485: $datatable .= '<td class="LC_left_item">';
5486: }
5487: $datatable .= ' '.
5488: '</td></tr></table>';
5489: }
5490: $datatable .= '</fieldset>';
5491: }
5492: if ($showroles) {
5493: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5494: '<legend>'.&mt('Role mapping').'</legend><table><tr>';
5495: foreach my $role (@courseroles) {
5496: my ($selected,$selectnone);
5497: if (!$rolemaps{$role}) {
5498: $selectnone = ' selected="selected"';
5499: }
5500: $datatable .= '<td style="text-align: center">'.
5501: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5502: '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
5503: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5504: foreach my $ltirole (@ltiroles) {
5505: unless ($selectnone) {
5506: if ($rolemaps{$role} eq $ltirole) {
5507: $selected = ' selected="selected"';
5508: } else {
5509: $selected = '';
5510: }
5511: }
5512: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5513: }
5514: $datatable .= '</select></td>';
5515: }
5516: $datatable .= '</tr></table></fieldset>'.
5517: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5518: '<legend>'.&mt('Custom items sent on launch').'</legend>'.
5519: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5520: '<tr><td></td><td>lms</td>'.
5521: '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
5522: ' value="Loncapa" disabled="disabled"/></td></tr>';
5523: if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
5524: (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
5525: my %custom = %{$settings->{$provider}->{'custom'}};
5526: if (keys(%custom) > 0) {
5527: foreach my $key (sort(keys(%custom))) {
5528: next if ($key eq 'lms');
5529: $datatable .= '<tr><td><span class="LC_nobreak">'.
5530: '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
5531: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
5532: '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
5533: ' value="'.$custom{$key}.'" /></td></tr>';
5534: }
5535: }
5536: }
5537: $datatable .= '<tr><td><span class="LC_nobreak">'.
5538: '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
5539: &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
5540: '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
5541: '</table></fieldset></td></tr>'."\n";
5542: }
5543: $datatable .= '</td></tr>';
5544: }
5545: $itemcount ++;
5546: }
5547: }
5548: return $datatable;
5549: }
5550:
5551: sub proctoring_data {
5552: my $requserfields = {
5553: proctorio => ['user'],
5554: examity => ['roles','user'],
5555: };
5556: my $optuserfields = {
5557: proctorio => ['fullname'],
5558: examity => ['fullname','firstname','lastname','email'],
5559: };
5560: my $defaults = {
5561: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
5562: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
5563: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
5564: 'closetabs','onescreen','print','downloads','cache','rightclick',
5565: 'reentry','calculator','whiteboard'],
5566: examity => ['display'],
5567: };
5568: my $extended = {
5569: proctorio => {
5570: verifyid => ['verifyidauto','verifyidlive'],
5571: fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
5572: tabslinks => ['notabs','linksonly'],
5573: reentry => ['noreentry','agentreentry'],
5574: calculator => ['calculatorbasic','calculatorsci'],
5575: },
5576: examity => {
5577: display => {
5578: target => ['iframe','tab','window'],
5579: width => '',
5580: height => '',
5581: linktext => '',
5582: explanation => '',
5583: },
5584: },
5585: };
5586: my $crsconf = {
5587: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
5588: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
5589: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
5590: 'closetabs','onescreen','print','downloads','cache','rightclick',
5591: 'reentry','calculator','whiteboard'],
5592: examity => ['label','title','target','linktext','explanation','append'],
5593: };
5594: my $courseroles = ['cc','in','ta','ep','st'];
5595: my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
5596: return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
5597: }
5598:
5599: sub proctoring_titles {
5600: my ($item) = @_;
5601: my (%common_lt,%custom_lt);
5602: %common_lt = &Apache::lonlocal::texthash (
5603: 'avai' => 'Available?',
5604: 'base' => 'Basic Settings',
5605: 'requ' => 'User data required to be sent on launch',
5606: 'optu' => 'User data optionally sent on launch',
5607: 'udsl' => 'User data sent on launch',
5608: 'defa' => 'Defaults for items configurable in course',
5609: 'sigmethod' => 'Signature Method',
5610: 'key' => 'Key',
5611: 'lifetime' => 'Nonce lifetime (s)',
5612: 'secret' => 'Secret',
5613: 'icon' => 'Icon',
5614: 'fullname' => 'Full Name',
5615: 'visible' => 'Visible input',
5616: 'username' => 'username',
5617: 'user' => 'User',
5618: );
5619: if ($item eq 'proctorio') {
5620: %custom_lt = &Apache::lonlocal::texthash (
5621: 'version' => 'OAuth version',
5622: 'url' => 'API URL',
5623: 'uname:dom' => 'username-domain',
5624: );
5625: } elsif ($item eq 'examity') {
5626: %custom_lt = &Apache::lonlocal::texthash (
5627: 'version' => 'LTI Version',
5628: 'url' => 'URL',
5629: 'uname:dom' => 'username:domain',
5630: 'msgtype' => 'Message Type',
5631: 'firstname' => 'First Name',
5632: 'lastname' => 'Last Name',
5633: 'email' => 'E-mail',
5634: 'roles' => 'Role',
5635: 'crstarget' => 'Display target',
5636: 'crslabel' => 'Course label',
5637: 'crstitle' => 'Course title',
5638: 'crslinktext' => 'Link Text',
5639: 'crsexplanation' => 'Explanation',
5640: 'crsappend' => 'Provider URL',
5641: );
5642: }
5643: my %lt = (%common_lt,%custom_lt);
5644: return %lt;
5645: }
5646:
5647: sub proctoring_fieldtitles {
5648: my ($item) = @_;
5649: if ($item eq 'proctorio') {
5650: return &Apache::lonlocal::texthash (
5651: 'recordvideo' => 'Record video',
5652: 'recordaudio' => 'Record audio',
5653: 'recordscreen' => 'Record screen',
5654: 'recordwebtraffic' => 'Record web traffic',
5655: 'recordroomstart' => 'Record room scan',
5656: 'verifyvideo' => 'Verify webcam',
5657: 'verifyaudio' => 'Verify microphone',
5658: 'verifydesktop' => 'Verify desktop recording',
5659: 'verifyid' => 'Photo ID verification',
5660: 'verifysignature' => 'Require signature',
5661: 'fullscreen' => 'Fullscreen',
5662: 'clipboard' => 'Disable copy/paste',
5663: 'tabslinks' => 'New tabs/windows',
5664: 'closetabs' => 'Close other tabs',
5665: 'onescreen' => 'Limit to single screen',
5666: 'print' => 'Disable Printing',
5667: 'downloads' => 'Disable Downloads',
5668: 'cache' => 'Empty cache after exam',
5669: 'rightclick' => 'Disable right click',
5670: 'reentry' => 'Re-entry to exam',
5671: 'calculator' => 'Onscreen calculator',
5672: 'whiteboard' => 'Onscreen whiteboard',
5673: 'verifyidauto' => 'Automated verification',
5674: 'verifyidlive' => 'Live agent verification',
5675: 'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
5676: 'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
5677: 'fullscreensever' => 'Forced, navigation away ends exam',
5678: 'notabs' => 'Disaallowed',
5679: 'linksonly' => 'Allowed from links in exam',
5680: 'noreentry' => 'Disallowed',
5681: 'agentreentry' => 'Agent required for re-entry',
5682: 'calculatorbasic' => 'Basic',
5683: 'calculatorsci' => 'Scientific',
5684: );
5685: } elsif ($item eq 'examity') {
5686: return &Apache::lonlocal::texthash (
5687: 'target' => 'Display target',
5688: 'window' => 'Window',
5689: 'tab' => 'Tab',
5690: 'iframe' => 'iFrame',
5691: 'height' => 'Height (pixels)',
5692: 'width' => 'Width (pixels)',
5693: 'linktext' => 'Default Link Text',
5694: 'explanation' => 'Default Explanation',
5695: 'append' => 'Provider URL',
5696: );
5697: }
5698: }
5699:
5700: sub proctoring_providernames {
5701: return (
5702: proctorio => 'Proctorio',
5703: examity => 'Examity',
5704: );
5705: }
5706:
1.320 raeburn 5707: sub print_lti {
5708: my ($dom,$settings,$rowtotal) = @_;
5709: my $itemcount = 1;
5710: my $maxnum = 0;
5711: my $css_class;
5712: my %ordered;
5713: if (ref($settings) eq 'HASH') {
5714: foreach my $item (keys(%{$settings})) {
5715: if (ref($settings->{$item}) eq 'HASH') {
5716: my $num = $settings->{$item}{'order'};
5717: $ordered{$num} = $item;
5718: }
5719: }
5720: }
5721: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 5722: my $datatable;
1.320 raeburn 5723: my %lt = <i_names();
5724: if (keys(%ordered)) {
5725: my @items = sort { $a <=> $b } keys(%ordered);
5726: for (my $i=0; $i<@items; $i++) {
5727: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5728: my $item = $ordered{$items[$i]};
1.345 raeburn 5729: my ($key,$secret,$lifetime,$consumer,$requser,$current);
1.320 raeburn 5730: if (ref($settings->{$item}) eq 'HASH') {
5731: $key = $settings->{$item}->{'key'};
5732: $secret = $settings->{$item}->{'secret'};
5733: $lifetime = $settings->{$item}->{'lifetime'};
5734: $consumer = $settings->{$item}->{'consumer'};
1.345 raeburn 5735: $requser = $settings->{$item}->{'requser'};
1.320 raeburn 5736: $current = $settings->{$item};
5737: }
1.345 raeburn 5738: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
5739: my %checkedrequser = (
5740: yes => ' checked="checked"',
5741: no => '',
5742: );
5743: if (!$requser) {
5744: $checkedrequser{'no'} = $checkedrequser{'yes'};
5745: $checkedrequser{'yes'} = '';
1.352 raeburn 5746: }
1.320 raeburn 5747: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
5748: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5749: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
5750: for (my $k=0; $k<=$maxnum; $k++) {
5751: my $vpos = $k+1;
5752: my $selstr;
5753: if ($k == $i) {
5754: $selstr = ' selected="selected" ';
5755: }
5756: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5757: }
5758: $datatable .= '</select>'.(' 'x2).
5759: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
5760: &mt('Delete?').'</label></span></td>'.
5761: '<td colspan="2">'.
5762: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5763: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 5764: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
1.320 raeburn 5765: (' 'x2).
5766: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
5767: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
5768: (' 'x2).
5769: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.345 raeburn 5770: 'value="'.$lifetime.'" size="3" /></span>'.
5771: (' 'x2).
5772: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
5773: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
5774: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 5775: '<br /><br />'.
5776: '<span class="LC_nobreak">'.$lt{'key'}.
5777: ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
5778: (' 'x2).
5779: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
5780: '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
5781: '<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>'.
5782: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
1.325 raeburn 5783: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
1.320 raeburn 5784: $itemcount ++;
5785: }
5786: }
5787: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5788: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
5789: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
5790: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
5791: '<select name="lti_pos_add"'.$chgstr.'>';
5792: for (my $k=0; $k<$maxnum+1; $k++) {
5793: my $vpos = $k+1;
5794: my $selstr;
5795: if ($k == $maxnum) {
5796: $selstr = ' selected="selected" ';
5797: }
5798: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5799: }
5800: $datatable .= '</select> '."\n".
1.334 raeburn 5801: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.320 raeburn 5802: '<td colspan="2">'.
5803: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5804: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 5805: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
1.320 raeburn 5806: (' 'x2).
5807: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
5808: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
5809: (' 'x2).
1.345 raeburn 5810: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span> '."\n".
5811: (' 'x2).
5812: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
5813: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
5814: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 5815: '<br /><br />'.
5816: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
5817: (' 'x2).
5818: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
5819: '<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 5820: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
1.320 raeburn 5821: '</td>'."\n".
5822: '</tr>'."\n";
5823: $$rowtotal ++;
5824: return $datatable;;
5825: }
5826:
5827: sub lti_names {
5828: my %lt = &Apache::lonlocal::texthash(
5829: 'version' => 'LTI Version',
5830: 'url' => 'URL',
5831: 'key' => 'Key',
1.322 raeburn 5832: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 5833: 'consumer' => 'Consumer',
1.320 raeburn 5834: 'secret' => 'Secret',
1.345 raeburn 5835: 'requser' => "User's identity sent",
1.320 raeburn 5836: 'email' => 'Email address',
5837: 'sourcedid' => 'User ID',
5838: 'other' => 'Other',
5839: 'passback' => 'Can return grades to Consumer:',
5840: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 5841: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 5842: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 5843: );
5844: return %lt;
5845: }
5846:
5847: sub lti_options {
1.325 raeburn 5848: my ($num,$current,$itemcount,%lt) = @_;
1.363 raeburn 5849: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320 raeburn 5850: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
5851: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
5852: $checked{'makecrs'}{'N'} = ' checked="checked"';
5853: $checked{'mapcrstype'} = {};
5854: $checked{'makeuser'} = {};
5855: $checked{'selfenroll'} = {};
5856: $checked{'crssec'} = {};
5857: $checked{'crssecsrc'} = {};
1.325 raeburn 5858: $checked{'lcauth'} = {};
1.326 raeburn 5859: $checked{'menuitem'} = {};
1.325 raeburn 5860: if ($num eq 'add') {
5861: $checked{'lcauth'}{'lti'} = ' checked="checked"';
5862: }
1.320 raeburn 5863: my $userfieldsty = 'none';
5864: my $crsfieldsty = 'none';
5865: my $crssecfieldsty = 'none';
5866: my $secsrcfieldsty = 'none';
1.363 raeburn 5867: my $callbacksty = 'none';
1.337 raeburn 5868: my $passbacksty = 'none';
1.345 raeburn 5869: my $optionsty = 'block';
1.325 raeburn 5870: my $lcauthparm;
5871: my $lcauthparmstyle = 'display:none';
5872: my $lcauthparmtext;
1.326 raeburn 5873: my $menusty;
1.325 raeburn 5874: my $numinrow = 4;
1.326 raeburn 5875: my %menutitles = <imenu_titles();
1.320 raeburn 5876:
5877: if (ref($current) eq 'HASH') {
1.345 raeburn 5878: if (!$current->{'requser'}) {
5879: $optionsty = 'none';
5880: }
1.320 raeburn 5881: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
5882: $checked{'mapuser'}{'sourcedid'} = '';
5883: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
5884: $checked{'mapuser'}{'email'} = ' checked="checked"';
5885: } else {
5886: $checked{'mapuser'}{'other'} = ' checked="checked"';
5887: $userfield = $current->{'mapuser'};
5888: $userfieldsty = 'inline-block';
5889: }
5890: }
5891: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
5892: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
5893: if ($current->{'mapcrs'} eq 'context_id') {
5894: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
5895: } else {
5896: $checked{'mapcrs'}{'other'} = ' checked="checked"';
5897: $cidfield = $current->{'mapcrs'};
5898: $crsfieldsty = 'inline-block';
5899: }
5900: }
5901: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
5902: foreach my $type (@{$current->{'mapcrstype'}}) {
5903: $checked{'mapcrstype'}{$type} = ' checked="checked"';
5904: }
5905: }
1.345 raeburn 5906: if ($current->{'makecrs'}) {
1.320 raeburn 5907: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 5908: }
1.320 raeburn 5909: if (ref($current->{'makeuser'}) eq 'ARRAY') {
5910: foreach my $role (@{$current->{'makeuser'}}) {
5911: $checked{'makeuser'}{$role} = ' checked="checked"';
5912: }
5913: }
1.325 raeburn 5914: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
5915: $checked{'lcauth'}{$1} = ' checked="checked"';
5916: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
5917: $lcauthparm = $current->{'lcauthparm'};
5918: $lcauthparmstyle = 'display:table-row';
5919: if ($current->{'lcauth'} eq 'localauth') {
5920: $lcauthparmtext = &mt('Local auth argument');
5921: } else {
5922: $lcauthparmtext = &mt('Kerberos domain');
5923: }
5924: }
5925: }
1.320 raeburn 5926: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
5927: foreach my $role (@{$current->{'selfenroll'}}) {
5928: $checked{'selfenroll'}{$role} = ' checked="checked"';
5929: }
5930: }
5931: if (ref($current->{'maproles'}) eq 'HASH') {
5932: %rolemaps = %{$current->{'maproles'}};
5933: }
5934: if ($current->{'section'} ne '') {
5935: $checked{'crssec'}{'Y'} = ' checked="checked"';
5936: $crssecfieldsty = 'inline-block';
5937: if ($current->{'section'} eq 'course_section_sourcedid') {
5938: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
5939: } else {
5940: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
5941: $crssecsrc = $current->{'section'};
5942: $secsrcfieldsty = 'inline-block';
5943: }
5944: } else {
5945: $checked{'crssec'}{'N'} = ' checked="checked"';
5946: }
1.363 raeburn 5947: if ($current->{'callback'} ne '') {
5948: $callback = $current->{'callback'};
5949: $checked{'callback'}{'Y'} = ' checked="checked"';
5950: $callbacksty = 'inline-block';
5951: } else {
5952: $checked{'callback'}{'N'} = ' checked="checked"';
5953: }
1.326 raeburn 5954: if ($current->{'topmenu'}) {
5955: $checked{'topmenu'}{'Y'} = ' checked="checked"';
5956: } else {
5957: $checked{'topmenu'}{'N'} = ' checked="checked"';
5958: }
5959: if ($current->{'inlinemenu'}) {
5960: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5961: } else {
5962: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
5963: }
5964: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
5965: $menusty = 'inline-block';
5966: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
5967: foreach my $item (@{$current->{'lcmenu'}}) {
5968: if (exists($menutitles{$item})) {
5969: $checked{'menuitem'}{$item} = ' checked="checked"';
5970: }
5971: }
5972: }
5973: } else {
5974: $menusty = 'none';
5975: }
1.320 raeburn 5976: } else {
5977: $checked{'makecrs'}{'N'} = ' checked="checked"';
5978: $checked{'crssec'}{'N'} = ' checked="checked"';
1.363 raeburn 5979: $checked{'callback'}{'N'} = ' checked="checked"';
1.326 raeburn 5980: $checked{'topmenu'}{'N'} = ' checked="checked"';
5981: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5982: $checked{'menuitem'}{'grades'} = ' checked="checked"';
5983: $menusty = 'inline-block';
1.320 raeburn 5984: }
1.325 raeburn 5985: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 5986: my %coursetypetitles = &Apache::lonlocal::texthash (
5987: official => 'Official',
5988: unofficial => 'Unofficial',
5989: community => 'Community',
5990: textbook => 'Textbook',
5991: placement => 'Placement Test',
1.325 raeburn 5992: lti => 'LTI Provider',
1.320 raeburn 5993: );
1.325 raeburn 5994: my @authtypes = ('internal','krb4','krb5','localauth');
5995: my %shortauth = (
5996: internal => 'int',
5997: krb4 => 'krb4',
5998: krb5 => 'krb5',
5999: localauth => 'loc'
6000: );
6001: my %authnames = &authtype_names();
1.320 raeburn 6002: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
6003: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
6004: my @courseroles = ('cc','in','ta','ep','st');
6005: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
6006: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
6007: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363 raeburn 6008: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320 raeburn 6009: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 6010: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 6011: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.345 raeburn 6012: my $output = '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 6013: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
6014: foreach my $option ('sourcedid','email','other') {
6015: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
6016: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
6017: ($option eq 'other' ? '' : (' 'x2) );
6018: }
6019: $output .= '</span></div>'.
6020: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
6021: '<input type="text" name="lti_customuser_'.$num.'" '.
1.372 raeburn 6022: 'value="'.$userfield.'" /></div></fieldset>'.
1.345 raeburn 6023: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
1.320 raeburn 6024: foreach my $ltirole (@lticourseroles) {
6025: my ($selected,$selectnone);
6026: if ($rolemaps{$ltirole} eq '') {
6027: $selectnone = ' selected="selected"';
6028: }
6029: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
6030: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
6031: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6032: foreach my $role (@courseroles) {
6033: unless ($selectnone) {
6034: if ($rolemaps{$ltirole} eq $role) {
6035: $selected = ' selected="selected"';
6036: } else {
6037: $selected = '';
6038: }
6039: }
6040: $output .= '<option value="'.$role.'"'.$selected.'>'.
6041: &Apache::lonnet::plaintext($role,'Course').
6042: '</option>';
6043: }
6044: $output .= '</select></td>';
6045: }
6046: $output .= '</tr></table></fieldset>'.
1.345 raeburn 6047: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 6048: foreach my $ltirole (@ltiroles) {
6049: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
6050: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
6051: }
6052: $output .= '</fieldset>'.
1.345 raeburn 6053: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 6054: '<table>'.
6055: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
6056: '</table>'.
6057: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
6058: '<td class="LC_left_item">';
6059: foreach my $auth ('lti',@authtypes) {
6060: my $authtext;
6061: if ($auth eq 'lti') {
6062: $authtext = &mt('None');
6063: } else {
6064: $authtext = $authnames{$shortauth{$auth}};
6065: }
6066: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
6067: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
6068: $authtext.'</label></span> ';
6069: }
6070: $output .= '</td></tr>'.
6071: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
6072: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
6073: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
6074: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
6075: '</table></fieldset>'.
1.345 raeburn 6076: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 6077: '<div class="LC_floatleft"><span class="LC_nobreak">'.
6078: &mt('Unique course identifier').': ';
6079: foreach my $option ('course_offering_sourcedid','context_id','other') {
6080: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
6081: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
6082: ($option eq 'other' ? '' : (' 'x2) );
6083: }
1.334 raeburn 6084: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 6085: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
6086: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
6087: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
6088: foreach my $type (@coursetypes) {
6089: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
6090: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
6091: (' 'x2);
6092: }
6093: $output .= '</span></fieldset>'.
1.345 raeburn 6094: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 6095: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
6096: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
6097: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6098: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
6099: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6100: '</fieldset>'.
1.345 raeburn 6101: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 6102: foreach my $lticrsrole (@lticourseroles) {
6103: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
6104: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
6105: }
6106: $output .= '</fieldset>'.
1.345 raeburn 6107: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 6108: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
6109: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
6110: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
6111: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 6112: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 6113: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
6114: '<span class="LC_nobreak">'.&mt('From').':<label>'.
6115: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
6116: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
6117: &mt('Standard field').'</label>'.(' 'x2).
6118: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
6119: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 6120: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 6121: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 6122: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6123: my ($pb1p1chk,$pb1p0chk,$onclickpb);
6124: foreach my $extra ('roster','passback') {
1.320 raeburn 6125: my $checkedon = '';
6126: my $checkedoff = ' checked="checked"';
1.337 raeburn 6127: if ($extra eq 'passback') {
6128: $pb1p1chk = ' checked="checked"';
6129: $pb1p0chk = '';
6130: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
6131: } else {
6132: $onclickpb = '';
6133: }
1.320 raeburn 6134: if (ref($current) eq 'HASH') {
6135: if (($current->{$extra})) {
6136: $checkedon = $checkedoff;
6137: $checkedoff = '';
1.337 raeburn 6138: if ($extra eq 'passback') {
6139: $passbacksty = 'inline-block';
6140: }
6141: if ($current->{'passbackformat'} eq '1.0') {
6142: $pb1p0chk = ' checked="checked"';
6143: $pb1p1chk = '';
6144: }
1.320 raeburn 6145: }
6146: }
6147: $output .= $lt{$extra}.' '.
1.337 raeburn 6148: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 6149: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 6150: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 6151: &mt('Yes').'</label><br />';
6152: }
1.337 raeburn 6153: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
6154: '<span class="LC_nobreak">'.&mt('Grade format').
6155: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
6156: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
6157: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363 raeburn 6158: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
6159: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6160: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback on logout').': '.
6161: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
6162: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
6163: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
6164: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
6165: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
6166: '<span class="LC_nobreak">'.&mt('Parameter').': '.
6167: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
6168: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
1.345 raeburn 6169: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Course defaults (Course Coordinator can override)').'</legend>'.
1.326 raeburn 6170: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
6171: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
6172: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6173: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
1.334 raeburn 6174: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
1.326 raeburn 6175: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6176: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
6177: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
6178: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6179: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
1.334 raeburn 6180: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
1.326 raeburn 6181: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6182: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
6183: '<span class="LC_nobreak">'.&mt('Menu items').': ';
6184: foreach my $type ('fullname','coursetitle','role','logout','grades') {
6185: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
6186: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
6187: (' 'x2);
6188: }
1.334 raeburn 6189: $output .= '</span></div></fieldset>';
1.320 raeburn 6190: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
6191: #
6192: # $output .= '</fieldset>'.
6193: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
6194: return $output;
6195: }
6196:
1.326 raeburn 6197: sub ltimenu_titles {
6198: return &Apache::lonlocal::texthash(
6199: fullname => 'Full name',
6200: coursetitle => 'Course title',
6201: role => 'Role',
6202: logout => 'Logout',
6203: grades => 'Grades',
6204: );
6205: }
6206:
1.121 raeburn 6207: sub print_coursedefaults {
1.139 raeburn 6208: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 6209: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 6210: my $itemcount = 1;
1.192 raeburn 6211: my %choices = &Apache::lonlocal::texthash (
6212: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 6213: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 6214: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6215: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 6216: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6217: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.314 raeburn 6218: texengine => 'Default method to display mathematics',
1.257 raeburn 6219: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 6220: canclone => "People who may clone a course (besides course's owner and coordinators)",
6221: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 6222: );
1.198 raeburn 6223: my %staticdefaults = (
6224: anonsurvey_threshold => 10,
6225: uploadquota => 500,
1.257 raeburn 6226: postsubmit => 60,
1.276 raeburn 6227: mysqltables => 172800,
1.198 raeburn 6228: );
1.139 raeburn 6229: if ($position eq 'top') {
1.257 raeburn 6230: %defaultchecked = (
6231: 'canuse_pdfforms' => 'off',
6232: 'uselcmath' => 'on',
6233: 'usejsme' => 'on',
1.289 raeburn 6234: 'canclone' => 'none',
1.257 raeburn 6235: );
6236: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.349 raeburn 6237: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 6238: if (ref($settings) eq 'HASH') {
6239: if ($settings->{'texengine'}) {
6240: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6241: $deftex = $settings->{'texengine'};
6242: }
6243: }
6244: }
6245: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6246: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6247: '<span class="LC_nobreak">'.$choices{'texengine'}.
6248: '</span></td><td class="LC_right_item">'.
6249: '<select name="texengine">'."\n";
6250: my %texoptions = (
6251: MathJax => 'MathJax',
6252: mimetex => &mt('Convert to Images'),
6253: tth => &mt('TeX to HTML'),
6254: );
6255: foreach my $renderer ('MathJax','mimetex','tth') {
6256: my $selected = '';
6257: if ($renderer eq $deftex) {
6258: $selected = ' selected="selected"';
6259: }
6260: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6261: }
6262: $mathdisp .= '</select></td></tr>'."\n";
6263: $itemcount ++;
1.139 raeburn 6264: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 6265: \%choices,$itemcount);
1.314 raeburn 6266: $datatable = $mathdisp.$datatable;
1.264 raeburn 6267: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6268: $datatable .=
1.306 raeburn 6269: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 6270: '<span class="LC_nobreak">'.$choices{'canclone'}.
6271: '</span></td><td class="LC_left_item">';
6272: my $currcanclone = 'none';
6273: my $onclick;
6274: my @cloneoptions = ('none','domain');
1.380 raeburn 6275: my %clonetitles = &Apache::lonlocal::texthash (
1.264 raeburn 6276: none => 'No additional course requesters',
6277: domain => "Any course requester in course's domain",
6278: instcode => 'Course requests for official courses ...',
6279: );
6280: my (%codedefaults,@code_order,@posscodes);
6281: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6282: \@code_order) eq 'ok') {
6283: if (@code_order > 0) {
6284: push(@cloneoptions,'instcode');
6285: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6286: }
6287: }
6288: if (ref($settings) eq 'HASH') {
6289: if ($settings->{'canclone'}) {
6290: if (ref($settings->{'canclone'}) eq 'HASH') {
6291: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6292: if (@code_order > 0) {
6293: $currcanclone = 'instcode';
6294: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6295: }
6296: }
6297: } elsif ($settings->{'canclone'} eq 'domain') {
6298: $currcanclone = $settings->{'canclone'};
6299: }
6300: }
1.289 raeburn 6301: }
1.264 raeburn 6302: foreach my $option (@cloneoptions) {
6303: my ($checked,$additional);
6304: if ($currcanclone eq $option) {
6305: $checked = ' checked="checked"';
6306: }
6307: if ($option eq 'instcode') {
6308: if (@code_order) {
6309: my $show = 'none';
6310: if ($checked) {
6311: $show = 'block';
6312: }
1.317 raeburn 6313: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 6314: &mt('Institutional codes for new and cloned course have identical:').
6315: '<br />';
6316: foreach my $item (@code_order) {
6317: my $codechk;
6318: if ($checked) {
6319: if (grep(/^\Q$item\E$/,@posscodes)) {
6320: $codechk = ' checked="checked"';
6321: }
6322: }
6323: $additional .= '<label>'.
6324: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
6325: $item.'</label>';
6326: }
6327: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
6328: }
6329: }
6330: $datatable .=
6331: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
6332: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
6333: '</label> '.$additional.'</span><br />';
6334: }
6335: $datatable .= '</td>'.
6336: '</tr>';
6337: $itemcount ++;
1.139 raeburn 6338: } else {
6339: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 6340: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 6341: my $currusecredits = 0;
1.257 raeburn 6342: my $postsubmitclient = 1;
1.271 raeburn 6343: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 6344: if (ref($settings) eq 'HASH') {
6345: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 6346: if (ref($settings->{'uploadquota'}) eq 'HASH') {
6347: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
6348: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
6349: }
6350: }
1.192 raeburn 6351: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 6352: foreach my $type (@types) {
6353: next if ($type eq 'community');
6354: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
6355: if ($defcredits{$type} ne '') {
6356: $currusecredits = 1;
6357: }
6358: }
6359: }
6360: if (ref($settings->{'postsubmit'}) eq 'HASH') {
6361: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
6362: $postsubmitclient = 0;
6363: foreach my $type (@types) {
6364: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6365: }
6366: } else {
6367: foreach my $type (@types) {
6368: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
6369: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 6370: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 6371: } else {
6372: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6373: }
6374: } else {
6375: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6376: }
6377: }
6378: }
6379: } else {
6380: foreach my $type (@types) {
6381: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 6382: }
6383: }
1.276 raeburn 6384: if (ref($settings->{'mysqltables'}) eq 'HASH') {
6385: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
6386: $currmysql{$type} = $settings->{'mysqltables'}{$type};
6387: }
6388: } else {
6389: foreach my $type (@types) {
6390: $currmysql{$type} = $staticdefaults{'mysqltables'};
6391: }
6392: }
1.258 raeburn 6393: } else {
6394: foreach my $type (@types) {
6395: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6396: }
1.139 raeburn 6397: }
6398: if (!$currdefresponder) {
1.198 raeburn 6399: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 6400: } elsif ($currdefresponder < 1) {
6401: $currdefresponder = 1;
6402: }
1.198 raeburn 6403: foreach my $type (@types) {
6404: if ($curruploadquota{$type} eq '') {
6405: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
6406: }
6407: }
1.139 raeburn 6408: $datatable .=
1.192 raeburn 6409: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6410: $choices{'anonsurvey_threshold'}.
1.139 raeburn 6411: '</span></td>'.
6412: '<td class="LC_right_item"><span class="LC_nobreak">'.
6413: '<input type="text" name="anonsurvey_threshold"'.
6414: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 6415: '</td></tr>'."\n";
6416: $itemcount ++;
6417: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6418: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6419: $choices{'uploadquota'}.
6420: '</span></td>'.
1.306 raeburn 6421: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 6422: '<table><tr>';
1.198 raeburn 6423: foreach my $type (@types) {
1.306 raeburn 6424: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 6425: '<input type="text" name="uploadquota_'.$type.'"'.
6426: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
6427: }
6428: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 6429: $itemcount ++;
1.236 raeburn 6430: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 6431: my $display = 'none';
1.192 raeburn 6432: if ($currusecredits) {
6433: $display = 'block';
6434: }
6435: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 6436: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
6437: foreach my $type (@types) {
6438: next if ($type eq 'community');
1.306 raeburn 6439: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 6440: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 6441: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 6442: }
6443: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 6444: %defaultchecked = ('coursecredits' => 'off');
6445: @toggles = ('coursecredits');
6446: my $current = {
6447: 'coursecredits' => $currusecredits,
6448: };
6449: (my $table,$itemcount) =
6450: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 6451: \%choices,$itemcount,$onclick,$additional,'left');
6452: $datatable .= $table;
6453: $onclick = "toggleDisplay(this.form,'studentsubmission');";
6454: my $display = 'none';
6455: if ($postsubmitclient) {
6456: $display = 'block';
6457: }
6458: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 6459: &mt('Number of seconds submit is disabled').'<br />'.
6460: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
6461: '<table><tr>';
1.257 raeburn 6462: foreach my $type (@types) {
1.306 raeburn 6463: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 6464: '<input type="text" name="'.$type.'_timeout" value="'.
6465: $deftimeout{$type}.'" size="5" /></td>';
6466: }
6467: $additional .= '</tr></table></div>'."\n";
6468: %defaultchecked = ('postsubmit' => 'on');
6469: @toggles = ('postsubmit');
1.280 raeburn 6470: $current = {
6471: 'postsubmit' => $postsubmitclient,
6472: };
1.257 raeburn 6473: ($table,$itemcount) =
6474: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
6475: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 6476: $datatable .= $table;
1.276 raeburn 6477: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6478: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6479: $choices{'mysqltables'}.
6480: '</span></td>'.
1.306 raeburn 6481: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 6482: '<table><tr>';
6483: foreach my $type (@types) {
1.306 raeburn 6484: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 6485: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 6486: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 6487: }
6488: $datatable .= '</tr></table></td></tr>'."\n";
6489: $itemcount ++;
6490:
1.139 raeburn 6491: }
1.192 raeburn 6492: $$rowtotal += $itemcount;
1.121 raeburn 6493: return $datatable;
1.118 jms 6494: }
6495:
1.231 raeburn 6496: sub print_selfenrollment {
6497: my ($position,$dom,$settings,$rowtotal) = @_;
6498: my ($css_class,$datatable);
6499: my $itemcount = 1;
1.271 raeburn 6500: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 6501: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 6502: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
6503: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 6504: my @rows;
6505: my $key;
6506: if ($position eq 'top') {
6507: $key = 'admin';
6508: if (ref($rowsref) eq 'ARRAY') {
6509: @rows = @{$rowsref};
6510: }
6511: } elsif ($position eq 'middle') {
6512: $key = 'default';
6513: @rows = ('types','registered','approval','limit');
6514: }
6515: foreach my $row (@rows) {
6516: if (defined($titlesref->{$row})) {
6517: $itemcount ++;
6518: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6519: $datatable .= '<tr'.$css_class.'>'.
6520: '<td>'.$titlesref->{$row}.'</td>'.
6521: '<td class="LC_left_item">'.
6522: '<table><tr>';
6523: my (%current,%currentcap);
6524: if (ref($settings) eq 'HASH') {
6525: if (ref($settings->{$key}) eq 'HASH') {
6526: foreach my $type (@types) {
6527: if (ref($settings->{$key}->{$type}) eq 'HASH') {
6528: $current{$type} = $settings->{$key}->{$type}->{$row};
6529: }
6530: if (($row eq 'limit') && ($key eq 'default')) {
6531: if (ref($settings->{$key}->{$type}) eq 'HASH') {
6532: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
6533: }
6534: }
6535: }
6536: }
6537: }
6538: my %roles = (
6539: '0' => &Apache::lonnet::plaintext('dc'),
6540: );
6541:
6542: foreach my $type (@types) {
6543: unless (($row eq 'registered') && ($key eq 'default')) {
6544: $datatable .= '<th>'.&mt($type).'</th>';
6545: }
6546: }
6547: unless (($row eq 'registered') && ($key eq 'default')) {
6548: $datatable .= '</tr><tr>';
6549: }
6550: foreach my $type (@types) {
6551: if ($type eq 'community') {
6552: $roles{'1'} = &mt('Community personnel');
6553: } else {
6554: $roles{'1'} = &mt('Course personnel');
6555: }
6556: $datatable .= '<td style="vertical-align: top">';
6557: if ($position eq 'top') {
6558: my %checked;
6559: if ($current{$type} eq '0') {
6560: $checked{'0'} = ' checked="checked"';
6561: } else {
6562: $checked{'1'} = ' checked="checked"';
6563: }
6564: foreach my $role ('1','0') {
6565: $datatable .= '<span class="LC_nobreak"><label>'.
6566: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
6567: 'value="'.$role.'"'.$checked{$role}.' />'.
6568: $roles{$role}.'</label></span> ';
6569: }
6570: } else {
6571: if ($row eq 'types') {
6572: my %checked;
6573: if ($current{$type} =~ /^(all|dom)$/) {
6574: $checked{$1} = ' checked="checked"';
6575: } else {
6576: $checked{''} = ' checked="checked"';
6577: }
6578: foreach my $val ('','dom','all') {
6579: $datatable .= '<span class="LC_nobreak"><label>'.
6580: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6581: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6582: }
6583: } elsif ($row eq 'registered') {
6584: my %checked;
6585: if ($current{$type} eq '1') {
6586: $checked{'1'} = ' checked="checked"';
6587: } else {
6588: $checked{'0'} = ' checked="checked"';
6589: }
6590: foreach my $val ('0','1') {
6591: $datatable .= '<span class="LC_nobreak"><label>'.
6592: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6593: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6594: }
6595: } elsif ($row eq 'approval') {
6596: my %checked;
6597: if ($current{$type} =~ /^([12])$/) {
6598: $checked{$1} = ' checked="checked"';
6599: } else {
6600: $checked{'0'} = ' checked="checked"';
6601: }
6602: for my $val (0..2) {
6603: $datatable .= '<span class="LC_nobreak"><label>'.
6604: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6605: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6606: }
6607: } elsif ($row eq 'limit') {
6608: my %checked;
6609: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
6610: $checked{$1} = ' checked="checked"';
6611: } else {
6612: $checked{'none'} = ' checked="checked"';
6613: }
6614: my $cap;
6615: if ($currentcap{$type} =~ /^\d+$/) {
6616: $cap = $currentcap{$type};
6617: }
6618: foreach my $val ('none','allstudents','selfenrolled') {
6619: $datatable .= '<span class="LC_nobreak"><label>'.
6620: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6621: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6622: }
6623: $datatable .= '<br />'.
6624: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
6625: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
6626: '</span>';
6627: }
6628: }
6629: $datatable .= '</td>';
6630: }
6631: $datatable .= '</tr>';
6632: }
6633: $datatable .= '</table></td></tr>';
6634: }
6635: } elsif ($position eq 'bottom') {
1.235 raeburn 6636: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
6637: }
6638: $$rowtotal += $itemcount;
6639: return $datatable;
6640: }
6641:
6642: sub print_validation_rows {
6643: my ($caller,$dom,$settings,$rowtotal) = @_;
6644: my ($itemsref,$namesref,$fieldsref);
6645: if ($caller eq 'selfenroll') {
6646: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
6647: } elsif ($caller eq 'requestcourses') {
6648: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
6649: }
6650: my %currvalidation;
6651: if (ref($settings) eq 'HASH') {
6652: if (ref($settings->{'validation'}) eq 'HASH') {
6653: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 6654: }
1.235 raeburn 6655: }
6656: my $datatable;
6657: my $itemcount = 0;
6658: foreach my $item (@{$itemsref}) {
6659: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6660: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6661: $namesref->{$item}.
6662: '</span></td>'.
6663: '<td class="LC_left_item">';
6664: if (($item eq 'url') || ($item eq 'button')) {
6665: $datatable .= '<span class="LC_nobreak">'.
6666: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
6667: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
6668: } elsif ($item eq 'fields') {
6669: my @currfields;
6670: if (ref($currvalidation{$item}) eq 'ARRAY') {
6671: @currfields = @{$currvalidation{$item}};
6672: }
6673: foreach my $field (@{$fieldsref}) {
6674: my $check = '';
6675: if (grep(/^\Q$field\E$/,@currfields)) {
6676: $check = ' checked="checked"';
6677: }
6678: $datatable .= '<span class="LC_nobreak"><label>'.
6679: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
6680: ' value="'.$field.'"'.$check.' />'.$field.
6681: '</label></span> ';
6682: }
6683: } elsif ($item eq 'markup') {
1.334 raeburn 6684: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 6685: $currvalidation{$item}.
1.231 raeburn 6686: '</textarea>';
1.235 raeburn 6687: }
6688: $datatable .= '</td></tr>'."\n";
6689: if (ref($rowtotal)) {
1.231 raeburn 6690: $itemcount ++;
6691: }
6692: }
1.235 raeburn 6693: if ($caller eq 'requestcourses') {
6694: my %currhash;
1.248 raeburn 6695: if (ref($settings) eq 'HASH') {
6696: if (ref($settings->{'validation'}) eq 'HASH') {
6697: if ($settings->{'validation'}{'dc'} ne '') {
6698: $currhash{$settings->{'validation'}{'dc'}} = 1;
6699: }
1.235 raeburn 6700: }
6701: }
6702: my $numinrow = 2;
6703: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
6704: 'validationdc',%currhash);
1.247 raeburn 6705: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 6706: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 6707: if ($numdc > 1) {
1.247 raeburn 6708: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 6709: } else {
1.247 raeburn 6710: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 6711: }
1.247 raeburn 6712: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 6713: $itemcount ++;
6714: }
6715: if (ref($rowtotal)) {
6716: $$rowtotal += $itemcount;
6717: }
1.231 raeburn 6718: return $datatable;
6719: }
6720:
1.357 raeburn 6721: sub print_privacy {
6722: my ($position,$dom,$settings,$rowtotal) = @_;
6723: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
6724: my $itemcount = 0;
6725: unless ($position eq 'top') {
6726: @items = ('domain','author','course','community');
6727: %names = &Apache::lonlocal::texthash (
6728: domain => 'Assigned domain role(s)',
6729: author => 'Assigned co-author role(s)',
6730: course => 'Assigned course role(s)',
6731: community => 'Assigned community role',
6732: );
6733: $numinrow = 4;
6734: ($othertitle,$usertypes,$types) =
6735: &Apache::loncommon::sorted_inst_types($dom);
6736: }
6737: if (($position eq 'top') || ($position eq 'middle')) {
6738: my (%by_ip,%by_location,@intdoms,@instdoms);
6739: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
6740: if ($position eq 'top') {
6741: my %curr;
6742: my @options = ('none','user','domain','auto');
6743: my %titles = &Apache::lonlocal::texthash (
6744: none => 'Not allowed',
6745: user => 'User authorizes',
6746: domain => 'DC authorizes',
6747: auto => 'Unrestricted',
6748: instdom => 'Other domain shares institution/provider',
6749: extdom => 'Other domain has different institution/provider',
6750: );
6751: my %names = &Apache::lonlocal::texthash (
6752: domain => 'Domain role',
6753: author => 'Co-author role',
6754: course => 'Course role',
6755: community => 'Community role',
6756: );
6757: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6758: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6759: foreach my $domtype ('instdom','extdom') {
6760: my (%checked,$skip);
6761: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6762: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
6763: '<td class="LC_left_item">';
6764: if ($domtype eq 'instdom') {
6765: unless (@instdoms > 1) {
6766: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
6767: $skip = 1;
6768: }
6769: } elsif ($domtype eq 'extdom') {
6770: if (keys(%by_location) == 0) {
6771: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
6772: $skip = 1;
6773: }
6774: }
6775: unless ($skip) {
6776: foreach my $roletype ('domain','author','course','community') {
6777: $checked{'auto'} = ' checked="checked"';
6778: if (ref($settings) eq 'HASH') {
6779: if (ref($settings->{approval}) eq 'HASH') {
6780: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
6781: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
6782: $checked{$1} = ' checked="checked"';
6783: $checked{'auto'} = '';
6784: }
6785: }
6786: }
6787: }
6788: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
6789: foreach my $option (@options) {
6790: $datatable .= '<span class="LC_nobreak"><label>'.
6791: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
6792: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
6793: '</label></span> ';
6794: }
6795: $datatable .= '</fieldset>';
6796: }
6797: }
6798: $datatable .= '</td></tr>';
6799: $itemcount ++;
6800: }
6801: } elsif ($position eq 'middle') {
6802: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
6803: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6804: foreach my $item (@{$types}) {
6805: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
6806: $numinrow,$itemcount,'','','','','',
6807: '',$usertypes->{$item});
6808: $itemcount ++;
6809: }
6810: }
6811: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
6812: $numinrow,$itemcount,'','','','','',
6813: '',$othertitle);
6814: $itemcount ++;
6815: } else {
1.360 raeburn 6816: my (@insttypes,%insttitles);
6817: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6818: @insttypes = @{$types};
6819: %insttitles = %{$usertypes};
6820: }
6821: foreach my $item (@insttypes,'default') {
6822: my $title;
6823: if ($item eq 'default') {
6824: $title = $othertitle;
6825: } else {
6826: $title = $insttitles{$item};
6827: }
6828: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6829: $datatable .= '<tr'.$css_class.'>'.
6830: '<td class="LC_left_item">'.$title.'</td>'.
6831: '<td class="LC_left_item">'.
6832: &mt('Nothing to set here, as there are no other domains').
6833: '</td></tr>';
6834: $itemcount ++;
6835: }
1.357 raeburn 6836: }
6837: }
6838: } else {
6839: my $prefix;
6840: if ($position eq 'lower') {
6841: $prefix = 'priv';
6842: } else {
6843: $prefix = 'unpriv';
6844: }
6845: foreach my $item (@items) {
6846: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
6847: $numinrow,$itemcount,'','','','','',
6848: '',$names{$item});
6849: $itemcount ++;
6850: }
6851: }
6852: if (ref($rowtotal)) {
6853: $$rowtotal += $itemcount;
6854: }
6855: return $datatable;
6856: }
6857:
1.354 raeburn 6858: sub print_passwords {
6859: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
6860: my ($datatable,$css_class);
6861: my $itemcount = 0;
6862: my %titles = &Apache::lonlocal::texthash (
6863: captcha => '"Forgot Password" CAPTCHA validation',
6864: link => 'Reset link expiration (hours)',
6865: case => 'Case-sensitive usernames/e-mail',
6866: prelink => 'Information required (form 1)',
6867: postlink => 'Information required (form 2)',
6868: emailsrc => 'LON-CAPA e-mail address type(s)',
6869: customtext => 'Domain specific text (HTML)',
6870: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
6871: intauth_check => 'Check bcrypt cost if authenticated',
6872: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
6873: permanent => 'Permanent e-mail address',
6874: critical => 'Critical notification address',
6875: notify => 'Notification address',
6876: min => 'Minimum password length',
6877: max => 'Maximum password length',
6878: chars => 'Required characters',
6879: expire => 'Password expiration (days)',
1.356 raeburn 6880: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 6881: );
6882: if ($position eq 'top') {
6883: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6884: my $shownlinklife = 2;
6885: my $prelink = 'both';
6886: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
6887: if (ref($settings) eq 'HASH') {
6888: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
6889: $shownlinklife = $settings->{resetlink};
6890: }
6891: if (ref($settings->{resetcase}) eq 'ARRAY') {
6892: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
6893: }
6894: if ($settings->{resetprelink} =~ /^(both|either)$/) {
6895: $prelink = $settings->{resetprelink};
6896: }
6897: if (ref($settings->{resetpostlink}) eq 'HASH') {
6898: %postlink = %{$settings->{resetpostlink}};
6899: }
6900: if (ref($settings->{resetemail}) eq 'ARRAY') {
6901: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
6902: }
6903: if ($settings->{resetremove}) {
6904: $nostdtext = 1;
6905: }
6906: if ($settings->{resetcustom}) {
6907: $customurl = $settings->{resetcustom};
6908: }
6909: } else {
6910: if (ref($types) eq 'ARRAY') {
6911: foreach my $item (@{$types}) {
6912: $casesens{$item} = 1;
6913: $postlink{$item} = ['username','email'];
6914: }
6915: }
6916: $casesens{'default'} = 1;
6917: $postlink{'default'} = ['username','email'];
6918: $prelink = 'both';
6919: %emailsrc = (
6920: permanent => 1,
6921: critical => 1,
6922: notify => 1,
6923: );
6924: }
6925: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
6926: $itemcount ++;
6927: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6928: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
6929: '<td class="LC_left_item">'.
6930: '<input type="textbox" value="'.$shownlinklife.'" '.
6931: 'name="passwords_link" size="3" /></td></tr>';
6932: $itemcount ++;
6933: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6934: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
6935: '<td class="LC_left_item">';
6936: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6937: foreach my $item (@{$types}) {
6938: my $checkedcase;
6939: if ($casesens{$item}) {
6940: $checkedcase = ' checked="checked"';
6941: }
6942: $datatable .= '<span class="LC_nobreak"><label>'.
6943: '<input type="checkbox" name="passwords_case_sensitive" value="'.
6944: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 6945: '</span> ';
1.354 raeburn 6946: }
6947: }
6948: my $checkedcase;
6949: if ($casesens{'default'}) {
6950: $checkedcase = ' checked="checked"';
6951: }
6952: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
6953: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
6954: $othertitle.'</label></span></td>';
6955: $itemcount ++;
6956: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6957: my %checkedpre = (
6958: both => ' checked="checked"',
6959: either => '',
6960: );
6961: if ($prelink eq 'either') {
6962: $checkedpre{either} = ' checked="checked"';
6963: $checkedpre{both} = '';
6964: }
6965: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
6966: '<td class="LC_left_item"><span class="LC_nobreak">'.
6967: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
6968: &mt('Both username and e-mail address').'</label></span> '.
6969: '<span class="LC_nobreak"><label>'.
6970: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
6971: &mt('Either username or e-mail address').'</label></span></td></tr>';
6972: $itemcount ++;
6973: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6974: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
6975: '<td class="LC_left_item">';
6976: my %postlinked;
6977: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6978: foreach my $item (@{$types}) {
6979: undef(%postlinked);
6980: $datatable .= '<fieldset style="display: inline-block;">'.
6981: '<legend>'.$usertypes->{$item}.'</legend>';
6982: if (ref($postlink{$item}) eq 'ARRAY') {
6983: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
6984: }
6985: foreach my $field ('email','username') {
6986: my $checked;
6987: if ($postlinked{$field}) {
6988: $checked = ' checked="checked"';
6989: }
6990: $datatable .= '<span class="LC_nobreak"><label>'.
6991: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
6992: $field.'"'.$checked.' />'.$field.'</label>'.
6993: '<span> ';
6994: }
6995: $datatable .= '</fieldset>';
6996: }
6997: }
6998: if (ref($postlink{'default'}) eq 'ARRAY') {
6999: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
7000: }
7001: $datatable .= '<fieldset style="display: inline-block;">'.
7002: '<legend>'.$othertitle.'</legend>';
7003: foreach my $field ('email','username') {
7004: my $checked;
7005: if ($postlinked{$field}) {
7006: $checked = ' checked="checked"';
7007: }
7008: $datatable .= '<span class="LC_nobreak"><label>'.
7009: '<input type="checkbox" name="passwords_postlink_default" value="'.
7010: $field.'"'.$checked.' />'.$field.'</label>'.
7011: '<span> ';
7012: }
7013: $datatable .= '</fieldset></td></tr>';
7014: $itemcount ++;
7015: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7016: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
7017: '<td class="LC_left_item">';
7018: foreach my $type ('permanent','critical','notify') {
7019: my $checkedemail;
7020: if ($emailsrc{$type}) {
7021: $checkedemail = ' checked="checked"';
7022: }
7023: $datatable .= '<span class="LC_nobreak"><label>'.
7024: '<input type="checkbox" name="passwords_emailsrc" value="'.
7025: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
7026: '<span> ';
7027: }
7028: $datatable .= '</td></tr>';
7029: $itemcount ++;
7030: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7031: my $switchserver = &check_switchserver($dom,$confname);
7032: my ($showstd,$noshowstd);
7033: if ($nostdtext) {
7034: $noshowstd = ' checked="checked"';
7035: } else {
7036: $showstd = ' checked="checked"';
7037: }
7038: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
7039: '<td class="LC_left_item"><span class="LC_nobreak">'.
7040: &mt('Retain standard text:').
7041: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
7042: &mt('Yes').'</label>'.' '.
7043: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
7044: &mt('No').'</label></span><br />'.
7045: '<span class="LC_fontsize_small">'.
7046: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
7047: &mt('Include custom text:');
7048: if ($customurl) {
1.369 raeburn 7049: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 7050: undef,undef,undef,undef,'background-color:#ffffff');
7051: $datatable .= '<span class="LC_nobreak"> '.$link.
7052: '<label><input type="checkbox" name="passwords_custom_del"'.
7053: ' value="1" />'.&mt('Delete?').'</label></span>'.
7054: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
7055: }
7056: if ($switchserver) {
7057: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
7058: } else {
7059: $datatable .='<span class="LC_nobreak"> '.
7060: '<input type="file" name="passwords_customfile" /></span>';
7061: }
7062: $datatable .= '</td></tr>';
7063: } elsif ($position eq 'middle') {
7064: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
7065: my @items = ('intauth_cost','intauth_check','intauth_switch');
7066: my %defaults;
7067: if (ref($domconf{'defaults'}) eq 'HASH') {
7068: %defaults = %{$domconf{'defaults'}};
7069: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
7070: $defaults{'intauth_cost'} = 10;
7071: }
7072: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
7073: $defaults{'intauth_check'} = 0;
7074: }
7075: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
7076: $defaults{'intauth_switch'} = 0;
7077: }
7078: } else {
7079: %defaults = (
7080: 'intauth_cost' => 10,
7081: 'intauth_check' => 0,
7082: 'intauth_switch' => 0,
7083: );
7084: }
7085: foreach my $item (@items) {
7086: if ($itemcount%2) {
7087: $css_class = '';
7088: } else {
7089: $css_class = ' class="LC_odd_row" ';
7090: }
7091: $datatable .= '<tr'.$css_class.'>'.
7092: '<td><span class="LC_nobreak">'.$titles{$item}.
7093: '</span></td><td class="LC_left_item" colspan="3">';
7094: if ($item eq 'intauth_switch') {
7095: my @options = (0,1,2);
7096: my %optiondesc = &Apache::lonlocal::texthash (
7097: 0 => 'No',
7098: 1 => 'Yes',
7099: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
7100: );
7101: $datatable .= '<table width="100%">';
7102: foreach my $option (@options) {
7103: my $checked = ' ';
7104: if ($defaults{$item} eq $option) {
7105: $checked = ' checked="checked"';
7106: }
7107: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7108: '<label><input type="radio" name="'.$item.
7109: '" value="'.$option.'"'.$checked.' />'.
7110: $optiondesc{$option}.'</label></span></td></tr>';
7111: }
7112: $datatable .= '</table>';
7113: } elsif ($item eq 'intauth_check') {
7114: my @options = (0,1,2);
7115: my %optiondesc = &Apache::lonlocal::texthash (
7116: 0 => 'No',
7117: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
7118: 2 => 'Yes, disallow login if stored cost is less than domain default',
7119: );
7120: $datatable .= '<table width="100%">';
7121: foreach my $option (@options) {
7122: my $checked = ' ';
7123: my $onclick;
7124: if ($defaults{$item} eq $option) {
7125: $checked = ' checked="checked"';
7126: }
7127: if ($option == 2) {
7128: $onclick = ' onclick="javascript:warnIntAuth(this);"';
7129: }
7130: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7131: '<label><input type="radio" name="'.$item.
7132: '" value="'.$option.'"'.$checked.$onclick.' />'.
7133: $optiondesc{$option}.'</label></span></td></tr>';
7134: }
7135: $datatable .= '</table>';
7136: } else {
7137: $datatable .= '<input type="text" name="'.$item.'" value="'.
7138: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
7139: }
7140: $datatable .= '</td></tr>';
7141: $itemcount ++;
7142: }
7143: } elsif ($position eq 'lower') {
1.356 raeburn 7144: my ($min,$max,%chars,$expire,$numsaved);
1.365 raeburn 7145: $min = $Apache::lonnet::passwdmin;
1.354 raeburn 7146: if (ref($settings) eq 'HASH') {
7147: if ($settings->{min}) {
7148: $min = $settings->{min};
7149: }
7150: if ($settings->{max}) {
7151: $max = $settings->{max};
7152: }
7153: if (ref($settings->{chars}) eq 'ARRAY') {
7154: map { $chars{$_} = 1; } (@{$settings->{chars}});
7155: }
7156: if ($settings->{expire}) {
7157: $expire = $settings->{expire};
7158: }
1.358 raeburn 7159: if ($settings->{numsaved}) {
7160: $numsaved = $settings->{numsaved};
1.356 raeburn 7161: }
1.354 raeburn 7162: }
7163: my %rulenames = &Apache::lonlocal::texthash(
7164: uc => 'At least one upper case letter',
7165: lc => 'At least one lower case letter',
7166: num => 'At least one number',
7167: spec => 'At least one non-alphanumeric',
7168: );
7169: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7170: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
7171: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 7172: '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
7173: 'onblur="javascript:warnIntPass(this);" />'.
7174: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
1.354 raeburn 7175: '</span></td></tr>';
7176: $itemcount ++;
7177: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7178: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
7179: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 7180: '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
7181: 'onblur="javascript:warnIntPass(this);" />'.
1.354 raeburn 7182: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
7183: '</span></td></tr>';
7184: $itemcount ++;
7185: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7186: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
7187: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
7188: '</span></td>';
7189: my $numinrow = 2;
7190: my @possrules = ('uc','lc','num','spec');
7191: $datatable .= '<td class="LC_left_item"><table>';
7192: for (my $i=0; $i<@possrules; $i++) {
7193: my ($rem,$checked);
7194: if ($chars{$possrules[$i]}) {
7195: $checked = ' checked="checked"';
7196: }
7197: $rem = $i%($numinrow);
7198: if ($rem == 0) {
7199: if ($i > 0) {
7200: $datatable .= '</tr>';
7201: }
7202: $datatable .= '<tr>';
7203: }
7204: $datatable .= '<td><span class="LC_nobreak"><label>'.
7205: '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
7206: $rulenames{$possrules[$i]}.'</label></span></td>';
7207: }
7208: my $rem = @possrules%($numinrow);
7209: my $colsleft = $numinrow - $rem;
7210: if ($colsleft > 1 ) {
7211: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7212: ' </td>';
7213: } elsif ($colsleft == 1) {
7214: $datatable .= '<td class="LC_left_item"> </td>';
7215: }
7216: $datatable .='</table></td></tr>';
7217: $itemcount ++;
7218: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7219: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
7220: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 7221: '<input type="text" name="passwords_expire" value="'.$expire.'" size="4" '.
7222: 'onblur="javascript:warnIntPass(this);" />'.
1.354 raeburn 7223: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
7224: '</span></td></tr>';
1.356 raeburn 7225: $itemcount ++;
7226: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7227: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
7228: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.367 raeburn 7229: '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
7230: 'onblur="javascript:warnIntPass(this);" />'.
1.356 raeburn 7231: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
7232: '</span></td></tr>';
1.354 raeburn 7233: } else {
1.359 raeburn 7234: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7235: my %ownerchg = (
7236: by => {},
7237: for => {},
7238: );
7239: my %ownertitles = &Apache::lonlocal::texthash (
7240: by => 'Course owner status(es) allowed',
7241: for => 'Student status(es) allowed',
7242: );
1.354 raeburn 7243: if (ref($settings) eq 'HASH') {
1.359 raeburn 7244: if (ref($settings->{crsownerchg}) eq 'HASH') {
7245: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
7246: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
7247: }
7248: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
7249: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
7250: }
1.354 raeburn 7251: }
7252: }
7253: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7254: $datatable .= '<tr '.$css_class.'>'.
7255: '<td>'.
7256: &mt('Requirements').'<ul>'.
1.359 raeburn 7257: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 7258: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
7259: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 7260: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 7261: '</ul>'.
7262: '</td>'.
1.359 raeburn 7263: '<td class="LC_left_item">';
7264: foreach my $item ('by','for') {
7265: $datatable .= '<fieldset style="display: inline-block;">'.
7266: '<legend>'.$ownertitles{$item}.'</legend>';
7267: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7268: foreach my $type (@{$types}) {
7269: my $checked;
7270: if ($ownerchg{$item}{$type}) {
7271: $checked = ' checked="checked"';
7272: }
7273: $datatable .= '<span class="LC_nobreak"><label>'.
7274: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
7275: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 7276: '</span> ';
1.359 raeburn 7277: }
7278: }
7279: my $checked;
7280: if ($ownerchg{$item}{'default'}) {
7281: $checked = ' checked="checked"';
7282: }
7283: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7284: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
7285: $othertitle.'</label></span></fieldset>';
7286: }
7287: $datatable .= '</td></tr>';
1.354 raeburn 7288: }
7289: return $datatable;
7290: }
7291:
1.373 raeburn 7292: sub print_wafproxy {
7293: my ($position,$dom,$settings,$rowtotal) = @_;
7294: my $css_class;
7295: my $itemcount = 0;
7296: my $datatable;
7297: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 7298: my (%othercontrol,%otherdoms,%aliases,%values,$setdom,$showdom);
1.374 raeburn 7299: my %lt = &wafproxy_titles();
1.373 raeburn 7300: foreach my $server (sort(keys(%servers))) {
7301: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381 raeburn 7302: next if ($serverhome eq '');
1.373 raeburn 7303: my $serverdom;
7304: if ($serverhome ne $server) {
7305: $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381 raeburn 7306: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
7307: $othercontrol{$server} = $serverdom;
7308: }
1.373 raeburn 7309: } else {
7310: $serverdom = &Apache::lonnet::host_domain($server);
1.381 raeburn 7311: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373 raeburn 7312: if ($serverdom ne $dom) {
7313: $othercontrol{$server} = $serverdom;
7314: } else {
7315: $setdom = 1;
7316: if (ref($settings) eq 'HASH') {
7317: if (ref($settings->{'alias'}) eq 'HASH') {
7318: $aliases{$dom} = $settings->{'alias'};
1.381 raeburn 7319: if ($aliases{$dom} ne '') {
7320: $showdom = 1;
7321: }
1.373 raeburn 7322: }
7323: }
7324: }
7325: }
7326: }
1.381 raeburn 7327: if ($setdom) {
7328: %{$values{$dom}} = ();
7329: if (ref($settings) eq 'HASH') {
7330: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
7331: $values{$dom}{$item} = $settings->{$item};
7332: }
7333: }
7334: }
1.373 raeburn 7335: if (keys(%othercontrol)) {
7336: %otherdoms = reverse(%othercontrol);
7337: foreach my $domain (keys(%otherdoms)) {
7338: %{$values{$domain}} = ();
7339: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
7340: if (ref($config{$domain}) eq 'HASH') {
7341: if (ref($config{$domain}{'wafproxy'}) eq 'HASH') {
7342: $aliases{$domain} = $config{$domain}{'wafproxy'}{'alias'};
1.381 raeburn 7343: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
1.373 raeburn 7344: $values{$domain}{$item} = $config{$domain}{'wafproxy'}{$item};
7345: }
7346: }
7347: }
7348: }
7349: }
7350: if ($position eq 'top') {
7351: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 7352: my %aliasinfo;
1.373 raeburn 7353: foreach my $server (sort(keys(%servers))) {
1.381 raeburn 7354: $itemcount ++;
7355: my $dom_in_effect;
7356: my $aliasrows = '<tr>'.
7357: '<td class="LC_left_item">'.&mt('Hostname').': '.
7358: &Apache::lonnet::hostname($server).'</td>';
1.373 raeburn 7359: if ($othercontrol{$server}) {
1.381 raeburn 7360: $dom_in_effect = $othercontrol{$server};
1.373 raeburn 7361: my $current;
7362: if (ref($aliases{$othercontrol{$server}}) eq 'HASH') {
7363: $current = $aliases{$othercontrol{$server}{$server}};
7364: }
7365: if ($current) {
1.381 raeburn 7366: $aliasrows .= $current;
1.373 raeburn 7367: } else {
1.381 raeburn 7368: $aliasrows .= &mt('None in effect');
1.373 raeburn 7369: }
1.381 raeburn 7370: $aliasrows .= '<td class="LC_left_item"><span class="LC_small">('.
1.373 raeburn 7371: &mt('WAF/Reverse Proxy controlled by domain: [_1]',
1.381 raeburn 7372: '<b>'.$othercontrol{$server}.'</b>').'</span></td>';
1.373 raeburn 7373: } else {
1.381 raeburn 7374: $dom_in_effect = $dom;
1.373 raeburn 7375: my $current;
7376: if (ref($aliases{$dom}) eq 'HASH') {
7377: if ($aliases{$dom}{$server}) {
7378: $current = $aliases{$dom}{$server};
7379: }
7380: }
1.381 raeburn 7381: $aliasrows .= '<td class="LC_left_item">'.&mt('WAF/Reverse Proxy Alias').': '.
7382: '<input type="text" name="wafproxy_alias_'.$server.'" '.
7383: 'value="'.$current.'" size="30" /></td>';
7384: }
7385: $aliasrows .= '</tr>';
7386: $aliasinfo{$dom_in_effect} .= $aliasrows;
7387: }
7388: if ($aliasinfo{$dom}) {
7389: my ($onclick,$wafon,$wafoff,$showtable);
7390: $onclick = ' onclick="javascript:toggleWAF();"';
7391: $wafoff = ' checked="checked"';
7392: $showtable = ' style="display:none";';
7393: if ($showdom) {
7394: $wafon = $wafoff;
7395: $wafoff = '';
7396: $showtable = ' style="display:inline;"';
7397: }
7398: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7399: $datatable = '<tr'.$css_class.'>'.
7400: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
7401: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
7402: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
7403: &mt('Yes').'</label>'.(' 'x2).'<label>'.
7404: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
7405: &mt('No').'</label></span></td>'.
7406: '<td class="LC_left_item">'.
7407: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
7408: '</table></td></tr>';
7409: $itemcount++;
7410: }
7411: if (keys(%othercontrol)) {
7412: foreach my $key (sort(keys(%othercontrol))) {
7413: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7414: $datatable = '<tr'.$css_class.'>'.
7415: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
7416: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
7417: '</table></td></tr>';
7418: $itemcount++;
1.373 raeburn 7419: }
7420: }
7421: } else {
7422: if ($setdom) {
7423: $itemcount ++;
7424: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381 raeburn 7425: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382 ! raeburn 7426: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381 raeburn 7427: $wafstyle = ' style="display:none;"';
7428: $nowafstyle = ' style="display:table-row;"';
7429: $currwafdisplay = ' style="display: none"';
7430: $wafrangestyle = ' style="display: none"';
7431: $curr_remotip = 'n';
1.382 ! raeburn 7432: $ssltossl = ' checked="checked"';
1.381 raeburn 7433: if ($showdom) {
7434: $wafstyle = ' style="display:table-row;"';
7435: $nowafstyle = ' style="display:none;"';
7436: if (keys(%{$values{$dom}})) {
7437: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
7438: $curr_remotip = $values{$dom}{remoteip};
7439: }
7440: if ($curr_remotip eq 'h') {
7441: $currwafdisplay = ' style="display:table-row"';
7442: $wafrangestyle = ' style="display:inline-block;"';
7443: }
1.382 ! raeburn 7444: if ($values{$dom}{'sslopt'}) {
! 7445: $alltossl = ' checked="checked"';
! 7446: $ssltossl = '';
! 7447: }
1.381 raeburn 7448: }
7449: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
7450: $vpndircheck = ' checked="checked"';
7451: $currwafvpn = ' style="display:table-row;"';
7452: $wafrangestyle = ' style="display:inline-block;"';
7453: } else {
7454: $vpnaliascheck = ' checked="checked"';
7455: $currwafvpn = ' style="display:none;"';
7456: }
7457: }
7458: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
7459: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
7460: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
7461: '</tr>'.
7462: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374 raeburn 7463: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381 raeburn 7464: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
7465: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'</div></td>'.
7466: '<td class="LC_left_item"><table>'.
7467: '<tr>'.
7468: '<td valign="top">'.$lt{'remoteip'}.': '.
7469: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
7470: my %ip_methods = &remoteip_methods();
7471: foreach my $option ('m','h','n') {
7472: my $sel;
7473: if ($option eq $curr_remotip) {
7474: $sel = ' selected="selected"';
7475: }
7476: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
7477: $ip_methods{$option}.'</option>';
7478: }
7479: $datatable .= '</select></td></tr>'."\n".
7480: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
7481: $lt{'ipheader'}.': '.
7482: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
7483: 'name="wafproxy_ipheader" />'.
7484: '</td></tr>'."\n".
7485: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382 ! raeburn 7486: $lt{'trusted'}.':<br />'.
1.381 raeburn 7487: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
7488: $values{$dom}{'trusted'}.'</textarea>'.
7489: '</td></tr>'."\n".
7490: '<tr><td><hr /></td></tr>'."\n".
7491: '<tr>'.
7492: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
7493: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
7494: $lt{'vpndirect'}.'</label>'.(' 'x2).
7495: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
7496: $lt{'vpnaliased'}.'</label></span></td></tr>';
7497: foreach my $item ('vpnint','vpnext') {
7498: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382 ! raeburn 7499: '<td valign="top">'.$lt{$item}.':<br />'.
1.381 raeburn 7500: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
7501: $values{$dom}{$item}.'</textarea>'.
7502: '</td></tr>'."\n";
1.373 raeburn 7503: }
1.382 ! raeburn 7504: $datatable .= '<tr><td><hr /></td></tr>'."\n".
! 7505: '<tr>'.
! 7506: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
! 7507: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
! 7508: $lt{'alltossl'}.'</label>'.(' 'x2).
! 7509: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
! 7510: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
! 7511: '</table></td></tr>';
1.373 raeburn 7512: }
7513: if (keys(%otherdoms)) {
7514: foreach my $domain (sort(keys(%otherdoms))) {
7515: $itemcount ++;
7516: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7517: $datatable .= '<tr'.$css_class.'>'.
1.374 raeburn 7518: '<td class="LC_left_item">'.&mt('Domain: [_1]',$domain).'</td>'.
7519: '<td class="LC_left_item"><table>';
1.382 ! raeburn 7520: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 7521: my $showval = &mt('None');
1.382 ! raeburn 7522: if ($item eq 'ssl') {
! 7523: $showval = $lt{'ssltossl'};
! 7524: }
1.373 raeburn 7525: if ($values{$domain}{$item}) {
1.381 raeburn 7526: $showval = $values{$domain}{$item};
1.382 ! raeburn 7527: if ($item eq 'ssl') {
! 7528: $showval = $lt{'alltossl'};
! 7529: }
1.373 raeburn 7530: }
7531: $datatable .= '<tr>'.
7532: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
7533: }
1.381 raeburn 7534: $datatable .= '</table></td></tr>';
1.373 raeburn 7535: }
7536: }
7537: }
7538: $$rowtotal += $itemcount;
7539: return $datatable;
7540: }
7541:
7542: sub wafproxy_titles {
7543: return &Apache::lonlocal::texthash(
1.381 raeburn 7544: remoteip => "Method for determining user's IP",
7545: ipheader => 'Request header containing remote IP',
7546: trusted => 'Trusted IP range(s)',
7547: vpnaccess => 'Access from institutional VPN',
7548: vpndirect => 'via regular hostname (no WAF)',
7549: vpnaliased => 'via aliased hostname (WAF)',
7550: vpnint => 'Internal IP Range(s) for VPN sessions',
7551: vpnext => 'IP Range(s) for backend WAF connections',
1.382 ! raeburn 7552: sslopt => 'Forwarding http/https',
1.381 raeburn 7553: alltossl => 'WAF forwards both http and https requests to https',
7554: ssltossl => 'WAF forwards http requests to http and https to https',
7555: );
7556: }
7557:
7558: sub remoteip_methods {
7559: return &Apache::lonlocal::texthash(
7560: m => 'Use Apache mod_remoteip',
7561: h => 'Use headers parsed by LON-CAPA',
7562: n => 'Not in use',
1.373 raeburn 7563: );
7564: }
7565:
1.137 raeburn 7566: sub print_usersessions {
7567: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 7568: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 7569: my (%by_ip,%by_location,@intdoms,@instdoms);
7570: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 7571:
7572: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 7573: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 7574: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 7575: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 7576: if ($position eq 'top') {
1.152 raeburn 7577: if (keys(%serverhomes) > 1) {
1.145 raeburn 7578: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 7579: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 7580: if (ref($settings) eq 'HASH') {
7581: if (ref($settings->{'offloadnow'}) eq 'HASH') {
7582: $curroffloadnow = $settings->{'offloadnow'};
7583: }
1.371 raeburn 7584: if (ref($settings->{'offloadoth'}) eq 'HASH') {
7585: $curroffloadoth = $settings->{'offloadoth'};
7586: }
1.261 raeburn 7587: }
1.371 raeburn 7588: my $other_insts = scalar(keys(%by_location));
7589: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
7590: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 7591: } else {
1.140 raeburn 7592: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 7593: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
7594: '</td></tr>';
1.140 raeburn 7595: }
1.137 raeburn 7596: } else {
1.279 raeburn 7597: my %titles = &usersession_titles();
7598: my ($prefix,@types);
7599: if ($position eq 'bottom') {
7600: $prefix = 'remote';
7601: @types = ('version','excludedomain','includedomain');
1.145 raeburn 7602: } else {
1.279 raeburn 7603: $prefix = 'hosted';
7604: @types = ('excludedomain','includedomain');
7605: }
7606: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
7607: }
7608: $$rowtotal += $itemcount;
7609: return $datatable;
7610: }
7611:
7612: sub rules_by_location {
7613: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
7614: my ($datatable,$itemcount,$css_class);
7615: if (keys(%{$by_location}) == 0) {
7616: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7617: $datatable = '<tr'.$css_class.'><td colspan="2">'.
7618: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
7619: '</td></tr>';
7620: $itemcount = 1;
7621: } else {
7622: $itemcount = 0;
7623: my $numinrow = 5;
7624: my (%current,%checkedon,%checkedoff);
7625: my @locations = sort(keys(%{$by_location}));
7626: foreach my $type (@{$types}) {
7627: $checkedon{$type} = '';
7628: $checkedoff{$type} = ' checked="checked"';
7629: }
7630: if (ref($settings) eq 'HASH') {
7631: if (ref($settings->{$prefix}) eq 'HASH') {
7632: foreach my $key (keys(%{$settings->{$prefix}})) {
7633: $current{$key} = $settings->{$prefix}{$key};
7634: if ($key eq 'version') {
7635: if ($current{$key} ne '') {
1.145 raeburn 7636: $checkedon{$key} = ' checked="checked"';
7637: $checkedoff{$key} = '';
7638: }
1.279 raeburn 7639: } elsif (ref($current{$key}) eq 'ARRAY') {
7640: $checkedon{$key} = ' checked="checked"';
7641: $checkedoff{$key} = '';
1.137 raeburn 7642: }
7643: }
7644: }
1.279 raeburn 7645: }
7646: foreach my $type (@{$types}) {
7647: next if ($type ne 'version' && !@locations);
7648: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7649: $datatable .= '<tr'.$css_class.'>
7650: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
7651: <span class="LC_nobreak">
7652: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
7653: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
7654: if ($type eq 'version') {
7655: my @lcversions = &Apache::lonnet::all_loncaparevs();
7656: my $selector = '<select name="'.$prefix.'_version">';
7657: foreach my $version (@lcversions) {
7658: my $selected = '';
7659: if ($current{'version'} eq $version) {
7660: $selected = ' selected="selected"';
1.145 raeburn 7661: }
1.279 raeburn 7662: $selector .= ' <option value="'.$version.'"'.
7663: $selected.'>'.$version.'</option>';
7664: }
7665: $selector .= '</select> ';
7666: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
7667: } else {
7668: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
7669: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
7670: ' />'.(' 'x2).
7671: '<input type="button" value="'.&mt('uncheck all').'" '.
7672: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
7673: "\n".
7674: '</div><div><table>';
7675: my $rem;
7676: for (my $i=0; $i<@locations; $i++) {
7677: my ($showloc,$value,$checkedtype);
7678: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
7679: my $ip = $by_location->{$locations[$i]}->[0];
7680: if (ref($by_ip->{$ip}) eq 'ARRAY') {
7681: $value = join(':',@{$by_ip->{$ip}});
7682: $showloc = join(', ',@{$by_ip->{$ip}});
7683: if (ref($current{$type}) eq 'ARRAY') {
7684: foreach my $loc (@{$by_ip->{$ip}}) {
7685: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
7686: $checkedtype = ' checked="checked"';
7687: last;
1.145 raeburn 7688: }
1.138 raeburn 7689: }
7690: }
7691: }
1.137 raeburn 7692: }
1.279 raeburn 7693: $rem = $i%($numinrow);
7694: if ($rem == 0) {
7695: if ($i > 0) {
7696: $datatable .= '</tr>';
7697: }
7698: $datatable .= '<tr>';
7699: }
7700: $datatable .= '<td class="LC_left_item">'.
7701: '<span class="LC_nobreak"><label>'.
7702: '<input type="checkbox" name="'.$prefix.'_'.$type.
7703: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
7704: '</label></span></td>';
7705: }
7706: $rem = @locations%($numinrow);
7707: my $colsleft = $numinrow - $rem;
7708: if ($colsleft > 1 ) {
7709: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7710: ' </td>';
7711: } elsif ($colsleft == 1) {
7712: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 7713: }
1.279 raeburn 7714: $datatable .= '</tr></table>';
1.137 raeburn 7715: }
1.279 raeburn 7716: $datatable .= '</td></tr>';
7717: $itemcount ++;
1.137 raeburn 7718: }
7719: }
1.279 raeburn 7720: return ($datatable,$itemcount);
1.137 raeburn 7721: }
7722:
1.275 raeburn 7723: sub print_ssl {
7724: my ($position,$dom,$settings,$rowtotal) = @_;
7725: my ($css_class,$datatable);
7726: my $itemcount = 1;
7727: if ($position eq 'top') {
1.281 raeburn 7728: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7729: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7730: my $same_institution;
7731: if ($intdom ne '') {
7732: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
7733: if (ref($internet_names) eq 'ARRAY') {
7734: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
7735: $same_institution = 1;
7736: }
7737: }
7738: }
1.275 raeburn 7739: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 7740: $datatable = '<tr'.$css_class.'><td colspan="2">';
7741: if ($same_institution) {
7742: my %domservers = &Apache::lonnet::get_servers($dom);
7743: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
7744: } else {
7745: $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.");
7746: }
7747: $datatable .= '</td></tr>';
1.275 raeburn 7748: $itemcount ++;
7749: } else {
7750: my %titles = &ssl_titles();
7751: my (%by_ip,%by_location,@intdoms,@instdoms);
7752: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7753: my @alldoms = &Apache::lonnet::all_domains();
7754: my %serverhomes = %Apache::lonnet::serverhomeIDs;
7755: my @domservers = &Apache::lonnet::get_servers($dom);
7756: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7757: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 7758: if (($position eq 'connto') || ($position eq 'connfrom')) {
7759: my $legacy;
7760: unless (ref($settings) eq 'HASH') {
7761: my $name;
7762: if ($position eq 'connto') {
7763: $name = 'loncAllowInsecure';
7764: } else {
7765: $name = 'londAllowInsecure';
7766: }
7767: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
7768: my @ids=&Apache::lonnet::current_machine_ids();
7769: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
7770: my %what = (
7771: $name => 1,
7772: );
7773: my ($result,$returnhash) =
7774: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
7775: if ($result eq 'ok') {
7776: if (ref($returnhash) eq 'HASH') {
7777: $legacy = $returnhash->{$name};
7778: }
7779: }
7780: } else {
7781: $legacy = $Apache::lonnet::perlvar{$name};
7782: }
7783: }
1.275 raeburn 7784: foreach my $type ('dom','intdom','other') {
7785: my %checked;
7786: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7787: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
7788: '<td class="LC_right_item">';
7789: my $skip;
7790: if ($type eq 'dom') {
7791: unless (keys(%servers) > 1) {
7792: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
7793: $skip = 1;
7794: }
7795: }
7796: if ($type eq 'intdom') {
7797: unless (@instdoms > 1) {
7798: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
7799: $skip = 1;
7800: }
7801: } elsif ($type eq 'other') {
7802: if (keys(%by_location) == 0) {
7803: $datatable .= &mt('Nothing to set here, as there are no other institutions');
7804: $skip = 1;
7805: }
7806: }
7807: unless ($skip) {
7808: $checked{'yes'} = ' checked="checked"';
7809: if (ref($settings) eq 'HASH') {
1.293 raeburn 7810: if (ref($settings->{$position}) eq 'HASH') {
7811: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 7812: $checked{$1} = $checked{'yes'};
7813: delete($checked{'yes'});
7814: }
7815: }
1.293 raeburn 7816: } else {
7817: if ($legacy == 0) {
7818: $checked{'req'} = $checked{'yes'};
7819: delete($checked{'yes'});
7820: }
1.275 raeburn 7821: }
7822: foreach my $option ('no','yes','req') {
7823: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 7824: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 7825: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7826: '</label></span>'.(' 'x2);
7827: }
7828: }
7829: $datatable .= '</td></tr>';
7830: $itemcount ++;
7831: }
7832: } else {
7833: my $prefix = 'replication';
7834: my @types = ('certreq','nocertreq');
1.279 raeburn 7835: if (keys(%by_location) == 0) {
7836: $datatable .= '<tr'.$css_class.'><td>'.
7837: &mt('Nothing to set here, as there are no other institutions').
7838: '</td></tr>';
7839: $itemcount ++;
1.275 raeburn 7840: } else {
1.279 raeburn 7841: ($datatable,$itemcount) =
7842: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 7843: }
7844: }
7845: }
7846: $$rowtotal += $itemcount;
7847: return $datatable;
7848: }
7849:
7850: sub ssl_titles {
7851: return &Apache::lonlocal::texthash (
7852: dom => 'LON-CAPA servers/VMs from same domain',
7853: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
7854: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 7855: connto => 'Connections to other servers',
7856: connfrom => 'Connections from other servers',
1.275 raeburn 7857: replication => 'Replicating content to other institutions',
7858: certreq => 'Client certificate required, but specific domains exempt',
7859: nocertreq => 'No client certificate required, except for specific domains',
7860: no => 'SSL not used',
7861: yes => 'SSL Optional (used if available)',
7862: req => 'SSL Required',
7863: );
1.279 raeburn 7864: }
7865:
7866: sub print_trust {
7867: my ($prefix,$dom,$settings,$rowtotal) = @_;
7868: my ($css_class,$datatable,%checked,%choices);
7869: my (%by_ip,%by_location,@intdoms,@instdoms);
7870: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7871: my $itemcount = 1;
7872: my %titles = &trust_titles();
7873: my @types = ('exc','inc');
7874: if ($prefix eq 'top') {
7875: $prefix = 'content';
7876: } elsif ($prefix eq 'bottom') {
7877: $prefix = 'msg';
7878: }
7879: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
7880: $$rowtotal += $itemcount;
7881: return $datatable;
7882: }
7883:
7884: sub trust_titles {
7885: return &Apache::lonlocal::texthash(
7886: content => "Access to this domain's content by others",
7887: shared => "Access to other domain's content by this domain",
7888: enroll => "Enrollment in this domain's courses by others",
7889: othcoau => "Co-author roles in this domain for others",
7890: coaurem => "Co-author roles for this domain's users elsewhere",
7891: domroles => "Domain roles in this domain assignable to others",
7892: catalog => "Course Catalog for this domain displayed elsewhere",
7893: reqcrs => "Requests for creation of courses in this domain by others",
7894: msg => "Users in other domains can send messages to this domain",
7895: exc => "Allow all, but exclude specific domains",
7896: inc => "Deny all, but include specific domains",
7897: );
1.275 raeburn 7898: }
7899:
1.138 raeburn 7900: sub build_location_hashes {
1.275 raeburn 7901: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 7902: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 7903: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 7904: my %iphost = &Apache::lonnet::get_iphost();
7905: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
7906: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
7907: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
7908: foreach my $id (@{$iphost{$primary_ip}}) {
7909: my $intdom = &Apache::lonnet::internet_dom($id);
7910: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
7911: push(@{$intdoms},$intdom);
7912: }
7913: }
7914: }
7915: foreach my $ip (keys(%iphost)) {
7916: if (ref($iphost{$ip}) eq 'ARRAY') {
7917: foreach my $id (@{$iphost{$ip}}) {
7918: my $location = &Apache::lonnet::internet_dom($id);
7919: if ($location) {
1.275 raeburn 7920: if (grep(/^\Q$location\E$/,@{$intdoms})) {
7921: my $dom = &Apache::lonnet::host_domain($id);
7922: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
7923: push(@{$instdoms},$dom);
7924: }
7925: next;
7926: }
1.138 raeburn 7927: if (ref($by_ip->{$ip}) eq 'ARRAY') {
7928: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
7929: push(@{$by_ip->{$ip}},$location);
7930: }
7931: } else {
7932: $by_ip->{$ip} = [$location];
7933: }
7934: }
7935: }
7936: }
7937: }
7938: foreach my $ip (sort(keys(%{$by_ip}))) {
7939: if (ref($by_ip->{$ip}) eq 'ARRAY') {
7940: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
7941: my $first = $by_ip->{$ip}->[0];
7942: if (ref($by_location->{$first}) eq 'ARRAY') {
7943: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
7944: push(@{$by_location->{$first}},$ip);
7945: }
7946: } else {
7947: $by_location->{$first} = [$ip];
7948: }
7949: }
7950: }
7951: return;
7952: }
7953:
1.145 raeburn 7954: sub current_offloads_to {
7955: my ($dom,$settings,$servers) = @_;
7956: my (%spareid,%otherdomconfigs);
1.152 raeburn 7957: if (ref($servers) eq 'HASH') {
1.145 raeburn 7958: foreach my $lonhost (sort(keys(%{$servers}))) {
7959: my $gotspares;
1.152 raeburn 7960: if (ref($settings) eq 'HASH') {
7961: if (ref($settings->{'spares'}) eq 'HASH') {
7962: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
7963: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
7964: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
7965: $gotspares = 1;
7966: }
1.145 raeburn 7967: }
7968: }
7969: unless ($gotspares) {
7970: my $gotspares;
7971: my $serverhomeID =
7972: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
7973: my $serverhomedom =
7974: &Apache::lonnet::host_domain($serverhomeID);
7975: if ($serverhomedom ne $dom) {
7976: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
7977: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
7978: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
7979: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
7980: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
7981: $gotspares = 1;
7982: }
7983: }
7984: } else {
7985: $otherdomconfigs{$serverhomedom} =
7986: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
7987: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
7988: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
7989: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
7990: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
7991: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
7992: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
7993: $gotspares = 1;
7994: }
7995: }
7996: }
7997: }
7998: }
7999: }
8000: }
8001: unless ($gotspares) {
8002: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
8003: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
8004: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
8005: } else {
8006: my $server_hostname = &Apache::lonnet::hostname($lonhost);
8007: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
8008: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
8009: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
8010: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
8011: } else {
1.150 raeburn 8012: my %what = (
8013: spareid => 1,
8014: );
8015: my ($result,$returnhash) =
8016: &Apache::lonnet::get_remote_globals($lonhost,\%what);
8017: if ($result eq 'ok') {
8018: if (ref($returnhash) eq 'HASH') {
8019: if (ref($returnhash->{'spareid'}) eq 'HASH') {
8020: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
8021: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
8022: }
8023: }
1.145 raeburn 8024: }
8025: }
8026: }
8027: }
8028: }
8029: }
8030: return %spareid;
8031: }
8032:
8033: sub spares_row {
1.371 raeburn 8034: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
8035: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 8036: my $css_class;
8037: my $numinrow = 4;
8038: my $itemcount = 1;
8039: my $datatable;
1.152 raeburn 8040: my %typetitles = &sparestype_titles();
8041: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 8042: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 8043: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
8044: my ($othercontrol,$serverdom);
8045: if ($serverhome ne $server) {
8046: $serverdom = &Apache::lonnet::host_domain($serverhome);
8047: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
8048: } else {
8049: $serverdom = &Apache::lonnet::host_domain($server);
8050: if ($serverdom ne $dom) {
8051: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
8052: }
8053: }
8054: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 8055: my ($checkednow,$checkedoth);
1.261 raeburn 8056: if (ref($curroffloadnow) eq 'HASH') {
8057: if ($curroffloadnow->{$server}) {
8058: $checkednow = ' checked="checked"';
8059: }
8060: }
1.371 raeburn 8061: if (ref($curroffloadoth) eq 'HASH') {
8062: if ($curroffloadoth->{$server}) {
8063: $checkedoth = ' checked="checked"';
8064: }
8065: }
1.145 raeburn 8066: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8067: $datatable .= '<tr'.$css_class.'>
8068: <td rowspan="2">
1.183 bisitz 8069: <span class="LC_nobreak">'.
8070: &mt('[_1] when busy, offloads to:'
1.261 raeburn 8071: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 8072: '<span class="LC_nobreak">'."\n".
1.261 raeburn 8073: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 8074: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 8075: "\n";
1.371 raeburn 8076: if ($other_insts) {
8077: $datatable .= '<br />'.
8078: '<span class="LC_nobreak">'."\n".
8079: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
8080: ' '.&mt('Switch other institutions on next access').'</label></span>'.
8081: "\n";
8082: }
1.145 raeburn 8083: my (%current,%canselect);
1.152 raeburn 8084: my @choices =
8085: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
8086: foreach my $type ('primary','default') {
8087: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 8088: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
8089: my @spares = @{$spareid->{$server}{$type}};
8090: if (@spares > 0) {
1.152 raeburn 8091: if ($othercontrol) {
8092: $current{$type} = join(', ',@spares);
8093: } else {
8094: $current{$type} .= '<table>';
8095: my $numspares = scalar(@spares);
8096: for (my $i=0; $i<@spares; $i++) {
8097: my $rem = $i%($numinrow);
8098: if ($rem == 0) {
8099: if ($i > 0) {
8100: $current{$type} .= '</tr>';
8101: }
8102: $current{$type} .= '<tr>';
1.145 raeburn 8103: }
1.152 raeburn 8104: $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'".');" /> '.
8105: $spareid->{$server}{$type}[$i].
8106: '</label></td>'."\n";
8107: }
8108: my $rem = @spares%($numinrow);
8109: my $colsleft = $numinrow - $rem;
8110: if ($colsleft > 1 ) {
8111: $current{$type} .= '<td colspan="'.$colsleft.
8112: '" class="LC_left_item">'.
8113: ' </td>';
8114: } elsif ($colsleft == 1) {
8115: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 8116: }
1.152 raeburn 8117: $current{$type} .= '</tr></table>';
1.150 raeburn 8118: }
1.145 raeburn 8119: }
8120: }
8121: if ($current{$type} eq '') {
8122: $current{$type} = &mt('None specified');
8123: }
1.152 raeburn 8124: if ($othercontrol) {
8125: if ($type eq 'primary') {
8126: $canselect{$type} = $othercontrol;
8127: }
8128: } else {
8129: $canselect{$type} =
8130: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
8131: '<select name="newspare_'.$type.'_'.$server.'" '.
8132: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
8133: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
8134: if (@choices > 0) {
8135: foreach my $lonhost (@choices) {
8136: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
8137: }
8138: }
8139: $canselect{$type} .= '</select>'."\n";
8140: }
8141: } else {
8142: $current{$type} = &mt('Could not be determined');
8143: if ($type eq 'primary') {
8144: $canselect{$type} = $othercontrol;
8145: }
1.145 raeburn 8146: }
1.152 raeburn 8147: if ($type eq 'default') {
8148: $datatable .= '<tr'.$css_class.'>';
8149: }
8150: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
8151: '<td>'.$current{$type}.'</td>'."\n".
8152: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 8153: }
8154: $itemcount ++;
8155: }
8156: }
8157: $$rowtotal += $itemcount;
8158: return $datatable;
8159: }
8160:
1.152 raeburn 8161: sub possible_newspares {
8162: my ($server,$currspares,$serverhomes,$altids) = @_;
8163: my $serverhostname = &Apache::lonnet::hostname($server);
8164: my %excluded;
8165: if ($serverhostname ne '') {
8166: %excluded = (
8167: $serverhostname => 1,
8168: );
8169: }
8170: if (ref($currspares) eq 'HASH') {
8171: foreach my $type (keys(%{$currspares})) {
8172: if (ref($currspares->{$type}) eq 'ARRAY') {
8173: if (@{$currspares->{$type}} > 0) {
8174: foreach my $curr (@{$currspares->{$type}}) {
8175: my $hostname = &Apache::lonnet::hostname($curr);
8176: $excluded{$hostname} = 1;
8177: }
8178: }
8179: }
8180: }
8181: }
8182: my @choices;
8183: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
8184: if (keys(%{$serverhomes}) > 1) {
8185: foreach my $name (sort(keys(%{$serverhomes}))) {
8186: unless ($excluded{$name}) {
8187: if (exists($altids->{$serverhomes->{$name}})) {
8188: push(@choices,$altids->{$serverhomes->{$name}});
8189: } else {
8190: push(@choices,$serverhomes->{$name});
1.145 raeburn 8191: }
8192: }
8193: }
8194: }
8195: }
1.152 raeburn 8196: return sort(@choices);
1.145 raeburn 8197: }
8198:
1.150 raeburn 8199: sub print_loadbalancing {
8200: my ($dom,$settings,$rowtotal) = @_;
8201: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8202: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8203: my $numinrow = 1;
8204: my $datatable;
8205: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 8206: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 8207: if (ref($settings) eq 'HASH') {
8208: %existing = %{$settings};
8209: }
8210: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
8211: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 8212: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 8213: } else {
8214: return;
8215: }
8216: my ($othertitle,$usertypes,$types) =
8217: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 8218: my $rownum = 8;
1.150 raeburn 8219: if (ref($types) eq 'ARRAY') {
8220: $rownum += scalar(@{$types});
8221: }
1.171 raeburn 8222: my @css_class = ('LC_odd_row','LC_even_row');
8223: my $balnum = 0;
8224: my $islast;
8225: my (@toshow,$disabledtext);
8226: if (keys(%currbalancer) > 0) {
8227: @toshow = sort(keys(%currbalancer));
8228: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
8229: push(@toshow,'');
8230: }
8231: } else {
8232: @toshow = ('');
8233: $disabledtext = &mt('No existing load balancer');
8234: }
8235: foreach my $lonhost (@toshow) {
8236: if ($balnum == scalar(@toshow)-1) {
8237: $islast = 1;
8238: } else {
8239: $islast = 0;
8240: }
8241: my $cssidx = $balnum%2;
8242: my $targets_div_style = 'display: none';
8243: my $disabled_div_style = 'display: block';
8244: my $homedom_div_style = 'display: none';
8245: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 8246: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 8247: '<p>';
8248: if ($lonhost eq '') {
1.210 raeburn 8249: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 8250: if (keys(%currbalancer) > 0) {
8251: $datatable .= &mt('Add balancer:');
8252: } else {
8253: $datatable .= &mt('Enable balancer:');
8254: }
8255: $datatable .= ' '.
8256: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
8257: ' id="loadbalancing_lonhost_'.$balnum.'"'.
8258: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
8259: '<option value="" selected="selected">'.&mt('None').
8260: '</option>'."\n";
8261: foreach my $server (sort(keys(%servers))) {
8262: next if ($currbalancer{$server});
8263: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
8264: }
1.210 raeburn 8265: $datatable .=
1.171 raeburn 8266: '</select>'."\n".
8267: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
8268: } else {
8269: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
8270: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
8271: &mt('Stop balancing').'</label>'.
8272: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
8273: $targets_div_style = 'display: block';
8274: $disabled_div_style = 'display: none';
8275: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
8276: $homedom_div_style = 'display: block';
8277: }
8278: }
1.306 raeburn 8279: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 8280: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
8281: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
8282: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
8283: my ($numspares,@spares) = &count_servers($lonhost,%servers);
8284: my @sparestypes = ('primary','default');
8285: my %typetitles = &sparestype_titles();
1.284 raeburn 8286: my %hostherechecked = (
8287: no => ' checked="checked"',
8288: );
1.342 raeburn 8289: my %balcookiechecked = (
8290: no => ' checked="checked"',
8291: );
1.171 raeburn 8292: foreach my $sparetype (@sparestypes) {
8293: my $targettable;
8294: for (my $i=0; $i<$numspares; $i++) {
8295: my $checked;
8296: if (ref($currtargets{$lonhost}) eq 'HASH') {
8297: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
8298: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
8299: $checked = ' checked="checked"';
8300: }
8301: }
8302: }
8303: my ($chkboxval,$disabled);
8304: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
8305: $chkboxval = $spares[$i];
8306: }
8307: if (exists($currbalancer{$spares[$i]})) {
8308: $disabled = ' disabled="disabled"';
8309: }
1.210 raeburn 8310: $targettable .=
1.253 raeburn 8311: '<td><span class="LC_nobreak"><label>'.
8312: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 8313: $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 8314: '</span></label></span></td>';
1.171 raeburn 8315: my $rem = $i%($numinrow);
8316: if ($rem == 0) {
8317: if (($i > 0) && ($i < $numspares-1)) {
8318: $targettable .= '</tr>';
8319: }
8320: if ($i < $numspares-1) {
8321: $targettable .= '<tr>';
1.150 raeburn 8322: }
8323: }
8324: }
1.171 raeburn 8325: if ($targettable ne '') {
8326: my $rem = $numspares%($numinrow);
8327: my $colsleft = $numinrow - $rem;
8328: if ($colsleft > 1 ) {
8329: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8330: ' </td>';
8331: } elsif ($colsleft == 1) {
8332: $targettable .= '<td class="LC_left_item"> </td>';
8333: }
8334: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
8335: '<table><tr>'.$targettable.'</tr></table><br />';
8336: }
1.284 raeburn 8337: $hostherechecked{$sparetype} = '';
8338: if (ref($currtargets{$lonhost}) eq 'HASH') {
8339: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
8340: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
8341: $hostherechecked{$sparetype} = ' checked="checked"';
8342: $hostherechecked{'no'} = '';
8343: }
8344: }
8345: }
8346: }
1.342 raeburn 8347: if ($currcookies{$lonhost}) {
8348: %balcookiechecked = (
8349: yes => ' checked="checked"',
8350: );
8351: }
1.284 raeburn 8352: $datatable .= &mt('Hosting on balancer itself').'<br />'.
8353: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
8354: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
8355: foreach my $sparetype (@sparestypes) {
8356: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
8357: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
8358: '</i></label><br />';
1.171 raeburn 8359: }
1.342 raeburn 8360: $datatable .= &mt('Use balancer cookie').'<br />'.
8361: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
8362: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
8363: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
8364: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
8365: '</div></td></tr>'.
1.171 raeburn 8366: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
8367: $othertitle,$usertypes,$types,\%servers,
8368: \%currbalancer,$lonhost,
8369: $targets_div_style,$homedom_div_style,
8370: $css_class[$cssidx],$balnum,$islast);
8371: $$rowtotal += $rownum;
8372: $balnum ++;
8373: }
8374: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
8375: return $datatable;
8376: }
8377:
8378: sub get_loadbalancers_config {
1.342 raeburn 8379: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 8380: return unless ((ref($servers) eq 'HASH') &&
8381: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 8382: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
8383: (ref($currcookies) eq 'HASH'));
1.171 raeburn 8384: if (keys(%{$existing}) > 0) {
8385: my $oldlonhost;
8386: foreach my $key (sort(keys(%{$existing}))) {
8387: if ($key eq 'lonhost') {
8388: $oldlonhost = $existing->{'lonhost'};
8389: $currbalancer->{$oldlonhost} = 1;
8390: } elsif ($key eq 'targets') {
8391: if ($oldlonhost) {
8392: $currtargets->{$oldlonhost} = $existing->{'targets'};
8393: }
8394: } elsif ($key eq 'rules') {
8395: if ($oldlonhost) {
8396: $currrules->{$oldlonhost} = $existing->{'rules'};
8397: }
8398: } elsif (ref($existing->{$key}) eq 'HASH') {
8399: $currbalancer->{$key} = 1;
8400: $currtargets->{$key} = $existing->{$key}{'targets'};
8401: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 8402: if ($existing->{$key}{'cookie'}) {
8403: $currcookies->{$key} = 1;
8404: }
1.150 raeburn 8405: }
8406: }
1.171 raeburn 8407: } else {
8408: my ($balancerref,$targetsref) =
8409: &Apache::lonnet::get_lonbalancer_config($servers);
8410: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
8411: foreach my $server (sort(keys(%{$balancerref}))) {
8412: $currbalancer->{$server} = 1;
8413: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 8414: }
8415: }
8416: }
1.171 raeburn 8417: return;
1.150 raeburn 8418: }
8419:
8420: sub loadbalancing_rules {
8421: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 8422: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
8423: $css_class,$balnum,$islast) = @_;
1.150 raeburn 8424: my $output;
1.171 raeburn 8425: my $num = 0;
1.210 raeburn 8426: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 8427: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8428: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8429: foreach my $type (@{$alltypes}) {
1.171 raeburn 8430: $num ++;
1.150 raeburn 8431: my $current;
8432: if (ref($currrules) eq 'HASH') {
8433: $current = $currrules->{$type};
8434: }
1.253 raeburn 8435: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 8436: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 8437: $current = '';
8438: }
8439: }
8440: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 8441: $servers,$currbalancer,$lonhost,$dom,
8442: $targets_div_style,$homedom_div_style,
8443: $css_class,$balnum,$num,$islast);
1.150 raeburn 8444: }
8445: }
8446: return $output;
8447: }
8448:
8449: sub loadbalancing_titles {
8450: my ($dom,$intdom,$usertypes,$types) = @_;
8451: my %othertypes = (
8452: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
8453: '_LC_author' => &mt('Users from [_1] with author role',$dom),
8454: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
8455: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 8456: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
8457: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 8458: );
1.209 raeburn 8459: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 8460: my @available;
1.150 raeburn 8461: if (ref($types) eq 'ARRAY') {
1.302 raeburn 8462: @available = @{$types};
1.150 raeburn 8463: }
1.302 raeburn 8464: unless (grep(/^default$/,@available)) {
8465: push(@available,'default');
8466: }
8467: unshift(@alltypes,@available);
1.150 raeburn 8468: my %titles;
8469: foreach my $type (@alltypes) {
8470: if ($type =~ /^_LC_/) {
8471: $titles{$type} = $othertypes{$type};
8472: } elsif ($type eq 'default') {
8473: $titles{$type} = &mt('All users from [_1]',$dom);
8474: if (ref($types) eq 'ARRAY') {
8475: if (@{$types} > 0) {
8476: $titles{$type} = &mt('Other users from [_1]',$dom);
8477: }
8478: }
8479: } elsif (ref($usertypes) eq 'HASH') {
8480: $titles{$type} = $usertypes->{$type};
8481: }
8482: }
8483: return (\@alltypes,\%othertypes,\%titles);
8484: }
8485:
8486: sub loadbalance_rule_row {
1.171 raeburn 8487: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
8488: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 8489: my @rulenames;
1.150 raeburn 8490: my %ruletitles = &offloadtype_text();
1.209 raeburn 8491: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 8492: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 8493: } else {
1.209 raeburn 8494: @rulenames = ('default','homeserver');
8495: if ($type eq '_LC_external') {
8496: push(@rulenames,'externalbalancer');
8497: } else {
8498: push(@rulenames,'specific');
8499: }
8500: push(@rulenames,'none');
1.150 raeburn 8501: }
8502: my $style = $targets_div_style;
1.253 raeburn 8503: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 8504: $style = $homedom_div_style;
8505: }
1.171 raeburn 8506: my $space;
8507: if ($islast && $num == 1) {
1.317 raeburn 8508: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 8509: }
1.210 raeburn 8510: my $output =
1.306 raeburn 8511: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 8512: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
8513: '<td valaign="top">'.$space.
8514: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 8515: for (my $i=0; $i<@rulenames; $i++) {
8516: my $rule = $rulenames[$i];
8517: my ($checked,$extra);
8518: if ($rulenames[$i] eq 'default') {
8519: $rule = '';
8520: }
8521: if ($rulenames[$i] eq 'specific') {
8522: if (ref($servers) eq 'HASH') {
8523: my $default;
8524: if (($current ne '') && (exists($servers->{$current}))) {
8525: $checked = ' checked="checked"';
8526: }
8527: unless ($checked) {
8528: $default = ' selected="selected"';
8529: }
1.210 raeburn 8530: $extra =
1.171 raeburn 8531: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
8532: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
8533: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
8534: '<option value=""'.$default.'></option>'."\n";
8535: foreach my $server (sort(keys(%{$servers}))) {
8536: if (ref($currbalancer) eq 'HASH') {
8537: next if (exists($currbalancer->{$server}));
8538: }
1.150 raeburn 8539: my $selected;
1.171 raeburn 8540: if ($server eq $current) {
1.150 raeburn 8541: $selected = ' selected="selected"';
8542: }
1.171 raeburn 8543: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 8544: }
8545: $extra .= '</select>';
8546: }
8547: } elsif ($rule eq $current) {
8548: $checked = ' checked="checked"';
8549: }
8550: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 8551: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
8552: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
8553: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 8554: ')"'.$checked.' /> ';
8555: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
8556: $output .= $ruletitles{'particular'};
8557: } else {
8558: $output .= $ruletitles{$rulenames[$i]};
8559: }
8560: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 8561: }
8562: $output .= '</div></td></tr>'."\n";
8563: return $output;
8564: }
8565:
8566: sub offloadtype_text {
8567: my %ruletitles = &Apache::lonlocal::texthash (
8568: 'default' => 'Offloads to default destinations',
8569: 'homeserver' => "Offloads to user's home server",
8570: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
8571: 'specific' => 'Offloads to specific server',
1.161 raeburn 8572: 'none' => 'No offload',
1.209 raeburn 8573: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
8574: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 8575: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 8576: );
8577: return %ruletitles;
8578: }
8579:
8580: sub sparestype_titles {
8581: my %typestitles = &Apache::lonlocal::texthash (
8582: 'primary' => 'primary',
8583: 'default' => 'default',
8584: );
8585: return %typestitles;
8586: }
8587:
1.28 raeburn 8588: sub contact_titles {
8589: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 8590: 'supportemail' => 'Support E-mail address',
8591: 'adminemail' => 'Default Server Admin E-mail address',
8592: 'errormail' => 'Error reports to be e-mailed to',
8593: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 8594: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
8595: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 8596: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
8597: 'requestsmail' => 'E-mail from course requests requiring approval',
8598: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 8599: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 8600: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 8601: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
8602: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 8603: 'errorweights' => 'Weights used to compute error count',
8604: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 8605: );
8606: my %short_titles = &Apache::lonlocal::texthash (
8607: adminemail => 'Admin E-mail address',
8608: supportemail => 'Support E-mail',
8609: );
8610: return (\%titles,\%short_titles);
8611: }
8612:
1.286 raeburn 8613: sub helpform_fields {
8614: my %titles = &Apache::lonlocal::texthash (
8615: 'username' => 'Name',
8616: 'user' => 'Username/domain',
8617: 'phone' => 'Phone',
8618: 'cc' => 'Cc e-mail',
8619: 'course' => 'Course Details',
8620: 'section' => 'Sections',
1.289 raeburn 8621: 'screenshot' => 'File upload',
1.286 raeburn 8622: );
8623: my @fields = ('username','phone','user','course','section','cc','screenshot');
8624: my %possoptions = (
8625: username => ['yes','no','req'],
1.289 raeburn 8626: phone => ['yes','no','req'],
1.286 raeburn 8627: user => ['yes','no'],
1.289 raeburn 8628: cc => ['yes','no'],
1.286 raeburn 8629: course => ['yes','no'],
8630: section => ['yes','no'],
8631: screenshot => ['yes','no'],
8632: );
8633: my %fieldoptions = &Apache::lonlocal::texthash (
8634: 'yes' => 'Optional',
8635: 'req' => 'Required',
8636: 'no' => "Not shown",
8637: );
8638: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
8639: }
8640:
1.72 raeburn 8641: sub tool_titles {
8642: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 8643: aboutme => 'Personal web page',
1.86 raeburn 8644: blog => 'Blog',
1.162 raeburn 8645: webdav => 'WebDAV',
1.86 raeburn 8646: portfolio => 'Portfolio',
1.88 bisitz 8647: official => 'Official courses (with institutional codes)',
8648: unofficial => 'Unofficial courses',
1.98 raeburn 8649: community => 'Communities',
1.216 raeburn 8650: textbook => 'Textbook courses',
1.271 raeburn 8651: placement => 'Placement tests',
1.86 raeburn 8652: );
1.72 raeburn 8653: return %titles;
8654: }
8655:
1.101 raeburn 8656: sub courserequest_titles {
8657: my %titles = &Apache::lonlocal::texthash (
8658: official => 'Official',
8659: unofficial => 'Unofficial',
8660: community => 'Communities',
1.216 raeburn 8661: textbook => 'Textbook',
1.271 raeburn 8662: placement => 'Placement tests',
1.325 raeburn 8663: lti => 'LTI Provider',
1.101 raeburn 8664: norequest => 'Not allowed',
1.325 raeburn 8665: approval => 'Approval by DC',
1.101 raeburn 8666: validate => 'With validation',
8667: autolimit => 'Numerical limit',
1.103 raeburn 8668: unlimited => '(blank for unlimited)',
1.101 raeburn 8669: );
8670: return %titles;
8671: }
8672:
1.163 raeburn 8673: sub authorrequest_titles {
8674: my %titles = &Apache::lonlocal::texthash (
8675: norequest => 'Not allowed',
8676: approval => 'Approval by Dom. Coord.',
8677: automatic => 'Automatic approval',
8678: );
8679: return %titles;
1.210 raeburn 8680: }
1.163 raeburn 8681:
1.101 raeburn 8682: sub courserequest_conditions {
8683: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 8684: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 8685: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 8686: );
8687: return %conditions;
8688: }
8689:
8690:
1.27 raeburn 8691: sub print_usercreation {
1.30 raeburn 8692: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 8693: my $numinrow = 4;
1.28 raeburn 8694: my $datatable;
8695: if ($position eq 'top') {
1.30 raeburn 8696: $$rowtotal ++;
1.34 raeburn 8697: my $rowcount = 0;
1.32 raeburn 8698: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 8699: if (ref($rules) eq 'HASH') {
8700: if (keys(%{$rules}) > 0) {
1.32 raeburn 8701: $datatable .= &user_formats_row('username',$settings,$rules,
8702: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 8703: $$rowtotal ++;
1.32 raeburn 8704: $rowcount ++;
8705: }
8706: }
8707: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
8708: if (ref($idrules) eq 'HASH') {
8709: if (keys(%{$idrules}) > 0) {
8710: $datatable .= &user_formats_row('id',$settings,$idrules,
8711: $idruleorder,$numinrow,$rowcount);
8712: $$rowtotal ++;
8713: $rowcount ++;
1.28 raeburn 8714: }
8715: }
1.39 raeburn 8716: if ($rowcount == 0) {
8717: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
8718: $$rowtotal ++;
8719: $rowcount ++;
8720: }
1.34 raeburn 8721: } elsif ($position eq 'middle') {
1.224 raeburn 8722: my @creators = ('author','course','requestcrs');
1.37 raeburn 8723: my ($rules,$ruleorder) =
8724: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 8725: my %lt = &usercreation_types();
8726: my %checked;
8727: if (ref($settings) eq 'HASH') {
8728: if (ref($settings->{'cancreate'}) eq 'HASH') {
8729: foreach my $item (@creators) {
8730: $checked{$item} = $settings->{'cancreate'}{$item};
8731: }
8732: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
8733: foreach my $item (@creators) {
8734: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
8735: $checked{$item} = 'none';
8736: }
8737: }
8738: }
8739: }
8740: my $rownum = 0;
8741: foreach my $item (@creators) {
8742: $rownum ++;
1.224 raeburn 8743: if ($checked{$item} eq '') {
8744: $checked{$item} = 'any';
1.34 raeburn 8745: }
8746: my $css_class;
8747: if ($rownum%2) {
8748: $css_class = '';
8749: } else {
8750: $css_class = ' class="LC_odd_row" ';
8751: }
8752: $datatable .= '<tr'.$css_class.'>'.
8753: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 8754: '</span></td><td style="text-align: right">';
1.224 raeburn 8755: my @options = ('any');
8756: if (ref($rules) eq 'HASH') {
8757: if (keys(%{$rules}) > 0) {
8758: push(@options,('official','unofficial'));
1.37 raeburn 8759: }
8760: }
1.224 raeburn 8761: push(@options,'none');
1.37 raeburn 8762: foreach my $option (@options) {
1.50 raeburn 8763: my $type = 'radio';
1.34 raeburn 8764: my $check = ' ';
1.224 raeburn 8765: if ($checked{$item} eq $option) {
8766: $check = ' checked="checked" ';
1.34 raeburn 8767: }
8768: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 8769: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 8770: $item.'" value="'.$option.'"'.$check.'/> '.
8771: $lt{$option}.'</label> </span>';
8772: }
8773: $datatable .= '</td></tr>';
8774: }
1.28 raeburn 8775: } else {
8776: my @contexts = ('author','course','domain');
1.325 raeburn 8777: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 8778: my %checked;
8779: if (ref($settings) eq 'HASH') {
8780: if (ref($settings->{'authtypes'}) eq 'HASH') {
8781: foreach my $item (@contexts) {
8782: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
8783: foreach my $auth (@authtypes) {
8784: if ($settings->{'authtypes'}{$item}{$auth}) {
8785: $checked{$item}{$auth} = ' checked="checked" ';
8786: }
8787: }
8788: }
8789: }
1.27 raeburn 8790: }
1.35 raeburn 8791: } else {
8792: foreach my $item (@contexts) {
1.36 raeburn 8793: foreach my $auth (@authtypes) {
1.35 raeburn 8794: $checked{$item}{$auth} = ' checked="checked" ';
8795: }
8796: }
1.27 raeburn 8797: }
1.28 raeburn 8798: my %title = &context_names();
8799: my %authname = &authtype_names();
8800: my $rownum = 0;
8801: my $css_class;
8802: foreach my $item (@contexts) {
8803: if ($rownum%2) {
8804: $css_class = '';
8805: } else {
8806: $css_class = ' class="LC_odd_row" ';
8807: }
1.30 raeburn 8808: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 8809: '<td>'.$title{$item}.
8810: '</td><td class="LC_left_item">'.
8811: '<span class="LC_nobreak">';
8812: foreach my $auth (@authtypes) {
8813: $datatable .= '<label>'.
8814: '<input type="checkbox" name="'.$item.'_auth" '.
8815: $checked{$item}{$auth}.' value="'.$auth.'" />'.
8816: $authname{$auth}.'</label> ';
8817: }
8818: $datatable .= '</span></td></tr>';
8819: $rownum ++;
1.27 raeburn 8820: }
1.30 raeburn 8821: $$rowtotal += $rownum;
1.27 raeburn 8822: }
8823: return $datatable;
8824: }
8825:
1.224 raeburn 8826: sub print_selfcreation {
8827: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 8828: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
8829: $emaildomain,$datatable);
1.224 raeburn 8830: if (ref($settings) eq 'HASH') {
8831: if (ref($settings->{'cancreate'}) eq 'HASH') {
8832: $createsettings = $settings->{'cancreate'};
1.236 raeburn 8833: if (ref($createsettings) eq 'HASH') {
8834: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
8835: @selfcreate = @{$createsettings->{'selfcreate'}};
8836: } elsif ($createsettings->{'selfcreate'} ne '') {
8837: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
8838: @selfcreate = ('email','login','sso');
8839: } elsif ($createsettings->{'selfcreate'} ne 'none') {
8840: @selfcreate = ($createsettings->{'selfcreate'});
8841: }
8842: }
8843: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
8844: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 8845: }
1.305 raeburn 8846: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
8847: $emailoptions = $createsettings->{'emailoptions'};
8848: }
1.303 raeburn 8849: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
8850: $emailverified = $createsettings->{'emailverified'};
8851: }
8852: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
8853: $emaildomain = $createsettings->{'emaildomain'};
8854: }
1.224 raeburn 8855: }
8856: }
8857: }
8858: my %radiohash;
8859: my $numinrow = 4;
8860: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 8861: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 8862: if ($position eq 'top') {
8863: my %choices = &Apache::lonlocal::texthash (
8864: cancreate_login => 'Institutional Login',
8865: cancreate_sso => 'Institutional Single Sign On',
8866: );
8867: my @toggles = sort(keys(%choices));
8868: my %defaultchecked = (
8869: 'cancreate_login' => 'off',
8870: 'cancreate_sso' => 'off',
8871: );
1.228 raeburn 8872: my ($onclick,$itemcount);
1.224 raeburn 8873: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
8874: \%choices,$itemcount,$onclick);
1.228 raeburn 8875: $$rowtotal += $itemcount;
8876:
1.224 raeburn 8877: if (ref($usertypes) eq 'HASH') {
8878: if (keys(%{$usertypes}) > 0) {
8879: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
8880: $dom,$numinrow,$othertitle,
1.305 raeburn 8881: 'statustocreate',$rowtotal);
1.224 raeburn 8882: $$rowtotal ++;
8883: }
8884: }
1.240 raeburn 8885: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
8886: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8887: $fieldtitles{'inststatus'} = &mt('Institutional status');
8888: my $rem;
8889: my $numperrow = 2;
8890: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
8891: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 8892: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 8893: '<td class="LC_left_item">'."\n".
1.334 raeburn 8894: '<table>'."\n";
1.240 raeburn 8895: for (my $i=0; $i<@fields; $i++) {
8896: $rem = $i%($numperrow);
8897: if ($rem == 0) {
8898: if ($i > 0) {
8899: $datatable .= '</tr>';
8900: }
8901: $datatable .= '<tr>';
8902: }
8903: my $currval;
1.248 raeburn 8904: if (ref($createsettings) eq 'HASH') {
8905: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
8906: $currval = $createsettings->{'shibenv'}{$fields[$i]};
8907: }
1.240 raeburn 8908: }
8909: $datatable .= '<td class="LC_left_item">'.
8910: '<span class="LC_nobreak">'.
8911: '<input type="text" name="shibenv_'.$fields[$i].'" '.
8912: 'value="'.$currval.'" size="10" /> '.
8913: $fieldtitles{$fields[$i]}.'</span></td>';
8914: }
8915: my $colsleft = $numperrow - $rem;
8916: if ($colsleft > 1 ) {
8917: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8918: ' </td>';
8919: } elsif ($colsleft == 1) {
8920: $datatable .= '<td class="LC_left_item"> </td>';
8921: }
8922: $datatable .= '</tr></table></td></tr>';
8923: $$rowtotal ++;
1.224 raeburn 8924: } elsif ($position eq 'middle') {
8925: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 8926: my @posstypes;
1.224 raeburn 8927: if (ref($types) eq 'ARRAY') {
1.302 raeburn 8928: @posstypes = @{$types};
8929: }
8930: unless (grep(/^default$/,@posstypes)) {
8931: push(@posstypes,'default');
8932: }
8933: my %usertypeshash;
8934: if (ref($usertypes) eq 'HASH') {
8935: %usertypeshash = %{$usertypes};
8936: }
8937: $usertypeshash{'default'} = $othertitle;
8938: foreach my $status (@posstypes) {
8939: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
8940: $numinrow,$$rowtotal,\%usertypeshash);
8941: $$rowtotal ++;
1.224 raeburn 8942: }
8943: } else {
1.236 raeburn 8944: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 8945: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 8946: );
8947: my @toggles = sort(keys(%choices));
8948: my %defaultchecked = (
8949: 'cancreate_email' => 'off',
8950: );
1.305 raeburn 8951: my $customclass = 'LC_selfcreate_email';
8952: my $classprefix = 'LC_canmodify_emailusername_';
8953: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 8954: my $display = 'none';
1.305 raeburn 8955: my $rowstyle = 'display:none';
1.236 raeburn 8956: if (grep(/^\Qemail\E$/,@selfcreate)) {
8957: $display = 'block';
1.305 raeburn 8958: $rowstyle = 'display:table-row';
1.236 raeburn 8959: }
1.305 raeburn 8960: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
8961: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
8962: \%choices,$$rowtotal,$onclick);
8963: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
8964: $rowstyle);
8965: $$rowtotal ++;
8966: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
8967: $rowstyle);
8968: $$rowtotal ++;
8969: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 8970: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 8971: my ($emailrules,$emailruleorder) =
8972: &Apache::lonnet::inst_userrules($dom,'email');
8973: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8974: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8975: if (ref($types) eq 'ARRAY') {
8976: @posstypes = @{$types};
8977: }
8978: if (@posstypes) {
8979: unless (grep(/^default$/,@posstypes)) {
8980: push(@posstypes,'default');
1.302 raeburn 8981: }
8982: if (ref($usertypes) eq 'HASH') {
8983: %usertypeshash = %{$usertypes};
8984: }
1.305 raeburn 8985: my $currassign;
8986: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
8987: $currassign = {
8988: selfassign => $domdefaults{'inststatusguest'},
8989: };
8990: @ordered = @{$domdefaults{'inststatusguest'}};
8991: } else {
8992: $currassign = { selfassign => [] };
8993: }
8994: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
8995: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
8996: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
8997: $numinrow,$othertitle,'selfassign',
8998: $rowtotal,$onclicktypes,$customclass,
8999: $rowstyle);
9000: $$rowtotal ++;
1.302 raeburn 9001: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 9002: foreach my $status (@posstypes) {
9003: my $css_class;
9004: if ($$rowtotal%2) {
9005: $css_class = 'LC_odd_row ';
9006: }
9007: $css_class .= $customclass;
9008: my $rowid = $optionsprefix.$status;
9009: my $hidden = 1;
9010: my $currstyle = 'display:none';
9011: if (grep(/^\Q$status\E$/,@ordered)) {
9012: $currstyle = $rowstyle;
9013: $hidden = 0;
9014: }
9015: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
9016: $emailrules,$emailruleorder,$settings,$status,$rowid,
9017: $usertypeshash{$status},$css_class,$currstyle,$intdom);
9018: unless ($hidden) {
9019: $$rowtotal ++;
9020: }
1.224 raeburn 9021: }
1.302 raeburn 9022: } else {
1.305 raeburn 9023: my $css_class;
9024: if ($$rowtotal%2) {
9025: $css_class = 'LC_odd_row ';
9026: }
9027: $css_class .= $customclass;
1.302 raeburn 9028: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 9029: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
9030: $emailrules,$emailruleorder,$settings,'default','',
9031: $othertitle,$css_class,$rowstyle,$intdom);
9032: $$rowtotal ++;
1.224 raeburn 9033: }
9034: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 9035: $numinrow = 1;
1.305 raeburn 9036: if (@posstypes) {
9037: foreach my $status (@posstypes) {
9038: my $rowid = $classprefix.$status;
9039: my $datarowstyle = 'display:none';
9040: if (grep(/^\Q$status\E$/,@ordered)) {
9041: $datarowstyle = $rowstyle;
9042: }
9043: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
9044: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
9045: $infotitles,$rowid,$customclass,$datarowstyle);
9046: unless ($datarowstyle eq 'display:none') {
9047: $$rowtotal ++;
9048: }
1.224 raeburn 9049: }
1.305 raeburn 9050: } else {
9051: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
9052: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
9053: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 9054: }
9055: }
9056: return $datatable;
9057: }
9058:
1.305 raeburn 9059: sub selfcreate_javascript {
9060: return <<"ENDSCRIPT";
9061:
9062: <script type="text/javascript">
9063: // <![CDATA[
9064:
9065: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
9066: var x = document.getElementsByClassName(target);
9067: var insttypes = 0;
9068: var insttypeRegExp = new RegExp(prefix);
9069: if ((x.length != undefined) && (x.length > 0)) {
9070: if (form.elements[radio].length != undefined) {
9071: for (var i=0; i<form.elements[radio].length; i++) {
9072: if (form.elements[radio][i].checked) {
9073: if (form.elements[radio][i].value == 1) {
9074: for (var j=0; j<x.length; j++) {
9075: if (x[j].id == 'undefined') {
9076: x[j].style.display = 'table-row';
9077: } else if (insttypeRegExp.test(x[j].id)) {
9078: insttypes ++;
9079: } else {
9080: x[j].style.display = 'table-row';
9081: }
9082: }
9083: } else {
9084: for (var j=0; j<x.length; j++) {
9085: x[j].style.display = 'none';
9086: }
1.236 raeburn 9087: }
1.305 raeburn 9088: break;
9089: }
9090: }
9091: if (insttypes > 0) {
9092: toggleDataRow(form,checkbox,target,altprefix);
9093: toggleDataRow(form,checkbox,target,prefix,1);
9094: }
9095: }
9096: }
9097: return;
9098: }
9099:
9100: function toggleDataRow(form,checkbox,target,prefix,docount) {
9101: if (form.elements[checkbox].length != undefined) {
9102: var count = 0;
9103: if (docount) {
9104: for (var i=0; i<form.elements[checkbox].length; i++) {
9105: if (form.elements[checkbox][i].checked) {
9106: count ++;
1.236 raeburn 9107: }
1.305 raeburn 9108: }
9109: }
9110: for (var i=0; i<form.elements[checkbox].length; i++) {
9111: var type = form.elements[checkbox][i].value;
9112: if (document.getElementById(prefix+type)) {
9113: if (form.elements[checkbox][i].checked) {
9114: document.getElementById(prefix+type).style.display = 'table-row';
9115: if (count % 2 == 1) {
9116: document.getElementById(prefix+type).className = target+' LC_odd_row';
9117: } else {
9118: document.getElementById(prefix+type).className = target;
1.236 raeburn 9119: }
1.305 raeburn 9120: count ++;
1.236 raeburn 9121: } else {
1.305 raeburn 9122: document.getElementById(prefix+type).style.display = 'none';
9123: }
9124: }
9125: }
9126: }
9127: return;
9128: }
9129:
9130: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
9131: var caller = radio+'_'+status;
9132: if (form.elements[caller].length != undefined) {
9133: for (var i=0; i<form.elements[caller].length; i++) {
9134: if (form.elements[caller][i].checked) {
9135: if (document.getElementById(altprefix+'_inst_'+status)) {
9136: var curr = form.elements[caller][i].value;
9137: if (prefix) {
9138: document.getElementById(prefix+'_'+status).style.display = 'none';
9139: }
9140: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
9141: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
9142: if (curr == 'custom') {
9143: if (prefix) {
9144: document.getElementById(prefix+'_'+status).style.display = 'inline';
9145: }
9146: } else if (curr == 'inst') {
9147: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
9148: } else if (curr == 'noninst') {
9149: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 9150: }
1.305 raeburn 9151: break;
1.236 raeburn 9152: }
9153: }
9154: }
9155: }
9156: }
9157:
1.305 raeburn 9158: // ]]>
9159: </script>
9160:
9161: ENDSCRIPT
9162: }
9163:
9164: sub noninst_users {
9165: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
9166: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
9167: my $class = 'LC_left_item';
9168: if ($css_class) {
9169: $css_class = ' class="'.$css_class.'"';
9170: }
9171: if ($rowid) {
9172: $rowid = ' id="'.$rowid.'"';
9173: }
9174: if ($rowstyle) {
9175: $rowstyle = ' style="'.$rowstyle.'"';
9176: }
9177: my ($output,$description);
9178: if ($type eq 'default') {
9179: $description = &mt('Requests for: [_1]',$typetitle);
9180: } else {
9181: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
9182: }
9183: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
9184: "<td>$description</td>\n".
9185: '<td class="'.$class.'" colspan="2">'.
9186: '<table><tr>';
9187: my %headers = &Apache::lonlocal::texthash(
9188: approve => 'Processing',
9189: email => 'E-mail',
9190: username => 'Username',
9191: );
9192: foreach my $item ('approve','email','username') {
9193: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 9194: }
1.305 raeburn 9195: $output .= '</tr><tr>';
9196: foreach my $item ('approve','email','username') {
1.306 raeburn 9197: $output .= '<td style="vertical-align: top">';
1.305 raeburn 9198: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
9199: if ($item eq 'approve') {
9200: %choices = &Apache::lonlocal::texthash (
9201: automatic => 'Automatically approved',
9202: approval => 'Queued for approval',
9203: );
9204: @options = ('automatic','approval');
9205: $hashref = $processing;
9206: $defoption = 'automatic';
9207: $name = 'cancreate_emailprocess_'.$type;
9208: } elsif ($item eq 'email') {
9209: %choices = &Apache::lonlocal::texthash (
9210: any => 'Any e-mail',
9211: inst => 'Institutional only',
9212: noninst => 'Non-institutional only',
9213: custom => 'Custom restrictions',
9214: );
9215: @options = ('any','inst','noninst');
9216: my $showcustom;
9217: if (ref($emailrules) eq 'HASH') {
9218: if (keys(%{$emailrules}) > 0) {
9219: push(@options,'custom');
9220: $showcustom = 'cancreate_emailrule';
9221: if (ref($settings) eq 'HASH') {
9222: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
9223: foreach my $rule (@{$settings->{'email_rule'}}) {
9224: if (exists($emailrules->{$rule})) {
9225: $hascustom ++;
9226: }
9227: }
9228: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
9229: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
9230: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
9231: if (exists($emailrules->{$rule})) {
9232: $hascustom ++;
9233: }
9234: }
9235: }
9236: }
9237: }
9238: }
9239: }
9240: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
9241: "'cancreate_emaildomain','$type'".');"';
9242: $hashref = $emailoptions;
9243: $defoption = 'any';
9244: $name = 'cancreate_emailoptions_'.$type;
9245: } elsif ($item eq 'username') {
9246: %choices = &Apache::lonlocal::texthash (
9247: all => 'Same as e-mail',
9248: first => 'Omit @domain',
9249: free => 'Free to choose',
9250: );
9251: @options = ('all','first','free');
9252: $hashref = $emailverified;
9253: $defoption = 'all';
9254: $name = 'cancreate_usernameoptions_'.$type;
9255: }
9256: foreach my $option (@options) {
9257: my $checked;
9258: if (ref($hashref) eq 'HASH') {
9259: if ($type eq '') {
9260: if (!exists($hashref->{'default'})) {
9261: if ($option eq $defoption) {
9262: $checked = ' checked="checked"';
9263: }
9264: } else {
9265: if ($hashref->{'default'} eq $option) {
9266: $checked = ' checked="checked"';
9267: }
1.303 raeburn 9268: }
9269: } else {
1.305 raeburn 9270: if (!exists($hashref->{$type})) {
9271: if ($option eq $defoption) {
9272: $checked = ' checked="checked"';
9273: }
9274: } else {
9275: if ($hashref->{$type} eq $option) {
9276: $checked = ' checked="checked"';
9277: }
1.303 raeburn 9278: }
9279: }
1.305 raeburn 9280: } elsif (($item eq 'email') && ($hascustom)) {
9281: if ($option eq 'custom') {
9282: $checked = ' checked="checked"';
9283: }
9284: } elsif ($option eq $defoption) {
9285: $checked = ' checked="checked"';
9286: }
9287: $output .= '<span class="LC_nobreak"><label>'.
9288: '<input type="radio" name="'.$name.'"'.
9289: $checked.' value="'.$option.'"'.$onclick.' />'.
9290: $choices{$option}.'</label></span><br />';
9291: if ($item eq 'email') {
9292: if ($option eq 'custom') {
9293: my $id = 'cancreate_emailrule_'.$type;
9294: my $display = 'none';
9295: if ($checked) {
9296: $display = 'inline';
1.303 raeburn 9297: }
1.305 raeburn 9298: my $numinrow = 2;
9299: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
9300: '<legend>'.&mt('Disallow').'</legend><table>'.
9301: &user_formats_row('email',$settings,$emailrules,
9302: $emailruleorder,$numinrow,'',$type);
9303: '</table></fieldset>';
9304: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
9305: my %text = &Apache::lonlocal::texthash (
9306: inst => 'must end:',
9307: noninst => 'cannot end:',
9308: );
9309: my $value;
9310: if (ref($emaildomain) eq 'HASH') {
9311: if (ref($emaildomain->{$type}) eq 'HASH') {
9312: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 9313: }
9314: }
1.305 raeburn 9315: if ($value eq '') {
9316: $value = '@'.$intdom;
9317: }
9318: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
9319: my $display = 'none';
9320: if ($checked) {
9321: $display = 'inline';
9322: }
9323: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
9324: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
9325: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
9326: '</div>';
1.303 raeburn 9327: }
9328: }
9329: }
1.305 raeburn 9330: $output .= '</td>'."\n";
1.303 raeburn 9331: }
1.305 raeburn 9332: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 9333: return $output;
9334: }
9335:
1.165 raeburn 9336: sub captcha_choice {
1.305 raeburn 9337: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 9338: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
9339: $vertext,$currver);
1.165 raeburn 9340: my %lt = &captcha_phrases();
9341: $keyentry = 'hidden';
1.354 raeburn 9342: my $colspan=2;
1.165 raeburn 9343: if ($context eq 'cancreate') {
1.224 raeburn 9344: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 9345: } elsif ($context eq 'login') {
9346: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 9347: } elsif ($context eq 'passwords') {
9348: $rowname = &mt('"Forgot Password" CAPTCHA validation');
9349: $colspan=1;
1.165 raeburn 9350: }
9351: if (ref($settings) eq 'HASH') {
9352: if ($settings->{'captcha'}) {
9353: $checked{$settings->{'captcha'}} = ' checked="checked"';
9354: } else {
9355: $checked{'original'} = ' checked="checked"';
9356: }
9357: if ($settings->{'captcha'} eq 'recaptcha') {
9358: $pubtext = $lt{'pub'};
9359: $privtext = $lt{'priv'};
9360: $keyentry = 'text';
1.269 raeburn 9361: $vertext = $lt{'ver'};
9362: $currver = $settings->{'recaptchaversion'};
9363: if ($currver ne '2') {
9364: $currver = 1;
9365: }
1.165 raeburn 9366: }
9367: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
9368: $currpub = $settings->{'recaptchakeys'}{'public'};
9369: $currpriv = $settings->{'recaptchakeys'}{'private'};
9370: }
9371: } else {
9372: $checked{'original'} = ' checked="checked"';
9373: }
1.305 raeburn 9374: my $css_class;
9375: if ($itemcount%2) {
9376: $css_class = 'LC_odd_row';
9377: }
9378: if ($customcss) {
9379: $css_class .= " $customcss";
9380: }
9381: $css_class =~ s/^\s+//;
9382: if ($css_class) {
9383: $css_class = ' class="'.$css_class.'"';
9384: }
9385: if ($rowstyle) {
9386: $css_class .= ' style="'.$rowstyle.'"';
9387: }
1.169 raeburn 9388: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 9389: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 9390: '<table><tr><td>'."\n";
9391: foreach my $option ('original','recaptcha','notused') {
9392: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
9393: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
9394: $lt{$option}.'</label></span>';
9395: unless ($option eq 'notused') {
9396: $output .= (' 'x2)."\n";
9397: }
9398: }
9399: #
9400: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
9401: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 9402: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 9403: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 9404: #
1.165 raeburn 9405: $output .= '</td></tr>'."\n".
1.305 raeburn 9406: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 9407: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
9408: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
9409: $currpub.'" size="40" /></span><br />'."\n".
9410: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
9411: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 9412: $currpriv.'" size="40" /></span><br />'.
9413: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
9414: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
9415: $currver.'" size="3" /></span><br />'.
9416: '</td></tr></table>'."\n".
1.165 raeburn 9417: '</td></tr>';
9418: return $output;
9419: }
9420:
1.32 raeburn 9421: sub user_formats_row {
1.305 raeburn 9422: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 9423: my $output;
9424: my %text = (
9425: 'username' => 'new usernames',
9426: 'id' => 'IDs',
9427: );
1.305 raeburn 9428: unless ($type eq 'email') {
9429: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
9430: $output = '<tr '.$css_class.'>'.
9431: '<td><span class="LC_nobreak">'.
9432: &mt("Format rules to check for $text{$type}: ").
9433: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 9434: }
1.27 raeburn 9435: my $rem;
9436: if (ref($ruleorder) eq 'ARRAY') {
9437: for (my $i=0; $i<@{$ruleorder}; $i++) {
9438: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
9439: my $rem = $i%($numinrow);
9440: if ($rem == 0) {
9441: if ($i > 0) {
9442: $output .= '</tr>';
9443: }
9444: $output .= '<tr>';
9445: }
9446: my $check = ' ';
1.39 raeburn 9447: if (ref($settings) eq 'HASH') {
9448: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
9449: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
9450: $check = ' checked="checked" ';
9451: }
1.305 raeburn 9452: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
9453: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
9454: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
9455: $check = ' checked="checked" ';
9456: }
9457: }
1.27 raeburn 9458: }
9459: }
1.305 raeburn 9460: my $name = $type.'_rule';
9461: if ($type eq 'email') {
9462: $name .= '_'.$status;
9463: }
1.27 raeburn 9464: $output .= '<td class="LC_left_item">'.
9465: '<span class="LC_nobreak"><label>'.
1.311 raeburn 9466: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 9467: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
9468: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
9469: }
9470: }
9471: $rem = @{$ruleorder}%($numinrow);
9472: }
1.305 raeburn 9473: my $colsleft;
9474: if ($rem) {
9475: $colsleft = $numinrow - $rem;
9476: }
1.27 raeburn 9477: if ($colsleft > 1 ) {
9478: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9479: ' </td>';
9480: } elsif ($colsleft == 1) {
9481: $output .= '<td class="LC_left_item"> </td>';
9482: }
1.305 raeburn 9483: $output .= '</tr></table>';
9484: unless ($type eq 'email') {
9485: $output .= '</td></tr>';
9486: }
1.27 raeburn 9487: return $output;
9488: }
9489:
1.34 raeburn 9490: sub usercreation_types {
9491: my %lt = &Apache::lonlocal::texthash (
9492: author => 'When adding a co-author',
9493: course => 'When adding a user to a course',
1.100 raeburn 9494: requestcrs => 'When requesting a course',
1.34 raeburn 9495: any => 'Any',
9496: official => 'Institutional only ',
9497: unofficial => 'Non-institutional only',
9498: none => 'None',
9499: );
9500: return %lt;
1.48 raeburn 9501: }
1.34 raeburn 9502:
1.224 raeburn 9503: sub selfcreation_types {
9504: my %lt = &Apache::lonlocal::texthash (
9505: selfcreate => 'User creates own account',
9506: any => 'Any',
9507: official => 'Institutional only ',
9508: unofficial => 'Non-institutional only',
9509: email => 'E-mail address',
9510: login => 'Institutional Login',
9511: sso => 'SSO',
9512: );
9513: }
9514:
1.28 raeburn 9515: sub authtype_names {
9516: my %lt = &Apache::lonlocal::texthash(
9517: int => 'Internal',
9518: krb4 => 'Kerberos 4',
9519: krb5 => 'Kerberos 5',
9520: loc => 'Local',
1.325 raeburn 9521: lti => 'LTI',
1.28 raeburn 9522: );
9523: return %lt;
9524: }
9525:
9526: sub context_names {
9527: my %context_title = &Apache::lonlocal::texthash(
9528: author => 'Creating users when an Author',
9529: course => 'Creating users when in a course',
9530: domain => 'Creating users when a Domain Coordinator',
9531: );
9532: return %context_title;
9533: }
9534:
1.33 raeburn 9535: sub print_usermodification {
9536: my ($position,$dom,$settings,$rowtotal) = @_;
9537: my $numinrow = 4;
9538: my ($context,$datatable,$rowcount);
9539: if ($position eq 'top') {
9540: $rowcount = 0;
9541: $context = 'author';
9542: foreach my $role ('ca','aa') {
9543: $datatable .= &modifiable_userdata_row($context,$role,$settings,
9544: $numinrow,$rowcount);
9545: $$rowtotal ++;
9546: $rowcount ++;
9547: }
1.230 raeburn 9548: } elsif ($position eq 'bottom') {
1.33 raeburn 9549: $context = 'course';
9550: $rowcount = 0;
9551: foreach my $role ('st','ep','ta','in','cr') {
9552: $datatable .= &modifiable_userdata_row($context,$role,$settings,
9553: $numinrow,$rowcount);
9554: $$rowtotal ++;
9555: $rowcount ++;
9556: }
9557: }
9558: return $datatable;
9559: }
9560:
1.43 raeburn 9561: sub print_defaults {
1.236 raeburn 9562: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 9563: my $rownum = 0;
1.294 raeburn 9564: my ($datatable,$css_class,$titles);
9565: unless ($position eq 'bottom') {
9566: $titles = &defaults_titles($dom);
9567: }
1.236 raeburn 9568: if ($position eq 'top') {
9569: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
9570: 'datelocale_def','portal_def');
9571: my %defaults;
9572: if (ref($settings) eq 'HASH') {
9573: %defaults = %{$settings};
1.43 raeburn 9574: } else {
1.236 raeburn 9575: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9576: foreach my $item (@items) {
9577: $defaults{$item} = $domdefaults{$item};
9578: }
1.43 raeburn 9579: }
1.236 raeburn 9580: foreach my $item (@items) {
9581: if ($rownum%2) {
9582: $css_class = '';
9583: } else {
9584: $css_class = ' class="LC_odd_row" ';
9585: }
9586: $datatable .= '<tr'.$css_class.'>'.
9587: '<td><span class="LC_nobreak">'.$titles->{$item}.
9588: '</span></td><td class="LC_right_item" colspan="3">';
9589: if ($item eq 'auth_def') {
1.325 raeburn 9590: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 9591: my %shortauth = (
9592: internal => 'int',
9593: krb4 => 'krb4',
9594: krb5 => 'krb5',
1.325 raeburn 9595: localauth => 'loc',
9596: lti => 'lti',
1.236 raeburn 9597: );
9598: my %authnames = &authtype_names();
9599: foreach my $auth (@authtypes) {
9600: my $checked = ' ';
9601: if ($defaults{$item} eq $auth) {
9602: $checked = ' checked="checked" ';
9603: }
9604: $datatable .= '<label><input type="radio" name="'.$item.
9605: '" value="'.$auth.'"'.$checked.'/>'.
9606: $authnames{$shortauth{$auth}}.'</label> ';
9607: }
9608: } elsif ($item eq 'timezone_def') {
9609: my $includeempty = 1;
9610: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
9611: } elsif ($item eq 'datelocale_def') {
9612: my $includeempty = 1;
9613: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
9614: } elsif ($item eq 'lang_def') {
1.263 raeburn 9615: my $includeempty = 1;
9616: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 9617: } else {
9618: my $size;
9619: if ($item eq 'portal_def') {
9620: $size = ' size="25"';
9621: }
9622: $datatable .= '<input type="text" name="'.$item.'" value="'.
9623: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 9624: }
1.236 raeburn 9625: $datatable .= '</td></tr>';
9626: $rownum ++;
9627: }
1.354 raeburn 9628: } else {
1.294 raeburn 9629: my %defaults;
9630: if (ref($settings) eq 'HASH') {
1.354 raeburn 9631: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
9632: my $maxnum = @{$settings->{'inststatusorder'}};
9633: for (my $i=0; $i<$maxnum; $i++) {
9634: $css_class = $rownum%2?' class="LC_odd_row"':'';
9635: my $item = $settings->{'inststatusorder'}->[$i];
9636: my $title = $settings->{'inststatustypes'}->{$item};
9637: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
9638: $datatable .= '<tr'.$css_class.'>'.
9639: '<td><span class="LC_nobreak">'.
9640: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
9641: for (my $k=0; $k<=$maxnum; $k++) {
9642: my $vpos = $k+1;
9643: my $selstr;
9644: if ($k == $i) {
9645: $selstr = ' selected="selected" ';
9646: }
9647: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9648: }
9649: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
9650: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
9651: &mt('delete').'</span></td>'.
1.380 raeburn 9652: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354 raeburn 9653: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
9654: '</span></td></tr>';
9655: }
9656: $css_class = $rownum%2?' class="LC_odd_row"':'';
9657: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
9658: $datatable .= '<tr '.$css_class.'>'.
9659: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
9660: for (my $k=0; $k<=$maxnum; $k++) {
9661: my $vpos = $k+1;
9662: my $selstr;
9663: if ($k == $maxnum) {
9664: $selstr = ' selected="selected" ';
9665: }
9666: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9667: }
9668: $datatable .= '</select> '.&mt('Internal ID:').
9669: '<input type="text" size="10" name="addinststatus" value="" />'.
9670: ' '.&mt('(new)').
9671: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380 raeburn 9672: &mt('Name displayed').':'.
1.354 raeburn 9673: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
9674: '</tr>'."\n";
9675: $rownum ++;
1.294 raeburn 9676: }
1.354 raeburn 9677: }
9678: }
9679: $$rowtotal += $rownum;
1.43 raeburn 9680: return $datatable;
9681: }
9682:
1.168 raeburn 9683: sub get_languages_hash {
9684: my %langchoices;
9685: foreach my $id (&Apache::loncommon::languageids()) {
9686: my $code = &Apache::loncommon::supportedlanguagecode($id);
9687: if ($code ne '') {
9688: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
9689: }
9690: }
9691: return %langchoices;
9692: }
9693:
1.43 raeburn 9694: sub defaults_titles {
1.141 raeburn 9695: my ($dom) = @_;
1.43 raeburn 9696: my %titles = &Apache::lonlocal::texthash (
9697: 'auth_def' => 'Default authentication type',
9698: 'auth_arg_def' => 'Default authentication argument',
9699: 'lang_def' => 'Default language',
1.54 raeburn 9700: 'timezone_def' => 'Default timezone',
1.68 raeburn 9701: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 9702: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 9703: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
9704: 'intauth_check' => 'Check bcrypt cost if authenticated',
9705: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 9706: );
1.141 raeburn 9707: if ($dom) {
9708: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
9709: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
9710: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
9711: $protocol = 'http' if ($protocol ne 'https');
9712: if ($uint_dom) {
9713: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
9714: $uint_dom);
9715: }
9716: }
1.43 raeburn 9717: return (\%titles);
9718: }
9719:
1.346 raeburn 9720: sub print_scantron {
9721: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
9722: if ($position eq 'top') {
9723: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
9724: } else {
9725: return &print_scantronconfig($dom,$settings,\$rowtotal);
9726: }
9727: }
9728:
9729: sub scantron_javascript {
9730: return <<"ENDSCRIPT";
9731:
9732: <script type="text/javascript">
9733: // <![CDATA[
9734:
9735: function toggleScantron(form) {
1.347 raeburn 9736: var csvfieldset = new Array();
1.346 raeburn 9737: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 9738: csvfieldset.push(document.getElementById('scantroncsv_cols'));
9739: }
9740: if (document.getElementById('scantroncsv_options')) {
9741: csvfieldset.push(document.getElementById('scantroncsv_options'));
9742: }
9743: if (csvfieldset.length) {
1.346 raeburn 9744: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 9745: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 9746: if (scantroncsv.checked) {
1.347 raeburn 9747: for (var i=0; i<csvfieldset.length; i++) {
9748: csvfieldset[i].style.display = 'block';
9749: }
1.346 raeburn 9750: } else {
1.347 raeburn 9751: for (var i=0; i<csvfieldset.length; i++) {
9752: csvfieldset[i].style.display = 'none';
9753: }
1.346 raeburn 9754: var csvselects = document.getElementsByClassName('scantronconfig_csv');
9755: if (csvselects.length) {
9756: for (var j=0; j<csvselects.length; j++) {
9757: csvselects[j].selectedIndex = 0;
9758: }
9759: }
9760: }
9761: }
9762: }
9763: return;
9764: }
9765: // ]]>
9766: </script>
9767:
9768: ENDSCRIPT
9769:
9770: }
9771:
1.46 raeburn 9772: sub print_scantronformat {
9773: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
9774: my $itemcount = 1;
1.60 raeburn 9775: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
9776: %confhash);
1.46 raeburn 9777: my $switchserver = &check_switchserver($dom,$confname);
9778: my %lt = &Apache::lonlocal::texthash (
1.95 www 9779: default => 'Default bubblesheet format file error',
9780: custom => 'Custom bubblesheet format file error',
1.46 raeburn 9781: );
9782: my %scantronfiles = (
9783: default => 'default.tab',
9784: custom => 'custom.tab',
9785: );
9786: foreach my $key (keys(%scantronfiles)) {
9787: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
9788: .$scantronfiles{$key};
9789: }
9790: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
9791: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
9792: if (!$switchserver) {
9793: my $servadm = $r->dir_config('lonAdmEMail');
9794: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
9795: if ($configuserok eq 'ok') {
9796: if ($author_ok eq 'ok') {
9797: my %legacyfile = (
1.346 raeburn 9798: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
9799: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 9800: );
9801: my %md5chk;
9802: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 9803: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
9804: chomp($md5chk{$type});
1.46 raeburn 9805: }
9806: if ($md5chk{'default'} ne $md5chk{'custom'}) {
9807: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 9808: ($scantronurls{$type},my $error) =
1.46 raeburn 9809: &legacy_scantronformat($r,$dom,$confname,
9810: $type,$legacyfile{$type},
9811: $scantronurls{$type},
9812: $scantronfiles{$type});
1.60 raeburn 9813: if ($error ne '') {
9814: $error{$type} = $error;
9815: }
9816: }
9817: if (keys(%error) == 0) {
9818: $is_custom = 1;
1.346 raeburn 9819: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 9820: $scantronurls{'custom'};
1.346 raeburn 9821: my $putresult =
1.60 raeburn 9822: &Apache::lonnet::put_dom('configuration',
9823: \%confhash,$dom);
9824: if ($putresult ne 'ok') {
1.346 raeburn 9825: $error{'custom'} =
1.60 raeburn 9826: '<span class="LC_error">'.
9827: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
9828: }
1.46 raeburn 9829: }
9830: } else {
1.60 raeburn 9831: ($scantronurls{'default'},my $error) =
1.46 raeburn 9832: &legacy_scantronformat($r,$dom,$confname,
9833: 'default',$legacyfile{'default'},
9834: $scantronurls{'default'},
9835: $scantronfiles{'default'});
1.60 raeburn 9836: if ($error eq '') {
9837: $confhash{'scantron'}{'scantronformat'} = '';
9838: my $putresult =
9839: &Apache::lonnet::put_dom('configuration',
9840: \%confhash,$dom);
9841: if ($putresult ne 'ok') {
9842: $error{'default'} =
9843: '<span class="LC_error">'.
9844: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
9845: }
9846: } else {
9847: $error{'default'} = $error;
9848: }
1.46 raeburn 9849: }
9850: }
9851: }
9852: } else {
1.95 www 9853: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 9854: }
9855: }
9856: if (ref($settings) eq 'HASH') {
9857: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
9858: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
9859: if ((!@info) || ($info[0] eq 'no_such_dir')) {
9860: $scantronurl = '';
9861: } else {
9862: $scantronurl = $settings->{'scantronformat'};
9863: }
9864: $is_custom = 1;
9865: } else {
9866: $scantronurl = $scantronurls{'default'};
9867: }
9868: } else {
1.60 raeburn 9869: if ($is_custom) {
9870: $scantronurl = $scantronurls{'custom'};
9871: } else {
9872: $scantronurl = $scantronurls{'default'};
9873: }
1.46 raeburn 9874: }
9875: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9876: $datatable .= '<tr'.$css_class.'>';
9877: if (!$is_custom) {
1.65 raeburn 9878: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
9879: '<span class="LC_nobreak">';
1.46 raeburn 9880: if ($scantronurl) {
1.199 raeburn 9881: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
9882: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 9883: } else {
9884: $datatable = &mt('File unavailable for display');
9885: }
1.65 raeburn 9886: $datatable .= '</span></td>';
1.60 raeburn 9887: if (keys(%error) == 0) {
1.306 raeburn 9888: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 9889: if (!$switchserver) {
9890: $datatable .= &mt('Upload:').'<br />';
9891: }
9892: } else {
9893: my $errorstr;
9894: foreach my $key (sort(keys(%error))) {
9895: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
9896: }
9897: $datatable .= '<td>'.$errorstr;
9898: }
1.46 raeburn 9899: } else {
9900: if (keys(%error) > 0) {
9901: my $errorstr;
9902: foreach my $key (sort(keys(%error))) {
9903: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
9904: }
1.60 raeburn 9905: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 9906: } elsif ($scantronurl) {
1.199 raeburn 9907: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
9908: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 9909: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 9910: $link.
9911: '<label><input type="checkbox" name="scantronformat_del"'.
9912: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 9913: '<td><span class="LC_nobreak"> '.
9914: &mt('Replace:').'</span><br />';
1.46 raeburn 9915: }
9916: }
9917: if (keys(%error) == 0) {
9918: if ($switchserver) {
9919: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
9920: } else {
1.65 raeburn 9921: $datatable .='<span class="LC_nobreak"> '.
9922: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 9923: }
9924: }
9925: $datatable .= '</td></tr>';
9926: $$rowtotal ++;
9927: return $datatable;
9928: }
9929:
9930: sub legacy_scantronformat {
9931: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
9932: my ($url,$error);
9933: my @statinfo = &Apache::lonnet::stat_file($newurl);
9934: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
9935: (my $result,$url) =
9936: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
9937: '','',$newfile);
9938: if ($result ne 'ok') {
1.130 raeburn 9939: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 9940: }
9941: }
9942: return ($url,$error);
9943: }
1.43 raeburn 9944:
1.346 raeburn 9945: sub print_scantronconfig {
9946: my ($dom,$settings,$rowtotal) = @_;
9947: my $itemcount = 2;
9948: my $is_checked = ' checked="checked"';
1.347 raeburn 9949: my %optionson = (
9950: hdr => ' checked="checked"',
9951: pad => ' checked="checked"',
9952: rem => ' checked="checked"',
9953: );
9954: my %optionsoff = (
9955: hdr => '',
9956: pad => '',
9957: rem => '',
9958: );
1.346 raeburn 9959: my $currcsvsty = 'none';
1.347 raeburn 9960: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 9961: my @fields = &scantroncsv_fields();
9962: my %titles = &scantronconfig_titles();
9963: if (ref($settings) eq 'HASH') {
9964: if (ref($settings->{config}) eq 'HASH') {
9965: if ($settings->{config}->{dat}) {
9966: $checked{'dat'} = $is_checked;
9967: }
9968: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 9969: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
9970: %csvfields = %{$settings->{config}->{csv}->{fields}};
9971: if (keys(%csvfields) > 0) {
9972: $checked{'csv'} = $is_checked;
9973: $currcsvsty = 'block';
9974: }
9975: }
9976: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
9977: %csvoptions = %{$settings->{config}->{csv}->{options}};
9978: foreach my $option (keys(%optionson)) {
9979: unless ($csvoptions{$option}) {
9980: $optionsoff{$option} = $optionson{$option};
9981: $optionson{$option} = '';
9982: }
9983: }
1.346 raeburn 9984: }
9985: }
9986: } else {
9987: $checked{'dat'} = $is_checked;
9988: }
9989: } else {
9990: $checked{'dat'} = $is_checked;
9991: }
9992: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
9993: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
9994: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
9995: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
9996: foreach my $item ('dat','csv') {
9997: my $id;
9998: if ($item eq 'csv') {
9999: $id = 'id="scantronconfcsv" ';
1.347 raeburn 10000: }
1.346 raeburn 10001: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
10002: $titles{$item}.'</label>'.(' 'x3);
10003: if ($item eq 'csv') {
10004: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
10005: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
10006: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
10007: foreach my $col (@fields) {
10008: my $selnone;
10009: if ($csvfields{$col} eq '') {
10010: $selnone = ' selected="selected"';
10011: }
10012: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
10013: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
10014: '<option value=""'.$selnone.'></option>';
10015: for (my $i=0; $i<20; $i++) {
10016: my $shown = $i+1;
10017: my $sel;
10018: unless ($selnone) {
10019: if (exists($csvfields{$col})) {
10020: if ($csvfields{$col} == $i) {
10021: $sel = ' selected="selected"';
10022: }
10023: }
10024: }
10025: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
10026: }
10027: $datatable .= '</select></td></tr>';
10028: }
1.347 raeburn 10029: $datatable .= '</table></fieldset>'.
10030: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
10031: '<legend>'.&mt('CSV Options').'</legend>';
10032: foreach my $option ('hdr','pad','rem') {
10033: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
10034: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
10035: &mt('Yes').'</label>'.(' 'x2)."\n".
10036: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
10037: }
10038: $datatable .= '</fieldset>';
1.346 raeburn 10039: $itemcount ++;
10040: }
10041: }
10042: $datatable .= '</td></tr>';
10043: $$rowtotal ++;
10044: return $datatable;
10045: }
10046:
10047: sub scantronconfig_titles {
10048: return &Apache::lonlocal::texthash(
10049: dat => 'Standard format (.dat)',
10050: csv => 'Comma separated values (.csv)',
1.347 raeburn 10051: hdr => 'Remove first line in file (contains column titles)',
10052: pad => 'Prepend 0s to PaperID',
1.348 raeburn 10053: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 10054: CODE => 'CODE',
10055: ID => 'Student ID',
10056: PaperID => 'Paper ID',
10057: FirstName => 'First Name',
10058: LastName => 'Last Name',
10059: FirstQuestion => 'First Question Response',
10060: Section => 'Section',
10061: );
10062: }
10063:
10064: sub scantroncsv_fields {
10065: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
10066: }
10067:
1.49 raeburn 10068: sub print_coursecategories {
1.57 raeburn 10069: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
10070: my $datatable;
10071: if ($position eq 'top') {
1.238 raeburn 10072: my (%checked);
10073: my @catitems = ('unauth','auth');
10074: my @cattypes = ('std','domonly','codesrch','none');
10075: $checked{'unauth'} = 'std';
10076: $checked{'auth'} = 'std';
10077: if (ref($settings) eq 'HASH') {
10078: foreach my $type (@cattypes) {
10079: if ($type eq $settings->{'unauth'}) {
10080: $checked{'unauth'} = $type;
10081: }
10082: if ($type eq $settings->{'auth'}) {
10083: $checked{'auth'} = $type;
10084: }
10085: }
10086: }
10087: my %lt = &Apache::lonlocal::texthash (
10088: unauth => 'Catalog type for unauthenticated users',
10089: auth => 'Catalog type for authenticated users',
10090: none => 'No catalog',
10091: std => 'Standard catalog',
10092: domonly => 'Domain-only catalog',
10093: codesrch => "Code search form",
10094: );
10095: my $itemcount = 0;
10096: foreach my $item (@catitems) {
10097: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
10098: $datatable .= '<tr '.$css_class.'>'.
10099: '<td>'.$lt{$item}.'</td>'.
10100: '<td class="LC_right_item"><span class="LC_nobreak">';
10101: foreach my $type (@cattypes) {
10102: my $ischecked;
10103: if ($checked{$item} eq $type) {
10104: $ischecked=' checked="checked"';
10105: }
10106: $datatable .= '<label>'.
10107: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
10108: ' />'.$lt{$type}.'</label> ';
10109: }
1.327 raeburn 10110: $datatable .= '</span></td></tr>';
1.238 raeburn 10111: $itemcount ++;
10112: }
10113: $$rowtotal += $itemcount;
10114: } elsif ($position eq 'middle') {
1.57 raeburn 10115: my $toggle_cats_crs = ' ';
10116: my $toggle_cats_dom = ' checked="checked" ';
10117: my $can_cat_crs = ' ';
10118: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 10119: my $toggle_catscomm_comm = ' ';
10120: my $toggle_catscomm_dom = ' checked="checked" ';
10121: my $can_catcomm_comm = ' ';
10122: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 10123: my $toggle_catsplace_place = ' ';
10124: my $toggle_catsplace_dom = ' checked="checked" ';
10125: my $can_catplace_place = ' ';
10126: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 10127:
1.57 raeburn 10128: if (ref($settings) eq 'HASH') {
10129: if ($settings->{'togglecats'} eq 'crs') {
10130: $toggle_cats_crs = $toggle_cats_dom;
10131: $toggle_cats_dom = ' ';
10132: }
10133: if ($settings->{'categorize'} eq 'crs') {
10134: $can_cat_crs = $can_cat_dom;
10135: $can_cat_dom = ' ';
10136: }
1.120 raeburn 10137: if ($settings->{'togglecatscomm'} eq 'comm') {
10138: $toggle_catscomm_comm = $toggle_catscomm_dom;
10139: $toggle_catscomm_dom = ' ';
10140: }
10141: if ($settings->{'categorizecomm'} eq 'comm') {
10142: $can_catcomm_comm = $can_catcomm_dom;
10143: $can_catcomm_dom = ' ';
10144: }
1.272 raeburn 10145: if ($settings->{'togglecatsplace'} eq 'place') {
10146: $toggle_catsplace_place = $toggle_catsplace_dom;
10147: $toggle_catsplace_dom = ' ';
10148: }
10149: if ($settings->{'categorizeplace'} eq 'place') {
10150: $can_catplace_place = $can_catplace_dom;
10151: $can_catplace_dom = ' ';
10152: }
1.57 raeburn 10153: }
10154: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 10155: togglecats => 'Show/Hide a course in catalog',
10156: togglecatscomm => 'Show/Hide a community in catalog',
10157: togglecatsplace => 'Show/Hide a placement test in catalog',
10158: categorize => 'Assign a category to a course',
10159: categorizecomm => 'Assign a category to a community',
10160: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 10161: );
10162: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 10163: dom => 'Set in Domain',
10164: crs => 'Set in Course',
10165: comm => 'Set in Community',
10166: place => 'Set in Placement Test',
1.57 raeburn 10167: );
10168: $datatable = '<tr class="LC_odd_row">'.
10169: '<td>'.$title{'togglecats'}.'</td>'.
10170: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10171: '<input type="radio" name="togglecats"'.
10172: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10173: '<label><input type="radio" name="togglecats"'.
10174: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
10175: '</tr><tr>'.
10176: '<td>'.$title{'categorize'}.'</td>'.
10177: '<td class="LC_right_item"><span class="LC_nobreak">'.
10178: '<label><input type="radio" name="categorize"'.
10179: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10180: '<label><input type="radio" name="categorize"'.
10181: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 10182: '</tr><tr class="LC_odd_row">'.
10183: '<td>'.$title{'togglecatscomm'}.'</td>'.
10184: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10185: '<input type="radio" name="togglecatscomm"'.
10186: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10187: '<label><input type="radio" name="togglecatscomm"'.
10188: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
10189: '</tr><tr>'.
10190: '<td>'.$title{'categorizecomm'}.'</td>'.
10191: '<td class="LC_right_item"><span class="LC_nobreak">'.
10192: '<label><input type="radio" name="categorizecomm"'.
10193: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10194: '<label><input type="radio" name="categorizecomm"'.
10195: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 10196: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 10197: '<td>'.$title{'togglecatsplace'}.'</td>'.
10198: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10199: '<input type="radio" name="togglecatsplace"'.
10200: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10201: '<label><input type="radio" name="togglecatscomm"'.
10202: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
10203: '</tr><tr>'.
10204: '<td>'.$title{'categorizeplace'}.'</td>'.
10205: '<td class="LC_right_item"><span class="LC_nobreak">'.
10206: '<label><input type="radio" name="categorizeplace"'.
10207: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10208: '<label><input type="radio" name="categorizeplace"'.
10209: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 10210: '</tr>';
1.272 raeburn 10211: $$rowtotal += 6;
1.57 raeburn 10212: } else {
10213: my $css_class;
10214: my $itemcount = 1;
10215: my $cathash;
10216: if (ref($settings) eq 'HASH') {
10217: $cathash = $settings->{'cats'};
10218: }
10219: if (ref($cathash) eq 'HASH') {
10220: my (@cats,@trails,%allitems,%idx,@jsarray);
10221: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
10222: \%allitems,\%idx,\@jsarray);
10223: my $maxdepth = scalar(@cats);
10224: my $colattrib = '';
10225: if ($maxdepth > 2) {
10226: $colattrib = ' colspan="2" ';
10227: }
10228: my @path;
10229: if (@cats > 0) {
10230: if (ref($cats[0]) eq 'ARRAY') {
10231: my $numtop = @{$cats[0]};
10232: my $maxnum = $numtop;
1.120 raeburn 10233: my %default_names = (
10234: instcode => &mt('Official courses'),
10235: communities => &mt('Communities'),
1.272 raeburn 10236: placement => &mt('Placement Tests'),
1.120 raeburn 10237: );
10238:
10239: if ((!grep(/^instcode$/,@{$cats[0]})) ||
10240: ($cathash->{'instcode::0'} eq '') ||
10241: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 10242: ($cathash->{'communities::0'} eq '') ||
10243: (!grep(/^placement$/,@{$cats[0]})) ||
10244: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 10245: $maxnum ++;
10246: }
10247: my $lastidx;
10248: for (my $i=0; $i<$numtop; $i++) {
10249: my $parent = $cats[0][$i];
10250: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10251: my $item = &escape($parent).'::0';
10252: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
10253: $lastidx = $idx{$item};
10254: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
10255: .'<select name="'.$item.'"'.$chgstr.'>';
10256: for (my $k=0; $k<=$maxnum; $k++) {
10257: my $vpos = $k+1;
10258: my $selstr;
10259: if ($k == $i) {
10260: $selstr = ' selected="selected" ';
10261: }
10262: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10263: }
1.214 raeburn 10264: $datatable .= '</select></span></td><td>';
1.272 raeburn 10265: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 10266: $datatable .= '<span class="LC_nobreak">'
10267: .$default_names{$parent}.'</span>';
10268: if ($parent eq 'instcode') {
10269: $datatable .= '<br /><span class="LC_nobreak">('
10270: .&mt('with institutional codes')
10271: .')</span></td><td'.$colattrib.'>';
10272: } else {
10273: $datatable .= '<table><tr><td>';
10274: }
10275: $datatable .= '<span class="LC_nobreak">'
10276: .'<label><input type="radio" name="'
10277: .$parent.'" value="1" checked="checked" />'
10278: .&mt('Display').'</label>';
10279: if ($parent eq 'instcode') {
10280: $datatable .= ' ';
10281: } else {
10282: $datatable .= '</span></td></tr><tr><td>'
10283: .'<span class="LC_nobreak">';
10284: }
10285: $datatable .= '<label><input type="radio" name="'
10286: .$parent.'" value="0" />'
10287: .&mt('Do not display').'</label></span>';
1.272 raeburn 10288: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 10289: $datatable .= '</td></tr></table>';
10290: }
10291: $datatable .= '</td>';
1.57 raeburn 10292: } else {
10293: $datatable .= $parent
1.214 raeburn 10294: .' <span class="LC_nobreak"><label>'
10295: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 10296: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
10297: }
10298: my $depth = 1;
10299: push(@path,$parent);
10300: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
10301: pop(@path);
10302: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
10303: $itemcount ++;
10304: }
1.48 raeburn 10305: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 10306: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
10307: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 10308: for (my $k=0; $k<=$maxnum; $k++) {
10309: my $vpos = $k+1;
10310: my $selstr;
1.57 raeburn 10311: if ($k == $numtop) {
1.48 raeburn 10312: $selstr = ' selected="selected" ';
10313: }
10314: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10315: }
1.59 bisitz 10316: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 10317: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
10318: .'</tr>'."\n";
1.48 raeburn 10319: $itemcount ++;
1.272 raeburn 10320: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 10321: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
10322: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10323: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
10324: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
10325: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
10326: for (my $k=0; $k<=$maxnum; $k++) {
10327: my $vpos = $k+1;
10328: my $selstr;
10329: if ($k == $maxnum) {
10330: $selstr = ' selected="selected" ';
10331: }
10332: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 10333: }
1.120 raeburn 10334: $datatable .= '</select></span></td>'.
10335: '<td><span class="LC_nobreak">'.
10336: $default_names{$default}.'</span>';
10337: if ($default eq 'instcode') {
10338: $datatable .= '<br /><span class="LC_nobreak">('
10339: .&mt('with institutional codes').')</span>';
10340: }
10341: $datatable .= '</td>'
10342: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
10343: .&mt('Display').'</label> '
10344: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
10345: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 10346: }
10347: }
10348: }
1.57 raeburn 10349: } else {
10350: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 10351: }
10352: } else {
1.327 raeburn 10353: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 10354: .&initialize_categories($itemcount);
1.48 raeburn 10355: }
1.57 raeburn 10356: $$rowtotal += $itemcount;
1.48 raeburn 10357: }
10358: return $datatable;
10359: }
10360:
1.69 raeburn 10361: sub print_serverstatuses {
10362: my ($dom,$settings,$rowtotal) = @_;
10363: my $datatable;
10364: my @pages = &serverstatus_pages();
10365: my (%namedaccess,%machineaccess);
10366: foreach my $type (@pages) {
10367: $namedaccess{$type} = '';
10368: $machineaccess{$type}= '';
10369: }
10370: if (ref($settings) eq 'HASH') {
10371: foreach my $type (@pages) {
10372: if (exists($settings->{$type})) {
10373: if (ref($settings->{$type}) eq 'HASH') {
10374: foreach my $key (keys(%{$settings->{$type}})) {
10375: if ($key eq 'namedusers') {
10376: $namedaccess{$type} = $settings->{$type}->{$key};
10377: } elsif ($key eq 'machines') {
10378: $machineaccess{$type} = $settings->{$type}->{$key};
10379: }
10380: }
10381: }
10382: }
10383: }
10384: }
1.81 raeburn 10385: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 10386: my $rownum = 0;
10387: my $css_class;
10388: foreach my $type (@pages) {
10389: $rownum ++;
10390: $css_class = $rownum%2?' class="LC_odd_row"':'';
10391: $datatable .= '<tr'.$css_class.'>'.
10392: '<td><span class="LC_nobreak">'.
10393: $titles->{$type}.'</span></td>'.
10394: '<td class="LC_left_item">'.
10395: '<input type="text" name="'.$type.'_namedusers" '.
10396: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
10397: '<td class="LC_right_item">'.
10398: '<span class="LC_nobreak">'.
10399: '<input type="text" name="'.$type.'_machines" '.
10400: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 10401: '</span></td></tr>'."\n";
1.69 raeburn 10402: }
10403: $$rowtotal += $rownum;
10404: return $datatable;
10405: }
10406:
10407: sub serverstatus_pages {
10408: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 10409: 'checksums','clusterstatus','certstatus','metadata_keywords',
10410: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
10411: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 10412: }
10413:
1.236 raeburn 10414: sub defaults_javascript {
10415: my ($settings) = @_;
1.354 raeburn 10416: return unless (ref($settings) eq 'HASH');
1.236 raeburn 10417: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10418: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
10419: if ($maxnum eq '') {
10420: $maxnum = 0;
10421: }
10422: $maxnum ++;
1.249 raeburn 10423: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 10424: return <<"ENDSCRIPT";
10425: <script type="text/javascript">
10426: // <![CDATA[
10427: function reorderTypes(form,caller) {
10428: var changedVal;
10429: $jstext
10430: var newpos = 'addinststatus_pos';
10431: var current = new Array;
10432: var maxh = $maxnum;
10433: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
10434: var oldVal;
10435: if (caller == newpos) {
10436: changedVal = newitemVal;
10437: } else {
10438: var curritem = 'inststatus_pos_'+caller;
10439: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
10440: current[newitemVal] = newpos;
10441: }
10442: for (var i=0; i<inststatuses.length; i++) {
10443: if (inststatuses[i] != caller) {
10444: var elementName = 'inststatus_pos_'+inststatuses[i];
10445: if (form.elements[elementName]) {
10446: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
10447: current[currVal] = elementName;
10448: }
10449: }
10450: }
10451: for (var j=0; j<maxh; j++) {
10452: if (current[j] == undefined) {
10453: oldVal = j;
10454: }
10455: }
10456: if (oldVal < changedVal) {
10457: for (var k=oldVal+1; k<=changedVal ; k++) {
10458: var elementName = current[k];
10459: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
10460: }
10461: } else {
10462: for (var k=changedVal; k<oldVal; k++) {
10463: var elementName = current[k];
10464: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
10465: }
10466: }
10467: return;
10468: }
10469:
10470: // ]]>
10471: </script>
10472:
10473: ENDSCRIPT
10474: }
1.354 raeburn 10475: return;
10476: }
10477:
10478: sub passwords_javascript {
1.365 raeburn 10479: my %intalert = &Apache::lonlocal::texthash (
10480: 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.',
10481: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
10482: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
10483: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
10484: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
10485: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
10486: );
10487: &js_escape(\%intalert);
10488: my $defmin = $Apache::lonnet::passwdmin;
1.354 raeburn 10489: my $intauthjs = <<"ENDSCRIPT";
10490:
10491: function warnIntAuth(field) {
10492: if (field.name == 'intauth_check') {
10493: if (field.value == '2') {
1.365 raeburn 10494: alert('$intalert{authcheck}');
1.354 raeburn 10495: }
10496: }
10497: if (field.name == 'intauth_cost') {
10498: field.value.replace(/\s/g,'');
10499: if (field.value != '') {
10500: var regexdigit=/^\\d+\$/;
10501: if (!regexdigit.test(field.value)) {
1.365 raeburn 10502: alert('$intalert{authcost}');
10503: }
10504: }
10505: }
10506: return;
10507: }
10508:
10509: function warnIntPass(field) {
10510: field.value.replace(/^\s+/,'');
10511: field.value.replace(/\s+\$/,'');
10512: var regexdigit=/^\\d+\$/;
10513: if (field.name == 'passwords_min') {
10514: if (field.value == '') {
10515: alert('$intalert{passmin}');
10516: field.value = '$defmin';
10517: } else {
10518: if (!regexdigit.test(field.value)) {
10519: alert('$intalert{passmin}');
10520: field.value = '$defmin';
10521: }
1.366 raeburn 10522: var minval = parseInt(field.value,10);
1.365 raeburn 10523: if (minval < $defmin) {
10524: alert('$intalert{passmin}');
10525: field.value = '$defmin';
10526: }
10527: }
10528: } else {
10529: if (field.value == '0') {
10530: field.value = '';
10531: }
10532: if (field.value != '') {
10533: if (field.name == 'passwords_expire') {
10534: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
10535: if (!regexpposnum.test(field.value)) {
10536: alert('$intalert{passexp}');
10537: field.value = '';
10538: } else {
10539: var expval = parseFloat(field.value);
10540: if (expval == 0) {
10541: alert('$intalert{passexp}');
10542: field.value = '';
10543: }
10544: }
10545: } else {
10546: if (!regexdigit.test(field.value)) {
10547: if (field.name == 'passwords_max') {
10548: alert('$intalert{passmax}');
10549: } else {
10550: if (field.name == 'passwords_numsaved') {
10551: alert('$intalert{passnum}');
10552: }
10553: }
1.370 raeburn 10554: field.value = '';
1.365 raeburn 10555: }
1.354 raeburn 10556: }
10557: }
10558: }
10559: return;
10560: }
10561:
10562: ENDSCRIPT
10563: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 10564: }
10565:
1.49 raeburn 10566: sub coursecategories_javascript {
10567: my ($settings) = @_;
1.57 raeburn 10568: my ($output,$jstext,$cathash);
1.49 raeburn 10569: if (ref($settings) eq 'HASH') {
1.57 raeburn 10570: $cathash = $settings->{'cats'};
10571: }
10572: if (ref($cathash) eq 'HASH') {
1.49 raeburn 10573: my (@cats,@jsarray,%idx);
1.57 raeburn 10574: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 10575: if (@jsarray > 0) {
10576: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
10577: for (my $i=0; $i<@jsarray; $i++) {
10578: if (ref($jsarray[$i]) eq 'ARRAY') {
10579: my $catstr = join('","',@{$jsarray[$i]});
10580: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
10581: }
10582: }
10583: }
10584: } else {
10585: $jstext = ' var categories = Array(1);'."\n".
10586: ' categories[0] = Array("instcode_pos");'."\n";
10587: }
1.237 bisitz 10588: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
10589: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 10590: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 10591: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
10592: &js_escape(\$instcode_reserved);
10593: &js_escape(\$communities_reserved);
1.272 raeburn 10594: &js_escape(\$placement_reserved);
1.265 damieng 10595: &js_escape(\$choose_again);
1.49 raeburn 10596: $output = <<"ENDSCRIPT";
10597: <script type="text/javascript">
1.109 raeburn 10598: // <![CDATA[
1.49 raeburn 10599: function reorderCats(form,parent,item,idx) {
10600: var changedVal;
10601: $jstext
10602: var newpos = 'addcategory_pos';
10603: if (parent == '') {
10604: var has_instcode = 0;
10605: var maxtop = categories[idx].length;
10606: for (var j=0; j<maxtop; j++) {
10607: if (categories[idx][j] == 'instcode::0') {
10608: has_instcode == 1;
10609: }
10610: }
10611: if (has_instcode == 0) {
10612: categories[idx][maxtop] = 'instcode_pos';
10613: }
10614: } else {
10615: newpos += '_'+parent;
10616: }
10617: var maxh = 1 + categories[idx].length;
10618: var current = new Array;
10619: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
10620: if (item == newpos) {
10621: changedVal = newitemVal;
10622: } else {
10623: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
10624: current[newitemVal] = newpos;
10625: }
10626: for (var i=0; i<categories[idx].length; i++) {
10627: var elementName = categories[idx][i];
10628: if (elementName != item) {
10629: if (form.elements[elementName]) {
10630: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
10631: current[currVal] = elementName;
10632: }
10633: }
10634: }
10635: var oldVal;
10636: for (var j=0; j<maxh; j++) {
10637: if (current[j] == undefined) {
10638: oldVal = j;
10639: }
10640: }
10641: if (oldVal < changedVal) {
10642: for (var k=oldVal+1; k<=changedVal ; k++) {
10643: var elementName = current[k];
10644: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
10645: }
10646: } else {
10647: for (var k=changedVal; k<oldVal; k++) {
10648: var elementName = current[k];
10649: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
10650: }
10651: }
10652: return;
10653: }
1.120 raeburn 10654:
10655: function categoryCheck(form) {
10656: if (form.elements['addcategory_name'].value == 'instcode') {
10657: alert('$instcode_reserved\\n$choose_again');
10658: return false;
10659: }
10660: if (form.elements['addcategory_name'].value == 'communities') {
10661: alert('$communities_reserved\\n$choose_again');
10662: return false;
10663: }
1.272 raeburn 10664: if (form.elements['addcategory_name'].value == 'placement') {
10665: alert('$placement_reserved\\n$choose_again');
10666: return false;
10667: }
1.120 raeburn 10668: return true;
10669: }
10670:
1.109 raeburn 10671: // ]]>
1.49 raeburn 10672: </script>
10673:
10674: ENDSCRIPT
10675: return $output;
10676: }
10677:
1.48 raeburn 10678: sub initialize_categories {
10679: my ($itemcount) = @_;
1.120 raeburn 10680: my ($datatable,$css_class,$chgstr);
1.380 raeburn 10681: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 10682: instcode => 'Official courses (with institutional codes)',
10683: communities => 'Communities',
1.272 raeburn 10684: placement => 'Placement Tests',
1.120 raeburn 10685: );
1.328 raeburn 10686: my %selnum = (
10687: instcode => '0',
10688: communities => '1',
10689: placement => '2',
10690: );
10691: my %selected;
1.272 raeburn 10692: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 10693: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 10694: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 10695: map { $selected{$selnum{$_}} = '' } keys(%selnum);
10696: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 10697: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 10698: .'<select name="'.$default.'_pos"'.$chgstr.'>'
10699: .'<option value="0"'.$selected{'0'}.'>1</option>'
10700: .'<option value="1"'.$selected{'1'}.'>2</option>'
10701: .'<option value="2"'.$selected{'2'}.'>3</option>'
10702: .'<option value="3">4</option></select> '
1.120 raeburn 10703: .$default_names{$default}
10704: .'</span></td><td><span class="LC_nobreak">'
10705: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
10706: .&mt('Display').'</label> <label>'
10707: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 10708: .'</label></span></td></tr>';
1.120 raeburn 10709: $itemcount ++;
10710: }
1.48 raeburn 10711: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 10712: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 10713: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 10714: .'<select name="addcategory_pos"'.$chgstr.'>'
10715: .'<option value="0">1</option>'
10716: .'<option value="1">2</option>'
1.328 raeburn 10717: .'<option value="2">3</option>'
10718: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 10719: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
10720: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
10721: .'</td></tr>';
1.48 raeburn 10722: return $datatable;
10723: }
10724:
10725: sub build_category_rows {
1.49 raeburn 10726: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
10727: my ($text,$name,$item,$chgstr);
1.48 raeburn 10728: if (ref($cats) eq 'ARRAY') {
10729: my $maxdepth = scalar(@{$cats});
10730: if (ref($cats->[$depth]) eq 'HASH') {
10731: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
10732: my $numchildren = @{$cats->[$depth]{$parent}};
10733: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 10734: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 10735: my ($idxnum,$parent_name,$parent_item);
10736: my $higher = $depth - 1;
10737: if ($higher == 0) {
10738: $parent_name = &escape($parent).'::'.$higher;
10739: } else {
10740: if (ref($path) eq 'ARRAY') {
10741: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
10742: }
10743: }
10744: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 10745: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 10746: if ($j < $numchildren) {
1.48 raeburn 10747: $name = $cats->[$depth]{$parent}[$j];
10748: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 10749: $idxnum = $idx->{$item};
10750: } else {
10751: $name = $parent_name;
10752: $item = $parent_item;
1.48 raeburn 10753: }
1.49 raeburn 10754: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
10755: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 10756: for (my $i=0; $i<=$numchildren; $i++) {
10757: my $vpos = $i+1;
10758: my $selstr;
10759: if ($j == $i) {
10760: $selstr = ' selected="selected" ';
10761: }
10762: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
10763: }
10764: $text .= '</select> ';
10765: if ($j < $numchildren) {
10766: my $deeper = $depth+1;
10767: $text .= $name.' '
10768: .'<label><input type="checkbox" name="deletecategory" value="'
10769: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
10770: if(ref($path) eq 'ARRAY') {
10771: push(@{$path},$name);
1.49 raeburn 10772: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 10773: pop(@{$path});
10774: }
10775: } else {
1.330 raeburn 10776: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 10777: if ($j == $numchildren) {
10778: $text .= $name;
10779: } else {
10780: $text .= $item;
10781: }
10782: $text .= '" value="" />';
10783: }
10784: $text .= '</td></tr>';
10785: }
10786: $text .= '</table></td>';
10787: } else {
10788: my $higher = $depth-1;
10789: if ($higher == 0) {
10790: $name = &escape($parent).'::'.$higher;
10791: } else {
10792: if (ref($path) eq 'ARRAY') {
10793: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
10794: }
10795: }
10796: my $colspan;
10797: if ($parent ne 'instcode') {
10798: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 10799: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 10800: }
10801: }
10802: }
10803: }
10804: return $text;
10805: }
10806:
1.33 raeburn 10807: sub modifiable_userdata_row {
1.305 raeburn 10808: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 10809: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 10810: my ($role,$rolename,$statustype);
10811: $role = $item;
1.224 raeburn 10812: if ($context eq 'cancreate') {
1.305 raeburn 10813: if ($item =~ /^(emailusername)_(.+)$/) {
10814: $role = $1;
10815: $statustype = $2;
1.228 raeburn 10816: if (ref($usertypes) eq 'HASH') {
10817: if ($usertypes->{$statustype}) {
10818: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
10819: } else {
10820: $rolename = &mt('Data provided by user');
10821: }
10822: }
1.224 raeburn 10823: }
10824: } elsif ($context eq 'selfcreate') {
1.63 raeburn 10825: if (ref($usertypes) eq 'HASH') {
10826: $rolename = $usertypes->{$role};
10827: } else {
10828: $rolename = $role;
10829: }
1.325 raeburn 10830: } elsif ($context eq 'lti') {
10831: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 10832: } elsif ($context eq 'privacy') {
10833: $rolename = $itemdesc;
1.33 raeburn 10834: } else {
1.63 raeburn 10835: if ($role eq 'cr') {
10836: $rolename = &mt('Custom role');
10837: } else {
10838: $rolename = &Apache::lonnet::plaintext($role);
10839: }
1.33 raeburn 10840: }
1.224 raeburn 10841: my (@fields,%fieldtitles);
10842: if (ref($fieldsref) eq 'ARRAY') {
10843: @fields = @{$fieldsref};
10844: } else {
10845: @fields = ('lastname','firstname','middlename','generation',
10846: 'permanentemail','id');
10847: }
10848: if ((ref($titlesref) eq 'HASH')) {
10849: %fieldtitles = %{$titlesref};
10850: } else {
10851: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10852: }
1.33 raeburn 10853: my $output;
1.305 raeburn 10854: my $css_class;
10855: if ($rowcount%2) {
10856: $css_class = 'LC_odd_row';
10857: }
10858: if ($customcss) {
10859: $css_class .= " $customcss";
10860: }
10861: $css_class =~ s/^\s+//;
10862: if ($css_class) {
10863: $css_class = ' class="'.$css_class.'"';
10864: }
10865: if ($rowstyle) {
10866: $css_class .= ' style="'.$rowstyle.'"';
10867: }
10868: if ($rowid) {
10869: $rowid = ' id="'.$rowid.'"';
10870: }
10871: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 10872: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
10873: '<td class="LC_left_item" colspan="2"><table>';
10874: my $rem;
10875: my %checks;
1.325 raeburn 10876: my %current;
1.33 raeburn 10877: if (ref($settings) eq 'HASH') {
1.325 raeburn 10878: my $hashref;
10879: if ($context eq 'lti') {
10880: if (ref($settings) eq 'HASH') {
10881: $hashref = $settings->{'instdata'};
10882: }
1.357 raeburn 10883: } elsif ($context eq 'privacy') {
10884: my ($key,$inner) = split(/_/,$role);
10885: if (ref($settings) eq 'HASH') {
10886: if (ref($settings->{$key}) eq 'HASH') {
10887: $hashref = $settings->{$key}->{$inner};
10888: }
10889: }
1.325 raeburn 10890: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 10891: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 10892: $hashref = $settings->{'lti_instdata'};
10893: }
10894: if ($role eq 'emailusername') {
10895: if ($statustype) {
10896: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
10897: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 10898: }
1.325 raeburn 10899: }
10900: }
10901: }
10902: if (ref($hashref) eq 'HASH') {
10903: foreach my $field (@fields) {
10904: if ($hashref->{$field}) {
10905: if ($role eq 'emailusername') {
10906: $checks{$field} = $hashref->{$field};
10907: } else {
10908: $checks{$field} = ' checked="checked" ';
1.33 raeburn 10909: }
10910: }
10911: }
10912: }
10913: }
1.305 raeburn 10914:
10915: my $total = scalar(@fields);
10916: for (my $i=0; $i<$total; $i++) {
10917: $rem = $i%($numinrow);
1.33 raeburn 10918: if ($rem == 0) {
10919: if ($i > 0) {
10920: $output .= '</tr>';
10921: }
10922: $output .= '<tr>';
10923: }
10924: my $check = ' ';
1.228 raeburn 10925: unless ($role eq 'emailusername') {
10926: if (exists($checks{$fields[$i]})) {
1.354 raeburn 10927: $check = $checks{$fields[$i]};
1.357 raeburn 10928: } elsif ($context eq 'privacy') {
10929: if ($role =~ /^priv_(domain|course)$/) {
10930: if (ref($settings) ne 'HASH') {
10931: $check = ' checked="checked" ';
10932: }
10933: } elsif ($role =~ /^priv_(author|community)$/) {
10934: if (ref($settings) ne 'HASH') {
10935: unless ($fields[$i] eq 'id') {
10936: $check = ' checked="checked" ';
10937: }
10938: }
10939: } elsif ($role =~ /^(unpriv|othdom)_/) {
10940: if (ref($settings) ne 'HASH') {
10941: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
10942: $check = ' checked="checked" ';
10943: }
10944: }
10945: }
1.325 raeburn 10946: } elsif ($context ne 'lti') {
1.228 raeburn 10947: if ($role eq 'st') {
10948: if (ref($settings) ne 'HASH') {
10949: $check = ' checked="checked" ';
10950: }
1.33 raeburn 10951: }
10952: }
10953: }
10954: $output .= '<td class="LC_left_item">'.
1.228 raeburn 10955: '<span class="LC_nobreak">';
1.325 raeburn 10956: my $prefix = 'canmodify';
1.228 raeburn 10957: if ($role eq 'emailusername') {
10958: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
10959: $checks{$fields[$i]} = 'omit';
10960: }
10961: foreach my $option ('required','optional','omit') {
10962: my $checked='';
10963: if ($checks{$fields[$i]} eq $option) {
10964: $checked='checked="checked" ';
10965: }
10966: $output .= '<label>'.
1.325 raeburn 10967: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 10968: &mt($option).'</label>'.(' ' x2);
10969: }
10970: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
10971: } else {
1.325 raeburn 10972: if ($context eq 'lti') {
10973: $prefix = 'lti';
1.357 raeburn 10974: } elsif ($context eq 'privacy') {
10975: $prefix = 'privacy';
1.325 raeburn 10976: }
1.228 raeburn 10977: $output .= '<label>'.
1.325 raeburn 10978: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 10979: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
10980: '</label>';
10981: }
10982: $output .= '</span></td>';
1.33 raeburn 10983: }
1.305 raeburn 10984: $rem = $total%$numinrow;
10985: my $colsleft;
10986: if ($rem) {
10987: $colsleft = $numinrow - $rem;
10988: }
10989: if ($colsleft > 1) {
1.33 raeburn 10990: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10991: ' </td>';
10992: } elsif ($colsleft == 1) {
10993: $output .= '<td class="LC_left_item"> </td>';
10994: }
10995: $output .= '</tr></table></td></tr>';
10996: return $output;
10997: }
1.28 raeburn 10998:
1.93 raeburn 10999: sub insttypes_row {
1.305 raeburn 11000: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
11001: $customcss,$rowstyle) = @_;
1.93 raeburn 11002: my %lt = &Apache::lonlocal::texthash (
11003: cansearch => 'Users allowed to search',
11004: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 11005: lockablenames => 'User preference to lock name',
1.305 raeburn 11006: selfassign => 'Self-reportable affiliations',
1.315 raeburn 11007: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 11008: );
11009: my $showdom;
11010: if ($context eq 'cansearch') {
11011: $showdom = ' ('.$dom.')';
11012: }
1.165 raeburn 11013: my $class = 'LC_left_item';
11014: if ($context eq 'statustocreate') {
11015: $class = 'LC_right_item';
11016: }
1.305 raeburn 11017: my $css_class;
11018: if ($$rowtotal%2) {
11019: $css_class = 'LC_odd_row';
11020: }
11021: if ($customcss) {
11022: $css_class .= ' '.$customcss;
11023: }
11024: $css_class =~ s/^\s+//;
11025: if ($css_class) {
11026: $css_class = ' class="'.$css_class.'"';
11027: }
11028: if ($rowstyle) {
11029: $css_class .= ' style="'.$rowstyle.'"';
11030: }
11031: if ($onclick) {
11032: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 11033: }
11034: my $output = '<tr'.$css_class.'>'.
11035: '<td>'.$lt{$context}.$showdom.
11036: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 11037: my $rem;
11038: if (ref($types) eq 'ARRAY') {
11039: for (my $i=0; $i<@{$types}; $i++) {
11040: if (defined($usertypes->{$types->[$i]})) {
11041: my $rem = $i%($numinrow);
11042: if ($rem == 0) {
11043: if ($i > 0) {
11044: $output .= '</tr>';
11045: }
11046: $output .= '<tr>';
1.23 raeburn 11047: }
1.26 raeburn 11048: my $check = ' ';
1.99 raeburn 11049: if (ref($settings) eq 'HASH') {
11050: if (ref($settings->{$context}) eq 'ARRAY') {
11051: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
11052: $check = ' checked="checked" ';
11053: }
1.315 raeburn 11054: } elsif (ref($settings->{$context}) eq 'HASH') {
11055: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
11056: $check = ' checked="checked" ';
11057: }
1.99 raeburn 11058: } elsif ($context eq 'statustocreate') {
1.26 raeburn 11059: $check = ' checked="checked" ';
11060: }
1.23 raeburn 11061: }
1.26 raeburn 11062: $output .= '<td class="LC_left_item">'.
11063: '<span class="LC_nobreak"><label>'.
1.93 raeburn 11064: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 11065: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 11066: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 11067: }
11068: }
1.26 raeburn 11069: $rem = @{$types}%($numinrow);
1.23 raeburn 11070: }
11071: my $colsleft = $numinrow - $rem;
1.315 raeburn 11072: if ($context eq 'overrides') {
11073: if ($colsleft > 1) {
11074: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
11075: } else {
11076: $output .= '<td class="LC_left_item">';
11077: }
11078: $output .= ' ';
1.23 raeburn 11079: } else {
1.334 raeburn 11080: if ($rem == 0) {
1.315 raeburn 11081: $output .= '<tr>';
11082: }
11083: if ($colsleft > 1) {
11084: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
11085: } else {
11086: $output .= '<td class="LC_left_item">';
11087: }
11088: my $defcheck = ' ';
11089: if (ref($settings) eq 'HASH') {
11090: if (ref($settings->{$context}) eq 'ARRAY') {
11091: if (grep(/^default$/,@{$settings->{$context}})) {
11092: $defcheck = ' checked="checked" ';
11093: }
11094: } elsif ($context eq 'statustocreate') {
1.99 raeburn 11095: $defcheck = ' checked="checked" ';
11096: }
1.26 raeburn 11097: }
1.315 raeburn 11098: $output .= '<span class="LC_nobreak"><label>'.
11099: '<input type="checkbox" name="'.$context.'" '.
11100: 'value="default"'.$defcheck.$onclick.' />'.
11101: $othertitle.'</label></span>';
1.23 raeburn 11102: }
1.315 raeburn 11103: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 11104: return $output;
1.23 raeburn 11105: }
11106:
11107: sub sorted_searchtitles {
11108: my %searchtitles = &Apache::lonlocal::texthash(
11109: 'uname' => 'username',
11110: 'lastname' => 'last name',
11111: 'lastfirst' => 'last name, first name',
11112: );
11113: my @titleorder = ('uname','lastname','lastfirst');
11114: return (\%searchtitles,\@titleorder);
11115: }
11116:
1.25 raeburn 11117: sub sorted_searchtypes {
11118: my %srchtypes_desc = (
11119: exact => 'is exact match',
11120: contains => 'contains ..',
11121: begins => 'begins with ..',
11122: );
11123: my @srchtypeorder = ('exact','begins','contains');
11124: return (\%srchtypes_desc,\@srchtypeorder);
11125: }
11126:
1.3 raeburn 11127: sub usertype_update_row {
11128: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
11129: my $datatable;
11130: my $numinrow = 4;
11131: foreach my $type (@{$types}) {
11132: if (defined($usertypes->{$type})) {
11133: $$rownums ++;
11134: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
11135: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
11136: '</td><td class="LC_left_item"><table>';
11137: for (my $i=0; $i<@{$fields}; $i++) {
11138: my $rem = $i%($numinrow);
11139: if ($rem == 0) {
11140: if ($i > 0) {
11141: $datatable .= '</tr>';
11142: }
11143: $datatable .= '<tr>';
11144: }
11145: my $check = ' ';
1.39 raeburn 11146: if (ref($settings) eq 'HASH') {
11147: if (ref($settings->{'fields'}) eq 'HASH') {
11148: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
11149: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
11150: $check = ' checked="checked" ';
11151: }
1.3 raeburn 11152: }
11153: }
11154: }
11155:
11156: if ($i == @{$fields}-1) {
11157: my $colsleft = $numinrow - $rem;
11158: if ($colsleft > 1) {
11159: $datatable .= '<td colspan="'.$colsleft.'">';
11160: } else {
11161: $datatable .= '<td>';
11162: }
11163: } else {
11164: $datatable .= '<td>';
11165: }
1.8 raeburn 11166: $datatable .= '<span class="LC_nobreak"><label>'.
11167: '<input type="checkbox" name="updateable_'.$type.
11168: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
11169: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 11170: }
11171: $datatable .= '</tr></table></td></tr>';
11172: }
11173: }
11174: return $datatable;
1.1 raeburn 11175: }
11176:
11177: sub modify_login {
1.205 raeburn 11178: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 11179: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
11180: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
11181: %title = ( coursecatalog => 'Display course catalog',
11182: adminmail => 'Display administrator E-mail address',
1.188 raeburn 11183: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 11184: newuser => 'Link for visitors to create a user account',
11185: loginheader => 'Log-in box header');
11186: @offon = ('off','on');
1.112 raeburn 11187: if (ref($domconfig{login}) eq 'HASH') {
11188: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
11189: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
11190: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
11191: }
11192: }
11193: }
1.9 raeburn 11194: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
11195: \%domconfig,\%loginhash);
1.188 raeburn 11196: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 11197: foreach my $item (@toggles) {
11198: $loginhash{login}{$item} = $env{'form.'.$item};
11199: }
1.41 raeburn 11200: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 11201: if (ref($colchanges{'login'}) eq 'HASH') {
11202: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
11203: \%loginhash);
11204: }
1.110 raeburn 11205:
1.149 raeburn 11206: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 11207: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 11208: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 11209: if (keys(%servers) > 1) {
11210: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 11211: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
11212: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
11213: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
11214: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
11215: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
11216: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11217: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
11218: $changes{'loginvia'}{$lonhost} = 1;
11219: } else {
11220: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
11221: $changes{'loginvia'}{$lonhost} = 1;
11222: }
11223: } else {
11224: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11225: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
11226: $changes{'loginvia'}{$lonhost} = 1;
11227: }
11228: }
11229: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
11230: foreach my $item (@loginvia_attribs) {
11231: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
11232: }
11233: } else {
11234: foreach my $item (@loginvia_attribs) {
11235: my $new = $env{'form.'.$lonhost.'_'.$item};
11236: if (($item eq 'serverpath') && ($new eq 'custom')) {
11237: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
11238: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
11239: $new = '/';
11240: }
11241: }
11242: if (($item eq 'custompath') &&
11243: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
11244: $new = '';
11245: }
11246: if ($new ne $curr_loginvia{$lonhost}{$item}) {
11247: $changes{'loginvia'}{$lonhost} = 1;
11248: }
11249: if ($item eq 'exempt') {
1.256 raeburn 11250: $new = &check_exempt_addresses($new);
1.128 raeburn 11251: }
11252: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
11253: }
11254: }
1.112 raeburn 11255: } else {
1.128 raeburn 11256: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11257: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 11258: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 11259: foreach my $item (@loginvia_attribs) {
11260: my $new = $env{'form.'.$lonhost.'_'.$item};
11261: if (($item eq 'serverpath') && ($new eq 'custom')) {
11262: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
11263: $new = '/';
11264: }
11265: }
11266: if (($item eq 'custompath') &&
11267: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
11268: $new = '';
11269: }
11270: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
11271: }
1.110 raeburn 11272: }
11273: }
11274: }
11275: }
1.119 raeburn 11276:
1.168 raeburn 11277: my $servadm = $r->dir_config('lonAdmEMail');
11278: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
11279: if (ref($domconfig{'login'}) eq 'HASH') {
11280: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
11281: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
11282: if ($lang eq 'nolang') {
11283: push(@currlangs,$lang);
11284: } elsif (defined($langchoices{$lang})) {
11285: push(@currlangs,$lang);
11286: } else {
11287: next;
11288: }
11289: }
11290: }
11291: }
11292: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
11293: if (@currlangs > 0) {
11294: foreach my $lang (@currlangs) {
11295: if (grep(/^\Q$lang\E$/,@delurls)) {
11296: $changes{'helpurl'}{$lang} = 1;
11297: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
11298: $changes{'helpurl'}{$lang} = 1;
11299: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
11300: push(@newlangs,$lang);
11301: } else {
11302: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
11303: }
11304: }
11305: }
11306: unless (grep(/^nolang$/,@currlangs)) {
11307: if ($env{'form.loginhelpurl_nolang.filename'}) {
11308: $changes{'helpurl'}{'nolang'} = 1;
11309: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
11310: push(@newlangs,'nolang');
11311: }
11312: }
11313: if ($env{'form.loginhelpurl_add_lang'}) {
11314: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
11315: ($env{'form.loginhelpurl_add_file.filename'})) {
11316: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
11317: $addedfile = $env{'form.loginhelpurl_add_lang'};
11318: }
11319: }
11320: if ((@newlangs > 0) || ($addedfile)) {
11321: my $error;
11322: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11323: if ($configuserok eq 'ok') {
11324: if ($switchserver) {
11325: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
11326: } elsif ($author_ok eq 'ok') {
11327: my @allnew = @newlangs;
11328: if ($addedfile ne '') {
11329: push(@allnew,$addedfile);
11330: }
11331: foreach my $lang (@allnew) {
11332: my $formelem = 'loginhelpurl_'.$lang;
11333: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
11334: $formelem = 'loginhelpurl_add_file';
11335: }
11336: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
11337: "help/$lang",'','',$newfile{$lang});
11338: if ($result eq 'ok') {
11339: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
11340: $changes{'helpurl'}{$lang} = 1;
11341: } else {
11342: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
11343: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 11344: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 11345: (!grep(/^\Q$lang\E$/,@delurls))) {
11346: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
11347: }
11348: }
11349: }
11350: } else {
11351: $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);
11352: }
11353: } else {
11354: $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);
11355: }
11356: if ($error) {
11357: &Apache::lonnet::logthis($error);
11358: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11359: }
11360: }
1.256 raeburn 11361:
11362: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
11363: if (ref($domconfig{'login'}) eq 'HASH') {
11364: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
11365: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
11366: if ($domservers{$lonhost}) {
11367: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
11368: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 11369: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 11370: }
11371: }
11372: }
11373: }
11374: }
11375: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
11376: foreach my $lonhost (sort(keys(%domservers))) {
11377: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
11378: $changes{'headtag'}{$lonhost} = 1;
11379: } else {
11380: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
11381: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
11382: }
11383: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
11384: push(@newhosts,$lonhost);
11385: } elsif ($currheadtagurls{$lonhost}) {
11386: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
11387: if ($currexempt{$lonhost}) {
1.289 raeburn 11388: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 11389: $changes{'headtag'}{$lonhost} = 1;
11390: }
11391: } elsif ($possexempt{$lonhost}) {
11392: $changes{'headtag'}{$lonhost} = 1;
11393: }
11394: if ($possexempt{$lonhost}) {
11395: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
11396: }
11397: }
11398: }
11399: }
11400: if (@newhosts) {
11401: my $error;
11402: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11403: if ($configuserok eq 'ok') {
11404: if ($switchserver) {
11405: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
11406: } elsif ($author_ok eq 'ok') {
11407: foreach my $lonhost (@newhosts) {
11408: my $formelem = 'loginheadtag_'.$lonhost;
11409: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
11410: "login/headtag/$lonhost",'','',
11411: $env{'form.loginheadtag_'.$lonhost.'.filename'});
11412: if ($result eq 'ok') {
11413: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
11414: $changes{'headtag'}{$lonhost} = 1;
11415: if ($possexempt{$lonhost}) {
11416: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
11417: }
11418: } else {
11419: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
11420: $newheadtagurls{$lonhost},$result);
11421: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
11422: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
11423: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
11424: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
11425: }
11426: }
11427: }
11428: } else {
11429: $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);
11430: }
11431: } else {
11432: $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);
11433: }
11434: if ($error) {
11435: &Apache::lonnet::logthis($error);
11436: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11437: }
11438: }
1.169 raeburn 11439: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 11440:
11441: my $defaulthelpfile = '/adm/loginproblems.html';
11442: my $defaulttext = &mt('Default in use');
11443:
1.1 raeburn 11444: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
11445: $dom);
11446: if ($putresult eq 'ok') {
1.188 raeburn 11447: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 11448: my %defaultchecked = (
11449: 'coursecatalog' => 'on',
1.188 raeburn 11450: 'helpdesk' => 'on',
1.42 raeburn 11451: 'adminmail' => 'off',
1.43 raeburn 11452: 'newuser' => 'off',
1.42 raeburn 11453: );
1.55 raeburn 11454: if (ref($domconfig{'login'}) eq 'HASH') {
11455: foreach my $item (@toggles) {
11456: if ($defaultchecked{$item} eq 'on') {
11457: if (($domconfig{'login'}{$item} eq '0') &&
11458: ($env{'form.'.$item} eq '1')) {
11459: $changes{$item} = 1;
11460: } elsif (($domconfig{'login'}{$item} eq '' ||
11461: $domconfig{'login'}{$item} eq '1') &&
11462: ($env{'form.'.$item} eq '0')) {
11463: $changes{$item} = 1;
11464: }
11465: } elsif ($defaultchecked{$item} eq 'off') {
11466: if (($domconfig{'login'}{$item} eq '1') &&
11467: ($env{'form.'.$item} eq '0')) {
11468: $changes{$item} = 1;
11469: } elsif (($domconfig{'login'}{$item} eq '' ||
11470: $domconfig{'login'}{$item} eq '0') &&
11471: ($env{'form.'.$item} eq '1')) {
11472: $changes{$item} = 1;
11473: }
1.42 raeburn 11474: }
11475: }
1.41 raeburn 11476: }
1.6 raeburn 11477: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 11478: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 11479: if (ref($lastactref) eq 'HASH') {
11480: $lastactref->{'domainconfig'} = 1;
11481: }
1.1 raeburn 11482: $resulttext = &mt('Changes made:').'<ul>';
11483: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 11484: if ($item eq 'loginvia') {
1.112 raeburn 11485: if (ref($changes{$item}) eq 'HASH') {
11486: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
11487: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 11488: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
11489: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
11490: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
11491: $protocol = 'http' if ($protocol ne 'https');
11492: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
11493:
11494: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
11495: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
11496: } else {
11497: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
11498: }
11499: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
11500: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
11501: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
11502: }
11503: $resulttext .= '</li>';
11504: } else {
11505: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
11506: }
1.112 raeburn 11507: } else {
1.128 raeburn 11508: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 11509: }
11510: }
1.128 raeburn 11511: $resulttext .= '</ul></li>';
1.112 raeburn 11512: }
1.168 raeburn 11513: } elsif ($item eq 'helpurl') {
11514: if (ref($changes{$item}) eq 'HASH') {
11515: foreach my $lang (sort(keys(%{$changes{$item}}))) {
11516: if (grep(/^\Q$lang\E$/,@delurls)) {
11517: my ($chg,$link);
11518: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
11519: if ($lang eq 'nolang') {
11520: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
11521: } else {
11522: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
11523: }
11524: $resulttext .= '<li>'.$chg.'</li>';
11525: } else {
11526: my $chg;
11527: if ($lang eq 'nolang') {
11528: $chg = &mt('custom log-in help file for no preferred language');
11529: } else {
11530: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
11531: }
11532: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
11533: $loginhash{'login'}{'helpurl'}{$lang}.
11534: '?inhibitmenu=yes',$chg,600,500).
11535: '</li>';
11536: }
11537: }
11538: }
1.256 raeburn 11539: } elsif ($item eq 'headtag') {
11540: if (ref($changes{$item}) eq 'HASH') {
11541: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
11542: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
11543: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
11544: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
11545: $resulttext .= '<li><a href="'.
11546: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
11547: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
11548: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
11549: if ($possexempt{$lonhost}) {
11550: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
11551: } else {
11552: $resulttext .= &mt('included for any client IP');
11553: }
11554: $resulttext .= '</li>';
11555: }
11556: }
11557: }
1.169 raeburn 11558: } elsif ($item eq 'captcha') {
11559: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 11560: my $chgtxt;
1.169 raeburn 11561: if ($loginhash{'login'}{$item} eq 'notused') {
11562: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
11563: } else {
11564: my %captchas = &captcha_phrases();
11565: if ($captchas{$loginhash{'login'}{$item}}) {
11566: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
11567: } else {
11568: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
11569: }
11570: }
11571: $resulttext .= '<li>'.$chgtxt.'</li>';
11572: }
11573: } elsif ($item eq 'recaptchakeys') {
11574: if (ref($loginhash{'login'}) eq 'HASH') {
11575: my ($privkey,$pubkey);
11576: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
11577: $pubkey = $loginhash{'login'}{$item}{'public'};
11578: $privkey = $loginhash{'login'}{$item}{'private'};
11579: }
11580: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
11581: if (!$pubkey) {
11582: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
11583: } else {
11584: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
11585: }
11586: if (!$privkey) {
11587: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
11588: } else {
1.251 raeburn 11589: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 11590: }
11591: $chgtxt .= '</ul>';
11592: $resulttext .= '<li>'.$chgtxt.'</li>';
11593: }
1.269 raeburn 11594: } elsif ($item eq 'recaptchaversion') {
11595: if (ref($loginhash{'login'}) eq 'HASH') {
11596: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 11597: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 11598: '</li>';
11599: }
11600: }
1.41 raeburn 11601: } else {
11602: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
11603: }
1.1 raeburn 11604: }
1.6 raeburn 11605: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 11606: } else {
11607: $resulttext = &mt('No changes made to log-in page settings');
11608: }
11609: } else {
1.11 albertel 11610: $resulttext = '<span class="LC_error">'.
11611: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11612: }
1.6 raeburn 11613: if ($errors) {
1.9 raeburn 11614: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 11615: $errors.'</ul>';
11616: }
11617: return $resulttext;
11618: }
11619:
1.256 raeburn 11620: sub check_exempt_addresses {
11621: my ($iplist) = @_;
11622: $iplist =~ s/^\s+//;
11623: $iplist =~ s/\s+$//;
11624: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
11625: my (@okips,$new);
11626: foreach my $ip (@poss_ips) {
11627: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
11628: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
11629: push(@okips,$ip);
11630: }
11631: }
11632: }
11633: if (@okips > 0) {
11634: $new = join(',',@okips);
11635: } else {
11636: $new = '';
11637: }
11638: return $new;
11639: }
11640:
1.6 raeburn 11641: sub color_font_choices {
11642: my %choices =
11643: &Apache::lonlocal::texthash (
11644: img => "Header",
11645: bgs => "Background colors",
11646: links => "Link colors",
1.55 raeburn 11647: images => "Images",
1.6 raeburn 11648: font => "Font color",
1.201 raeburn 11649: fontmenu => "Font menu",
1.76 raeburn 11650: pgbg => "Page",
1.6 raeburn 11651: tabbg => "Header",
11652: sidebg => "Border",
11653: link => "Link",
11654: alink => "Active link",
11655: vlink => "Visited link",
11656: );
11657: return %choices;
11658: }
11659:
11660: sub modify_rolecolors {
1.205 raeburn 11661: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 11662: my ($resulttext,%rolehash);
11663: $rolehash{'rolecolors'} = {};
1.55 raeburn 11664: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
11665: if ($domconfig{'rolecolors'} eq '') {
11666: $domconfig{'rolecolors'} = {};
11667: }
11668: }
1.9 raeburn 11669: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 11670: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
11671: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
11672: $dom);
11673: if ($putresult eq 'ok') {
11674: if (keys(%changes) > 0) {
1.41 raeburn 11675: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 11676: if (ref($lastactref) eq 'HASH') {
11677: $lastactref->{'domainconfig'} = 1;
11678: }
1.6 raeburn 11679: $resulttext = &display_colorchgs($dom,\%changes,$roles,
11680: $rolehash{'rolecolors'});
11681: } else {
11682: $resulttext = &mt('No changes made to default color schemes');
11683: }
11684: } else {
1.11 albertel 11685: $resulttext = '<span class="LC_error">'.
11686: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 11687: }
11688: if ($errors) {
11689: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11690: $errors.'</ul>';
11691: }
11692: return $resulttext;
11693: }
11694:
11695: sub modify_colors {
1.9 raeburn 11696: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 11697: my (%changes,%choices);
1.51 raeburn 11698: my @bgs;
1.6 raeburn 11699: my @links = ('link','alink','vlink');
1.41 raeburn 11700: my @logintext;
1.6 raeburn 11701: my @images;
11702: my $servadm = $r->dir_config('lonAdmEMail');
11703: my $errors;
1.200 raeburn 11704: my %defaults;
1.6 raeburn 11705: foreach my $role (@{$roles}) {
11706: if ($role eq 'login') {
1.12 raeburn 11707: %choices = &login_choices();
1.41 raeburn 11708: @logintext = ('textcol','bgcol');
1.12 raeburn 11709: } else {
11710: %choices = &color_font_choices();
11711: }
11712: if ($role eq 'login') {
1.41 raeburn 11713: @images = ('img','logo','domlogo','login');
1.51 raeburn 11714: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 11715: } else {
11716: @images = ('img');
1.200 raeburn 11717: @bgs = ('pgbg','tabbg','sidebg');
11718: }
11719: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
11720: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
11721: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
11722: }
11723: if ($role eq 'login') {
11724: foreach my $item (@logintext) {
1.234 raeburn 11725: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
11726: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
11727: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
11728: }
11729: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 11730: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
11731: }
11732: }
11733: } else {
1.234 raeburn 11734: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
11735: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
11736: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
11737: }
11738: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 11739: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
11740: }
1.6 raeburn 11741: }
1.200 raeburn 11742: foreach my $item (@bgs) {
1.234 raeburn 11743: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
11744: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
11745: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
11746: }
11747: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 11748: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
11749: }
11750: }
11751: foreach my $item (@links) {
1.234 raeburn 11752: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
11753: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
11754: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
11755: }
11756: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 11757: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
11758: }
1.6 raeburn 11759: }
1.46 raeburn 11760: my ($configuserok,$author_ok,$switchserver) =
11761: &config_check($dom,$confname,$servadm);
1.9 raeburn 11762: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 11763: if (ref($domconfig->{$role}) ne 'HASH') {
11764: $domconfig->{$role} = {};
11765: }
1.8 raeburn 11766: foreach my $img (@images) {
1.70 raeburn 11767: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
11768: if (defined($env{'form.login_showlogo_'.$img})) {
11769: $confhash->{$role}{'showlogo'}{$img} = 1;
11770: } else {
11771: $confhash->{$role}{'showlogo'}{$img} = 0;
11772: }
11773: }
1.18 albertel 11774: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
11775: && !defined($domconfig->{$role}{$img})
11776: && !$env{'form.'.$role.'_del_'.$img}
11777: && $env{'form.'.$role.'_import_'.$img}) {
11778: # import the old configured image from the .tab setting
11779: # if they haven't provided a new one
11780: $domconfig->{$role}{$img} =
11781: $env{'form.'.$role.'_import_'.$img};
11782: }
1.6 raeburn 11783: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 11784: my $error;
1.6 raeburn 11785: if ($configuserok eq 'ok') {
1.9 raeburn 11786: if ($switchserver) {
1.12 raeburn 11787: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 11788: } else {
11789: if ($author_ok eq 'ok') {
11790: my ($result,$logourl) =
11791: &publishlogo($r,'upload',$role.'_'.$img,
11792: $dom,$confname,$img,$width,$height);
11793: if ($result eq 'ok') {
11794: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 11795: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 11796: } else {
1.12 raeburn 11797: $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 11798: }
11799: } else {
1.46 raeburn 11800: $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 11801: }
11802: }
11803: } else {
1.46 raeburn 11804: $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 11805: }
11806: if ($error) {
1.8 raeburn 11807: &Apache::lonnet::logthis($error);
1.11 albertel 11808: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 11809: }
11810: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 11811: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
11812: my $error;
11813: if ($configuserok eq 'ok') {
11814: # is confname an author?
11815: if ($switchserver eq '') {
11816: if ($author_ok eq 'ok') {
11817: my ($result,$logourl) =
11818: &publishlogo($r,'copy',$domconfig->{$role}{$img},
11819: $dom,$confname,$img,$width,$height);
11820: if ($result eq 'ok') {
11821: $confhash->{$role}{$img} = $logourl;
1.18 albertel 11822: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 11823: }
11824: }
11825: }
11826: }
1.6 raeburn 11827: }
11828: }
11829: }
11830: if (ref($domconfig) eq 'HASH') {
11831: if (ref($domconfig->{$role}) eq 'HASH') {
11832: foreach my $img (@images) {
11833: if ($domconfig->{$role}{$img} ne '') {
11834: if ($env{'form.'.$role.'_del_'.$img}) {
11835: $confhash->{$role}{$img} = '';
1.12 raeburn 11836: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 11837: } else {
1.9 raeburn 11838: if ($confhash->{$role}{$img} eq '') {
11839: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
11840: }
1.6 raeburn 11841: }
11842: } else {
11843: if ($env{'form.'.$role.'_del_'.$img}) {
11844: $confhash->{$role}{$img} = '';
1.12 raeburn 11845: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 11846: }
11847: }
1.70 raeburn 11848: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
11849: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
11850: if ($confhash->{$role}{'showlogo'}{$img} ne
11851: $domconfig->{$role}{'showlogo'}{$img}) {
11852: $changes{$role}{'showlogo'}{$img} = 1;
11853: }
11854: } else {
11855: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
11856: $changes{$role}{'showlogo'}{$img} = 1;
11857: }
11858: }
11859: }
11860: }
1.6 raeburn 11861: if ($domconfig->{$role}{'font'} ne '') {
11862: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
11863: $changes{$role}{'font'} = 1;
11864: }
11865: } else {
11866: if ($confhash->{$role}{'font'}) {
11867: $changes{$role}{'font'} = 1;
11868: }
11869: }
1.107 raeburn 11870: if ($role ne 'login') {
11871: if ($domconfig->{$role}{'fontmenu'} ne '') {
11872: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
11873: $changes{$role}{'fontmenu'} = 1;
11874: }
11875: } else {
11876: if ($confhash->{$role}{'fontmenu'}) {
11877: $changes{$role}{'fontmenu'} = 1;
11878: }
1.97 tempelho 11879: }
11880: }
1.6 raeburn 11881: foreach my $item (@bgs) {
11882: if ($domconfig->{$role}{$item} ne '') {
11883: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11884: $changes{$role}{'bgs'}{$item} = 1;
11885: }
11886: } else {
11887: if ($confhash->{$role}{$item}) {
11888: $changes{$role}{'bgs'}{$item} = 1;
11889: }
11890: }
11891: }
11892: foreach my $item (@links) {
11893: if ($domconfig->{$role}{$item} ne '') {
11894: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11895: $changes{$role}{'links'}{$item} = 1;
11896: }
11897: } else {
11898: if ($confhash->{$role}{$item}) {
11899: $changes{$role}{'links'}{$item} = 1;
11900: }
11901: }
11902: }
1.41 raeburn 11903: foreach my $item (@logintext) {
11904: if ($domconfig->{$role}{$item} ne '') {
11905: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11906: $changes{$role}{'logintext'}{$item} = 1;
11907: }
11908: } else {
11909: if ($confhash->{$role}{$item}) {
11910: $changes{$role}{'logintext'}{$item} = 1;
11911: }
11912: }
11913: }
1.6 raeburn 11914: } else {
11915: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 11916: \@logintext,$confhash,\%changes);
1.6 raeburn 11917: }
11918: } else {
11919: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 11920: \@logintext,$confhash,\%changes);
1.6 raeburn 11921: }
11922: }
11923: return ($errors,%changes);
11924: }
11925:
1.46 raeburn 11926: sub config_check {
11927: my ($dom,$confname,$servadm) = @_;
11928: my ($configuserok,$author_ok,$switchserver,%currroles);
11929: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
11930: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
11931: $confname,$servadm);
11932: if ($configuserok eq 'ok') {
11933: $switchserver = &check_switchserver($dom,$confname);
11934: if ($switchserver eq '') {
11935: $author_ok = &check_authorstatus($dom,$confname,%currroles);
11936: }
11937: }
11938: return ($configuserok,$author_ok,$switchserver);
11939: }
11940:
1.6 raeburn 11941: sub default_change_checker {
1.41 raeburn 11942: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 11943: foreach my $item (@{$links}) {
11944: if ($confhash->{$role}{$item}) {
11945: $changes->{$role}{'links'}{$item} = 1;
11946: }
11947: }
11948: foreach my $item (@{$bgs}) {
11949: if ($confhash->{$role}{$item}) {
11950: $changes->{$role}{'bgs'}{$item} = 1;
11951: }
11952: }
1.41 raeburn 11953: foreach my $item (@{$logintext}) {
11954: if ($confhash->{$role}{$item}) {
11955: $changes->{$role}{'logintext'}{$item} = 1;
11956: }
11957: }
1.6 raeburn 11958: foreach my $img (@{$images}) {
11959: if ($env{'form.'.$role.'_del_'.$img}) {
11960: $confhash->{$role}{$img} = '';
1.12 raeburn 11961: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 11962: }
1.70 raeburn 11963: if ($role eq 'login') {
11964: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
11965: $changes->{$role}{'showlogo'}{$img} = 1;
11966: }
11967: }
1.6 raeburn 11968: }
11969: if ($confhash->{$role}{'font'}) {
11970: $changes->{$role}{'font'} = 1;
11971: }
1.48 raeburn 11972: }
1.6 raeburn 11973:
11974: sub display_colorchgs {
11975: my ($dom,$changes,$roles,$confhash) = @_;
11976: my (%choices,$resulttext);
11977: if (!grep(/^login$/,@{$roles})) {
11978: $resulttext = &mt('Changes made:').'<br />';
11979: }
11980: foreach my $role (@{$roles}) {
11981: if ($role eq 'login') {
11982: %choices = &login_choices();
11983: } else {
11984: %choices = &color_font_choices();
11985: }
11986: if (ref($changes->{$role}) eq 'HASH') {
11987: if ($role ne 'login') {
11988: $resulttext .= '<h4>'.&mt($role).'</h4>';
11989: }
11990: foreach my $key (sort(keys(%{$changes->{$role}}))) {
11991: if ($role ne 'login') {
11992: $resulttext .= '<ul>';
11993: }
11994: if (ref($changes->{$role}{$key}) eq 'HASH') {
11995: if ($role ne 'login') {
11996: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
11997: }
11998: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 11999: if (($role eq 'login') && ($key eq 'showlogo')) {
12000: if ($confhash->{$role}{$key}{$item}) {
12001: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
12002: } else {
12003: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
12004: }
12005: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 12006: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
12007: } else {
1.12 raeburn 12008: my $newitem = $confhash->{$role}{$item};
12009: if ($key eq 'images') {
1.306 raeburn 12010: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 12011: }
12012: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 12013: }
12014: }
12015: if ($role ne 'login') {
12016: $resulttext .= '</ul></li>';
12017: }
12018: } else {
12019: if ($confhash->{$role}{$key} eq '') {
12020: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
12021: } else {
12022: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
12023: }
12024: }
12025: if ($role ne 'login') {
12026: $resulttext .= '</ul>';
12027: }
12028: }
12029: }
12030: }
1.3 raeburn 12031: return $resulttext;
1.1 raeburn 12032: }
12033:
1.9 raeburn 12034: sub thumb_dimensions {
12035: return ('200','50');
12036: }
12037:
1.16 raeburn 12038: sub check_dimensions {
12039: my ($inputfile) = @_;
12040: my ($fullwidth,$fullheight);
12041: if ($inputfile =~ m|^[/\w.\-]+$|) {
12042: if (open(PIPE,"identify $inputfile 2>&1 |")) {
12043: my $imageinfo = <PIPE>;
12044: if (!close(PIPE)) {
12045: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
12046: }
12047: chomp($imageinfo);
12048: my ($fullsize) =
1.21 raeburn 12049: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 12050: if ($fullsize) {
12051: ($fullwidth,$fullheight) = split(/x/,$fullsize);
12052: }
12053: }
12054: }
12055: return ($fullwidth,$fullheight);
12056: }
12057:
1.9 raeburn 12058: sub check_configuser {
12059: my ($uhome,$dom,$confname,$servadm) = @_;
12060: my ($configuserok,%currroles);
12061: if ($uhome eq 'no_host') {
12062: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 12063: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 12064: $configuserok =
12065: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
12066: $configpass,'','','','','',undef,$servadm);
12067: } else {
12068: $configuserok = 'ok';
12069: %currroles =
12070: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
12071: }
12072: return ($configuserok,%currroles);
12073: }
12074:
12075: sub check_authorstatus {
12076: my ($dom,$confname,%currroles) = @_;
12077: my $author_ok;
1.40 raeburn 12078: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 12079: my $start = time;
12080: my $end = 0;
12081: $author_ok =
12082: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 12083: 'au',$end,$start,'','','domconfig');
1.9 raeburn 12084: } else {
12085: $author_ok = 'ok';
12086: }
12087: return $author_ok;
12088: }
12089:
12090: sub publishlogo {
1.46 raeburn 12091: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 12092: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 12093: if ($action eq 'upload') {
12094: $fname=$env{'form.'.$formname.'.filename'};
12095: chop($env{'form.'.$formname});
12096: } else {
12097: ($fname) = ($formname =~ /([^\/]+)$/);
12098: }
1.46 raeburn 12099: if ($savefileas ne '') {
12100: $fname = $savefileas;
12101: }
1.9 raeburn 12102: $fname=&Apache::lonnet::clean_filename($fname);
12103: # See if there is anything left
12104: unless ($fname) { return ('error: no uploaded file'); }
12105: $fname="$subdir/$fname";
1.210 raeburn 12106: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 12107: my $filepath="$docroot/priv";
12108: my $relpath = "$dom/$confname";
1.9 raeburn 12109: my ($fnamepath,$file,$fetchthumb);
12110: $file=$fname;
12111: if ($fname=~m|/|) {
12112: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
12113: }
1.164 raeburn 12114: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 12115: my $count;
1.164 raeburn 12116: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 12117: $filepath.="/$parts[$count]";
12118: if ((-e $filepath)!=1) {
12119: mkdir($filepath,02770);
12120: }
12121: }
12122: # Check for bad extension and disallow upload
12123: if ($file=~/\.(\w+)$/ &&
12124: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
12125: $output =
1.207 bisitz 12126: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 12127: } elsif ($file=~/\.(\w+)$/ &&
12128: !defined(&Apache::loncommon::fileembstyle($1))) {
12129: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
12130: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 12131: $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 12132: } elsif (-d "$filepath/$file") {
1.195 bisitz 12133: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 12134: } else {
12135: my $source = $filepath.'/'.$file;
12136: my $logfile;
1.316 raeburn 12137: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 12138: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 12139: }
12140: print $logfile
12141: "\n================= Publish ".localtime()." ================\n".
12142: $env{'user.name'}.':'.$env{'user.domain'}."\n";
12143: # Save the file
1.316 raeburn 12144: if (!open(FH,">",$source)) {
1.9 raeburn 12145: &Apache::lonnet::logthis('Failed to create '.$source);
12146: return (&mt('Failed to create file'));
12147: }
12148: if ($action eq 'upload') {
12149: if (!print FH ($env{'form.'.$formname})) {
12150: &Apache::lonnet::logthis('Failed to write to '.$source);
12151: return (&mt('Failed to write file'));
12152: }
12153: } else {
12154: my $original = &Apache::lonnet::filelocation('',$formname);
12155: if(!copy($original,$source)) {
12156: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
12157: return (&mt('Failed to write file'));
12158: }
12159: }
12160: close(FH);
12161: chmod(0660, $source); # Permissions to rw-rw---.
12162:
12163: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
12164: my $copyfile=$targetdir.'/'.$file;
12165:
12166: my @parts=split(/\//,$targetdir);
12167: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
12168: for (my $count=5;$count<=$#parts;$count++) {
12169: $path.="/$parts[$count]";
12170: if (!-e $path) {
12171: print $logfile "\nCreating directory ".$path;
12172: mkdir($path,02770);
12173: }
12174: }
12175: my $versionresult;
12176: if (-e $copyfile) {
12177: $versionresult = &logo_versioning($targetdir,$file,$logfile);
12178: } else {
12179: $versionresult = 'ok';
12180: }
12181: if ($versionresult eq 'ok') {
12182: if (copy($source,$copyfile)) {
12183: print $logfile "\nCopied original source to ".$copyfile."\n";
12184: $output = 'ok';
12185: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 12186: push(@{$modified_urls},[$copyfile,$source]);
12187: my $metaoutput =
12188: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
12189: unless ($registered_cleanup) {
12190: my $handlers = $r->get_handlers('PerlCleanupHandler');
12191: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
12192: $registered_cleanup=1;
12193: }
1.9 raeburn 12194: } else {
12195: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
12196: $output = &mt('Failed to copy file to RES space').", $!";
12197: }
12198: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
12199: my $inputfile = $filepath.'/'.$file;
12200: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 12201: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
12202: if ($fullwidth ne '' && $fullheight ne '') {
12203: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
12204: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 12205: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
12206: system({$args[0]} @args);
1.16 raeburn 12207: chmod(0660, $filepath.'/tn-'.$file);
12208: if (-e $outfile) {
12209: my $copyfile=$targetdir.'/tn-'.$file;
12210: if (copy($outfile,$copyfile)) {
12211: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 12212: my $thumb_metaoutput =
12213: &write_metadata($dom,$confname,$formname,
12214: $targetdir,'tn-'.$file,$logfile);
12215: push(@{$modified_urls},[$copyfile,$outfile]);
12216: unless ($registered_cleanup) {
12217: my $handlers = $r->get_handlers('PerlCleanupHandler');
12218: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
12219: $registered_cleanup=1;
12220: }
1.267 raeburn 12221: $madethumb = 1;
1.16 raeburn 12222: } else {
12223: print $logfile "\nUnable to write ".$copyfile.
12224: ':'.$!."\n";
12225: }
12226: }
1.9 raeburn 12227: }
12228: }
12229: }
12230: } else {
12231: $output = $versionresult;
12232: }
12233: }
1.267 raeburn 12234: return ($output,$logourl,$madethumb);
1.9 raeburn 12235: }
12236:
12237: sub logo_versioning {
12238: my ($targetdir,$file,$logfile) = @_;
12239: my $target = $targetdir.'/'.$file;
12240: my ($maxversion,$fn,$extn,$output);
12241: $maxversion = 0;
12242: if ($file =~ /^(.+)\.(\w+)$/) {
12243: $fn=$1;
12244: $extn=$2;
12245: }
12246: opendir(DIR,$targetdir);
12247: while (my $filename=readdir(DIR)) {
12248: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
12249: $maxversion=($1>$maxversion)?$1:$maxversion;
12250: }
12251: }
12252: $maxversion++;
12253: print $logfile "\nCreating old version ".$maxversion."\n";
12254: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
12255: if (copy($target,$copyfile)) {
12256: print $logfile "Copied old target to ".$copyfile."\n";
12257: $copyfile=$copyfile.'.meta';
12258: if (copy($target.'.meta',$copyfile)) {
12259: print $logfile "Copied old target metadata to ".$copyfile."\n";
12260: $output = 'ok';
12261: } else {
12262: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
12263: $output = &mt('Failed to copy old meta').", $!, ";
12264: }
12265: } else {
12266: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
12267: $output = &mt('Failed to copy old target').", $!, ";
12268: }
12269: return $output;
12270: }
12271:
12272: sub write_metadata {
12273: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
12274: my (%metadatafields,%metadatakeys,$output);
12275: $metadatafields{'title'}=$formname;
12276: $metadatafields{'creationdate'}=time;
12277: $metadatafields{'lastrevisiondate'}=time;
12278: $metadatafields{'copyright'}='public';
12279: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
12280: $env{'user.domain'};
12281: $metadatafields{'authorspace'}=$confname.':'.$dom;
12282: $metadatafields{'domain'}=$dom;
12283: {
12284: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
12285: my $mfh;
1.316 raeburn 12286: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 12287: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 12288: unless ($_=~/\./) {
12289: my $unikey=$_;
12290: $unikey=~/^([A-Za-z]+)/;
12291: my $tag=$1;
12292: $tag=~tr/A-Z/a-z/;
12293: print $mfh "\n\<$tag";
12294: foreach (split(/\,/,$metadatakeys{$unikey})) {
12295: my $value=$metadatafields{$unikey.'.'.$_};
12296: $value=~s/\"/\'\'/g;
12297: print $mfh ' '.$_.'="'.$value.'"';
12298: }
12299: print $mfh '>'.
12300: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
12301: .'</'.$tag.'>';
12302: }
12303: }
12304: $output = 'ok';
12305: print $logfile "\nWrote metadata";
12306: close($mfh);
12307: } else {
12308: print $logfile "\nFailed to open metadata file";
1.9 raeburn 12309: $output = &mt('Could not write metadata');
12310: }
12311: }
1.155 raeburn 12312: return $output;
12313: }
12314:
12315: sub notifysubscribed {
12316: foreach my $targetsource (@{$modified_urls}){
12317: next unless (ref($targetsource) eq 'ARRAY');
12318: my ($target,$source)=@{$targetsource};
12319: if ($source ne '') {
1.316 raeburn 12320: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 12321: print $logfh "\nCleanup phase: Notifications\n";
12322: my @subscribed=&subscribed_hosts($target);
12323: foreach my $subhost (@subscribed) {
12324: print $logfh "\nNotifying host ".$subhost.':';
12325: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
12326: print $logfh $reply;
12327: }
12328: my @subscribedmeta=&subscribed_hosts("$target.meta");
12329: foreach my $subhost (@subscribedmeta) {
12330: print $logfh "\nNotifying host for metadata only ".$subhost.':';
12331: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
12332: $subhost);
12333: print $logfh $reply;
12334: }
12335: print $logfh "\n============ Done ============\n";
1.160 raeburn 12336: close($logfh);
1.155 raeburn 12337: }
12338: }
12339: }
12340: return OK;
12341: }
12342:
12343: sub subscribed_hosts {
12344: my ($target) = @_;
12345: my @subscribed;
1.316 raeburn 12346: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 12347: while (my $subline=<$fh>) {
12348: if ($subline =~ /^($match_lonid):/) {
12349: my $host = $1;
12350: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
12351: unless (grep(/^\Q$host\E$/,@subscribed)) {
12352: push(@subscribed,$host);
12353: }
12354: }
12355: }
12356: }
12357: }
12358: return @subscribed;
1.9 raeburn 12359: }
12360:
12361: sub check_switchserver {
12362: my ($dom,$confname) = @_;
12363: my ($allowed,$switchserver);
12364: my $home = &Apache::lonnet::homeserver($confname,$dom);
12365: if ($home eq 'no_host') {
12366: $home = &Apache::lonnet::domain($dom,'primary');
12367: }
12368: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 12369: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
12370: if (!$allowed) {
1.180 raeburn 12371: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 12372: }
12373: return $switchserver;
12374: }
12375:
1.1 raeburn 12376: sub modify_quotas {
1.216 raeburn 12377: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 12378: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 12379: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 12380: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
12381: $validationfieldsref);
1.86 raeburn 12382: if ($action eq 'quotas') {
12383: $context = 'tools';
1.163 raeburn 12384: } else {
1.86 raeburn 12385: $context = $action;
12386: }
12387: if ($context eq 'requestcourses') {
1.325 raeburn 12388: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 12389: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 12390: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
12391: %titles = &courserequest_titles();
12392: $toolregexp = join('|',@usertools);
12393: %conditions = &courserequest_conditions();
1.216 raeburn 12394: $confname = $dom.'-domainconfig';
12395: my $servadm = $r->dir_config('lonAdmEMail');
12396: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 12397: ($validationitemsref,$validationnamesref,$validationfieldsref) =
12398: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 12399: } elsif ($context eq 'requestauthor') {
12400: @usertools = ('author');
12401: %titles = &authorrequest_titles();
1.86 raeburn 12402: } else {
1.162 raeburn 12403: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 12404: %titles = &tool_titles();
1.86 raeburn 12405: }
1.212 raeburn 12406: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 12407: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 12408: foreach my $key (keys(%env)) {
1.101 raeburn 12409: if ($context eq 'requestcourses') {
12410: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
12411: my $item = $1;
12412: my $type = $2;
12413: if ($type =~ /^limit_(.+)/) {
12414: $limithash{$item}{$1} = $env{$key};
12415: } else {
12416: $confhash{$item}{$type} = $env{$key};
12417: }
12418: }
1.163 raeburn 12419: } elsif ($context eq 'requestauthor') {
12420: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
12421: $confhash{$1} = $env{$key};
12422: }
1.101 raeburn 12423: } else {
1.86 raeburn 12424: if ($key =~ /^form\.quota_(.+)$/) {
12425: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 12426: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
12427: $confhash{'authorquota'}{$1} = $env{$key};
12428: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 12429: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
12430: }
1.72 raeburn 12431: }
12432: }
1.163 raeburn 12433: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 12434: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 12435: @approvalnotify = sort(@approvalnotify);
12436: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 12437: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 12438: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
12439: foreach my $type (@hasuniquecode) {
12440: if (grep(/^\Q$type\E$/,@crstypes)) {
12441: $confhash{'uniquecode'}{$type} = 1;
12442: }
1.216 raeburn 12443: }
1.242 raeburn 12444: my (%newbook,%allpos);
1.216 raeburn 12445: if ($context eq 'requestcourses') {
1.242 raeburn 12446: foreach my $type ('textbooks','templates') {
12447: @{$allpos{$type}} = ();
12448: my $invalid;
12449: if ($type eq 'textbooks') {
12450: $invalid = &mt('Invalid LON-CAPA course for textbook');
12451: } else {
12452: $invalid = &mt('Invalid LON-CAPA course for template');
12453: }
12454: if ($env{'form.'.$type.'_addbook'}) {
12455: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
12456: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
12457: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
12458: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
12459: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
12460: } else {
12461: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
12462: my $position = $env{'form.'.$type.'_addbook_pos'};
12463: $position =~ s/\D+//g;
12464: if ($position ne '') {
12465: $allpos{$type}[$position] = $newbook{$type};
12466: }
1.216 raeburn 12467: }
1.242 raeburn 12468: } else {
12469: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 12470: }
12471: }
1.242 raeburn 12472: }
1.216 raeburn 12473: }
1.102 raeburn 12474: if (ref($domconfig{$action}) eq 'HASH') {
12475: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
12476: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
12477: $changes{'notify'}{'approval'} = 1;
12478: }
12479: } else {
1.144 raeburn 12480: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 12481: $changes{'notify'}{'approval'} = 1;
12482: }
12483: }
1.218 raeburn 12484: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
12485: if (ref($confhash{'uniquecode'}) eq 'HASH') {
12486: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
12487: unless ($confhash{'uniquecode'}{$crstype}) {
12488: $changes{'uniquecode'} = 1;
12489: }
12490: }
12491: unless ($changes{'uniquecode'}) {
12492: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
12493: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
12494: $changes{'uniquecode'} = 1;
12495: }
12496: }
12497: }
12498: } else {
12499: $changes{'uniquecode'} = 1;
12500: }
12501: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
12502: $changes{'uniquecode'} = 1;
1.216 raeburn 12503: }
12504: if ($context eq 'requestcourses') {
1.242 raeburn 12505: foreach my $type ('textbooks','templates') {
12506: if (ref($domconfig{$action}{$type}) eq 'HASH') {
12507: my %deletions;
12508: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
12509: if (@todelete) {
12510: map { $deletions{$_} = 1; } @todelete;
12511: }
12512: my %imgdeletions;
12513: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
12514: if (@todeleteimages) {
12515: map { $imgdeletions{$_} = 1; } @todeleteimages;
12516: }
12517: my $maxnum = $env{'form.'.$type.'_maxnum'};
12518: for (my $i=0; $i<=$maxnum; $i++) {
12519: my $itemid = $env{'form.'.$type.'_id_'.$i};
12520: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
12521: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
12522: if ($deletions{$key}) {
12523: if ($domconfig{$action}{$type}{$key}{'image'}) {
12524: #FIXME need to obsolete item in RES space
12525: }
12526: next;
12527: } else {
12528: my $newpos = $env{'form.'.$itemid};
12529: $newpos =~ s/\D+//g;
1.243 raeburn 12530: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 12531: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 12532: ($type eq 'templates'));
1.242 raeburn 12533: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
12534: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
12535: $changes{$type}{$key} = 1;
12536: }
12537: }
12538: $allpos{$type}[$newpos] = $key;
12539: }
12540: if ($imgdeletions{$key}) {
12541: $changes{$type}{$key} = 1;
1.216 raeburn 12542: #FIXME need to obsolete item in RES space
1.242 raeburn 12543: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
12544: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 12545: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
12546: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
12547: } else {
12548: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
12549: $cdom,$cnum,$type,$configuserok,
12550: $switchserver,$author_ok);
12551: if ($imgurl) {
12552: $confhash{$type}{$key}{'image'} = $imgurl;
12553: $changes{$type}{$key} = 1;
12554: }
12555: if ($error) {
12556: &Apache::lonnet::logthis($error);
12557: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12558: }
12559: }
1.242 raeburn 12560: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
12561: $confhash{$type}{$key}{'image'} =
12562: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 12563: }
12564: }
12565: }
12566: }
12567: }
12568: }
1.102 raeburn 12569: } else {
1.144 raeburn 12570: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 12571: $changes{'notify'}{'approval'} = 1;
12572: }
1.218 raeburn 12573: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 12574: $changes{'uniquecode'} = 1;
12575: }
12576: }
12577: if ($context eq 'requestcourses') {
1.242 raeburn 12578: foreach my $type ('textbooks','templates') {
12579: if ($newbook{$type}) {
12580: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 12581: foreach my $item ('subject','title','publisher','author') {
12582: next if ((($item eq 'author') || ($item eq 'publisher')) &&
12583: ($type eq 'template'));
1.242 raeburn 12584: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
12585: if ($env{'form.'.$type.'_addbook_'.$item}) {
12586: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
12587: }
12588: }
12589: if ($type eq 'textbooks') {
12590: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
12591: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 12592: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
12593: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
12594: } else {
12595: my ($imageurl,$error) =
12596: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
12597: $configuserok,$switchserver,$author_ok);
12598: if ($imageurl) {
12599: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
12600: }
12601: if ($error) {
12602: &Apache::lonnet::logthis($error);
12603: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12604: }
1.242 raeburn 12605: }
12606: }
1.216 raeburn 12607: }
12608: }
1.242 raeburn 12609: if (@{$allpos{$type}} > 0) {
12610: my $idx = 0;
12611: foreach my $item (@{$allpos{$type}}) {
12612: if ($item ne '') {
12613: $confhash{$type}{$item}{'order'} = $idx;
12614: if (ref($domconfig{$action}) eq 'HASH') {
12615: if (ref($domconfig{$action}{$type}) eq 'HASH') {
12616: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
12617: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
12618: $changes{$type}{$item} = 1;
12619: }
1.216 raeburn 12620: }
12621: }
12622: }
1.242 raeburn 12623: $idx ++;
1.216 raeburn 12624: }
12625: }
12626: }
12627: }
1.235 raeburn 12628: if (ref($validationitemsref) eq 'ARRAY') {
12629: foreach my $item (@{$validationitemsref}) {
12630: if ($item eq 'fields') {
12631: my @changed;
12632: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
12633: if (@{$confhash{'validation'}{$item}} > 0) {
12634: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
12635: }
1.266 raeburn 12636: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12637: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12638: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
12639: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
12640: $domconfig{'requestcourses'}{'validation'}{$item});
12641: } else {
12642: @changed = @{$confhash{'validation'}{$item}};
12643: }
1.235 raeburn 12644: } else {
12645: @changed = @{$confhash{'validation'}{$item}};
12646: }
12647: } else {
12648: @changed = @{$confhash{'validation'}{$item}};
12649: }
12650: if (@changed) {
12651: if ($confhash{'validation'}{$item}) {
12652: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
12653: } else {
12654: $changes{'validation'}{$item} = &mt('None');
12655: }
12656: }
12657: } else {
12658: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
12659: if ($item eq 'markup') {
12660: if ($env{'form.requestcourses_validation_'.$item}) {
12661: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
12662: }
12663: }
1.266 raeburn 12664: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12665: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12666: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
12667: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
12668: }
12669: } else {
12670: if ($confhash{'validation'}{$item} ne '') {
12671: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
12672: }
1.235 raeburn 12673: }
12674: } else {
12675: if ($confhash{'validation'}{$item} ne '') {
12676: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
12677: }
12678: }
12679: }
12680: }
12681: }
12682: if ($env{'form.validationdc'}) {
12683: my $newval = $env{'form.validationdc'};
1.285 raeburn 12684: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 12685: if (exists($domcoords{$newval})) {
12686: $confhash{'validation'}{'dc'} = $newval;
12687: }
12688: }
12689: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 12690: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12691: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12692: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
12693: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
12694: if ($confhash{'validation'}{'dc'} eq '') {
12695: $changes{'validation'}{'dc'} = &mt('None');
12696: } else {
12697: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
12698: }
1.235 raeburn 12699: }
1.266 raeburn 12700: } elsif ($confhash{'validation'}{'dc'} ne '') {
12701: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 12702: }
12703: } elsif ($confhash{'validation'}{'dc'} ne '') {
12704: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
12705: }
12706: } elsif ($confhash{'validation'}{'dc'} ne '') {
12707: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 12708: }
1.266 raeburn 12709: } else {
12710: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12711: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12712: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
12713: $changes{'validation'}{'dc'} = &mt('None');
12714: }
12715: }
1.235 raeburn 12716: }
12717: }
1.102 raeburn 12718: }
12719: } else {
1.86 raeburn 12720: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 12721: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 12722: }
1.72 raeburn 12723: foreach my $item (@usertools) {
12724: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 12725: my $unset;
1.101 raeburn 12726: if ($context eq 'requestcourses') {
1.104 raeburn 12727: $unset = '0';
12728: if ($type eq '_LC_adv') {
12729: $unset = '';
12730: }
1.101 raeburn 12731: if ($confhash{$item}{$type} eq 'autolimit') {
12732: $confhash{$item}{$type} .= '=';
12733: unless ($limithash{$item}{$type} =~ /\D/) {
12734: $confhash{$item}{$type} .= $limithash{$item}{$type};
12735: }
12736: }
1.163 raeburn 12737: } elsif ($context eq 'requestauthor') {
12738: $unset = '0';
12739: if ($type eq '_LC_adv') {
12740: $unset = '';
12741: }
1.72 raeburn 12742: } else {
1.101 raeburn 12743: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
12744: $confhash{$item}{$type} = 1;
12745: } else {
12746: $confhash{$item}{$type} = 0;
12747: }
1.72 raeburn 12748: }
1.86 raeburn 12749: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 12750: if ($action eq 'requestauthor') {
12751: if ($domconfig{$action}{$type} ne $confhash{$type}) {
12752: $changes{$type} = 1;
12753: }
12754: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 12755: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
12756: $changes{$item}{$type} = 1;
12757: }
12758: } else {
12759: if ($context eq 'requestcourses') {
1.104 raeburn 12760: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 12761: $changes{$item}{$type} = 1;
12762: }
12763: } else {
12764: if (!$confhash{$item}{$type}) {
12765: $changes{$item}{$type} = 1;
12766: }
12767: }
12768: }
12769: } else {
12770: if ($context eq 'requestcourses') {
1.104 raeburn 12771: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 12772: $changes{$item}{$type} = 1;
12773: }
1.163 raeburn 12774: } elsif ($context eq 'requestauthor') {
12775: if ($confhash{$type} ne $unset) {
12776: $changes{$type} = 1;
12777: }
1.72 raeburn 12778: } else {
12779: if (!$confhash{$item}{$type}) {
12780: $changes{$item}{$type} = 1;
12781: }
12782: }
12783: }
1.1 raeburn 12784: }
12785: }
1.163 raeburn 12786: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 12787: if (ref($domconfig{'quotas'}) eq 'HASH') {
12788: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
12789: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
12790: if (exists($confhash{'defaultquota'}{$key})) {
12791: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
12792: $changes{'defaultquota'}{$key} = 1;
12793: }
12794: } else {
12795: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 12796: }
12797: }
1.86 raeburn 12798: } else {
12799: foreach my $key (keys(%{$domconfig{'quotas'}})) {
12800: if (exists($confhash{'defaultquota'}{$key})) {
12801: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
12802: $changes{'defaultquota'}{$key} = 1;
12803: }
12804: } else {
12805: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 12806: }
1.1 raeburn 12807: }
12808: }
1.197 raeburn 12809: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
12810: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
12811: if (exists($confhash{'authorquota'}{$key})) {
12812: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
12813: $changes{'authorquota'}{$key} = 1;
12814: }
12815: } else {
12816: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
12817: }
12818: }
12819: }
1.1 raeburn 12820: }
1.86 raeburn 12821: if (ref($confhash{'defaultquota'}) eq 'HASH') {
12822: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
12823: if (ref($domconfig{'quotas'}) eq 'HASH') {
12824: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
12825: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
12826: $changes{'defaultquota'}{$key} = 1;
12827: }
12828: } else {
12829: if (!exists($domconfig{'quotas'}{$key})) {
12830: $changes{'defaultquota'}{$key} = 1;
12831: }
1.72 raeburn 12832: }
12833: } else {
1.86 raeburn 12834: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 12835: }
1.1 raeburn 12836: }
12837: }
1.197 raeburn 12838: if (ref($confhash{'authorquota'}) eq 'HASH') {
12839: foreach my $key (keys(%{$confhash{'authorquota'}})) {
12840: if (ref($domconfig{'quotas'}) eq 'HASH') {
12841: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
12842: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
12843: $changes{'authorquota'}{$key} = 1;
12844: }
12845: } else {
12846: $changes{'authorquota'}{$key} = 1;
12847: }
12848: } else {
12849: $changes{'authorquota'}{$key} = 1;
12850: }
12851: }
12852: }
1.1 raeburn 12853: }
1.72 raeburn 12854:
1.163 raeburn 12855: if ($context eq 'requestauthor') {
12856: $domdefaults{'requestauthor'} = \%confhash;
12857: } else {
12858: foreach my $key (keys(%confhash)) {
1.242 raeburn 12859: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 12860: $domdefaults{$key} = $confhash{$key};
12861: }
1.163 raeburn 12862: }
1.72 raeburn 12863: }
1.163 raeburn 12864:
1.1 raeburn 12865: my %quotahash = (
1.86 raeburn 12866: $action => { %confhash }
1.1 raeburn 12867: );
12868: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
12869: $dom);
12870: if ($putresult eq 'ok') {
12871: if (keys(%changes) > 0) {
1.72 raeburn 12872: my $cachetime = 24*60*60;
12873: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 12874: if (ref($lastactref) eq 'HASH') {
12875: $lastactref->{'domdefaults'} = 1;
12876: }
1.1 raeburn 12877: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 12878: unless (($context eq 'requestcourses') ||
1.163 raeburn 12879: ($context eq 'requestauthor')) {
1.86 raeburn 12880: if (ref($changes{'defaultquota'}) eq 'HASH') {
12881: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
12882: foreach my $type (@{$types},'default') {
12883: if (defined($changes{'defaultquota'}{$type})) {
12884: my $typetitle = $usertypes->{$type};
12885: if ($type eq 'default') {
12886: $typetitle = $othertitle;
12887: }
1.213 raeburn 12888: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 12889: }
12890: }
1.86 raeburn 12891: $resulttext .= '</ul></li>';
1.72 raeburn 12892: }
1.197 raeburn 12893: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 12894: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 12895: foreach my $type (@{$types},'default') {
12896: if (defined($changes{'authorquota'}{$type})) {
12897: my $typetitle = $usertypes->{$type};
12898: if ($type eq 'default') {
12899: $typetitle = $othertitle;
12900: }
1.213 raeburn 12901: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 12902: }
12903: }
12904: $resulttext .= '</ul></li>';
12905: }
1.72 raeburn 12906: }
1.80 raeburn 12907: my %newenv;
1.72 raeburn 12908: foreach my $item (@usertools) {
1.163 raeburn 12909: my (%haschgs,%inconf);
12910: if ($context eq 'requestauthor') {
12911: %haschgs = %changes;
1.210 raeburn 12912: %inconf = %confhash;
1.163 raeburn 12913: } else {
12914: if (ref($changes{$item}) eq 'HASH') {
12915: %haschgs = %{$changes{$item}};
12916: }
12917: if (ref($confhash{$item}) eq 'HASH') {
12918: %inconf = %{$confhash{$item}};
12919: }
12920: }
12921: if (keys(%haschgs) > 0) {
1.80 raeburn 12922: my $newacc =
12923: &Apache::lonnet::usertools_access($env{'user.name'},
12924: $env{'user.domain'},
1.86 raeburn 12925: $item,'reload',$context);
1.210 raeburn 12926: if (($context eq 'requestcourses') ||
1.163 raeburn 12927: ($context eq 'requestauthor')) {
1.108 raeburn 12928: if ($env{'environment.canrequest.'.$item} ne $newacc) {
12929: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 12930: }
12931: } else {
12932: if ($env{'environment.availabletools.'.$item} ne $newacc) {
12933: $newenv{'environment.availabletools.'.$item} = $newacc;
12934: }
1.80 raeburn 12935: }
1.163 raeburn 12936: unless ($context eq 'requestauthor') {
12937: $resulttext .= '<li>'.$titles{$item}.'<ul>';
12938: }
1.72 raeburn 12939: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 12940: if ($haschgs{$type}) {
1.72 raeburn 12941: my $typetitle = $usertypes->{$type};
12942: if ($type eq 'default') {
12943: $typetitle = $othertitle;
12944: } elsif ($type eq '_LC_adv') {
12945: $typetitle = 'LON-CAPA Advanced Users';
12946: }
1.163 raeburn 12947: if ($inconf{$type}) {
1.101 raeburn 12948: if ($context eq 'requestcourses') {
12949: my $cond;
1.163 raeburn 12950: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 12951: if ($1 eq '') {
12952: $cond = &mt('(Automatic processing of any request).');
12953: } else {
12954: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
12955: }
12956: } else {
1.163 raeburn 12957: $cond = $conditions{$inconf{$type}};
1.101 raeburn 12958: }
12959: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 12960: } elsif ($context eq 'requestauthor') {
12961: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
12962: $titles{$inconf{$type}},$typetitle);
12963:
1.101 raeburn 12964: } else {
12965: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
12966: }
1.72 raeburn 12967: } else {
1.104 raeburn 12968: if ($type eq '_LC_adv') {
1.163 raeburn 12969: if ($inconf{$type} eq '0') {
1.104 raeburn 12970: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
12971: } else {
12972: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
12973: }
12974: } else {
12975: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
12976: }
1.72 raeburn 12977: }
12978: }
1.26 raeburn 12979: }
1.163 raeburn 12980: unless ($context eq 'requestauthor') {
12981: $resulttext .= '</ul></li>';
12982: }
1.26 raeburn 12983: }
1.1 raeburn 12984: }
1.163 raeburn 12985: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 12986: if (ref($changes{'notify'}) eq 'HASH') {
12987: if ($changes{'notify'}{'approval'}) {
12988: if (ref($confhash{'notify'}) eq 'HASH') {
12989: if ($confhash{'notify'}{'approval'}) {
12990: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
12991: } else {
1.163 raeburn 12992: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 12993: }
12994: }
12995: }
12996: }
12997: }
1.216 raeburn 12998: if ($action eq 'requestcourses') {
12999: my @offon = ('off','on');
13000: if ($changes{'uniquecode'}) {
1.218 raeburn 13001: if (ref($confhash{'uniquecode'}) eq 'HASH') {
13002: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
13003: $resulttext .= '<li>'.
13004: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
13005: '</li>';
13006: } else {
13007: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
13008: '</li>';
13009: }
1.216 raeburn 13010: }
1.242 raeburn 13011: foreach my $type ('textbooks','templates') {
13012: if (ref($changes{$type}) eq 'HASH') {
13013: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
13014: foreach my $key (sort(keys(%{$changes{$type}}))) {
13015: my %coursehash = &Apache::lonnet::coursedescription($key);
13016: my $coursetitle = $coursehash{'description'};
13017: my $position = $confhash{$type}{$key}{'order'} + 1;
13018: $resulttext .= '<li>';
1.243 raeburn 13019: foreach my $item ('subject','title','publisher','author') {
13020: next if ((($item eq 'author') || ($item eq 'publisher')) &&
13021: ($type eq 'templates'));
1.242 raeburn 13022: my $name = $item.':';
13023: $name =~ s/^(\w)/\U$1/;
13024: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
13025: }
13026: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
13027: if ($type eq 'textbooks') {
13028: if ($confhash{$type}{$key}{'image'}) {
13029: $resulttext .= ' '.&mt('Image: [_1]',
13030: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
13031: ' alt="Textbook cover" />').'<br />';
13032: }
13033: }
13034: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 13035: }
1.242 raeburn 13036: $resulttext .= '</ul></li>';
1.216 raeburn 13037: }
13038: }
1.235 raeburn 13039: if (ref($changes{'validation'}) eq 'HASH') {
13040: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
13041: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
13042: foreach my $item (@{$validationitemsref}) {
13043: if (exists($changes{'validation'}{$item})) {
13044: if ($item eq 'markup') {
13045: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
13046: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
13047: } else {
13048: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
13049: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
13050: }
13051: }
13052: }
13053: if (exists($changes{'validation'}{'dc'})) {
13054: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
13055: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
13056: }
13057: }
13058: }
1.216 raeburn 13059: }
1.1 raeburn 13060: $resulttext .= '</ul>';
1.80 raeburn 13061: if (keys(%newenv)) {
13062: &Apache::lonnet::appenv(\%newenv);
13063: }
1.1 raeburn 13064: } else {
1.86 raeburn 13065: if ($context eq 'requestcourses') {
13066: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 13067: } elsif ($context eq 'requestauthor') {
13068: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 13069: } else {
1.90 weissno 13070: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 13071: }
1.1 raeburn 13072: }
13073: } else {
1.11 albertel 13074: $resulttext = '<span class="LC_error">'.
13075: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13076: }
1.216 raeburn 13077: if ($errors) {
13078: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
13079: '<ul>'.$errors.'</ul></p>';
13080: }
1.3 raeburn 13081: return $resulttext;
1.1 raeburn 13082: }
13083:
1.216 raeburn 13084: sub process_textbook_image {
1.242 raeburn 13085: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 13086: my $filename = $env{'form.'.$caller.'.filename'};
13087: my ($error,$url);
13088: my ($width,$height) = (50,50);
13089: if ($configuserok eq 'ok') {
13090: if ($switchserver) {
13091: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
13092: $switchserver);
13093: } elsif ($author_ok eq 'ok') {
13094: my ($result,$imageurl) =
13095: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 13096: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 13097: if ($result eq 'ok') {
13098: $url = $imageurl;
13099: } else {
13100: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
13101: }
13102: } else {
13103: $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);
13104: }
13105: } else {
13106: $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);
13107: }
13108: return ($url,$error);
13109: }
13110:
1.267 raeburn 13111: sub modify_ltitools {
13112: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
13113: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 13114: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 13115: my $confname = $dom.'-domainconfig';
13116: my $servadm = $r->dir_config('lonAdmEMail');
13117: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
13118: my (%posslti,%possfield);
13119: my @courseroles = ('cc','in','ta','ep','st');
13120: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
13121: map { $posslti{$_} = 1; } @ltiroles;
13122: my @allfields = ('fullname','firstname','lastname','email','user','roles');
13123: map { $possfield{$_} = 1; } @allfields;
13124: my %lt = <itools_names();
13125: if ($env{'form.ltitools_add'}) {
13126: my $title = $env{'form.ltitools_add_title'};
13127: $title =~ s/(`)/'/g;
13128: ($newid,my $error) = &get_ltitools_id($dom,$title);
13129: if ($newid) {
13130: my $position = $env{'form.ltitools_add_pos'};
13131: $position =~ s/\D+//g;
13132: if ($position ne '') {
13133: $allpos[$position] = $newid;
13134: }
13135: $changes{$newid} = 1;
1.322 raeburn 13136: foreach my $item ('title','url','key','secret','lifetime') {
1.267 raeburn 13137: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322 raeburn 13138: if ($item eq 'lifetime') {
13139: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
13140: }
1.267 raeburn 13141: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 13142: if (($item eq 'key') || ($item eq 'secret')) {
13143: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
13144: } else {
13145: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
13146: }
1.267 raeburn 13147: }
13148: }
13149: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
13150: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
13151: }
13152: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
13153: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
13154: }
1.323 raeburn 13155: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
13156: $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
13157: } else {
13158: $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
13159: }
1.296 raeburn 13160: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 13161: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
13162: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 13163: if (($item eq 'width') || ($item eq 'height')) {
13164: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
13165: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
13166: }
13167: } else {
13168: if ($env{'form.ltitools_add_'.$item} ne '') {
13169: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
13170: }
1.267 raeburn 13171: }
13172: }
13173: if ($env{'form.ltitools_add_target'} eq 'window') {
13174: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 13175: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
13176: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 13177: } else {
13178: $confhash{$newid}{'display'}{'target'} = 'iframe';
13179: }
13180: foreach my $item ('passback','roster') {
1.319 raeburn 13181: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 13182: $confhash{$newid}{$item} = 1;
1.319 raeburn 13183: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
13184: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
13185: $lifetime =~ s/^\s+|\s+$//g;
13186: if ($lifetime =~ /^\d+\.?\d*$/) {
13187: $confhash{$newid}{$item.'valid'} = $lifetime;
13188: }
13189: }
1.267 raeburn 13190: }
13191: }
13192: if ($env{'form.ltitools_add_image.filename'} ne '') {
13193: my ($imageurl,$error) =
1.307 raeburn 13194: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 13195: $configuserok,$switchserver,$author_ok);
13196: if ($imageurl) {
13197: $confhash{$newid}{'image'} = $imageurl;
13198: }
13199: if ($error) {
13200: &Apache::lonnet::logthis($error);
13201: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13202: }
13203: }
13204: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
13205: foreach my $field (@fields) {
13206: if ($possfield{$field}) {
13207: if ($field eq 'roles') {
13208: foreach my $role (@courseroles) {
13209: my $choice = $env{'form.ltitools_add_roles_'.$role};
13210: if (($choice ne '') && ($posslti{$choice})) {
13211: $confhash{$newid}{'roles'}{$role} = $choice;
13212: if ($role eq 'cc') {
13213: $confhash{$newid}{'roles'}{'co'} = $choice;
13214: }
13215: }
13216: }
13217: } else {
13218: $confhash{$newid}{'fields'}{$field} = 1;
13219: }
13220: }
13221: }
1.324 raeburn 13222: if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
13223: if ($confhash{$newid}{'fields'}{'user'}) {
13224: if ($env{'form.ltitools_userincdom_add'}) {
13225: $confhash{$newid}{'incdom'} = 1;
13226: }
13227: }
13228: }
1.273 raeburn 13229: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
13230: foreach my $item (@courseconfig) {
13231: $confhash{$newid}{'crsconf'}{$item} = 1;
13232: }
1.267 raeburn 13233: if ($env{'form.ltitools_add_custom'}) {
13234: my $name = $env{'form.ltitools_add_custom_name'};
13235: my $value = $env{'form.ltitools_add_custom_value'};
13236: $value =~ s/(`)/'/g;
13237: $name =~ s/(`)/'/g;
13238: $confhash{$newid}{'custom'}{$name} = $value;
13239: }
13240: } else {
13241: my $error = &mt('Failed to acquire unique ID for new external tool');
13242: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13243: }
13244: }
13245: if (ref($domconfig{$action}) eq 'HASH') {
13246: my %deletions;
13247: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
13248: if (@todelete) {
13249: map { $deletions{$_} = 1; } @todelete;
13250: }
13251: my %customadds;
13252: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
13253: if (@newcustom) {
13254: map { $customadds{$_} = 1; } @newcustom;
13255: }
13256: my %imgdeletions;
13257: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
13258: if (@todeleteimages) {
13259: map { $imgdeletions{$_} = 1; } @todeleteimages;
13260: }
13261: my $maxnum = $env{'form.ltitools_maxnum'};
13262: for (my $i=0; $i<=$maxnum; $i++) {
13263: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 13264: $itemid =~ s/\D+//g;
1.267 raeburn 13265: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
13266: if ($deletions{$itemid}) {
13267: if ($domconfig{$action}{$itemid}{'image'}) {
13268: #FIXME need to obsolete item in RES space
13269: }
13270: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
13271: next;
13272: } else {
13273: my $newpos = $env{'form.ltitools_'.$itemid};
13274: $newpos =~ s/\D+//g;
1.322 raeburn 13275: foreach my $item ('title','url','lifetime') {
1.267 raeburn 13276: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
13277: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
13278: $changes{$itemid} = 1;
13279: }
13280: }
1.297 raeburn 13281: foreach my $item ('key','secret') {
13282: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
13283: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
13284: $changes{$itemid} = 1;
13285: }
13286: }
1.267 raeburn 13287: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
13288: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
13289: }
13290: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
13291: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
13292: }
1.323 raeburn 13293: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
13294: $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
13295: } else {
13296: $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
13297: }
13298: if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
13299: if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
13300: $changes{$itemid} = 1;
13301: }
13302: } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
13303: $changes{$itemid} = 1;
13304: }
1.267 raeburn 13305: foreach my $size ('width','height') {
13306: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
13307: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
13308: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
13309: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
13310: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13311: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
13312: $changes{$itemid} = 1;
13313: }
13314: } else {
13315: $changes{$itemid} = 1;
13316: }
1.296 raeburn 13317: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13318: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
13319: $changes{$itemid} = 1;
13320: }
13321: }
13322: }
13323: foreach my $item ('linktext','explanation') {
13324: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
13325: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
13326: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
13327: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
13328: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13329: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
13330: $changes{$itemid} = 1;
13331: }
13332: } else {
13333: $changes{$itemid} = 1;
13334: }
13335: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13336: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
13337: $changes{$itemid} = 1;
13338: }
1.267 raeburn 13339: }
13340: }
13341: if ($env{'form.ltitools_target_'.$i} eq 'window') {
13342: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 13343: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
13344: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 13345: } else {
13346: $confhash{$itemid}{'display'}{'target'} = 'iframe';
13347: }
13348: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13349: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
13350: $changes{$itemid} = 1;
13351: }
13352: } else {
13353: $changes{$itemid} = 1;
13354: }
13355: foreach my $extra ('passback','roster') {
13356: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
13357: $confhash{$itemid}{$extra} = 1;
1.319 raeburn 13358: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
1.338 raeburn 13359: my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
1.319 raeburn 13360: $lifetime =~ s/^\s+|\s+$//g;
13361: if ($lifetime =~ /^\d+\.?\d*$/) {
13362: $confhash{$itemid}{$extra.'valid'} = $lifetime;
13363: }
13364: }
1.267 raeburn 13365: }
13366: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
13367: $changes{$itemid} = 1;
13368: }
1.319 raeburn 13369: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
13370: $changes{$itemid} = 1;
13371: }
1.267 raeburn 13372: }
1.273 raeburn 13373: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 13374: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 13375: if (grep(/^\Q$item\E$/,@courseconfig)) {
13376: $confhash{$itemid}{'crsconf'}{$item} = 1;
13377: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
13378: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
13379: $changes{$itemid} = 1;
13380: }
13381: } else {
13382: $changes{$itemid} = 1;
13383: }
13384: }
13385: }
1.267 raeburn 13386: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
13387: foreach my $field (@fields) {
13388: if ($possfield{$field}) {
13389: if ($field eq 'roles') {
13390: foreach my $role (@courseroles) {
13391: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
13392: if (($choice ne '') && ($posslti{$choice})) {
13393: $confhash{$itemid}{'roles'}{$role} = $choice;
13394: if ($role eq 'cc') {
13395: $confhash{$itemid}{'roles'}{'co'} = $choice;
13396: }
13397: }
13398: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
13399: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
13400: $changes{$itemid} = 1;
13401: }
13402: } elsif ($confhash{$itemid}{'roles'}{$role}) {
13403: $changes{$itemid} = 1;
13404: }
13405: }
13406: } else {
13407: $confhash{$itemid}{'fields'}{$field} = 1;
13408: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
13409: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
13410: $changes{$itemid} = 1;
13411: }
13412: } else {
13413: $changes{$itemid} = 1;
13414: }
13415: }
13416: }
13417: }
1.324 raeburn 13418: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
13419: if ($confhash{$itemid}{'fields'}{'user'}) {
13420: if ($env{'form.ltitools_userincdom_'.$i}) {
13421: $confhash{$itemid}{'incdom'} = 1;
13422: }
13423: if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
13424: $changes{$itemid} = 1;
13425: }
13426: }
13427: }
1.267 raeburn 13428: $allpos[$newpos] = $itemid;
13429: }
13430: if ($imgdeletions{$itemid}) {
13431: $changes{$itemid} = 1;
13432: #FIXME need to obsolete item in RES space
13433: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
13434: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
13435: $itemid,$configuserok,$switchserver,
13436: $author_ok);
13437: if ($imgurl) {
13438: $confhash{$itemid}{'image'} = $imgurl;
13439: $changes{$itemid} = 1;
13440: }
13441: if ($error) {
13442: &Apache::lonnet::logthis($error);
13443: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13444: }
13445: } elsif ($domconfig{$action}{$itemid}{'image'}) {
13446: $confhash{$itemid}{'image'} =
13447: $domconfig{$action}{$itemid}{'image'};
13448: }
13449: if ($customadds{$i}) {
13450: my $name = $env{'form.ltitools_custom_name_'.$i};
13451: $name =~ s/(`)/'/g;
13452: $name =~ s/^\s+//;
13453: $name =~ s/\s+$//;
13454: my $value = $env{'form.ltitools_custom_value_'.$i};
13455: $value =~ s/(`)/'/g;
13456: $value =~ s/^\s+//;
13457: $value =~ s/\s+$//;
13458: if ($name ne '') {
13459: $confhash{$itemid}{'custom'}{$name} = $value;
13460: $changes{$itemid} = 1;
13461: }
13462: }
13463: my %customdels;
13464: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
13465: if (@customdeletions) {
13466: $changes{$itemid} = 1;
13467: }
13468: map { $customdels{$_} = 1; } @customdeletions;
13469: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
13470: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
13471: unless ($customdels{$key}) {
13472: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
13473: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
13474: }
13475: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
13476: $changes{$itemid} = 1;
13477: }
13478: }
13479: }
13480: }
13481: unless ($changes{$itemid}) {
13482: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
13483: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
13484: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
13485: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
13486: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
13487: $changes{$itemid} = 1;
13488: last;
13489: }
13490: }
13491: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
13492: $changes{$itemid} = 1;
13493: }
13494: }
13495: last if ($changes{$itemid});
13496: }
13497: }
13498: }
13499: }
13500: }
13501: if (@allpos > 0) {
13502: my $idx = 0;
13503: foreach my $itemid (@allpos) {
13504: if ($itemid ne '') {
13505: $confhash{$itemid}{'order'} = $idx;
13506: if (ref($domconfig{$action}) eq 'HASH') {
13507: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
13508: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
13509: $changes{$itemid} = 1;
13510: }
13511: }
13512: }
13513: $idx ++;
13514: }
13515: }
13516: }
13517: my %ltitoolshash = (
13518: $action => { %confhash }
13519: );
13520: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
13521: $dom);
13522: if ($putresult eq 'ok') {
1.297 raeburn 13523: my %ltienchash = (
13524: $action => { %encconfig }
13525: );
13526: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267 raeburn 13527: if (keys(%changes) > 0) {
13528: my $cachetime = 24*60*60;
1.297 raeburn 13529: my %ltiall = %confhash;
13530: foreach my $id (keys(%ltiall)) {
13531: if (ref($encconfig{$id}) eq 'HASH') {
13532: foreach my $item ('key','secret') {
13533: $ltiall{$id}{$item} = $encconfig{$id}{$item};
13534: }
13535: }
13536: }
13537: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 13538: if (ref($lastactref) eq 'HASH') {
13539: $lastactref->{'ltitools'} = 1;
13540: }
13541: $resulttext = &mt('Changes made:').'<ul>';
13542: my %bynum;
13543: foreach my $itemid (sort(keys(%changes))) {
13544: my $position = $confhash{$itemid}{'order'};
13545: $bynum{$position} = $itemid;
13546: }
13547: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13548: my $itemid = $bynum{$pos};
13549: if (ref($confhash{$itemid}) ne 'HASH') {
13550: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
13551: } else {
13552: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
13553: if ($confhash{$itemid}{'image'}) {
13554: $resulttext .= ' '.
13555: '<img src="'.$confhash{$itemid}{'image'}.'"'.
13556: ' alt="'.&mt('Tool Provider icon').'" />';
13557: }
13558: $resulttext .= '</li><ul>';
13559: my $position = $pos + 1;
13560: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323 raeburn 13561: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267 raeburn 13562: if ($confhash{$itemid}{$item} ne '') {
13563: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
13564: }
13565: }
1.297 raeburn 13566: if ($encconfig{$itemid}{'key'} ne '') {
13567: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
13568: }
13569: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 13570: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 13571: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 13572: $resulttext .= ('*'x$num).'</li>';
13573: }
1.273 raeburn 13574: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 13575: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 13576: my $numconfig = 0;
13577: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
13578: foreach my $item (@possconfig) {
13579: if ($confhash{$itemid}{'crsconf'}{$item}) {
13580: $numconfig ++;
1.296 raeburn 13581: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 13582: }
13583: }
13584: }
13585: if (!$numconfig) {
1.372 raeburn 13586: $resulttext .= ' '.&mt('None');
1.273 raeburn 13587: }
13588: $resulttext .= '</li>';
1.267 raeburn 13589: foreach my $item ('passback','roster') {
13590: $resulttext .= '<li>'.$lt{$item}.' ';
13591: if ($confhash{$itemid}{$item}) {
13592: $resulttext .= &mt('Yes');
1.319 raeburn 13593: if ($confhash{$itemid}{$item.'valid'}) {
13594: if ($item eq 'passback') {
13595: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
13596: $confhash{$itemid}{$item.'valid'});
13597: } else {
13598: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
13599: $confhash{$itemid}{$item.'valid'});
13600: }
13601: }
1.267 raeburn 13602: } else {
13603: $resulttext .= &mt('No');
13604: }
13605: $resulttext .= '</li>';
13606: }
13607: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
13608: my $displaylist;
13609: if ($confhash{$itemid}{'display'}{'target'}) {
13610: $displaylist = &mt('Display target').': '.
13611: $confhash{$itemid}{'display'}{'target'}.',';
13612: }
13613: foreach my $size ('width','height') {
13614: if ($confhash{$itemid}{'display'}{$size}) {
13615: $displaylist .= (' 'x2).$lt{$size}.': '.
13616: $confhash{$itemid}{'display'}{$size}.',';
13617: }
13618: }
13619: if ($displaylist) {
13620: $displaylist =~ s/,$//;
13621: $resulttext .= '<li>'.$displaylist.'</li>';
13622: }
1.296 raeburn 13623: foreach my $item ('linktext','explanation') {
13624: if ($confhash{$itemid}{'display'}{$item}) {
13625: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
13626: }
13627: }
13628: }
1.267 raeburn 13629: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
13630: my $fieldlist;
13631: foreach my $field (@allfields) {
13632: if ($confhash{$itemid}{'fields'}{$field}) {
13633: $fieldlist .= (' 'x2).$lt{$field}.',';
13634: }
13635: }
13636: if ($fieldlist) {
13637: $fieldlist =~ s/,$//;
1.324 raeburn 13638: if ($confhash{$itemid}{'fields'}{'user'}) {
13639: if ($confhash{$itemid}{'incdom'}) {
13640: $fieldlist .= ' ('.&mt('username:domain').')';
13641: } else {
13642: $fieldlist .= ' ('.&mt('username').')';
13643: }
13644: }
1.267 raeburn 13645: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
13646: }
13647: }
13648: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
13649: my $rolemaps;
13650: foreach my $role (@courseroles) {
13651: if ($confhash{$itemid}{'roles'}{$role}) {
13652: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
13653: $confhash{$itemid}{'roles'}{$role}.',';
13654: }
13655: }
13656: if ($rolemaps) {
13657: $rolemaps =~ s/,$//;
13658: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
13659: }
13660: }
13661: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
13662: my $customlist;
13663: if (keys(%{$confhash{$itemid}{'custom'}})) {
13664: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
13665: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
13666: }
13667: }
13668: if ($customlist) {
1.317 raeburn 13669: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 13670: }
13671: }
13672: $resulttext .= '</ul></li>';
13673: }
13674: }
13675: $resulttext .= '</ul>';
13676: } else {
13677: $resulttext = &mt('No changes made.');
13678: }
13679: } else {
13680: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13681: }
13682: if ($errors) {
13683: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13684: $errors.'</ul>';
13685: }
13686: return $resulttext;
13687: }
13688:
13689: sub process_ltitools_image {
13690: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
13691: my $filename = $env{'form.'.$caller.'.filename'};
13692: my ($error,$url);
13693: my ($width,$height) = (21,21);
13694: if ($configuserok eq 'ok') {
13695: if ($switchserver) {
13696: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
13697: $switchserver);
13698: } elsif ($author_ok eq 'ok') {
13699: my ($result,$imageurl,$madethumb) =
13700: &publishlogo($r,'upload',$caller,$dom,$confname,
13701: "ltitools/$itemid/icon",$width,$height);
13702: if ($result eq 'ok') {
13703: if ($madethumb) {
13704: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
13705: my $imagethumb = "$path/tn-".$imagefile;
13706: $url = $imagethumb;
13707: } else {
13708: $url = $imageurl;
13709: }
13710: } else {
13711: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
13712: }
13713: } else {
13714: $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);
13715: }
13716: } else {
13717: $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);
13718: }
13719: return ($url,$error);
13720: }
13721:
13722: sub get_ltitools_id {
13723: my ($cdom,$title) = @_;
13724: # get lock on ltitools db
13725: my $lockhash = {
13726: lock => $env{'user.name'}.
13727: ':'.$env{'user.domain'},
13728: };
13729: my $tries = 0;
13730: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
13731: my ($id,$error);
13732:
13733: while (($gotlock ne 'ok') && ($tries<10)) {
13734: $tries ++;
13735: sleep (0.1);
13736: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
13737: }
13738: if ($gotlock eq 'ok') {
13739: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
13740: if ($currids{'lock'}) {
13741: delete($currids{'lock'});
13742: if (keys(%currids)) {
13743: my @curr = sort { $a <=> $b } keys(%currids);
13744: if ($curr[-1] =~ /^\d+$/) {
13745: $id = 1 + $curr[-1];
13746: }
13747: } else {
13748: $id = 1;
13749: }
13750: if ($id) {
13751: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
13752: $error = 'nostore';
13753: }
13754: } else {
13755: $error = 'nonumber';
13756: }
13757: }
13758: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
13759: } else {
13760: $error = 'nolock';
13761: }
13762: return ($id,$error);
13763: }
13764:
1.372 raeburn 13765: sub modify_proctoring {
13766: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
13767: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13768: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
13769: my $confname = $dom.'-domainconfig';
13770: my $servadm = $r->dir_config('lonAdmEMail');
13771: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
13772: my %providernames = &proctoring_providernames();
13773: my $maxnum = scalar(keys(%providernames));
13774:
13775: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
13776: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
13777: if (ref($requref) eq 'HASH') {
13778: %requserfields = %{$requref};
13779: }
13780: if (ref($opturef) eq 'HASH') {
13781: %optuserfields = %{$opturef};
13782: }
13783: if (ref($defref) eq 'HASH') {
13784: %defaults = %{$defref};
13785: }
13786: if (ref($extref) eq 'HASH') {
13787: %extended = %{$extref};
13788: }
13789: if (ref($crsref) eq 'HASH') {
13790: %crsconf = %{$crsref};
13791: }
13792: if (ref($rolesref) eq 'ARRAY') {
13793: @courseroles = @{$rolesref};
13794: }
13795: if (ref($ltiref) eq 'ARRAY') {
13796: @ltiroles = @{$ltiref};
13797: }
13798:
13799: if (ref($domconfig{$action}) eq 'HASH') {
13800: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
13801: if (@todeleteimages) {
13802: map { $imgdeletions{$_} = 1; } @todeleteimages;
13803: }
13804: }
13805: my %customadds;
13806: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
13807: if (@newcustom) {
13808: map { $customadds{$_} = 1; } @newcustom;
13809: }
13810: foreach my $provider (sort(keys(%providernames))) {
13811: $confhash{$provider} = {};
13812: my $pos = $env{'form.proctoring_pos_'.$provider};
13813: $pos =~ s/\D+//g;
13814: $allpos[$pos] = $provider;
13815: my (%current,%currentenc);
13816: my $showroles = 0;
13817: if (ref($domconfig{$action}) eq 'HASH') {
13818: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
13819: %current = %{$domconfig{$action}{$provider}};
13820: foreach my $item ('key','secret') {
13821: $currentenc{$item} = $current{$item};
13822: delete($current{$item});
13823: }
13824: }
13825: }
13826: if ($env{'form.proctoring_available_'.$provider}) {
13827: $confhash{$provider}{'available'} = 1;
13828: unless ($current{'available'}) {
13829: $changes{$provider} = 1;
13830: }
13831: } else {
13832: %{$confhash{$provider}} = %current;
13833: %{$encconfhash{$provider}} = %currentenc;
13834: $confhash{$provider}{'available'} = 0;
13835: if ($current{'available'}) {
13836: $changes{$provider} = 1;
13837: }
13838: }
13839: if ($confhash{$provider}{'available'}) {
13840: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
13841: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
13842: if ($field eq 'lifetime') {
13843: if ($possval =~ /^\d+$/) {
13844: $confhash{$provider}{$field} = $possval;
13845: }
13846: } elsif ($field eq 'version') {
13847: if ($possval =~ /^\d+\.\d+$/) {
13848: $confhash{$provider}{$field} = $possval;
13849: }
13850: } elsif ($field eq 'sigmethod') {
13851: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
13852: $confhash{$provider}{$field} = $possval;
13853: }
13854: } elsif ($field eq 'url') {
13855: $confhash{$provider}{$field} = $possval;
13856: } elsif (($field eq 'key') || ($field eq 'secret')) {
13857: $encconfhash{$provider}{$field} = $possval;
13858: unless ($currentenc{$field} eq $possval) {
13859: $changes{$provider} = 1;
13860: }
13861: }
13862: unless (($field eq 'key') || ($field eq 'secret')) {
13863: unless ($current{$field} eq $confhash{$provider}{$field}) {
13864: $changes{$provider} = 1;
13865: }
13866: }
13867: }
13868: if ($imgdeletions{$provider}) {
13869: $changes{$provider} = 1;
13870: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
13871: my ($imageurl,$error) =
13872: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
13873: $configuserok,$switchserver,$author_ok);
13874: if ($imageurl) {
13875: $confhash{$provider}{'image'} = $imageurl;
13876: $changes{$provider} = 1;
13877: }
13878: if ($error) {
13879: &Apache::lonnet::logthis($error);
13880: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13881: }
13882: } elsif (exists($current{'image'})) {
13883: $confhash{$provider}{'image'} = $current{'image'};
13884: }
13885: if (ref($requserfields{$provider}) eq 'ARRAY') {
13886: if (@{$requserfields{$provider}} > 0) {
13887: if (grep(/^user$/,@{$requserfields{$provider}})) {
13888: if ($env{'form.proctoring_userincdom_'.$provider}) {
13889: $confhash{$provider}{'incdom'} = 1;
13890: }
13891: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
13892: $changes{$provider} = 1;
13893: }
13894: }
13895: if (grep(/^roles$/,@{$requserfields{$provider}})) {
13896: $showroles = 1;
13897: }
13898: }
13899: }
13900: $confhash{$provider}{'fields'} = [];
13901: if (ref($optuserfields{$provider}) eq 'ARRAY') {
13902: if (@{$optuserfields{$provider}} > 0) {
13903: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
13904: foreach my $field (@{$optuserfields{$provider}}) {
13905: if (grep(/^\Q$field\E$/,@optfields)) {
13906: push(@{$confhash{$provider}{'fields'}},$field);
13907: }
13908: }
13909: }
13910: if (ref($current{'fields'}) eq 'ARRAY') {
13911: unless ($changes{$provider}) {
13912: my @new = sort(@{$confhash{$provider}{'fields'}});
13913: my @old = sort(@{$current{'fields'}});
13914: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
13915: if (@diffs) {
13916: $changes{$provider} = 1;
13917: }
13918: }
13919: } elsif (@{$confhash{$provider}{'fields'}}) {
13920: $changes{$provider} = 1;
13921: }
13922: }
13923: if (ref($defaults{$provider}) eq 'ARRAY') {
13924: if (@{$defaults{$provider}} > 0) {
13925: my %options;
13926: if (ref($extended{$provider}) eq 'HASH') {
13927: %options = %{$extended{$provider}};
13928: }
13929: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
13930: foreach my $field (@{$defaults{$provider}}) {
13931: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
13932: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
13933: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
13934: push(@{$confhash{$provider}{'defaults'}},$poss);
13935: }
13936: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
13937: foreach my $inner (keys(%{$options{$field}})) {
13938: if (ref($options{$field}{$inner}) eq 'ARRAY') {
13939: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
13940: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
13941: $confhash{$provider}{'defaults'}{$inner} = $poss;
13942: }
13943: } else {
13944: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
13945: }
13946: }
13947: } else {
13948: if (grep(/^\Q$field\E$/,@checked)) {
13949: push(@{$confhash{$provider}{'defaults'}},$field);
13950: }
13951: }
13952: }
13953: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
13954: if (ref($current{'defaults'}) eq 'ARRAY') {
13955: unless ($changes{$provider}) {
13956: my @new = sort(@{$confhash{$provider}{'defaults'}});
13957: my @old = sort(@{$current{'defaults'}});
13958: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
13959: if (@diffs) {
13960: $changes{$provider} = 1;
13961: }
13962: }
13963: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
13964: if (@{$current{'defaults'}}) {
13965: $changes{$provider} = 1;
13966: }
13967: }
13968: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
13969: if (ref($current{'defaults'}) eq 'HASH') {
13970: unless ($changes{$provider}) {
13971: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
13972: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
13973: $changes{$provider} = 1;
13974: last;
13975: }
13976: }
13977: }
13978: unless ($changes{$provider}) {
13979: foreach my $key (keys(%{$current{'defaults'}})) {
13980: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
13981: $changes{$provider} = 1;
13982: last;
13983: }
13984: }
13985: }
13986: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
13987: $changes{$provider} = 1;
13988: }
13989: }
13990: }
13991: }
13992: if (ref($crsconf{$provider}) eq 'ARRAY') {
13993: if (@{$crsconf{$provider}} > 0) {
13994: $confhash{$provider}{'crsconf'} = [];
13995: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
13996: foreach my $crsfield (@{$crsconf{$provider}}) {
13997: if (grep(/^\Q$crsfield\E$/,@checked)) {
13998: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
13999: }
14000: }
14001: if (ref($current{'crsconf'}) eq 'ARRAY') {
14002: unless ($changes{$provider}) {
14003: my @new = sort(@{$confhash{$provider}{'crsconf'}});
14004: my @old = sort(@{$current{'crsconf'}});
14005: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
14006: if (@diffs) {
14007: $changes{$provider} = 1;
14008: }
14009: }
14010: } elsif (@{$confhash{$provider}{'crsconf'}}) {
14011: $changes{$provider} = 1;
14012: }
14013: }
14014: }
14015: if ($showroles) {
14016: $confhash{$provider}{'roles'} = {};
14017: foreach my $role (@courseroles) {
14018: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
14019: if (grep(/^\Q$poss\E$/,@ltiroles)) {
14020: $confhash{$provider}{'roles'}{$role} = $poss;
14021: }
14022: }
14023: unless ($changes{$provider}) {
14024: if (ref($current{'roles'}) eq 'HASH') {
14025: foreach my $role (keys(%{$current{'roles'}})) {
14026: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
14027: $changes{$provider} = 1;
14028: last
14029: }
14030: }
14031: unless ($changes{$provider}) {
14032: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
14033: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
14034: $changes{$provider} = 1;
14035: last;
14036: }
14037: }
14038: }
14039: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
14040: $changes{$provider} = 1;
14041: }
14042: }
14043: }
14044: if (ref($current{'custom'}) eq 'HASH') {
14045: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
14046: foreach my $key (keys(%{$current{'custom'}})) {
14047: if (grep(/^\Q$key\E$/,@customdels)) {
14048: $changes{$provider} = 1;
14049: } else {
14050: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
14051: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
14052: $changes{$provider} = 1;
14053: }
14054: }
14055: }
14056: }
14057: if ($customadds{$provider}) {
14058: my $name = $env{'form.proctoring_custom_name_'.$provider};
14059: $name =~ s/(`)/'/g;
14060: $name =~ s/^\s+//;
14061: $name =~ s/\s+$//;
14062: my $value = $env{'form.proctoring_custom_value_'.$provider};
14063: $value =~ s/(`)/'/g;
14064: $value =~ s/^\s+//;
14065: $value =~ s/\s+$//;
14066: if ($name ne '') {
14067: $confhash{$provider}{'custom'}{$name} = $value;
14068: $changes{$provider} = 1;
14069: }
14070: }
14071: }
14072: }
14073: if (@allpos > 0) {
14074: my $idx = 0;
14075: foreach my $provider (@allpos) {
14076: if ($provider ne '') {
14077: $confhash{$provider}{'order'} = $idx;
14078: unless ($changes{$provider}) {
14079: if (ref($domconfig{$action}) eq 'HASH') {
14080: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
14081: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
14082: $changes{$provider} = 1;
14083: }
14084: }
14085: }
14086: }
14087: $idx ++;
14088: }
14089: }
14090: }
14091: my %proc_hash = (
14092: $action => { %confhash }
14093: );
14094: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
14095: $dom);
14096: if ($putresult eq 'ok') {
14097: my %proc_enchash = (
14098: $action => { %encconfhash }
14099: );
14100: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom);
14101: if (keys(%changes) > 0) {
14102: my $cachetime = 24*60*60;
14103: my %procall = %confhash;
14104: foreach my $provider (keys(%procall)) {
14105: if (ref($encconfhash{$provider}) eq 'HASH') {
14106: foreach my $key ('key','secret') {
14107: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
14108: }
14109: }
14110: }
14111: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
14112: if (ref($lastactref) eq 'HASH') {
14113: $lastactref->{'proctoring'} = 1;
14114: }
14115: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
14116: my %bynum;
14117: foreach my $provider (sort(keys(%changes))) {
14118: my $position = $confhash{$provider}{'order'};
14119: $bynum{$position} = $provider;
14120: }
14121: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
14122: my $provider = $bynum{$pos};
14123: my %lt = &proctoring_titles($provider);
14124: my %fieldtitles = &proctoring_fieldtitles($provider);
14125: if (!$confhash{$provider}{'available'}) {
14126: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
14127: } else {
14128: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
14129: if ($confhash{$provider}{'image'}) {
14130: $resulttext .= ' '.
14131: '<img src="'.$confhash{$provider}{'image'}.'"'.
14132: ' alt="'.&mt('Proctoring icon').'" />';
14133: }
14134: $resulttext .= '<ul>';
14135: my $position = $pos + 1;
14136: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
14137: foreach my $key ('version','sigmethod','url','lifetime') {
14138: if ($confhash{$provider}{$key} ne '') {
14139: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
14140: }
14141: }
14142: if ($encconfhash{$provider}{'key'} ne '') {
14143: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
14144: }
14145: if ($encconfhash{$provider}{'secret'} ne '') {
14146: $resulttext .= '<li>'.$lt{'secret'}.': ';
14147: my $num = length($encconfhash{$provider}{'secret'});
14148: $resulttext .= ('*'x$num).'</li>';
14149: }
14150: my (@fields,$showroles);
14151: if (ref($requserfields{$provider}) eq 'ARRAY') {
14152: push(@fields,@{$requserfields{$provider}});
14153: }
14154: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
14155: push(@fields,@{$confhash{$provider}{'fields'}});
14156: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
14157: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
14158: }
14159: if (@fields) {
14160: if (grep(/^roles$/,@fields)) {
14161: $showroles = 1;
14162: }
14163: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
14164: join('", "', map { $lt{$_}; } @fields).'"</li>';
14165: }
14166: if (ref($requserfields{$provider}) eq 'ARRAY') {
14167: if (grep(/^user$/,@{$requserfields{$provider}})) {
14168: if ($confhash{$provider}{'incdom'}) {
14169: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
14170: } else {
14171: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
14172: }
14173: }
14174: }
14175: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
14176: if (@{$confhash{$provider}{'defaults'}} > 0) {
14177: $resulttext .= '<li>'.$lt{'defa'};
14178: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
14179: $resulttext .= ' "'.$fieldtitles{$field}.'",';
14180: }
14181: $resulttext =~ s/,$//;
14182: $resulttext .= '</li>';
14183: }
14184: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
14185: if (keys(%{$confhash{$provider}{'defaults'}})) {
14186: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
14187: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
14188: if ($confhash{$provider}{'defaults'}{$key} ne '') {
14189: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
14190: }
14191: }
14192: $resulttext .= '</ul></li>';
14193: }
14194: }
14195: if (ref($crsconf{$provider}) eq 'ARRAY') {
14196: if (@{$crsconf{$provider}} > 0) {
14197: $resulttext .= '<li>'.&mt('Configurable in course:');
14198: my $numconfig = 0;
14199: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
14200: if (@{$confhash{$provider}{'crsconf'}} > 0) {
14201: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
14202: $numconfig ++;
14203: if ($provider eq 'examity') {
14204: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
14205: } else {
14206: $resulttext .= ' "'.$fieldtitles{$field}.'",';
14207: }
14208: }
14209: $resulttext =~ s/,$//;
14210: }
14211: }
14212: if (!$numconfig) {
14213: $resulttext .= ' '.&mt('None');
14214: }
14215: $resulttext .= '</li>';
14216: }
14217: }
14218: if ($showroles) {
14219: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
14220: my $rolemaps;
14221: foreach my $role (@courseroles) {
14222: if ($confhash{$provider}{'roles'}{$role}) {
14223: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
14224: $confhash{$provider}{'roles'}{$role}.',';
14225: }
14226: }
14227: if ($rolemaps) {
14228: $rolemaps =~ s/,$//;
14229: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
14230: }
14231: }
14232: }
14233: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
14234: my $customlist;
14235: if (keys(%{$confhash{$provider}{'custom'}})) {
14236: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
14237: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
14238: }
14239: $customlist =~ s/,$//;
14240: }
14241: if ($customlist) {
14242: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
14243: }
14244: }
14245: $resulttext .= '</ul></li>';
14246: }
14247: }
14248: $resulttext .= '</ul>';
14249: } else {
14250: $resulttext = &mt('No changes made.');
14251: }
14252: } else {
14253: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14254: }
14255: if ($errors) {
14256: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14257: $errors.'</ul>';
14258: }
14259: return $resulttext;
14260: }
14261:
14262: sub process_proctoring_image {
14263: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
14264: my $filename = $env{'form.'.$caller.'.filename'};
14265: my ($error,$url);
14266: my ($width,$height) = (21,21);
14267: if ($configuserok eq 'ok') {
14268: if ($switchserver) {
14269: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
14270: $switchserver);
14271: } elsif ($author_ok eq 'ok') {
14272: my ($result,$imageurl,$madethumb) =
14273: &publishlogo($r,'upload',$caller,$dom,$confname,
14274: "proctoring/$provider/icon",$width,$height);
14275: if ($result eq 'ok') {
14276: if ($madethumb) {
14277: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
14278: my $imagethumb = "$path/tn-".$imagefile;
14279: $url = $imagethumb;
14280: } else {
14281: $url = $imageurl;
14282: }
14283: } else {
14284: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14285: }
14286: } else {
14287: $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);
14288: }
14289: } else {
14290: $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);
14291: }
14292: return ($url,$error);
14293: }
14294:
1.320 raeburn 14295: sub modify_lti {
14296: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
14297: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14298: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
14299: my (%posslti,%posslticrs,%posscrstype);
14300: my @courseroles = ('cc','in','ta','ep','st');
14301: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
14302: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
14303: my @coursetypes = ('official','unofficial','community','textbook','placement');
14304: my %coursetypetitles = &Apache::lonlocal::texthash (
14305: official => 'Official',
14306: unofficial => 'Unofficial',
14307: community => 'Community',
14308: textbook => 'Textbook',
14309: placement => 'Placement Test',
14310: );
1.325 raeburn 14311: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 14312: my %lt = <i_names();
14313: map { $posslti{$_} = 1; } @ltiroles;
14314: map { $posslticrs{$_} = 1; } @lticourseroles;
14315: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 14316:
1.326 raeburn 14317: my %menutitles = <imenu_titles();
14318:
1.320 raeburn 14319: my (@items,%deletions,%itemids);
14320: if ($env{'form.lti_add'}) {
14321: my $consumer = $env{'form.lti_consumer_add'};
14322: $consumer =~ s/(`)/'/g;
14323: ($newid,my $error) = &get_lti_id($dom,$consumer);
14324: if ($newid) {
14325: $itemids{'add'} = $newid;
14326: push(@items,'add');
14327: $changes{$newid} = 1;
14328: } else {
14329: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
14330: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14331: }
14332: }
14333: if (ref($domconfig{$action}) eq 'HASH') {
14334: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
14335: if (@todelete) {
14336: map { $deletions{$_} = 1; } @todelete;
14337: }
14338: my $maxnum = $env{'form.lti_maxnum'};
14339: for (my $i=0; $i<=$maxnum; $i++) {
14340: my $itemid = $env{'form.lti_id_'.$i};
14341: $itemid =~ s/\D+//g;
14342: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14343: if ($deletions{$itemid}) {
14344: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
14345: } else {
14346: push(@items,$i);
14347: $itemids{$i} = $itemid;
14348: }
14349: }
14350: }
14351: }
14352: foreach my $idx (@items) {
14353: my $itemid = $itemids{$idx};
14354: next unless ($itemid);
14355: my $position = $env{'form.lti_pos_'.$idx};
14356: $position =~ s/\D+//g;
14357: if ($position ne '') {
14358: $allpos[$position] = $itemid;
14359: }
1.345 raeburn 14360: foreach my $item ('consumer','key','secret','lifetime','requser') {
1.320 raeburn 14361: my $formitem = 'form.lti_'.$item.'_'.$idx;
14362: $env{$formitem} =~ s/(`)/'/g;
14363: if ($item eq 'lifetime') {
14364: $env{$formitem} =~ s/[^\d.]//g;
14365: }
14366: if ($env{$formitem} ne '') {
14367: if (($item eq 'key') || ($item eq 'secret')) {
14368: $encconfig{$itemid}{$item} = $env{$formitem};
14369: } else {
14370: $confhash{$itemid}{$item} = $env{$formitem};
14371: unless (($idx eq 'add') || ($changes{$itemid})) {
14372: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
14373: $changes{$itemid} = 1;
14374: }
14375: }
14376: }
14377: }
14378: }
14379: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
14380: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
14381: }
1.345 raeburn 14382: if ($confhash{$itemid}{'requser'}) {
14383: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
14384: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
14385: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
14386: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
14387: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
14388: my $mapuser = $env{'form.lti_customuser_'.$idx};
14389: $mapuser =~ s/(`)/'/g;
14390: $mapuser =~ s/^\s+|\s+$//g;
14391: $confhash{$itemid}{'mapuser'} = $mapuser;
14392: }
14393: foreach my $ltirole (@lticourseroles) {
14394: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
14395: if (grep(/^\Q$possrole\E$/,@courseroles)) {
14396: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
14397: }
14398: }
14399: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
14400: my @makeuser;
14401: foreach my $ltirole (sort(@possmakeuser)) {
14402: if ($posslti{$ltirole}) {
14403: push(@makeuser,$ltirole);
14404: }
14405: }
14406: $confhash{$itemid}{'makeuser'} = \@makeuser;
14407: if (@makeuser) {
14408: my $lcauth = $env{'form.lti_lcauth_'.$idx};
14409: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
14410: $confhash{$itemid}{'lcauth'} = $lcauth;
14411: if ($lcauth ne 'internal') {
14412: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
14413: $lcauthparm =~ s/^(\s+|\s+)$//g;
14414: $lcauthparm =~ s/`//g;
14415: if ($lcauthparm ne '') {
14416: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
14417: }
14418: }
14419: } else {
14420: $confhash{$itemid}{'lcauth'} = 'lti';
14421: }
1.320 raeburn 14422: }
1.345 raeburn 14423: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
14424: if (@possinstdata) {
14425: foreach my $field (@possinstdata) {
14426: if (exists($fieldtitles{$field})) {
14427: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 14428: }
14429: }
14430: }
1.345 raeburn 14431: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
14432: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
14433: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
14434: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
14435: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
14436: $mapcrs =~ s/(`)/'/g;
14437: $mapcrs =~ s/^\s+|\s+$//g;
14438: $confhash{$itemid}{'mapcrs'} = $mapcrs;
14439: }
14440: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
14441: my @crstypes;
14442: foreach my $type (sort(@posstypes)) {
14443: if ($posscrstype{$type}) {
14444: push(@crstypes,$type);
1.325 raeburn 14445: }
14446: }
1.345 raeburn 14447: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
14448: if ($env{'form.lti_makecrs_'.$idx}) {
14449: $confhash{$itemid}{'makecrs'} = 1;
1.320 raeburn 14450: }
1.345 raeburn 14451: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
14452: my @selfenroll;
14453: foreach my $type (sort(@possenroll)) {
14454: if ($posslticrs{$type}) {
14455: push(@selfenroll,$type);
14456: }
1.320 raeburn 14457: }
1.345 raeburn 14458: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
14459: if ($env{'form.lti_crssec_'.$idx}) {
14460: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
14461: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
14462: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
14463: my $section = $env{'form.lti_customsection_'.$idx};
14464: $section =~ s/(`)/'/g;
14465: $section =~ s/^\s+|\s+$//g;
14466: if ($section ne '') {
14467: $confhash{$itemid}{'section'} = $section;
14468: }
1.320 raeburn 14469: }
14470: }
1.363 raeburn 14471: if ($env{'form.lti_callback_'.$idx}) {
14472: if ($env{'form.lti_callbackparam_'.$idx}) {
14473: my $callback = $env{'form.lti_callbackparam_'.$idx};
14474: $callback =~ s/^\s+|\s+$//g;
14475: $confhash{$itemid}{'callback'} = $callback;
14476: }
14477: }
1.345 raeburn 14478: foreach my $field ('passback','roster','topmenu','inlinemenu') {
14479: if ($env{'form.lti_'.$field.'_'.$idx}) {
14480: $confhash{$itemid}{$field} = 1;
14481: }
1.320 raeburn 14482: }
1.345 raeburn 14483: if ($env{'form.lti_passback_'.$idx}) {
14484: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
14485: $confhash{$itemid}{'passbackformat'} = '1.0';
14486: } else {
14487: $confhash{$itemid}{'passbackformat'} = '1.1';
14488: }
1.337 raeburn 14489: }
1.345 raeburn 14490: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
14491: $confhash{$itemid}{lcmenu} = [];
14492: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
14493: foreach my $field (@possmenu) {
14494: if (exists($menutitles{$field})) {
14495: if ($field eq 'grades') {
14496: next unless ($env{'form.lti_inlinemenu_'.$idx});
14497: }
14498: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 14499: }
14500: }
14501: }
1.345 raeburn 14502: unless (($idx eq 'add') || ($changes{$itemid})) {
1.363 raeburn 14503: foreach my $field ('mapuser','mapcrs','makecrs','section','passback','roster','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
1.345 raeburn 14504: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.337 raeburn 14505: $changes{$itemid} = 1;
14506: }
14507: }
1.320 raeburn 14508: unless ($changes{$itemid}) {
1.345 raeburn 14509: if ($domconfig{$action}{$itemid}{'passback'} eq $confhash{$itemid}{'passback'}) {
14510: if ($domconfig{$action}{$itemid}{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 14511: $changes{$itemid} = 1;
14512: }
1.345 raeburn 14513: }
1.320 raeburn 14514: }
1.345 raeburn 14515: foreach my $field ('makeuser','mapcrstype','selfenroll','instdata','lcmenu') {
14516: unless ($changes{$itemid}) {
14517: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
14518: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
14519: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
14520: $confhash{$itemid}{$field});
14521: if (@diffs) {
14522: $changes{$itemid} = 1;
14523: }
14524: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
14525: $changes{$itemid} = 1;
14526: }
14527: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
14528: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 14529: $changes{$itemid} = 1;
14530: }
14531: }
1.345 raeburn 14532: }
14533: }
14534: unless ($changes{$itemid}) {
14535: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
14536: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
14537: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
14538: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
14539: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.320 raeburn 14540: $changes{$itemid} = 1;
14541: last;
14542: }
14543: }
1.345 raeburn 14544: unless ($changes{$itemid}) {
14545: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
14546: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
14547: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
14548: $changes{$itemid} = 1;
14549: last;
14550: }
14551: }
14552: }
14553: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
14554: $changes{$itemid} = 1;
1.320 raeburn 14555: }
1.345 raeburn 14556: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
14557: unless ($changes{$itemid}) {
14558: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
14559: $changes{$itemid} = 1;
14560: }
1.320 raeburn 14561: }
14562: }
14563: }
14564: }
14565: }
14566: }
14567: if (@allpos > 0) {
14568: my $idx = 0;
14569: foreach my $itemid (@allpos) {
14570: if ($itemid ne '') {
14571: $confhash{$itemid}{'order'} = $idx;
14572: if (ref($domconfig{$action}) eq 'HASH') {
14573: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14574: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
14575: $changes{$itemid} = 1;
14576: }
14577: }
14578: }
14579: $idx ++;
14580: }
14581: }
14582: }
14583: my %ltihash = (
14584: $action => { %confhash }
14585: );
14586: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
14587: $dom);
14588: if ($putresult eq 'ok') {
14589: my %ltienchash = (
14590: $action => { %encconfig }
14591: );
14592: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
14593: if (keys(%changes) > 0) {
14594: my $cachetime = 24*60*60;
14595: my %ltiall = %confhash;
14596: foreach my $id (keys(%ltiall)) {
14597: if (ref($encconfig{$id}) eq 'HASH') {
14598: foreach my $item ('key','secret') {
14599: $ltiall{$id}{$item} = $encconfig{$id}{$item};
14600: }
14601: }
14602: }
14603: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
14604: if (ref($lastactref) eq 'HASH') {
14605: $lastactref->{'lti'} = 1;
14606: }
14607: $resulttext = &mt('Changes made:').'<ul>';
14608: my %bynum;
14609: foreach my $itemid (sort(keys(%changes))) {
14610: my $position = $confhash{$itemid}{'order'};
14611: $bynum{$position} = $itemid;
14612: }
14613: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
14614: my $itemid = $bynum{$pos};
14615: if (ref($confhash{$itemid}) ne 'HASH') {
14616: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
14617: } else {
14618: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b></li><ul>';
14619: my $position = $pos + 1;
14620: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
14621: foreach my $item ('version','lifetime') {
14622: if ($confhash{$itemid}{$item} ne '') {
14623: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
14624: }
14625: }
14626: if ($encconfig{$itemid}{'key'} ne '') {
14627: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
14628: }
14629: if ($encconfig{$itemid}{'secret'} ne '') {
14630: $resulttext .= '<li>'.$lt{'secret'}.': ';
14631: my $num = length($encconfig{$itemid}{'secret'});
14632: $resulttext .= ('*'x$num).'</li>';
14633: }
1.345 raeburn 14634: if ($confhash{$itemid}{'requser'}) {
14635: if ($confhash{$itemid}{'mapuser'}) {
14636: my $shownmapuser;
14637: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
14638: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
14639: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
14640: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
14641: } else {
14642: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 14643: }
1.345 raeburn 14644: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 14645: }
1.345 raeburn 14646: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
14647: my $rolemaps;
14648: foreach my $role (@ltiroles) {
14649: if ($confhash{$itemid}{'maproles'}{$role}) {
14650: $rolemaps .= (' 'x2).$role.'='.
14651: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
14652: 'Course').',';
14653: }
14654: }
14655: if ($rolemaps) {
14656: $rolemaps =~ s/,$//;
14657: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
14658: }
14659: }
14660: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
14661: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
14662: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
14663: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
14664: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
14665: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
14666: } else {
14667: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
14668: $confhash{$itemid}{'lcauth'});
14669: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
14670: $resulttext .= '; '.&mt('a randomly generated password will be created');
14671: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
14672: if ($confhash{$itemid}{'lcauthparm'} ne '') {
14673: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
14674: }
14675: } else {
14676: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
14677: }
14678: }
14679: $resulttext .= '</li>';
14680: } else {
14681: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
14682: }
1.320 raeburn 14683: }
1.345 raeburn 14684: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
14685: if (@{$confhash{$itemid}{'instdata'}} > 0) {
14686: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
14687: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 14688: } else {
1.345 raeburn 14689: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 14690: }
1.320 raeburn 14691: }
1.345 raeburn 14692: if ($confhash{$itemid}{'mapcrs'}) {
14693: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
14694: }
14695: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
14696: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
14697: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
14698: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
14699: '</li>';
14700: } else {
14701: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
14702: }
1.325 raeburn 14703: }
1.345 raeburn 14704: if ($confhash{$itemid}{'makecrs'}) {
14705: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
1.320 raeburn 14706: } else {
1.345 raeburn 14707: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
1.320 raeburn 14708: }
1.345 raeburn 14709: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
14710: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
14711: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
14712: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
14713: '</li>';
14714: } else {
14715: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
14716: }
1.320 raeburn 14717: }
1.345 raeburn 14718: if ($confhash{$itemid}{'section'}) {
14719: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
14720: $resulttext .= '<li>'.&mt('User section from standard field:').
14721: ' (course_section_sourcedid)'.'</li>';
14722: } else {
14723: $resulttext .= '<li>'.&mt('User section from:').' '.
14724: $confhash{$itemid}{'section'}.'</li>';
14725: }
1.320 raeburn 14726: } else {
1.345 raeburn 14727: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
1.320 raeburn 14728: }
1.363 raeburn 14729: if ($confhash{$itemid}{'callback'}) {
14730: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
14731: } else {
14732: $resulttext .= '<li>'.&mt('No callback to logout LON-CAPA session when user logs out of Comsumer');
14733: }
1.345 raeburn 14734: foreach my $item ('passback','roster','topmenu','inlinemenu') {
14735: $resulttext .= '<li>'.$lt{$item}.': ';
14736: if ($confhash{$itemid}{$item}) {
14737: $resulttext .= &mt('Yes');
14738: if ($item eq 'passback') {
14739: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
14740: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
14741: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
14742: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
14743: }
1.337 raeburn 14744: }
1.345 raeburn 14745: } else {
14746: $resulttext .= &mt('No');
1.337 raeburn 14747: }
1.345 raeburn 14748: $resulttext .= '</li>';
1.320 raeburn 14749: }
1.345 raeburn 14750: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
14751: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
14752: $resulttext .= '<li>'.&mt('Menu items:').' '.
14753: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
14754: } else {
14755: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
14756: }
1.326 raeburn 14757: }
14758: }
1.320 raeburn 14759: $resulttext .= '</ul></li>';
14760: }
14761: }
14762: $resulttext .= '</ul>';
14763: } else {
14764: $resulttext = &mt('No changes made.');
14765: }
14766: } else {
14767: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14768: }
14769: if ($errors) {
14770: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14771: $errors.'</ul>';
14772: }
14773: return $resulttext;
14774: }
14775:
14776: sub get_lti_id {
14777: my ($domain,$consumer) = @_;
14778: # get lock on lti db
14779: my $lockhash = {
14780: lock => $env{'user.name'}.
14781: ':'.$env{'user.domain'},
14782: };
14783: my $tries = 0;
14784: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
14785: my ($id,$error);
14786:
14787: while (($gotlock ne 'ok') && ($tries<10)) {
14788: $tries ++;
14789: sleep (0.1);
14790: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
14791: }
14792: if ($gotlock eq 'ok') {
14793: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
14794: if ($currids{'lock'}) {
14795: delete($currids{'lock'});
14796: if (keys(%currids)) {
14797: my @curr = sort { $a <=> $b } keys(%currids);
14798: if ($curr[-1] =~ /^\d+$/) {
14799: $id = 1 + $curr[-1];
14800: }
14801: } else {
14802: $id = 1;
14803: }
14804: if ($id) {
14805: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
14806: $error = 'nostore';
14807: }
14808: } else {
14809: $error = 'nonumber';
14810: }
14811: }
14812: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
14813: } else {
14814: $error = 'nolock';
14815: }
14816: return ($id,$error);
14817: }
14818:
1.3 raeburn 14819: sub modify_autoenroll {
1.205 raeburn 14820: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 14821: my ($resulttext,%changes);
14822: my %currautoenroll;
14823: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
14824: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
14825: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
14826: }
14827: }
14828: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
14829: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 14830: sender => 'Sender for notification messages',
1.274 raeburn 14831: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
14832: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 14833: my @offon = ('off','on');
1.17 raeburn 14834: my $sender_uname = $env{'form.sender_uname'};
14835: my $sender_domain = $env{'form.sender_domain'};
14836: if ($sender_domain eq '') {
14837: $sender_uname = '';
14838: } elsif ($sender_uname eq '') {
14839: $sender_domain = '';
14840: }
1.129 raeburn 14841: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 14842: my $failsafe = $env{'form.autoenroll_failsafe'};
14843: $failsafe =~ s{^\s+|\s+$}{}g;
14844: if ($failsafe =~ /\D/) {
14845: undef($failsafe);
14846: }
1.1 raeburn 14847: my %autoenrollhash = (
1.129 raeburn 14848: autoenroll => { 'run' => $env{'form.autoenroll_run'},
14849: 'sender_uname' => $sender_uname,
14850: 'sender_domain' => $sender_domain,
14851: 'co-owners' => $coowners,
1.274 raeburn 14852: 'autofailsafe' => $failsafe,
1.1 raeburn 14853: }
14854: );
1.4 raeburn 14855: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
14856: $dom);
1.1 raeburn 14857: if ($putresult eq 'ok') {
14858: if (exists($currautoenroll{'run'})) {
14859: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
14860: $changes{'run'} = 1;
14861: }
14862: } elsif ($autorun) {
14863: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 14864: $changes{'run'} = 1;
1.1 raeburn 14865: }
14866: }
1.17 raeburn 14867: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 14868: $changes{'sender'} = 1;
14869: }
1.17 raeburn 14870: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 14871: $changes{'sender'} = 1;
14872: }
1.129 raeburn 14873: if ($currautoenroll{'co-owners'} ne '') {
14874: if ($currautoenroll{'co-owners'} ne $coowners) {
14875: $changes{'coowners'} = 1;
14876: }
14877: } elsif ($coowners) {
14878: $changes{'coowners'} = 1;
1.274 raeburn 14879: }
14880: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
14881: $changes{'autofailsafe'} = 1;
14882: }
1.1 raeburn 14883: if (keys(%changes) > 0) {
14884: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 14885: if ($changes{'run'}) {
1.1 raeburn 14886: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
14887: }
14888: if ($changes{'sender'}) {
1.17 raeburn 14889: if ($sender_uname eq '' || $sender_domain eq '') {
14890: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
14891: } else {
14892: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
14893: }
1.1 raeburn 14894: }
1.129 raeburn 14895: if ($changes{'coowners'}) {
14896: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
14897: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 14898: if (ref($lastactref) eq 'HASH') {
14899: $lastactref->{'domainconfig'} = 1;
14900: }
1.129 raeburn 14901: }
1.274 raeburn 14902: if ($changes{'autofailsafe'}) {
14903: if ($failsafe ne '') {
1.299 raeburn 14904: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 14905: } else {
1.299 raeburn 14906: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 14907: }
14908: &Apache::lonnet::get_domain_defaults($dom,1);
14909: if (ref($lastactref) eq 'HASH') {
14910: $lastactref->{'domdefaults'} = 1;
14911: }
14912: }
1.1 raeburn 14913: $resulttext .= '</ul>';
14914: } else {
14915: $resulttext = &mt('No changes made to auto-enrollment settings');
14916: }
14917: } else {
1.11 albertel 14918: $resulttext = '<span class="LC_error">'.
14919: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14920: }
1.3 raeburn 14921: return $resulttext;
1.1 raeburn 14922: }
14923:
14924: sub modify_autoupdate {
1.3 raeburn 14925: my ($dom,%domconfig) = @_;
1.1 raeburn 14926: my ($resulttext,%currautoupdate,%fields,%changes);
14927: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
14928: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
14929: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
14930: }
14931: }
14932: my @offon = ('off','on');
14933: my %title = &Apache::lonlocal::texthash (
14934: run => 'Auto-update:',
14935: classlists => 'Updates to user information in classlists?'
14936: );
1.44 raeburn 14937: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 14938: my %fieldtitles = &Apache::lonlocal::texthash (
14939: id => 'Student/Employee ID',
1.20 raeburn 14940: permanentemail => 'E-mail address',
1.1 raeburn 14941: lastname => 'Last Name',
14942: firstname => 'First Name',
14943: middlename => 'Middle Name',
1.132 raeburn 14944: generation => 'Generation',
1.1 raeburn 14945: );
1.142 raeburn 14946: $othertitle = &mt('All users');
1.1 raeburn 14947: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 14948: $othertitle = &mt('Other users');
1.1 raeburn 14949: }
14950: foreach my $key (keys(%env)) {
14951: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 14952: my ($usertype,$item) = ($1,$2);
14953: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
14954: if ($usertype eq 'default') {
14955: push(@{$fields{$1}},$2);
14956: } elsif (ref($types) eq 'ARRAY') {
14957: if (grep(/^\Q$usertype\E$/,@{$types})) {
14958: push(@{$fields{$1}},$2);
14959: }
14960: }
14961: }
1.1 raeburn 14962: }
14963: }
1.131 raeburn 14964: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
14965: @lockablenames = sort(@lockablenames);
14966: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
14967: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
14968: if (@changed) {
14969: $changes{'lockablenames'} = 1;
14970: }
14971: } else {
14972: if (@lockablenames) {
14973: $changes{'lockablenames'} = 1;
14974: }
14975: }
1.1 raeburn 14976: my %updatehash = (
14977: autoupdate => { run => $env{'form.autoupdate_run'},
14978: classlists => $env{'form.classlists'},
14979: fields => {%fields},
1.131 raeburn 14980: lockablenames => \@lockablenames,
1.1 raeburn 14981: }
14982: );
14983: foreach my $key (keys(%currautoupdate)) {
14984: if (($key eq 'run') || ($key eq 'classlists')) {
14985: if (exists($updatehash{autoupdate}{$key})) {
14986: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
14987: $changes{$key} = 1;
14988: }
14989: }
14990: } elsif ($key eq 'fields') {
14991: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 14992: foreach my $item (@{$types},'default') {
1.1 raeburn 14993: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
14994: my $change = 0;
14995: foreach my $type (@{$currautoupdate{$key}{$item}}) {
14996: if (!exists($fields{$item})) {
14997: $change = 1;
1.132 raeburn 14998: last;
1.1 raeburn 14999: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 15000: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 15001: $change = 1;
1.132 raeburn 15002: last;
1.1 raeburn 15003: }
15004: }
15005: }
15006: if ($change) {
15007: push(@{$changes{$key}},$item);
15008: }
1.26 raeburn 15009: }
1.1 raeburn 15010: }
15011: }
1.131 raeburn 15012: } elsif ($key eq 'lockablenames') {
15013: if (ref($currautoupdate{$key}) eq 'ARRAY') {
15014: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
15015: if (@changed) {
15016: $changes{'lockablenames'} = 1;
15017: }
15018: } else {
15019: if (@lockablenames) {
15020: $changes{'lockablenames'} = 1;
15021: }
15022: }
15023: }
15024: }
15025: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
15026: if (@lockablenames) {
15027: $changes{'lockablenames'} = 1;
1.1 raeburn 15028: }
15029: }
1.26 raeburn 15030: foreach my $item (@{$types},'default') {
15031: if (defined($fields{$item})) {
15032: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 15033: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
15034: my $change = 0;
15035: if (ref($fields{$item}) eq 'ARRAY') {
15036: foreach my $type (@{$fields{$item}}) {
15037: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
15038: $change = 1;
15039: last;
15040: }
15041: }
15042: }
15043: if ($change) {
15044: push(@{$changes{'fields'}},$item);
15045: }
15046: } else {
1.26 raeburn 15047: push(@{$changes{'fields'}},$item);
15048: }
15049: } else {
15050: push(@{$changes{'fields'}},$item);
1.1 raeburn 15051: }
15052: }
15053: }
15054: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
15055: $dom);
15056: if ($putresult eq 'ok') {
15057: if (keys(%changes) > 0) {
15058: $resulttext = &mt('Changes made:').'<ul>';
15059: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 15060: if ($key eq 'lockablenames') {
15061: $resulttext .= '<li>';
15062: if (@lockablenames) {
15063: $usertypes->{'default'} = $othertitle;
15064: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
15065: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
15066: } else {
15067: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
15068: }
15069: $resulttext .= '</li>';
15070: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 15071: foreach my $item (@{$changes{$key}}) {
15072: my @newvalues;
15073: foreach my $type (@{$fields{$item}}) {
15074: push(@newvalues,$fieldtitles{$type});
15075: }
1.3 raeburn 15076: my $newvaluestr;
15077: if (@newvalues > 0) {
15078: $newvaluestr = join(', ',@newvalues);
15079: } else {
15080: $newvaluestr = &mt('none');
1.6 raeburn 15081: }
1.1 raeburn 15082: if ($item eq 'default') {
1.26 raeburn 15083: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 15084: } else {
1.26 raeburn 15085: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 15086: }
15087: }
15088: } else {
15089: my $newvalue;
15090: if ($key eq 'run') {
15091: $newvalue = $offon[$env{'form.autoupdate_run'}];
15092: } else {
15093: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 15094: }
1.1 raeburn 15095: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
15096: }
15097: }
15098: $resulttext .= '</ul>';
15099: } else {
1.3 raeburn 15100: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 15101: }
15102: } else {
1.11 albertel 15103: $resulttext = '<span class="LC_error">'.
15104: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 15105: }
1.3 raeburn 15106: return $resulttext;
1.1 raeburn 15107: }
15108:
1.125 raeburn 15109: sub modify_autocreate {
15110: my ($dom,%domconfig) = @_;
15111: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
15112: if (ref($domconfig{'autocreate'}) eq 'HASH') {
15113: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
15114: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
15115: }
15116: }
15117: my %title= ( xml => 'Auto-creation of courses in XML course description files',
15118: req => 'Auto-creation of validated requests for official courses',
15119: xmldc => 'Identity of course creator of courses from XML files',
15120: );
15121: my @types = ('xml','req');
15122: foreach my $item (@types) {
15123: $newvals{$item} = $env{'form.autocreate_'.$item};
15124: $newvals{$item} =~ s/\D//g;
15125: $newvals{$item} = 0 if ($newvals{$item} eq '');
15126: }
15127: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 15128: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 15129: unless (exists($domcoords{$newvals{'xmldc'}})) {
15130: $newvals{'xmldc'} = '';
15131: }
15132: %autocreatehash = (
15133: autocreate => { xml => $newvals{'xml'},
15134: req => $newvals{'req'},
15135: }
15136: );
15137: if ($newvals{'xmldc'} ne '') {
15138: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
15139: }
15140: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
15141: $dom);
15142: if ($putresult eq 'ok') {
15143: my @items = @types;
15144: if ($newvals{'xml'}) {
15145: push(@items,'xmldc');
15146: }
15147: foreach my $item (@items) {
15148: if (exists($currautocreate{$item})) {
15149: if ($currautocreate{$item} ne $newvals{$item}) {
15150: $changes{$item} = 1;
15151: }
15152: } elsif ($newvals{$item}) {
15153: $changes{$item} = 1;
15154: }
15155: }
15156: if (keys(%changes) > 0) {
15157: my @offon = ('off','on');
15158: $resulttext = &mt('Changes made:').'<ul>';
15159: foreach my $item (@types) {
15160: if ($changes{$item}) {
15161: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 15162: $resulttext .= '<li>'.
15163: &mt("$title{$item} set to [_1]$newtxt [_2]",
15164: '<b>','</b>').
15165: '</li>';
1.125 raeburn 15166: }
15167: }
15168: if ($changes{'xmldc'}) {
15169: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
15170: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 15171: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 15172: }
15173: $resulttext .= '</ul>';
15174: } else {
15175: $resulttext = &mt('No changes made to auto-creation settings');
15176: }
15177: } else {
15178: $resulttext = '<span class="LC_error">'.
15179: &mt('An error occurred: [_1]',$putresult).'</span>';
15180: }
15181: return $resulttext;
15182: }
15183:
1.23 raeburn 15184: sub modify_directorysrch {
1.295 raeburn 15185: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 15186: my ($resulttext,%changes);
15187: my %currdirsrch;
15188: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
15189: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
15190: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
15191: }
15192: }
1.277 raeburn 15193: my %title = ( available => 'Institutional directory search available',
15194: localonly => 'Other domains can search institution',
15195: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 15196: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 15197: searchby => 'Search types',
15198: searchtypes => 'Search latitude');
15199: my @offon = ('off','on');
1.24 raeburn 15200: my @otherdoms = ('Yes','No');
1.23 raeburn 15201:
1.25 raeburn 15202: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 15203: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
15204: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
15205:
1.44 raeburn 15206: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 15207: if (keys(%{$usertypes}) == 0) {
15208: @cansearch = ('default');
15209: } else {
15210: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
15211: foreach my $type (@{$currdirsrch{'cansearch'}}) {
15212: if (!grep(/^\Q$type\E$/,@cansearch)) {
15213: push(@{$changes{'cansearch'}},$type);
15214: }
1.23 raeburn 15215: }
1.26 raeburn 15216: foreach my $type (@cansearch) {
15217: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
15218: push(@{$changes{'cansearch'}},$type);
15219: }
1.23 raeburn 15220: }
1.26 raeburn 15221: } else {
15222: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 15223: }
15224: }
15225:
15226: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
15227: foreach my $by (@{$currdirsrch{'searchby'}}) {
15228: if (!grep(/^\Q$by\E$/,@searchby)) {
15229: push(@{$changes{'searchby'}},$by);
15230: }
15231: }
15232: foreach my $by (@searchby) {
15233: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
15234: push(@{$changes{'searchby'}},$by);
15235: }
15236: }
15237: } else {
15238: push(@{$changes{'searchby'}},@searchby);
15239: }
1.25 raeburn 15240:
15241: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
15242: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
15243: if (!grep(/^\Q$type\E$/,@searchtypes)) {
15244: push(@{$changes{'searchtypes'}},$type);
15245: }
15246: }
15247: foreach my $type (@searchtypes) {
15248: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
15249: push(@{$changes{'searchtypes'}},$type);
15250: }
15251: }
15252: } else {
15253: if (exists($currdirsrch{'searchtypes'})) {
15254: foreach my $type (@searchtypes) {
15255: if ($type ne $currdirsrch{'searchtypes'}) {
15256: push(@{$changes{'searchtypes'}},$type);
15257: }
15258: }
15259: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
15260: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
15261: }
15262: } else {
15263: push(@{$changes{'searchtypes'}},@searchtypes);
15264: }
15265: }
15266:
1.23 raeburn 15267: my %dirsrch_hash = (
15268: directorysrch => { available => $env{'form.dirsrch_available'},
15269: cansearch => \@cansearch,
1.277 raeburn 15270: localonly => $env{'form.dirsrch_instlocalonly'},
15271: lclocalonly => $env{'form.dirsrch_domlocalonly'},
15272: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 15273: searchby => \@searchby,
1.25 raeburn 15274: searchtypes => \@searchtypes,
1.23 raeburn 15275: }
15276: );
15277: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
15278: $dom);
15279: if ($putresult eq 'ok') {
15280: if (exists($currdirsrch{'available'})) {
15281: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
15282: $changes{'available'} = 1;
15283: }
15284: } else {
15285: if ($env{'form.dirsrch_available'} eq '1') {
15286: $changes{'available'} = 1;
15287: }
15288: }
1.277 raeburn 15289: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 15290: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
15291: $changes{'lcavailable'} = 1;
15292: }
1.277 raeburn 15293: } else {
15294: if ($env{'form.dirsrch_lcavailable'} eq '1') {
15295: $changes{'lcavailable'} = 1;
15296: }
15297: }
1.24 raeburn 15298: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 15299: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
15300: $changes{'localonly'} = 1;
15301: }
1.24 raeburn 15302: } else {
1.277 raeburn 15303: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 15304: $changes{'localonly'} = 1;
15305: }
15306: }
1.277 raeburn 15307: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 15308: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
15309: $changes{'lclocalonly'} = 1;
15310: }
1.277 raeburn 15311: } else {
15312: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
15313: $changes{'lclocalonly'} = 1;
15314: }
15315: }
1.23 raeburn 15316: if (keys(%changes) > 0) {
15317: $resulttext = &mt('Changes made:').'<ul>';
15318: if ($changes{'available'}) {
15319: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
15320: }
1.277 raeburn 15321: if ($changes{'lcavailable'}) {
15322: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
15323: }
1.24 raeburn 15324: if ($changes{'localonly'}) {
1.277 raeburn 15325: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 15326: }
1.277 raeburn 15327: if ($changes{'lclocalonly'}) {
15328: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 15329: }
1.23 raeburn 15330: if (ref($changes{'cansearch'}) eq 'ARRAY') {
15331: my $chgtext;
1.26 raeburn 15332: if (ref($usertypes) eq 'HASH') {
15333: if (keys(%{$usertypes}) > 0) {
15334: foreach my $type (@{$types}) {
15335: if (grep(/^\Q$type\E$/,@cansearch)) {
15336: $chgtext .= $usertypes->{$type}.'; ';
15337: }
15338: }
15339: if (grep(/^default$/,@cansearch)) {
15340: $chgtext .= $othertitle;
15341: } else {
15342: $chgtext =~ s/\; $//;
15343: }
1.210 raeburn 15344: $resulttext .=
1.178 raeburn 15345: '<li>'.
15346: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
15347: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
15348: '</li>';
1.23 raeburn 15349: }
15350: }
15351: }
15352: if (ref($changes{'searchby'}) eq 'ARRAY') {
15353: my ($searchtitles,$titleorder) = &sorted_searchtitles();
15354: my $chgtext;
15355: foreach my $type (@{$titleorder}) {
15356: if (grep(/^\Q$type\E$/,@searchby)) {
15357: if (defined($searchtitles->{$type})) {
15358: $chgtext .= $searchtitles->{$type}.'; ';
15359: }
15360: }
15361: }
15362: $chgtext =~ s/\; $//;
15363: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
15364: }
1.25 raeburn 15365: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
15366: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
15367: my $chgtext;
15368: foreach my $type (@{$srchtypeorder}) {
15369: if (grep(/^\Q$type\E$/,@searchtypes)) {
15370: if (defined($srchtypes_desc->{$type})) {
15371: $chgtext .= $srchtypes_desc->{$type}.'; ';
15372: }
15373: }
15374: }
15375: $chgtext =~ s/\; $//;
1.178 raeburn 15376: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 15377: }
15378: $resulttext .= '</ul>';
1.295 raeburn 15379: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
15380: if (ref($lastactref) eq 'HASH') {
15381: $lastactref->{'directorysrch'} = 1;
15382: }
1.23 raeburn 15383: } else {
1.277 raeburn 15384: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 15385: }
15386: } else {
15387: $resulttext = '<span class="LC_error">'.
1.27 raeburn 15388: &mt('An error occurred: [_1]',$putresult).'</span>';
15389: }
15390: return $resulttext;
15391: }
15392:
1.28 raeburn 15393: sub modify_contacts {
1.205 raeburn 15394: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 15395: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
15396: if (ref($domconfig{'contacts'}) eq 'HASH') {
15397: foreach my $key (keys(%{$domconfig{'contacts'}})) {
15398: $currsetting{$key} = $domconfig{'contacts'}{$key};
15399: }
15400: }
1.286 raeburn 15401: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 15402: my @contacts = ('supportemail','adminemail');
1.286 raeburn 15403: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 15404: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 15405: my @toggles = ('reporterrors','reportupdates','reportstatus');
15406: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 15407: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 15408: foreach my $type (@mailings) {
15409: @{$newsetting{$type}} =
15410: &Apache::loncommon::get_env_multiple('form.'.$type);
15411: foreach my $item (@contacts) {
15412: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
15413: $contacts_hash{contacts}{$type}{$item} = 1;
15414: } else {
15415: $contacts_hash{contacts}{$type}{$item} = 0;
15416: }
1.289 raeburn 15417: }
1.28 raeburn 15418: $others{$type} = $env{'form.'.$type.'_others'};
15419: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 15420: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15421: $bcc{$type} = $env{'form.'.$type.'_bcc'};
15422: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 15423: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
15424: $includestr{$type} = $env{'form.'.$type.'_includestr'};
15425: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
15426: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
15427: }
1.134 raeburn 15428: }
1.28 raeburn 15429: }
15430: foreach my $item (@contacts) {
15431: $to{$item} = $env{'form.'.$item};
15432: $contacts_hash{'contacts'}{$item} = $to{$item};
15433: }
1.203 raeburn 15434: foreach my $item (@toggles) {
15435: if ($env{'form.'.$item} =~ /^(0|1)$/) {
15436: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
15437: }
15438: }
1.340 raeburn 15439: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
15440: foreach my $item (@lonstatus) {
15441: if ($item eq 'excluded') {
15442: my (%serverhomes,@excluded);
15443: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
15444: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
15445: if (@possexcluded) {
15446: foreach my $id (sort(@possexcluded)) {
15447: if ($serverhomes{$id}) {
15448: push(@excluded,$id);
15449: }
15450: }
15451: }
15452: if (@excluded) {
15453: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
15454: }
15455: } elsif ($item eq 'weights') {
1.377 raeburn 15456: foreach my $type ('E','W','N','U') {
1.340 raeburn 15457: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
15458: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
15459: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
15460: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
15461: $env{'form.error'.$item.'_'.$type};
15462: }
15463: }
15464: }
15465: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
15466: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
15467: if ($env{'form.error'.$item} =~ /^\d+$/) {
15468: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
15469: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
15470: }
15471: }
15472: }
15473: }
1.286 raeburn 15474: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
15475: foreach my $field (@{$fields}) {
15476: if (ref($possoptions->{$field}) eq 'ARRAY') {
15477: my $value = $env{'form.helpform_'.$field};
15478: $value =~ s/^\s+|\s+$//g;
15479: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 15480: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 15481: if ($field eq 'screenshot') {
15482: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
15483: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 15484: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 15485: }
15486: }
15487: }
15488: }
15489: }
15490: }
1.315 raeburn 15491: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
15492: my (@statuses,%usertypeshash,@overrides);
15493: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
15494: @statuses = @{$types};
15495: if (ref($usertypes) eq 'HASH') {
15496: %usertypeshash = %{$usertypes};
15497: }
15498: }
15499: if (@statuses) {
15500: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
15501: foreach my $type (@possoverrides) {
15502: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
15503: push(@overrides,$type);
15504: }
15505: }
15506: if (@overrides) {
15507: foreach my $type (@overrides) {
15508: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
15509: foreach my $item (@contacts) {
15510: if (grep(/^\Q$item\E$/,@standard)) {
15511: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
15512: $newsetting{'override_'.$type}{$item} = 1;
15513: } else {
15514: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
15515: $newsetting{'override_'.$type}{$item} = 0;
15516: }
15517: }
15518: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
15519: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
15520: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
15521: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
15522: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
15523: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
15524: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
15525: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
15526: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
15527: }
15528: }
15529: }
15530: }
1.28 raeburn 15531: if (keys(%currsetting) > 0) {
15532: foreach my $item (@contacts) {
15533: if ($to{$item} ne $currsetting{$item}) {
15534: $changes{$item} = 1;
15535: }
15536: }
15537: foreach my $type (@mailings) {
15538: foreach my $item (@contacts) {
15539: if (ref($currsetting{$type}) eq 'HASH') {
15540: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
15541: push(@{$changes{$type}},$item);
15542: }
15543: } else {
15544: push(@{$changes{$type}},@{$newsetting{$type}});
15545: }
15546: }
15547: if ($others{$type} ne $currsetting{$type}{'others'}) {
15548: push(@{$changes{$type}},'others');
15549: }
1.289 raeburn 15550: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15551: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
15552: push(@{$changes{$type}},'bcc');
15553: }
1.286 raeburn 15554: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
15555: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
15556: push(@{$changes{$type}},'include');
15557: }
15558: }
15559: }
15560: if (ref($fields) eq 'ARRAY') {
15561: if (ref($currsetting{'helpform'}) eq 'HASH') {
15562: foreach my $field (@{$fields}) {
15563: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
15564: push(@{$changes{'helpform'}},$field);
15565: }
15566: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
15567: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
15568: push(@{$changes{'helpform'}},'maxsize');
15569: }
15570: }
15571: }
15572: } else {
15573: foreach my $field (@{$fields}) {
15574: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
15575: push(@{$changes{'helpform'}},$field);
15576: }
15577: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
15578: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
15579: push(@{$changes{'helpform'}},'maxsize');
15580: }
15581: }
15582: }
1.134 raeburn 15583: }
1.28 raeburn 15584: }
1.315 raeburn 15585: if (@statuses) {
15586: if (ref($currsetting{'overrides'}) eq 'HASH') {
15587: foreach my $key (keys(%{$currsetting{'overrides'}})) {
15588: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
15589: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
15590: foreach my $item (@contacts,'bcc','others','include') {
15591: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
15592: push(@{$changes{'overrides'}},$key);
15593: last;
15594: }
15595: }
15596: } else {
15597: push(@{$changes{'overrides'}},$key);
15598: }
15599: }
15600: }
15601: foreach my $key (@overrides) {
15602: unless (exists($currsetting{'overrides'}{$key})) {
15603: push(@{$changes{'overrides'}},$key);
15604: }
15605: }
15606: } else {
15607: foreach my $key (@overrides) {
15608: push(@{$changes{'overrides'}},$key);
15609: }
15610: }
15611: }
1.340 raeburn 15612: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
15613: foreach my $key ('excluded','weights','threshold','sysmail') {
15614: if ($key eq 'excluded') {
15615: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
15616: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
15617: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
15618: (@{$currsetting{'lonstatus'}{$key}})) {
15619: my @diffs =
15620: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
15621: $currsetting{'lonstatus'}{$key});
15622: if (@diffs) {
15623: push(@{$changes{'lonstatus'}},$key);
15624: }
15625: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
15626: push(@{$changes{'lonstatus'}},$key);
15627: }
15628: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
15629: (@{$currsetting{'lonstatus'}{$key}})) {
15630: push(@{$changes{'lonstatus'}},$key);
15631: }
15632: } elsif ($key eq 'weights') {
15633: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
15634: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
15635: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 15636: foreach my $type ('E','W','N','U') {
1.340 raeburn 15637: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
15638: $currsetting{'lonstatus'}{$key}{$type}) {
15639: push(@{$changes{'lonstatus'}},$key);
15640: last;
15641: }
15642: }
15643: } else {
1.341 raeburn 15644: foreach my $type ('E','W','N','U') {
1.340 raeburn 15645: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
15646: push(@{$changes{'lonstatus'}},$key);
15647: last;
15648: }
15649: }
15650: }
15651: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 15652: foreach my $type ('E','W','N','U') {
1.340 raeburn 15653: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
15654: push(@{$changes{'lonstatus'}},$key);
15655: last;
15656: }
15657: }
15658: }
15659: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
15660: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
15661: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
15662: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
15663: push(@{$changes{'lonstatus'}},$key);
15664: }
15665: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
15666: push(@{$changes{'lonstatus'}},$key);
15667: }
15668: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
15669: push(@{$changes{'lonstatus'}},$key);
15670: }
15671: }
15672: }
15673: } else {
15674: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
15675: foreach my $key ('excluded','weights','threshold','sysmail') {
15676: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
15677: push(@{$changes{'lonstatus'}},$key);
15678: }
15679: }
15680: }
15681: }
1.28 raeburn 15682: } else {
15683: my %default;
15684: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
15685: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
15686: $default{'errormail'} = 'adminemail';
15687: $default{'packagesmail'} = 'adminemail';
15688: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 15689: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 15690: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 15691: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 15692: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 15693: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 15694: foreach my $item (@contacts) {
15695: if ($to{$item} ne $default{$item}) {
1.286 raeburn 15696: $changes{$item} = 1;
1.203 raeburn 15697: }
1.28 raeburn 15698: }
15699: foreach my $type (@mailings) {
15700: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
15701: push(@{$changes{$type}},@{$newsetting{$type}});
15702: }
15703: if ($others{$type} ne '') {
15704: push(@{$changes{$type}},'others');
1.134 raeburn 15705: }
1.286 raeburn 15706: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15707: if ($bcc{$type} ne '') {
15708: push(@{$changes{$type}},'bcc');
15709: }
1.286 raeburn 15710: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
15711: push(@{$changes{$type}},'include');
15712: }
1.134 raeburn 15713: }
1.28 raeburn 15714: }
1.286 raeburn 15715: if (ref($fields) eq 'ARRAY') {
15716: foreach my $field (@{$fields}) {
15717: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
15718: push(@{$changes{'helpform'}},$field);
15719: }
15720: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
15721: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
15722: push(@{$changes{'helpform'}},'maxsize');
15723: }
15724: }
15725: }
1.289 raeburn 15726: }
1.340 raeburn 15727: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
15728: foreach my $key ('excluded','weights','threshold','sysmail') {
15729: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
15730: push(@{$changes{'lonstatus'}},$key);
15731: }
15732: }
15733: }
1.28 raeburn 15734: }
1.203 raeburn 15735: foreach my $item (@toggles) {
15736: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
15737: $changes{$item} = 1;
15738: } elsif ((!$env{'form.'.$item}) &&
15739: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
15740: $changes{$item} = 1;
15741: }
15742: }
1.28 raeburn 15743: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
15744: $dom);
15745: if ($putresult eq 'ok') {
15746: if (keys(%changes) > 0) {
1.205 raeburn 15747: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 15748: if (ref($lastactref) eq 'HASH') {
15749: $lastactref->{'domainconfig'} = 1;
15750: }
1.28 raeburn 15751: my ($titles,$short_titles) = &contact_titles();
15752: $resulttext = &mt('Changes made:').'<ul>';
15753: foreach my $item (@contacts) {
15754: if ($changes{$item}) {
15755: $resulttext .= '<li>'.$titles->{$item}.
15756: &mt(' set to: ').
15757: '<span class="LC_cusr_emph">'.
15758: $to{$item}.'</span></li>';
15759: }
15760: }
15761: foreach my $type (@mailings) {
15762: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 15763: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 15764: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 15765: } else {
15766: $resulttext .= '<li>'.$titles->{$type}.': ';
15767: }
1.28 raeburn 15768: my @text;
15769: foreach my $item (@{$newsetting{$type}}) {
15770: push(@text,$short_titles->{$item});
15771: }
15772: if ($others{$type} ne '') {
15773: push(@text,$others{$type});
15774: }
1.286 raeburn 15775: if (@text) {
15776: $resulttext .= '<span class="LC_cusr_emph">'.
15777: join(', ',@text).'</span>';
15778: }
15779: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15780: if ($bcc{$type} ne '') {
1.286 raeburn 15781: my $bcctext;
15782: if (@text) {
1.289 raeburn 15783: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 15784: } else {
15785: $bcctext = '(Bcc)';
15786: }
15787: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
15788: } elsif (!@text) {
15789: $resulttext .= &mt('No one');
15790: }
1.289 raeburn 15791: if ($includestr{$type} ne '') {
1.286 raeburn 15792: if ($includeloc{$type} eq 'b') {
15793: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
15794: } elsif ($includeloc{$type} eq 's') {
15795: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
15796: }
1.134 raeburn 15797: }
1.286 raeburn 15798: } elsif (!@text) {
15799: $resulttext .= &mt('No recipients');
1.134 raeburn 15800: }
15801: $resulttext .= '</li>';
1.28 raeburn 15802: }
15803: }
1.315 raeburn 15804: if (ref($changes{'overrides'}) eq 'ARRAY') {
15805: my @deletions;
15806: foreach my $type (@{$changes{'overrides'}}) {
15807: if ($usertypeshash{$type}) {
15808: if (grep(/^\Q$type\E/,@overrides)) {
15809: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
15810: $usertypeshash{$type}).'<ul><li>';
15811: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
15812: my @text;
15813: foreach my $item (@contacts) {
15814: if ($newsetting{'override_'.$type}{$item}) {
15815: push(@text,$short_titles->{$item});
15816: }
15817: }
15818: if ($newsetting{'override_'.$type}{'others'} ne '') {
15819: push(@text,$newsetting{'override_'.$type}{'others'});
15820: }
15821:
15822: if (@text) {
15823: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
15824: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
15825: }
15826: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
15827: my $bcctext;
15828: if (@text) {
15829: $bcctext = ' '.&mt('with Bcc to');
15830: } else {
15831: $bcctext = '(Bcc)';
15832: }
15833: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
15834: } elsif (!@text) {
15835: $resulttext .= &mt('Helpdesk e-mail sent to no one');
15836: }
15837: $resulttext .= '</li>';
15838: if ($newsetting{'override_'.$type}{'include'} ne '') {
15839: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
15840: if ($loc eq 'b') {
15841: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
15842: } elsif ($loc eq 's') {
15843: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
15844: }
15845: }
15846: }
15847: $resulttext .= '</li></ul></li>';
15848: } else {
15849: push(@deletions,$usertypeshash{$type});
15850: }
15851: }
15852: }
15853: if (@deletions) {
15854: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
15855: join(', ',@deletions)).'</li>';
15856: }
15857: }
1.203 raeburn 15858: my @offon = ('off','on');
1.340 raeburn 15859: my $corelink = &core_link_msu();
1.203 raeburn 15860: if ($changes{'reporterrors'}) {
15861: $resulttext .= '<li>'.
15862: &mt('E-mail error reports to [_1] set to "'.
15863: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 15864: $corelink).
1.203 raeburn 15865: '</li>';
15866: }
15867: if ($changes{'reportupdates'}) {
15868: $resulttext .= '<li>'.
15869: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
15870: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 15871: $corelink).
1.203 raeburn 15872: '</li>';
15873: }
1.340 raeburn 15874: if ($changes{'reportstatus'}) {
15875: $resulttext .= '<li>'.
15876: &mt('E-mail status if errors above threshold to [_1] set to "'.
15877: $offon[$env{'form.reportstatus'}].'".',
15878: $corelink).
15879: '</li>';
15880: }
15881: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
15882: $resulttext .= '<li>'.
15883: &mt('Nightly status check e-mail settings').':<ul>';
15884: my (%defval,%use_def,%shown);
15885: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
15886: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
15887: $defval{'weights'} =
1.341 raeburn 15888: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 15889: $defval{'excluded'} = &mt('None');
15890: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
15891: foreach my $item ('threshold','sysmail','weights','excluded') {
15892: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
15893: if (($item eq 'threshold') || ($item eq 'sysmail')) {
15894: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
15895: } elsif ($item eq 'weights') {
15896: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 15897: foreach my $type ('E','W','N','U') {
1.340 raeburn 15898: $shown{$item} .= $lonstatus_names->{$type}.'=';
15899: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
15900: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
15901: } else {
15902: $shown{$item} .= $lonstatus_defs->{$type};
15903: }
15904: $shown{$item} .= ', ';
15905: }
15906: $shown{$item} =~ s/, $//;
15907: } else {
15908: $shown{$item} = $defval{$item};
15909: }
15910: } elsif ($item eq 'excluded') {
15911: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
15912: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
15913: } else {
15914: $shown{$item} = $defval{$item};
15915: }
15916: }
15917: } else {
15918: $shown{$item} = $defval{$item};
15919: }
15920: }
15921: } else {
15922: foreach my $item ('threshold','weights','excluded','sysmail') {
15923: $shown{$item} = $defval{$item};
15924: }
15925: }
15926: foreach my $item ('threshold','weights','excluded','sysmail') {
15927: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
15928: $shown{$item}).'</li>';
15929: }
15930: $resulttext .= '</ul></li>';
15931: }
1.286 raeburn 15932: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
15933: my (@optional,@required,@unused,$maxsizechg);
15934: foreach my $field (@{$changes{'helpform'}}) {
15935: if ($field eq 'maxsize') {
15936: $maxsizechg = 1;
15937: next;
15938: }
15939: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 15940: push(@optional,$field);
1.286 raeburn 15941: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
15942: push(@unused,$field);
15943: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 15944: push(@required,$field);
1.286 raeburn 15945: }
15946: }
15947: if (@optional) {
15948: $resulttext .= '<li>'.
15949: &mt('Help form fields changed to "Optional": [_1].',
15950: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
15951: '</li>';
15952: }
15953: if (@required) {
15954: $resulttext .= '<li>'.
15955: &mt('Help form fields changed to "Required": [_1].',
15956: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
15957: '</li>';
15958: }
15959: if (@unused) {
15960: $resulttext .= '<li>'.
15961: &mt('Help form fields changed to "Not shown": [_1].',
15962: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
15963: '</li>';
15964: }
15965: if ($maxsizechg) {
15966: $resulttext .= '<li>'.
15967: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
15968: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
15969: '</li>';
15970: }
15971: }
1.28 raeburn 15972: $resulttext .= '</ul>';
15973: } else {
1.288 raeburn 15974: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 15975: }
15976: } else {
15977: $resulttext = '<span class="LC_error">'.
15978: &mt('An error occurred: [_1].',$putresult).'</span>';
15979: }
15980: return $resulttext;
15981: }
15982:
1.357 raeburn 15983: sub modify_privacy {
15984: my ($dom,%domconfig) = @_;
15985: my ($resulttext,%current,%changes);
15986: if (ref($domconfig{'privacy'}) eq 'HASH') {
15987: %current = %{$domconfig{'privacy'}};
15988: }
15989: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
15990: my @items = ('domain','author','course','community');
15991: my %names = &Apache::lonlocal::texthash (
15992: domain => 'Assigned domain role(s)',
15993: author => 'Assigned co-author role(s)',
15994: course => 'Assigned course role(s)',
15995: community => 'Assigned community role',
15996: );
15997: my %roles = &Apache::lonlocal::texthash (
15998: domain => 'Domain role',
15999: author => 'Co-author role',
16000: course => 'Course role',
16001: community => 'Community role',
16002: );
16003: my %titles = &Apache::lonlocal::texthash (
16004: approval => 'Approval for role in different domain',
16005: othdom => 'User information available in other domain',
16006: priv => 'Information viewable by privileged user in same domain',
16007: unpriv => 'Information viewable by unprivileged user in same domain',
16008: instdom => 'Other domain shares institution/provider',
16009: extdom => 'Other domain has different institution/provider',
16010: none => 'Not allowed',
16011: user => 'User authorizes',
16012: domain => 'Domain Coordinator authorizes',
16013: auto => 'Unrestricted',
16014: );
16015: my %fieldnames = &Apache::lonlocal::texthash (
16016: id => 'Student/Employee ID',
16017: permanentemail => 'E-mail address',
16018: lastname => 'Last Name',
16019: firstname => 'First Name',
16020: middlename => 'Middle Name',
16021: generation => 'Generation',
16022: );
16023: my ($othertitle,$usertypes,$types) =
16024: &Apache::loncommon::sorted_inst_types($dom);
16025: my (%by_ip,%by_location,@intdoms,@instdoms);
16026: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
16027:
16028: my %privacyhash = (
16029: 'approval' => {
16030: instdom => {},
16031: extdom => {},
16032: },
16033: 'othdom' => {},
16034: 'priv' => {},
16035: 'unpriv' => {},
16036: );
16037: foreach my $item (@items) {
16038: if (@instdoms > 1) {
16039: if ($env{'form.privacy_approval_instdom'.$item} =~ /^(none|user|domain|auto)$/) {
16040: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
16041: }
16042: if (ref($current{'approval'}) eq 'HASH') {
16043: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
16044: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
16045: $changes{'approval'} = 1;
16046: }
16047: }
16048: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
16049: $changes{'approval'} = 1;
16050: }
16051: }
16052: if (keys(%by_location) > 0) {
16053: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
16054: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
16055: }
16056: if (ref($current{'approval'}) eq 'HASH') {
16057: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
16058: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
16059: $changes{'approval'} = 1;
16060: }
16061: }
16062: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
16063: $changes{'approval'} = 1;
16064: }
16065: }
16066: foreach my $status ('priv','unpriv') {
16067: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
16068: my @newvalues;
16069: foreach my $field (@possibles) {
16070: if (grep(/^\Q$field\E$/,@fields)) {
16071: $privacyhash{$status}{$item}{$field} = 1;
16072: push(@newvalues,$field);
16073: }
16074: }
16075: @newvalues = sort(@newvalues);
16076: if (ref($current{$status}) eq 'HASH') {
16077: if (ref($current{$status}{$item}) eq 'HASH') {
16078: my @currvalues = sort(keys(%{$current{$status}{$item}}));
16079: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
16080: if (@diffs > 0) {
16081: $changes{$status} = 1;
16082: }
16083: }
16084: } else {
16085: my @stdfields;
16086: foreach my $field (@fields) {
16087: if ($field eq 'id') {
16088: next if ($status eq 'unpriv');
16089: next if (($status eq 'priv') && ($item eq 'community'));
16090: }
16091: push(@stdfields,$field);
16092: }
16093: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
16094: if (@diffs > 0) {
16095: $changes{$status} = 1;
16096: }
16097: }
16098: }
16099: }
16100: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
16101: my @statuses;
16102: if (ref($types) eq 'ARRAY') {
16103: @statuses = @{$types};
16104: }
16105: foreach my $type (@statuses,'default') {
16106: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
16107: my @newvalues;
16108: foreach my $field (sort(@possfields)) {
16109: if (grep(/^\Q$field\E$/,@fields)) {
16110: $privacyhash{'othdom'}{$type}{$field} = 1;
16111: push(@newvalues,$field);
16112: }
16113: }
16114: @newvalues = sort(@newvalues);
16115: if (ref($current{'othdom'}) eq 'HASH') {
16116: if (ref($current{'othdom'}{$type}) eq 'HASH') {
16117: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
16118: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
16119: if (@diffs > 0) {
16120: $changes{'othdom'} = 1;
16121: }
16122: }
16123: } else {
16124: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
16125: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
16126: if (@diffs > 0) {
16127: $changes{'othdom'} = 1;
16128: }
16129: }
16130: }
16131: }
16132: my %confighash = (
16133: privacy => \%privacyhash,
16134: );
16135: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
16136: if ($putresult eq 'ok') {
16137: if (keys(%changes) > 0) {
16138: $resulttext = &mt('Changes made: ').'<ul>';
16139: foreach my $key ('approval','othdom','priv','unpriv') {
16140: if ($changes{$key}) {
16141: $resulttext .= '<li>'.$titles{$key}.':<ul>';
16142: if ($key eq 'approval') {
16143: if (keys(%{$privacyhash{$key}{instdom}})) {
16144: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
16145: foreach my $item (@items) {
16146: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
16147: }
16148: $resulttext .= '</ul></li>';
16149: }
16150: if (keys(%{$privacyhash{$key}{extdom}})) {
16151: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
16152: foreach my $item (@items) {
16153: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
16154: }
16155: $resulttext .= '</ul></li>';
16156: }
16157: } elsif ($key eq 'othdom') {
16158: my @statuses;
16159: if (ref($types) eq 'ARRAY') {
16160: @statuses = @{$types};
16161: }
16162: if (ref($privacyhash{$key}) eq 'HASH') {
16163: foreach my $status (@statuses,'default') {
16164: if ($status eq 'default') {
16165: $resulttext .= '<li>'.$othertitle.': ';
16166: } elsif (ref($usertypes) eq 'HASH') {
16167: $resulttext .= '<li>'.$usertypes->{$status}.': ';
16168: } else {
16169: next;
16170: }
16171: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
16172: if (keys(%{$privacyhash{$key}{$status}})) {
16173: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
16174: } else {
16175: $resulttext .= &mt('none');
16176: }
16177: }
16178: $resulttext .= '</li>';
16179: }
16180: }
16181: } else {
16182: foreach my $item (@items) {
16183: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
16184: $resulttext .= '<li>'.$names{$item}.': ';
16185: if (keys(%{$privacyhash{$key}{$item}})) {
16186: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
16187: } else {
16188: $resulttext .= &mt('none');
16189: }
16190: $resulttext .= '</li>';
16191: }
16192: }
16193: }
16194: $resulttext .= '</ul></li>';
16195: }
16196: }
16197: } else {
16198: $resulttext = &mt('No changes made to user information settings');
16199: }
16200: } else {
16201: $resulttext = '<span class="LC_error">'.
16202: &mt('An error occurred: [_1]',$putresult).'</span>';
16203: }
16204: return $resulttext;
16205: }
16206:
1.354 raeburn 16207: sub modify_passwords {
16208: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 16209: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
16210: $updatedefaults,$updateconf);
1.354 raeburn 16211: my $customfn = 'resetpw.html';
16212: if (ref($domconfig{'passwords'}) eq 'HASH') {
16213: %current = %{$domconfig{'passwords'}};
16214: }
16215: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16216: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
16217: if (ref($types) eq 'ARRAY') {
16218: @oktypes = @{$types};
16219: }
16220: push(@oktypes,'default');
16221:
16222: my %titles = &Apache::lonlocal::texthash (
16223: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
16224: intauth_check => 'Check bcrypt cost if authenticated',
16225: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
16226: permanent => 'Permanent e-mail address',
16227: critical => 'Critical notification address',
16228: notify => 'Notification address',
16229: min => 'Minimum password length',
16230: max => 'Maximum password length',
16231: chars => 'Required characters',
16232: expire => 'Password expiration (days)',
1.356 raeburn 16233: numsaved => 'Number of previous passwords to save',
1.354 raeburn 16234: reset => 'Resetting Forgotten Password',
16235: intauth => 'Encryption of Stored Passwords (Internal Auth)',
16236: rules => 'Rules for LON-CAPA Passwords',
16237: crsownerchg => 'Course Owner Changing Student Passwords',
16238: username => 'Username',
16239: email => 'E-mail address',
16240: );
16241:
16242: #
16243: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
16244: #
16245: my (%curr_defaults,%save_defaults);
16246: if (ref($domconfig{'defaults'}) eq 'HASH') {
16247: foreach my $key (keys(%{$domconfig{'defaults'}})) {
16248: if ($key =~ /^intauth_(cost|check|switch)$/) {
16249: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
16250: } else {
16251: $save_defaults{$key} = $domconfig{'defaults'}{$key};
16252: }
16253: }
16254: }
16255: my %staticdefaults = (
16256: 'resetlink' => 2,
16257: 'resetcase' => \@oktypes,
16258: 'resetprelink' => 'both',
16259: 'resetemail' => ['critical','notify','permanent'],
16260: 'intauth_cost' => 10,
16261: 'intauth_check' => 0,
16262: 'intauth_switch' => 0,
16263: );
1.365 raeburn 16264: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 16265: foreach my $type (@oktypes) {
16266: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
16267: }
16268: my $linklife = $env{'form.passwords_link'};
16269: $linklife =~ s/^\s+|\s+$//g;
16270: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
16271: $newvalues{'resetlink'} = $linklife;
16272: if ($current{'resetlink'}) {
16273: if ($current{'resetlink'} ne $linklife) {
16274: $changes{'reset'} = 1;
16275: }
1.368 raeburn 16276: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16277: if ($staticdefaults{'resetlink'} ne $linklife) {
16278: $changes{'reset'} = 1;
16279: }
16280: }
16281: } elsif ($current{'resetlink'}) {
16282: $changes{'reset'} = 1;
16283: }
16284: my @casesens;
16285: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
16286: foreach my $case (sort(@posscase)) {
16287: if (grep(/^\Q$case\E$/,@oktypes)) {
16288: push(@casesens,$case);
16289: }
16290: }
16291: $newvalues{'resetcase'} = \@casesens;
16292: if (ref($current{'resetcase'}) eq 'ARRAY') {
16293: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
16294: if (@diffs > 0) {
16295: $changes{'reset'} = 1;
16296: }
1.368 raeburn 16297: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16298: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
16299: if (@diffs > 0) {
16300: $changes{'reset'} = 1;
16301: }
16302: }
16303: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
16304: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
16305: if (exists($current{'resetprelink'})) {
16306: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
16307: $changes{'reset'} = 1;
16308: }
1.368 raeburn 16309: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16310: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
16311: $changes{'reset'} = 1;
16312: }
16313: }
16314: } elsif ($current{'resetprelink'}) {
16315: $changes{'reset'} = 1;
16316: }
16317: foreach my $type (@oktypes) {
16318: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
16319: my @postlink;
16320: foreach my $item (sort(@possplink)) {
16321: if ($item =~ /^(email|username)$/) {
16322: push(@postlink,$item);
16323: }
16324: }
16325: $newvalues{'resetpostlink'}{$type} = \@postlink;
16326: unless ($changes{'reset'}) {
16327: if (ref($current{'resetpostlink'}) eq 'HASH') {
16328: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
16329: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
16330: if (@diffs > 0) {
16331: $changes{'reset'} = 1;
16332: }
16333: } else {
16334: $changes{'reset'} = 1;
16335: }
1.368 raeburn 16336: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16337: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
16338: if (@diffs > 0) {
16339: $changes{'reset'} = 1;
16340: }
16341: }
16342: }
16343: }
16344: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
16345: my @resetemail;
16346: foreach my $item (sort(@possemailsrc)) {
16347: if ($item =~ /^(permanent|critical|notify)$/) {
16348: push(@resetemail,$item);
16349: }
16350: }
16351: $newvalues{'resetemail'} = \@resetemail;
16352: unless ($changes{'reset'}) {
16353: if (ref($current{'resetemail'}) eq 'ARRAY') {
16354: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
16355: if (@diffs > 0) {
16356: $changes{'reset'} = 1;
16357: }
1.368 raeburn 16358: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16359: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
16360: if (@diffs > 0) {
16361: $changes{'reset'} = 1;
16362: }
16363: }
16364: }
16365: if ($env{'form.passwords_stdtext'} == 0) {
16366: $newvalues{'resetremove'} = 1;
16367: unless ($current{'resetremove'}) {
16368: $changes{'reset'} = 1;
16369: }
16370: } elsif ($current{'resetremove'}) {
16371: $changes{'reset'} = 1;
16372: }
16373: if ($env{'form.passwords_customfile.filename'} ne '') {
16374: my $servadm = $r->dir_config('lonAdmEMail');
16375: my ($configuserok,$author_ok,$switchserver) =
16376: &config_check($dom,$confname,$servadm);
16377: my $error;
16378: if ($configuserok eq 'ok') {
16379: if ($switchserver) {
16380: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
16381: } else {
16382: if ($author_ok eq 'ok') {
16383: my ($result,$customurl) =
16384: &publishlogo($r,'upload','passwords_customfile',$dom,
16385: $confname,'customtext/resetpw','','',$customfn);
16386: if ($result eq 'ok') {
16387: $newvalues{'resetcustom'} = $customurl;
16388: $changes{'reset'} = 1;
16389: } else {
16390: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
16391: }
16392: } else {
16393: $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);
16394: }
16395: }
16396: } else {
16397: $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);
16398: }
16399: if ($error) {
16400: &Apache::lonnet::logthis($error);
16401: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
16402: }
16403: } elsif ($current{'resetcustom'}) {
16404: if ($env{'form.passwords_custom_del'}) {
16405: $changes{'reset'} = 1;
16406: } else {
16407: $newvalues{'resetcustom'} = $current{'resetcustom'};
16408: }
16409: }
16410: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
16411: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
16412: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
16413: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
16414: $changes{'intauth'} = 1;
16415: }
16416: } else {
16417: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
16418: }
16419: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
16420: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
16421: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
16422: $changes{'intauth'} = 1;
16423: }
16424: } else {
16425: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
16426: }
16427: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
16428: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
16429: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
16430: $changes{'intauth'} = 1;
16431: }
16432: } else {
16433: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
16434: }
16435: foreach my $item ('cost','check','switch') {
16436: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
16437: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
16438: $updatedefaults = 1;
16439: }
16440: }
1.356 raeburn 16441: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 16442: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.356 raeburn 16443: my $ruleok;
16444: if ($rule eq 'expire') {
1.365 raeburn 16445: if (($env{'form.passwords_'.$rule} =~ /^\d+(|\.\d*)$/) &&
16446: ($env{'form.passwords_'.$rule} ne '0')) {
1.359 raeburn 16447: $ruleok = 1;
1.356 raeburn 16448: }
1.365 raeburn 16449: } elsif ($rule eq 'min') {
16450: if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
16451: if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
16452: $ruleok = 1;
16453: }
16454: }
16455: } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
16456: ($env{'form.passwords_'.$rule} ne '0')) {
1.356 raeburn 16457: $ruleok = 1;
16458: }
16459: if ($ruleok) {
1.354 raeburn 16460: $newvalues{$rule} = $env{'form.passwords_'.$rule};
16461: if (exists($current{$rule})) {
16462: if ($newvalues{$rule} ne $current{$rule}) {
16463: $changes{'rules'} = 1;
16464: }
16465: } elsif ($rule eq 'min') {
16466: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
16467: $changes{'rules'} = 1;
16468: }
1.370 raeburn 16469: } else {
16470: $changes{'rules'} = 1;
1.354 raeburn 16471: }
16472: } elsif (exists($current{$rule})) {
16473: $changes{'rules'} = 1;
16474: }
16475: }
16476: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
16477: my @chars;
16478: foreach my $item (sort(@posschars)) {
16479: if ($item =~ /^(uc|lc|num|spec)$/) {
16480: push(@chars,$item);
16481: }
16482: }
16483: $newvalues{'chars'} = \@chars;
16484: unless ($changes{'rules'}) {
16485: if (ref($current{'chars'}) eq 'ARRAY') {
16486: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
16487: if (@diffs > 0) {
16488: $changes{'rules'} = 1;
16489: }
16490: } else {
16491: if (@chars > 0) {
16492: $changes{'rules'} = 1;
16493: }
16494: }
16495: }
1.359 raeburn 16496: my %crsownerchg = (
16497: by => [],
16498: for => [],
16499: );
16500: foreach my $item ('by','for') {
16501: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
16502: foreach my $type (sort(@posstypes)) {
16503: if (grep(/^\Q$type\E$/,@oktypes)) {
16504: push(@{$crsownerchg{$item}},$type);
16505: }
16506: }
16507: }
16508: $newvalues{'crsownerchg'} = \%crsownerchg;
16509: if (ref($current{'crsownerchg'}) eq 'HASH') {
16510: foreach my $item ('by','for') {
16511: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
16512: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
16513: if (@diffs > 0) {
16514: $changes{'crsownerchg'} = 1;
16515: last;
16516: }
16517: }
16518: }
1.368 raeburn 16519: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 16520: foreach my $item ('by','for') {
16521: if (@{$crsownerchg{$item}} > 0) {
16522: $changes{'crsownerchg'} = 1;
16523: last;
16524: }
1.354 raeburn 16525: }
16526: }
16527:
16528: my %confighash = (
16529: defaults => \%save_defaults,
16530: passwords => \%newvalues,
16531: );
16532: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
16533:
16534: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
16535: if ($putresult eq 'ok') {
16536: if (keys(%changes) > 0) {
16537: $resulttext = &mt('Changes made: ').'<ul>';
16538: foreach my $key ('reset','intauth','rules','crsownerchg') {
16539: if ($changes{$key}) {
1.355 raeburn 16540: unless ($key eq 'intauth') {
16541: $updateconf = 1;
16542: }
1.354 raeburn 16543: $resulttext .= '<li>'.$titles{$key}.':<ul>';
16544: if ($key eq 'reset') {
16545: if ($confighash{'passwords'}{'captcha'} eq 'original') {
16546: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
16547: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
16548: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 16549: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
16550: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
16551: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
16552: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
16553: }
1.354 raeburn 16554: } else {
16555: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
16556: }
16557: if ($confighash{'passwords'}{'resetlink'}) {
16558: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
16559: } else {
16560: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
16561: &mt('Will default to 2 hours').'</li>';
16562: }
16563: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
16564: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
16565: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
16566: } else {
16567: my $casesens;
16568: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
16569: if ($type eq 'default') {
16570: $casesens .= $othertitle.', ';
16571: } elsif ($usertypes->{$type} ne '') {
16572: $casesens .= $usertypes->{$type}.', ';
16573: }
16574: }
16575: $casesens =~ s/\Q, \E$//;
16576: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
16577: }
16578: } else {
16579: $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>';
16580: }
16581: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
16582: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
16583: } else {
16584: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
16585: }
16586: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
16587: my $output;
16588: if (ref($types) eq 'ARRAY') {
16589: foreach my $type (@{$types}) {
16590: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
16591: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
16592: $output .= $usertypes->{$type}.' -- '.&mt('none');
16593: } else {
16594: $output .= $usertypes->{$type}.' -- '.
16595: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
16596: }
16597: }
16598: }
16599: }
16600: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
16601: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
16602: $output .= $othertitle.' -- '.&mt('none');
16603: } else {
16604: $output .= $othertitle.' -- '.
16605: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
16606: }
16607: }
16608: if ($output) {
16609: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
16610: } else {
16611: $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>';
16612: }
16613: } else {
16614: $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>';
16615: }
16616: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
16617: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
16618: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
16619: } else {
16620: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
16621: }
16622: } else {
1.379 raeburn 16623: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
1.354 raeburn 16624: }
16625: if ($confighash{'passwords'}{'resetremove'}) {
16626: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
16627: } else {
16628: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
16629: }
16630: if ($confighash{'passwords'}{'resetcustom'}) {
16631: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 16632: &mt('custom text'),600,500,undef,undef,
16633: undef,undef,'background-color:#ffffff');
16634: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 16635: } else {
16636: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
16637: }
16638: } elsif ($key eq 'intauth') {
16639: foreach my $item ('cost','switch','check') {
16640: my $value = $save_defaults{$key.'_'.$item};
16641: if ($item eq 'switch') {
16642: my %optiondesc = &Apache::lonlocal::texthash (
16643: 0 => 'No',
16644: 1 => 'Yes',
16645: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
16646: );
16647: if ($value =~ /^(0|1|2)$/) {
16648: $value = $optiondesc{$value};
16649: } else {
16650: $value = &mt('none -- defaults to No');
16651: }
16652: } elsif ($item eq 'check') {
16653: my %optiondesc = &Apache::lonlocal::texthash (
16654: 0 => 'No',
16655: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
16656: 2 => 'Yes, disallow login if stored cost is less than domain default',
16657: );
16658: if ($value =~ /^(0|1|2)$/) {
16659: $value = $optiondesc{$value};
16660: } else {
16661: $value = &mt('none -- defaults to No');
16662: }
16663: }
16664: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
16665: }
16666: } elsif ($key eq 'rules') {
1.356 raeburn 16667: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 16668: if ($confighash{'passwords'}{$rule} eq '') {
16669: if ($rule eq 'min') {
1.356 raeburn 16670: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 16671: ' '.&mt('Default of [_1] will be used',
16672: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 16673: } else {
16674: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 16675: }
16676: } else {
16677: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
16678: }
16679: }
1.370 raeburn 16680: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
16681: if (@{$confighash{'passwords'}{'chars'}} > 0) {
16682: my %rulenames = &Apache::lonlocal::texthash(
16683: uc => 'At least one upper case letter',
16684: lc => 'At least one lower case letter',
16685: num => 'At least one number',
16686: spec => 'At least one non-alphanumeric',
16687: );
16688: my $needed = '<ul><li>'.
16689: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
16690: '</li></ul>';
16691: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
16692: } else {
16693: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
16694: }
16695: } else {
16696: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
16697: }
1.354 raeburn 16698: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 16699: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
16700: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
16701: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
16702: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
16703: } else {
16704: my %crsownerstr;
16705: foreach my $item ('by','for') {
16706: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
16707: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
16708: if ($type eq 'default') {
16709: $crsownerstr{$item} .= $othertitle.', ';
16710: } elsif ($usertypes->{$type} ne '') {
16711: $crsownerstr{$item} .= $usertypes->{$type}.', ';
16712: }
16713: }
16714: $crsownerstr{$item} =~ s/\Q, \E$//;
16715: }
16716: }
16717: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
16718: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
16719: }
1.354 raeburn 16720: } else {
1.359 raeburn 16721: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 16722: }
16723: }
16724: $resulttext .= '</ul></li>';
16725: }
16726: }
16727: $resulttext .= '</ul>';
16728: } else {
16729: $resulttext = &mt('No changes made to password settings');
16730: }
1.355 raeburn 16731: my $cachetime = 24*60*60;
1.354 raeburn 16732: if ($updatedefaults) {
16733: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16734: if (ref($lastactref) eq 'HASH') {
16735: $lastactref->{'domdefaults'} = 1;
16736: }
16737: }
1.355 raeburn 16738: if ($updateconf) {
16739: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
16740: if (ref($lastactref) eq 'HASH') {
16741: $lastactref->{'passwdconf'} = 1;
16742: }
16743: }
1.354 raeburn 16744: } else {
16745: $resulttext = '<span class="LC_error">'.
16746: &mt('An error occurred: [_1]',$putresult).'</span>';
16747: }
16748: if ($errors) {
16749: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
16750: $errors.'</ul></p>';
16751: }
16752: return $resulttext;
16753: }
16754:
1.28 raeburn 16755: sub modify_usercreation {
1.27 raeburn 16756: my ($dom,%domconfig) = @_;
1.224 raeburn 16757: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 16758: my $warningmsg;
1.27 raeburn 16759: if (ref($domconfig{'usercreation'}) eq 'HASH') {
16760: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 16761: if ($key eq 'cancreate') {
16762: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
16763: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 16764: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
16765: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
16766: } else {
1.224 raeburn 16767: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
16768: }
16769: }
16770: }
16771: } elsif ($key eq 'email_rule') {
16772: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
16773: } else {
16774: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
16775: }
1.27 raeburn 16776: }
16777: }
16778: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 16779: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 16780: my @contexts = ('author','course','requestcrs');
1.34 raeburn 16781: foreach my $item(@contexts) {
1.224 raeburn 16782: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 16783: }
1.34 raeburn 16784: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
16785: foreach my $item (@contexts) {
1.224 raeburn 16786: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
16787: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 16788: }
1.27 raeburn 16789: }
1.34 raeburn 16790: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
16791: foreach my $item (@contexts) {
1.43 raeburn 16792: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 16793: if ($cancreate{$item} ne 'any') {
16794: push(@{$changes{'cancreate'}},$item);
16795: }
16796: } else {
16797: if ($cancreate{$item} ne 'none') {
16798: push(@{$changes{'cancreate'}},$item);
16799: }
1.27 raeburn 16800: }
16801: }
16802: } else {
1.43 raeburn 16803: foreach my $item (@contexts) {
1.34 raeburn 16804: push(@{$changes{'cancreate'}},$item);
16805: }
1.27 raeburn 16806: }
1.34 raeburn 16807:
1.27 raeburn 16808: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
16809: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
16810: if (!grep(/^\Q$type\E$/,@username_rule)) {
16811: push(@{$changes{'username_rule'}},$type);
16812: }
16813: }
16814: foreach my $type (@username_rule) {
16815: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
16816: push(@{$changes{'username_rule'}},$type);
16817: }
16818: }
16819: } else {
16820: push(@{$changes{'username_rule'}},@username_rule);
16821: }
16822:
1.32 raeburn 16823: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
16824: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
16825: if (!grep(/^\Q$type\E$/,@id_rule)) {
16826: push(@{$changes{'id_rule'}},$type);
16827: }
16828: }
16829: foreach my $type (@id_rule) {
16830: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
16831: push(@{$changes{'id_rule'}},$type);
16832: }
16833: }
16834: } else {
16835: push(@{$changes{'id_rule'}},@id_rule);
16836: }
16837:
1.43 raeburn 16838: my @authen_contexts = ('author','course','domain');
1.325 raeburn 16839: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 16840: my %authhash;
1.43 raeburn 16841: foreach my $item (@authen_contexts) {
1.28 raeburn 16842: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
16843: foreach my $auth (@authtypes) {
16844: if (grep(/^\Q$auth\E$/,@authallowed)) {
16845: $authhash{$item}{$auth} = 1;
16846: } else {
16847: $authhash{$item}{$auth} = 0;
16848: }
16849: }
16850: }
16851: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 16852: foreach my $item (@authen_contexts) {
1.28 raeburn 16853: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
16854: foreach my $auth (@authtypes) {
16855: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
16856: push(@{$changes{'authtypes'}},$item);
16857: last;
16858: }
16859: }
16860: }
16861: }
16862: } else {
1.43 raeburn 16863: foreach my $item (@authen_contexts) {
1.28 raeburn 16864: push(@{$changes{'authtypes'}},$item);
16865: }
16866: }
16867:
1.224 raeburn 16868: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
16869: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
16870: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
16871: $save_usercreate{'id_rule'} = \@id_rule;
16872: $save_usercreate{'username_rule'} = \@username_rule,
16873: $save_usercreate{'authtypes'} = \%authhash;
16874:
1.27 raeburn 16875: my %usercreation_hash = (
1.224 raeburn 16876: usercreation => \%save_usercreate,
16877: );
1.27 raeburn 16878:
16879: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
16880: $dom);
1.50 raeburn 16881:
1.224 raeburn 16882: if ($putresult eq 'ok') {
16883: if (keys(%changes) > 0) {
16884: $resulttext = &mt('Changes made:').'<ul>';
16885: if (ref($changes{'cancreate'}) eq 'ARRAY') {
16886: my %lt = &usercreation_types();
16887: foreach my $type (@{$changes{'cancreate'}}) {
16888: my $chgtext = $lt{$type}.', ';
16889: if ($cancreate{$type} eq 'none') {
16890: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
16891: } elsif ($cancreate{$type} eq 'any') {
16892: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
16893: } elsif ($cancreate{$type} eq 'official') {
16894: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
16895: } elsif ($cancreate{$type} eq 'unofficial') {
16896: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
16897: }
16898: $resulttext .= '<li>'.$chgtext.'</li>';
16899: }
16900: }
16901: if (ref($changes{'username_rule'}) eq 'ARRAY') {
16902: my ($rules,$ruleorder) =
16903: &Apache::lonnet::inst_userrules($dom,'username');
16904: my $chgtext = '<ul>';
16905: foreach my $type (@username_rule) {
16906: if (ref($rules->{$type}) eq 'HASH') {
16907: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
16908: }
16909: }
16910: $chgtext .= '</ul>';
16911: if (@username_rule > 0) {
16912: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
16913: } else {
16914: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
16915: }
16916: }
16917: if (ref($changes{'id_rule'}) eq 'ARRAY') {
16918: my ($idrules,$idruleorder) =
16919: &Apache::lonnet::inst_userrules($dom,'id');
16920: my $chgtext = '<ul>';
16921: foreach my $type (@id_rule) {
16922: if (ref($idrules->{$type}) eq 'HASH') {
16923: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
16924: }
16925: }
16926: $chgtext .= '</ul>';
16927: if (@id_rule > 0) {
16928: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
16929: } else {
16930: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
16931: }
16932: }
16933: my %authname = &authtype_names();
16934: my %context_title = &context_names();
16935: if (ref($changes{'authtypes'}) eq 'ARRAY') {
16936: my $chgtext = '<ul>';
16937: foreach my $type (@{$changes{'authtypes'}}) {
16938: my @allowed;
16939: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
16940: foreach my $auth (@authtypes) {
16941: if ($authhash{$type}{$auth}) {
16942: push(@allowed,$authname{$auth});
16943: }
16944: }
16945: if (@allowed > 0) {
16946: $chgtext .= join(', ',@allowed).'</li>';
16947: } else {
16948: $chgtext .= &mt('none').'</li>';
16949: }
16950: }
16951: $chgtext .= '</ul>';
16952: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
16953: $resulttext .= '</li>';
16954: }
16955: $resulttext .= '</ul>';
16956: } else {
16957: $resulttext = &mt('No changes made to user creation settings');
16958: }
16959: } else {
16960: $resulttext = '<span class="LC_error">'.
16961: &mt('An error occurred: [_1]',$putresult).'</span>';
16962: }
16963: if ($warningmsg ne '') {
16964: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
16965: }
16966: return $resulttext;
16967: }
16968:
16969: sub modify_selfcreation {
1.305 raeburn 16970: my ($dom,$lastactref,%domconfig) = @_;
16971: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
16972: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
16973: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 16974: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
16975: if (ref($typesref) eq 'ARRAY') {
16976: @types = @{$typesref};
16977: }
16978: if (ref($usertypesref) eq 'HASH') {
16979: %usertypes = %{$usertypesref};
1.228 raeburn 16980: }
1.303 raeburn 16981: $usertypes{'default'} = $othertitle;
1.224 raeburn 16982: #
16983: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
16984: #
16985: if (ref($domconfig{'usercreation'}) eq 'HASH') {
16986: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
16987: if ($key eq 'cancreate') {
16988: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
16989: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
16990: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 16991: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
16992: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
16993: ($item eq 'emailusername') || ($item eq 'shibenv') ||
16994: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 16995: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 16996: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
16997: } else {
16998: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
16999: }
17000: }
17001: }
17002: } elsif ($key eq 'email_rule') {
17003: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
17004: } else {
17005: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
17006: }
17007: }
17008: }
17009: #
17010: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
17011: #
17012: if (ref($domconfig{'usermodification'}) eq 'HASH') {
17013: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
17014: if ($key eq 'selfcreate') {
17015: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
17016: } else {
17017: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
17018: }
17019: }
17020: }
1.305 raeburn 17021: #
17022: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
17023: #
17024: if (ref($domconfig{'inststatus'}) eq 'HASH') {
17025: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
17026: if ($key eq 'inststatusguest') {
17027: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
17028: } else {
17029: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
17030: }
17031: }
17032: }
1.224 raeburn 17033:
17034: my @contexts = ('selfcreate');
17035: @{$cancreate{'selfcreate'}} = ();
17036: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 17037: if (@types) {
17038: @{$cancreate{'statustocreate'}} = ();
17039: }
1.236 raeburn 17040: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 17041: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 17042: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 17043: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 17044: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 17045: my %selfcreatetypes = (
17046: sso => 'users authenticated by institutional single sign on',
17047: login => 'users authenticated by institutional log-in',
1.303 raeburn 17048: email => 'users verified by e-mail',
1.50 raeburn 17049: );
1.224 raeburn 17050: #
17051: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
17052: # is permitted.
17053: #
1.305 raeburn 17054: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 17055:
1.305 raeburn 17056: my (@statuses,%email_rule);
1.228 raeburn 17057: foreach my $item ('login','sso','email') {
1.224 raeburn 17058: if ($item eq 'email') {
1.236 raeburn 17059: if ($env{'form.cancreate_email'}) {
1.305 raeburn 17060: if (@types) {
17061: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
17062: foreach my $status (@poss_statuses) {
17063: if (grep(/^\Q$status\E$/,(@types,'default'))) {
17064: push(@statuses,$status);
17065: }
17066: }
17067: $save_inststatus{'inststatusguest'} = \@statuses;
17068: } else {
17069: push(@statuses,'default');
17070: }
17071: if (@statuses) {
17072: my %curr_rule;
17073: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
17074: foreach my $type (@statuses) {
17075: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 17076: }
1.305 raeburn 17077: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
17078: foreach my $type (@statuses) {
17079: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
17080: }
17081: }
17082: push(@{$cancreate{'selfcreate'}},'email');
17083: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
17084: my %curremaildom;
17085: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
17086: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
17087: }
17088: foreach my $type (@statuses) {
17089: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
17090: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
17091: }
17092: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
17093: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
17094: }
17095: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
17096: #
17097: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
17098: #
17099: my $chosen = $1;
17100: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
17101: my $emaildom;
17102: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
17103: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
17104: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
17105: if (ref($curremaildom{$type}) eq 'HASH') {
17106: if (exists($curremaildom{$type}{$chosen})) {
17107: if ($curremaildom{$type}{$chosen} ne $emaildom) {
17108: push(@{$changes{'cancreate'}},'emaildomain');
17109: }
17110: } elsif ($emaildom ne '') {
17111: push(@{$changes{'cancreate'}},'emaildomain');
17112: }
17113: } elsif ($emaildom ne '') {
17114: push(@{$changes{'cancreate'}},'emaildomain');
17115: }
17116: }
17117: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
17118: } elsif ($chosen eq 'custom') {
17119: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
17120: $email_rule{$type} = [];
17121: if (ref($emailrules) eq 'HASH') {
17122: foreach my $rule (@possemail_rules) {
17123: if (exists($emailrules->{$rule})) {
17124: push(@{$email_rule{$type}},$rule);
17125: }
17126: }
17127: }
17128: if (@{$email_rule{$type}}) {
17129: $cancreate{'emailoptions'}{$type} = 'custom';
17130: if (ref($curr_rule{$type}) eq 'ARRAY') {
17131: if (@{$curr_rule{$type}} > 0) {
17132: foreach my $rule (@{$curr_rule{$type}}) {
17133: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
17134: push(@{$changes{'email_rule'}},$type);
17135: }
17136: }
17137: }
17138: foreach my $type (@{$email_rule{$type}}) {
17139: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
17140: push(@{$changes{'email_rule'}},$type);
17141: }
17142: }
17143: } else {
17144: push(@{$changes{'email_rule'}},$type);
17145: }
17146: }
17147: } else {
17148: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
17149: }
17150: }
17151: }
17152: if (@types) {
17153: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
17154: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
17155: if (@changed) {
17156: push(@{$changes{'inststatus'}},'inststatusguest');
17157: }
17158: } else {
17159: push(@{$changes{'inststatus'}},'inststatusguest');
17160: }
17161: }
17162: } else {
17163: delete($env{'form.cancreate_email'});
17164: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
17165: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
17166: push(@{$changes{'inststatus'}},'inststatusguest');
17167: }
17168: }
17169: }
17170: } else {
17171: $save_inststatus{'inststatusguest'} = [];
17172: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
17173: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
17174: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 17175: }
17176: }
1.224 raeburn 17177: }
17178: } else {
17179: if ($env{'form.cancreate_'.$item}) {
17180: push(@{$cancreate{'selfcreate'}},$item);
17181: }
17182: }
17183: }
1.305 raeburn 17184: my (%userinfo,%savecaptcha);
1.224 raeburn 17185: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
17186: #
1.228 raeburn 17187: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
17188: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 17189: #
1.236 raeburn 17190:
1.244 raeburn 17191: if ($env{'form.cancreate_email'}) {
1.228 raeburn 17192: push(@contexts,'emailusername');
1.305 raeburn 17193: if (@statuses) {
17194: foreach my $type (@statuses) {
1.228 raeburn 17195: if (ref($infofields) eq 'ARRAY') {
17196: foreach my $field (@{$infofields}) {
17197: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
17198: $cancreate{'emailusername'}{$type}{$field} = $1;
17199: }
17200: }
1.224 raeburn 17201: }
17202: }
17203: }
17204: #
17205: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 17206: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 17207: #
17208:
17209: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
17210: @approvalnotify = sort(@approvalnotify);
17211: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
17212: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
17213: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
17214: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
17215: push(@{$changes{'cancreate'}},'notify');
17216: }
17217: } else {
17218: if ($cancreate{'notify'}{'approval'}) {
17219: push(@{$changes{'cancreate'}},'notify');
17220: }
17221: }
17222: } elsif ($cancreate{'notify'}{'approval'}) {
17223: push(@{$changes{'cancreate'}},'notify');
17224: }
17225:
17226: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
17227: }
17228: #
1.236 raeburn 17229: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 17230: # institutional log-in.
17231: #
17232: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
17233: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
17234: ($domdefaults{'auth_def'} eq 'localauth'))) {
17235: $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.').' '.
17236: &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.');
17237: }
17238: }
17239: my @fields = ('lastname','firstname','middlename','generation',
17240: 'permanentemail','id');
1.240 raeburn 17241: my @shibfields = (@fields,'inststatus');
1.224 raeburn 17242: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
17243: #
17244: # Where usernames may created for institutional log-in and/or institutional single sign on:
17245: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
17246: # may self-create accounts
17247: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
17248: # which the user may supply, if institutional data is unavailable.
17249: #
17250: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 17251: if (@types) {
1.305 raeburn 17252: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
17253: push(@contexts,'statustocreate');
1.303 raeburn 17254: foreach my $type (@types) {
1.224 raeburn 17255: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
17256: foreach my $field (@fields) {
17257: if (grep(/^\Q$field\E$/,@modifiable)) {
17258: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
17259: } else {
17260: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
17261: }
17262: }
17263: }
17264: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 17265: foreach my $type (@types) {
1.224 raeburn 17266: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
17267: foreach my $field (@fields) {
17268: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
17269: $curr_usermodify{'selfcreate'}{$type}{$field}) {
17270: push(@{$changes{'selfcreate'}},$type);
17271: last;
17272: }
17273: }
17274: }
17275: }
17276: } else {
1.303 raeburn 17277: foreach my $type (@types) {
1.224 raeburn 17278: push(@{$changes{'selfcreate'}},$type);
17279: }
17280: }
17281: }
1.240 raeburn 17282: foreach my $field (@shibfields) {
17283: if ($env{'form.shibenv_'.$field} ne '') {
17284: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
17285: }
17286: }
17287: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
17288: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
17289: foreach my $field (@shibfields) {
17290: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
17291: push(@{$changes{'cancreate'}},'shibenv');
17292: }
17293: }
17294: } else {
17295: foreach my $field (@shibfields) {
17296: if ($env{'form.shibenv_'.$field}) {
17297: push(@{$changes{'cancreate'}},'shibenv');
17298: last;
17299: }
17300: }
17301: }
17302: }
1.224 raeburn 17303: }
17304: foreach my $item (@contexts) {
17305: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
17306: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
17307: if (ref($cancreate{$item}) eq 'ARRAY') {
17308: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
17309: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17310: push(@{$changes{'cancreate'}},$item);
17311: }
17312: }
17313: }
17314: }
17315: if (ref($cancreate{$item}) eq 'ARRAY') {
17316: foreach my $type (@{$cancreate{$item}}) {
17317: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
17318: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17319: push(@{$changes{'cancreate'}},$item);
17320: }
17321: }
17322: }
17323: }
17324: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
17325: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 17326: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
17327: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
17328: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
17329: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 17330: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17331: push(@{$changes{'cancreate'}},$item);
17332: }
17333: }
17334: }
1.305 raeburn 17335: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17336: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 17337: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17338: push(@{$changes{'cancreate'}},$item);
17339: }
1.224 raeburn 17340: }
17341: }
17342: }
1.305 raeburn 17343: foreach my $type (keys(%{$cancreate{$item}})) {
17344: if (ref($cancreate{$item}{$type}) eq 'HASH') {
17345: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
17346: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
17347: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 17348: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17349: push(@{$changes{'cancreate'}},$item);
17350: }
17351: }
17352: } else {
17353: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17354: push(@{$changes{'cancreate'}},$item);
17355: }
17356: }
17357: }
1.305 raeburn 17358: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17359: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 17360: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17361: push(@{$changes{'cancreate'}},$item);
17362: }
1.224 raeburn 17363: }
17364: }
17365: }
17366: }
17367: } elsif ($curr_usercreation{'cancreate'}{$item}) {
17368: if (ref($cancreate{$item}) eq 'ARRAY') {
17369: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
17370: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17371: push(@{$changes{'cancreate'}},$item);
17372: }
17373: }
1.305 raeburn 17374: }
17375: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17376: if (ref($cancreate{$item}) eq 'HASH') {
17377: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17378: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 17379: }
17380: }
17381: } elsif ($item eq 'emailusername') {
1.228 raeburn 17382: if (ref($cancreate{$item}) eq 'HASH') {
17383: foreach my $type (keys(%{$cancreate{$item}})) {
17384: if (ref($cancreate{$item}{$type}) eq 'HASH') {
17385: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
17386: if ($cancreate{$item}{$type}{$field}) {
17387: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17388: push(@{$changes{'cancreate'}},$item);
17389: }
17390: last;
17391: }
17392: }
17393: }
17394: }
1.224 raeburn 17395: }
17396: }
17397: }
17398: #
17399: # Populate %save_usercreate hash with updates to self-creation configuration.
17400: #
17401: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
17402: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 17403: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 17404: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
17405: if (ref($cancreate{'notify'}) eq 'HASH') {
17406: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
17407: }
1.236 raeburn 17408: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
17409: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
17410: }
1.303 raeburn 17411: if (ref($cancreate{'emailverified'}) eq 'HASH') {
17412: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
17413: }
1.305 raeburn 17414: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
17415: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
17416: }
1.303 raeburn 17417: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
17418: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
17419: }
1.224 raeburn 17420: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
17421: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
17422: }
1.240 raeburn 17423: if (ref($cancreate{'shibenv'}) eq 'HASH') {
17424: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
17425: }
1.224 raeburn 17426: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 17427: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 17428:
17429: my %userconfig_hash = (
17430: usercreation => \%save_usercreate,
17431: usermodification => \%save_usermodify,
1.305 raeburn 17432: inststatus => \%save_inststatus,
1.224 raeburn 17433: );
1.305 raeburn 17434:
1.224 raeburn 17435: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
17436: $dom);
17437: #
1.305 raeburn 17438: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 17439: #
1.27 raeburn 17440: if ($putresult eq 'ok') {
17441: if (keys(%changes) > 0) {
17442: $resulttext = &mt('Changes made:').'<ul>';
17443: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 17444: my %lt = &selfcreation_types();
1.34 raeburn 17445: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 17446: my $chgtext = '';
1.45 raeburn 17447: if ($type eq 'selfcreate') {
1.50 raeburn 17448: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 17449: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 17450: } else {
1.224 raeburn 17451: $chgtext .= &mt('Self-creation of a new account is permitted for:').
17452: '<ul>';
1.50 raeburn 17453: foreach my $case (@{$cancreate{$type}}) {
17454: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
17455: }
17456: $chgtext .= '</ul>';
1.100 raeburn 17457: if (ref($cancreate{$type}) eq 'ARRAY') {
17458: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
17459: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
17460: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 17461: $chgtext .= '<span class="LC_warning">'.
17462: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
17463: '</span><br />';
17464: }
17465: }
17466: }
17467: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 17468: if (!@statuses) {
17469: $chgtext .= '<span class="LC_warning">'.
17470: &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.").
17471: '</span><br />';
1.303 raeburn 17472:
1.100 raeburn 17473: }
17474: }
17475: }
1.43 raeburn 17476: }
1.240 raeburn 17477: } elsif ($type eq 'shibenv') {
17478: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 17479: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 17480: } else {
17481: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
17482: '<ul>';
17483: foreach my $field (@shibfields) {
17484: next if ($cancreate{$type}{$field} eq '');
17485: if ($field eq 'inststatus') {
17486: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
17487: } else {
17488: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
17489: }
17490: }
17491: $chgtext .= '</ul>';
1.303 raeburn 17492: }
1.93 raeburn 17493: } elsif ($type eq 'statustocreate') {
1.96 raeburn 17494: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
17495: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
17496: if (@{$cancreate{'selfcreate'}} > 0) {
17497: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 17498: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 17499: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 17500: $chgtext .= '<br />'.
17501: '<span class="LC_warning">'.
17502: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
17503: '</span>';
17504: }
1.303 raeburn 17505: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 17506: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 17507: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
17508: } else {
17509: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
17510: }
17511: $chgtext .= '<ul>';
17512: foreach my $case (@{$cancreate{$type}}) {
17513: if ($case eq 'default') {
17514: $chgtext .= '<li>'.$othertitle.'</li>';
17515: } else {
1.303 raeburn 17516: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 17517: }
17518: }
1.100 raeburn 17519: $chgtext .= '</ul>';
17520: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 17521: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 17522: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
17523: '</span>';
1.100 raeburn 17524: }
17525: }
17526: } else {
17527: if (@{$cancreate{$type}} == 0) {
17528: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
17529: } else {
17530: $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 17531: }
17532: }
1.303 raeburn 17533: $chgtext .= '<br />';
1.93 raeburn 17534: }
1.236 raeburn 17535: } elsif ($type eq 'selfcreateprocessing') {
17536: my %choices = &Apache::lonlocal::texthash (
17537: automatic => 'Automatic approval',
17538: approval => 'Queued for approval',
17539: );
1.305 raeburn 17540: if (@types) {
17541: if (@statuses) {
1.303 raeburn 17542: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 17543: '<ul>';
1.305 raeburn 17544: foreach my $status (@statuses) {
17545: if ($status eq 'default') {
17546: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 17547: } else {
1.305 raeburn 17548: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 17549: }
17550: }
17551: $chgtext .= '</ul>';
17552: }
17553: } else {
17554: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
17555: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
17556: }
17557: } elsif ($type eq 'emailverified') {
17558: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 17559: all => 'Same as e-mail',
17560: first => 'Omit @domain',
17561: free => 'Free to choose',
1.303 raeburn 17562: );
1.305 raeburn 17563: if (@types) {
17564: if (@statuses) {
1.303 raeburn 17565: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
17566: '<ul>';
1.305 raeburn 17567: foreach my $status (@statuses) {
1.362 raeburn 17568: if ($status eq 'default') {
1.305 raeburn 17569: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 17570: } else {
1.305 raeburn 17571: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 17572: }
17573: }
17574: $chgtext .= '</ul>';
17575: }
17576: } else {
1.305 raeburn 17577: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 17578: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 17579: }
1.305 raeburn 17580: } elsif ($type eq 'emailoptions') {
17581: my %options = &Apache::lonlocal::texthash (
17582: any => 'Any e-mail',
17583: inst => 'Institutional only',
17584: noninst => 'Non-institutional only',
17585: custom => 'Custom restrictions',
17586: );
17587: if (@types) {
17588: if (@statuses) {
17589: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
17590: '<ul>';
17591: foreach my $status (@statuses) {
17592: if ($type eq 'default') {
17593: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
17594: } else {
17595: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 17596: }
17597: }
1.305 raeburn 17598: $chgtext .= '</ul>';
17599: }
17600: } else {
17601: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
17602: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
17603: } else {
17604: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
17605: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 17606: }
1.305 raeburn 17607: }
17608: } elsif ($type eq 'emaildomain') {
17609: my $output;
17610: if (@statuses) {
17611: foreach my $type (@statuses) {
17612: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
17613: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
17614: if ($type eq 'default') {
17615: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17616: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
17617: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
17618: } else {
17619: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
17620: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
17621: }
1.303 raeburn 17622: } else {
1.305 raeburn 17623: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17624: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
17625: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
17626: } else {
17627: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
17628: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
17629: }
1.303 raeburn 17630: }
1.305 raeburn 17631: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
17632: if ($type eq 'default') {
17633: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17634: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
17635: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
17636: } else {
17637: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
17638: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
17639: }
1.303 raeburn 17640: } else {
1.305 raeburn 17641: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17642: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
17643: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
17644: } else {
17645: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
17646: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
17647: }
1.303 raeburn 17648: }
17649: }
17650: }
17651: }
1.305 raeburn 17652: }
17653: if ($output ne '') {
17654: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
17655: '<ul>'.$output.'</ul>';
1.236 raeburn 17656: }
1.165 raeburn 17657: } elsif ($type eq 'captcha') {
1.224 raeburn 17658: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 17659: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
17660: } else {
17661: my %captchas = &captcha_phrases();
1.224 raeburn 17662: if ($captchas{$savecaptcha{$type}}) {
17663: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 17664: } else {
1.210 raeburn 17665: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 17666: }
17667: }
17668: } elsif ($type eq 'recaptchakeys') {
17669: my ($privkey,$pubkey);
1.224 raeburn 17670: if (ref($savecaptcha{$type}) eq 'HASH') {
17671: $pubkey = $savecaptcha{$type}{'public'};
17672: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 17673: }
17674: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
17675: if (!$pubkey) {
17676: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
17677: } else {
17678: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
17679: }
17680: if (!$privkey) {
17681: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
17682: } else {
17683: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
17684: }
17685: $chgtext .= '</ul>';
1.269 raeburn 17686: } elsif ($type eq 'recaptchaversion') {
17687: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 17688: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 17689: }
1.224 raeburn 17690: } elsif ($type eq 'emailusername') {
17691: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 17692: if (@statuses) {
17693: foreach my $type (@statuses) {
1.228 raeburn 17694: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
17695: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 17696: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 17697: '<ul>';
17698: foreach my $field (@{$infofields}) {
17699: if ($cancreate{'emailusername'}{$type}{$field}) {
17700: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
17701: }
17702: }
1.245 raeburn 17703: $chgtext .= '</ul>';
17704: } else {
1.303 raeburn 17705: $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 17706: }
17707: } else {
1.303 raeburn 17708: $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 17709: }
17710: }
17711: }
17712: }
17713: } elsif ($type eq 'notify') {
1.303 raeburn 17714: my $numapprove = 0;
1.224 raeburn 17715: if (ref($changes{'cancreate'}) eq 'ARRAY') {
17716: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
17717: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 17718: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
17719: $numapprove ++;
1.224 raeburn 17720: }
17721: }
1.43 raeburn 17722: }
1.303 raeburn 17723: unless ($numapprove) {
17724: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
17725: }
1.34 raeburn 17726: }
1.224 raeburn 17727: if ($chgtext) {
17728: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 17729: }
17730: }
17731: }
1.305 raeburn 17732: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 17733: my ($emailrules,$emailruleorder) =
17734: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 17735: foreach my $type (@{$changes{'email_rule'}}) {
17736: if (ref($email_rule{$type}) eq 'ARRAY') {
17737: my $chgtext = '<ul>';
17738: foreach my $rule (@{$email_rule{$type}}) {
17739: if (ref($emailrules->{$rule}) eq 'HASH') {
17740: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
17741: }
17742: }
17743: $chgtext .= '</ul>';
1.310 raeburn 17744: my $typename;
1.305 raeburn 17745: if (@types) {
17746: if ($type eq 'default') {
17747: $typename = $othertitle;
17748: } else {
17749: $typename = $usertypes{$type};
17750: }
17751: $chgtext .= &mt('(Affiliation: [_1])',$typename);
17752: }
17753: if (@{$email_rule{$type}} > 0) {
17754: $resulttext .= '<li>'.
17755: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
17756: $usertypes{$type}).
17757: $chgtext.
17758: '</li>';
17759: } else {
17760: $resulttext .= '<li>'.
1.310 raeburn 17761: &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 17762: '</li>'.
1.310 raeburn 17763: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 17764: }
1.43 raeburn 17765: }
17766: }
1.305 raeburn 17767: }
17768: if (ref($changes{'inststatus'}) eq 'ARRAY') {
17769: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
17770: if (@{$save_inststatus{'inststatusguest'}} > 0) {
17771: my $chgtext = '<ul>';
17772: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
17773: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
17774: }
17775: $chgtext .= '</ul>';
17776: $resulttext .= '<li>'.
17777: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
17778: $chgtext.
17779: '</li>';
17780: } else {
17781: $resulttext .= '<li>'.
17782: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
17783: '</li>';
17784: }
1.43 raeburn 17785: }
17786: }
1.224 raeburn 17787: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
17788: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
17789: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
17790: foreach my $type (@{$changes{'selfcreate'}}) {
17791: my $typename = $type;
1.303 raeburn 17792: if (keys(%usertypes) > 0) {
17793: if ($usertypes{$type} ne '') {
17794: $typename = $usertypes{$type};
1.224 raeburn 17795: }
17796: }
17797: my @modifiable;
17798: $resulttext .= '<li>'.
17799: &mt('Self-creation of account by users with status: [_1]',
17800: '<span class="LC_cusr_emph">'.$typename.'</span>').
17801: ' - '.&mt('modifiable fields (if institutional data blank): ');
17802: foreach my $field (@fields) {
17803: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
17804: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 17805: }
17806: }
1.224 raeburn 17807: if (@modifiable > 0) {
17808: $resulttext .= join(', ',@modifiable);
1.43 raeburn 17809: } else {
1.224 raeburn 17810: $resulttext .= &mt('none');
1.43 raeburn 17811: }
1.224 raeburn 17812: $resulttext .= '</li>';
1.28 raeburn 17813: }
1.224 raeburn 17814: $resulttext .= '</ul></li>';
1.28 raeburn 17815: }
1.27 raeburn 17816: $resulttext .= '</ul>';
1.305 raeburn 17817: my $cachetime = 24*60*60;
17818: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
17819: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17820: if (ref($lastactref) eq 'HASH') {
17821: $lastactref->{'domdefaults'} = 1;
17822: }
1.27 raeburn 17823: } else {
1.224 raeburn 17824: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 17825: }
17826: } else {
17827: $resulttext = '<span class="LC_error">'.
1.23 raeburn 17828: &mt('An error occurred: [_1]',$putresult).'</span>';
17829: }
1.43 raeburn 17830: if ($warningmsg ne '') {
17831: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
17832: }
1.23 raeburn 17833: return $resulttext;
17834: }
17835:
1.165 raeburn 17836: sub process_captcha {
1.369 raeburn 17837: my ($container,$changes,$newsettings,$currsettings) = @_;
17838: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 17839: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
17840: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
17841: $newsettings->{'captcha'} = 'original';
17842: }
1.369 raeburn 17843: my %current;
17844: if (ref($currsettings) eq 'HASH') {
17845: %current = %{$currsettings};
17846: }
17847: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 17848: if ($container eq 'cancreate') {
1.169 raeburn 17849: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
17850: push(@{$changes->{'cancreate'}},'captcha');
17851: } elsif (!defined($changes->{'cancreate'})) {
17852: $changes->{'cancreate'} = ['captcha'];
17853: }
1.368 raeburn 17854: } elsif ($container eq 'passwords') {
17855: $changes->{'reset'} = 1;
1.169 raeburn 17856: } else {
17857: $changes->{'captcha'} = 1;
1.165 raeburn 17858: }
17859: }
1.269 raeburn 17860: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 17861: if ($newsettings->{'captcha'} eq 'recaptcha') {
17862: $newpub = $env{'form.'.$container.'_recaptchapub'};
17863: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 17864: $newpub =~ s/[^\w\-]//g;
17865: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 17866: $newsettings->{'recaptchakeys'} = {
17867: public => $newpub,
17868: private => $newpriv,
17869: };
1.269 raeburn 17870: $newversion = $env{'form.'.$container.'_recaptchaversion'};
17871: $newversion =~ s/\D//g;
17872: if ($newversion ne '2') {
17873: $newversion = 1;
17874: }
17875: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 17876: }
1.369 raeburn 17877: if (ref($current{'recaptchakeys'}) eq 'HASH') {
17878: $currpub = $current{'recaptchakeys'}{'public'};
17879: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 17880: unless ($newsettings->{'captcha'} eq 'recaptcha') {
17881: $newsettings->{'recaptchakeys'} = {
17882: public => '',
17883: private => '',
17884: }
17885: }
1.165 raeburn 17886: }
1.369 raeburn 17887: if ($current{'captcha'} eq 'recaptcha') {
17888: $currversion = $current{'recaptchaversion'};
1.269 raeburn 17889: if ($currversion ne '2') {
17890: $currversion = 1;
17891: }
17892: }
17893: if ($currversion ne $newversion) {
17894: if ($container eq 'cancreate') {
17895: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
17896: push(@{$changes->{'cancreate'}},'recaptchaversion');
17897: } elsif (!defined($changes->{'cancreate'})) {
17898: $changes->{'cancreate'} = ['recaptchaversion'];
17899: }
1.368 raeburn 17900: } elsif ($container eq 'passwords') {
17901: $changes->{'reset'} = 1;
1.269 raeburn 17902: } else {
17903: $changes->{'recaptchaversion'} = 1;
17904: }
17905: }
1.165 raeburn 17906: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 17907: if ($container eq 'cancreate') {
17908: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
17909: push(@{$changes->{'cancreate'}},'recaptchakeys');
17910: } elsif (!defined($changes->{'cancreate'})) {
17911: $changes->{'cancreate'} = ['recaptchakeys'];
17912: }
1.368 raeburn 17913: } elsif ($container eq 'passwords') {
17914: $changes->{'reset'} = 1;
1.169 raeburn 17915: } else {
1.210 raeburn 17916: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 17917: }
17918: }
17919: return;
17920: }
17921:
1.33 raeburn 17922: sub modify_usermodification {
17923: my ($dom,%domconfig) = @_;
1.224 raeburn 17924: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 17925: if (ref($domconfig{'usermodification'}) eq 'HASH') {
17926: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 17927: if ($key eq 'selfcreate') {
17928: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
17929: } else {
17930: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
17931: }
1.33 raeburn 17932: }
17933: }
1.224 raeburn 17934: my @contexts = ('author','course');
1.33 raeburn 17935: my %context_title = (
17936: author => 'In author context',
17937: course => 'In course context',
17938: );
17939: my @fields = ('lastname','firstname','middlename','generation',
17940: 'permanentemail','id');
17941: my %roles = (
17942: author => ['ca','aa'],
17943: course => ['st','ep','ta','in','cr'],
17944: );
17945: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
17946: foreach my $context (@contexts) {
17947: foreach my $role (@{$roles{$context}}) {
17948: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
17949: foreach my $item (@fields) {
17950: if (grep(/^\Q$item\E$/,@modifiable)) {
17951: $modifyhash{$context}{$role}{$item} = 1;
17952: } else {
17953: $modifyhash{$context}{$role}{$item} = 0;
17954: }
17955: }
17956: }
17957: if (ref($curr_usermodification{$context}) eq 'HASH') {
17958: foreach my $role (@{$roles{$context}}) {
17959: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
17960: foreach my $field (@fields) {
17961: if ($modifyhash{$context}{$role}{$field} ne
17962: $curr_usermodification{$context}{$role}{$field}) {
17963: push(@{$changes{$context}},$role);
17964: last;
17965: }
17966: }
17967: }
17968: }
17969: } else {
17970: foreach my $context (@contexts) {
17971: foreach my $role (@{$roles{$context}}) {
17972: push(@{$changes{$context}},$role);
17973: }
17974: }
17975: }
17976: }
17977: my %usermodification_hash = (
17978: usermodification => \%modifyhash,
17979: );
17980: my $putresult = &Apache::lonnet::put_dom('configuration',
17981: \%usermodification_hash,$dom);
17982: if ($putresult eq 'ok') {
17983: if (keys(%changes) > 0) {
17984: $resulttext = &mt('Changes made: ').'<ul>';
17985: foreach my $context (@contexts) {
17986: if (ref($changes{$context}) eq 'ARRAY') {
17987: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
17988: if (ref($changes{$context}) eq 'ARRAY') {
17989: foreach my $role (@{$changes{$context}}) {
17990: my $rolename;
1.224 raeburn 17991: if ($role eq 'cr') {
17992: $rolename = &mt('Custom');
1.33 raeburn 17993: } else {
1.224 raeburn 17994: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 17995: }
17996: my @modifiable;
1.224 raeburn 17997: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 17998: foreach my $field (@fields) {
17999: if ($modifyhash{$context}{$role}{$field}) {
18000: push(@modifiable,$fieldtitles{$field});
18001: }
18002: }
18003: if (@modifiable > 0) {
18004: $resulttext .= join(', ',@modifiable);
18005: } else {
18006: $resulttext .= &mt('none');
18007: }
18008: $resulttext .= '</li>';
18009: }
18010: $resulttext .= '</ul></li>';
18011: }
18012: }
18013: }
18014: $resulttext .= '</ul>';
18015: } else {
18016: $resulttext = &mt('No changes made to user modification settings');
18017: }
18018: } else {
18019: $resulttext = '<span class="LC_error">'.
18020: &mt('An error occurred: [_1]',$putresult).'</span>';
18021: }
18022: return $resulttext;
18023: }
18024:
1.43 raeburn 18025: sub modify_defaults {
1.212 raeburn 18026: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 18027: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 18028: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 18029: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 18030: 'portal_def');
1.325 raeburn 18031: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 18032: foreach my $item (@items) {
18033: $newvalues{$item} = $env{'form.'.$item};
18034: if ($item eq 'auth_def') {
18035: if ($newvalues{$item} ne '') {
18036: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
18037: push(@errors,$item);
18038: }
18039: }
18040: } elsif ($item eq 'lang_def') {
18041: if ($newvalues{$item} ne '') {
18042: if ($newvalues{$item} =~ /^(\w+)/) {
18043: my $langcode = $1;
1.103 raeburn 18044: if ($langcode ne 'x_chef') {
18045: if (code2language($langcode) eq '') {
18046: push(@errors,$item);
18047: }
1.43 raeburn 18048: }
18049: } else {
18050: push(@errors,$item);
18051: }
18052: }
1.54 raeburn 18053: } elsif ($item eq 'timezone_def') {
18054: if ($newvalues{$item} ne '') {
1.62 raeburn 18055: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 18056: push(@errors,$item);
18057: }
18058: }
1.68 raeburn 18059: } elsif ($item eq 'datelocale_def') {
18060: if ($newvalues{$item} ne '') {
18061: my @datelocale_ids = DateTime::Locale->ids();
18062: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
18063: push(@errors,$item);
18064: }
18065: }
1.141 raeburn 18066: } elsif ($item eq 'portal_def') {
18067: if ($newvalues{$item} ne '') {
18068: 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])\/?$/) {
18069: push(@errors,$item);
18070: }
18071: }
1.43 raeburn 18072: }
18073: if (grep(/^\Q$item\E$/,@errors)) {
18074: $newvalues{$item} = $domdefaults{$item};
18075: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
18076: $changes{$item} = 1;
18077: }
1.72 raeburn 18078: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 18079: }
1.354 raeburn 18080: my %staticdefaults = (
18081: 'intauth_cost' => 10,
18082: 'intauth_check' => 0,
18083: 'intauth_switch' => 0,
18084: );
18085: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
18086: if (exists($domdefaults{$item})) {
18087: $newvalues{$item} = $domdefaults{$item};
18088: } else {
18089: $newvalues{$item} = $staticdefaults{$item};
18090: }
18091: }
1.43 raeburn 18092: my %defaults_hash = (
1.72 raeburn 18093: defaults => \%newvalues,
18094: );
1.43 raeburn 18095: my $title = &defaults_titles();
1.236 raeburn 18096:
18097: my $currinststatus;
18098: if (ref($domconfig{'inststatus'}) eq 'HASH') {
18099: $currinststatus = $domconfig{'inststatus'};
18100: } else {
18101: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
18102: $currinststatus = {
18103: inststatustypes => $usertypes,
18104: inststatusorder => $types,
18105: inststatusguest => [],
18106: };
18107: }
18108: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
18109: my @allpos;
18110: my %alltypes;
1.305 raeburn 18111: my @inststatusguest;
18112: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
18113: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
18114: unless (grep(/^\Q$type\E$/,@todelete)) {
18115: push(@inststatusguest,$type);
18116: }
18117: }
18118: }
18119: my ($currtitles,$currorder);
1.236 raeburn 18120: if (ref($currinststatus) eq 'HASH') {
18121: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
18122: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
18123: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
18124: if ($currinststatus->{inststatustypes}->{$type} ne '') {
18125: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
18126: }
18127: }
18128: unless (grep(/^\Q$type\E$/,@todelete)) {
18129: my $position = $env{'form.inststatus_pos_'.$type};
18130: $position =~ s/\D+//g;
18131: $allpos[$position] = $type;
18132: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
18133: $alltypes{$type} =~ s/`//g;
18134: }
18135: }
18136: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
18137: $currtitles =~ s/,$//;
18138: }
18139: }
18140: if ($env{'form.addinststatus'}) {
18141: my $newtype = $env{'form.addinststatus'};
18142: $newtype =~ s/\W//g;
18143: unless (exists($alltypes{$newtype})) {
18144: $alltypes{$newtype} = $env{'form.addinststatus_title'};
18145: $alltypes{$newtype} =~ s/`//g;
18146: my $position = $env{'form.addinststatus_pos'};
18147: $position =~ s/\D+//g;
18148: if ($position ne '') {
18149: $allpos[$position] = $newtype;
18150: }
18151: }
18152: }
1.305 raeburn 18153: my @orderedstatus;
1.236 raeburn 18154: foreach my $type (@allpos) {
18155: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
18156: push(@orderedstatus,$type);
18157: }
18158: }
18159: foreach my $type (keys(%alltypes)) {
18160: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
18161: delete($alltypes{$type});
18162: }
18163: }
18164: $defaults_hash{'inststatus'} = {
18165: inststatustypes => \%alltypes,
18166: inststatusorder => \@orderedstatus,
1.305 raeburn 18167: inststatusguest => \@inststatusguest,
1.236 raeburn 18168: };
18169: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
18170: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
18171: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
18172: }
18173: }
18174: if ($currorder ne join(',',@orderedstatus)) {
18175: $changes{'inststatus'}{'inststatusorder'} = 1;
18176: }
18177: my $newtitles;
18178: foreach my $item (@orderedstatus) {
18179: $newtitles .= $alltypes{$item}.',';
18180: }
18181: $newtitles =~ s/,$//;
18182: if ($currtitles ne $newtitles) {
18183: $changes{'inststatus'}{'inststatustypes'} = 1;
18184: }
1.43 raeburn 18185: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
18186: $dom);
18187: if ($putresult eq 'ok') {
18188: if (keys(%changes) > 0) {
18189: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 18190: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 18191: 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";
18192: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 18193: if ($item eq 'inststatus') {
18194: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 18195: if (@orderedstatus) {
1.236 raeburn 18196: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
18197: foreach my $type (@orderedstatus) {
18198: $resulttext .= $alltypes{$type}.', ';
18199: }
18200: $resulttext =~ s/, $//;
18201: $resulttext .= '</li>';
1.305 raeburn 18202: } else {
18203: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 18204: }
18205: }
18206: } else {
18207: my $value = $env{'form.'.$item};
18208: if ($value eq '') {
18209: $value = &mt('none');
18210: } elsif ($item eq 'auth_def') {
18211: my %authnames = &authtype_names();
18212: my %shortauth = (
18213: internal => 'int',
18214: krb4 => 'krb4',
18215: krb5 => 'krb5',
18216: localauth => 'loc',
1.325 raeburn 18217: lti => 'lti',
1.236 raeburn 18218: );
18219: $value = $authnames{$shortauth{$value}};
18220: }
18221: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
18222: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 18223: }
18224: }
18225: $resulttext .= '</ul>';
18226: $mailmsgtext .= "\n";
18227: my $cachetime = 24*60*60;
1.72 raeburn 18228: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 18229: if (ref($lastactref) eq 'HASH') {
18230: $lastactref->{'domdefaults'} = 1;
18231: }
1.68 raeburn 18232: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 18233: my $notify = 1;
18234: if (ref($domconfig{'contacts'}) eq 'HASH') {
18235: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
18236: $notify = 0;
18237: }
18238: }
18239: if ($notify) {
18240: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
18241: "LON-CAPA Domain Settings Change - $dom",
18242: $mailmsgtext);
18243: }
1.54 raeburn 18244: }
1.43 raeburn 18245: } else {
1.54 raeburn 18246: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 18247: }
18248: } else {
18249: $resulttext = '<span class="LC_error">'.
18250: &mt('An error occurred: [_1]',$putresult).'</span>';
18251: }
18252: if (@errors > 0) {
18253: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
18254: foreach my $item (@errors) {
18255: $resulttext .= ' "'.$title->{$item}.'",';
18256: }
18257: $resulttext =~ s/,$//;
18258: }
18259: return $resulttext;
18260: }
18261:
1.46 raeburn 18262: sub modify_scantron {
1.205 raeburn 18263: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 18264: my ($resulttext,%confhash,%changes,$errors);
18265: my $custom = 'custom.tab';
18266: my $default = 'default.tab';
18267: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 18268: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 18269: &config_check($dom,$confname,$servadm);
18270: if ($env{'form.scantronformat.filename'} ne '') {
18271: my $error;
18272: if ($configuserok eq 'ok') {
18273: if ($switchserver) {
1.130 raeburn 18274: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 18275: } else {
18276: if ($author_ok eq 'ok') {
18277: my ($result,$scantronurl) =
18278: &publishlogo($r,'upload','scantronformat',$dom,
18279: $confname,'scantron','','',$custom);
18280: if ($result eq 'ok') {
18281: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 18282: $changes{'scantronformat'} = 1;
1.46 raeburn 18283: } else {
18284: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
18285: }
18286: } else {
18287: $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);
18288: }
18289: }
18290: } else {
18291: $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);
18292: }
18293: if ($error) {
18294: &Apache::lonnet::logthis($error);
18295: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18296: }
18297: }
1.48 raeburn 18298: if (ref($domconfig{'scantron'}) eq 'HASH') {
18299: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
18300: if ($env{'form.scantronformat_del'}) {
18301: $confhash{'scantron'}{'scantronformat'} = '';
18302: $changes{'scantronformat'} = 1;
1.347 raeburn 18303: } else {
18304: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 18305: }
18306: }
18307: }
1.347 raeburn 18308: my @options = ('hdr','pad','rem');
1.346 raeburn 18309: my @fields = &scantroncsv_fields();
18310: my %titles = &scantronconfig_titles();
1.347 raeburn 18311: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 18312: my ($newdat,$currdat,%newcol,%currcol);
18313: if (grep(/^dat$/,@formats)) {
18314: $confhash{'scantron'}{config}{dat} = 1;
18315: $newdat = 1;
18316: } else {
18317: $newdat = 0;
18318: }
18319: if (grep(/^csv$/,@formats)) {
18320: my %bynum;
18321: foreach my $field (@fields) {
18322: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
18323: my $posscol = $1;
18324: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 18325: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 18326: $bynum{$posscol} = $field;
18327: $newcol{$field} = $posscol;
18328: }
18329: }
18330: }
1.347 raeburn 18331: if (keys(%newcol)) {
18332: foreach my $option (@options) {
18333: if ($env{'form.scantroncsv_'.$option}) {
18334: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
18335: }
18336: }
18337: }
1.346 raeburn 18338: }
18339: $currdat = 1;
18340: if (ref($domconfig{'scantron'}) eq 'HASH') {
18341: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 18342: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 18343: $currdat = 0;
18344: }
18345: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 18346: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
18347: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
18348: }
1.346 raeburn 18349: }
18350: }
18351: }
18352: if ($currdat != $newdat) {
18353: $changes{'config'} = 1;
18354: } else {
18355: foreach my $field (@fields) {
18356: if ($currcol{$field} ne '') {
18357: if ($currcol{$field} ne $newcol{$field}) {
18358: $changes{'config'} = 1;
18359: last;
1.347 raeburn 18360: }
1.346 raeburn 18361: } elsif ($newcol{$field} ne '') {
18362: $changes{'config'} = 1;
18363: last;
18364: }
18365: }
18366: }
1.46 raeburn 18367: if (keys(%confhash) > 0) {
18368: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
18369: $dom);
18370: if ($putresult eq 'ok') {
18371: if (keys(%changes) > 0) {
1.48 raeburn 18372: if (ref($confhash{'scantron'}) eq 'HASH') {
18373: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 18374: if ($changes{'scantronformat'}) {
18375: if ($confhash{'scantron'}{'scantronformat'} eq '') {
18376: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
18377: } else {
18378: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
18379: }
18380: }
1.347 raeburn 18381: if ($changes{'config'}) {
1.346 raeburn 18382: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
18383: if ($confhash{'scantron'}{'config'}{'dat'}) {
18384: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
18385: }
18386: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 18387: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
18388: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
18389: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
18390: foreach my $field (@fields) {
18391: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
18392: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
18393: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
18394: }
18395: }
18396: $resulttext .= '</ul></li>';
18397: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
18398: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
18399: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
18400: foreach my $option (@options) {
18401: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
18402: $resulttext .= '<li>'.$titles{$option}.'</li>';
18403: }
18404: }
18405: $resulttext .= '</ul></li>';
18406: }
1.346 raeburn 18407: }
18408: }
18409: }
18410: }
18411: } else {
18412: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
18413: }
1.46 raeburn 18414: }
1.48 raeburn 18415: $resulttext .= '</ul>';
18416: } else {
1.130 raeburn 18417: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 18418: }
18419: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 18420: if (ref($lastactref) eq 'HASH') {
18421: $lastactref->{'domainconfig'} = 1;
18422: }
1.46 raeburn 18423: } else {
1.346 raeburn 18424: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 18425: }
18426: } else {
18427: $resulttext = '<span class="LC_error">'.
18428: &mt('An error occurred: [_1]',$putresult).'</span>';
18429: }
18430: } else {
1.130 raeburn 18431: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 18432: }
18433: if ($errors) {
1.353 raeburn 18434: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18435: $errors.'</ul></p>';
1.46 raeburn 18436: }
18437: return $resulttext;
18438: }
18439:
1.48 raeburn 18440: sub modify_coursecategories {
1.239 raeburn 18441: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 18442: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
18443: $cathash);
1.48 raeburn 18444: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 18445: my @catitems = ('unauth','auth');
18446: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 18447: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 18448: $cathash = $domconfig{'coursecategories'}{'cats'};
18449: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
18450: $changes{'togglecats'} = 1;
18451: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
18452: }
18453: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
18454: $changes{'categorize'} = 1;
18455: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
18456: }
1.120 raeburn 18457: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
18458: $changes{'togglecatscomm'} = 1;
18459: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
18460: }
18461: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
18462: $changes{'categorizecomm'} = 1;
18463: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 18464:
18465: }
18466: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
18467: $changes{'togglecatsplace'} = 1;
18468: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
18469: }
18470: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
18471: $changes{'categorizeplace'} = 1;
18472: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 18473: }
1.238 raeburn 18474: foreach my $item (@catitems) {
18475: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
18476: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
18477: $changes{$item} = 1;
18478: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
18479: }
18480: }
18481: }
1.57 raeburn 18482: } else {
18483: $changes{'togglecats'} = 1;
18484: $changes{'categorize'} = 1;
1.124 raeburn 18485: $changes{'togglecatscomm'} = 1;
18486: $changes{'categorizecomm'} = 1;
1.272 raeburn 18487: $changes{'togglecatsplace'} = 1;
18488: $changes{'categorizeplace'} = 1;
1.87 raeburn 18489: $domconfig{'coursecategories'} = {
18490: togglecats => $env{'form.togglecats'},
18491: categorize => $env{'form.categorize'},
1.124 raeburn 18492: togglecatscomm => $env{'form.togglecatscomm'},
18493: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 18494: togglecatsplace => $env{'form.togglecatsplace'},
18495: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 18496: };
1.238 raeburn 18497: foreach my $item (@catitems) {
18498: if ($env{'form.coursecat_'.$item} ne 'std') {
18499: $changes{$item} = 1;
18500: }
18501: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
18502: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
18503: }
18504: }
1.57 raeburn 18505: }
18506: if (ref($cathash) eq 'HASH') {
18507: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 18508: push (@deletecategory,'instcode::0');
18509: }
1.120 raeburn 18510: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
18511: push(@deletecategory,'communities::0');
18512: }
1.272 raeburn 18513: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
18514: push(@deletecategory,'placement::0');
18515: }
1.48 raeburn 18516: }
1.57 raeburn 18517: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
18518: if (ref($cathash) eq 'HASH') {
1.48 raeburn 18519: if (@deletecategory > 0) {
18520: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 18521: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 18522: foreach my $item (@deletecategory) {
1.57 raeburn 18523: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
18524: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 18525: $deletions{$item} = 1;
1.57 raeburn 18526: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 18527: }
18528: }
18529: }
1.57 raeburn 18530: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 18531: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 18532: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 18533: $reorderings{$item} = 1;
1.57 raeburn 18534: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 18535: }
18536: if ($env{'form.addcategory_name_'.$item} ne '') {
18537: my $newcat = $env{'form.addcategory_name_'.$item};
18538: my $newdepth = $depth+1;
18539: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 18540: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 18541: $adds{$newitem} = 1;
18542: }
18543: if ($env{'form.subcat_'.$item} ne '') {
18544: my $newcat = $env{'form.subcat_'.$item};
18545: my $newdepth = $depth+1;
18546: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 18547: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 18548: $adds{$newitem} = 1;
18549: }
18550: }
18551: }
18552: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 18553: if (ref($cathash) eq 'HASH') {
1.48 raeburn 18554: my $newitem = 'instcode::0';
1.57 raeburn 18555: if ($cathash->{$newitem} eq '') {
18556: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 18557: $adds{$newitem} = 1;
18558: }
18559: } else {
18560: my $newitem = 'instcode::0';
1.57 raeburn 18561: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 18562: $adds{$newitem} = 1;
18563: }
18564: }
1.120 raeburn 18565: if ($env{'form.communities'} eq '1') {
18566: if (ref($cathash) eq 'HASH') {
18567: my $newitem = 'communities::0';
18568: if ($cathash->{$newitem} eq '') {
18569: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
18570: $adds{$newitem} = 1;
18571: }
18572: } else {
18573: my $newitem = 'communities::0';
18574: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
18575: $adds{$newitem} = 1;
18576: }
18577: }
1.272 raeburn 18578: if ($env{'form.placement'} eq '1') {
18579: if (ref($cathash) eq 'HASH') {
18580: my $newitem = 'placement::0';
18581: if ($cathash->{$newitem} eq '') {
18582: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
18583: $adds{$newitem} = 1;
18584: }
18585: } else {
18586: my $newitem = 'placement::0';
18587: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
18588: $adds{$newitem} = 1;
18589: }
18590: }
1.48 raeburn 18591: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 18592: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 18593: ($env{'form.addcategory_name'} ne 'communities') &&
18594: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 18595: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
18596: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
18597: $adds{$newitem} = 1;
18598: }
1.48 raeburn 18599: }
1.57 raeburn 18600: my $putresult;
1.48 raeburn 18601: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
18602: if (keys(%deletions) > 0) {
18603: foreach my $key (keys(%deletions)) {
18604: if ($predelallitems{$key} ne '') {
18605: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
18606: }
18607: }
18608: }
18609: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 18610: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 18611: if (ref($chkcats[0]) eq 'ARRAY') {
18612: my $depth = 0;
18613: my $chg = 0;
18614: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
18615: my $name = $chkcats[0][$i];
18616: my $item;
18617: if ($name eq '') {
18618: $chg ++;
18619: } else {
18620: $item = &escape($name).'::0';
18621: if ($chg) {
1.57 raeburn 18622: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 18623: }
18624: $depth ++;
1.57 raeburn 18625: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 18626: $depth --;
18627: }
18628: }
18629: }
1.57 raeburn 18630: }
18631: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
18632: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 18633: if ($putresult eq 'ok') {
1.57 raeburn 18634: my %title = (
1.120 raeburn 18635: togglecats => 'Show/Hide a course in catalog',
18636: categorize => 'Assign a category to a course',
18637: togglecatscomm => 'Show/Hide a community in catalog',
18638: categorizecomm => 'Assign a category to a community',
1.57 raeburn 18639: );
18640: my %level = (
1.120 raeburn 18641: dom => 'set in Domain ("Modify Course/Community")',
18642: crs => 'set in Course ("Course Configuration")',
18643: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 18644: none => 'No catalog',
18645: std => 'Standard catalog',
18646: domonly => 'Domain-only catalog',
18647: codesrch => 'Code search form',
1.57 raeburn 18648: );
1.48 raeburn 18649: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 18650: if ($changes{'togglecats'}) {
18651: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
18652: }
18653: if ($changes{'categorize'}) {
18654: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 18655: }
1.120 raeburn 18656: if ($changes{'togglecatscomm'}) {
18657: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
18658: }
18659: if ($changes{'categorizecomm'}) {
18660: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
18661: }
1.238 raeburn 18662: if ($changes{'unauth'}) {
18663: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
18664: }
18665: if ($changes{'auth'}) {
18666: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
18667: }
1.57 raeburn 18668: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
18669: my $cathash;
18670: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
18671: $cathash = $domconfig{'coursecategories'}{'cats'};
18672: } else {
18673: $cathash = {};
18674: }
18675: my (@cats,@trails,%allitems);
18676: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
18677: if (keys(%deletions) > 0) {
18678: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
18679: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
18680: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
18681: }
18682: $resulttext .= '</ul></li>';
18683: }
18684: if (keys(%reorderings) > 0) {
18685: my %sort_by_trail;
18686: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
18687: foreach my $key (keys(%reorderings)) {
18688: if ($allitems{$key} ne '') {
18689: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
18690: }
1.48 raeburn 18691: }
1.57 raeburn 18692: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
18693: $resulttext .= '<li>'.$trails[$trail].'</li>';
18694: }
18695: $resulttext .= '</ul></li>';
1.48 raeburn 18696: }
1.57 raeburn 18697: if (keys(%adds) > 0) {
18698: my %sort_by_trail;
18699: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
18700: foreach my $key (keys(%adds)) {
18701: if ($allitems{$key} ne '') {
18702: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
18703: }
18704: }
18705: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
18706: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 18707: }
1.57 raeburn 18708: $resulttext .= '</ul></li>';
1.48 raeburn 18709: }
1.364 raeburn 18710: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
18711: if (ref($lastactref) eq 'HASH') {
18712: $lastactref->{'cats'} = 1;
18713: }
1.48 raeburn 18714: }
18715: $resulttext .= '</ul>';
1.239 raeburn 18716: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 18717: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
18718: if ($changes{'auth'}) {
18719: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
18720: }
18721: if ($changes{'unauth'}) {
18722: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
18723: }
18724: my $cachetime = 24*60*60;
18725: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 18726: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 18727: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 18728: }
18729: }
1.48 raeburn 18730: } else {
18731: $resulttext = '<span class="LC_error">'.
1.57 raeburn 18732: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 18733: }
18734: } else {
1.120 raeburn 18735: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 18736: }
18737: return $resulttext;
18738: }
18739:
1.69 raeburn 18740: sub modify_serverstatuses {
18741: my ($dom,%domconfig) = @_;
18742: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
18743: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
18744: %currserverstatus = %{$domconfig{'serverstatuses'}};
18745: }
18746: my @pages = &serverstatus_pages();
18747: foreach my $type (@pages) {
18748: $newserverstatus{$type}{'namedusers'} = '';
18749: $newserverstatus{$type}{'machines'} = '';
18750: if (defined($env{'form.'.$type.'_namedusers'})) {
18751: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
18752: my @okusers;
18753: foreach my $user (@users) {
18754: my ($uname,$udom) = split(/:/,$user);
18755: if (($udom =~ /^$match_domain$/) &&
18756: (&Apache::lonnet::domain($udom)) &&
18757: ($uname =~ /^$match_username$/)) {
18758: if (!grep(/^\Q$user\E/,@okusers)) {
18759: push(@okusers,$user);
18760: }
18761: }
18762: }
18763: if (@okusers > 0) {
18764: @okusers = sort(@okusers);
18765: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
18766: }
18767: }
18768: if (defined($env{'form.'.$type.'_machines'})) {
18769: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
18770: my @okmachines;
18771: foreach my $ip (@machines) {
18772: my @parts = split(/\./,$ip);
18773: next if (@parts < 4);
18774: my $badip = 0;
18775: for (my $i=0; $i<4; $i++) {
18776: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
18777: $badip = 1;
18778: last;
18779: }
18780: }
18781: if (!$badip) {
18782: push(@okmachines,$ip);
18783: }
18784: }
18785: @okmachines = sort(@okmachines);
18786: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
18787: }
18788: }
18789: my %serverstatushash = (
18790: serverstatuses => \%newserverstatus,
18791: );
18792: foreach my $type (@pages) {
1.83 raeburn 18793: foreach my $setting ('namedusers','machines') {
1.84 raeburn 18794: my (@current,@new);
1.83 raeburn 18795: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 18796: if ($currserverstatus{$type}{$setting} ne '') {
18797: @current = split(/,/,$currserverstatus{$type}{$setting});
18798: }
18799: }
18800: if ($newserverstatus{$type}{$setting} ne '') {
18801: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 18802: }
18803: if (@current > 0) {
18804: if (@new > 0) {
18805: foreach my $item (@current) {
18806: if (!grep(/^\Q$item\E$/,@new)) {
18807: $changes{$type}{$setting} = 1;
1.82 raeburn 18808: last;
18809: }
18810: }
1.84 raeburn 18811: foreach my $item (@new) {
18812: if (!grep(/^\Q$item\E$/,@current)) {
18813: $changes{$type}{$setting} = 1;
18814: last;
1.82 raeburn 18815: }
18816: }
18817: } else {
1.83 raeburn 18818: $changes{$type}{$setting} = 1;
1.69 raeburn 18819: }
1.83 raeburn 18820: } elsif (@new > 0) {
18821: $changes{$type}{$setting} = 1;
1.69 raeburn 18822: }
18823: }
18824: }
18825: if (keys(%changes) > 0) {
1.81 raeburn 18826: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 18827: my $putresult = &Apache::lonnet::put_dom('configuration',
18828: \%serverstatushash,$dom);
18829: if ($putresult eq 'ok') {
18830: $resulttext .= &mt('Changes made:').'<ul>';
18831: foreach my $type (@pages) {
1.84 raeburn 18832: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 18833: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 18834: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 18835: if ($newserverstatus{$type}{'namedusers'} eq '') {
18836: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
18837: } else {
18838: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
18839: }
1.84 raeburn 18840: }
18841: if ($changes{$type}{'machines'}) {
1.69 raeburn 18842: if ($newserverstatus{$type}{'machines'} eq '') {
18843: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
18844: } else {
18845: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
18846: }
18847:
18848: }
18849: $resulttext .= '</ul></li>';
18850: }
18851: }
18852: $resulttext .= '</ul>';
18853: } else {
18854: $resulttext = '<span class="LC_error">'.
18855: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
18856:
18857: }
18858: } else {
18859: $resulttext = &mt('No changes made to access to server status pages');
18860: }
18861: return $resulttext;
18862: }
18863:
1.118 jms 18864: sub modify_helpsettings {
1.285 raeburn 18865: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 18866: my ($resulttext,$errors,%changes,%helphash);
18867: my %defaultchecked = ('submitbugs' => 'on');
18868: my @offon = ('off','on');
1.118 jms 18869: my @toggles = ('submitbugs');
1.285 raeburn 18870: my %current = ('submitbugs' => '',
18871: 'adhoc' => {},
18872: );
1.118 jms 18873: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 18874: %current = %{$domconfig{'helpsettings'}};
18875: }
1.285 raeburn 18876: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 18877: foreach my $item (@toggles) {
18878: if ($defaultchecked{$item} eq 'on') {
18879: if ($current{$item} eq '') {
18880: if ($env{'form.'.$item} eq '0') {
18881: $changes{$item} = 1;
18882: }
18883: } elsif ($current{$item} ne $env{'form.'.$item}) {
18884: $changes{$item} = 1;
18885: }
18886: } elsif ($defaultchecked{$item} eq 'off') {
18887: if ($current{$item} eq '') {
18888: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 18889: $changes{$item} = 1;
18890: }
1.282 raeburn 18891: } elsif ($current{$item} ne $env{'form.'.$item}) {
18892: $changes{$item} = 1;
18893: }
18894: }
18895: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
18896: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
18897: }
18898: }
1.285 raeburn 18899: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 18900: my $confname = $dom.'-domainconfig';
18901: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 18902: my (@allpos,%newsettings,%changedprivs,$newrole);
18903: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 18904: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 18905: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 18906: my %lt = &Apache::lonlocal::texthash(
18907: s => 'system',
18908: d => 'domain',
18909: order => 'Display order',
18910: access => 'Role usage',
1.291 raeburn 18911: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 18912: dh => 'All with domain helpdesk role',
18913: da => 'All with domain helpdesk assistant role',
1.285 raeburn 18914: none => 'None',
18915: status => 'Determined based on institutional status',
18916: inc => 'Include all, but exclude specific personnel',
18917: exc => 'Exclude all, but include specific personnel',
18918: );
18919: for (my $num=0; $num<=$maxnum; $num++) {
18920: my ($prefix,$identifier,$rolename,%curr);
18921: if ($num == $maxnum) {
18922: next unless ($env{'form.newcusthelp'} == $maxnum);
18923: $identifier = 'custhelp'.$num;
18924: $prefix = 'helproles_'.$num;
18925: $rolename = $env{'form.custhelpname'.$num};
18926: $rolename=~s/[^A-Za-z0-9]//gs;
18927: next if ($rolename eq '');
18928: next if (exists($existing{'rolesdef_'.$rolename}));
18929: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
18930: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
18931: $newprivs{'c'},$confname,$dom);
18932: if ($result ne 'ok') {
18933: $errors .= '<li><span class="LC_error">'.
18934: &mt('An error occurred storing the new custom role: [_1]',
18935: $result).'</span></li>';
18936: next;
18937: } else {
18938: $changedprivs{$rolename} = \%newprivs;
18939: $newrole = $rolename;
18940: }
18941: } else {
18942: $prefix = 'helproles_'.$num;
18943: $rolename = $env{'form.'.$prefix};
18944: next if ($rolename eq '');
18945: next unless (exists($existing{'rolesdef_'.$rolename}));
18946: $identifier = 'custhelp'.$num;
18947: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
18948: my %currprivs;
1.289 raeburn 18949: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 18950: split(/\_/,$existing{'rolesdef_'.$rolename});
18951: foreach my $level ('c','d','s') {
18952: if ($newprivs{$level} ne $currprivs{$level}) {
18953: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
18954: $newprivs{'c'},$confname,$dom);
18955: if ($result ne 'ok') {
18956: $errors .= '<li><span class="LC_error">'.
18957: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
18958: $rolename,$result).'</span></li>';
18959: } else {
18960: $changedprivs{$rolename} = \%newprivs;
18961: }
18962: last;
18963: }
18964: }
18965: if (ref($current{'adhoc'}) eq 'HASH') {
18966: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
18967: %curr = %{$current{'adhoc'}{$rolename}};
18968: }
18969: }
18970: }
18971: my $newpos = $env{'form.'.$prefix.'_pos'};
18972: $newpos =~ s/\D+//g;
18973: $allpos[$newpos] = $rolename;
18974: my $newdesc = $env{'form.'.$prefix.'_desc'};
18975: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
18976: if ($curr{'desc'}) {
18977: if ($curr{'desc'} ne $newdesc) {
18978: $changes{'customrole'}{$rolename}{'desc'} = 1;
18979: $newsettings{$rolename}{'desc'} = $newdesc;
18980: }
18981: } elsif ($newdesc ne '') {
18982: $changes{'customrole'}{$rolename}{'desc'} = 1;
18983: $newsettings{$rolename}{'desc'} = $newdesc;
18984: }
18985: my $access = $env{'form.'.$prefix.'_access'};
18986: if (grep(/^\Q$access\E$/,@accesstypes)) {
18987: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
18988: if ($access eq 'status') {
18989: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
18990: if (scalar(@statuses) == 0) {
1.289 raeburn 18991: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 18992: } else {
18993: my (@shownstatus,$numtypes);
18994: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
18995: if (ref($types) eq 'ARRAY') {
18996: $numtypes = scalar(@{$types});
18997: foreach my $type (sort(@statuses)) {
18998: if ($type eq 'default') {
18999: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
19000: } elsif (grep(/^\Q$type\E$/,@{$types})) {
19001: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
19002: push(@shownstatus,$usertypes->{$type});
19003: }
19004: }
19005: }
19006: if (grep(/^default$/,@statuses)) {
19007: push(@shownstatus,$othertitle);
19008: }
19009: if (scalar(@shownstatus) == 1+$numtypes) {
19010: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
19011: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
19012: } else {
19013: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
19014: if (ref($curr{'status'}) eq 'ARRAY') {
19015: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
19016: if (@diffs) {
19017: $changes{'customrole'}{$rolename}{$access} = 1;
19018: }
19019: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
19020: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 19021: }
1.166 raeburn 19022: }
19023: }
1.285 raeburn 19024: } elsif (($access eq 'inc') || ($access eq 'exc')) {
19025: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
19026: my @newspecstaff;
19027: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
19028: foreach my $person (sort(@personnel)) {
19029: if ($domhelpdesk{$person}) {
19030: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
19031: }
19032: }
19033: if (ref($curr{$access}) eq 'ARRAY') {
19034: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
19035: if (@diffs) {
19036: $changes{'customrole'}{$rolename}{$access} = 1;
19037: }
19038: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
19039: $changes{'customrole'}{$rolename}{$access} = 1;
19040: }
19041: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
19042: my ($uname,$udom) = split(/:/,$person);
19043: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
19044: }
19045: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 19046: }
1.285 raeburn 19047: } else {
19048: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
19049: }
19050: unless ($curr{'access'} eq $access) {
19051: $changes{'customrole'}{$rolename}{'access'} = 1;
19052: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 19053: }
19054: }
1.285 raeburn 19055: if (@allpos > 0) {
19056: my $idx = 0;
19057: foreach my $rolename (@allpos) {
19058: if ($rolename ne '') {
19059: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
19060: if (ref($current{'adhoc'}) eq 'HASH') {
19061: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
19062: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
19063: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 19064: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 19065: }
19066: }
1.282 raeburn 19067: }
1.285 raeburn 19068: $idx ++;
1.166 raeburn 19069: }
19070: }
1.118 jms 19071: }
1.123 jms 19072: my $putresult;
19073: if (keys(%changes) > 0) {
1.166 raeburn 19074: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 19075: if ($putresult eq 'ok') {
1.285 raeburn 19076: if (ref($helphash{'helpsettings'}) eq 'HASH') {
19077: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
19078: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
19079: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
19080: }
19081: }
19082: my $cachetime = 24*60*60;
19083: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19084: if (ref($lastactref) eq 'HASH') {
19085: $lastactref->{'domdefaults'} = 1;
19086: }
19087: } else {
19088: $errors .= '<li><span class="LC_error">'.
19089: &mt('An error occurred storing the settings: [_1]',
19090: $putresult).'</span></li>';
19091: }
19092: }
19093: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
19094: $resulttext = &mt('Changes made:').'<ul>';
19095: my (%shownprivs,@levelorder);
19096: @levelorder = ('c','d','s');
19097: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 19098: foreach my $item (sort(keys(%changes))) {
19099: if ($item eq 'submitbugs') {
19100: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
19101: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
19102: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 19103: } elsif ($item eq 'customrole') {
19104: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 19105: my @keyorder = ('order','desc','access','status','exc','inc');
19106: my %keytext = &Apache::lonlocal::texthash(
19107: order => 'Order',
19108: desc => 'Role description',
19109: access => 'Role usage',
1.300 droeschl 19110: status => 'Allowed institutional types',
1.285 raeburn 19111: exc => 'Allowed personnel',
19112: inc => 'Disallowed personnel',
19113: );
1.282 raeburn 19114: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 19115: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
19116: if ($role eq $newrole) {
19117: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
19118: $role).'<ul>';
19119: } else {
19120: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
19121: $role).'<ul>';
19122: }
19123: foreach my $key (@keyorder) {
19124: if ($changes{'customrole'}{$role}{$key}) {
19125: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
19126: $keytext{$key},$newsettings{$role}{$key}).
19127: '</li>';
19128: }
19129: }
19130: if (ref($changedprivs{$role}) eq 'HASH') {
19131: $shownprivs{$role} = 1;
19132: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
19133: foreach my $level (@levelorder) {
19134: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
19135: next if ($item eq '');
19136: my ($priv) = split(/\&/,$item,2);
19137: if (&Apache::lonnet::plaintext($priv)) {
19138: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
19139: unless ($level eq 'c') {
19140: $resulttext .= ' ('.$lt{$level}.')';
19141: }
19142: $resulttext .= '</li>';
19143: }
19144: }
19145: }
19146: $resulttext .= '</ul>';
19147: }
19148: $resulttext .= '</ul></li>';
19149: }
19150: }
19151: }
19152: }
19153: }
19154: }
19155: if (keys(%changedprivs)) {
19156: foreach my $role (sort(keys(%changedprivs))) {
19157: unless ($shownprivs{$role}) {
19158: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
19159: $role).'<ul>'.
19160: '<li>'.&mt('Privileges set to :').'<ul>';
19161: foreach my $level (@levelorder) {
19162: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
19163: next if ($item eq '');
19164: my ($priv) = split(/\&/,$item,2);
19165: if (&Apache::lonnet::plaintext($priv)) {
19166: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
19167: unless ($level eq 'c') {
19168: $resulttext .= ' ('.$lt{$level}.')';
19169: }
19170: $resulttext .= '</li>';
19171: }
1.282 raeburn 19172: }
19173: }
1.285 raeburn 19174: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 19175: }
19176: }
19177: }
1.285 raeburn 19178: $resulttext .= '</ul>';
19179: } else {
19180: $resulttext = &mt('No changes made to help settings');
1.118 jms 19181: }
19182: if ($errors) {
1.168 raeburn 19183: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 19184: $errors.'</ul>';
1.118 jms 19185: }
19186: return $resulttext;
19187: }
19188:
1.121 raeburn 19189: sub modify_coursedefaults {
1.212 raeburn 19190: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 19191: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 19192: my %defaultchecked = (
19193: 'canuse_pdfforms' => 'off',
19194: 'uselcmath' => 'on',
19195: 'usejsme' => 'on'
19196: );
19197: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 19198: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 19199: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
19200: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
19201: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 19202: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 19203: my %staticdefaults = (
19204: anonsurvey_threshold => 10,
19205: uploadquota => 500,
1.257 raeburn 19206: postsubmit => 60,
1.276 raeburn 19207: mysqltables => 172800,
1.198 raeburn 19208: );
1.314 raeburn 19209: my %texoptions = (
19210: MathJax => 'MathJax',
19211: mimetex => &mt('Convert to Images'),
19212: tth => &mt('TeX to HTML'),
19213: );
1.121 raeburn 19214: $defaultshash{'coursedefaults'} = {};
19215:
19216: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
19217: if ($domconfig{'coursedefaults'} eq '') {
19218: $domconfig{'coursedefaults'} = {};
19219: }
19220: }
19221:
19222: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
19223: foreach my $item (@toggles) {
19224: if ($defaultchecked{$item} eq 'on') {
19225: if (($domconfig{'coursedefaults'}{$item} eq '') &&
19226: ($env{'form.'.$item} eq '0')) {
19227: $changes{$item} = 1;
1.192 raeburn 19228: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 19229: $changes{$item} = 1;
19230: }
19231: } elsif ($defaultchecked{$item} eq 'off') {
19232: if (($domconfig{'coursedefaults'}{$item} eq '') &&
19233: ($env{'form.'.$item} eq '1')) {
19234: $changes{$item} = 1;
19235: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
19236: $changes{$item} = 1;
19237: }
19238: }
19239: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
19240: }
1.198 raeburn 19241: foreach my $item (@numbers) {
19242: my ($currdef,$newdef);
1.208 raeburn 19243: $newdef = $env{'form.'.$item};
1.198 raeburn 19244: if ($item eq 'anonsurvey_threshold') {
19245: $currdef = $domconfig{'coursedefaults'}{$item};
19246: $newdef =~ s/\D//g;
19247: if ($newdef eq '' || $newdef < 1) {
19248: $newdef = 1;
19249: }
19250: $defaultshash{'coursedefaults'}{$item} = $newdef;
19251: } else {
1.276 raeburn 19252: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
19253: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
19254: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 19255: }
19256: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 19257: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 19258: }
19259: if ($currdef ne $newdef) {
19260: if ($item eq 'anonsurvey_threshold') {
19261: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
19262: $changes{$item} = 1;
19263: }
1.276 raeburn 19264: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 19265: my $setting = $1;
1.276 raeburn 19266: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
19267: $changes{$setting} = 1;
1.198 raeburn 19268: }
19269: }
1.139 raeburn 19270: }
19271: }
1.314 raeburn 19272: my $texengine;
19273: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
19274: $texengine = $env{'form.texengine'};
1.349 raeburn 19275: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
19276: if ($currdef eq '') {
19277: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 19278: $changes{'texengine'} = 1;
19279: }
1.349 raeburn 19280: } elsif ($currdef ne $texengine) {
1.314 raeburn 19281: $changes{'texengine'} = 1;
19282: }
19283: }
19284: if ($texengine ne '') {
19285: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
19286: }
1.264 raeburn 19287: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
19288: my @currclonecode;
19289: if (ref($currclone) eq 'HASH') {
19290: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
19291: @currclonecode = @{$currclone->{'instcode'}};
19292: }
19293: }
19294: my $newclone;
1.289 raeburn 19295: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 19296: $newclone = $env{'form.canclone'};
19297: }
19298: if ($newclone eq 'instcode') {
19299: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
19300: my (%codedefaults,@code_order,@clonecode);
19301: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
19302: \@code_order);
19303: foreach my $item (@code_order) {
19304: if (grep(/^\Q$item\E$/,@newcodes)) {
19305: push(@clonecode,$item);
19306: }
19307: }
19308: if (@clonecode) {
19309: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
19310: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
19311: if (@diffs) {
19312: $changes{'canclone'} = 1;
19313: }
19314: } else {
19315: $newclone eq '';
19316: }
19317: } elsif ($newclone ne '') {
1.289 raeburn 19318: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
19319: }
1.264 raeburn 19320: if ($newclone ne $currclone) {
19321: $changes{'canclone'} = 1;
19322: }
1.257 raeburn 19323: my %credits;
19324: foreach my $type (@types) {
19325: unless ($type eq 'community') {
19326: $credits{$type} = $env{'form.'.$type.'_credits'};
19327: $credits{$type} =~ s/[^\d.]+//g;
19328: }
19329: }
19330: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
19331: ($env{'form.coursecredits'} eq '1')) {
19332: $changes{'coursecredits'} = 1;
19333: foreach my $type (keys(%credits)) {
19334: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
19335: }
19336: } else {
1.289 raeburn 19337: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 19338: foreach my $type (@types) {
19339: unless ($type eq 'community') {
1.289 raeburn 19340: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 19341: $changes{'coursecredits'} = 1;
19342: }
19343: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
19344: }
19345: }
19346: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
19347: foreach my $type (@types) {
19348: unless ($type eq 'community') {
19349: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
19350: $changes{'coursecredits'} = 1;
19351: last;
19352: }
19353: }
19354: }
19355: }
19356: }
19357: if ($env{'form.postsubmit'} eq '1') {
19358: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
19359: my %currtimeout;
19360: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19361: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
19362: $changes{'postsubmit'} = 1;
19363: }
19364: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19365: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
19366: }
19367: } else {
19368: $changes{'postsubmit'} = 1;
19369: }
19370: foreach my $type (@types) {
19371: my $timeout = $env{'form.'.$type.'_timeout'};
19372: $timeout =~ s/\D//g;
19373: if ($timeout == $staticdefaults{'postsubmit'}) {
19374: $timeout = '';
19375: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
19376: $timeout = '0';
19377: }
19378: unless ($timeout eq '') {
19379: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
19380: }
19381: if (exists($currtimeout{$type})) {
19382: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 19383: $changes{'postsubmit'} = 1;
1.257 raeburn 19384: }
19385: } elsif ($timeout ne '') {
19386: $changes{'postsubmit'} = 1;
19387: }
19388: }
19389: } else {
19390: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
19391: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19392: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
19393: $changes{'postsubmit'} = 1;
19394: }
19395: } else {
19396: $changes{'postsubmit'} = 1;
19397: }
1.192 raeburn 19398: }
1.121 raeburn 19399: }
19400: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
19401: $dom);
19402: if ($putresult eq 'ok') {
19403: if (keys(%changes) > 0) {
1.213 raeburn 19404: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 19405: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 19406: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314 raeburn 19407: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
19408: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257 raeburn 19409: if ($changes{$item}) {
19410: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
19411: }
1.289 raeburn 19412: }
1.192 raeburn 19413: if ($changes{'coursecredits'}) {
19414: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 19415: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
19416: $domdefaults{$type.'credits'} =
19417: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
19418: }
19419: }
19420: }
19421: if ($changes{'postsubmit'}) {
19422: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19423: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
19424: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19425: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
19426: $domdefaults{$type.'postsubtimeout'} =
19427: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
19428: }
19429: }
1.192 raeburn 19430: }
19431: }
1.198 raeburn 19432: if ($changes{'uploadquota'}) {
19433: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
19434: foreach my $type (@types) {
19435: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
19436: }
19437: }
19438: }
1.264 raeburn 19439: if ($changes{'canclone'}) {
19440: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
19441: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
19442: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
19443: if (@clonecodes) {
19444: $domdefaults{'canclone'} = join('+',@clonecodes);
19445: }
19446: }
19447: } else {
19448: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
19449: }
19450: }
1.121 raeburn 19451: my $cachetime = 24*60*60;
19452: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 19453: if (ref($lastactref) eq 'HASH') {
19454: $lastactref->{'domdefaults'} = 1;
19455: }
1.121 raeburn 19456: }
19457: $resulttext = &mt('Changes made:').'<ul>';
19458: foreach my $item (sort(keys(%changes))) {
19459: if ($item eq 'canuse_pdfforms') {
19460: if ($env{'form.'.$item} eq '1') {
19461: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
19462: } else {
19463: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
19464: }
1.257 raeburn 19465: } elsif ($item eq 'uselcmath') {
19466: if ($env{'form.'.$item} eq '1') {
19467: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
19468: } else {
19469: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
19470: }
19471: } elsif ($item eq 'usejsme') {
19472: if ($env{'form.'.$item} eq '1') {
19473: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
19474: } else {
1.289 raeburn 19475: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 19476: }
1.314 raeburn 19477: } elsif ($item eq 'texengine') {
19478: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
19479: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
19480: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
19481: }
1.139 raeburn 19482: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 19483: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 19484: } elsif ($item eq 'uploadquota') {
19485: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
19486: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
19487: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
19488: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 19489: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 19490: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 19491: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
19492: '</ul>'.
19493: '</li>';
19494: } else {
19495: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
19496: }
1.276 raeburn 19497: } elsif ($item eq 'mysqltables') {
19498: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
19499: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
19500: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
19501: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
19502: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
19503: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
19504: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
19505: '</ul>'.
19506: '</li>';
19507: } else {
19508: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
19509: }
1.257 raeburn 19510: } elsif ($item eq 'postsubmit') {
19511: if ($domdefaults{'postsubmit'} eq 'off') {
19512: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
19513: } else {
19514: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 19515: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 19516: $resulttext .= &mt('durations:').'<ul>';
19517: foreach my $type (@types) {
19518: $resulttext .= '<li>';
19519: my $timeout;
19520: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19521: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
19522: }
19523: my $display;
19524: if ($timeout eq '0') {
19525: $display = &mt('unlimited');
19526: } elsif ($timeout eq '') {
19527: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
19528: } else {
19529: $display = &mt('[quant,_1,second]',$timeout);
19530: }
19531: if ($type eq 'community') {
19532: $resulttext .= &mt('Communities');
19533: } elsif ($type eq 'official') {
19534: $resulttext .= &mt('Official courses');
19535: } elsif ($type eq 'unofficial') {
19536: $resulttext .= &mt('Unofficial courses');
19537: } elsif ($type eq 'textbook') {
19538: $resulttext .= &mt('Textbook courses');
1.271 raeburn 19539: } elsif ($type eq 'placement') {
19540: $resulttext .= &mt('Placement tests');
1.257 raeburn 19541: }
19542: $resulttext .= ' -- '.$display.'</li>';
19543: }
19544: $resulttext .= '</ul>';
19545: }
1.289 raeburn 19546: $resulttext .= '</li>';
1.257 raeburn 19547: }
1.192 raeburn 19548: } elsif ($item eq 'coursecredits') {
19549: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
19550: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 19551: ($domdefaults{'unofficialcredits'} eq '') &&
19552: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 19553: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
19554: } else {
19555: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
19556: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
19557: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 19558: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 19559: '</ul>'.
19560: '</li>';
19561: }
19562: } else {
19563: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
19564: }
1.264 raeburn 19565: } elsif ($item eq 'canclone') {
19566: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
19567: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
19568: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
19569: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
19570: }
19571: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
19572: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
19573: } else {
1.289 raeburn 19574: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 19575: }
1.140 raeburn 19576: }
1.121 raeburn 19577: }
19578: $resulttext .= '</ul>';
19579: } else {
19580: $resulttext = &mt('No changes made to course defaults');
19581: }
19582: } else {
19583: $resulttext = '<span class="LC_error">'.
19584: &mt('An error occurred: [_1]',$putresult).'</span>';
19585: }
19586: return $resulttext;
19587: }
19588:
1.231 raeburn 19589: sub modify_selfenrollment {
19590: my ($dom,$lastactref,%domconfig) = @_;
19591: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 19592: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 19593: my %titles = &tool_titles();
1.232 raeburn 19594: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
19595: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 19596: $ordered{'default'} = ['types','registered','approval','limit'];
19597:
19598: my (%roles,%shown,%toplevel);
19599: $roles{'0'} = &Apache::lonnet::plaintext('dc');
19600:
19601: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
19602: if ($domconfig{'selfenrollment'} eq '') {
19603: $domconfig{'selfenrollment'} = {};
19604: }
19605: }
19606: %toplevel = (
19607: admin => 'Configuration Rights',
19608: default => 'Default settings',
19609: validation => 'Validation of self-enrollment requests',
19610: );
1.233 raeburn 19611: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 19612:
19613: if (ref($ordered{'admin'}) eq 'ARRAY') {
19614: foreach my $item (@{$ordered{'admin'}}) {
19615: foreach my $type (@types) {
19616: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
19617: $selfenrollhash{'admin'}{$type}{$item} = 1;
19618: } else {
19619: $selfenrollhash{'admin'}{$type}{$item} = 0;
19620: }
19621: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
19622: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
19623: if ($selfenrollhash{'admin'}{$type}{$item} ne
19624: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
19625: push(@{$changes{'admin'}{$type}},$item);
19626: }
19627: } else {
19628: if (!$selfenrollhash{'admin'}{$type}{$item}) {
19629: push(@{$changes{'admin'}{$type}},$item);
19630: }
19631: }
19632: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
19633: push(@{$changes{'admin'}{$type}},$item);
19634: }
19635: }
19636: }
19637: }
19638:
19639: foreach my $item (@{$ordered{'default'}}) {
19640: foreach my $type (@types) {
19641: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
19642: if ($item eq 'types') {
19643: unless (($value eq 'all') || ($value eq 'dom')) {
19644: $value = '';
19645: }
19646: } elsif ($item eq 'registered') {
19647: unless ($value eq '1') {
19648: $value = 0;
19649: }
19650: } elsif ($item eq 'approval') {
19651: unless ($value =~ /^[012]$/) {
19652: $value = 0;
19653: }
19654: } else {
19655: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
19656: $value = 'none';
19657: }
19658: }
19659: $selfenrollhash{'default'}{$type}{$item} = $value;
19660: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
19661: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
19662: if ($selfenrollhash{'default'}{$type}{$item} ne
19663: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
19664: push(@{$changes{'default'}{$type}},$item);
19665: }
19666: } else {
19667: push(@{$changes{'default'}{$type}},$item);
19668: }
19669: } else {
19670: push(@{$changes{'default'}{$type}},$item);
19671: }
19672: if ($item eq 'limit') {
19673: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
19674: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
19675: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
19676: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
19677: }
19678: } else {
19679: $selfenrollhash{'default'}{$type}{'cap'} = '';
19680: }
19681: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
19682: if ($selfenrollhash{'default'}{$type}{'cap'} ne
19683: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
19684: push(@{$changes{'default'}{$type}},'cap');
19685: }
19686: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
19687: push(@{$changes{'default'}{$type}},'cap');
19688: }
19689: }
19690: }
19691: }
19692:
19693: foreach my $item (@{$itemsref}) {
19694: if ($item eq 'fields') {
19695: my @changed;
19696: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
19697: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
19698: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
19699: }
19700: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
19701: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
19702: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
19703: $domconfig{'selfenrollment'}{'validation'}{$item});
19704: } else {
19705: @changed = @{$selfenrollhash{'validation'}{$item}};
19706: }
19707: } else {
19708: @changed = @{$selfenrollhash{'validation'}{$item}};
19709: }
19710: if (@changed) {
19711: if ($selfenrollhash{'validation'}{$item}) {
19712: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
19713: } else {
19714: $changes{'validation'}{$item} = &mt('None');
19715: }
19716: }
19717: } else {
19718: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
19719: if ($item eq 'markup') {
19720: if ($env{'form.selfenroll_validation_'.$item}) {
19721: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
19722: }
19723: }
19724: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
19725: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
19726: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
19727: }
19728: }
19729: }
19730: }
19731:
19732: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
19733: $dom);
19734: if ($putresult eq 'ok') {
19735: if (keys(%changes) > 0) {
19736: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
19737: $resulttext = &mt('Changes made:').'<ul>';
19738: foreach my $key ('admin','default','validation') {
19739: if (ref($changes{$key}) eq 'HASH') {
19740: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
19741: if ($key eq 'validation') {
19742: foreach my $item (@{$itemsref}) {
19743: if (exists($changes{$key}{$item})) {
19744: if ($item eq 'markup') {
19745: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
19746: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
19747: } else {
19748: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
19749: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
19750: }
19751: }
19752: }
19753: } else {
19754: foreach my $type (@types) {
19755: if ($type eq 'community') {
19756: $roles{'1'} = &mt('Community personnel');
19757: } else {
19758: $roles{'1'} = &mt('Course personnel');
19759: }
19760: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 19761: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
19762: if ($key eq 'admin') {
19763: my @mgrdc = ();
19764: if (ref($ordered{$key}) eq 'ARRAY') {
19765: foreach my $item (@{$ordered{'admin'}}) {
19766: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
19767: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
19768: push(@mgrdc,$item);
19769: }
19770: }
19771: }
19772: if (@mgrdc) {
19773: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
19774: } else {
19775: delete($domdefaults{$type.'selfenrolladmdc'});
19776: }
19777: }
19778: } else {
19779: if (ref($ordered{$key}) eq 'ARRAY') {
19780: foreach my $item (@{$ordered{$key}}) {
19781: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
19782: $domdefaults{$type.'selfenroll'.$item} =
19783: $selfenrollhash{$key}{$type}{$item};
19784: }
19785: }
19786: }
19787: }
19788: }
1.231 raeburn 19789: $resulttext .= '<li>'.$titles{$type}.'<ul>';
19790: foreach my $item (@{$ordered{$key}}) {
19791: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
19792: $resulttext .= '<li>';
19793: if ($key eq 'admin') {
19794: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
19795: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
19796: } else {
19797: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
19798: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
19799: }
19800: $resulttext .= '</li>';
19801: }
19802: }
19803: $resulttext .= '</ul></li>';
19804: }
19805: }
19806: $resulttext .= '</ul></li>';
19807: }
19808: }
1.305 raeburn 19809: }
19810: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
19811: my $cachetime = 24*60*60;
19812: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19813: if (ref($lastactref) eq 'HASH') {
19814: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 19815: }
1.231 raeburn 19816: }
19817: $resulttext .= '</ul>';
19818: } else {
19819: $resulttext = &mt('No changes made to self-enrollment settings');
19820: }
19821: } else {
19822: $resulttext = '<span class="LC_error">'.
19823: &mt('An error occurred: [_1]',$putresult).'</span>';
19824: }
19825: return $resulttext;
19826: }
19827:
1.373 raeburn 19828: sub modify_wafproxy {
19829: my ($dom,$action,$lastactref,%domconfig) = @_;
19830: my %servers = &Apache::lonnet::internet_dom_servers($dom);
19831: my (%othercontrol,%canset,%values,%curralias,%currvalue,@warnings,%wafproxy,
19832: %changes,%expirecache);
19833: foreach my $server (sort(keys(%servers))) {
19834: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
19835: if ($serverhome eq $server) {
19836: my $serverdom = &Apache::lonnet::host_domain($server);
19837: if ($serverdom eq $dom) {
19838: $canset{$server} = 1;
19839: }
19840: }
19841: }
1.381 raeburn 19842: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
19843: %{$values{$dom}} = ();
19844: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
19845: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
19846: }
1.382 ! raeburn 19847: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 19848: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
19849: }
19850: }
1.373 raeburn 19851: my $output;
19852: if (keys(%canset)) {
19853: %{$wafproxy{'alias'}} = ();
19854: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 19855: if ($env{'form.wafproxy_'.$dom}) {
19856: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
19857: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
19858: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
19859: $changes{'alias'} = 1;
19860: }
19861: } else {
19862: $wafproxy{'alias'}{$key} = '';
19863: if ($curralias{$key}) {
19864: $changes{'alias'} = 1;
19865: }
1.373 raeburn 19866: }
19867: if ($wafproxy{'alias'}{$key} eq '') {
19868: if ($curralias{$key}) {
19869: $expirecache{$key} = 1;
19870: }
19871: delete($wafproxy{'alias'}{$key});
19872: }
19873: }
19874: unless (keys(%{$wafproxy{'alias'}})) {
19875: delete($wafproxy{'alias'});
19876: }
19877: # Localization for values in %warn occus in &mt() calls separately.
19878: my %warn = (
19879: trusted => 'trusted IP range(s)',
1.381 raeburn 19880: vpnint => 'internal IP range(s) for VPN sessions(s)',
19881: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 19882: );
1.382 ! raeburn 19883: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 19884: my $possible = $env{'form.wafproxy_'.$item};
19885: $possible =~ s/^\s+|\s+$//g;
19886: if ($possible ne '') {
1.381 raeburn 19887: if ($item eq 'remoteip') {
19888: if ($possible =~ /^[mhn]$/) {
19889: $wafproxy{$item} = $possible;
19890: }
19891: } elsif ($item eq 'ipheader') {
19892: if ($wafproxy{'remoteip'} eq 'h') {
19893: $wafproxy{$item} = $possible;
19894: }
1.382 ! raeburn 19895: } elsif ($item eq 'sslopt') {
! 19896: if ($possible =~ /^0|1$/) {
! 19897: $wafproxy{$item} = $possible;
! 19898: }
1.373 raeburn 19899: } else {
19900: my (@ok,$count);
1.381 raeburn 19901: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
19902: unless ($env{'form.wafproxy_vpnaccess'}) {
19903: $possible = '';
19904: }
19905: } elsif ($item eq 'trusted') {
19906: unless ($wafproxy{'remoteip'} eq 'h') {
19907: $possible = '';
19908: }
19909: }
19910: unless ($possible eq '') {
19911: $possible =~ s/[\r\n]+/\s/g;
19912: $possible =~ s/\s*-\s*/-/g;
19913: $possible =~ s/\s+/,/g;
19914: }
1.373 raeburn 19915: $count = 0;
1.381 raeburn 19916: if ($possible ne '') {
1.373 raeburn 19917: foreach my $poss (split(/\,/,$possible)) {
19918: $count ++;
19919: if (&validate_ip_pattern($poss)) {
19920: push(@ok,$poss);
19921: }
19922: }
19923: if (@ok) {
19924: $wafproxy{$item} = join(',',@ok);
19925: }
19926: my $diff = $count - scalar(@ok);
19927: if ($diff) {
19928: push(@warnings,'<li>'.
19929: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
19930: $diff,$warn{$item}).
19931: '</li>');
19932: }
19933: }
19934: }
1.381 raeburn 19935: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 19936: $changes{$item} = 1;
19937: }
1.381 raeburn 19938: } elsif ($currvalue{$item}) {
19939: $changes{$item} = 1;
19940: }
19941: }
19942: } else {
19943: if (keys(%curralias)) {
19944: $changes{'alias'} = 1;
19945: }
19946: if (keys(%currvalue)) {
19947: foreach my $key (keys(%currvalue)) {
19948: $changes{$key} = 1;
1.373 raeburn 19949: }
19950: }
19951: }
19952: if (keys(%changes)) {
19953: my %defaultshash = (
19954: wafproxy => \%wafproxy,
19955: );
19956: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
19957: $dom);
19958: if ($putresult eq 'ok') {
19959: my $cachetime = 24*60*60;
19960: my (%domdefaults,$updatedomdefs);
1.382 ! raeburn 19961: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 19962: if ($changes{$item}) {
19963: unless ($updatedomdefs) {
19964: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
19965: $updatedomdefs = 1;
19966: }
19967: if ($wafproxy{$item}) {
19968: $domdefaults{'waf_'.$item} = $wafproxy{$item};
19969: } elsif (exists($domdefaults{'waf_'.$item})) {
19970: delete($domdefaults{'waf_'.$item});
19971: }
19972: }
19973: }
19974: if ($updatedomdefs) {
19975: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19976: if (ref($lastactref) eq 'HASH') {
19977: $lastactref->{'domdefaults'} = 1;
19978: }
19979: }
19980: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
19981: my %updates = %expirecache;
19982: foreach my $key (keys(%expirecache)) {
19983: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
19984: }
19985: if (ref($wafproxy{'alias'}) eq 'HASH') {
19986: my $cachetime = 24*60*60;
19987: foreach my $key (keys(%{$wafproxy{'alias'}})) {
19988: $updates{$key} = 1;
19989: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
19990: $cachetime);
19991: }
19992: }
19993: if (ref($lastactref) eq 'HASH') {
19994: $lastactref->{'proxyalias'} = \%updates;
19995: }
19996: }
19997: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.382 ! raeburn 19998: foreach my $item ('alias','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 19999: if ($changes{$item}) {
20000: if ($item eq 'alias') {
20001: my $numaliased = 0;
20002: if (ref($wafproxy{'alias'}) eq 'HASH') {
20003: my $shown;
20004: if (keys(%{$wafproxy{'alias'}})) {
20005: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
20006: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
20007: &Apache::lonnet::hostname($server),
20008: $wafproxy{'alias'}{$server}).'</li>';
20009: $numaliased ++;
20010: }
20011: if ($numaliased) {
20012: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
20013: '<ul>'.$shown.'</ul>').'</li>';
20014: }
20015: }
20016: }
20017: unless ($numaliased) {
20018: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
20019: }
20020: } else {
1.381 raeburn 20021: if ($item eq 'remoteip') {
20022: my %ip_methods = &remoteip_methods();
20023: if ($wafproxy{$item} =~ /^[mh]$/) {
20024: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
20025: $ip_methods{$wafproxy{$item}}).'</li>';
20026: } else {
20027: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
20028: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
20029: '</li>';
20030: } else {
20031: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
20032: }
20033: }
20034: } elsif ($item eq 'ipheader') {
1.373 raeburn 20035: if ($wafproxy{$item}) {
1.381 raeburn 20036: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 20037: $wafproxy{$item}).'</li>';
20038: } else {
1.381 raeburn 20039: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 20040: }
20041: } elsif ($item eq 'trusted') {
20042: if ($wafproxy{$item}) {
1.381 raeburn 20043: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 20044: $wafproxy{$item}).'</li>';
20045: } else {
20046: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
20047: }
1.381 raeburn 20048: } elsif ($item eq 'vpnint') {
20049: if ($wafproxy{$item}) {
20050: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
20051: $wafproxy{$item}).'</li>';
20052: } else {
20053: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
20054: }
20055: } elsif ($item eq 'vpnext') {
1.373 raeburn 20056: if ($wafproxy{$item}) {
1.381 raeburn 20057: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 20058: $wafproxy{$item}).'</li>';
20059: } else {
1.381 raeburn 20060: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 20061: }
1.382 ! raeburn 20062: } elsif ($item eq 'sslopt') {
! 20063: if ($wafproxy{$item}) {
! 20064: $output .= '<li>'.&mt('WAF/Reverse Proxy expected to forward requests to https on LON-CAPA node, regardless of original protocol in web browser (http or https).').'</li>';
! 20065: } else {
! 20066: $output .= '<li>'.&mt('WAF/Reverse Proxy expected to preserve original protocol in web browser (either http or https) when forwarding to LON-CAPA node.').'</li>';
! 20067: }
1.373 raeburn 20068: }
20069: }
20070: }
20071: }
20072: } else {
20073: $output = '<span class="LC_error">'.
20074: &mt('An error occurred: [_1]',$putresult).'</span>';
20075: }
20076: } elsif (keys(%canset)) {
20077: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
20078: }
20079: if (@warnings) {
20080: $output .= '<br />'.&mt('Warnings:').'<ul>'.
20081: join("\n",@warnings).'</ul>';
20082: }
20083: return $output;
20084: }
20085:
20086: sub validate_ip_pattern {
20087: my ($pattern) = @_;
20088: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
20089: my ($start,$end) = ($1,$2);
20090: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
20091: return 1;
20092: }
20093: } elsif (&Net::CIDR::cidrvalidate($pattern)) {
20094: return 1;
20095: }
20096: return
20097: }
20098:
1.137 raeburn 20099: sub modify_usersessions {
1.212 raeburn 20100: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 20101: my @hostingtypes = ('version','excludedomain','includedomain');
20102: my @offloadtypes = ('primary','default');
20103: my %types = (
20104: remote => \@hostingtypes,
20105: hosted => \@hostingtypes,
20106: spares => \@offloadtypes,
20107: );
20108: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 20109: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 20110: my (%by_ip,%by_location,@intdoms,@instdoms);
20111: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 20112: my @locations = sort(keys(%by_location));
1.137 raeburn 20113: my (%defaultshash,%changes);
20114: foreach my $prefix (@prefixes) {
20115: $defaultshash{'usersessions'}{$prefix} = {};
20116: }
1.212 raeburn 20117: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 20118: my $resulttext;
1.138 raeburn 20119: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 20120: foreach my $prefix (@prefixes) {
1.145 raeburn 20121: next if ($prefix eq 'spares');
20122: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 20123: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
20124: if ($type eq 'version') {
20125: my $value = $env{'form.'.$prefix.'_'.$type};
20126: my $okvalue;
20127: if ($value ne '') {
20128: if (grep(/^\Q$value\E$/,@lcversions)) {
20129: $okvalue = $value;
20130: }
20131: }
20132: if (ref($domconfig{'usersessions'}) eq 'HASH') {
20133: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
20134: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
20135: if ($inuse == 0) {
20136: $changes{$prefix}{$type} = 1;
20137: } else {
20138: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
20139: $changes{$prefix}{$type} = 1;
20140: }
20141: if ($okvalue ne '') {
20142: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20143: }
20144: }
20145: } else {
20146: if (($inuse == 1) && ($okvalue ne '')) {
20147: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20148: $changes{$prefix}{$type} = 1;
20149: }
20150: }
20151: } else {
20152: if (($inuse == 1) && ($okvalue ne '')) {
20153: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20154: $changes{$prefix}{$type} = 1;
20155: }
20156: }
20157: } else {
20158: if (($inuse == 1) && ($okvalue ne '')) {
20159: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20160: $changes{$prefix}{$type} = 1;
20161: }
20162: }
20163: } else {
20164: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
20165: my @okvals;
20166: foreach my $val (@vals) {
1.138 raeburn 20167: if ($val =~ /:/) {
20168: my @items = split(/:/,$val);
20169: foreach my $item (@items) {
20170: if (ref($by_location{$item}) eq 'ARRAY') {
20171: push(@okvals,$item);
20172: }
20173: }
20174: } else {
20175: if (ref($by_location{$val}) eq 'ARRAY') {
20176: push(@okvals,$val);
20177: }
1.137 raeburn 20178: }
20179: }
20180: @okvals = sort(@okvals);
20181: if (ref($domconfig{'usersessions'}) eq 'HASH') {
20182: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
20183: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
20184: if ($inuse == 0) {
20185: $changes{$prefix}{$type} = 1;
20186: } else {
20187: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20188: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
20189: if (@changed > 0) {
20190: $changes{$prefix}{$type} = 1;
20191: }
20192: }
20193: } else {
20194: if ($inuse == 1) {
20195: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20196: $changes{$prefix}{$type} = 1;
20197: }
20198: }
20199: } else {
20200: if ($inuse == 1) {
20201: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20202: $changes{$prefix}{$type} = 1;
20203: }
20204: }
20205: } else {
20206: if ($inuse == 1) {
20207: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20208: $changes{$prefix}{$type} = 1;
20209: }
20210: }
20211: }
20212: }
20213: }
1.145 raeburn 20214:
20215: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 20216: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 20217: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
20218: my $savespares;
20219:
20220: foreach my $lonhost (sort(keys(%servers))) {
20221: my $serverhomeID =
20222: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 20223: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 20224: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
20225: my %spareschg;
20226: foreach my $type (@{$types{'spares'}}) {
20227: my @okspares;
20228: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
20229: foreach my $server (@checked) {
1.152 raeburn 20230: if (&Apache::lonnet::hostname($server) ne '') {
20231: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
20232: unless (grep(/^\Q$server\E$/,@okspares)) {
20233: push(@okspares,$server);
20234: }
1.145 raeburn 20235: }
20236: }
20237: }
20238: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
20239: my $newspare;
1.152 raeburn 20240: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
20241: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 20242: $newspare = $new;
20243: }
20244: }
1.152 raeburn 20245: my @spares;
20246: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
20247: @spares = sort(@okspares,$newspare);
20248: } else {
20249: @spares = sort(@okspares);
20250: }
20251: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 20252: if (ref($spareid{$lonhost}) eq 'HASH') {
20253: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 20254: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 20255: if (@diffs > 0) {
20256: $spareschg{$type} = 1;
20257: }
20258: }
20259: }
20260: }
20261: if (keys(%spareschg) > 0) {
20262: $changes{'spares'}{$lonhost} = \%spareschg;
20263: }
20264: }
1.261 raeburn 20265: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 20266: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 20267: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
20268: my @okoffload;
20269: if (@offloadnow) {
20270: foreach my $server (@offloadnow) {
20271: if (&Apache::lonnet::hostname($server) ne '') {
20272: unless (grep(/^\Q$server\E$/,@okoffload)) {
20273: push(@okoffload,$server);
20274: }
20275: }
20276: }
20277: if (@okoffload) {
20278: foreach my $lonhost (@okoffload) {
20279: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
20280: }
20281: }
20282: }
1.371 raeburn 20283: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
20284: my @okoffloadoth;
20285: if (@offloadoth) {
20286: foreach my $server (@offloadoth) {
20287: if (&Apache::lonnet::hostname($server) ne '') {
20288: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
20289: push(@okoffloadoth,$server);
20290: }
20291: }
20292: }
20293: if (@okoffloadoth) {
20294: foreach my $lonhost (@okoffloadoth) {
20295: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
20296: }
20297: }
20298: }
1.145 raeburn 20299: if (ref($domconfig{'usersessions'}) eq 'HASH') {
20300: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
20301: if (ref($changes{'spares'}) eq 'HASH') {
20302: if (keys(%{$changes{'spares'}}) > 0) {
20303: $savespares = 1;
20304: }
20305: }
20306: } else {
20307: $savespares = 1;
20308: }
1.371 raeburn 20309: foreach my $offload ('offloadnow','offloadoth') {
20310: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
20311: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
20312: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
20313: $changes{$offload} = 1;
20314: last;
20315: }
1.261 raeburn 20316: }
1.371 raeburn 20317: unless ($changes{$offload}) {
20318: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
20319: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
20320: $changes{$offload} = 1;
20321: last;
20322: }
1.261 raeburn 20323: }
20324: }
1.371 raeburn 20325: } else {
20326: if (($offload eq 'offloadnow') && (@okoffload)) {
20327: $changes{'offloadnow'} = 1;
20328: }
20329: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
20330: $changes{'offloadoth'} = 1;
20331: }
20332: }
20333: }
20334: } else {
20335: if (@okoffload) {
1.261 raeburn 20336: $changes{'offloadnow'} = 1;
20337: }
1.371 raeburn 20338: if (@okoffloadoth) {
20339: $changes{'offloadoth'} = 1;
20340: }
1.145 raeburn 20341: }
1.147 raeburn 20342: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
20343: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 20344: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20345: $dom);
20346: if ($putresult eq 'ok') {
20347: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
20348: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
20349: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
20350: }
20351: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
20352: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
20353: }
1.261 raeburn 20354: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
20355: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
20356: }
1.371 raeburn 20357: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
20358: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
20359: }
1.137 raeburn 20360: }
20361: my $cachetime = 24*60*60;
20362: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 20363: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 20364: if (ref($lastactref) eq 'HASH') {
20365: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 20366: $lastactref->{'usersessions'} = 1;
1.212 raeburn 20367: }
1.147 raeburn 20368: if (keys(%changes) > 0) {
20369: my %lt = &usersession_titles();
20370: $resulttext = &mt('Changes made:').'<ul>';
20371: foreach my $prefix (@prefixes) {
20372: if (ref($changes{$prefix}) eq 'HASH') {
20373: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
20374: if ($prefix eq 'spares') {
20375: if (ref($changes{$prefix}) eq 'HASH') {
20376: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
20377: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 20378: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 20379: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
20380: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 20381: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
20382: foreach my $type (@{$types{$prefix}}) {
20383: if ($changes{$prefix}{$lonhost}{$type}) {
20384: my $offloadto = &mt('None');
20385: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
20386: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
20387: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
20388: }
1.145 raeburn 20389: }
1.147 raeburn 20390: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 20391: }
1.137 raeburn 20392: }
20393: }
1.147 raeburn 20394: $resulttext .= '</li>';
1.137 raeburn 20395: }
20396: }
1.147 raeburn 20397: } else {
20398: foreach my $type (@{$types{$prefix}}) {
20399: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 20400: my ($newvalue,$notinuse);
1.147 raeburn 20401: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
20402: if (ref($defaultshash{'usersessions'}{$prefix})) {
20403: if ($type eq 'version') {
20404: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 20405: } else {
20406: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
20407: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
20408: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
20409: }
20410: } else {
20411: $notinuse = 1;
1.147 raeburn 20412: }
1.145 raeburn 20413: }
20414: }
20415: }
1.147 raeburn 20416: if ($newvalue eq '') {
20417: if ($type eq 'version') {
20418: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 20419: } elsif ($notinuse) {
20420: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 20421: } else {
20422: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
20423: }
1.145 raeburn 20424: } else {
1.147 raeburn 20425: if ($type eq 'version') {
1.344 raeburn 20426: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 20427: }
20428: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 20429: }
1.137 raeburn 20430: }
20431: }
20432: }
1.147 raeburn 20433: $resulttext .= '</ul>';
1.137 raeburn 20434: }
20435: }
1.261 raeburn 20436: if ($changes{'offloadnow'}) {
20437: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
20438: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 20439: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 20440: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
20441: $resulttext .= '<li>'.$lonhost.'</li>';
20442: }
20443: $resulttext .= '</ul>';
20444: } else {
1.371 raeburn 20445: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
20446: }
20447: } else {
20448: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
20449: }
20450: }
20451: if ($changes{'offloadoth'}) {
20452: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
20453: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
20454: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
20455: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
20456: $resulttext .= '<li>'.$lonhost.'</li>';
20457: }
20458: $resulttext .= '</ul>';
20459: } else {
20460: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 20461: }
20462: } else {
1.371 raeburn 20463: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 20464: }
20465: }
1.147 raeburn 20466: $resulttext .= '</ul>';
20467: } else {
20468: $resulttext = $nochgmsg;
1.137 raeburn 20469: }
20470: } else {
20471: $resulttext = '<span class="LC_error">'.
20472: &mt('An error occurred: [_1]',$putresult).'</span>';
20473: }
20474: } else {
1.147 raeburn 20475: $resulttext = $nochgmsg;
1.137 raeburn 20476: }
20477: return $resulttext;
20478: }
20479:
1.275 raeburn 20480: sub modify_ssl {
20481: my ($dom,$lastactref,%domconfig) = @_;
20482: my (%by_ip,%by_location,@intdoms,@instdoms);
20483: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
20484: my @locations = sort(keys(%by_location));
20485: my %servers = &Apache::lonnet::internet_dom_servers($dom);
20486: my (%defaultshash,%changes);
20487: my $action = 'ssl';
1.293 raeburn 20488: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 20489: foreach my $prefix (@prefixes) {
20490: $defaultshash{$action}{$prefix} = {};
20491: }
20492: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
20493: my $resulttext;
20494: my %iphost = &Apache::lonnet::get_iphost();
20495: my @reptypes = ('certreq','nocertreq');
20496: my @connecttypes = ('dom','intdom','other');
20497: my %types = (
1.293 raeburn 20498: connto => \@connecttypes,
20499: connfrom => \@connecttypes,
20500: replication => \@reptypes,
1.275 raeburn 20501: );
20502: foreach my $prefix (sort(keys(%types))) {
20503: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 20504: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 20505: my $value = 'yes';
20506: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
20507: $value = $env{'form.'.$prefix.'_'.$type};
20508: }
1.335 raeburn 20509: if (ref($domconfig{$action}) eq 'HASH') {
20510: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
20511: if ($domconfig{$action}{$prefix}{$type} ne '') {
20512: if ($value ne $domconfig{$action}{$prefix}{$type}) {
20513: $changes{$prefix}{$type} = 1;
20514: }
20515: $defaultshash{$action}{$prefix}{$type} = $value;
20516: } else {
20517: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 20518: $changes{$prefix}{$type} = 1;
20519: }
20520: } else {
20521: $defaultshash{$action}{$prefix}{$type} = $value;
20522: $changes{$prefix}{$type} = 1;
20523: }
20524: } else {
20525: $defaultshash{$action}{$prefix}{$type} = $value;
20526: $changes{$prefix}{$type} = 1;
20527: }
20528: if (($type eq 'dom') && (keys(%servers) == 1)) {
20529: delete($changes{$prefix}{$type});
20530: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
20531: delete($changes{$prefix}{$type});
20532: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
20533: delete($changes{$prefix}{$type});
20534: }
20535: } elsif ($prefix eq 'replication') {
20536: if (@locations > 0) {
20537: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
20538: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
20539: my @okvals;
20540: foreach my $val (@vals) {
20541: if ($val =~ /:/) {
20542: my @items = split(/:/,$val);
20543: foreach my $item (@items) {
20544: if (ref($by_location{$item}) eq 'ARRAY') {
20545: push(@okvals,$item);
20546: }
20547: }
20548: } else {
20549: if (ref($by_location{$val}) eq 'ARRAY') {
20550: push(@okvals,$val);
20551: }
20552: }
20553: }
20554: @okvals = sort(@okvals);
20555: if (ref($domconfig{$action}) eq 'HASH') {
20556: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
20557: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
20558: if ($inuse == 0) {
20559: $changes{$prefix}{$type} = 1;
20560: } else {
20561: $defaultshash{$action}{$prefix}{$type} = \@okvals;
20562: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
20563: if (@changed > 0) {
20564: $changes{$prefix}{$type} = 1;
20565: }
20566: }
20567: } else {
20568: if ($inuse == 1) {
20569: $defaultshash{$action}{$prefix}{$type} = \@okvals;
20570: $changes{$prefix}{$type} = 1;
20571: }
20572: }
20573: } else {
20574: if ($inuse == 1) {
20575: $defaultshash{$action}{$prefix}{$type} = \@okvals;
20576: $changes{$prefix}{$type} = 1;
20577: }
20578: }
20579: } else {
20580: if ($inuse == 1) {
20581: $defaultshash{$action}{$prefix}{$type} = \@okvals;
20582: $changes{$prefix}{$type} = 1;
20583: }
20584: }
20585: }
20586: }
20587: }
20588: }
1.336 raeburn 20589: if (keys(%changes)) {
20590: foreach my $prefix (keys(%changes)) {
20591: if (ref($changes{$prefix}) eq 'HASH') {
20592: if (scalar(keys(%{$changes{$prefix}})) == 0) {
20593: delete($changes{$prefix});
20594: }
20595: } else {
20596: delete($changes{$prefix});
20597: }
20598: }
20599: }
1.275 raeburn 20600: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
20601: if (keys(%changes) > 0) {
20602: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20603: $dom);
20604: if ($putresult eq 'ok') {
20605: if (ref($defaultshash{$action}) eq 'HASH') {
20606: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
20607: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
20608: }
1.293 raeburn 20609: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 20610: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 20611: }
20612: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 20613: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 20614: }
20615: }
20616: my $cachetime = 24*60*60;
20617: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20618: if (ref($lastactref) eq 'HASH') {
20619: $lastactref->{'domdefaults'} = 1;
20620: }
20621: if (keys(%changes) > 0) {
20622: my %titles = &ssl_titles();
20623: $resulttext = &mt('Changes made:').'<ul>';
20624: foreach my $prefix (@prefixes) {
20625: if (ref($changes{$prefix}) eq 'HASH') {
20626: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
20627: foreach my $type (@{$types{$prefix}}) {
20628: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 20629: my ($newvalue,$notinuse);
1.275 raeburn 20630: if (ref($defaultshash{$action}) eq 'HASH') {
20631: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 20632: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 20633: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 20634: } else {
20635: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
20636: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
20637: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
20638: }
20639: } else {
20640: $notinuse = 1;
1.275 raeburn 20641: }
20642: }
20643: }
1.344 raeburn 20644: if ($notinuse) {
20645: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
20646: } elsif ($newvalue eq '') {
1.275 raeburn 20647: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
20648: } else {
20649: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
20650: }
20651: }
20652: }
20653: }
20654: $resulttext .= '</ul>';
20655: }
20656: }
20657: } else {
20658: $resulttext = $nochgmsg;
20659: }
20660: } else {
20661: $resulttext = '<span class="LC_error">'.
20662: &mt('An error occurred: [_1]',$putresult).'</span>';
20663: }
20664: } else {
20665: $resulttext = $nochgmsg;
20666: }
20667: return $resulttext;
20668: }
20669:
1.279 raeburn 20670: sub modify_trust {
20671: my ($dom,$lastactref,%domconfig) = @_;
20672: my (%by_ip,%by_location,@intdoms,@instdoms);
20673: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
20674: my @locations = sort(keys(%by_location));
20675: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
20676: my @types = ('exc','inc');
20677: my (%defaultshash,%changes);
20678: foreach my $prefix (@prefixes) {
20679: $defaultshash{'trust'}{$prefix} = {};
20680: }
20681: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
20682: my $resulttext;
20683: foreach my $prefix (@prefixes) {
20684: foreach my $type (@types) {
20685: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
20686: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
20687: my @okvals;
20688: foreach my $val (@vals) {
20689: if ($val =~ /:/) {
20690: my @items = split(/:/,$val);
20691: foreach my $item (@items) {
20692: if (ref($by_location{$item}) eq 'ARRAY') {
20693: push(@okvals,$item);
20694: }
20695: }
20696: } else {
20697: if (ref($by_location{$val}) eq 'ARRAY') {
20698: push(@okvals,$val);
20699: }
20700: }
20701: }
20702: @okvals = sort(@okvals);
20703: if (ref($domconfig{'trust'}) eq 'HASH') {
20704: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
20705: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
20706: if ($inuse == 0) {
20707: $changes{$prefix}{$type} = 1;
20708: } else {
20709: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
20710: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
20711: if (@changed > 0) {
20712: $changes{$prefix}{$type} = 1;
20713: }
20714: }
20715: } else {
20716: if ($inuse == 1) {
20717: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
20718: $changes{$prefix}{$type} = 1;
20719: }
20720: }
20721: } else {
20722: if ($inuse == 1) {
20723: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
20724: $changes{$prefix}{$type} = 1;
20725: }
20726: }
20727: } else {
20728: if ($inuse == 1) {
20729: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
20730: $changes{$prefix}{$type} = 1;
20731: }
20732: }
20733: }
20734: }
20735: my $nochgmsg = &mt('No changes made to trust settings.');
20736: if (keys(%changes) > 0) {
20737: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20738: $dom);
20739: if ($putresult eq 'ok') {
20740: if (ref($defaultshash{'trust'}) eq 'HASH') {
20741: foreach my $prefix (@prefixes) {
20742: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
20743: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
20744: }
20745: }
20746: }
20747: my $cachetime = 24*60*60;
20748: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20749: if (ref($lastactref) eq 'HASH') {
20750: $lastactref->{'domdefaults'} = 1;
20751: }
20752: if (keys(%changes) > 0) {
20753: my %lt = &trust_titles();
20754: $resulttext = &mt('Changes made:').'<ul>';
20755: foreach my $prefix (@prefixes) {
20756: if (ref($changes{$prefix}) eq 'HASH') {
20757: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
20758: foreach my $type (@types) {
20759: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 20760: my ($newvalue,$notinuse);
1.279 raeburn 20761: if (ref($defaultshash{'trust'}) eq 'HASH') {
20762: if (ref($defaultshash{'trust'}{$prefix})) {
20763: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
20764: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
20765: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
20766: }
1.344 raeburn 20767: } else {
20768: $notinuse = 1;
1.279 raeburn 20769: }
20770: }
20771: }
1.344 raeburn 20772: if ($notinuse) {
20773: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
20774: } elsif ($newvalue eq '') {
1.279 raeburn 20775: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
20776: } else {
20777: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
20778: }
20779: }
20780: }
20781: $resulttext .= '</ul>';
20782: }
20783: }
20784: $resulttext .= '</ul>';
20785: } else {
20786: $resulttext = $nochgmsg;
20787: }
20788: } else {
20789: $resulttext = '<span class="LC_error">'.
20790: &mt('An error occurred: [_1]',$putresult).'</span>';
20791: }
20792: } else {
20793: $resulttext = $nochgmsg;
20794: }
20795: return $resulttext;
20796: }
20797:
1.150 raeburn 20798: sub modify_loadbalancing {
20799: my ($dom,%domconfig) = @_;
20800: my $primary_id = &Apache::lonnet::domain($dom,'primary');
20801: my $intdom = &Apache::lonnet::internet_dom($primary_id);
20802: my ($othertitle,$usertypes,$types) =
20803: &Apache::loncommon::sorted_inst_types($dom);
20804: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 20805: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 20806: my @sparestypes = ('primary','default');
20807: my %typetitles = &sparestype_titles();
20808: my $resulttext;
1.342 raeburn 20809: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 20810: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
20811: %existing = %{$domconfig{'loadbalancing'}};
20812: }
20813: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 20814: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 20815: my ($saveloadbalancing,%defaultshash,%changes);
20816: my ($alltypes,$othertypes,$titles) =
20817: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
20818: my %ruletitles = &offloadtype_text();
20819: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
20820: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
20821: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
20822: if ($balancer eq '') {
20823: next;
20824: }
1.210 raeburn 20825: if (!exists($servers{$balancer})) {
1.171 raeburn 20826: if (exists($currbalancer{$balancer})) {
20827: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 20828: }
1.171 raeburn 20829: next;
20830: }
20831: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
20832: push(@{$changes{'delete'}},$balancer);
20833: next;
20834: }
20835: if (!exists($currbalancer{$balancer})) {
20836: push(@{$changes{'add'}},$balancer);
20837: }
20838: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
20839: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
20840: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
20841: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
20842: $saveloadbalancing = 1;
20843: }
20844: foreach my $sparetype (@sparestypes) {
20845: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
20846: my @offloadto;
20847: foreach my $target (@targets) {
20848: if (($servers{$target}) && ($target ne $balancer)) {
20849: if ($sparetype eq 'default') {
20850: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
20851: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 20852: }
20853: }
1.171 raeburn 20854: unless(grep(/^\Q$target\E$/,@offloadto)) {
20855: push(@offloadto,$target);
20856: }
1.150 raeburn 20857: }
20858: }
1.284 raeburn 20859: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
20860: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
20861: push(@offloadto,$balancer);
20862: }
20863: }
20864: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 20865: }
1.342 raeburn 20866: if ($env{'form.loadbalancing_cookie_'.$i}) {
20867: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
20868: if (exists($currbalancer{$balancer})) {
20869: unless ($currcookies{$balancer}) {
20870: $changes{'curr'}{$balancer}{'cookie'} = 1;
20871: }
20872: }
20873: } elsif (exists($currbalancer{$balancer})) {
20874: if ($currcookies{$balancer}) {
20875: $changes{'curr'}{$balancer}{'cookie'} = 1;
20876: }
20877: }
1.171 raeburn 20878: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 20879: foreach my $sparetype (@sparestypes) {
1.171 raeburn 20880: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
20881: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 20882: if (@targetdiffs > 0) {
1.171 raeburn 20883: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 20884: }
1.171 raeburn 20885: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20886: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
20887: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 20888: }
20889: }
20890: }
20891: } else {
1.171 raeburn 20892: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 20893: foreach my $sparetype (@sparestypes) {
1.171 raeburn 20894: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20895: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
20896: $changes{'curr'}{$balancer}{'targets'} = 1;
20897: }
1.150 raeburn 20898: }
20899: }
1.210 raeburn 20900: }
1.150 raeburn 20901: }
20902: my $ishomedom;
1.171 raeburn 20903: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
20904: $ishomedom = 1;
1.150 raeburn 20905: }
20906: if (ref($alltypes) eq 'ARRAY') {
20907: foreach my $type (@{$alltypes}) {
20908: my $rule;
1.210 raeburn 20909: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 20910: (!$ishomedom)) {
1.171 raeburn 20911: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
20912: }
20913: if ($rule eq 'specific') {
1.255 raeburn 20914: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 20915: if (exists($servers{$specifiedhost})) {
1.255 raeburn 20916: $rule = $specifiedhost;
20917: }
1.150 raeburn 20918: }
1.171 raeburn 20919: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
20920: if (ref($currrules{$balancer}) eq 'HASH') {
20921: if ($rule ne $currrules{$balancer}{$type}) {
20922: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 20923: }
20924: } elsif ($rule ne '') {
1.171 raeburn 20925: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 20926: }
20927: }
20928: }
1.171 raeburn 20929: }
20930: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
20931: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
20932: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
20933: $defaultshash{'loadbalancing'} = {};
20934: }
20935: my $putresult = &Apache::lonnet::put_dom('configuration',
20936: \%defaultshash,$dom);
20937: if ($putresult eq 'ok') {
20938: if (keys(%changes) > 0) {
1.252 raeburn 20939: my %toupdate;
1.171 raeburn 20940: if (ref($changes{'delete'}) eq 'ARRAY') {
20941: foreach my $balancer (sort(@{$changes{'delete'}})) {
20942: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 20943: $toupdate{$balancer} = 1;
1.150 raeburn 20944: }
1.171 raeburn 20945: }
20946: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 20947: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 20948: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 20949: $toupdate{$balancer} = 1;
1.171 raeburn 20950: }
20951: }
20952: if (ref($changes{'curr'}) eq 'HASH') {
20953: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 20954: $toupdate{$balancer} = 1;
1.171 raeburn 20955: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
20956: if ($changes{'curr'}{$balancer}{'targets'}) {
20957: my %offloadstr;
20958: foreach my $sparetype (@sparestypes) {
20959: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20960: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
20961: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
20962: }
20963: }
1.150 raeburn 20964: }
1.171 raeburn 20965: if (keys(%offloadstr) == 0) {
20966: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 20967: } else {
1.171 raeburn 20968: my $showoffload;
20969: foreach my $sparetype (@sparestypes) {
20970: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
20971: if (defined($offloadstr{$sparetype})) {
20972: $showoffload .= $offloadstr{$sparetype};
20973: } else {
20974: $showoffload .= &mt('None');
20975: }
20976: $showoffload .= (' 'x3);
20977: }
20978: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 20979: }
20980: }
20981: }
1.171 raeburn 20982: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
20983: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
20984: foreach my $type (@{$alltypes}) {
20985: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
20986: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
20987: my $balancetext;
20988: if ($rule eq '') {
20989: $balancetext = $ruletitles{'default'};
1.209 raeburn 20990: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 20991: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 20992: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 20993: foreach my $sparetype (@sparestypes) {
20994: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20995: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
20996: }
20997: }
1.253 raeburn 20998: foreach my $item (@{$alltypes}) {
20999: next if ($item =~ /^_LC_ipchange/);
21000: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
21001: if ($hasrule eq 'homeserver') {
21002: map { $toupdate{$_} = 1; } (keys(%libraryservers));
21003: } else {
21004: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
21005: if ($servers{$hasrule}) {
21006: $toupdate{$hasrule} = 1;
21007: }
21008: }
21009: }
21010: }
1.254 raeburn 21011: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
21012: $balancetext = $ruletitles{$rule};
21013: } else {
21014: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
21015: $balancetext = $ruletitles{'particular'}.' '.$receiver;
21016: if ($receiver) {
21017: $toupdate{$receiver};
21018: }
21019: }
21020: } else {
21021: $balancetext = $ruletitles{$rule};
1.252 raeburn 21022: }
1.171 raeburn 21023: } else {
21024: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
21025: }
1.210 raeburn 21026: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 21027: }
21028: }
21029: }
21030: }
1.342 raeburn 21031: if ($changes{'curr'}{$balancer}{'cookie'}) {
21032: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
21033: $balancer).'</li>';
21034: }
1.375 raeburn 21035: }
21036: }
21037: if (keys(%toupdate)) {
21038: my %thismachine;
21039: my $updatedhere;
21040: my $cachetime = 60*60*24;
21041: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
21042: foreach my $lonhost (keys(%toupdate)) {
21043: if ($thismachine{$lonhost}) {
21044: unless ($updatedhere) {
21045: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
21046: $defaultshash{'loadbalancing'},
21047: $cachetime);
21048: $updatedhere = 1;
1.252 raeburn 21049: }
1.375 raeburn 21050: } else {
21051: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
21052: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 21053: }
1.150 raeburn 21054: }
1.171 raeburn 21055: }
21056: if ($resulttext ne '') {
21057: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 21058: } else {
21059: $resulttext = $nochgmsg;
21060: }
21061: } else {
1.171 raeburn 21062: $resulttext = $nochgmsg;
1.150 raeburn 21063: }
21064: } else {
1.171 raeburn 21065: $resulttext = '<span class="LC_error">'.
21066: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 21067: }
21068: } else {
1.171 raeburn 21069: $resulttext = $nochgmsg;
1.150 raeburn 21070: }
21071: return $resulttext;
21072: }
21073:
1.48 raeburn 21074: sub recurse_check {
21075: my ($chkcats,$categories,$depth,$name) = @_;
21076: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
21077: my $chg = 0;
21078: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
21079: my $category = $chkcats->[$depth]{$name}[$j];
21080: my $item;
21081: if ($category eq '') {
21082: $chg ++;
21083: } else {
21084: my $deeper = $depth + 1;
21085: $item = &escape($category).':'.&escape($name).':'.$depth;
21086: if ($chg) {
21087: $categories->{$item} -= $chg;
21088: }
21089: &recurse_check($chkcats,$categories,$deeper,$category);
21090: $deeper --;
21091: }
21092: }
21093: }
21094: return;
21095: }
21096:
21097: sub recurse_cat_deletes {
21098: my ($item,$coursecategories,$deletions) = @_;
21099: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
21100: my $subdepth = $depth + 1;
21101: if (ref($coursecategories) eq 'HASH') {
21102: foreach my $subitem (keys(%{$coursecategories})) {
21103: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
21104: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
21105: delete($coursecategories->{$subitem});
21106: $deletions->{$subitem} = 1;
21107: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 21108: }
1.48 raeburn 21109: }
21110: }
21111: return;
21112: }
21113:
1.125 raeburn 21114: sub active_dc_picker {
1.191 raeburn 21115: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 21116: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 21117: my @domcoord = keys(%domcoords);
21118: if (keys(%currhash)) {
21119: foreach my $dc (keys(%currhash)) {
21120: unless (exists($domcoords{$dc})) {
21121: push(@domcoord,$dc);
21122: }
21123: }
21124: }
21125: @domcoord = sort(@domcoord);
1.210 raeburn 21126: my $numdcs = scalar(@domcoord);
1.191 raeburn 21127: my $rows = 0;
21128: my $table;
1.125 raeburn 21129: if ($numdcs > 1) {
1.191 raeburn 21130: $table = '<table>';
21131: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 21132: my $rem = $i%($numinrow);
21133: if ($rem == 0) {
21134: if ($i > 0) {
1.191 raeburn 21135: $table .= '</tr>';
1.125 raeburn 21136: }
1.191 raeburn 21137: $table .= '<tr>';
21138: $rows ++;
1.125 raeburn 21139: }
1.191 raeburn 21140: my $check = '';
21141: if ($inputtype eq 'radio') {
21142: if (keys(%currhash) == 0) {
21143: if (!$i) {
21144: $check = ' checked="checked"';
21145: }
21146: } elsif (exists($currhash{$domcoord[$i]})) {
21147: $check = ' checked="checked"';
21148: }
21149: } else {
21150: if (exists($currhash{$domcoord[$i]})) {
21151: $check = ' checked="checked"';
1.125 raeburn 21152: }
21153: }
1.191 raeburn 21154: if ($i == @domcoord - 1) {
1.125 raeburn 21155: my $colsleft = $numinrow - $rem;
21156: if ($colsleft > 1) {
1.191 raeburn 21157: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 21158: } else {
1.191 raeburn 21159: $table .= '<td class="LC_left_item">';
1.125 raeburn 21160: }
21161: } else {
1.191 raeburn 21162: $table .= '<td class="LC_left_item">';
21163: }
21164: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
21165: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
21166: $table .= '<span class="LC_nobreak"><label>'.
21167: '<input type="'.$inputtype.'" name="'.$name.'"'.
21168: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
21169: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 21170: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 21171: }
1.219 raeburn 21172: $table .= '</label></span></td>';
1.191 raeburn 21173: }
21174: $table .= '</tr></table>';
21175: } elsif ($numdcs == 1) {
1.219 raeburn 21176: my ($dcname,$dcdom) = split(':',$domcoord[0]);
21177: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 21178: if ($inputtype eq 'radio') {
1.247 raeburn 21179: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 21180: if ($user ne $dcname.':'.$dcdom) {
21181: $table .= ' ('.$dcname.':'.$dcdom.')';
21182: }
1.191 raeburn 21183: } else {
21184: my $check;
21185: if (exists($currhash{$domcoord[0]})) {
21186: $check = ' checked="checked"';
1.125 raeburn 21187: }
1.247 raeburn 21188: $table = '<span class="LC_nobreak"><label>'.
21189: '<input type="checkbox" name="'.$name.'" '.
21190: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 21191: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 21192: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 21193: }
1.220 raeburn 21194: $table .= '</label></span>';
1.191 raeburn 21195: $rows ++;
1.125 raeburn 21196: }
21197: }
1.191 raeburn 21198: return ($numdcs,$table,$rows);
1.125 raeburn 21199: }
21200:
1.137 raeburn 21201: sub usersession_titles {
21202: return &Apache::lonlocal::texthash(
21203: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
21204: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 21205: spares => 'Servers offloaded to, when busy',
1.137 raeburn 21206: version => 'LON-CAPA version requirement',
1.138 raeburn 21207: excludedomain => 'Allow all, but exclude specific domains',
21208: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 21209: primary => 'Primary (checked first)',
1.154 raeburn 21210: default => 'Default',
1.137 raeburn 21211: );
21212: }
21213:
1.152 raeburn 21214: sub id_for_thisdom {
21215: my (%servers) = @_;
21216: my %altids;
21217: foreach my $server (keys(%servers)) {
21218: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
21219: if ($serverhome ne $server) {
21220: $altids{$serverhome} = $server;
21221: }
21222: }
21223: return %altids;
21224: }
21225:
1.150 raeburn 21226: sub count_servers {
21227: my ($currbalancer,%servers) = @_;
21228: my (@spares,$numspares);
21229: foreach my $lonhost (sort(keys(%servers))) {
21230: next if ($currbalancer eq $lonhost);
21231: push(@spares,$lonhost);
21232: }
21233: if ($currbalancer) {
21234: $numspares = scalar(@spares);
21235: } else {
21236: $numspares = scalar(@spares) - 1;
21237: }
21238: return ($numspares,@spares);
21239: }
21240:
21241: sub lonbalance_targets_js {
1.171 raeburn 21242: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 21243: my $select = &mt('Select');
21244: my ($alltargets,$allishome,$allinsttypes,@alltypes);
21245: if (ref($servers) eq 'HASH') {
21246: $alltargets = join("','",sort(keys(%{$servers})));
21247: my @homedoms;
21248: foreach my $server (sort(keys(%{$servers}))) {
21249: if (&Apache::lonnet::host_domain($server) eq $dom) {
21250: push(@homedoms,'1');
21251: } else {
21252: push(@homedoms,'0');
21253: }
21254: }
21255: $allishome = join("','",@homedoms);
21256: }
21257: if (ref($types) eq 'ARRAY') {
21258: if (@{$types} > 0) {
21259: @alltypes = @{$types};
21260: }
21261: }
21262: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
21263: $allinsttypes = join("','",@alltypes);
1.342 raeburn 21264: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 21265: if (ref($settings) eq 'HASH') {
21266: %existing = %{$settings};
21267: }
21268: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 21269: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 21270: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 21271: return <<"END";
21272:
21273: <script type="text/javascript">
21274: // <![CDATA[
21275:
1.171 raeburn 21276: currBalancers = new Array('$balancers');
21277:
21278: function toggleTargets(balnum) {
21279: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
21280: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
21281: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
21282: var prevbalancer = prevhostitem.value;
21283: var baltotal = document.getElementById('loadbalancing_total').value;
21284: prevhostitem.value = balancer;
21285: if (prevbalancer != '') {
21286: var prevIdx = currBalancers.indexOf(prevbalancer);
21287: if (prevIdx != -1) {
21288: currBalancers.splice(prevIdx,1);
21289: }
21290: }
1.150 raeburn 21291: if (balancer == '') {
1.171 raeburn 21292: hideSpares(balnum);
1.150 raeburn 21293: } else {
1.171 raeburn 21294: var currIdx = currBalancers.indexOf(balancer);
21295: if (currIdx == -1) {
21296: currBalancers.push(balancer);
21297: }
1.150 raeburn 21298: var homedoms = new Array('$allishome');
1.171 raeburn 21299: var ishomedom = homedoms[lonhostitem.selectedIndex];
21300: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 21301: }
1.171 raeburn 21302: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 21303: return;
21304: }
21305:
1.171 raeburn 21306: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 21307: var alltargets = new Array('$alltargets');
21308: var insttypes = new Array('$allinsttypes');
1.151 raeburn 21309: var offloadtypes = new Array('primary','default');
21310:
1.171 raeburn 21311: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
21312: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 21313:
1.151 raeburn 21314: for (var i=0; i<offloadtypes.length; i++) {
21315: var count = 0;
21316: for (var j=0; j<alltargets.length; j++) {
21317: if (alltargets[j] != balancer) {
1.171 raeburn 21318: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
21319: item.value = alltargets[j];
21320: item.style.textAlign='left';
21321: item.style.textFace='normal';
21322: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
21323: if (currBalancers.indexOf(alltargets[j]) == -1) {
21324: item.disabled = '';
21325: } else {
21326: item.disabled = 'disabled';
21327: item.checked = false;
21328: }
1.151 raeburn 21329: count ++;
21330: }
1.150 raeburn 21331: }
21332: }
1.151 raeburn 21333: for (var k=0; k<insttypes.length; k++) {
21334: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 21335: if (ishomedom == 1) {
1.171 raeburn 21336: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
21337: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 21338: } else {
1.171 raeburn 21339: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
21340: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 21341: }
21342: } else {
1.171 raeburn 21343: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
21344: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 21345: }
1.151 raeburn 21346: if ((insttypes[k] != '_LC_external') &&
21347: ((insttypes[k] != '_LC_internetdom') ||
21348: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 21349: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
21350: item.options.length = 0;
21351: item.options[0] = new Option("","",true,true);
1.210 raeburn 21352: var idx = 0;
1.151 raeburn 21353: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 21354: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
21355: idx ++;
21356: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 21357: }
21358: }
21359: }
21360: }
21361: return;
21362: }
21363:
1.171 raeburn 21364: function hideSpares(balnum) {
1.150 raeburn 21365: var alltargets = new Array('$alltargets');
21366: var insttypes = new Array('$allinsttypes');
21367: var offloadtypes = new Array('primary','default');
21368:
1.171 raeburn 21369: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
21370: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 21371:
21372: var total = alltargets.length - 1;
21373: for (var i=0; i<offloadtypes; i++) {
21374: for (var j=0; j<total; j++) {
1.171 raeburn 21375: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
21376: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
21377: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 21378: }
1.150 raeburn 21379: }
21380: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 21381: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
21382: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 21383: if (insttypes[k] != '_LC_external') {
1.171 raeburn 21384: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
21385: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 21386: }
21387: }
21388: return;
21389: }
21390:
1.171 raeburn 21391: function checkOffloads(item,balnum,type) {
1.150 raeburn 21392: var alltargets = new Array('$alltargets');
21393: var offloadtypes = new Array('primary','default');
21394: if (item.checked) {
21395: var total = alltargets.length - 1;
21396: var other;
21397: if (type == offloadtypes[0]) {
1.151 raeburn 21398: other = offloadtypes[1];
1.150 raeburn 21399: } else {
1.151 raeburn 21400: other = offloadtypes[0];
1.150 raeburn 21401: }
21402: for (var i=0; i<total; i++) {
1.171 raeburn 21403: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 21404: if (server == item.value) {
1.171 raeburn 21405: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
21406: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 21407: }
21408: }
21409: }
21410: }
21411: return;
21412: }
21413:
1.171 raeburn 21414: function singleServerToggle(balnum,type) {
21415: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 21416: if (offloadtoSelIdx == 0) {
1.171 raeburn 21417: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
21418: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 21419:
21420: } else {
1.171 raeburn 21421: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
21422: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 21423: }
21424: return;
21425: }
21426:
1.171 raeburn 21427: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 21428: if (type == '_LC_external') {
1.171 raeburn 21429: return;
1.150 raeburn 21430: }
1.171 raeburn 21431: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 21432: for (var i=0; i<typesRules.length; i++) {
21433: if (formname.elements[typesRules[i]].checked) {
21434: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 21435: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
21436: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 21437: } else {
1.171 raeburn 21438: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
21439: }
21440: }
21441: }
21442: return;
21443: }
21444:
21445: function balancerDeleteChange(balnum) {
21446: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
21447: var baltotal = document.getElementById('loadbalancing_total').value;
21448: var addtarget;
21449: var removetarget;
21450: var action = 'delete';
21451: if (document.getElementById('loadbalancing_delete_'+balnum)) {
21452: var lonhost = hostitem.value;
21453: var currIdx = currBalancers.indexOf(lonhost);
21454: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
21455: if (currIdx != -1) {
21456: currBalancers.splice(currIdx,1);
21457: }
21458: addtarget = lonhost;
21459: } else {
21460: if (currIdx == -1) {
21461: currBalancers.push(lonhost);
21462: }
21463: removetarget = lonhost;
21464: action = 'undelete';
21465: }
21466: balancerChange(balnum,baltotal,action,addtarget,removetarget);
21467: }
21468: return;
21469: }
21470:
21471: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
21472: if (baltotal > 1) {
21473: var offloadtypes = new Array('primary','default');
21474: var alltargets = new Array('$alltargets');
21475: var insttypes = new Array('$allinsttypes');
21476: for (var i=0; i<baltotal; i++) {
21477: if (i != balnum) {
21478: for (var j=0; j<offloadtypes.length; j++) {
21479: var total = alltargets.length - 1;
21480: for (var k=0; k<total; k++) {
21481: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
21482: var server = serveritem.value;
21483: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
21484: if (server == addtarget) {
21485: serveritem.disabled = '';
21486: }
21487: }
21488: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
21489: if (server == removetarget) {
21490: serveritem.disabled = 'disabled';
21491: serveritem.checked = false;
21492: }
21493: }
21494: }
21495: }
21496: for (var j=0; j<insttypes.length; j++) {
21497: if (insttypes[j] != '_LC_external') {
21498: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
21499: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
21500: var currSel = singleserver.selectedIndex;
21501: var currVal = singleserver.options[currSel].value;
21502: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
21503: var numoptions = singleserver.options.length;
21504: var needsnew = 1;
21505: for (var k=0; k<numoptions; k++) {
21506: if (singleserver.options[k] == addtarget) {
21507: needsnew = 0;
21508: break;
21509: }
21510: }
21511: if (needsnew == 1) {
21512: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
21513: }
21514: }
21515: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
21516: singleserver.options.length = 0;
21517: if ((currVal) && (currVal != removetarget)) {
21518: singleserver.options[0] = new Option("","",false,false);
21519: } else {
21520: singleserver.options[0] = new Option("","",true,true);
21521: }
21522: var idx = 0;
21523: for (var m=0; m<alltargets.length; m++) {
21524: if (currBalancers.indexOf(alltargets[m]) == -1) {
21525: idx ++;
21526: if (currVal == alltargets[m]) {
21527: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
21528: } else {
21529: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
21530: }
21531: }
21532: }
21533: }
21534: }
21535: }
21536: }
1.150 raeburn 21537: }
21538: }
21539: }
21540: return;
21541: }
21542:
1.152 raeburn 21543: // ]]>
21544: </script>
21545:
21546: END
21547: }
21548:
1.372 raeburn 21549:
1.152 raeburn 21550: sub new_spares_js {
21551: my @sparestypes = ('primary','default');
21552: my $types = join("','",@sparestypes);
21553: my $select = &mt('Select');
21554: return <<"END";
21555:
21556: <script type="text/javascript">
21557: // <![CDATA[
21558:
21559: function updateNewSpares(formname,lonhost) {
21560: var types = new Array('$types');
21561: var include = new Array();
21562: var exclude = new Array();
21563: for (var i=0; i<types.length; i++) {
21564: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
21565: for (var j=0; j<spareboxes.length; j++) {
21566: if (formname.elements[spareboxes[j]].checked) {
21567: exclude.push(formname.elements[spareboxes[j]].value);
21568: } else {
21569: include.push(formname.elements[spareboxes[j]].value);
21570: }
21571: }
21572: }
21573: for (var i=0; i<types.length; i++) {
21574: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
21575: var selIdx = newSpare.selectedIndex;
21576: var currnew = newSpare.options[selIdx].value;
21577: var okSpares = new Array();
21578: for (var j=0; j<newSpare.options.length; j++) {
21579: var possible = newSpare.options[j].value;
21580: if (possible != '') {
21581: if (exclude.indexOf(possible) == -1) {
21582: okSpares.push(possible);
21583: } else {
21584: if (currnew == possible) {
21585: selIdx = 0;
21586: }
21587: }
21588: }
21589: }
21590: for (var k=0; k<include.length; k++) {
21591: if (okSpares.indexOf(include[k]) == -1) {
21592: okSpares.push(include[k]);
21593: }
21594: }
21595: okSpares.sort();
21596: newSpare.options.length = 0;
21597: if (selIdx == 0) {
21598: newSpare.options[0] = new Option("$select","",true,true);
21599: } else {
21600: newSpare.options[0] = new Option("$select","",false,false);
21601: }
21602: for (var m=0; m<okSpares.length; m++) {
21603: var idx = m+1;
21604: var selThis = 0;
21605: if (selIdx != 0) {
21606: if (okSpares[m] == currnew) {
21607: selThis = 1;
21608: }
21609: }
21610: if (selThis == 1) {
21611: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
21612: } else {
21613: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
21614: }
21615: }
21616: }
21617: return;
21618: }
21619:
21620: function checkNewSpares(lonhost,type) {
21621: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
21622: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 21623: if (chosen != '') {
1.152 raeburn 21624: var othertype;
21625: var othernewSpare;
21626: if (type == 'primary') {
21627: othernewSpare = document.getElementById('newspare_default_'+lonhost);
21628: }
21629: if (type == 'default') {
21630: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
21631: }
21632: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
21633: othernewSpare.selectedIndex = 0;
21634: }
21635: }
21636: return;
21637: }
21638:
21639: // ]]>
21640: </script>
21641:
21642: END
21643:
21644: }
21645:
21646: sub common_domprefs_js {
21647: return <<"END";
21648:
21649: <script type="text/javascript">
21650: // <![CDATA[
21651:
1.150 raeburn 21652: function getIndicesByName(formname,item) {
1.152 raeburn 21653: var group = new Array();
1.150 raeburn 21654: for (var i=0;i<formname.elements.length;i++) {
21655: if (formname.elements[i].name == item) {
1.152 raeburn 21656: group.push(formname.elements[i].id);
1.150 raeburn 21657: }
21658: }
1.152 raeburn 21659: return group;
1.150 raeburn 21660: }
21661:
21662: // ]]>
21663: </script>
21664:
21665: END
1.152 raeburn 21666:
1.150 raeburn 21667: }
21668:
1.165 raeburn 21669: sub recaptcha_js {
21670: my %lt = &captcha_phrases();
21671: return <<"END";
21672:
21673: <script type="text/javascript">
21674: // <![CDATA[
21675:
21676: function updateCaptcha(caller,context) {
21677: var privitem;
21678: var pubitem;
21679: var privtext;
21680: var pubtext;
1.269 raeburn 21681: var versionitem;
21682: var versiontext;
1.165 raeburn 21683: if (document.getElementById(context+'_recaptchapub')) {
21684: pubitem = document.getElementById(context+'_recaptchapub');
21685: } else {
21686: return;
21687: }
21688: if (document.getElementById(context+'_recaptchapriv')) {
21689: privitem = document.getElementById(context+'_recaptchapriv');
21690: } else {
21691: return;
21692: }
21693: if (document.getElementById(context+'_recaptchapubtxt')) {
21694: pubtext = document.getElementById(context+'_recaptchapubtxt');
21695: } else {
21696: return;
21697: }
21698: if (document.getElementById(context+'_recaptchaprivtxt')) {
21699: privtext = document.getElementById(context+'_recaptchaprivtxt');
21700: } else {
21701: return;
21702: }
1.269 raeburn 21703: if (document.getElementById(context+'_recaptchaversion')) {
21704: versionitem = document.getElementById(context+'_recaptchaversion');
21705: } else {
21706: return;
21707: }
21708: if (document.getElementById(context+'_recaptchavertxt')) {
21709: versiontext = document.getElementById(context+'_recaptchavertxt');
21710: } else {
21711: return;
21712: }
1.165 raeburn 21713: if (caller.checked) {
21714: if (caller.value == 'recaptcha') {
21715: pubitem.type = 'text';
21716: privitem.type = 'text';
21717: pubitem.size = '40';
21718: privitem.size = '40';
21719: pubtext.innerHTML = "$lt{'pub'}";
21720: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 21721: versionitem.type = 'text';
21722: versionitem.size = '3';
1.289 raeburn 21723: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 21724: } else {
21725: pubitem.type = 'hidden';
21726: privitem.type = 'hidden';
1.269 raeburn 21727: versionitem.type = 'hidden';
1.165 raeburn 21728: pubtext.innerHTML = '';
21729: privtext.innerHTML = '';
1.269 raeburn 21730: versiontext.innerHTML = '';
1.165 raeburn 21731: }
21732: }
21733: return;
21734: }
21735:
21736: // ]]>
21737: </script>
21738:
21739: END
21740:
21741: }
21742:
1.236 raeburn 21743: sub toggle_display_js {
1.192 raeburn 21744: return <<"END";
21745:
21746: <script type="text/javascript">
21747: // <![CDATA[
21748:
1.236 raeburn 21749: function toggleDisplay(domForm,caller) {
21750: if (document.getElementById(caller)) {
21751: var divitem = document.getElementById(caller);
21752: var optionsElement = domForm.coursecredits;
1.264 raeburn 21753: var checkval = 1;
21754: var dispval = 'block';
1.303 raeburn 21755: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 21756: if (caller == 'emailoptions') {
1.372 raeburn 21757: optionsElement = domForm.cancreate_email;
1.236 raeburn 21758: }
1.257 raeburn 21759: if (caller == 'studentsubmission') {
21760: optionsElement = domForm.postsubmit;
21761: }
1.264 raeburn 21762: if (caller == 'cloneinstcode') {
21763: optionsElement = domForm.canclone;
21764: checkval = 'instcode';
21765: }
1.303 raeburn 21766: if (selfcreateRegExp.test(caller)) {
21767: optionsElement = domForm.elements[caller];
21768: checkval = 'other';
21769: dispval = 'inline'
21770: }
1.236 raeburn 21771: if (optionsElement.length) {
1.192 raeburn 21772: var currval;
1.236 raeburn 21773: for (var i=0; i<optionsElement.length; i++) {
21774: if (optionsElement[i].checked) {
21775: currval = optionsElement[i].value;
1.192 raeburn 21776: }
21777: }
1.264 raeburn 21778: if (currval == checkval) {
21779: divitem.style.display = dispval;
1.192 raeburn 21780: } else {
1.236 raeburn 21781: divitem.style.display = 'none';
1.192 raeburn 21782: }
21783: }
21784: }
21785: return;
21786: }
21787:
21788: // ]]>
21789: </script>
21790:
21791: END
21792:
21793: }
21794:
1.165 raeburn 21795: sub captcha_phrases {
21796: return &Apache::lonlocal::texthash (
21797: priv => 'Private key',
21798: pub => 'Public key',
21799: original => 'original (CAPTCHA)',
21800: recaptcha => 'successor (ReCAPTCHA)',
21801: notused => 'unused',
1.289 raeburn 21802: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 21803: );
21804: }
21805:
1.205 raeburn 21806: sub devalidate_remote_domconfs {
1.212 raeburn 21807: my ($dom,$cachekeys) = @_;
21808: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 21809: my %servers = &Apache::lonnet::internet_dom_servers($dom);
21810: my %thismachine;
21811: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 21812: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.373 raeburn 21813: 'directorysrch','passwdconf','cats','proxyalias');
1.260 raeburn 21814: if (keys(%servers)) {
1.205 raeburn 21815: foreach my $server (keys(%servers)) {
21816: next if ($thismachine{$server});
1.212 raeburn 21817: my @cached;
21818: foreach my $name (@posscached) {
21819: if ($cachekeys->{$name}) {
1.373 raeburn 21820: if ($name eq 'proxyalias') {
21821: if (ref($cachekeys->{$name}) eq 'HASH') {
21822: foreach my $key (keys(%{$cachekeys->{$name}})) {
21823: push(@cached,&escape($name).':'.&escape($key));
21824: }
21825: }
21826: } else {
21827: push(@cached,&escape($name).':'.&escape($dom));
21828: }
1.212 raeburn 21829: }
21830: }
21831: if (@cached) {
21832: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
21833: }
1.205 raeburn 21834: }
21835: }
21836: return;
21837: }
21838:
1.3 raeburn 21839: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>