Annotation of loncom/interface/domainprefs.pm, revision 1.321
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.321 ! raeburn 4: # $Id: domainprefs.pm,v 1.320 2017/11/30 15:15:14 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.271 raeburn 107: (official, unofficial, community, textbook, and placement).
108: In each case the radio buttons allow the selection of one of four values:
1.101 raeburn 109:
1.104 raeburn 110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
1.104 raeburn 121: approval
1.101 raeburn 122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
1.143 raeburn 145: - course requests will be processed automatically up to a limit of
1.101 raeburn 146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
1.1 raeburn 158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
1.43 raeburn 166: use Apache::lonmsg();
1.91 raeburn 167: use Apache::lonconfigsettings;
1.232 raeburn 168: use Apache::lonuserutils();
1.235 raeburn 169: use Apache::loncoursequeueadmin();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.275 raeburn 173: use LONCAPA::SSL;
1.9 raeburn 174: use File::Copy;
1.43 raeburn 175: use Locale::Language;
1.62 raeburn 176: use DateTime::TimeZone;
1.68 raeburn 177: use DateTime::Locale;
1.267 raeburn 178: use Time::HiRes qw( sleep );
1.1 raeburn 179:
1.155 raeburn 180: my $registered_cleanup;
181: my $modified_urls;
182:
1.1 raeburn 183: sub handler {
184: my $r=shift;
185: if ($r->header_only) {
186: &Apache::loncommon::content_type($r,'text/html');
187: $r->send_http_header;
188: return OK;
189: }
190:
1.91 raeburn 191: my $context = 'domain';
1.1 raeburn 192: my $dom = $env{'request.role.domain'};
1.5 albertel 193: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 194: if (&Apache::lonnet::allowed('mau',$dom)) {
195: &Apache::loncommon::content_type($r,'text/html');
196: $r->send_http_header;
197: } else {
198: $env{'user.error.msg'}=
199: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
200: return HTTP_NOT_ACCEPTABLE;
201: }
1.155 raeburn 202:
203: $registered_cleanup=0;
204: @{$modified_urls}=();
205:
1.1 raeburn 206: &Apache::lonhtmlcommon::clear_breadcrumbs();
207: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 208: ['phase','actions']);
1.30 raeburn 209: my $phase = 'pickactions';
1.3 raeburn 210: if ( exists($env{'form.phase'}) ) {
211: $phase = $env{'form.phase'};
212: }
1.150 raeburn 213: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 214: my %domconfig =
1.6 raeburn 215: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 216: 'quotas','autoenroll','autoupdate','autocreate',
217: 'directorysrch','usercreation','usermodification',
218: 'contacts','defaults','scantron','coursecategories',
219: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 220: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 221: 'requestauthor','selfenrollment','inststatus',
1.320 raeburn 222: 'ltitools','ssl','trust','lti'],$dom);
223: my %encconfig =
224: &Apache::lonnet::get_dom('encconfig',['ltitools','lti'],$dom);
1.297 raeburn 225: if (ref($domconfig{'ltitools'}) eq 'HASH') {
226: if (ref($encconfig{'ltitools'}) eq 'HASH') {
227: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
1.320 raeburn 228: if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
229: (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
1.297 raeburn 230: foreach my $item ('key','secret') {
231: $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
232: }
233: }
234: }
235: }
236: }
1.320 raeburn 237: if (ref($domconfig{'lti'}) eq 'HASH') {
238: if (ref($encconfig{'lti'}) eq 'HASH') {
239: foreach my $id (keys(%{$domconfig{'lti'}})) {
240: if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
241: (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
242: foreach my $item ('key','secret') {
243: $domconfig{'lti'}{$id}{$item} = $encconfig{'lti'}{$id}{$item};
244: }
245: }
246: }
247: }
248: }
1.43 raeburn 249: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 250: 'autoupdate','autocreate','directorysrch','contacts',
1.224 raeburn 251: 'usercreation','selfcreation','usermodification','scantron',
1.163 raeburn 252: 'requestcourses','requestauthor','coursecategories',
1.267 raeburn 253: 'serverstatuses','helpsettings','coursedefaults',
1.320 raeburn 254: 'ltitools','selfenrollment','usersessions','ssl','trust','lti');
1.171 raeburn 255: my %existing;
256: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
257: %existing = %{$domconfig{'loadbalancing'}};
258: }
259: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 260: push(@prefs_order,'loadbalancing');
261: }
1.30 raeburn 262: my %prefs = (
263: 'rolecolors' =>
264: { text => 'Default color schemes',
1.67 raeburn 265: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 266: header => [{col1 => 'Student Settings',
267: col2 => '',},
268: {col1 => 'Coordinator Settings',
269: col2 => '',},
270: {col1 => 'Author Settings',
271: col2 => '',},
272: {col1 => 'Administrator Settings',
273: col2 => '',}],
1.230 raeburn 274: print => \&print_rolecolors,
275: modify => \&modify_rolecolors,
1.30 raeburn 276: },
1.110 raeburn 277: 'login' =>
1.30 raeburn 278: { text => 'Log-in page options',
1.67 raeburn 279: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 280: header => [{col1 => 'Log-in Page Items',
281: col2 => '',},
282: {col1 => 'Log-in Help',
1.256 raeburn 283: col2 => 'Value'},
284: {col1 => 'Custom HTML in document head',
1.168 raeburn 285: col2 => 'Value'}],
1.230 raeburn 286: print => \&print_login,
287: modify => \&modify_login,
1.30 raeburn 288: },
1.43 raeburn 289: 'defaults' =>
1.236 raeburn 290: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 291: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 292: header => [{col1 => 'Setting',
1.236 raeburn 293: col2 => 'Value'},
1.294 raeburn 294: {col1 => 'Internal Authentication',
295: col2 => 'Value'},
1.236 raeburn 296: {col1 => 'Institutional user types',
1.305 raeburn 297: col2 => 'Name displayed'}],
1.230 raeburn 298: print => \&print_defaults,
299: modify => \&modify_defaults,
1.43 raeburn 300: },
1.30 raeburn 301: 'quotas' =>
1.197 raeburn 302: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 303: help => 'Domain_Configuration_Quotas',
1.77 raeburn 304: header => [{col1 => 'User affiliation',
1.72 raeburn 305: col2 => 'Available tools',
1.213 raeburn 306: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 307: print => \&print_quotas,
308: modify => \&modify_quotas,
1.30 raeburn 309: },
310: 'autoenroll' =>
311: { text => 'Auto-enrollment settings',
1.67 raeburn 312: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 313: header => [{col1 => 'Configuration setting',
314: col2 => 'Value(s)'}],
1.230 raeburn 315: print => \&print_autoenroll,
316: modify => \&modify_autoenroll,
1.30 raeburn 317: },
318: 'autoupdate' =>
319: { text => 'Auto-update settings',
1.67 raeburn 320: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 321: header => [{col1 => 'Setting',
322: col2 => 'Value',},
1.131 raeburn 323: {col1 => 'Setting',
324: col2 => 'Affiliation'},
1.43 raeburn 325: {col1 => 'User population',
1.227 bisitz 326: col2 => 'Updatable user data'}],
1.230 raeburn 327: print => \&print_autoupdate,
328: modify => \&modify_autoupdate,
1.30 raeburn 329: },
1.125 raeburn 330: 'autocreate' =>
331: { text => 'Auto-course creation settings',
332: help => 'Domain_Configuration_Auto_Creation',
333: header => [{col1 => 'Configuration Setting',
334: col2 => 'Value',}],
1.230 raeburn 335: print => \&print_autocreate,
336: modify => \&modify_autocreate,
1.125 raeburn 337: },
1.30 raeburn 338: 'directorysrch' =>
1.277 raeburn 339: { text => 'Directory searches',
1.67 raeburn 340: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 341: header => [{col1 => 'Institutional Directory Setting',
342: col2 => 'Value',},
343: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 344: col2 => 'Value',}],
1.230 raeburn 345: print => \&print_directorysrch,
346: modify => \&modify_directorysrch,
1.30 raeburn 347: },
348: 'contacts' =>
1.286 raeburn 349: { text => 'E-mail addresses and helpform',
1.67 raeburn 350: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 351: header => [{col1 => 'Default e-mail addresses',
352: col2 => 'Value',},
353: {col1 => 'Recipient(s) for notifications',
354: col2 => 'Value',},
355: {col1 => 'Ask helpdesk form settings',
356: col2 => 'Value',},],
1.230 raeburn 357: print => \&print_contacts,
358: modify => \&modify_contacts,
1.30 raeburn 359: },
360: 'usercreation' =>
361: { text => 'User creation',
1.67 raeburn 362: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 363: header => [{col1 => 'Format rule type',
364: col2 => 'Format rules in force'},
1.34 raeburn 365: {col1 => 'User account creation',
366: col2 => 'Usernames which may be created',},
1.30 raeburn 367: {col1 => 'Context',
1.43 raeburn 368: col2 => 'Assignable authentication types'}],
1.230 raeburn 369: print => \&print_usercreation,
370: modify => \&modify_usercreation,
1.30 raeburn 371: },
1.224 raeburn 372: 'selfcreation' =>
373: { text => 'Users self-creating accounts',
374: help => 'Domain_Configuration_Self_Creation',
375: header => [{col1 => 'Self-creation with institutional username',
376: col2 => 'Enabled?'},
377: {col1 => 'Institutional user type (login/SSO self-creation)',
378: col2 => 'Information user can enter'},
1.303 raeburn 379: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 380: col2 => 'Settings'}],
1.230 raeburn 381: print => \&print_selfcreation,
382: modify => \&modify_selfcreation,
1.224 raeburn 383: },
1.69 raeburn 384: 'usermodification' =>
1.33 raeburn 385: { text => 'User modification',
1.67 raeburn 386: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 387: header => [{col1 => 'Target user has role',
1.227 bisitz 388: col2 => 'User information updatable in author context'},
1.33 raeburn 389: {col1 => 'Target user has role',
1.227 bisitz 390: col2 => 'User information updatable in course context'}],
1.230 raeburn 391: print => \&print_usermodification,
392: modify => \&modify_usermodification,
1.33 raeburn 393: },
1.69 raeburn 394: 'scantron' =>
1.95 www 395: { text => 'Bubblesheet format file',
1.67 raeburn 396: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 397: header => [ {col1 => 'Item',
398: col2 => '',
399: }],
1.230 raeburn 400: print => \&print_scantron,
401: modify => \&modify_scantron,
1.46 raeburn 402: },
1.86 raeburn 403: 'requestcourses' =>
404: {text => 'Request creation of courses',
405: help => 'Domain_Configuration_Request_Courses',
406: header => [{col1 => 'User affiliation',
1.102 raeburn 407: col2 => 'Availability/Processing of requests',},
408: {col1 => 'Setting',
1.216 raeburn 409: col2 => 'Value'},
410: {col1 => 'Available textbooks',
1.235 raeburn 411: col2 => ''},
1.242 raeburn 412: {col1 => 'Available templates',
413: col2 => ''},
1.235 raeburn 414: {col1 => 'Validation (not official courses)',
415: col2 => 'Value'},],
1.230 raeburn 416: print => \&print_quotas,
417: modify => \&modify_quotas,
1.86 raeburn 418: },
1.163 raeburn 419: 'requestauthor' =>
1.223 bisitz 420: {text => 'Request Authoring Space',
1.163 raeburn 421: help => 'Domain_Configuration_Request_Author',
422: header => [{col1 => 'User affiliation',
423: col2 => 'Availability/Processing of requests',},
424: {col1 => 'Setting',
425: col2 => 'Value'}],
1.230 raeburn 426: print => \&print_quotas,
427: modify => \&modify_quotas,
1.163 raeburn 428: },
1.69 raeburn 429: 'coursecategories' =>
1.120 raeburn 430: { text => 'Cataloging of courses/communities',
1.67 raeburn 431: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 432: header => [{col1 => 'Catalog type/availability',
433: col2 => '',},
434: {col1 => 'Category settings for standard catalog',
1.57 raeburn 435: col2 => '',},
436: {col1 => 'Categories',
437: col2 => '',
438: }],
1.230 raeburn 439: print => \&print_coursecategories,
440: modify => \&modify_coursecategories,
1.69 raeburn 441: },
442: 'serverstatuses' =>
1.77 raeburn 443: {text => 'Access to server status pages',
1.69 raeburn 444: help => 'Domain_Configuration_Server_Status',
445: header => [{col1 => 'Status Page',
446: col2 => 'Other named users',
447: col3 => 'Specific IPs',
448: }],
1.230 raeburn 449: print => \&print_serverstatuses,
450: modify => \&modify_serverstatuses,
1.69 raeburn 451: },
1.118 jms 452: 'helpsettings' =>
1.282 raeburn 453: {text => 'Support settings',
1.118 jms 454: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 455: header => [{col1 => 'Help Page Settings (logged-in users)',
456: col2 => 'Value'},
457: {col1 => 'Helpdesk Roles',
458: col2 => 'Settings'},],
1.230 raeburn 459: print => \&print_helpsettings,
460: modify => \&modify_helpsettings,
1.118 jms 461: },
1.121 raeburn 462: 'coursedefaults' =>
463: {text => 'Course/Community defaults',
464: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 465: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
466: col2 => 'Value',},
467: {col1 => 'Defaults which can be overridden for each course by a DC',
468: col2 => 'Value',},],
1.230 raeburn 469: print => \&print_coursedefaults,
470: modify => \&modify_coursedefaults,
1.121 raeburn 471: },
1.231 raeburn 472: 'selfenrollment' =>
473: {text => 'Self-enrollment in Course/Community',
474: help => 'Domain_Configuration_Selfenrollment',
475: header => [{col1 => 'Configuration Rights',
476: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
477: {col1 => 'Defaults',
478: col2 => 'Value'},
479: {col1 => 'Self-enrollment validation (optional)',
480: col2 => 'Value'},],
481: print => \&print_selfenrollment,
482: modify => \&modify_selfenrollment,
483: },
1.120 raeburn 484: 'privacy' =>
485: {text => 'User Privacy',
486: help => 'Domain_Configuration_User_Privacy',
487: header => [{col1 => 'Setting',
488: col2 => 'Value',}],
1.230 raeburn 489: print => \&print_privacy,
490: modify => \&modify_privacy,
1.120 raeburn 491: },
1.141 raeburn 492: 'usersessions' =>
1.145 raeburn 493: {text => 'User session hosting/offloading',
1.137 raeburn 494: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 495: header => [{col1 => 'Domain server',
496: col2 => 'Servers to offload sessions to when busy'},
497: {col1 => 'Hosting of users from other domains',
1.137 raeburn 498: col2 => 'Rules'},
499: {col1 => "Hosting domain's own users elsewhere",
500: col2 => 'Rules'}],
1.230 raeburn 501: print => \&print_usersessions,
502: modify => \&modify_usersessions,
1.137 raeburn 503: },
1.279 raeburn 504: 'loadbalancing' =>
1.185 raeburn 505: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 506: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 507: header => [{col1 => 'Balancers',
1.150 raeburn 508: col2 => 'Default destinations',
1.183 bisitz 509: col3 => 'User affiliation',
1.150 raeburn 510: col4 => 'Overrides'},
511: ],
1.230 raeburn 512: print => \&print_loadbalancing,
513: modify => \&modify_loadbalancing,
1.150 raeburn 514: },
1.279 raeburn 515: 'ltitools' =>
1.267 raeburn 516: {text => 'External Tools (LTI)',
1.296 raeburn 517: help => 'Domain_Configuration_LTI_Tools',
1.267 raeburn 518: header => [{col1 => 'Setting',
519: col2 => 'Value',}],
520: print => \&print_ltitools,
521: modify => \&modify_ltitools,
522: },
1.279 raeburn 523: 'ssl' =>
1.275 raeburn 524: {text => 'LON-CAPA Network (SSL)',
525: help => 'Domain_Configuration_Network_SSL',
526: header => [{col1 => 'Server',
527: col2 => 'Certificate Status'},
528: {col1 => 'Connections to other servers',
529: col2 => 'Rules'},
1.293 raeburn 530: {col1 => 'Connections from other servers',
531: col2 => 'Rules'},
1.275 raeburn 532: {col1 => "Replicating domain's published content",
533: col2 => 'Rules'}],
534: print => \&print_ssl,
535: modify => \&modify_ssl,
536: },
1.279 raeburn 537: 'trust' =>
538: {text => 'Trust Settings',
539: help => 'Domain_Configuration_Trust',
540: header => [{col1 => "Access to this domain's content by others",
541: col2 => 'Rules'},
542: {col1 => "Access to other domain's content by this domain",
543: col2 => 'Rules'},
544: {col1 => "Enrollment in this domain's courses by others",
545: col2 => 'Rules',},
546: {col1 => "Co-author roles in this domain for others",
547: col2 => 'Rules',},
548: {col1 => "Co-author roles for this domain's users elsewhere",
549: col2 => 'Rules',},
550: {col1 => "Domain roles in this domain assignable to others",
551: col2 => 'Rules'},
552: {col1 => "Course catalog for this domain displayed elsewhere",
553: col2 => 'Rules'},
554: {col1 => "Requests for creation of courses in this domain by others",
555: col2 => 'Rules'},
556: {col1 => "Users in other domains can send messages to this domain",
557: col2 => 'Rules'},],
558: print => \&print_trust,
559: modify => \&modify_trust,
560: },
1.320 raeburn 561: 'lti' =>
562: {text => 'LTI Provider',
563: help => 'Domain_Configuration_LTI_Provider',
564: header => [{col1 => 'Setting',
565: col2 => 'Value',}],
566: print => \&print_lti,
567: modify => \&modify_lti,
568: },
1.3 raeburn 569: );
1.110 raeburn 570: if (keys(%servers) > 1) {
571: $prefs{'login'} = { text => 'Log-in page options',
572: help => 'Domain_Configuration_Login_Page',
573: header => [{col1 => 'Log-in Service',
574: col2 => 'Server Setting',},
575: {col1 => 'Log-in Page Items',
1.168 raeburn 576: col2 => ''},
577: {col1 => 'Log-in Help',
1.256 raeburn 578: col2 => 'Value'},
579: {col1 => 'Custom HTML in document head',
1.168 raeburn 580: col2 => 'Value'}],
1.230 raeburn 581: print => \&print_login,
582: modify => \&modify_login,
1.110 raeburn 583: };
584: }
1.174 foxr 585:
1.6 raeburn 586: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 587: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 588: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 589: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 590: text=>"Settings to display/modify"});
1.9 raeburn 591: my $confname = $dom.'-domainconfig';
1.174 foxr 592:
1.3 raeburn 593: if ($phase eq 'process') {
1.212 raeburn 594: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
595: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 596: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 597: $r->rflush();
1.212 raeburn 598: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 599: }
1.30 raeburn 600: } elsif ($phase eq 'display') {
1.192 raeburn 601: my $js = &recaptcha_js().
1.236 raeburn 602: &toggle_display_js();
1.171 raeburn 603: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 604: my ($othertitle,$usertypes,$types) =
605: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 606: $js .= &lonbalance_targets_js($dom,$types,\%servers,
607: $domconfig{'loadbalancing'}).
1.170 raeburn 608: &new_spares_js().
609: &common_domprefs_js().
610: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 611: }
1.216 raeburn 612: if (grep(/^requestcourses$/,@actions)) {
613: my $javascript_validations;
614: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
615: $js .= <<END;
616: <script type="text/javascript">
617: $javascript_validations
618: </script>
619: $coursebrowserjs
620: END
621: }
1.305 raeburn 622: if (grep(/^selfcreation$/,@actions)) {
623: $js .= &selfcreate_javascript();
624: }
1.286 raeburn 625: if (grep(/^contacts$/,@actions)) {
626: $js .= &contacts_javascript();
627: }
1.150 raeburn 628: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 629: } else {
1.180 raeburn 630: # check if domconfig user exists for the domain.
631: my $servadm = $r->dir_config('lonAdmEMail');
632: my ($configuserok,$author_ok,$switchserver) =
633: &config_check($dom,$confname,$servadm);
634: unless ($configuserok eq 'ok') {
1.181 raeburn 635: &Apache::lonconfigsettings::print_header($r,$phase,$context);
636: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 637: $confname).
1.181 raeburn 638: '<br />'
639: );
1.180 raeburn 640: if ($switchserver) {
1.181 raeburn 641: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
642: '<br />'.
643: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
644: '<br />'.
645: &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).
646: '<br />'.
647: &mt('To do that now, use the following link: [_1]',$switchserver)
648: );
649: } else {
650: $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.').
651: '<br />'.
652: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
653: );
1.180 raeburn 654: }
655: $r->print(&Apache::loncommon::end_page());
656: return OK;
657: }
1.21 raeburn 658: if (keys(%domconfig) == 0) {
659: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 660: my @ids=&Apache::lonnet::current_machine_ids();
661: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 662: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 663: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 664: my $custom_img_count = 0;
665: foreach my $img (@loginimages) {
666: if ($designhash{$dom.'.login.'.$img} ne '') {
667: $custom_img_count ++;
668: }
669: }
670: foreach my $role (@roles) {
671: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
672: $custom_img_count ++;
673: }
674: }
675: if ($custom_img_count > 0) {
1.94 raeburn 676: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 677: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 678: $r->print(
679: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
680: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
681: &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 />'.
682: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
683: if ($switch_server) {
1.30 raeburn 684: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 685: }
1.91 raeburn 686: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 687: return OK;
688: }
689: }
690: }
1.91 raeburn 691: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 692: }
693: return OK;
694: }
695:
696: sub process_changes {
1.205 raeburn 697: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 698: my %domconfig;
699: if (ref($values) eq 'HASH') {
700: %domconfig = %{$values};
701: }
1.3 raeburn 702: my $output;
703: if ($action eq 'login') {
1.205 raeburn 704: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 705: } elsif ($action eq 'rolecolors') {
1.9 raeburn 706: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 707: $lastactref,%domconfig);
1.3 raeburn 708: } elsif ($action eq 'quotas') {
1.216 raeburn 709: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 710: } elsif ($action eq 'autoenroll') {
1.205 raeburn 711: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 712: } elsif ($action eq 'autoupdate') {
713: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 714: } elsif ($action eq 'autocreate') {
715: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 716: } elsif ($action eq 'directorysrch') {
1.295 raeburn 717: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 718: } elsif ($action eq 'usercreation') {
1.28 raeburn 719: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 720: } elsif ($action eq 'selfcreation') {
1.305 raeburn 721: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 722: } elsif ($action eq 'usermodification') {
723: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 724: } elsif ($action eq 'contacts') {
1.205 raeburn 725: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 726: } elsif ($action eq 'defaults') {
1.212 raeburn 727: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 728: } elsif ($action eq 'scantron') {
1.205 raeburn 729: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 730: } elsif ($action eq 'coursecategories') {
1.239 raeburn 731: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 732: } elsif ($action eq 'serverstatuses') {
733: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 734: } elsif ($action eq 'requestcourses') {
1.216 raeburn 735: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 736: } elsif ($action eq 'requestauthor') {
1.216 raeburn 737: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 738: } elsif ($action eq 'helpsettings') {
1.285 raeburn 739: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 740: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 741: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 742: } elsif ($action eq 'selfenrollment') {
743: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 744: } elsif ($action eq 'usersessions') {
1.212 raeburn 745: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 746: } elsif ($action eq 'loadbalancing') {
747: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 748: } elsif ($action eq 'ltitools') {
749: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 750: } elsif ($action eq 'ssl') {
751: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 752: } elsif ($action eq 'trust') {
753: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 754: } elsif ($action eq 'lti') {
755: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 756: }
757: return $output;
758: }
759:
760: sub print_config_box {
1.9 raeburn 761: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 762: my $rowtotal = 0;
1.49 raeburn 763: my $output;
764: if ($action eq 'coursecategories') {
765: $output = &coursecategories_javascript($settings);
1.236 raeburn 766: } elsif ($action eq 'defaults') {
767: $output = &defaults_javascript($settings);
1.282 raeburn 768: } elsif ($action eq 'helpsettings') {
769: my (%privs,%levelscurrent);
770: my %full=();
771: my %levels=(
772: course => {},
773: domain => {},
774: system => {},
775: );
776: my $context = 'domain';
777: my $crstype = 'Course';
778: my $formname = 'display';
779: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
780: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
781: $output =
782: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
783: \@templateroles);
1.91 raeburn 784: }
1.236 raeburn 785: $output .=
1.30 raeburn 786: '<table class="LC_nested_outer">
1.3 raeburn 787: <tr>
1.306 raeburn 788: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 789: &mt($item->{text}).' '.
790: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
791: '</tr>';
1.30 raeburn 792: $rowtotal ++;
1.110 raeburn 793: my $numheaders = 1;
794: if (ref($item->{'header'}) eq 'ARRAY') {
795: $numheaders = scalar(@{$item->{'header'}});
796: }
797: if ($numheaders > 1) {
1.64 raeburn 798: my $colspan = '';
1.145 raeburn 799: my $rightcolspan = '';
1.238 raeburn 800: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 801: ($action eq 'directorysrch') ||
1.256 raeburn 802: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 803: $colspan = ' colspan="2"';
804: }
1.145 raeburn 805: if ($action eq 'usersessions') {
806: $rightcolspan = ' colspan="3"';
807: }
1.30 raeburn 808: $output .= '
1.3 raeburn 809: <tr>
810: <td>
811: <table class="LC_nested">
812: <tr class="LC_info_row">
1.59 bisitz 813: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 814: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 815: </tr>';
1.69 raeburn 816: $rowtotal ++;
1.230 raeburn 817: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 818: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 819: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 820: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
821: ($action eq 'contacts')) {
1.230 raeburn 822: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 823: } elsif ($action eq 'coursecategories') {
1.230 raeburn 824: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 825: } elsif ($action eq 'login') {
1.256 raeburn 826: if ($numheaders == 4) {
1.168 raeburn 827: $colspan = ' colspan="2"';
828: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
829: } else {
830: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
831: }
1.230 raeburn 832: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 833: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 834: } elsif ($action eq 'rolecolors') {
1.30 raeburn 835: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 836: }
1.30 raeburn 837: $output .= '
1.6 raeburn 838: </table>
839: </td>
840: </tr>
841: <tr>
842: <td>
843: <table class="LC_nested">
844: <tr class="LC_info_row">
1.230 raeburn 845: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 846: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 847: </tr>';
848: $rowtotal ++;
1.230 raeburn 849: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
850: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 851: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.294 raeburn 852: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults')) {
1.238 raeburn 853: if ($action eq 'coursecategories') {
854: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
855: $colspan = ' colspan="2"';
1.279 raeburn 856: } elsif ($action eq 'trust') {
857: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.238 raeburn 858: } else {
859: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
860: }
1.279 raeburn 861: if ($action eq 'trust') {
862: $output .= '
863: </table>
864: </td>
865: </tr>';
866: my @trusthdrs = qw(2 3 4 5 6 7);
867: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
868: for (my $i=0; $i<@trusthdrs; $i++) {
869: $output .= '
870: <tr>
871: <td>
872: <table class="LC_nested">
873: <tr class="LC_info_row">
874: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
875: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
876: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
877: </table>
878: </td>
879: </tr>';
880: }
881: $output .= '
882: <tr>
883: <td>
884: <table class="LC_nested">
885: <tr class="LC_info_row">
886: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
887: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
888: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
889: } else {
890: $output .= '
1.63 raeburn 891: </table>
892: </td>
893: </tr>
894: <tr>
895: <td>
896: <table class="LC_nested">
897: <tr class="LC_info_row">
898: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 899: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 900: </tr>'."\n";
1.279 raeburn 901: if ($action eq 'coursecategories') {
902: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
903: } else {
904: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
905: }
1.238 raeburn 906: }
1.63 raeburn 907: $rowtotal ++;
1.236 raeburn 908: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282 raeburn 909: ($action eq 'defaults') || ($action eq 'directorysrch') ||
910: ($action eq 'helpsettings')) {
1.230 raeburn 911: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.293 raeburn 912: } elsif ($action eq 'ssl') {
913: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
914: </table>
915: </td>
916: </tr>
917: <tr>
918: <td>
919: <table class="LC_nested">
920: <tr class="LC_info_row">
921: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
922: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
923: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
924: </table>
925: </td>
926: </tr>
927: <tr>
928: <td>
929: <table class="LC_nested">
930: <tr class="LC_info_row">
931: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
932: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
933: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 934: } elsif ($action eq 'login') {
1.256 raeburn 935: if ($numheaders == 4) {
1.168 raeburn 936: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
937: </table>
938: </td>
939: </tr>
940: <tr>
941: <td>
942: <table class="LC_nested">
943: <tr class="LC_info_row">
944: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 945: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 946: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
947: $rowtotal ++;
948: } else {
949: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
950: }
1.256 raeburn 951: $output .= '
952: </table>
953: </td>
954: </tr>
955: <tr>
956: <td>
957: <table class="LC_nested">
958: <tr class="LC_info_row">';
959: if ($numheaders == 4) {
960: $output .= '
961: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
962: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
963: </tr>';
964: } else {
965: $output .= '
966: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
967: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
968: </tr>';
969: }
970: $rowtotal ++;
971: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 972: } elsif ($action eq 'requestcourses') {
1.247 raeburn 973: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
974: $rowtotal ++;
975: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 976: </table>
977: </td>
978: </tr>
979: <tr>
980: <td>
981: <table class="LC_nested">
982: <tr class="LC_info_row">
983: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
984: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 985: &textbookcourses_javascript($settings).
986: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
987: </table>
988: </td>
989: </tr>
990: <tr>
991: <td>
992: <table class="LC_nested">
993: <tr class="LC_info_row">
994: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
995: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
996: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 997: </table>
998: </td>
999: </tr>
1000: <tr>
1001: <td>
1002: <table class="LC_nested">
1003: <tr class="LC_info_row">
1.306 raeburn 1004: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1005: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1006: </tr>'.
1007: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1008: } elsif ($action eq 'requestauthor') {
1009: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1010: $rowtotal ++;
1.122 jms 1011: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1012: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1013: </table>
1014: </td>
1015: </tr>
1016: <tr>
1017: <td>
1018: <table class="LC_nested">
1019: <tr class="LC_info_row">
1.306 raeburn 1020: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1021: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1022: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1023: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1024: </tr>'.
1.30 raeburn 1025: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1026: </table>
1027: </td>
1028: </tr>
1029: <tr>
1030: <td>
1031: <table class="LC_nested">
1032: <tr class="LC_info_row">
1.59 bisitz 1033: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1034: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1035: </tr>'.
1.30 raeburn 1036: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1037: $rowtotal += 2;
1.6 raeburn 1038: }
1.3 raeburn 1039: } else {
1.30 raeburn 1040: $output .= '
1.3 raeburn 1041: <tr>
1042: <td>
1043: <table class="LC_nested">
1.30 raeburn 1044: <tr class="LC_info_row">';
1.277 raeburn 1045: if ($action eq 'login') {
1.30 raeburn 1046: $output .= '
1.59 bisitz 1047: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1048: } elsif ($action eq 'serverstatuses') {
1049: $output .= '
1.306 raeburn 1050: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1051: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1052:
1.6 raeburn 1053: } else {
1.30 raeburn 1054: $output .= '
1.306 raeburn 1055: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1056: }
1.72 raeburn 1057: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1058: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1059: &mt($item->{'header'}->[0]->{'col2'});
1060: if ($action eq 'serverstatuses') {
1061: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1062: }
1.69 raeburn 1063: } else {
1.306 raeburn 1064: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1065: &mt($item->{'header'}->[0]->{'col2'});
1066: }
1067: $output .= '</td>';
1068: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1069: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1070: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1071: &mt($item->{'header'}->[0]->{'col3'});
1072: } else {
1.306 raeburn 1073: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1074: &mt($item->{'header'}->[0]->{'col3'});
1075: }
1.69 raeburn 1076: if ($action eq 'serverstatuses') {
1077: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1078: }
1079: $output .= '</td>';
1.6 raeburn 1080: }
1.150 raeburn 1081: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1082: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1083: &mt($item->{'header'}->[0]->{'col4'});
1084: }
1.69 raeburn 1085: $output .= '</tr>';
1.48 raeburn 1086: $rowtotal ++;
1.168 raeburn 1087: if ($action eq 'quotas') {
1.86 raeburn 1088: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1089: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1090: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.320 raeburn 1091: ($action eq 'ltitools') || ($action eq 'lti')) {
1.230 raeburn 1092: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 1093: } elsif ($action eq 'scantron') {
1094: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.121 raeburn 1095: }
1.3 raeburn 1096: }
1.30 raeburn 1097: $output .= '
1.3 raeburn 1098: </table>
1099: </td>
1100: </tr>
1.30 raeburn 1101: </table><br />';
1102: return ($output,$rowtotal);
1.1 raeburn 1103: }
1104:
1.3 raeburn 1105: sub print_login {
1.168 raeburn 1106: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 1107: my ($css_class,$datatable);
1.6 raeburn 1108: my %choices = &login_choices();
1.110 raeburn 1109:
1.168 raeburn 1110: if ($caller eq 'service') {
1.149 raeburn 1111: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1112: my $choice = $choices{'disallowlogin'};
1113: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1114: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1115: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1116: '<th>'.$choices{'server'}.'</th>'.
1117: '<th>'.$choices{'serverpath'}.'</th>'.
1118: '<th>'.$choices{'custompath'}.'</th>'.
1119: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1120: my %disallowed;
1121: if (ref($settings) eq 'HASH') {
1122: if (ref($settings->{'loginvia'}) eq 'HASH') {
1123: %disallowed = %{$settings->{'loginvia'}};
1124: }
1125: }
1126: foreach my $lonhost (sort(keys(%servers))) {
1127: my $direct = 'selected="selected"';
1.128 raeburn 1128: if (ref($disallowed{$lonhost}) eq 'HASH') {
1129: if ($disallowed{$lonhost}{'server'} ne '') {
1130: $direct = '';
1131: }
1.110 raeburn 1132: }
1.115 raeburn 1133: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1134: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1135: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1136: '</option>';
1.184 raeburn 1137: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1138: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1139: my $selected = '';
1.128 raeburn 1140: if (ref($disallowed{$lonhost}) eq 'HASH') {
1141: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1142: $selected = 'selected="selected"';
1143: }
1.110 raeburn 1144: }
1145: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1146: $servers{$hostid}.'</option>';
1147: }
1.128 raeburn 1148: $datatable .= '</select></td>'.
1149: '<td><select name="'.$lonhost.'_serverpath">';
1150: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1151: my $pathname = $path;
1152: if ($path eq 'custom') {
1153: $pathname = &mt('Custom Path').' ->';
1154: }
1155: my $selected = '';
1156: if (ref($disallowed{$lonhost}) eq 'HASH') {
1157: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1158: $selected = 'selected="selected"';
1159: }
1160: } elsif ($path eq '') {
1161: $selected = 'selected="selected"';
1162: }
1163: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1164: }
1165: $datatable .= '</select></td>';
1166: my ($custom,$exempt);
1167: if (ref($disallowed{$lonhost}) eq 'HASH') {
1168: $custom = $disallowed{$lonhost}{'custompath'};
1169: $exempt = $disallowed{$lonhost}{'exempt'};
1170: }
1171: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1172: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1173: '</tr>';
1.110 raeburn 1174: }
1175: $datatable .= '</table></td></tr>';
1176: return $datatable;
1.168 raeburn 1177: } elsif ($caller eq 'page') {
1178: my %defaultchecked = (
1179: 'coursecatalog' => 'on',
1.188 raeburn 1180: 'helpdesk' => 'on',
1.168 raeburn 1181: 'adminmail' => 'off',
1182: 'newuser' => 'off',
1183: );
1.188 raeburn 1184: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1185: my (%checkedon,%checkedoff);
1.42 raeburn 1186: foreach my $item (@toggles) {
1.168 raeburn 1187: if ($defaultchecked{$item} eq 'on') {
1188: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1189: $checkedoff{$item} = ' ';
1.168 raeburn 1190: } elsif ($defaultchecked{$item} eq 'off') {
1191: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1192: $checkedon{$item} = ' ';
1193: }
1.1 raeburn 1194: }
1.168 raeburn 1195: my @images = ('img','logo','domlogo','login');
1196: my @logintext = ('textcol','bgcol');
1197: my @bgs = ('pgbg','mainbg','sidebg');
1198: my @links = ('link','alink','vlink');
1199: my %designhash = &Apache::loncommon::get_domainconf($dom);
1200: my %defaultdesign = %Apache::loncommon::defaultdesign;
1201: my (%is_custom,%designs);
1202: my %defaults = (
1203: font => $defaultdesign{'login.font'},
1204: );
1.6 raeburn 1205: foreach my $item (@images) {
1.168 raeburn 1206: $defaults{$item} = $defaultdesign{'login.'.$item};
1207: $defaults{'showlogo'}{$item} = 1;
1208: }
1209: foreach my $item (@bgs) {
1210: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1211: }
1.41 raeburn 1212: foreach my $item (@logintext) {
1.168 raeburn 1213: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1214: }
1.168 raeburn 1215: foreach my $item (@links) {
1216: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1217: }
1.168 raeburn 1218: if (ref($settings) eq 'HASH') {
1219: foreach my $item (@toggles) {
1220: if ($settings->{$item} eq '1') {
1221: $checkedon{$item} = ' checked="checked" ';
1222: $checkedoff{$item} = ' ';
1223: } elsif ($settings->{$item} eq '0') {
1224: $checkedoff{$item} = ' checked="checked" ';
1225: $checkedon{$item} = ' ';
1226: }
1227: }
1228: foreach my $item (@images) {
1229: if (defined($settings->{$item})) {
1230: $designs{$item} = $settings->{$item};
1231: $is_custom{$item} = 1;
1232: }
1233: if (defined($settings->{'showlogo'}{$item})) {
1234: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1235: }
1236: }
1237: foreach my $item (@logintext) {
1238: if ($settings->{$item} ne '') {
1239: $designs{'logintext'}{$item} = $settings->{$item};
1240: $is_custom{$item} = 1;
1241: }
1242: }
1243: if ($settings->{'font'} ne '') {
1244: $designs{'font'} = $settings->{'font'};
1245: $is_custom{'font'} = 1;
1246: }
1247: foreach my $item (@bgs) {
1248: if ($settings->{$item} ne '') {
1249: $designs{'bgs'}{$item} = $settings->{$item};
1250: $is_custom{$item} = 1;
1251: }
1252: }
1253: foreach my $item (@links) {
1254: if ($settings->{$item} ne '') {
1255: $designs{'links'}{$item} = $settings->{$item};
1256: $is_custom{$item} = 1;
1257: }
1258: }
1259: } else {
1260: if ($designhash{$dom.'.login.font'} ne '') {
1261: $designs{'font'} = $designhash{$dom.'.login.font'};
1262: $is_custom{'font'} = 1;
1263: }
1264: foreach my $item (@images) {
1265: if ($designhash{$dom.'.login.'.$item} ne '') {
1266: $designs{$item} = $designhash{$dom.'.login.'.$item};
1267: $is_custom{$item} = 1;
1268: }
1269: }
1270: foreach my $item (@bgs) {
1271: if ($designhash{$dom.'.login.'.$item} ne '') {
1272: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1273: $is_custom{$item} = 1;
1274: }
1.6 raeburn 1275: }
1.168 raeburn 1276: foreach my $item (@links) {
1277: if ($designhash{$dom.'.login.'.$item} ne '') {
1278: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1279: $is_custom{$item} = 1;
1280: }
1.6 raeburn 1281: }
1282: }
1.168 raeburn 1283: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1284: logo => 'Institution Logo',
1285: domlogo => 'Domain Logo',
1286: login => 'Login box');
1287: my $itemcount = 1;
1288: foreach my $item (@toggles) {
1289: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1290: $datatable .=
1291: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1292: '</td><td>'.
1293: '<span class="LC_nobreak"><label><input type="radio" name="'.
1294: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1295: '</label> <label><input type="radio" name="'.$item.'"'.
1296: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1297: '</tr>';
1298: $itemcount ++;
1.6 raeburn 1299: }
1.168 raeburn 1300: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1301: $datatable .= '</tr></table></td></tr>';
1302: } elsif ($caller eq 'help') {
1303: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1304: my $switchserver = &check_switchserver($dom,$confname);
1305: my $itemcount = 1;
1306: $defaulturl = '/adm/loginproblems.html';
1307: $defaulttype = 'default';
1308: %lt = &Apache::lonlocal::texthash (
1309: del => 'Delete?',
1310: rep => 'Replace:',
1311: upl => 'Upload:',
1312: default => 'Default',
1313: custom => 'Custom',
1314: );
1315: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1316: my @currlangs;
1317: if (ref($settings) eq 'HASH') {
1318: if (ref($settings->{'helpurl'}) eq 'HASH') {
1319: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1320: next if ($settings->{'helpurl'}{$key} eq '');
1321: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1322: $type{$key} = 'custom';
1323: unless ($key eq 'nolang') {
1324: push(@currlangs,$key);
1325: }
1326: }
1327: } elsif ($settings->{'helpurl'} ne '') {
1328: $type{'nolang'} = 'custom';
1329: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1330: }
1331: }
1.168 raeburn 1332: foreach my $lang ('nolang',sort(@currlangs)) {
1333: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1334: $datatable .= '<tr'.$css_class.'>';
1335: if ($url{$lang} eq '') {
1336: $url{$lang} = $defaulturl;
1337: }
1338: if ($type{$lang} eq '') {
1339: $type{$lang} = $defaulttype;
1340: }
1341: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1342: if ($lang eq 'nolang') {
1343: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1344: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1345: } else {
1346: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1347: $langchoices{$lang},
1348: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1349: }
1350: $datatable .= '</span></td>'."\n".
1351: '<td class="LC_left_item">';
1352: if ($type{$lang} eq 'custom') {
1353: $datatable .= '<span class="LC_nobreak"><label>'.
1354: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1355: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1356: } else {
1357: $datatable .= $lt{'upl'};
1358: }
1359: $datatable .='<br />';
1360: if ($switchserver) {
1361: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1362: } else {
1363: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1364: }
1.168 raeburn 1365: $datatable .= '</td></tr>';
1366: $itemcount ++;
1.6 raeburn 1367: }
1.168 raeburn 1368: my @addlangs;
1369: foreach my $lang (sort(keys(%langchoices))) {
1370: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1371: push(@addlangs,$lang);
1372: }
1373: if (@addlangs > 0) {
1374: my %toadd;
1375: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1376: $toadd{''} = &mt('Select');
1377: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1378: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1379: &mt('Add log-in help page for a specific language:').' '.
1380: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1381: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1382: if ($switchserver) {
1383: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1384: } else {
1385: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1386: }
1.168 raeburn 1387: $datatable .= '</td></tr>';
1.169 raeburn 1388: $itemcount ++;
1.6 raeburn 1389: }
1.169 raeburn 1390: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1391: } elsif ($caller eq 'headtag') {
1392: my %domservers = &Apache::lonnet::get_servers($dom);
1393: my $choice = $choices{'headtag'};
1394: $css_class = ' class="LC_odd_row"';
1395: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1396: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1397: '<th>'.$choices{'current'}.'</th>'.
1398: '<th>'.$choices{'action'}.'</th>'.
1399: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1400: my (%currurls,%currexempt);
1401: if (ref($settings) eq 'HASH') {
1402: if (ref($settings->{'headtag'}) eq 'HASH') {
1403: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1404: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1405: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1406: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1407: }
1408: }
1409: }
1410: }
1411: my %lt = &Apache::lonlocal::texthash(
1412: del => 'Delete?',
1413: rep => 'Replace:',
1414: upl => 'Upload:',
1415: curr => 'View contents',
1416: none => 'None',
1417: );
1418: my $switchserver = &check_switchserver($dom,$confname);
1419: foreach my $lonhost (sort(keys(%domservers))) {
1420: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1421: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1422: if ($currurls{$lonhost}) {
1423: $datatable .= '<td class="LC_right_item"><a href="'.
1424: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1425: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1426: '">'.$lt{'curr'}.'</a></td>'.
1427: '<td><span class="LC_nobreak"><label>'.
1428: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1429: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1430: } else {
1431: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1432: }
1433: $datatable .='<br />';
1434: if ($switchserver) {
1435: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1436: } else {
1437: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1438: }
1439: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1440: }
1441: $datatable .= '</table></td></tr>';
1.1 raeburn 1442: }
1.6 raeburn 1443: return $datatable;
1444: }
1445:
1446: sub login_choices {
1447: my %choices =
1448: &Apache::lonlocal::texthash (
1.116 bisitz 1449: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1450: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1451: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1452: disallowlogin => "Login page requests redirected",
1453: hostid => "Server",
1.128 raeburn 1454: server => "Redirect to:",
1455: serverpath => "Path",
1456: custompath => "Custom",
1457: exempt => "Exempt IP(s)",
1.110 raeburn 1458: directlogin => "No redirect",
1459: newuser => "Link to create a user account",
1460: img => "Header",
1461: logo => "Main Logo",
1462: domlogo => "Domain Logo",
1463: login => "Log-in Header",
1464: textcol => "Text color",
1465: bgcol => "Box color",
1466: bgs => "Background colors",
1467: links => "Link colors",
1468: font => "Font color",
1469: pgbg => "Header",
1470: mainbg => "Page",
1471: sidebg => "Login box",
1472: link => "Link",
1473: alink => "Active link",
1474: vlink => "Visited link",
1.256 raeburn 1475: headtag => "Custom markup",
1476: action => "Action",
1477: current => "Current",
1.6 raeburn 1478: );
1479: return %choices;
1480: }
1481:
1482: sub print_rolecolors {
1.30 raeburn 1483: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1484: my %choices = &color_font_choices();
1485: my @bgs = ('pgbg','tabbg','sidebg');
1486: my @links = ('link','alink','vlink');
1487: my @images = ('img');
1488: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1489: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1490: my %defaultdesign = %Apache::loncommon::defaultdesign;
1491: my (%is_custom,%designs);
1.200 raeburn 1492: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1493: if (ref($settings) eq 'HASH') {
1494: if (ref($settings->{$role}) eq 'HASH') {
1495: if ($settings->{$role}->{'img'} ne '') {
1496: $designs{'img'} = $settings->{$role}->{'img'};
1497: $is_custom{'img'} = 1;
1498: }
1499: if ($settings->{$role}->{'font'} ne '') {
1500: $designs{'font'} = $settings->{$role}->{'font'};
1501: $is_custom{'font'} = 1;
1502: }
1.97 tempelho 1503: if ($settings->{$role}->{'fontmenu'} ne '') {
1504: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1505: $is_custom{'fontmenu'} = 1;
1506: }
1.6 raeburn 1507: foreach my $item (@bgs) {
1508: if ($settings->{$role}->{$item} ne '') {
1509: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1510: $is_custom{$item} = 1;
1511: }
1512: }
1513: foreach my $item (@links) {
1514: if ($settings->{$role}->{$item} ne '') {
1515: $designs{'links'}{$item} = $settings->{$role}->{$item};
1516: $is_custom{$item} = 1;
1517: }
1518: }
1519: }
1520: } else {
1521: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1522: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1523: $is_custom{'img'} = 1;
1524: }
1.97 tempelho 1525: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1526: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1527: $is_custom{'fontmenu'} = 1;
1528: }
1.6 raeburn 1529: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1530: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1531: $is_custom{'font'} = 1;
1532: }
1533: foreach my $item (@bgs) {
1534: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1535: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1536: $is_custom{$item} = 1;
1537:
1538: }
1539: }
1540: foreach my $item (@links) {
1541: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1542: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1543: $is_custom{$item} = 1;
1544: }
1545: }
1546: }
1547: my $itemcount = 1;
1.30 raeburn 1548: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1549: $datatable .= '</tr></table></td></tr>';
1550: return $datatable;
1551: }
1552:
1.200 raeburn 1553: sub role_defaults {
1554: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1555: my %defaults;
1556: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1557: return %defaults;
1558: }
1559: my %defaultdesign = %Apache::loncommon::defaultdesign;
1560: if ($role eq 'login') {
1561: %defaults = (
1562: font => $defaultdesign{$role.'.font'},
1563: );
1564: if (ref($logintext) eq 'ARRAY') {
1565: foreach my $item (@{$logintext}) {
1566: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1567: }
1568: }
1569: foreach my $item (@{$images}) {
1570: $defaults{'showlogo'}{$item} = 1;
1571: }
1572: } else {
1573: %defaults = (
1574: img => $defaultdesign{$role.'.img'},
1575: font => $defaultdesign{$role.'.font'},
1576: fontmenu => $defaultdesign{$role.'.fontmenu'},
1577: );
1578: }
1579: foreach my $item (@{$bgs}) {
1580: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1581: }
1582: foreach my $item (@{$links}) {
1583: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1584: }
1585: foreach my $item (@{$images}) {
1586: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1587: }
1588: return %defaults;
1589: }
1590:
1.6 raeburn 1591: sub display_color_options {
1.9 raeburn 1592: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1593: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1594: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1595: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1596: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1597: '<td>'.$choices->{'font'}.'</td>';
1598: if (!$is_custom->{'font'}) {
1.30 raeburn 1599: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1600: } else {
1601: $datatable .= '<td> </td>';
1602: }
1.174 foxr 1603: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1604:
1.8 raeburn 1605: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1606: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1607: ' value="'.$current_color.'" /> '.
1.174 foxr 1608: ' </td></tr>';
1.107 raeburn 1609: unless ($role eq 'login') {
1610: $datatable .= '<tr'.$css_class.'>'.
1611: '<td>'.$choices->{'fontmenu'}.'</td>';
1612: if (!$is_custom->{'fontmenu'}) {
1613: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1614: } else {
1615: $datatable .= '<td> </td>';
1616: }
1.202 raeburn 1617: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1618: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1619: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1620: '<input class="colorchooser" type="text" size="10" name="'
1621: .$role.'_fontmenu"'.
1622: ' value="'.$current_color.'" /> '.
1623: ' </td></tr>';
1.97 tempelho 1624: }
1.9 raeburn 1625: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1626: foreach my $img (@{$images}) {
1.18 albertel 1627: $itemcount ++;
1.6 raeburn 1628: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1629: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1630: '<td>'.$choices->{$img};
1.41 raeburn 1631: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1632: if ($role eq 'login') {
1633: if ($img eq 'login') {
1634: $login_hdr_pick =
1.135 bisitz 1635: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1636: $logincolors =
1637: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1638: $designs,$defaults);
1.70 raeburn 1639: } elsif ($img ne 'domlogo') {
1640: $datatable.= &logo_display_options($img,$defaults,$designs);
1641: }
1642: }
1643: $datatable .= '</td>';
1.6 raeburn 1644: if ($designs->{$img} ne '') {
1645: $imgfile = $designs->{$img};
1.18 albertel 1646: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1647: } else {
1648: $imgfile = $defaults->{$img};
1649: }
1650: if ($imgfile) {
1.9 raeburn 1651: my ($showfile,$fullsize);
1652: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1653: my $urldir = $1;
1654: my $filename = $2;
1655: my @info = &Apache::lonnet::stat_file($designs->{$img});
1656: if (@info) {
1657: my $thumbfile = 'tn-'.$filename;
1658: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1659: if (@thumb) {
1660: $showfile = $urldir.'/'.$thumbfile;
1661: } else {
1662: $showfile = $imgfile;
1663: }
1664: } else {
1665: $showfile = '';
1666: }
1667: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1668: $showfile = $imgfile;
1.6 raeburn 1669: my $imgdir = $1;
1670: my $filename = $2;
1.159 raeburn 1671: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1672: $showfile = "/$imgdir/tn-".$filename;
1673: } else {
1.159 raeburn 1674: my $input = $londocroot.$imgfile;
1675: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1676: if (!-e $output) {
1.9 raeburn 1677: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1678: my ($fullwidth,$fullheight) = &check_dimensions($input);
1679: if ($fullwidth ne '' && $fullheight ne '') {
1680: if ($fullwidth > $width && $fullheight > $height) {
1681: my $size = $width.'x'.$height;
1.316 raeburn 1682: my @args = ('convert','-sample',$size,$input,$output);
1683: system({$args[0]} @args);
1.159 raeburn 1684: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1685: }
1686: }
1.6 raeburn 1687: }
1688: }
1.16 raeburn 1689: }
1.6 raeburn 1690: if ($showfile) {
1.40 raeburn 1691: if ($showfile =~ m{^/(adm|res)/}) {
1692: if ($showfile =~ m{^/res/}) {
1693: my $local_showfile =
1694: &Apache::lonnet::filelocation('',$showfile);
1695: &Apache::lonnet::repcopy($local_showfile);
1696: }
1697: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1698: }
1699: if ($imgfile) {
1700: if ($imgfile =~ m{^/(adm|res)/}) {
1701: if ($imgfile =~ m{^/res/}) {
1702: my $local_imgfile =
1703: &Apache::lonnet::filelocation('',$imgfile);
1704: &Apache::lonnet::repcopy($local_imgfile);
1705: }
1706: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1707: } else {
1708: $fullsize = $imgfile;
1709: }
1710: }
1.41 raeburn 1711: $datatable .= '<td>';
1712: if ($img eq 'login') {
1.135 bisitz 1713: $datatable .= $login_hdr_pick;
1714: }
1.41 raeburn 1715: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1716: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1717: } else {
1.201 raeburn 1718: $datatable .= '<td> </td><td class="LC_left_item">'.
1719: &mt('Upload:').'<br />';
1.6 raeburn 1720: }
1721: } else {
1.201 raeburn 1722: $datatable .= '<td> </td><td class="LC_left_item">'.
1723: &mt('Upload:').'<br />';
1.6 raeburn 1724: }
1.9 raeburn 1725: if ($switchserver) {
1726: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1727: } else {
1.135 bisitz 1728: if ($img ne 'login') { # suppress file selection for Log-in header
1729: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1730: }
1.9 raeburn 1731: }
1732: $datatable .= '</td></tr>';
1.6 raeburn 1733: }
1734: $itemcount ++;
1735: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1736: $datatable .= '<tr'.$css_class.'>'.
1737: '<td>'.$choices->{'bgs'}.'</td>';
1738: my $bgs_def;
1739: foreach my $item (@{$bgs}) {
1740: if (!$is_custom->{$item}) {
1.70 raeburn 1741: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 1742: }
1743: }
1744: if ($bgs_def) {
1.8 raeburn 1745: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1746: } else {
1747: $datatable .= '<td> </td>';
1748: }
1749: $datatable .= '<td class="LC_right_item">'.
1750: '<table border="0"><tr>';
1.174 foxr 1751:
1.6 raeburn 1752: foreach my $item (@{$bgs}) {
1.306 raeburn 1753: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 1754: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1755: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1756: $datatable .= ' ';
1.6 raeburn 1757: }
1.174 foxr 1758: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1759: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1760: }
1761: $datatable .= '</tr></table></td></tr>';
1762: $itemcount ++;
1763: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1764: $datatable .= '<tr'.$css_class.'>'.
1765: '<td>'.$choices->{'links'}.'</td>';
1766: my $links_def;
1767: foreach my $item (@{$links}) {
1768: if (!$is_custom->{$item}) {
1.30 raeburn 1769: $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1770: }
1771: }
1772: if ($links_def) {
1.8 raeburn 1773: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1774: } else {
1775: $datatable .= '<td> </td>';
1776: }
1777: $datatable .= '<td class="LC_right_item">'.
1778: '<table border="0"><tr>';
1779: foreach my $item (@{$links}) {
1.234 raeburn 1780: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 1781: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 1782: if ($designs->{'links'}{$item}) {
1.174 foxr 1783: $datatable.=' ';
1.6 raeburn 1784: }
1.174 foxr 1785: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1786: '" /></td>';
1787: }
1.30 raeburn 1788: $$rowtotal += $itemcount;
1.3 raeburn 1789: return $datatable;
1790: }
1791:
1.70 raeburn 1792: sub logo_display_options {
1793: my ($img,$defaults,$designs) = @_;
1794: my $checkedon;
1795: if (ref($defaults) eq 'HASH') {
1796: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1797: if ($defaults->{'showlogo'}{$img}) {
1798: $checkedon = 'checked="checked" ';
1799: }
1800: }
1801: }
1802: if (ref($designs) eq 'HASH') {
1803: if (ref($designs->{'showlogo'}) eq 'HASH') {
1804: if (defined($designs->{'showlogo'}{$img})) {
1805: if ($designs->{'showlogo'}{$img} == 0) {
1806: $checkedon = '';
1807: } elsif ($designs->{'showlogo'}{$img} == 1) {
1808: $checkedon = 'checked="checked" ';
1809: }
1810: }
1811: }
1812: }
1813: return '<br /><label> <input type="checkbox" name="'.
1814: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1815: &mt('show').'</label>'."\n";
1816: }
1817:
1.41 raeburn 1818: sub login_header_options {
1.135 bisitz 1819: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1820: my $output = '';
1.41 raeburn 1821: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1822: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1823: if (!$is_custom->{'textcol'}) {
1824: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1825: ' ';
1826: }
1827: if (!$is_custom->{'bgcol'}) {
1828: $output .= $choices->{'bgcol'}.': '.
1829: '<span id="css_'.$role.'_font" style="background-color: '.
1830: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1831: }
1832: $output .= '<br />';
1833: }
1834: $output .='<br />';
1835: return $output;
1836: }
1837:
1838: sub login_text_colors {
1.201 raeburn 1839: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1840: my $color_menu = '<table border="0"><tr>';
1841: foreach my $item (@{$logintext}) {
1.306 raeburn 1842: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 1843: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1844: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1845: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1846: }
1847: $color_menu .= '</tr></table><br />';
1848: return $color_menu;
1849: }
1850:
1851: sub image_changes {
1852: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1853: my $output;
1.135 bisitz 1854: if ($img eq 'login') {
1855: # suppress image for Log-in header
1856: } elsif (!$is_custom) {
1.70 raeburn 1857: if ($img ne 'domlogo') {
1.41 raeburn 1858: $output .= &mt('Default image:').'<br />';
1859: } else {
1860: $output .= &mt('Default in use:').'<br />';
1861: }
1862: }
1.135 bisitz 1863: if ($img eq 'login') { # suppress image for Log-in header
1864: $output .= '<td>'.$logincolors;
1.41 raeburn 1865: } else {
1.135 bisitz 1866: if ($img_import) {
1867: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1868: }
1869: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1870: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1871: if ($is_custom) {
1872: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1873: '<input type="checkbox" name="'.
1874: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1875: '</label> '.&mt('Replace:').'</span><br />';
1876: } else {
1.306 raeburn 1877: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1878: }
1.41 raeburn 1879: }
1880: return $output;
1881: }
1882:
1.3 raeburn 1883: sub print_quotas {
1.86 raeburn 1884: my ($dom,$settings,$rowtotal,$action) = @_;
1885: my $context;
1886: if ($action eq 'quotas') {
1887: $context = 'tools';
1888: } else {
1889: $context = $action;
1890: }
1.197 raeburn 1891: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1892: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1893: my $typecount = 0;
1.101 raeburn 1894: my ($css_class,%titles);
1.86 raeburn 1895: if ($context eq 'requestcourses') {
1.271 raeburn 1896: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 1897: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1898: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1899: %titles = &courserequest_titles();
1.163 raeburn 1900: } elsif ($context eq 'requestauthor') {
1901: @usertools = ('author');
1902: @options = ('norequest','approval','automatic');
1.210 raeburn 1903: %titles = &authorrequest_titles();
1.86 raeburn 1904: } else {
1.162 raeburn 1905: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1906: %titles = &tool_titles();
1.86 raeburn 1907: }
1.26 raeburn 1908: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1909: foreach my $type (@{$types}) {
1.197 raeburn 1910: my ($currdefquota,$currauthorquota);
1.163 raeburn 1911: unless (($context eq 'requestcourses') ||
1912: ($context eq 'requestauthor')) {
1.86 raeburn 1913: if (ref($settings) eq 'HASH') {
1914: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1915: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1916: } else {
1917: $currdefquota = $settings->{$type};
1918: }
1.197 raeburn 1919: if (ref($settings->{authorquota}) eq 'HASH') {
1920: $currauthorquota = $settings->{authorquota}->{$type};
1921: }
1.78 raeburn 1922: }
1.72 raeburn 1923: }
1.3 raeburn 1924: if (defined($usertypes->{$type})) {
1925: $typecount ++;
1926: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1927: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1928: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1929: '<td class="LC_left_item">';
1.101 raeburn 1930: if ($context eq 'requestcourses') {
1931: $datatable .= '<table><tr>';
1932: }
1933: my %cell;
1.72 raeburn 1934: foreach my $item (@usertools) {
1.101 raeburn 1935: if ($context eq 'requestcourses') {
1936: my ($curroption,$currlimit);
1937: if (ref($settings) eq 'HASH') {
1938: if (ref($settings->{$item}) eq 'HASH') {
1939: $curroption = $settings->{$item}->{$type};
1940: if ($curroption =~ /^autolimit=(\d*)$/) {
1941: $currlimit = $1;
1942: }
1943: }
1944: }
1945: if (!$curroption) {
1946: $curroption = 'norequest';
1947: }
1948: $datatable .= '<th>'.$titles{$item}.'</th>';
1949: foreach my $option (@options) {
1950: my $val = $option;
1951: if ($option eq 'norequest') {
1952: $val = 0;
1953: }
1954: if ($option eq 'validate') {
1955: my $canvalidate = 0;
1956: if (ref($validations{$item}) eq 'HASH') {
1957: if ($validations{$item}{$type}) {
1958: $canvalidate = 1;
1959: }
1960: }
1961: next if (!$canvalidate);
1962: }
1963: my $checked = '';
1964: if ($option eq $curroption) {
1965: $checked = ' checked="checked"';
1966: } elsif ($option eq 'autolimit') {
1967: if ($curroption =~ /^autolimit/) {
1968: $checked = ' checked="checked"';
1969: }
1970: }
1971: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1972: '<input type="radio" name="crsreq_'.$item.
1973: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1974: $titles{$option}.'</label>';
1.101 raeburn 1975: if ($option eq 'autolimit') {
1.127 raeburn 1976: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1977: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1978: 'value="'.$currlimit.'" />';
1.101 raeburn 1979: }
1.127 raeburn 1980: $cell{$item} .= '</span> ';
1.103 raeburn 1981: if ($option eq 'autolimit') {
1.127 raeburn 1982: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1983: }
1.101 raeburn 1984: }
1.163 raeburn 1985: } elsif ($context eq 'requestauthor') {
1986: my $curroption;
1987: if (ref($settings) eq 'HASH') {
1988: $curroption = $settings->{$type};
1989: }
1990: if (!$curroption) {
1991: $curroption = 'norequest';
1992: }
1993: foreach my $option (@options) {
1994: my $val = $option;
1995: if ($option eq 'norequest') {
1996: $val = 0;
1997: }
1998: my $checked = '';
1999: if ($option eq $curroption) {
2000: $checked = ' checked="checked"';
2001: }
2002: $datatable .= '<span class="LC_nobreak"><label>'.
2003: '<input type="radio" name="authorreq_'.$type.
2004: '" value="'.$val.'"'.$checked.' />'.
2005: $titles{$option}.'</label></span> ';
2006: }
1.101 raeburn 2007: } else {
2008: my $checked = 'checked="checked" ';
2009: if (ref($settings) eq 'HASH') {
2010: if (ref($settings->{$item}) eq 'HASH') {
2011: if ($settings->{$item}->{$type} == 0) {
2012: $checked = '';
2013: } elsif ($settings->{$item}->{$type} == 1) {
2014: $checked = 'checked="checked" ';
2015: }
1.78 raeburn 2016: }
1.72 raeburn 2017: }
1.101 raeburn 2018: $datatable .= '<span class="LC_nobreak"><label>'.
2019: '<input type="checkbox" name="'.$context.'_'.$item.
2020: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2021: '</label></span> ';
1.72 raeburn 2022: }
1.101 raeburn 2023: }
2024: if ($context eq 'requestcourses') {
2025: $datatable .= '</tr><tr>';
2026: foreach my $item (@usertools) {
1.106 raeburn 2027: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2028: }
2029: $datatable .= '</tr></table>';
1.72 raeburn 2030: }
1.86 raeburn 2031: $datatable .= '</td>';
1.163 raeburn 2032: unless (($context eq 'requestcourses') ||
2033: ($context eq 'requestauthor')) {
1.86 raeburn 2034: $datatable .=
1.197 raeburn 2035: '<td class="LC_right_item">'.
2036: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2037: '<input type="text" name="quota_'.$type.
1.72 raeburn 2038: '" value="'.$currdefquota.
1.197 raeburn 2039: '" size="5" /></span>'.(' ' x 2).
2040: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2041: '<input type="text" name="authorquota_'.$type.
2042: '" value="'.$currauthorquota.
2043: '" size="5" /></span></td>';
1.86 raeburn 2044: }
2045: $datatable .= '</tr>';
1.3 raeburn 2046: }
2047: }
2048: }
1.163 raeburn 2049: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2050: $defaultquota = '20';
1.197 raeburn 2051: $authorquota = '500';
1.86 raeburn 2052: if (ref($settings) eq 'HASH') {
2053: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2054: $defaultquota = $settings->{'defaultquota'}->{'default'};
2055: } elsif (defined($settings->{'default'})) {
2056: $defaultquota = $settings->{'default'};
2057: }
1.197 raeburn 2058: if (ref($settings->{'authorquota'}) eq 'HASH') {
2059: $authorquota = $settings->{'authorquota'}->{'default'};
2060: }
1.3 raeburn 2061: }
2062: }
2063: $typecount ++;
2064: $css_class = $typecount%2?' class="LC_odd_row"':'';
2065: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2066: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2067: '<td class="LC_left_item">';
1.101 raeburn 2068: if ($context eq 'requestcourses') {
2069: $datatable .= '<table><tr>';
2070: }
2071: my %defcell;
1.72 raeburn 2072: foreach my $item (@usertools) {
1.101 raeburn 2073: if ($context eq 'requestcourses') {
2074: my ($curroption,$currlimit);
2075: if (ref($settings) eq 'HASH') {
2076: if (ref($settings->{$item}) eq 'HASH') {
2077: $curroption = $settings->{$item}->{'default'};
2078: if ($curroption =~ /^autolimit=(\d*)$/) {
2079: $currlimit = $1;
2080: }
2081: }
2082: }
2083: if (!$curroption) {
2084: $curroption = 'norequest';
2085: }
2086: $datatable .= '<th>'.$titles{$item}.'</th>';
2087: foreach my $option (@options) {
2088: my $val = $option;
2089: if ($option eq 'norequest') {
2090: $val = 0;
2091: }
2092: if ($option eq 'validate') {
2093: my $canvalidate = 0;
2094: if (ref($validations{$item}) eq 'HASH') {
2095: if ($validations{$item}{'default'}) {
2096: $canvalidate = 1;
2097: }
2098: }
2099: next if (!$canvalidate);
2100: }
2101: my $checked = '';
2102: if ($option eq $curroption) {
2103: $checked = ' checked="checked"';
2104: } elsif ($option eq 'autolimit') {
2105: if ($curroption =~ /^autolimit/) {
2106: $checked = ' checked="checked"';
2107: }
2108: }
2109: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2110: '<input type="radio" name="crsreq_'.$item.
2111: '_default" value="'.$val.'"'.$checked.' />'.
2112: $titles{$option}.'</label>';
2113: if ($option eq 'autolimit') {
1.127 raeburn 2114: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2115: $item.'_limit_default" size="1" '.
2116: 'value="'.$currlimit.'" />';
2117: }
1.127 raeburn 2118: $defcell{$item} .= '</span> ';
1.104 raeburn 2119: if ($option eq 'autolimit') {
1.127 raeburn 2120: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2121: }
1.101 raeburn 2122: }
1.163 raeburn 2123: } elsif ($context eq 'requestauthor') {
2124: my $curroption;
2125: if (ref($settings) eq 'HASH') {
1.172 raeburn 2126: $curroption = $settings->{'default'};
1.163 raeburn 2127: }
2128: if (!$curroption) {
2129: $curroption = 'norequest';
2130: }
2131: foreach my $option (@options) {
2132: my $val = $option;
2133: if ($option eq 'norequest') {
2134: $val = 0;
2135: }
2136: my $checked = '';
2137: if ($option eq $curroption) {
2138: $checked = ' checked="checked"';
2139: }
2140: $datatable .= '<span class="LC_nobreak"><label>'.
2141: '<input type="radio" name="authorreq_default"'.
2142: ' value="'.$val.'"'.$checked.' />'.
2143: $titles{$option}.'</label></span> ';
2144: }
1.101 raeburn 2145: } else {
2146: my $checked = 'checked="checked" ';
2147: if (ref($settings) eq 'HASH') {
2148: if (ref($settings->{$item}) eq 'HASH') {
2149: if ($settings->{$item}->{'default'} == 0) {
2150: $checked = '';
2151: } elsif ($settings->{$item}->{'default'} == 1) {
2152: $checked = 'checked="checked" ';
2153: }
1.78 raeburn 2154: }
1.72 raeburn 2155: }
1.101 raeburn 2156: $datatable .= '<span class="LC_nobreak"><label>'.
2157: '<input type="checkbox" name="'.$context.'_'.$item.
2158: '" value="default" '.$checked.'/>'.$titles{$item}.
2159: '</label></span> ';
2160: }
2161: }
2162: if ($context eq 'requestcourses') {
2163: $datatable .= '</tr><tr>';
2164: foreach my $item (@usertools) {
1.106 raeburn 2165: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2166: }
1.101 raeburn 2167: $datatable .= '</tr></table>';
1.72 raeburn 2168: }
1.86 raeburn 2169: $datatable .= '</td>';
1.163 raeburn 2170: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2171: $datatable .= '<td class="LC_right_item">'.
2172: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2173: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2174: $defaultquota.'" size="5" /></span>'.(' ' x2).
2175: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2176: '<input type="text" name="authorquota" value="'.
2177: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2178: }
2179: $datatable .= '</tr>';
1.72 raeburn 2180: $typecount ++;
2181: $css_class = $typecount%2?' class="LC_odd_row"':'';
2182: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2183: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2184: if ($context eq 'requestcourses') {
1.109 raeburn 2185: $datatable .= &mt('(overrides affiliation, if set)').
2186: '</td>'.
2187: '<td class="LC_left_item">'.
2188: '<table><tr>';
1.101 raeburn 2189: } else {
1.109 raeburn 2190: $datatable .= &mt('(overrides affiliation, if checked)').
2191: '</td>'.
2192: '<td class="LC_left_item" colspan="2">'.
2193: '<br />';
1.101 raeburn 2194: }
2195: my %advcell;
1.72 raeburn 2196: foreach my $item (@usertools) {
1.101 raeburn 2197: if ($context eq 'requestcourses') {
2198: my ($curroption,$currlimit);
2199: if (ref($settings) eq 'HASH') {
2200: if (ref($settings->{$item}) eq 'HASH') {
2201: $curroption = $settings->{$item}->{'_LC_adv'};
2202: if ($curroption =~ /^autolimit=(\d*)$/) {
2203: $currlimit = $1;
2204: }
2205: }
2206: }
2207: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2208: my $checked = '';
2209: if ($curroption eq '') {
2210: $checked = ' checked="checked"';
2211: }
2212: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2213: '<input type="radio" name="crsreq_'.$item.
2214: '__LC_adv" value=""'.$checked.' />'.
2215: &mt('No override set').'</label></span> ';
1.101 raeburn 2216: foreach my $option (@options) {
2217: my $val = $option;
2218: if ($option eq 'norequest') {
2219: $val = 0;
2220: }
2221: if ($option eq 'validate') {
2222: my $canvalidate = 0;
2223: if (ref($validations{$item}) eq 'HASH') {
2224: if ($validations{$item}{'_LC_adv'}) {
2225: $canvalidate = 1;
2226: }
2227: }
2228: next if (!$canvalidate);
2229: }
2230: my $checked = '';
1.104 raeburn 2231: if ($val eq $curroption) {
1.101 raeburn 2232: $checked = ' checked="checked"';
2233: } elsif ($option eq 'autolimit') {
2234: if ($curroption =~ /^autolimit/) {
2235: $checked = ' checked="checked"';
2236: }
2237: }
2238: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2239: '<input type="radio" name="crsreq_'.$item.
2240: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2241: $titles{$option}.'</label>';
2242: if ($option eq 'autolimit') {
1.127 raeburn 2243: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2244: $item.'_limit__LC_adv" size="1" '.
2245: 'value="'.$currlimit.'" />';
2246: }
1.127 raeburn 2247: $advcell{$item} .= '</span> ';
1.104 raeburn 2248: if ($option eq 'autolimit') {
1.127 raeburn 2249: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2250: }
1.101 raeburn 2251: }
1.163 raeburn 2252: } elsif ($context eq 'requestauthor') {
2253: my $curroption;
2254: if (ref($settings) eq 'HASH') {
2255: $curroption = $settings->{'_LC_adv'};
2256: }
2257: my $checked = '';
2258: if ($curroption eq '') {
2259: $checked = ' checked="checked"';
2260: }
2261: $datatable .= '<span class="LC_nobreak"><label>'.
2262: '<input type="radio" name="authorreq__LC_adv"'.
2263: ' value=""'.$checked.' />'.
2264: &mt('No override set').'</label></span> ';
2265: foreach my $option (@options) {
2266: my $val = $option;
2267: if ($option eq 'norequest') {
2268: $val = 0;
2269: }
2270: my $checked = '';
2271: if ($val eq $curroption) {
2272: $checked = ' checked="checked"';
2273: }
2274: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2275: '<input type="radio" name="authorreq__LC_adv"'.
2276: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2277: $titles{$option}.'</label></span> ';
2278: }
1.101 raeburn 2279: } else {
2280: my $checked = 'checked="checked" ';
2281: if (ref($settings) eq 'HASH') {
2282: if (ref($settings->{$item}) eq 'HASH') {
2283: if ($settings->{$item}->{'_LC_adv'} == 0) {
2284: $checked = '';
2285: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2286: $checked = 'checked="checked" ';
2287: }
1.79 raeburn 2288: }
1.72 raeburn 2289: }
1.101 raeburn 2290: $datatable .= '<span class="LC_nobreak"><label>'.
2291: '<input type="checkbox" name="'.$context.'_'.$item.
2292: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2293: '</label></span> ';
2294: }
2295: }
2296: if ($context eq 'requestcourses') {
2297: $datatable .= '</tr><tr>';
2298: foreach my $item (@usertools) {
1.106 raeburn 2299: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2300: }
1.101 raeburn 2301: $datatable .= '</tr></table>';
1.72 raeburn 2302: }
1.98 raeburn 2303: $datatable .= '</td></tr>';
1.30 raeburn 2304: $$rowtotal += $typecount;
1.3 raeburn 2305: return $datatable;
2306: }
2307:
1.163 raeburn 2308: sub print_requestmail {
1.305 raeburn 2309: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2310: my ($now,$datatable,%currapp);
1.102 raeburn 2311: $now = time;
2312: if (ref($settings) eq 'HASH') {
2313: if (ref($settings->{'notify'}) eq 'HASH') {
2314: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2315: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2316: }
2317: }
2318: }
1.191 raeburn 2319: my $numinrow = 2;
1.224 raeburn 2320: my $css_class;
1.305 raeburn 2321: if ($$rowtotal%2) {
2322: $css_class = 'LC_odd_row';
2323: }
2324: if ($customcss) {
2325: $css_class .= " $customcss";
2326: }
2327: $css_class =~ s/^\s+//;
2328: if ($css_class) {
2329: $css_class = ' class="'.$css_class.'"';
2330: }
2331: if ($rowstyle) {
2332: $css_class .= ' style="'.$rowstyle.'"';
2333: }
1.163 raeburn 2334: my $text;
2335: if ($action eq 'requestcourses') {
2336: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2337: } elsif ($action eq 'requestauthor') {
2338: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2339: } else {
1.224 raeburn 2340: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2341: }
1.224 raeburn 2342: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2343: ' <td>'.$text.'</td>'.
1.102 raeburn 2344: ' <td class="LC_left_item">';
1.191 raeburn 2345: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2346: $action.'notifyapproval',%currapp);
1.191 raeburn 2347: if ($numdc > 0) {
2348: $datatable .= $table;
1.102 raeburn 2349: } else {
2350: $datatable .= &mt('There are no active Domain Coordinators');
2351: }
2352: $datatable .='</td></tr>';
2353: return $datatable;
2354: }
2355:
1.216 raeburn 2356: sub print_studentcode {
2357: my ($settings,$rowtotal) = @_;
2358: my $rownum = 0;
1.218 raeburn 2359: my ($output,%current);
1.271 raeburn 2360: my @crstypes = ('official','unofficial','community','textbook','placement');
1.248 raeburn 2361: if (ref($settings) eq 'HASH') {
2362: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2363: foreach my $type (@crstypes) {
2364: $current{$type} = $settings->{'uniquecode'}{$type};
2365: }
1.218 raeburn 2366: }
2367: }
2368: $output .= '<tr>'.
2369: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2370: '<td class="LC_left_item">';
2371: foreach my $type (@crstypes) {
2372: my $check = ' ';
2373: if ($current{$type}) {
2374: $check = ' checked="checked" ';
2375: }
2376: $output .= '<span class="LC_nobreak"><label>'.
2377: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2378: &mt($type).'</label></span>'.(' 'x2).' ';
2379: }
2380: $output .= '</td></tr>';
2381: $$rowtotal ++;
2382: return $output;
1.216 raeburn 2383: }
2384:
2385: sub print_textbookcourses {
1.242 raeburn 2386: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2387: my $rownum = 0;
2388: my $css_class;
2389: my $itemcount = 1;
2390: my $maxnum = 0;
2391: my $bookshash;
2392: if (ref($settings) eq 'HASH') {
1.242 raeburn 2393: $bookshash = $settings->{$type};
1.216 raeburn 2394: }
2395: my %ordered;
2396: if (ref($bookshash) eq 'HASH') {
2397: foreach my $item (keys(%{$bookshash})) {
2398: if (ref($bookshash->{$item}) eq 'HASH') {
2399: my $num = $bookshash->{$item}{'order'};
2400: $ordered{$num} = $item;
2401: }
2402: }
2403: }
2404: my $confname = $dom.'-domainconfig';
2405: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2406: my $maxnum = scalar(keys(%ordered));
2407: my $datatable;
1.216 raeburn 2408: if (keys(%ordered)) {
2409: my @items = sort { $a <=> $b } keys(%ordered);
2410: for (my $i=0; $i<@items; $i++) {
2411: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2412: my $key = $ordered{$items[$i]};
2413: my %coursehash=&Apache::lonnet::coursedescription($key);
2414: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2415: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2416: if (ref($bookshash->{$key}) eq 'HASH') {
2417: $subject = $bookshash->{$key}->{'subject'};
2418: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2419: if ($type eq 'textbooks') {
1.243 raeburn 2420: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2421: $author = $bookshash->{$key}->{'author'};
2422: $image = $bookshash->{$key}->{'image'};
2423: if ($image ne '') {
2424: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2425: my $imagethumb = "$path/tn-".$imagefile;
2426: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2427: }
1.216 raeburn 2428: }
2429: }
1.242 raeburn 2430: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2431: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2432: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2433: for (my $k=0; $k<=$maxnum; $k++) {
2434: my $vpos = $k+1;
2435: my $selstr;
2436: if ($k == $i) {
2437: $selstr = ' selected="selected" ';
2438: }
2439: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2440: }
2441: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2442: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2443: &mt('Delete?').'</label></span></td>'.
2444: '<td colspan="2">'.
1.242 raeburn 2445: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2446: (' 'x2).
1.242 raeburn 2447: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2448: if ($type eq 'textbooks') {
2449: $datatable .= (' 'x2).
1.243 raeburn 2450: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2451: (' 'x2).
1.242 raeburn 2452: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2453: (' 'x2).
2454: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2455: if ($image) {
1.267 raeburn 2456: $datatable .= $imgsrc.
1.242 raeburn 2457: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2458: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2459: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2460: }
2461: if ($switchserver) {
2462: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2463: } else {
2464: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2465: }
1.216 raeburn 2466: }
1.242 raeburn 2467: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2468: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2469: $coursetitle.'</span></td></tr>'."\n";
2470: $itemcount ++;
2471: }
2472: }
2473: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2474: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2475: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2476: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2477: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2478: for (my $k=0; $k<$maxnum+1; $k++) {
2479: my $vpos = $k+1;
2480: my $selstr;
2481: if ($k == $maxnum) {
2482: $selstr = ' selected="selected" ';
2483: }
2484: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2485: }
2486: $datatable .= '</select> '."\n".
1.242 raeburn 2487: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.216 raeburn 2488: '<td colspan="2">'.
1.242 raeburn 2489: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2490: (' 'x2).
1.242 raeburn 2491: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2492: (' 'x2);
2493: if ($type eq 'textbooks') {
1.243 raeburn 2494: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2495: (' 'x2).
2496: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2497: (' 'x2).
2498: '<span class="LC_nobreak">'.&mt('Image:').' ';
2499: if ($switchserver) {
2500: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2501: } else {
2502: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2503: }
1.216 raeburn 2504: }
2505: $datatable .= '</span>'."\n".
2506: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2507: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2508: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2509: &Apache::loncommon::selectcourse_link
1.242 raeburn 2510: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.216 raeburn 2511: '</span></td>'."\n".
2512: '</tr>'."\n";
2513: $itemcount ++;
2514: return $datatable;
2515: }
2516:
1.217 raeburn 2517: sub textbookcourses_javascript {
1.242 raeburn 2518: my ($settings) = @_;
2519: return unless(ref($settings) eq 'HASH');
2520: my (%ordered,%total,%jstext);
2521: foreach my $type ('textbooks','templates') {
2522: $total{$type} = 0;
2523: if (ref($settings->{$type}) eq 'HASH') {
2524: foreach my $item (keys(%{$settings->{$type}})) {
2525: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2526: my $num = $settings->{$type}->{$item}{'order'};
2527: $ordered{$type}{$num} = $item;
2528: }
2529: }
2530: $total{$type} = scalar(keys(%{$settings->{$type}}));
2531: }
2532: my @jsarray = ();
2533: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2534: push(@jsarray,$ordered{$type}{$item});
2535: }
2536: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2537: }
2538: return <<"ENDSCRIPT";
2539: <script type="text/javascript">
2540: // <![CDATA[
1.242 raeburn 2541: function reorderBooks(form,item,caller) {
1.217 raeburn 2542: var changedVal;
1.242 raeburn 2543: $jstext{'textbooks'};
2544: $jstext{'templates'};
2545: var newpos;
2546: var maxh;
2547: if (caller == 'textbooks') {
2548: newpos = 'textbooks_addbook_pos';
2549: maxh = 1 + $total{'textbooks'};
2550: } else {
2551: newpos = 'templates_addbook_pos';
2552: maxh = 1 + $total{'templates'};
2553: }
1.217 raeburn 2554: var current = new Array;
2555: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2556: if (item == newpos) {
2557: changedVal = newitemVal;
2558: } else {
2559: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2560: current[newitemVal] = newpos;
2561: }
1.242 raeburn 2562: if (caller == 'textbooks') {
2563: for (var i=0; i<textbooks.length; i++) {
2564: var elementName = 'textbooks_'+textbooks[i];
2565: if (elementName != item) {
2566: if (form.elements[elementName]) {
2567: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2568: current[currVal] = elementName;
2569: }
2570: }
2571: }
2572: }
2573: if (caller == 'templates') {
2574: for (var i=0; i<templates.length; i++) {
2575: var elementName = 'templates_'+templates[i];
2576: if (elementName != item) {
2577: if (form.elements[elementName]) {
2578: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2579: current[currVal] = elementName;
2580: }
1.217 raeburn 2581: }
2582: }
2583: }
2584: var oldVal;
2585: for (var j=0; j<maxh; j++) {
2586: if (current[j] == undefined) {
2587: oldVal = j;
2588: }
2589: }
2590: if (oldVal < changedVal) {
2591: for (var k=oldVal+1; k<=changedVal ; k++) {
2592: var elementName = current[k];
2593: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2594: }
2595: } else {
2596: for (var k=changedVal; k<oldVal; k++) {
2597: var elementName = current[k];
2598: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2599: }
2600: }
2601: return;
2602: }
2603:
2604: // ]]>
2605: </script>
2606:
2607: ENDSCRIPT
2608: }
2609:
1.267 raeburn 2610: sub ltitools_javascript {
2611: my ($settings) = @_;
1.319 raeburn 2612: my $togglejs = <itools_toggle_js();
2613: unless (ref($settings) eq 'HASH') {
2614: return $togglejs;
2615: }
1.267 raeburn 2616: my (%ordered,$total,%jstext);
2617: $total = 0;
2618: foreach my $item (keys(%{$settings})) {
2619: if (ref($settings->{$item}) eq 'HASH') {
2620: my $num = $settings->{$item}{'order'};
2621: $ordered{$num} = $item;
2622: }
2623: }
2624: $total = scalar(keys(%{$settings}));
2625: my @jsarray = ();
2626: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2627: push(@jsarray,$ordered{$item});
2628: }
2629: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2630: return <<"ENDSCRIPT";
2631: <script type="text/javascript">
2632: // <![CDATA[
1.319 raeburn 2633: function reorderLTITools(form,item) {
1.267 raeburn 2634: var changedVal;
2635: $jstext
2636: var newpos = 'ltitools_add_pos';
2637: var maxh = 1 + $total;
2638: var current = new Array;
2639: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2640: if (item == newpos) {
2641: changedVal = newitemVal;
2642: } else {
2643: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2644: current[newitemVal] = newpos;
2645: }
2646: for (var i=0; i<ltitools.length; i++) {
2647: var elementName = 'ltitools_'+ltitools[i];
2648: if (elementName != item) {
2649: if (form.elements[elementName]) {
2650: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2651: current[currVal] = elementName;
2652: }
2653: }
2654: }
2655: var oldVal;
2656: for (var j=0; j<maxh; j++) {
2657: if (current[j] == undefined) {
2658: oldVal = j;
2659: }
2660: }
2661: if (oldVal < changedVal) {
2662: for (var k=oldVal+1; k<=changedVal ; k++) {
2663: var elementName = current[k];
2664: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2665: }
2666: } else {
2667: for (var k=changedVal; k<oldVal; k++) {
2668: var elementName = current[k];
2669: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2670: }
2671: }
2672: return;
2673: }
2674:
2675: // ]]>
2676: </script>
2677:
1.319 raeburn 2678: $togglejs
2679:
2680: ENDSCRIPT
2681: }
2682:
2683: sub ltitools_toggle_js {
2684: return <<"ENDSCRIPT";
2685: <script type="text/javascript">
2686: // <![CDATA[
2687:
2688: function toggleLTITools(form,setting,item) {
2689: var radioname = '';
2690: var divid = '';
2691: if ((setting == 'passback') || (setting == 'roster')) {
2692: radioname = 'ltitools_'+setting+'_'+item;
2693: divid = 'ltitools_'+setting+'time_'+item;
2694: var num = form.elements[radioname].length;
2695: if (num) {
2696: var setvis = '';
2697: for (var i=0; i<num; i++) {
2698: if (form.elements[radioname][i].checked) {
2699: if (form.elements[radioname][i].value == '1') {
2700: if (document.getElementById(divid)) {
2701: document.getElementById(divid).style.display = 'inline-block';
2702: }
2703: setvis = 1;
2704: }
2705: break;
2706: }
2707: }
2708: }
2709: if (!setvis) {
2710: if (document.getElementById(divid)) {
2711: document.getElementById(divid).style.display = 'none';
2712: }
2713: }
2714: }
2715: return;
2716: }
2717: // ]]>
2718: </script>
2719:
1.267 raeburn 2720: ENDSCRIPT
2721: }
2722:
1.320 raeburn 2723: sub lti_javascript {
2724: my ($settings) = @_;
2725: my $togglejs = <i_toggle_js();
2726: unless (ref($settings) eq 'HASH') {
2727: return $togglejs;
2728: }
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 lti = Array('."'".join("','",@jsarray)."'".');'."\n";
2743: return <<"ENDSCRIPT";
2744: <script type="text/javascript">
2745: // <![CDATA[
2746: function reorderLTI(form,item) {
2747: var changedVal;
2748: $jstext
2749: var newpos = 'lti_pos_add';
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<lti.length; i++) {
2760: var elementName = 'lti_pos_'+lti[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: </script>
2789:
2790: $togglejs
2791:
2792: ENDSCRIPT
2793: }
2794:
2795: sub lti_toggle_js {
2796: return <<"ENDSCRIPT";
2797: <script type="text/javascript">
2798: // <![CDATA[
2799:
2800: function toggleLTI(form,setting,item) {
2801: if ((setting == 'user') || (setting == 'crs')) {
2802: var radioname = '';
2803: var divid = '';
2804: if (setting == 'user') {
2805: radioname = 'lti_mapuser_'+item;
2806: divid = 'lti_userfield_'+item;
2807: } else {
2808: radioname = 'lti_mapcrs_'+item;
2809: divid = 'lti_crsfield_'+item;
2810: }
2811: var num = form.elements[radioname].length;
2812: if (num) {
2813: var setvis = '';
2814: for (var i=0; i<num; i++) {
2815: if (form.elements[radioname][i].checked) {
2816: if (form.elements[radioname][i].value == 'other') {
2817: if (document.getElementById(divid)) {
2818: document.getElementById(divid).style.display = 'inline-block';
2819: }
2820: setvis = 1;
2821: break;
2822: }
2823: }
2824: }
2825: if (!setvis) {
2826: if (document.getElementById(divid)) {
2827: document.getElementById(divid).style.display = 'none';
2828: }
2829: }
2830: }
2831: } else if ((setting == 'sec') || (setting == 'secsrc')) {
2832: var numsec = form.elements['lti_crssec_'+item].length;
2833: if (numsec) {
2834: var setvis = '';
2835: for (var i=0; i<numsec; i++) {
2836: if (form.elements['lti_crssec_'+item][i].checked) {
2837: if (form.elements['lti_crssec_'+item][i].value == '1') {
2838: if (document.getElementById('lti_crssecfield_'+item)) {
2839: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
2840: setvis = 1;
2841: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
2842: if (numsrcsec) {
2843: var setsrcvis = '';
2844: for (var j=0; j<numsrcsec; j++) {
2845: if (form.elements['lti_crssecsrc_'+item][j].checked) {
2846: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
2847: if (document.getElementById('lti_secsrcfield_'+item)) {
2848: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
2849: setsrcvis = 1;
2850: }
2851: }
2852: }
2853: }
2854: if (!setsrcvis) {
2855: if (document.getElementById('lti_secsrcfield_'+item)) {
2856: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
2857: }
2858: }
2859: }
2860: }
2861: }
2862: }
2863: }
2864: if (!setvis) {
2865: if (document.getElementById('lti_crssecfield_'+item)) {
2866: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
2867: }
2868: if (document.getElementById('lti_secsrcfield_'+item)) {
2869: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
2870: }
2871: }
2872: }
2873: }
2874: return;
2875: }
2876: // ]]>
2877: </script>
2878:
2879: ENDSCRIPT
2880: }
2881:
1.3 raeburn 2882: sub print_autoenroll {
1.30 raeburn 2883: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2884: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 2885: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2886: if (ref($settings) eq 'HASH') {
2887: if (exists($settings->{'run'})) {
2888: if ($settings->{'run'} eq '0') {
2889: $runoff = ' checked="checked" ';
2890: $runon = ' ';
2891: } else {
2892: $runon = ' checked="checked" ';
2893: $runoff = ' ';
2894: }
2895: } else {
2896: if ($autorun) {
2897: $runon = ' checked="checked" ';
2898: $runoff = ' ';
2899: } else {
2900: $runoff = ' checked="checked" ';
2901: $runon = ' ';
2902: }
2903: }
1.129 raeburn 2904: if (exists($settings->{'co-owners'})) {
2905: if ($settings->{'co-owners'} eq '0') {
2906: $coownersoff = ' checked="checked" ';
2907: $coownerson = ' ';
2908: } else {
2909: $coownerson = ' checked="checked" ';
2910: $coownersoff = ' ';
2911: }
2912: } else {
2913: $coownersoff = ' checked="checked" ';
2914: $coownerson = ' ';
2915: }
1.3 raeburn 2916: if (exists($settings->{'sender_domain'})) {
2917: $defdom = $settings->{'sender_domain'};
2918: }
1.274 raeburn 2919: if (exists($settings->{'autofailsafe'})) {
2920: $failsafe = $settings->{'autofailsafe'};
2921: }
1.14 raeburn 2922: } else {
2923: if ($autorun) {
2924: $runon = ' checked="checked" ';
2925: $runoff = ' ';
2926: } else {
2927: $runoff = ' checked="checked" ';
2928: $runon = ' ';
2929: }
1.3 raeburn 2930: }
2931: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2932: my $notif_sender;
2933: if (ref($settings) eq 'HASH') {
2934: $notif_sender = $settings->{'sender_uname'};
2935: }
1.3 raeburn 2936: my $datatable='<tr class="LC_odd_row">'.
2937: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2938: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2939: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2940: $runon.' value="1" />'.&mt('Yes').'</label> '.
2941: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2942: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2943: '</tr><tr>'.
2944: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2945: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2946: &mt('username').': '.
2947: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2948: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2949: ': '.$domform.'</span></td></tr>'.
2950: '<tr class="LC_odd_row">'.
2951: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2952: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2953: '<input type="radio" name="autoassign_coowners"'.
2954: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2955: '<label><input type="radio" name="autoassign_coowners"'.
2956: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 2957: '</tr><tr>'.
2958: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2959: '<td class="LC_right_item"><span class="LC_nobreak">'.
2960: '<input type="text" name="autoenroll_failsafe"'.
2961: ' value="'.$failsafe.'" size="4" /></td></tr>';
2962: $$rowtotal += 4;
1.3 raeburn 2963: return $datatable;
2964: }
2965:
2966: sub print_autoupdate {
1.30 raeburn 2967: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2968: my $datatable;
2969: if ($position eq 'top') {
2970: my $updateon = ' ';
2971: my $updateoff = ' checked="checked" ';
2972: my $classlistson = ' ';
2973: my $classlistsoff = ' checked="checked" ';
2974: if (ref($settings) eq 'HASH') {
2975: if ($settings->{'run'} eq '1') {
2976: $updateon = $updateoff;
2977: $updateoff = ' ';
2978: }
2979: if ($settings->{'classlists'} eq '1') {
2980: $classlistson = $classlistsoff;
2981: $classlistsoff = ' ';
2982: }
2983: }
2984: my %title = (
2985: run => 'Auto-update active?',
2986: classlists => 'Update information in classlists?',
2987: );
2988: $datatable = '<tr class="LC_odd_row">'.
2989: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2990: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2991: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2992: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2993: '<label><input type="radio" name="autoupdate_run"'.
2994: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2995: '</tr><tr>'.
2996: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2997: '<td class="LC_right_item"><span class="LC_nobreak">'.
2998: '<label><input type="radio" name="classlists"'.
2999: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
3000: '<label><input type="radio" name="classlists"'.
3001: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3002: '</tr>';
1.30 raeburn 3003: $$rowtotal += 2;
1.131 raeburn 3004: } elsif ($position eq 'middle') {
3005: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3006: my $numinrow = 3;
3007: my $locknamesettings;
3008: $datatable .= &insttypes_row($settings,$types,$usertypes,
3009: $dom,$numinrow,$othertitle,
1.305 raeburn 3010: 'lockablenames',$rowtotal);
1.131 raeburn 3011: $$rowtotal ++;
1.3 raeburn 3012: } else {
1.44 raeburn 3013: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3014: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3015: 'permanentemail','id');
1.33 raeburn 3016: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3017: my $numrows = 0;
1.26 raeburn 3018: if (ref($types) eq 'ARRAY') {
3019: if (@{$types} > 0) {
3020: $datatable =
3021: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3022: \@fields,$types,\$numrows);
1.30 raeburn 3023: $$rowtotal += @{$types};
1.26 raeburn 3024: }
1.3 raeburn 3025: }
3026: $datatable .=
3027: &usertype_update_row($settings,{'default' => $othertitle},
3028: \%fieldtitles,\@fields,['default'],
3029: \$numrows);
1.30 raeburn 3030: $$rowtotal ++;
1.3 raeburn 3031: }
3032: return $datatable;
3033: }
3034:
1.125 raeburn 3035: sub print_autocreate {
3036: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 3037: my (%createon,%createoff,%currhash);
1.125 raeburn 3038: my @types = ('xml','req');
3039: if (ref($settings) eq 'HASH') {
3040: foreach my $item (@types) {
3041: $createoff{$item} = ' checked="checked" ';
3042: $createon{$item} = ' ';
3043: if (exists($settings->{$item})) {
3044: if ($settings->{$item}) {
3045: $createon{$item} = ' checked="checked" ';
3046: $createoff{$item} = ' ';
3047: }
3048: }
3049: }
1.210 raeburn 3050: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 3051: $currhash{$settings->{'xmldc'}} = 1;
3052: }
1.125 raeburn 3053: } else {
3054: foreach my $item (@types) {
3055: $createoff{$item} = ' checked="checked" ';
3056: $createon{$item} = ' ';
3057: }
3058: }
3059: $$rowtotal += 2;
1.191 raeburn 3060: my $numinrow = 2;
1.125 raeburn 3061: my $datatable='<tr class="LC_odd_row">'.
3062: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3063: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3064: '<input type="radio" name="autocreate_xml"'.
3065: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3066: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3067: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3068: '</td></tr><tr>'.
3069: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3070: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3071: '<input type="radio" name="autocreate_req"'.
3072: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3073: '<label><input type="radio" name="autocreate_req"'.
3074: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 3075: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3076: 'autocreate_xmldc',%currhash);
1.247 raeburn 3077: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3078: if ($numdc > 1) {
1.247 raeburn 3079: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3080: '</td><td class="LC_left_item">';
1.125 raeburn 3081: } else {
1.247 raeburn 3082: $datatable .= &mt('Course creation processed as:').
3083: '</td><td class="LC_right_item">';
1.125 raeburn 3084: }
1.247 raeburn 3085: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 3086: $$rowtotal += $rows;
1.125 raeburn 3087: return $datatable;
3088: }
3089:
1.23 raeburn 3090: sub print_directorysrch {
1.277 raeburn 3091: my ($position,$dom,$settings,$rowtotal) = @_;
3092: my $datatable;
3093: if ($position eq 'top') {
3094: my $instsrchon = ' ';
3095: my $instsrchoff = ' checked="checked" ';
3096: my ($exacton,$containson,$beginson);
3097: my $instlocalon = ' ';
3098: my $instlocaloff = ' checked="checked" ';
3099: if (ref($settings) eq 'HASH') {
3100: if ($settings->{'available'} eq '1') {
3101: $instsrchon = $instsrchoff;
3102: $instsrchoff = ' ';
3103: }
3104: if ($settings->{'localonly'} eq '1') {
3105: $instlocalon = $instlocaloff;
3106: $instlocaloff = ' ';
3107: }
3108: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3109: foreach my $type (@{$settings->{'searchtypes'}}) {
3110: if ($type eq 'exact') {
3111: $exacton = ' checked="checked" ';
3112: } elsif ($type eq 'contains') {
3113: $containson = ' checked="checked" ';
3114: } elsif ($type eq 'begins') {
3115: $beginson = ' checked="checked" ';
3116: }
3117: }
3118: } else {
3119: if ($settings->{'searchtypes'} eq 'exact') {
3120: $exacton = ' checked="checked" ';
3121: } elsif ($settings->{'searchtypes'} eq 'contains') {
3122: $containson = ' checked="checked" ';
3123: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 3124: $exacton = ' checked="checked" ';
3125: $containson = ' checked="checked" ';
3126: }
3127: }
1.277 raeburn 3128: }
3129: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3130: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3131:
3132: my $numinrow = 4;
3133: my $cansrchrow = 0;
3134: $datatable='<tr class="LC_odd_row">'.
3135: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3136: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3137: '<input type="radio" name="dirsrch_available"'.
3138: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3139: '<label><input type="radio" name="dirsrch_available"'.
3140: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3141: '</tr><tr>'.
3142: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3143: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3144: '<input type="radio" name="dirsrch_instlocalonly"'.
3145: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3146: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3147: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3148: '</tr>';
3149: $$rowtotal += 2;
3150: if (ref($usertypes) eq 'HASH') {
3151: if (keys(%{$usertypes}) > 0) {
3152: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 3153: $numinrow,$othertitle,'cansearch',
3154: $rowtotal);
1.277 raeburn 3155: $cansrchrow = 1;
1.25 raeburn 3156: }
1.23 raeburn 3157: }
1.277 raeburn 3158: if ($cansrchrow) {
3159: $$rowtotal ++;
3160: $datatable .= '<tr>';
3161: } else {
3162: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 3163: }
1.277 raeburn 3164: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3165: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3166: foreach my $title (@{$titleorder}) {
3167: if (defined($searchtitles->{$title})) {
3168: my $check = ' ';
3169: if (ref($settings) eq 'HASH') {
3170: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3171: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3172: $check = ' checked="checked" ';
3173: }
1.39 raeburn 3174: }
1.25 raeburn 3175: }
1.277 raeburn 3176: $datatable .= '<td class="LC_left_item">'.
3177: '<span class="LC_nobreak"><label>'.
3178: '<input type="checkbox" name="searchby" '.
3179: 'value="'.$title.'"'.$check.'/>'.
3180: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 3181: }
3182: }
1.277 raeburn 3183: $datatable .= '</tr></table></td></tr>';
3184: $$rowtotal ++;
3185: if ($cansrchrow) {
3186: $datatable .= '<tr class="LC_odd_row">';
3187: } else {
3188: $datatable .= '<tr>';
3189: }
3190: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3191: '<td class="LC_left_item" colspan="2">'.
3192: '<span class="LC_nobreak"><label>'.
3193: '<input type="checkbox" name="searchtypes" '.
3194: $exacton.' value="exact" />'.&mt('Exact match').
3195: '</label> '.
3196: '<label><input type="checkbox" name="searchtypes" '.
3197: $beginson.' value="begins" />'.&mt('Begins with').
3198: '</label> '.
3199: '<label><input type="checkbox" name="searchtypes" '.
3200: $containson.' value="contains" />'.&mt('Contains').
3201: '</label></span></td></tr>';
3202: $$rowtotal ++;
1.26 raeburn 3203: } else {
1.277 raeburn 3204: my $domsrchon = ' checked="checked" ';
3205: my $domsrchoff = ' ';
3206: my $domlocalon = ' ';
3207: my $domlocaloff = ' checked="checked" ';
3208: if (ref($settings) eq 'HASH') {
3209: if ($settings->{'lclocalonly'} eq '1') {
3210: $domlocalon = $domlocaloff;
3211: $domlocaloff = ' ';
3212: }
3213: if ($settings->{'lcavailable'} eq '0') {
3214: $domsrchoff = $domsrchon;
3215: $domsrchon = ' ';
3216: }
3217: }
3218: $datatable='<tr class="LC_odd_row">'.
3219: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3220: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3221: '<input type="radio" name="dirsrch_domavailable"'.
3222: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3223: '<label><input type="radio" name="dirsrch_domavailable"'.
3224: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3225: '</tr><tr>'.
3226: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3227: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3228: '<input type="radio" name="dirsrch_domlocalonly"'.
3229: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3230: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3231: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3232: '</tr>';
3233: $$rowtotal += 2;
1.26 raeburn 3234: }
1.25 raeburn 3235: return $datatable;
3236: }
3237:
1.28 raeburn 3238: sub print_contacts {
1.286 raeburn 3239: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3240: my $datatable;
3241: my @contacts = ('adminemail','supportemail');
1.286 raeburn 3242: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
3243: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
3244: if ($position eq 'top') {
3245: if (ref($settings) eq 'HASH') {
3246: foreach my $item (@contacts) {
3247: if (exists($settings->{$item})) {
3248: $to{$item} = $settings->{$item};
3249: }
3250: }
3251: }
3252: } elsif ($position eq 'middle') {
3253: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
3254: 'updatesmail','idconflictsmail');
1.288 raeburn 3255: foreach my $type (@mailings) {
3256: $otheremails{$type} = '';
3257: }
1.286 raeburn 3258: } else {
3259: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 3260: foreach my $type (@mailings) {
3261: $otheremails{$type} = '';
3262: }
1.286 raeburn 3263: $bccemails{'helpdeskmail'} = '';
3264: $bccemails{'otherdomsmail'} = '';
3265: $includestr{'helpdeskmail'} = '';
3266: $includestr{'otherdomsmail'} = '';
3267: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3268: }
1.28 raeburn 3269: if (ref($settings) eq 'HASH') {
1.286 raeburn 3270: unless ($position eq 'top') {
3271: foreach my $type (@mailings) {
3272: if (exists($settings->{$type})) {
3273: if (ref($settings->{$type}) eq 'HASH') {
3274: foreach my $item (@contacts) {
3275: if ($settings->{$type}{$item}) {
3276: $checked{$type}{$item} = ' checked="checked" ';
3277: }
3278: }
3279: $otheremails{$type} = $settings->{$type}{'others'};
3280: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3281: $bccemails{$type} = $settings->{$type}{'bcc'};
3282: if ($settings->{$type}{'include'} ne '') {
3283: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3284: $includestr{$type} = &unescape($includestr{$type});
3285: }
3286: }
3287: }
3288: } elsif ($type eq 'lonstatusmail') {
3289: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3290: }
1.28 raeburn 3291: }
3292: }
1.286 raeburn 3293: if ($position eq 'bottom') {
3294: foreach my $type (@mailings) {
3295: $bccemails{$type} = $settings->{$type}{'bcc'};
3296: if ($settings->{$type}{'include'} ne '') {
3297: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3298: $includestr{$type} = &unescape($includestr{$type});
3299: }
3300: }
3301: if (ref($settings->{'helpform'}) eq 'HASH') {
3302: if (ref($fields) eq 'ARRAY') {
3303: foreach my $field (@{$fields}) {
3304: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3305: }
1.286 raeburn 3306: }
3307: if (exists($settings->{'helpform'}{'maxsize'})) {
3308: $maxsize = $settings->{'helpform'}{'maxsize'};
3309: } else {
1.289 raeburn 3310: $maxsize = '1.0';
1.286 raeburn 3311: }
3312: } else {
3313: if (ref($fields) eq 'ARRAY') {
3314: foreach my $field (@{$fields}) {
3315: $currfield{$field} = 'yes';
1.134 raeburn 3316: }
1.28 raeburn 3317: }
1.286 raeburn 3318: $maxsize = '1.0';
1.28 raeburn 3319: }
3320: }
3321: } else {
1.286 raeburn 3322: if ($position eq 'top') {
3323: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3324: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3325: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3326: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 3327: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3328: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3329: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3330: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
3331: } elsif ($position eq 'bottom') {
3332: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3333: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3334: if (ref($fields) eq 'ARRAY') {
3335: foreach my $field (@{$fields}) {
3336: $currfield{$field} = 'yes';
3337: }
3338: }
3339: $maxsize = '1.0';
3340: }
1.28 raeburn 3341: }
3342: my ($titles,$short_titles) = &contact_titles();
3343: my $rownum = 0;
3344: my $css_class;
1.286 raeburn 3345: if ($position eq 'top') {
3346: foreach my $item (@contacts) {
3347: $css_class = $rownum%2?' class="LC_odd_row"':'';
3348: $datatable .= '<tr'.$css_class.'>'.
3349: '<td><span class="LC_nobreak">'.$titles->{$item}.
3350: '</span></td><td class="LC_right_item">'.
3351: '<input type="text" name="'.$item.'" value="'.
3352: $to{$item}.'" /></td></tr>';
3353: $rownum ++;
3354: }
1.315 raeburn 3355: } elsif ($position eq 'bottom') {
3356: $css_class = $rownum%2?' class="LC_odd_row"':'';
3357: $datatable .= '<tr'.$css_class.'>'.
3358: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3359: &mt('(e-mail, subject, and description always shown)').
3360: '</td><td class="LC_left_item">';
3361: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3362: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3363: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3364: foreach my $field (@{$fields}) {
3365: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3366: if (($field eq 'screenshot') || ($field eq 'cc')) {
3367: $datatable .= ' '.&mt('(logged-in users)');
3368: }
3369: $datatable .='</td><td>';
3370: my $clickaction;
3371: if ($field eq 'screenshot') {
3372: $clickaction = ' onclick="screenshotSize(this);"';
3373: }
3374: if (ref($possoptions->{$field}) eq 'ARRAY') {
3375: foreach my $option (@{$possoptions->{$field}}) {
3376: my $checked;
3377: if ($currfield{$field} eq $option) {
3378: $checked = ' checked="checked"';
3379: }
3380: $datatable .= '<span class="LC_nobreak"><label>'.
3381: '<input type="radio" name="helpform_'.$field.'" '.
3382: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3383: '</label></span>'.(' 'x2);
3384: }
3385: }
3386: if ($field eq 'screenshot') {
3387: my $display;
3388: if ($currfield{$field} eq 'no') {
3389: $display = ' style="display:none"';
3390: }
3391: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.' />'.
3392: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3393: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3394: }
3395: $datatable .= '</td></tr>';
3396: }
3397: $datatable .= '</table>';
3398: }
3399: $datatable .= '</td></tr>'."\n";
3400: $rownum ++;
3401: }
3402: unless ($position eq 'top') {
1.286 raeburn 3403: foreach my $type (@mailings) {
3404: $css_class = $rownum%2?' class="LC_odd_row"':'';
3405: $datatable .= '<tr'.$css_class.'>'.
3406: '<td><span class="LC_nobreak">'.
3407: $titles->{$type}.': </span></td>'.
3408: '<td class="LC_left_item">';
3409: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3410: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3411: }
3412: $datatable .= '<span class="LC_nobreak">';
3413: foreach my $item (@contacts) {
3414: $datatable .= '<label>'.
3415: '<input type="checkbox" name="'.$type.'"'.
3416: $checked{$type}{$item}.
3417: ' value="'.$item.'" />'.$short_titles->{$item}.
3418: '</label> ';
3419: }
3420: $datatable .= '</span><br />'.&mt('Others').': '.
3421: '<input type="text" name="'.$type.'_others" '.
3422: 'value="'.$otheremails{$type}.'" />';
3423: my %locchecked;
3424: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3425: foreach my $loc ('s','b') {
3426: if ($includeloc{$type} eq $loc) {
3427: $locchecked{$loc} = ' checked="checked"';
3428: last;
3429: }
3430: }
3431: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3432: '<input type="text" name="'.$type.'_bcc" '.
3433: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3434: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3435: &mt('Text automatically added to e-mail:').' '.
3436: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br >'.
3437: '<span class="LC_nobreak">'.&mt('Location:').' '.
3438: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3439: (' 'x2).
3440: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3441: '</span></fieldset>';
3442: }
3443: $datatable .= '</td></tr>'."\n";
3444: $rownum ++;
3445: }
1.28 raeburn 3446: }
1.286 raeburn 3447: if ($position eq 'middle') {
3448: my %choices;
3449: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
1.289 raeburn 3450: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3451: &mt('LON-CAPA core group - MSU'),600,500));
1.286 raeburn 3452: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
3453: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3454: &mt('LON-CAPA core group - MSU'),600,500));
3455: my @toggles = ('reporterrors','reportupdates');
3456: my %defaultchecked = ('reporterrors' => 'on',
3457: 'reportupdates' => 'on');
3458: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3459: \%choices,$rownum);
3460: $datatable .= $reports;
3461: } elsif ($position eq 'bottom') {
1.315 raeburn 3462: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3463: my (@posstypes,%usertypeshash);
3464: if (ref($types) eq 'ARRAY') {
3465: @posstypes = @{$types};
3466: }
3467: if (@posstypes) {
3468: if (ref($usertypes) eq 'HASH') {
3469: %usertypeshash = %{$usertypes};
3470: }
3471: my @overridden;
3472: my $numinrow = 4;
3473: if (ref($settings) eq 'HASH') {
3474: if (ref($settings->{'overrides'}) eq 'HASH') {
3475: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3476: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3477: push(@overridden,$key);
3478: foreach my $item (@contacts) {
3479: if ($settings->{'overrides'}{$key}{$item}) {
3480: $checked{'override_'.$key}{$item} = ' checked="checked" ';
3481: }
3482: }
3483: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3484: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3485: $includeloc{'override_'.$key} = '';
3486: $includestr{'override_'.$key} = '';
3487: if ($settings->{'overrides'}{$key}{'include'} ne '') {
3488: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3489: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3490: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3491: }
1.286 raeburn 3492: }
3493: }
3494: }
1.315 raeburn 3495: }
3496: my $customclass = 'LC_helpdesk_override';
3497: my $optionsprefix = 'LC_options_helpdesk_';
3498:
3499: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3500:
3501: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3502: $numinrow,$othertitle,'overrides',
3503: \$rownum,$onclicktypes,$customclass);
3504: $rownum ++;
3505: $usertypeshash{'default'} = $othertitle;
3506: foreach my $status (@posstypes) {
3507: my $css_class;
3508: if ($rownum%2) {
3509: $css_class = 'LC_odd_row ';
3510: }
3511: $css_class .= $customclass;
3512: my $rowid = $optionsprefix.$status;
3513: my $hidden = 1;
3514: my $currstyle = 'display:none';
3515: if (grep(/^\Q$status\E$/,@overridden)) {
3516: $currstyle = 'display:table-row';
3517: $hidden = 0;
3518: }
3519: my $key = 'override_'.$status;
3520: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3521: $includeloc{$key},$includestr{$key},$status,$rowid,
3522: $usertypeshash{$status},$css_class,$currstyle,
3523: \@contacts,$short_titles);
3524: unless ($hidden) {
3525: $rownum ++;
1.286 raeburn 3526: }
3527: }
1.134 raeburn 3528: }
1.28 raeburn 3529: }
1.30 raeburn 3530: $$rowtotal += $rownum;
1.28 raeburn 3531: return $datatable;
3532: }
3533:
1.315 raeburn 3534: sub overridden_helpdesk {
3535: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3536: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3537: my $class = 'LC_left_item';
3538: if ($css_class) {
3539: $css_class = ' class="'.$css_class.'"';
3540: }
3541: if ($rowid) {
3542: $rowid = ' id="'.$rowid.'"';
3543: }
3544: if ($rowstyle) {
3545: $rowstyle = ' style="'.$rowstyle.'"';
3546: }
3547: my ($output,$description);
3548: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3549: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3550: "<td>$description</td>\n".
3551: '<td class="'.$class.'" colspan="2">'.
3552: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3553: '<span class="LC_nobreak">';
3554: if (ref($contacts) eq 'ARRAY') {
3555: foreach my $item (@{$contacts}) {
3556: my $check;
3557: if (ref($checked) eq 'HASH') {
3558: $check = $checked->{$item};
3559: }
3560: my $title;
3561: if (ref($short_titles) eq 'HASH') {
3562: $title = $short_titles->{$item};
3563: }
3564: $output .= '<label>'.
3565: '<input type="checkbox" name="override_'.$type.'"'.$check.
3566: ' value="'.$item.'" />'.$title.'</label> ';
3567: }
3568: }
3569: $output .= '</span><br />'.&mt('Others').': '.
3570: '<input type="text" name="override_'.$type.'_others" '.
3571: 'value="'.$otheremails.'" />';
3572: my %locchecked;
3573: foreach my $loc ('s','b') {
3574: if ($includeloc eq $loc) {
3575: $locchecked{$loc} = ' checked="checked"';
3576: last;
3577: }
3578: }
3579: $output .= '<br />'.&mt('Bcc:').(' 'x6).
3580: '<input type="text" name="override_'.$type.'_bcc" '.
3581: 'value="'.$bccemails.'" /></fieldset>'.
3582: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3583: &mt('Text automatically added to e-mail:').' '.
3584: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br >'.
3585: '<span class="LC_nobreak">'.&mt('Location:').' '.
3586: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3587: (' 'x2).
3588: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3589: '</span></fieldset>'.
3590: '</td></tr>'."\n";
3591: return $output;
3592: }
3593:
1.286 raeburn 3594: sub contacts_javascript {
3595: return <<"ENDSCRIPT";
3596:
3597: <script type="text/javascript">
3598: // <![CDATA[
3599:
3600: function screenshotSize(field) {
3601: if (document.getElementById('help_screenshotsize')) {
3602: if (field.value == 'no') {
1.289 raeburn 3603: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 3604: } else {
3605: document.getElementById('help_screenshotsize').style.display="";
3606: }
3607: }
3608: return;
3609: }
3610:
1.315 raeburn 3611: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
3612: if (form.elements[checkbox].length != undefined) {
3613: var count = 0;
3614: if (docount) {
3615: for (var i=0; i<form.elements[checkbox].length; i++) {
3616: if (form.elements[checkbox][i].checked) {
3617: count ++;
3618: }
3619: }
3620: }
3621: for (var i=0; i<form.elements[checkbox].length; i++) {
3622: var type = form.elements[checkbox][i].value;
3623: if (document.getElementById(prefix+type)) {
3624: if (form.elements[checkbox][i].checked) {
3625: document.getElementById(prefix+type).style.display = 'table-row';
3626: if (count % 2 == 1) {
3627: document.getElementById(prefix+type).className = target+' LC_odd_row';
3628: } else {
3629: document.getElementById(prefix+type).className = target;
3630: }
3631: count ++;
3632: } else {
3633: document.getElementById(prefix+type).style.display = 'none';
3634: }
3635: }
3636: }
3637: }
3638: return;
3639: }
3640:
3641:
1.286 raeburn 3642: // ]]>
3643: </script>
3644:
3645: ENDSCRIPT
3646: }
3647:
1.118 jms 3648: sub print_helpsettings {
1.282 raeburn 3649: my ($position,$dom,$settings,$rowtotal) = @_;
3650: my $confname = $dom.'-domainconfig';
1.285 raeburn 3651: my $formname = 'display';
1.168 raeburn 3652: my ($datatable,$itemcount);
1.282 raeburn 3653: if ($position eq 'top') {
3654: $itemcount = 1;
3655: my (%choices,%defaultchecked,@toggles);
3656: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3657: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3658: &mt('LON-CAPA bug tracker'),600,500));
3659: %defaultchecked = ('submitbugs' => 'on');
3660: @toggles = ('submitbugs');
3661: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3662: \%choices,$itemcount);
3663: $$rowtotal ++;
3664: } else {
3665: my $css_class;
3666: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 3667: my (%customroles,%ordered,%current);
1.301 raeburn 3668: if (ref($settings) eq 'HASH') {
3669: if (ref($settings->{'adhoc'}) eq 'HASH') {
3670: %current = %{$settings->{'adhoc'}};
3671: }
1.285 raeburn 3672: }
3673: my $count = 0;
3674: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 3675: if ($key=~/^rolesdef\_(\w+)$/) {
3676: my $rolename = $1;
1.285 raeburn 3677: my (%privs,$order);
1.282 raeburn 3678: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3679: $customroles{$rolename} = \%privs;
1.285 raeburn 3680: if (ref($current{$rolename}) eq 'HASH') {
3681: $order = $current{$rolename}{'order'};
3682: }
3683: if ($order eq '') {
3684: $order = $count;
3685: }
3686: $ordered{$order} = $rolename;
3687: $count++;
3688: }
3689: }
3690: my $maxnum = scalar(keys(%ordered));
3691: my @roles_by_num = ();
3692: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3693: push(@roles_by_num,$item);
3694: }
3695: my $context = 'domprefs';
3696: my $crstype = 'Course';
3697: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 3698: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 3699: my ($numstatustypes,@jsarray);
3700: if (ref($types) eq 'ARRAY') {
3701: if (@{$types} > 0) {
3702: $numstatustypes = scalar(@{$types});
3703: push(@accesstypes,'status');
3704: @jsarray = ('bystatus');
1.282 raeburn 3705: }
3706: }
1.290 raeburn 3707: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 3708: if (keys(%domhelpdesk)) {
3709: push(@accesstypes,('inc','exc'));
3710: push(@jsarray,('notinc','notexc'));
3711: }
3712: my $hiddenstr = join("','",@jsarray);
3713: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.282 raeburn 3714: my $context = 'domprefs';
3715: my $crstype = 'Course';
1.285 raeburn 3716: my $prefix = 'helproles_';
3717: my $add_class = 'LC_hidden';
3718: foreach my $num (@roles_by_num) {
3719: my $role = $ordered{$num};
3720: my ($desc,$access,@statuses);
3721: if (ref($current{$role}) eq 'HASH') {
3722: $desc = $current{$role}{'desc'};
3723: $access = $current{$role}{'access'};
3724: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3725: @statuses = @{$current{$role}{'insttypes'}};
3726: }
3727: }
3728: if ($desc eq '') {
3729: $desc = $role;
3730: }
3731: my $identifier = 'custhelp'.$num;
1.282 raeburn 3732: my %full=();
3733: my %levels= (
3734: course => {},
3735: domain => {},
3736: system => {},
3737: );
3738: my %levelscurrent=(
3739: course => {},
3740: domain => {},
3741: system => {},
3742: );
3743: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3744: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3745: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 3746: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 3747: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 3748: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3749: for (my $k=0; $k<=$maxnum; $k++) {
3750: my $vpos = $k+1;
3751: my $selstr;
3752: if ($k == $num) {
3753: $selstr = ' selected="selected" ';
3754: }
3755: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3756: }
3757: $datatable .= '</select>'.(' 'x2).
3758: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3759: '</td>'.
3760: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3761: &mt('Name shown to users:').
3762: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3763: '</fieldset>'.
3764: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3765: $othertitle,$usertypes,$types,\%domhelpdesk).
3766: '<fieldset>'.
3767: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 3768: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 3769: \%levelscurrent,$identifier,
3770: 'LC_hidden',$prefix.$num.'_privs').
3771: '</fieldset></td>';
1.282 raeburn 3772: $itemcount ++;
3773: }
3774: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3775: my $newcust = 'custhelp'.$count;
3776: my (%privs,%levelscurrent);
3777: my %full=();
3778: my %levels= (
3779: course => {},
3780: domain => {},
3781: system => {},
3782: );
3783: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3784: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 3785: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 3786: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 3787: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3788: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3789: for (my $k=0; $k<$maxnum+1; $k++) {
3790: my $vpos = $k+1;
3791: my $selstr;
3792: if ($k == $maxnum) {
3793: $selstr = ' selected="selected" ';
3794: }
3795: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3796: }
3797: $datatable .= '</select> '."\n".
1.282 raeburn 3798: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3799: '</label></span></td>'.
1.285 raeburn 3800: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3801: '<span class="LC_nobreak">'.
3802: &mt('Internal name:').
3803: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3804: '</span>'.(' 'x4).
3805: '<span class="LC_nobreak">'.
3806: &mt('Name shown to users:').
3807: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3808: '</span></fieldset>'.
3809: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3810: $usertypes,$types,\%domhelpdesk).
3811: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 3812: &Apache::lonuserutils::custom_role_header($context,$crstype,
3813: \@templateroles,$newcust).
3814: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3815: \%levelscurrent,$newcust).
1.285 raeburn 3816: '</fieldset></td></tr>';
1.282 raeburn 3817: $count ++;
3818: $$rowtotal += $count;
3819: }
1.166 raeburn 3820: return $datatable;
1.121 raeburn 3821: }
3822:
1.285 raeburn 3823: sub adhocbutton {
3824: my ($prefix,$num,$field,$visibility) = @_;
3825: my %lt = &Apache::lonlocal::texthash(
3826: show => 'Show details',
3827: hide => 'Hide details',
3828: );
3829: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3830: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3831: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3832: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3833: }
3834:
3835: sub helpsettings_javascript {
3836: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3837: return unless(ref($roles_by_num) eq 'ARRAY');
3838: my %html_js_lt = &Apache::lonlocal::texthash(
3839: show => 'Show details',
3840: hide => 'Hide details',
3841: );
3842: &html_escape(\%html_js_lt);
3843: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3844: return <<"ENDSCRIPT";
3845: <script type="text/javascript">
3846: // <![CDATA[
3847:
3848: function reorderHelpRoles(form,item) {
3849: var changedVal;
3850: $jstext
3851: var newpos = 'helproles_${total}_pos';
3852: var maxh = 1 + $total;
3853: var current = new Array();
3854: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3855: if (item == newpos) {
3856: changedVal = newitemVal;
3857: } else {
3858: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3859: current[newitemVal] = newpos;
3860: }
3861: for (var i=0; i<helproles.length; i++) {
3862: var elementName = 'helproles_'+helproles[i]+'_pos';
3863: if (elementName != item) {
3864: if (form.elements[elementName]) {
3865: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3866: current[currVal] = elementName;
3867: }
3868: }
3869: }
3870: var oldVal;
3871: for (var j=0; j<maxh; j++) {
3872: if (current[j] == undefined) {
3873: oldVal = j;
3874: }
3875: }
3876: if (oldVal < changedVal) {
3877: for (var k=oldVal+1; k<=changedVal ; k++) {
3878: var elementName = current[k];
3879: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3880: }
3881: } else {
3882: for (var k=changedVal; k<oldVal; k++) {
3883: var elementName = current[k];
3884: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3885: }
3886: }
3887: return;
3888: }
3889:
3890: function helpdeskAccess(num) {
3891: var curraccess = null;
3892: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3893: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3894: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3895: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3896: }
3897: }
3898: }
3899: var shown = Array();
3900: var hidden = Array();
3901: if (curraccess == 'none') {
3902: hidden = Array('$hiddenstr');
3903: } else {
3904: if (curraccess == 'status') {
3905: shown = Array('bystatus');
3906: hidden = Array('notinc','notexc');
3907: } else {
3908: if (curraccess == 'exc') {
3909: shown = Array('notexc');
3910: hidden = Array('notinc','bystatus');
3911: }
3912: if (curraccess == 'inc') {
3913: shown = Array('notinc');
3914: hidden = Array('notexc','bystatus');
3915: }
1.293 raeburn 3916: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 3917: hidden = Array('notinc','notexc','bystatus');
3918: }
3919: }
3920: }
3921: if (hidden.length > 0) {
3922: for (var i=0; i<hidden.length; i++) {
3923: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3924: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3925: }
3926: }
3927: }
3928: if (shown.length > 0) {
3929: for (var i=0; i<shown.length; i++) {
3930: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3931: if (shown[i] == 'privs') {
3932: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3933: } else {
3934: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3935: }
3936: }
3937: }
3938: }
3939: return;
3940: }
3941:
3942: function toggleHelpdeskItem(num,field) {
3943: if (document.getElementById('helproles_'+num+'_'+field)) {
3944: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 3945: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 3946: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3947: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3948: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3949: }
3950: } else {
3951: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3952: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3953: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3954: }
3955: }
3956: }
3957: return;
3958: }
3959:
3960: // ]]>
3961: </script>
3962:
3963: ENDSCRIPT
3964: }
3965:
3966: sub helpdeskroles_access {
3967: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3968: $usertypes,$types,$domhelpdesk) = @_;
3969: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3970: my %lt = &Apache::lonlocal::texthash(
3971: 'rou' => 'Role usage',
3972: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 3973: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3974: 'dh' => 'All with domain helpdesk role',
3975: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 3976: 'none' => 'None',
3977: 'status' => 'Determined based on institutional status',
3978: 'inc' => 'Include all, but exclude specific personnel',
3979: 'exc' => 'Exclude all, but include specific personnel',
3980: );
3981: my %usecheck = (
3982: all => ' checked="checked"',
3983: );
3984: my %displaydiv = (
3985: status => 'none',
3986: inc => 'none',
3987: exc => 'none',
3988: priv => 'block',
3989: );
3990: my $output;
3991: if (ref($current) eq 'HASH') {
3992: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3993: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3994: $usecheck{$current->{access}} = $usecheck{'all'};
3995: delete($usecheck{'all'});
3996: if ($current->{access} =~ /^(status|inc|exc)$/) {
3997: my $access = $1;
3998: $displaydiv{$access} = 'inline';
3999: } elsif ($current->{access} eq 'none') {
4000: $displaydiv{'priv'} = 'none';
4001: }
4002: }
4003: }
4004: }
4005: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4006: '<p>'.$lt{'whi'}.'</p>';
4007: foreach my $access (@{$accesstypes}) {
4008: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4009: ' onclick="helpdeskAccess('."'$num'".');" />'.
4010: $lt{$access}.'</label>';
4011: if ($access eq 'status') {
4012: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4013: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4014: $othertitle,$usertypes,$types).
4015: '</div>';
4016: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4017: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4018: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4019: '</div>';
4020: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4021: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4022: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4023: '</div>';
4024: }
4025: $output .= '</p>';
4026: }
4027: $output .= '</fieldset>';
4028: return $output;
4029: }
4030:
1.121 raeburn 4031: sub radiobutton_prefs {
1.192 raeburn 4032: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 4033: $additional,$align) = @_;
1.121 raeburn 4034: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4035: (ref($choices) eq 'HASH'));
4036:
1.170 raeburn 4037: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 4038:
4039: foreach my $item (@{$toggles}) {
4040: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4041: $checkedon{$item} = ' checked="checked" ';
4042: $checkedoff{$item} = ' ';
1.121 raeburn 4043: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4044: $checkedoff{$item} = ' checked="checked" ';
4045: $checkedon{$item} = ' ';
4046: }
4047: }
4048: if (ref($settings) eq 'HASH') {
1.121 raeburn 4049: foreach my $item (@{$toggles}) {
1.118 jms 4050: if ($settings->{$item} eq '1') {
4051: $checkedon{$item} = ' checked="checked" ';
4052: $checkedoff{$item} = ' ';
4053: } elsif ($settings->{$item} eq '0') {
4054: $checkedoff{$item} = ' checked="checked" ';
4055: $checkedon{$item} = ' ';
4056: }
4057: }
1.121 raeburn 4058: }
1.192 raeburn 4059: if ($onclick) {
4060: $onclick = ' onclick="'.$onclick.'"';
4061: }
1.121 raeburn 4062: foreach my $item (@{$toggles}) {
1.118 jms 4063: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4064: $datatable .=
1.306 raeburn 4065: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 4066: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 4067: '</span></td>';
4068: if ($align eq 'left') {
4069: $datatable .= '<td class="LC_left_item">';
4070: } else {
4071: $datatable .= '<td class="LC_right_item">';
4072: }
1.289 raeburn 4073: $datatable .=
1.257 raeburn 4074: '<span class="LC_nobreak">'.
1.118 jms 4075: '<label><input type="radio" name="'.
1.192 raeburn 4076: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 4077: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 4078: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
4079: '</span>'.$additional.
4080: '</td>'.
1.118 jms 4081: '</tr>';
4082: $itemcount ++;
1.121 raeburn 4083: }
4084: return ($datatable,$itemcount);
4085: }
4086:
1.267 raeburn 4087: sub print_ltitools {
4088: my ($dom,$settings,$rowtotal) = @_;
4089: my $rownum = 0;
4090: my $css_class;
4091: my $itemcount = 1;
4092: my $maxnum = 0;
4093: my %ordered;
4094: if (ref($settings) eq 'HASH') {
4095: foreach my $item (keys(%{$settings})) {
4096: if (ref($settings->{$item}) eq 'HASH') {
4097: my $num = $settings->{$item}{'order'};
4098: $ordered{$num} = $item;
4099: }
4100: }
4101: }
4102: my $confname = $dom.'-domainconfig';
4103: my $switchserver = &check_switchserver($dom,$confname);
4104: my $maxnum = scalar(keys(%ordered));
4105: my $datatable = <itools_javascript($settings);
4106: my %lt = <itools_names();
4107: my @courseroles = ('cc','in','ta','ep','st');
4108: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
4109: my @fields = ('fullname','firstname','lastname','email','user','roles');
4110: if (keys(%ordered)) {
4111: my @items = sort { $a <=> $b } keys(%ordered);
4112: for (my $i=0; $i<@items; $i++) {
4113: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4114: my $item = $ordered{$items[$i]};
1.317 raeburn 4115: my ($title,$key,$secret,$url,$imgsrc);
1.267 raeburn 4116: if (ref($settings->{$item}) eq 'HASH') {
4117: $title = $settings->{$item}->{'title'};
4118: $url = $settings->{$item}->{'url'};
4119: $key = $settings->{$item}->{'key'};
4120: $secret = $settings->{$item}->{'secret'};
4121: my $image = $settings->{$item}->{'image'};
4122: if ($image ne '') {
4123: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
4124: }
4125: }
1.319 raeburn 4126: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267 raeburn 4127: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4128: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
4129: for (my $k=0; $k<=$maxnum; $k++) {
4130: my $vpos = $k+1;
4131: my $selstr;
4132: if ($k == $i) {
4133: $selstr = ' selected="selected" ';
4134: }
4135: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4136: }
4137: $datatable .= '</select>'.(' 'x2).
4138: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4139: &mt('Delete?').'</label></span></td>'.
4140: '<td colspan="2">'.
4141: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4142: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
4143: (' 'x2).
4144: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4145: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4146: (' 'x2).
4147: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4148: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
4149: '<br /><br />'.
4150: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_url_'.$i.'"'.
4151: ' value="'.$url.'" /></span>'.
4152: (' 'x2).
1.319 raeburn 4153: '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267 raeburn 4154: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4155: (' 'x2).
4156: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4157: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4158: '<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>'.
4159: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4160: '</fieldset>'.
4161: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4162: '<span class="LC_nobreak">'.&mt('Display target:');
4163: my %currdisp;
4164: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4165: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4166: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 4167: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4168: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 4169: } else {
4170: $currdisp{'iframe'} = ' checked="checked"';
4171: }
4172: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4173: $currdisp{'width'} = $1;
4174: }
4175: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4176: $currdisp{'height'} = $1;
4177: }
1.296 raeburn 4178: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4179: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 4180: } else {
4181: $currdisp{'iframe'} = ' checked="checked"';
4182: }
1.298 raeburn 4183: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4184: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4185: $lt{$disp}.'</label>'.(' 'x2);
4186: }
4187: $datatable .= (' 'x4);
4188: foreach my $dimen ('width','height') {
4189: $datatable .= '<label>'.$lt{$dimen}.' '.
4190: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4191: (' 'x2);
4192: }
1.296 raeburn 4193: $datatable .= '<br />'.
4194: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
4195: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></label></div>'.
4196: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4197: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
4198: '</textarea></div><div style=""></div><br />';
1.319 raeburn 4199: my %units = (
4200: 'passback' => 'days',
4201: 'roster' => 'seconds',
4202: );
1.267 raeburn 4203: foreach my $extra ('passback','roster') {
1.319 raeburn 4204: my $validsty = 'none';
4205: my $currvalid;
1.267 raeburn 4206: my $checkedon = '';
4207: my $checkedoff = ' checked="checked"';
4208: if ($settings->{$item}->{$extra}) {
4209: $checkedon = $checkedoff;
4210: $checkedoff = '';
1.319 raeburn 4211: $validsty = 'inline-block';
4212: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
4213: $currvalid = $settings->{$item}->{$extra.'valid'};
4214: }
4215: }
4216: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
4217: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4218: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
4219: &mt('No').'</label>'.(' 'x2).
4220: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
4221: &mt('Yes').'</label></span></div>'.
4222: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
4223: '<span class="LC_nobreak">'.
4224: &mt("at least [_1] $units{$extra} after launch",
4225: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
4226: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4227: }
1.319 raeburn 4228: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
1.267 raeburn 4229: if ($imgsrc) {
4230: $datatable .= $imgsrc.
4231: '<label><input type="checkbox" name="ltitools_image_del"'.
4232: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
4233: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
4234: } else {
4235: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4236: }
4237: if ($switchserver) {
4238: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4239: } else {
4240: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
4241: }
4242: $datatable .= '</span></fieldset>';
4243: my (%checkedfields,%rolemaps);
4244: if (ref($settings->{$item}) eq 'HASH') {
4245: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
4246: %checkedfields = %{$settings->{$item}->{'fields'}};
4247: }
4248: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
4249: %rolemaps = %{$settings->{$item}->{'roles'}};
4250: $checkedfields{'roles'} = 1;
4251: }
4252: }
4253: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4254: '<span class="LC_nobreak">';
4255: foreach my $field (@fields) {
4256: my $checked;
4257: if ($checkedfields{$field}) {
4258: $checked = ' checked="checked"';
4259: }
4260: $datatable .= '<label>'.
4261: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
4262: $lt{$field}.'</label>'.(' ' x2);
4263: }
4264: $datatable .= '</span></fieldset>'.
4265: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4266: foreach my $role (@courseroles) {
4267: my ($selected,$selectnone);
4268: if (!$rolemaps{$role}) {
4269: $selectnone = ' selected="selected"';
4270: }
1.306 raeburn 4271: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4272: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4273: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
4274: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4275: foreach my $ltirole (@ltiroles) {
4276: unless ($selectnone) {
4277: if ($rolemaps{$role} eq $ltirole) {
4278: $selected = ' selected="selected"';
4279: } else {
4280: $selected = '';
4281: }
4282: }
4283: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
4284: }
4285: $datatable .= '</select></td>';
4286: }
1.273 raeburn 4287: $datatable .= '</tr></table></fieldset>';
4288: my %courseconfig;
4289: if (ref($settings->{$item}) eq 'HASH') {
4290: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
4291: %courseconfig = %{$settings->{$item}->{'crsconf'}};
4292: }
4293: }
4294: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4295: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 4296: my $checked;
4297: if ($courseconfig{$item}) {
4298: $checked = ' checked="checked"';
4299: }
4300: $datatable .= '<label>'.
4301: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
4302: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
4303: }
4304: $datatable .= '</span></fieldset>'.
1.267 raeburn 4305: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4306: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
4307: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
4308: my %custom = %{$settings->{$item}->{'custom'}};
4309: if (keys(%custom) > 0) {
4310: foreach my $key (sort(keys(%custom))) {
4311: $datatable .= '<tr><td><span class="LC_nobreak">'.
4312: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
4313: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
4314: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
4315: ' value="'.$custom{$key}.'" /></td></tr>';
4316: }
4317: }
4318: }
4319: $datatable .= '<tr><td><span class="LC_nobreak">'.
4320: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
4321: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
4322: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
4323: $datatable .= '</table></fieldset></td></tr>'."\n";
4324: $itemcount ++;
4325: }
4326: }
4327: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319 raeburn 4328: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267 raeburn 4329: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4330: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
4331: '<select name="ltitools_add_pos"'.$chgstr.'>';
4332: for (my $k=0; $k<$maxnum+1; $k++) {
4333: my $vpos = $k+1;
4334: my $selstr;
4335: if ($k == $maxnum) {
4336: $selstr = ' selected="selected" ';
4337: }
4338: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4339: }
4340: $datatable .= '</select> '."\n".
4341: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
4342: '<td colspan="2">'.
4343: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4344: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
4345: (' 'x2).
4346: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
4347: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4348: (' 'x2).
4349: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
4350: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
4351: '<br />'.
4352: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
4353: (' 'x2).
4354: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
4355: (' 'x2).
4356: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
4357: '<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".
4358: '</fieldset>'.
4359: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4360: '<span class="LC_nobreak">'.&mt('Display target:');
4361: my %defaultdisp;
4362: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 4363: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4364: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
4365: $lt{$disp}.'</label>'.(' 'x2);
4366: }
4367: $datatable .= (' 'x4);
4368: foreach my $dimen ('width','height') {
4369: $datatable .= '<label>'.$lt{$dimen}.' '.
4370: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
4371: (' 'x2);
4372: }
1.296 raeburn 4373: $datatable .= '<br />'.
4374: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
4375: '<input type="text" name="ltitools_add_linktext" size="5" /></label></div>'.
4376: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4377: '<textarea name=ltitools_add_explanation" rows="5" cols="40"></textarea>'.
4378: '</div><div style=""></div><br />';
1.319 raeburn 4379: my %units = (
4380: 'passback' => 'days',
4381: 'roster' => 'seconds',
4382: );
4383: my %defaulttimes = (
4384: 'passback' => '7',
4385: 'roster' => '300',
4386: );
1.267 raeburn 4387: foreach my $extra ('passback','roster') {
1.319 raeburn 4388: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
4389: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4390: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
4391: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
4392: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
4393: &mt('Yes').'</label></span></div>'.
4394: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
4395: '<span class="LC_nobreak">'.
4396: &mt("at least [_1] $units{$extra} after launch",
4397: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
4398: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4399: }
1.319 raeburn 4400: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
1.267 raeburn 4401: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4402: if ($switchserver) {
4403: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4404: } else {
4405: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
4406: }
4407: $datatable .= '</span></fieldset>'.
4408: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4409: '<span class="LC_nobreak">';
4410: foreach my $field (@fields) {
4411: $datatable .= '<label>'.
4412: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
4413: $lt{$field}.'</label>'.(' ' x2);
4414: }
4415: $datatable .= '</span></fieldset>'.
4416: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4417: foreach my $role (@courseroles) {
4418: my ($checked,$checkednone);
1.306 raeburn 4419: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4420: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4421: '<select name="ltitools_add_roles_'.$role.'">'.
4422: '<option value="" selected="selected">'.&mt('Select').'</option>';
4423: foreach my $ltirole (@ltiroles) {
4424: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
4425: }
4426: $datatable .= '</select></td>';
4427: }
4428: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 4429: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4430: foreach my $item ('label','title','target','linktext','explanation','append') {
1.296 raeburn 4431: $datatable .= '<label>'.
4432: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4433: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 4434: }
4435: $datatable .= '</span></fieldset>'.
1.267 raeburn 4436: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4437: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4438: '<tr><td><span class="LC_nobreak">'.
4439: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4440: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4441: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
4442: '</table></fieldset></td></tr>'."\n".
4443: '</td>'."\n".
4444: '</tr>'."\n";
4445: $itemcount ++;
4446: return $datatable;
4447: }
4448:
4449: sub ltitools_names {
4450: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 4451: 'title' => 'Title',
4452: 'version' => 'Version',
4453: 'msgtype' => 'Message Type',
4454: 'url' => 'URL',
4455: 'key' => 'Key',
4456: 'secret' => 'Secret',
4457: 'icon' => 'Icon',
4458: 'user' => 'Username:domain',
4459: 'fullname' => 'Full Name',
4460: 'firstname' => 'First Name',
4461: 'lastname' => 'Last Name',
4462: 'email' => 'E-mail',
4463: 'roles' => 'Role',
1.298 raeburn 4464: 'window' => 'Window',
4465: 'tab' => 'Tab',
1.296 raeburn 4466: 'iframe' => 'iFrame',
4467: 'height' => 'Height',
4468: 'width' => 'Width',
4469: 'linktext' => 'Default Link Text',
4470: 'explanation' => 'Default Explanation',
4471: 'passback' => 'Tool can return grades:',
4472: 'roster' => 'Tool can retrieve roster:',
4473: 'crstarget' => 'Display target',
4474: 'crslabel' => 'Course label',
4475: 'crstitle' => 'Course title',
4476: 'crslinktext' => 'Link Text',
4477: 'crsexplanation' => 'Explanation',
1.318 raeburn 4478: 'crsappend' => 'Provider URL',
1.267 raeburn 4479: );
4480: return %lt;
4481: }
4482:
1.320 raeburn 4483: sub print_lti {
4484: my ($dom,$settings,$rowtotal) = @_;
4485: my $itemcount = 1;
4486: my $maxnum = 0;
4487: my $css_class;
4488: my %ordered;
4489: if (ref($settings) eq 'HASH') {
4490: foreach my $item (keys(%{$settings})) {
4491: if (ref($settings->{$item}) eq 'HASH') {
4492: my $num = $settings->{$item}{'order'};
4493: $ordered{$num} = $item;
4494: }
4495: }
4496: }
4497: my $maxnum = scalar(keys(%ordered));
4498: my $datatable = <i_javascript($settings);
4499: my %lt = <i_names();
4500: if (keys(%ordered)) {
4501: my @items = sort { $a <=> $b } keys(%ordered);
4502: for (my $i=0; $i<@items; $i++) {
4503: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4504: my $item = $ordered{$items[$i]};
4505: my ($key,$secret,$lifetime,$consumer,$current);
4506: if (ref($settings->{$item}) eq 'HASH') {
4507: $key = $settings->{$item}->{'key'};
4508: $secret = $settings->{$item}->{'secret'};
4509: $lifetime = $settings->{$item}->{'lifetime'};
4510: $consumer = $settings->{$item}->{'consumer'};
4511: $current = $settings->{$item};
4512: }
4513: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
4514: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4515: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
4516: for (my $k=0; $k<=$maxnum; $k++) {
4517: my $vpos = $k+1;
4518: my $selstr;
4519: if ($k == $i) {
4520: $selstr = ' selected="selected" ';
4521: }
4522: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4523: }
4524: $datatable .= '</select>'.(' 'x2).
4525: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
4526: &mt('Delete?').'</label></span></td>'.
4527: '<td colspan="2">'.
4528: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4529: '<span class="LC_nobreak">'.$lt{'consumer'}.
4530: ':<input type="text" size="20" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
4531: (' 'x2).
4532: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
4533: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4534: (' 'x2).
4535: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
4536: 'value="'.$lifetime.'" size="5" /></span>'.
4537: '<br /><br />'.
4538: '<span class="LC_nobreak">'.$lt{'key'}.
4539: ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
4540: (' 'x2).
4541: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4542: '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
4543: '<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>'.
4544: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
4545: '</fieldset>'.<i_options($i,$current,%lt).'</td></tr>';
4546: $itemcount ++;
4547: }
4548: }
4549: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4550: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
4551: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4552: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
4553: '<select name="lti_pos_add"'.$chgstr.'>';
4554: for (my $k=0; $k<$maxnum+1; $k++) {
4555: my $vpos = $k+1;
4556: my $selstr;
4557: if ($k == $maxnum) {
4558: $selstr = ' selected="selected" ';
4559: }
4560: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4561: }
4562: $datatable .= '</select> '."\n".
4563: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</td>'."\n".
4564: '<td colspan="2">'.
4565: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4566: '<span class="LC_nobreak">'.$lt{'consumer'}.
4567: ':<input type="text" size="20" name="lti_consumer_add" value="" /></span> '."\n".
4568: (' 'x2).
4569: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
4570: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4571: (' 'x2).
4572: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="lti_lifetime_add" value="" /></span> '."\n".
4573: '<br /><br />'.
4574: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
4575: (' 'x2).
4576: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
4577: '<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".
4578: '</fieldset>'.<i_options('add',undef,%lt).
4579: '</td>'."\n".
4580: '</tr>'."\n";
4581: $$rowtotal ++;
4582: return $datatable;;
4583: }
4584:
4585: sub lti_names {
4586: my %lt = &Apache::lonlocal::texthash(
4587: 'version' => 'LTI Version',
4588: 'url' => 'URL',
4589: 'key' => 'Key',
4590: 'lifetime' => 'Nonce lifetime (seconds)',
4591: 'consumer' => 'LTI Consumer',
4592: 'secret' => 'Secret',
4593: 'email' => 'Email address',
4594: 'sourcedid' => 'User ID',
4595: 'other' => 'Other',
4596: 'passback' => 'Can return grades to Consumer:',
4597: 'roster' => 'Can retrieve roster from Consumer:',
4598: );
4599: return %lt;
4600: }
4601:
4602: sub lti_options {
4603: my ($num,$current,%lt) = @_;
4604: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield);
4605: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
4606: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
4607: $checked{'makecrs'}{'N'} = ' checked="checked"';
4608: $checked{'mapcrstype'} = {};
4609: $checked{'makeuser'} = {};
4610: $checked{'selfenroll'} = {};
4611: $checked{'crssec'} = {};
4612: $checked{'crssecsrc'} = {};
4613:
4614: my $userfieldsty = 'none';
4615: my $crsfieldsty = 'none';
4616: my $crssecfieldsty = 'none';
4617: my $secsrcfieldsty = 'none';
4618:
4619: if (ref($current) eq 'HASH') {
4620: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
4621: $checked{'mapuser'}{'sourcedid'} = '';
4622: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
4623: $checked{'mapuser'}{'email'} = ' checked="checked"';
4624: } else {
4625: $checked{'mapuser'}{'other'} = ' checked="checked"';
4626: $userfield = $current->{'mapuser'};
4627: $userfieldsty = 'inline-block';
4628: }
4629: }
4630: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
4631: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
4632: if ($current->{'mapcrs'} eq 'context_id') {
4633: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
4634: } else {
4635: $checked{'mapcrs'}{'other'} = ' checked="checked"';
4636: $cidfield = $current->{'mapcrs'};
4637: $crsfieldsty = 'inline-block';
4638: }
4639: }
4640: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
4641: foreach my $type (@{$current->{'mapcrstype'}}) {
4642: $checked{'mapcrstype'}{$type} = ' checked="checked"';
4643: }
4644: }
4645: if ($current->{'makecrs'}) {
4646: $checked{'makecrs'}{'Y'} = ' checked="checked"';
4647: }
4648: if (ref($current->{'makeuser'}) eq 'ARRAY') {
4649: foreach my $role (@{$current->{'makeuser'}}) {
4650: $checked{'makeuser'}{$role} = ' checked="checked"';
4651: }
4652: }
4653: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
4654: foreach my $role (@{$current->{'selfenroll'}}) {
4655: $checked{'selfenroll'}{$role} = ' checked="checked"';
4656: }
4657: }
4658: if (ref($current->{'maproles'}) eq 'HASH') {
4659: %rolemaps = %{$current->{'maproles'}};
4660: }
4661: if ($current->{'section'} ne '') {
4662: $checked{'crssec'}{'Y'} = ' checked="checked"';
4663: $crssecfieldsty = 'inline-block';
4664: if ($current->{'section'} eq 'course_section_sourcedid') {
4665: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
4666: } else {
4667: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
4668: $crssecsrc = $current->{'section'};
4669: $secsrcfieldsty = 'inline-block';
4670: }
4671: } else {
4672: $checked{'crssec'}{'N'} = ' checked="checked"';
4673: }
4674: } else {
4675: $checked{'makecrs'}{'N'} = ' checked="checked"';
4676: $checked{'crssec'}{'N'} = ' checked="checked"';
4677: }
4678: my @coursetypes = ('official','unofficial','community','textbook','placement');
4679: my %coursetypetitles = &Apache::lonlocal::texthash (
4680: official => 'Official',
4681: unofficial => 'Unofficial',
4682: community => 'Community',
4683: textbook => 'Textbook',
4684: placement => 'Placement Test',
4685: );
4686: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
4687: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
4688: my @courseroles = ('cc','in','ta','ep','st');
4689: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
4690: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
4691: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
4692: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
4693: my $output = '<fieldset><legend>'.&mt('Mapping users').'</legend>'.
4694: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
4695: foreach my $option ('sourcedid','email','other') {
4696: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
4697: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
4698: ($option eq 'other' ? '' : (' 'x2) );
4699: }
4700: $output .= '</span></div>'.
4701: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
4702: '<input type="text" name="lti_customuser_'.$num.'" '.
4703: 'value="'.$userfield.'" /></div></fieldset>'.
4704: '<fieldset><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
4705: foreach my $ltirole (@lticourseroles) {
4706: my ($selected,$selectnone);
4707: if ($rolemaps{$ltirole} eq '') {
4708: $selectnone = ' selected="selected"';
4709: }
4710: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
4711: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
4712: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4713: foreach my $role (@courseroles) {
4714: unless ($selectnone) {
4715: if ($rolemaps{$ltirole} eq $role) {
4716: $selected = ' selected="selected"';
4717: } else {
4718: $selected = '';
4719: }
4720: }
4721: $output .= '<option value="'.$role.'"'.$selected.'>'.
4722: &Apache::lonnet::plaintext($role,'Course').
4723: '</option>';
4724: }
4725: $output .= '</select></td>';
4726: }
4727: $output .= '</tr></table></fieldset>'.
4728: '<fieldset><legend>'.&mt('Roles which may create user accounts').'</legend>';
4729: foreach my $ltirole (@ltiroles) {
4730: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
4731: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
4732: }
4733: $output .= '</fieldset>'.
4734: '<fieldset><legend>'.&mt('Mapping courses').'</legend>'.
4735: '<div class="LC_floatleft"><span class="LC_nobreak">'.
4736: &mt('Unique course identifier').': ';
4737: foreach my $option ('course_offering_sourcedid','context_id','other') {
4738: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
4739: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
4740: ($option eq 'other' ? '' : (' 'x2) );
4741: }
4742: $output .= '</div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'".>'.
4743: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
4744: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
4745: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
4746: foreach my $type (@coursetypes) {
4747: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
4748: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
4749: (' 'x2);
4750: }
4751: $output .= '</span></fieldset>'.
4752: '<fieldset><legend>'.&mt('Creating courses').'</legend>'.
4753: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
4754: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
4755: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
4756: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
4757: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
4758: '</fieldset>'.
4759: '<fieldset><legend>'.&mt('Roles which may self-enroll').'</legend>';
4760: foreach my $lticrsrole (@lticourseroles) {
4761: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
4762: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
4763: }
4764: $output .= '</fieldset>'.
4765: '<fieldset><legend>'.&mt('Course options').'</legend>'.
4766: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
4767: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
4768: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
4769: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
4770: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label><span></div>'.
4771: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
4772: '<span class="LC_nobreak">'.&mt('From').':<label>'.
4773: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
4774: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
4775: &mt('Standard field').'</label>'.(' 'x2).
4776: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
4777: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
4778: '</label></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
4779: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
4780: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
4781: foreach my $extra ('passback','roster') {
4782: my $checkedon = '';
4783: my $checkedoff = ' checked="checked"';
4784: if (ref($current) eq 'HASH') {
4785: if (($current->{$extra})) {
4786: $checkedon = $checkedoff;
4787: $checkedoff = '';
4788: }
4789: }
4790: $output .= $lt{$extra}.' '.
4791: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.' />'.
4792: &mt('No').'</label>'.(' 'x2).
4793: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.' />'.
4794: &mt('Yes').'</label><br />';
4795: }
4796: $output .= '</span></fieldset>';
4797: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
4798: #
4799: # $output .= '</fieldset>'.
4800: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
4801: return $output;
4802: }
4803:
1.121 raeburn 4804: sub print_coursedefaults {
1.139 raeburn 4805: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 4806: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 4807: my $itemcount = 1;
1.192 raeburn 4808: my %choices = &Apache::lonlocal::texthash (
4809: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 4810: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 4811: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
4812: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 4813: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
4814: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.314 raeburn 4815: texengine => 'Default method to display mathematics',
1.257 raeburn 4816: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 4817: canclone => "People who may clone a course (besides course's owner and coordinators)",
4818: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 4819: );
1.198 raeburn 4820: my %staticdefaults = (
1.314 raeburn 4821: texengine => 'MathJax',
1.198 raeburn 4822: anonsurvey_threshold => 10,
4823: uploadquota => 500,
1.257 raeburn 4824: postsubmit => 60,
1.276 raeburn 4825: mysqltables => 172800,
1.198 raeburn 4826: );
1.139 raeburn 4827: if ($position eq 'top') {
1.257 raeburn 4828: %defaultchecked = (
4829: 'canuse_pdfforms' => 'off',
4830: 'uselcmath' => 'on',
4831: 'usejsme' => 'on',
1.289 raeburn 4832: 'canclone' => 'none',
1.257 raeburn 4833: );
4834: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.314 raeburn 4835: my $deftex = $staticdefaults{'texengine'};
4836: if (ref($settings) eq 'HASH') {
4837: if ($settings->{'texengine'}) {
4838: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
4839: $deftex = $settings->{'texengine'};
4840: }
4841: }
4842: }
4843: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4844: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
4845: '<span class="LC_nobreak">'.$choices{'texengine'}.
4846: '</span></td><td class="LC_right_item">'.
4847: '<select name="texengine">'."\n";
4848: my %texoptions = (
4849: MathJax => 'MathJax',
4850: mimetex => &mt('Convert to Images'),
4851: tth => &mt('TeX to HTML'),
4852: );
4853: foreach my $renderer ('MathJax','mimetex','tth') {
4854: my $selected = '';
4855: if ($renderer eq $deftex) {
4856: $selected = ' selected="selected"';
4857: }
4858: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
4859: }
4860: $mathdisp .= '</select></td></tr>'."\n";
4861: $itemcount ++;
1.139 raeburn 4862: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 4863: \%choices,$itemcount);
1.314 raeburn 4864: $datatable = $mathdisp.$datatable;
1.264 raeburn 4865: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4866: $datatable .=
1.306 raeburn 4867: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 4868: '<span class="LC_nobreak">'.$choices{'canclone'}.
4869: '</span></td><td class="LC_left_item">';
4870: my $currcanclone = 'none';
4871: my $onclick;
4872: my @cloneoptions = ('none','domain');
4873: my %clonetitles = (
4874: none => 'No additional course requesters',
4875: domain => "Any course requester in course's domain",
4876: instcode => 'Course requests for official courses ...',
4877: );
4878: my (%codedefaults,@code_order,@posscodes);
4879: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
4880: \@code_order) eq 'ok') {
4881: if (@code_order > 0) {
4882: push(@cloneoptions,'instcode');
4883: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
4884: }
4885: }
4886: if (ref($settings) eq 'HASH') {
4887: if ($settings->{'canclone'}) {
4888: if (ref($settings->{'canclone'}) eq 'HASH') {
4889: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
4890: if (@code_order > 0) {
4891: $currcanclone = 'instcode';
4892: @posscodes = @{$settings->{'canclone'}{'instcode'}};
4893: }
4894: }
4895: } elsif ($settings->{'canclone'} eq 'domain') {
4896: $currcanclone = $settings->{'canclone'};
4897: }
4898: }
1.289 raeburn 4899: }
1.264 raeburn 4900: foreach my $option (@cloneoptions) {
4901: my ($checked,$additional);
4902: if ($currcanclone eq $option) {
4903: $checked = ' checked="checked"';
4904: }
4905: if ($option eq 'instcode') {
4906: if (@code_order) {
4907: my $show = 'none';
4908: if ($checked) {
4909: $show = 'block';
4910: }
1.317 raeburn 4911: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 4912: &mt('Institutional codes for new and cloned course have identical:').
4913: '<br />';
4914: foreach my $item (@code_order) {
4915: my $codechk;
4916: if ($checked) {
4917: if (grep(/^\Q$item\E$/,@posscodes)) {
4918: $codechk = ' checked="checked"';
4919: }
4920: }
4921: $additional .= '<label>'.
4922: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
4923: $item.'</label>';
4924: }
4925: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
4926: }
4927: }
4928: $datatable .=
4929: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
4930: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
4931: '</label> '.$additional.'</span><br />';
4932: }
4933: $datatable .= '</td>'.
4934: '</tr>';
4935: $itemcount ++;
1.139 raeburn 4936: } else {
4937: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 4938: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 4939: my $currusecredits = 0;
1.257 raeburn 4940: my $postsubmitclient = 1;
1.271 raeburn 4941: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 4942: if (ref($settings) eq 'HASH') {
4943: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 4944: if (ref($settings->{'uploadquota'}) eq 'HASH') {
4945: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
4946: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
4947: }
4948: }
1.192 raeburn 4949: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 4950: foreach my $type (@types) {
4951: next if ($type eq 'community');
4952: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
4953: if ($defcredits{$type} ne '') {
4954: $currusecredits = 1;
4955: }
4956: }
4957: }
4958: if (ref($settings->{'postsubmit'}) eq 'HASH') {
4959: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
4960: $postsubmitclient = 0;
4961: foreach my $type (@types) {
4962: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4963: }
4964: } else {
4965: foreach my $type (@types) {
4966: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
4967: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 4968: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 4969: } else {
4970: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4971: }
4972: } else {
4973: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4974: }
4975: }
4976: }
4977: } else {
4978: foreach my $type (@types) {
4979: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 4980: }
4981: }
1.276 raeburn 4982: if (ref($settings->{'mysqltables'}) eq 'HASH') {
4983: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
4984: $currmysql{$type} = $settings->{'mysqltables'}{$type};
4985: }
4986: } else {
4987: foreach my $type (@types) {
4988: $currmysql{$type} = $staticdefaults{'mysqltables'};
4989: }
4990: }
1.258 raeburn 4991: } else {
4992: foreach my $type (@types) {
4993: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4994: }
1.139 raeburn 4995: }
4996: if (!$currdefresponder) {
1.198 raeburn 4997: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 4998: } elsif ($currdefresponder < 1) {
4999: $currdefresponder = 1;
5000: }
1.198 raeburn 5001: foreach my $type (@types) {
5002: if ($curruploadquota{$type} eq '') {
5003: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
5004: }
5005: }
1.139 raeburn 5006: $datatable .=
1.192 raeburn 5007: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5008: $choices{'anonsurvey_threshold'}.
1.139 raeburn 5009: '</span></td>'.
5010: '<td class="LC_right_item"><span class="LC_nobreak">'.
5011: '<input type="text" name="anonsurvey_threshold"'.
5012: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 5013: '</td></tr>'."\n";
5014: $itemcount ++;
5015: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5016: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5017: $choices{'uploadquota'}.
5018: '</span></td>'.
1.306 raeburn 5019: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 5020: '<table><tr>';
1.198 raeburn 5021: foreach my $type (@types) {
1.306 raeburn 5022: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 5023: '<input type="text" name="uploadquota_'.$type.'"'.
5024: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
5025: }
5026: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 5027: $itemcount ++;
1.236 raeburn 5028: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 5029: my $display = 'none';
1.192 raeburn 5030: if ($currusecredits) {
5031: $display = 'block';
5032: }
5033: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 5034: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
5035: foreach my $type (@types) {
5036: next if ($type eq 'community');
1.306 raeburn 5037: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5038: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 5039: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 5040: }
5041: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 5042: %defaultchecked = ('coursecredits' => 'off');
5043: @toggles = ('coursecredits');
5044: my $current = {
5045: 'coursecredits' => $currusecredits,
5046: };
5047: (my $table,$itemcount) =
5048: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 5049: \%choices,$itemcount,$onclick,$additional,'left');
5050: $datatable .= $table;
5051: $onclick = "toggleDisplay(this.form,'studentsubmission');";
5052: my $display = 'none';
5053: if ($postsubmitclient) {
5054: $display = 'block';
5055: }
5056: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 5057: &mt('Number of seconds submit is disabled').'<br />'.
5058: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
5059: '<table><tr>';
1.257 raeburn 5060: foreach my $type (@types) {
1.306 raeburn 5061: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5062: '<input type="text" name="'.$type.'_timeout" value="'.
5063: $deftimeout{$type}.'" size="5" /></td>';
5064: }
5065: $additional .= '</tr></table></div>'."\n";
5066: %defaultchecked = ('postsubmit' => 'on');
5067: @toggles = ('postsubmit');
1.280 raeburn 5068: $current = {
5069: 'postsubmit' => $postsubmitclient,
5070: };
1.257 raeburn 5071: ($table,$itemcount) =
5072: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
5073: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 5074: $datatable .= $table;
1.276 raeburn 5075: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5076: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5077: $choices{'mysqltables'}.
5078: '</span></td>'.
1.306 raeburn 5079: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 5080: '<table><tr>';
5081: foreach my $type (@types) {
1.306 raeburn 5082: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 5083: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 5084: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 5085: }
5086: $datatable .= '</tr></table></td></tr>'."\n";
5087: $itemcount ++;
5088:
1.139 raeburn 5089: }
1.192 raeburn 5090: $$rowtotal += $itemcount;
1.121 raeburn 5091: return $datatable;
1.118 jms 5092: }
5093:
1.231 raeburn 5094: sub print_selfenrollment {
5095: my ($position,$dom,$settings,$rowtotal) = @_;
5096: my ($css_class,$datatable);
5097: my $itemcount = 1;
1.271 raeburn 5098: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 5099: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 5100: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
5101: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 5102: my @rows;
5103: my $key;
5104: if ($position eq 'top') {
5105: $key = 'admin';
5106: if (ref($rowsref) eq 'ARRAY') {
5107: @rows = @{$rowsref};
5108: }
5109: } elsif ($position eq 'middle') {
5110: $key = 'default';
5111: @rows = ('types','registered','approval','limit');
5112: }
5113: foreach my $row (@rows) {
5114: if (defined($titlesref->{$row})) {
5115: $itemcount ++;
5116: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5117: $datatable .= '<tr'.$css_class.'>'.
5118: '<td>'.$titlesref->{$row}.'</td>'.
5119: '<td class="LC_left_item">'.
5120: '<table><tr>';
5121: my (%current,%currentcap);
5122: if (ref($settings) eq 'HASH') {
5123: if (ref($settings->{$key}) eq 'HASH') {
5124: foreach my $type (@types) {
5125: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5126: $current{$type} = $settings->{$key}->{$type}->{$row};
5127: }
5128: if (($row eq 'limit') && ($key eq 'default')) {
5129: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5130: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
5131: }
5132: }
5133: }
5134: }
5135: }
5136: my %roles = (
5137: '0' => &Apache::lonnet::plaintext('dc'),
5138: );
5139:
5140: foreach my $type (@types) {
5141: unless (($row eq 'registered') && ($key eq 'default')) {
5142: $datatable .= '<th>'.&mt($type).'</th>';
5143: }
5144: }
5145: unless (($row eq 'registered') && ($key eq 'default')) {
5146: $datatable .= '</tr><tr>';
5147: }
5148: foreach my $type (@types) {
5149: if ($type eq 'community') {
5150: $roles{'1'} = &mt('Community personnel');
5151: } else {
5152: $roles{'1'} = &mt('Course personnel');
5153: }
5154: $datatable .= '<td style="vertical-align: top">';
5155: if ($position eq 'top') {
5156: my %checked;
5157: if ($current{$type} eq '0') {
5158: $checked{'0'} = ' checked="checked"';
5159: } else {
5160: $checked{'1'} = ' checked="checked"';
5161: }
5162: foreach my $role ('1','0') {
5163: $datatable .= '<span class="LC_nobreak"><label>'.
5164: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
5165: 'value="'.$role.'"'.$checked{$role}.' />'.
5166: $roles{$role}.'</label></span> ';
5167: }
5168: } else {
5169: if ($row eq 'types') {
5170: my %checked;
5171: if ($current{$type} =~ /^(all|dom)$/) {
5172: $checked{$1} = ' checked="checked"';
5173: } else {
5174: $checked{''} = ' checked="checked"';
5175: }
5176: foreach my $val ('','dom','all') {
5177: $datatable .= '<span class="LC_nobreak"><label>'.
5178: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5179: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5180: }
5181: } elsif ($row eq 'registered') {
5182: my %checked;
5183: if ($current{$type} eq '1') {
5184: $checked{'1'} = ' checked="checked"';
5185: } else {
5186: $checked{'0'} = ' checked="checked"';
5187: }
5188: foreach my $val ('0','1') {
5189: $datatable .= '<span class="LC_nobreak"><label>'.
5190: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5191: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5192: }
5193: } elsif ($row eq 'approval') {
5194: my %checked;
5195: if ($current{$type} =~ /^([12])$/) {
5196: $checked{$1} = ' checked="checked"';
5197: } else {
5198: $checked{'0'} = ' checked="checked"';
5199: }
5200: for my $val (0..2) {
5201: $datatable .= '<span class="LC_nobreak"><label>'.
5202: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5203: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5204: }
5205: } elsif ($row eq 'limit') {
5206: my %checked;
5207: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
5208: $checked{$1} = ' checked="checked"';
5209: } else {
5210: $checked{'none'} = ' checked="checked"';
5211: }
5212: my $cap;
5213: if ($currentcap{$type} =~ /^\d+$/) {
5214: $cap = $currentcap{$type};
5215: }
5216: foreach my $val ('none','allstudents','selfenrolled') {
5217: $datatable .= '<span class="LC_nobreak"><label>'.
5218: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5219: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5220: }
5221: $datatable .= '<br />'.
5222: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
5223: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
5224: '</span>';
5225: }
5226: }
5227: $datatable .= '</td>';
5228: }
5229: $datatable .= '</tr>';
5230: }
5231: $datatable .= '</table></td></tr>';
5232: }
5233: } elsif ($position eq 'bottom') {
1.235 raeburn 5234: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
5235: }
5236: $$rowtotal += $itemcount;
5237: return $datatable;
5238: }
5239:
5240: sub print_validation_rows {
5241: my ($caller,$dom,$settings,$rowtotal) = @_;
5242: my ($itemsref,$namesref,$fieldsref);
5243: if ($caller eq 'selfenroll') {
5244: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
5245: } elsif ($caller eq 'requestcourses') {
5246: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
5247: }
5248: my %currvalidation;
5249: if (ref($settings) eq 'HASH') {
5250: if (ref($settings->{'validation'}) eq 'HASH') {
5251: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 5252: }
1.235 raeburn 5253: }
5254: my $datatable;
5255: my $itemcount = 0;
5256: foreach my $item (@{$itemsref}) {
5257: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5258: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5259: $namesref->{$item}.
5260: '</span></td>'.
5261: '<td class="LC_left_item">';
5262: if (($item eq 'url') || ($item eq 'button')) {
5263: $datatable .= '<span class="LC_nobreak">'.
5264: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
5265: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
5266: } elsif ($item eq 'fields') {
5267: my @currfields;
5268: if (ref($currvalidation{$item}) eq 'ARRAY') {
5269: @currfields = @{$currvalidation{$item}};
5270: }
5271: foreach my $field (@{$fieldsref}) {
5272: my $check = '';
5273: if (grep(/^\Q$field\E$/,@currfields)) {
5274: $check = ' checked="checked"';
5275: }
5276: $datatable .= '<span class="LC_nobreak"><label>'.
5277: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
5278: ' value="'.$field.'"'.$check.' />'.$field.
5279: '</label></span> ';
5280: }
5281: } elsif ($item eq 'markup') {
5282: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
5283: $currvalidation{$item}.
1.231 raeburn 5284: '</textarea>';
1.235 raeburn 5285: }
5286: $datatable .= '</td></tr>'."\n";
5287: if (ref($rowtotal)) {
1.231 raeburn 5288: $itemcount ++;
5289: }
5290: }
1.235 raeburn 5291: if ($caller eq 'requestcourses') {
5292: my %currhash;
1.248 raeburn 5293: if (ref($settings) eq 'HASH') {
5294: if (ref($settings->{'validation'}) eq 'HASH') {
5295: if ($settings->{'validation'}{'dc'} ne '') {
5296: $currhash{$settings->{'validation'}{'dc'}} = 1;
5297: }
1.235 raeburn 5298: }
5299: }
5300: my $numinrow = 2;
5301: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
5302: 'validationdc',%currhash);
1.247 raeburn 5303: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5304: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235 raeburn 5305: if ($numdc > 1) {
1.247 raeburn 5306: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 5307: } else {
1.247 raeburn 5308: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 5309: }
1.247 raeburn 5310: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 5311: $itemcount ++;
5312: }
5313: if (ref($rowtotal)) {
5314: $$rowtotal += $itemcount;
5315: }
1.231 raeburn 5316: return $datatable;
5317: }
5318:
1.137 raeburn 5319: sub print_usersessions {
5320: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 5321: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 5322: my (%by_ip,%by_location,@intdoms,@instdoms);
5323: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 5324:
5325: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 5326: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 5327: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 5328: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 5329: if ($position eq 'top') {
1.152 raeburn 5330: if (keys(%serverhomes) > 1) {
1.145 raeburn 5331: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 5332: my $curroffloadnow;
5333: if (ref($settings) eq 'HASH') {
5334: if (ref($settings->{'offloadnow'}) eq 'HASH') {
5335: $curroffloadnow = $settings->{'offloadnow'};
5336: }
5337: }
5338: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 5339: } else {
1.140 raeburn 5340: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 5341: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
5342: '</td></tr>';
1.140 raeburn 5343: }
1.137 raeburn 5344: } else {
1.279 raeburn 5345: my %titles = &usersession_titles();
5346: my ($prefix,@types);
5347: if ($position eq 'bottom') {
5348: $prefix = 'remote';
5349: @types = ('version','excludedomain','includedomain');
1.145 raeburn 5350: } else {
1.279 raeburn 5351: $prefix = 'hosted';
5352: @types = ('excludedomain','includedomain');
5353: }
5354: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
5355: }
5356: $$rowtotal += $itemcount;
5357: return $datatable;
5358: }
5359:
5360: sub rules_by_location {
5361: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
5362: my ($datatable,$itemcount,$css_class);
5363: if (keys(%{$by_location}) == 0) {
5364: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5365: $datatable = '<tr'.$css_class.'><td colspan="2">'.
5366: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
5367: '</td></tr>';
5368: $itemcount = 1;
5369: } else {
5370: $itemcount = 0;
5371: my $numinrow = 5;
5372: my (%current,%checkedon,%checkedoff);
5373: my @locations = sort(keys(%{$by_location}));
5374: foreach my $type (@{$types}) {
5375: $checkedon{$type} = '';
5376: $checkedoff{$type} = ' checked="checked"';
5377: }
5378: if (ref($settings) eq 'HASH') {
5379: if (ref($settings->{$prefix}) eq 'HASH') {
5380: foreach my $key (keys(%{$settings->{$prefix}})) {
5381: $current{$key} = $settings->{$prefix}{$key};
5382: if ($key eq 'version') {
5383: if ($current{$key} ne '') {
1.145 raeburn 5384: $checkedon{$key} = ' checked="checked"';
5385: $checkedoff{$key} = '';
5386: }
1.279 raeburn 5387: } elsif (ref($current{$key}) eq 'ARRAY') {
5388: $checkedon{$key} = ' checked="checked"';
5389: $checkedoff{$key} = '';
1.137 raeburn 5390: }
5391: }
5392: }
1.279 raeburn 5393: }
5394: foreach my $type (@{$types}) {
5395: next if ($type ne 'version' && !@locations);
5396: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5397: $datatable .= '<tr'.$css_class.'>
5398: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
5399: <span class="LC_nobreak">
5400: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
5401: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
5402: if ($type eq 'version') {
5403: my @lcversions = &Apache::lonnet::all_loncaparevs();
5404: my $selector = '<select name="'.$prefix.'_version">';
5405: foreach my $version (@lcversions) {
5406: my $selected = '';
5407: if ($current{'version'} eq $version) {
5408: $selected = ' selected="selected"';
1.145 raeburn 5409: }
1.279 raeburn 5410: $selector .= ' <option value="'.$version.'"'.
5411: $selected.'>'.$version.'</option>';
5412: }
5413: $selector .= '</select> ';
5414: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
5415: } else {
5416: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
5417: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
5418: ' />'.(' 'x2).
5419: '<input type="button" value="'.&mt('uncheck all').'" '.
5420: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
5421: "\n".
5422: '</div><div><table>';
5423: my $rem;
5424: for (my $i=0; $i<@locations; $i++) {
5425: my ($showloc,$value,$checkedtype);
5426: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
5427: my $ip = $by_location->{$locations[$i]}->[0];
5428: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5429: $value = join(':',@{$by_ip->{$ip}});
5430: $showloc = join(', ',@{$by_ip->{$ip}});
5431: if (ref($current{$type}) eq 'ARRAY') {
5432: foreach my $loc (@{$by_ip->{$ip}}) {
5433: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
5434: $checkedtype = ' checked="checked"';
5435: last;
1.145 raeburn 5436: }
1.138 raeburn 5437: }
5438: }
5439: }
1.137 raeburn 5440: }
1.279 raeburn 5441: $rem = $i%($numinrow);
5442: if ($rem == 0) {
5443: if ($i > 0) {
5444: $datatable .= '</tr>';
5445: }
5446: $datatable .= '<tr>';
5447: }
5448: $datatable .= '<td class="LC_left_item">'.
5449: '<span class="LC_nobreak"><label>'.
5450: '<input type="checkbox" name="'.$prefix.'_'.$type.
5451: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
5452: '</label></span></td>';
5453: }
5454: $rem = @locations%($numinrow);
5455: my $colsleft = $numinrow - $rem;
5456: if ($colsleft > 1 ) {
5457: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5458: ' </td>';
5459: } elsif ($colsleft == 1) {
5460: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 5461: }
1.279 raeburn 5462: $datatable .= '</tr></table>';
1.137 raeburn 5463: }
1.279 raeburn 5464: $datatable .= '</td></tr>';
5465: $itemcount ++;
1.137 raeburn 5466: }
5467: }
1.279 raeburn 5468: return ($datatable,$itemcount);
1.137 raeburn 5469: }
5470:
1.275 raeburn 5471: sub print_ssl {
5472: my ($position,$dom,$settings,$rowtotal) = @_;
5473: my ($css_class,$datatable);
5474: my $itemcount = 1;
5475: if ($position eq 'top') {
1.281 raeburn 5476: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5477: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5478: my $same_institution;
5479: if ($intdom ne '') {
5480: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
5481: if (ref($internet_names) eq 'ARRAY') {
5482: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
5483: $same_institution = 1;
5484: }
5485: }
5486: }
1.275 raeburn 5487: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 5488: $datatable = '<tr'.$css_class.'><td colspan="2">';
5489: if ($same_institution) {
5490: my %domservers = &Apache::lonnet::get_servers($dom);
5491: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
5492: } else {
5493: $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.");
5494: }
5495: $datatable .= '</td></tr>';
1.275 raeburn 5496: $itemcount ++;
5497: } else {
5498: my %titles = &ssl_titles();
5499: my (%by_ip,%by_location,@intdoms,@instdoms);
5500: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
5501: my @alldoms = &Apache::lonnet::all_domains();
5502: my %serverhomes = %Apache::lonnet::serverhomeIDs;
5503: my @domservers = &Apache::lonnet::get_servers($dom);
5504: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5505: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 5506: if (($position eq 'connto') || ($position eq 'connfrom')) {
5507: my $legacy;
5508: unless (ref($settings) eq 'HASH') {
5509: my $name;
5510: if ($position eq 'connto') {
5511: $name = 'loncAllowInsecure';
5512: } else {
5513: $name = 'londAllowInsecure';
5514: }
5515: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
5516: my @ids=&Apache::lonnet::current_machine_ids();
5517: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
5518: my %what = (
5519: $name => 1,
5520: );
5521: my ($result,$returnhash) =
5522: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
5523: if ($result eq 'ok') {
5524: if (ref($returnhash) eq 'HASH') {
5525: $legacy = $returnhash->{$name};
5526: }
5527: }
5528: } else {
5529: $legacy = $Apache::lonnet::perlvar{$name};
5530: }
5531: }
1.275 raeburn 5532: foreach my $type ('dom','intdom','other') {
5533: my %checked;
5534: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5535: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
5536: '<td class="LC_right_item">';
5537: my $skip;
5538: if ($type eq 'dom') {
5539: unless (keys(%servers) > 1) {
5540: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
5541: $skip = 1;
5542: }
5543: }
5544: if ($type eq 'intdom') {
5545: unless (@instdoms > 1) {
5546: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
5547: $skip = 1;
5548: }
5549: } elsif ($type eq 'other') {
5550: if (keys(%by_location) == 0) {
5551: $datatable .= &mt('Nothing to set here, as there are no other institutions');
5552: $skip = 1;
5553: }
5554: }
5555: unless ($skip) {
5556: $checked{'yes'} = ' checked="checked"';
5557: if (ref($settings) eq 'HASH') {
1.293 raeburn 5558: if (ref($settings->{$position}) eq 'HASH') {
5559: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 5560: $checked{$1} = $checked{'yes'};
5561: delete($checked{'yes'});
5562: }
5563: }
1.293 raeburn 5564: } else {
5565: if ($legacy == 0) {
5566: $checked{'req'} = $checked{'yes'};
5567: delete($checked{'yes'});
5568: }
1.275 raeburn 5569: }
5570: foreach my $option ('no','yes','req') {
5571: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 5572: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 5573: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
5574: '</label></span>'.(' 'x2);
5575: }
5576: }
5577: $datatable .= '</td></tr>';
5578: $itemcount ++;
5579: }
5580: } else {
5581: my $prefix = 'replication';
5582: my @types = ('certreq','nocertreq');
1.279 raeburn 5583: if (keys(%by_location) == 0) {
5584: $datatable .= '<tr'.$css_class.'><td>'.
5585: &mt('Nothing to set here, as there are no other institutions').
5586: '</td></tr>';
5587: $itemcount ++;
1.275 raeburn 5588: } else {
1.279 raeburn 5589: ($datatable,$itemcount) =
5590: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 5591: }
5592: }
5593: }
5594: $$rowtotal += $itemcount;
5595: return $datatable;
5596: }
5597:
5598: sub ssl_titles {
5599: return &Apache::lonlocal::texthash (
5600: dom => 'LON-CAPA servers/VMs from same domain',
5601: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
5602: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 5603: connto => 'Connections to other servers',
5604: connfrom => 'Connections from other servers',
1.275 raeburn 5605: replication => 'Replicating content to other institutions',
5606: certreq => 'Client certificate required, but specific domains exempt',
5607: nocertreq => 'No client certificate required, except for specific domains',
5608: no => 'SSL not used',
5609: yes => 'SSL Optional (used if available)',
5610: req => 'SSL Required',
5611: );
1.279 raeburn 5612: }
5613:
5614: sub print_trust {
5615: my ($prefix,$dom,$settings,$rowtotal) = @_;
5616: my ($css_class,$datatable,%checked,%choices);
5617: my (%by_ip,%by_location,@intdoms,@instdoms);
5618: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
5619: my $itemcount = 1;
5620: my %titles = &trust_titles();
5621: my @types = ('exc','inc');
5622: if ($prefix eq 'top') {
5623: $prefix = 'content';
5624: } elsif ($prefix eq 'bottom') {
5625: $prefix = 'msg';
5626: }
5627: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
5628: $$rowtotal += $itemcount;
5629: return $datatable;
5630: }
5631:
5632: sub trust_titles {
5633: return &Apache::lonlocal::texthash(
5634: content => "Access to this domain's content by others",
5635: shared => "Access to other domain's content by this domain",
5636: enroll => "Enrollment in this domain's courses by others",
5637: othcoau => "Co-author roles in this domain for others",
5638: coaurem => "Co-author roles for this domain's users elsewhere",
5639: domroles => "Domain roles in this domain assignable to others",
5640: catalog => "Course Catalog for this domain displayed elsewhere",
5641: reqcrs => "Requests for creation of courses in this domain by others",
5642: msg => "Users in other domains can send messages to this domain",
5643: exc => "Allow all, but exclude specific domains",
5644: inc => "Deny all, but include specific domains",
5645: );
1.275 raeburn 5646: }
5647:
1.138 raeburn 5648: sub build_location_hashes {
1.275 raeburn 5649: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 5650: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 5651: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 5652: my %iphost = &Apache::lonnet::get_iphost();
5653: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
5654: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
5655: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
5656: foreach my $id (@{$iphost{$primary_ip}}) {
5657: my $intdom = &Apache::lonnet::internet_dom($id);
5658: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
5659: push(@{$intdoms},$intdom);
5660: }
5661: }
5662: }
5663: foreach my $ip (keys(%iphost)) {
5664: if (ref($iphost{$ip}) eq 'ARRAY') {
5665: foreach my $id (@{$iphost{$ip}}) {
5666: my $location = &Apache::lonnet::internet_dom($id);
5667: if ($location) {
1.275 raeburn 5668: if (grep(/^\Q$location\E$/,@{$intdoms})) {
5669: my $dom = &Apache::lonnet::host_domain($id);
5670: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
5671: push(@{$instdoms},$dom);
5672: }
5673: next;
5674: }
1.138 raeburn 5675: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5676: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
5677: push(@{$by_ip->{$ip}},$location);
5678: }
5679: } else {
5680: $by_ip->{$ip} = [$location];
5681: }
5682: }
5683: }
5684: }
5685: }
5686: foreach my $ip (sort(keys(%{$by_ip}))) {
5687: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5688: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
5689: my $first = $by_ip->{$ip}->[0];
5690: if (ref($by_location->{$first}) eq 'ARRAY') {
5691: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
5692: push(@{$by_location->{$first}},$ip);
5693: }
5694: } else {
5695: $by_location->{$first} = [$ip];
5696: }
5697: }
5698: }
5699: return;
5700: }
5701:
1.145 raeburn 5702: sub current_offloads_to {
5703: my ($dom,$settings,$servers) = @_;
5704: my (%spareid,%otherdomconfigs);
1.152 raeburn 5705: if (ref($servers) eq 'HASH') {
1.145 raeburn 5706: foreach my $lonhost (sort(keys(%{$servers}))) {
5707: my $gotspares;
1.152 raeburn 5708: if (ref($settings) eq 'HASH') {
5709: if (ref($settings->{'spares'}) eq 'HASH') {
5710: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
5711: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
5712: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
5713: $gotspares = 1;
5714: }
1.145 raeburn 5715: }
5716: }
5717: unless ($gotspares) {
5718: my $gotspares;
5719: my $serverhomeID =
5720: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
5721: my $serverhomedom =
5722: &Apache::lonnet::host_domain($serverhomeID);
5723: if ($serverhomedom ne $dom) {
5724: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
5725: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5726: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5727: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5728: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5729: $gotspares = 1;
5730: }
5731: }
5732: } else {
5733: $otherdomconfigs{$serverhomedom} =
5734: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
5735: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
5736: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5737: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5738: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
5739: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5740: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5741: $gotspares = 1;
5742: }
5743: }
5744: }
5745: }
5746: }
5747: }
5748: }
5749: unless ($gotspares) {
5750: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
5751: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5752: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5753: } else {
5754: my $server_hostname = &Apache::lonnet::hostname($lonhost);
5755: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
5756: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
5757: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5758: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5759: } else {
1.150 raeburn 5760: my %what = (
5761: spareid => 1,
5762: );
5763: my ($result,$returnhash) =
5764: &Apache::lonnet::get_remote_globals($lonhost,\%what);
5765: if ($result eq 'ok') {
5766: if (ref($returnhash) eq 'HASH') {
5767: if (ref($returnhash->{'spareid'}) eq 'HASH') {
5768: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
5769: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
5770: }
5771: }
1.145 raeburn 5772: }
5773: }
5774: }
5775: }
5776: }
5777: }
5778: return %spareid;
5779: }
5780:
5781: sub spares_row {
1.261 raeburn 5782: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 5783: my $css_class;
5784: my $numinrow = 4;
5785: my $itemcount = 1;
5786: my $datatable;
1.152 raeburn 5787: my %typetitles = &sparestype_titles();
5788: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 5789: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 5790: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
5791: my ($othercontrol,$serverdom);
5792: if ($serverhome ne $server) {
5793: $serverdom = &Apache::lonnet::host_domain($serverhome);
5794: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5795: } else {
5796: $serverdom = &Apache::lonnet::host_domain($server);
5797: if ($serverdom ne $dom) {
5798: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5799: }
5800: }
5801: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 5802: my $checkednow;
5803: if (ref($curroffloadnow) eq 'HASH') {
5804: if ($curroffloadnow->{$server}) {
5805: $checkednow = ' checked="checked"';
5806: }
5807: }
1.145 raeburn 5808: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5809: $datatable .= '<tr'.$css_class.'>
5810: <td rowspan="2">
1.183 bisitz 5811: <span class="LC_nobreak">'.
5812: &mt('[_1] when busy, offloads to:'
1.261 raeburn 5813: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 5814: '<span class="LC_nobreak">'."\n".
1.261 raeburn 5815: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
5816: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 5817: "\n";
1.145 raeburn 5818: my (%current,%canselect);
1.152 raeburn 5819: my @choices =
5820: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
5821: foreach my $type ('primary','default') {
5822: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 5823: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
5824: my @spares = @{$spareid->{$server}{$type}};
5825: if (@spares > 0) {
1.152 raeburn 5826: if ($othercontrol) {
5827: $current{$type} = join(', ',@spares);
5828: } else {
5829: $current{$type} .= '<table>';
5830: my $numspares = scalar(@spares);
5831: for (my $i=0; $i<@spares; $i++) {
5832: my $rem = $i%($numinrow);
5833: if ($rem == 0) {
5834: if ($i > 0) {
5835: $current{$type} .= '</tr>';
5836: }
5837: $current{$type} .= '<tr>';
1.145 raeburn 5838: }
1.152 raeburn 5839: $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'".');" /> '.
5840: $spareid->{$server}{$type}[$i].
5841: '</label></td>'."\n";
5842: }
5843: my $rem = @spares%($numinrow);
5844: my $colsleft = $numinrow - $rem;
5845: if ($colsleft > 1 ) {
5846: $current{$type} .= '<td colspan="'.$colsleft.
5847: '" class="LC_left_item">'.
5848: ' </td>';
5849: } elsif ($colsleft == 1) {
5850: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 5851: }
1.152 raeburn 5852: $current{$type} .= '</tr></table>';
1.150 raeburn 5853: }
1.145 raeburn 5854: }
5855: }
5856: if ($current{$type} eq '') {
5857: $current{$type} = &mt('None specified');
5858: }
1.152 raeburn 5859: if ($othercontrol) {
5860: if ($type eq 'primary') {
5861: $canselect{$type} = $othercontrol;
5862: }
5863: } else {
5864: $canselect{$type} =
5865: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
5866: '<select name="newspare_'.$type.'_'.$server.'" '.
5867: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
5868: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
5869: if (@choices > 0) {
5870: foreach my $lonhost (@choices) {
5871: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
5872: }
5873: }
5874: $canselect{$type} .= '</select>'."\n";
5875: }
5876: } else {
5877: $current{$type} = &mt('Could not be determined');
5878: if ($type eq 'primary') {
5879: $canselect{$type} = $othercontrol;
5880: }
1.145 raeburn 5881: }
1.152 raeburn 5882: if ($type eq 'default') {
5883: $datatable .= '<tr'.$css_class.'>';
5884: }
5885: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
5886: '<td>'.$current{$type}.'</td>'."\n".
5887: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 5888: }
5889: $itemcount ++;
5890: }
5891: }
5892: $$rowtotal += $itemcount;
5893: return $datatable;
5894: }
5895:
1.152 raeburn 5896: sub possible_newspares {
5897: my ($server,$currspares,$serverhomes,$altids) = @_;
5898: my $serverhostname = &Apache::lonnet::hostname($server);
5899: my %excluded;
5900: if ($serverhostname ne '') {
5901: %excluded = (
5902: $serverhostname => 1,
5903: );
5904: }
5905: if (ref($currspares) eq 'HASH') {
5906: foreach my $type (keys(%{$currspares})) {
5907: if (ref($currspares->{$type}) eq 'ARRAY') {
5908: if (@{$currspares->{$type}} > 0) {
5909: foreach my $curr (@{$currspares->{$type}}) {
5910: my $hostname = &Apache::lonnet::hostname($curr);
5911: $excluded{$hostname} = 1;
5912: }
5913: }
5914: }
5915: }
5916: }
5917: my @choices;
5918: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
5919: if (keys(%{$serverhomes}) > 1) {
5920: foreach my $name (sort(keys(%{$serverhomes}))) {
5921: unless ($excluded{$name}) {
5922: if (exists($altids->{$serverhomes->{$name}})) {
5923: push(@choices,$altids->{$serverhomes->{$name}});
5924: } else {
5925: push(@choices,$serverhomes->{$name});
1.145 raeburn 5926: }
5927: }
5928: }
5929: }
5930: }
1.152 raeburn 5931: return sort(@choices);
1.145 raeburn 5932: }
5933:
1.150 raeburn 5934: sub print_loadbalancing {
5935: my ($dom,$settings,$rowtotal) = @_;
5936: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5937: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5938: my $numinrow = 1;
5939: my $datatable;
5940: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 5941: my (%currbalancer,%currtargets,%currrules,%existing);
5942: if (ref($settings) eq 'HASH') {
5943: %existing = %{$settings};
5944: }
5945: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
5946: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
5947: \%currtargets,\%currrules);
1.150 raeburn 5948: } else {
5949: return;
5950: }
5951: my ($othertitle,$usertypes,$types) =
5952: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 5953: my $rownum = 8;
1.150 raeburn 5954: if (ref($types) eq 'ARRAY') {
5955: $rownum += scalar(@{$types});
5956: }
1.171 raeburn 5957: my @css_class = ('LC_odd_row','LC_even_row');
5958: my $balnum = 0;
5959: my $islast;
5960: my (@toshow,$disabledtext);
5961: if (keys(%currbalancer) > 0) {
5962: @toshow = sort(keys(%currbalancer));
5963: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
5964: push(@toshow,'');
5965: }
5966: } else {
5967: @toshow = ('');
5968: $disabledtext = &mt('No existing load balancer');
5969: }
5970: foreach my $lonhost (@toshow) {
5971: if ($balnum == scalar(@toshow)-1) {
5972: $islast = 1;
5973: } else {
5974: $islast = 0;
5975: }
5976: my $cssidx = $balnum%2;
5977: my $targets_div_style = 'display: none';
5978: my $disabled_div_style = 'display: block';
5979: my $homedom_div_style = 'display: none';
5980: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 5981: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 5982: '<p>';
5983: if ($lonhost eq '') {
1.210 raeburn 5984: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 5985: if (keys(%currbalancer) > 0) {
5986: $datatable .= &mt('Add balancer:');
5987: } else {
5988: $datatable .= &mt('Enable balancer:');
5989: }
5990: $datatable .= ' '.
5991: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
5992: ' id="loadbalancing_lonhost_'.$balnum.'"'.
5993: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
5994: '<option value="" selected="selected">'.&mt('None').
5995: '</option>'."\n";
5996: foreach my $server (sort(keys(%servers))) {
5997: next if ($currbalancer{$server});
5998: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
5999: }
1.210 raeburn 6000: $datatable .=
1.171 raeburn 6001: '</select>'."\n".
6002: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
6003: } else {
6004: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
6005: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
6006: &mt('Stop balancing').'</label>'.
6007: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
6008: $targets_div_style = 'display: block';
6009: $disabled_div_style = 'display: none';
6010: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
6011: $homedom_div_style = 'display: block';
6012: }
6013: }
1.306 raeburn 6014: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 6015: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
6016: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
6017: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
6018: my ($numspares,@spares) = &count_servers($lonhost,%servers);
6019: my @sparestypes = ('primary','default');
6020: my %typetitles = &sparestype_titles();
1.284 raeburn 6021: my %hostherechecked = (
6022: no => ' checked="checked"',
6023: );
1.171 raeburn 6024: foreach my $sparetype (@sparestypes) {
6025: my $targettable;
6026: for (my $i=0; $i<$numspares; $i++) {
6027: my $checked;
6028: if (ref($currtargets{$lonhost}) eq 'HASH') {
6029: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6030: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6031: $checked = ' checked="checked"';
6032: }
6033: }
6034: }
6035: my ($chkboxval,$disabled);
6036: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
6037: $chkboxval = $spares[$i];
6038: }
6039: if (exists($currbalancer{$spares[$i]})) {
6040: $disabled = ' disabled="disabled"';
6041: }
1.210 raeburn 6042: $targettable .=
1.253 raeburn 6043: '<td><span class="LC_nobreak"><label>'.
6044: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 6045: $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 6046: '</span></label></span></td>';
1.171 raeburn 6047: my $rem = $i%($numinrow);
6048: if ($rem == 0) {
6049: if (($i > 0) && ($i < $numspares-1)) {
6050: $targettable .= '</tr>';
6051: }
6052: if ($i < $numspares-1) {
6053: $targettable .= '<tr>';
1.150 raeburn 6054: }
6055: }
6056: }
1.171 raeburn 6057: if ($targettable ne '') {
6058: my $rem = $numspares%($numinrow);
6059: my $colsleft = $numinrow - $rem;
6060: if ($colsleft > 1 ) {
6061: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6062: ' </td>';
6063: } elsif ($colsleft == 1) {
6064: $targettable .= '<td class="LC_left_item"> </td>';
6065: }
6066: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
6067: '<table><tr>'.$targettable.'</tr></table><br />';
6068: }
1.284 raeburn 6069: $hostherechecked{$sparetype} = '';
6070: if (ref($currtargets{$lonhost}) eq 'HASH') {
6071: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6072: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6073: $hostherechecked{$sparetype} = ' checked="checked"';
6074: $hostherechecked{'no'} = '';
6075: }
6076: }
6077: }
6078: }
6079: $datatable .= &mt('Hosting on balancer itself').'<br />'.
6080: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
6081: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
6082: foreach my $sparetype (@sparestypes) {
6083: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
6084: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
6085: '</i></label><br />';
1.171 raeburn 6086: }
6087: $datatable .= '</div></td></tr>'.
6088: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
6089: $othertitle,$usertypes,$types,\%servers,
6090: \%currbalancer,$lonhost,
6091: $targets_div_style,$homedom_div_style,
6092: $css_class[$cssidx],$balnum,$islast);
6093: $$rowtotal += $rownum;
6094: $balnum ++;
6095: }
6096: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
6097: return $datatable;
6098: }
6099:
6100: sub get_loadbalancers_config {
6101: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
6102: return unless ((ref($servers) eq 'HASH') &&
6103: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
6104: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
6105: if (keys(%{$existing}) > 0) {
6106: my $oldlonhost;
6107: foreach my $key (sort(keys(%{$existing}))) {
6108: if ($key eq 'lonhost') {
6109: $oldlonhost = $existing->{'lonhost'};
6110: $currbalancer->{$oldlonhost} = 1;
6111: } elsif ($key eq 'targets') {
6112: if ($oldlonhost) {
6113: $currtargets->{$oldlonhost} = $existing->{'targets'};
6114: }
6115: } elsif ($key eq 'rules') {
6116: if ($oldlonhost) {
6117: $currrules->{$oldlonhost} = $existing->{'rules'};
6118: }
6119: } elsif (ref($existing->{$key}) eq 'HASH') {
6120: $currbalancer->{$key} = 1;
6121: $currtargets->{$key} = $existing->{$key}{'targets'};
6122: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 6123: }
6124: }
1.171 raeburn 6125: } else {
6126: my ($balancerref,$targetsref) =
6127: &Apache::lonnet::get_lonbalancer_config($servers);
6128: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
6129: foreach my $server (sort(keys(%{$balancerref}))) {
6130: $currbalancer->{$server} = 1;
6131: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 6132: }
6133: }
6134: }
1.171 raeburn 6135: return;
1.150 raeburn 6136: }
6137:
6138: sub loadbalancing_rules {
6139: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 6140: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
6141: $css_class,$balnum,$islast) = @_;
1.150 raeburn 6142: my $output;
1.171 raeburn 6143: my $num = 0;
1.210 raeburn 6144: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 6145: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
6146: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
6147: foreach my $type (@{$alltypes}) {
1.171 raeburn 6148: $num ++;
1.150 raeburn 6149: my $current;
6150: if (ref($currrules) eq 'HASH') {
6151: $current = $currrules->{$type};
6152: }
1.253 raeburn 6153: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 6154: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 6155: $current = '';
6156: }
6157: }
6158: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 6159: $servers,$currbalancer,$lonhost,$dom,
6160: $targets_div_style,$homedom_div_style,
6161: $css_class,$balnum,$num,$islast);
1.150 raeburn 6162: }
6163: }
6164: return $output;
6165: }
6166:
6167: sub loadbalancing_titles {
6168: my ($dom,$intdom,$usertypes,$types) = @_;
6169: my %othertypes = (
6170: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
6171: '_LC_author' => &mt('Users from [_1] with author role',$dom),
6172: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
6173: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 6174: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
6175: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 6176: );
1.209 raeburn 6177: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 6178: my @available;
1.150 raeburn 6179: if (ref($types) eq 'ARRAY') {
1.302 raeburn 6180: @available = @{$types};
1.150 raeburn 6181: }
1.302 raeburn 6182: unless (grep(/^default$/,@available)) {
6183: push(@available,'default');
6184: }
6185: unshift(@alltypes,@available);
1.150 raeburn 6186: my %titles;
6187: foreach my $type (@alltypes) {
6188: if ($type =~ /^_LC_/) {
6189: $titles{$type} = $othertypes{$type};
6190: } elsif ($type eq 'default') {
6191: $titles{$type} = &mt('All users from [_1]',$dom);
6192: if (ref($types) eq 'ARRAY') {
6193: if (@{$types} > 0) {
6194: $titles{$type} = &mt('Other users from [_1]',$dom);
6195: }
6196: }
6197: } elsif (ref($usertypes) eq 'HASH') {
6198: $titles{$type} = $usertypes->{$type};
6199: }
6200: }
6201: return (\@alltypes,\%othertypes,\%titles);
6202: }
6203:
6204: sub loadbalance_rule_row {
1.171 raeburn 6205: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
6206: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 6207: my @rulenames;
1.150 raeburn 6208: my %ruletitles = &offloadtype_text();
1.209 raeburn 6209: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 6210: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 6211: } else {
1.209 raeburn 6212: @rulenames = ('default','homeserver');
6213: if ($type eq '_LC_external') {
6214: push(@rulenames,'externalbalancer');
6215: } else {
6216: push(@rulenames,'specific');
6217: }
6218: push(@rulenames,'none');
1.150 raeburn 6219: }
6220: my $style = $targets_div_style;
1.253 raeburn 6221: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 6222: $style = $homedom_div_style;
6223: }
1.171 raeburn 6224: my $space;
6225: if ($islast && $num == 1) {
1.317 raeburn 6226: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 6227: }
1.210 raeburn 6228: my $output =
1.306 raeburn 6229: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 6230: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
6231: '<td valaign="top">'.$space.
6232: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 6233: for (my $i=0; $i<@rulenames; $i++) {
6234: my $rule = $rulenames[$i];
6235: my ($checked,$extra);
6236: if ($rulenames[$i] eq 'default') {
6237: $rule = '';
6238: }
6239: if ($rulenames[$i] eq 'specific') {
6240: if (ref($servers) eq 'HASH') {
6241: my $default;
6242: if (($current ne '') && (exists($servers->{$current}))) {
6243: $checked = ' checked="checked"';
6244: }
6245: unless ($checked) {
6246: $default = ' selected="selected"';
6247: }
1.210 raeburn 6248: $extra =
1.171 raeburn 6249: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
6250: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
6251: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
6252: '<option value=""'.$default.'></option>'."\n";
6253: foreach my $server (sort(keys(%{$servers}))) {
6254: if (ref($currbalancer) eq 'HASH') {
6255: next if (exists($currbalancer->{$server}));
6256: }
1.150 raeburn 6257: my $selected;
1.171 raeburn 6258: if ($server eq $current) {
1.150 raeburn 6259: $selected = ' selected="selected"';
6260: }
1.171 raeburn 6261: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 6262: }
6263: $extra .= '</select>';
6264: }
6265: } elsif ($rule eq $current) {
6266: $checked = ' checked="checked"';
6267: }
6268: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 6269: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
6270: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
6271: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 6272: ')"'.$checked.' /> ';
6273: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
6274: $output .= $ruletitles{'particular'};
6275: } else {
6276: $output .= $ruletitles{$rulenames[$i]};
6277: }
6278: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 6279: }
6280: $output .= '</div></td></tr>'."\n";
6281: return $output;
6282: }
6283:
6284: sub offloadtype_text {
6285: my %ruletitles = &Apache::lonlocal::texthash (
6286: 'default' => 'Offloads to default destinations',
6287: 'homeserver' => "Offloads to user's home server",
6288: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
6289: 'specific' => 'Offloads to specific server',
1.161 raeburn 6290: 'none' => 'No offload',
1.209 raeburn 6291: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
6292: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 6293: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 6294: );
6295: return %ruletitles;
6296: }
6297:
6298: sub sparestype_titles {
6299: my %typestitles = &Apache::lonlocal::texthash (
6300: 'primary' => 'primary',
6301: 'default' => 'default',
6302: );
6303: return %typestitles;
6304: }
6305:
1.28 raeburn 6306: sub contact_titles {
6307: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 6308: 'supportemail' => 'Support E-mail address',
6309: 'adminemail' => 'Default Server Admin E-mail address',
6310: 'errormail' => 'Error reports to be e-mailed to',
6311: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 6312: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
6313: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 6314: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
6315: 'requestsmail' => 'E-mail from course requests requiring approval',
6316: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 6317: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 6318: );
6319: my %short_titles = &Apache::lonlocal::texthash (
6320: adminemail => 'Admin E-mail address',
6321: supportemail => 'Support E-mail',
6322: );
6323: return (\%titles,\%short_titles);
6324: }
6325:
1.286 raeburn 6326: sub helpform_fields {
6327: my %titles = &Apache::lonlocal::texthash (
6328: 'username' => 'Name',
6329: 'user' => 'Username/domain',
6330: 'phone' => 'Phone',
6331: 'cc' => 'Cc e-mail',
6332: 'course' => 'Course Details',
6333: 'section' => 'Sections',
1.289 raeburn 6334: 'screenshot' => 'File upload',
1.286 raeburn 6335: );
6336: my @fields = ('username','phone','user','course','section','cc','screenshot');
6337: my %possoptions = (
6338: username => ['yes','no','req'],
1.289 raeburn 6339: phone => ['yes','no','req'],
1.286 raeburn 6340: user => ['yes','no'],
1.289 raeburn 6341: cc => ['yes','no'],
1.286 raeburn 6342: course => ['yes','no'],
6343: section => ['yes','no'],
6344: screenshot => ['yes','no'],
6345: );
6346: my %fieldoptions = &Apache::lonlocal::texthash (
6347: 'yes' => 'Optional',
6348: 'req' => 'Required',
6349: 'no' => "Not shown",
6350: );
6351: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
6352: }
6353:
1.72 raeburn 6354: sub tool_titles {
6355: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 6356: aboutme => 'Personal web page',
1.86 raeburn 6357: blog => 'Blog',
1.162 raeburn 6358: webdav => 'WebDAV',
1.86 raeburn 6359: portfolio => 'Portfolio',
1.88 bisitz 6360: official => 'Official courses (with institutional codes)',
6361: unofficial => 'Unofficial courses',
1.98 raeburn 6362: community => 'Communities',
1.216 raeburn 6363: textbook => 'Textbook courses',
1.271 raeburn 6364: placement => 'Placement tests',
1.86 raeburn 6365: );
1.72 raeburn 6366: return %titles;
6367: }
6368:
1.101 raeburn 6369: sub courserequest_titles {
6370: my %titles = &Apache::lonlocal::texthash (
6371: official => 'Official',
6372: unofficial => 'Unofficial',
6373: community => 'Communities',
1.216 raeburn 6374: textbook => 'Textbook',
1.271 raeburn 6375: placement => 'Placement tests',
1.101 raeburn 6376: norequest => 'Not allowed',
1.104 raeburn 6377: approval => 'Approval by Dom. Coord.',
1.101 raeburn 6378: validate => 'With validation',
6379: autolimit => 'Numerical limit',
1.103 raeburn 6380: unlimited => '(blank for unlimited)',
1.101 raeburn 6381: );
6382: return %titles;
6383: }
6384:
1.163 raeburn 6385: sub authorrequest_titles {
6386: my %titles = &Apache::lonlocal::texthash (
6387: norequest => 'Not allowed',
6388: approval => 'Approval by Dom. Coord.',
6389: automatic => 'Automatic approval',
6390: );
6391: return %titles;
1.210 raeburn 6392: }
1.163 raeburn 6393:
1.101 raeburn 6394: sub courserequest_conditions {
6395: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 6396: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 6397: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 6398: );
6399: return %conditions;
6400: }
6401:
6402:
1.27 raeburn 6403: sub print_usercreation {
1.30 raeburn 6404: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 6405: my $numinrow = 4;
1.28 raeburn 6406: my $datatable;
6407: if ($position eq 'top') {
1.30 raeburn 6408: $$rowtotal ++;
1.34 raeburn 6409: my $rowcount = 0;
1.32 raeburn 6410: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 6411: if (ref($rules) eq 'HASH') {
6412: if (keys(%{$rules}) > 0) {
1.32 raeburn 6413: $datatable .= &user_formats_row('username',$settings,$rules,
6414: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 6415: $$rowtotal ++;
1.32 raeburn 6416: $rowcount ++;
6417: }
6418: }
6419: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
6420: if (ref($idrules) eq 'HASH') {
6421: if (keys(%{$idrules}) > 0) {
6422: $datatable .= &user_formats_row('id',$settings,$idrules,
6423: $idruleorder,$numinrow,$rowcount);
6424: $$rowtotal ++;
6425: $rowcount ++;
1.28 raeburn 6426: }
6427: }
1.39 raeburn 6428: if ($rowcount == 0) {
6429: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
6430: $$rowtotal ++;
6431: $rowcount ++;
6432: }
1.34 raeburn 6433: } elsif ($position eq 'middle') {
1.224 raeburn 6434: my @creators = ('author','course','requestcrs');
1.37 raeburn 6435: my ($rules,$ruleorder) =
6436: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 6437: my %lt = &usercreation_types();
6438: my %checked;
6439: if (ref($settings) eq 'HASH') {
6440: if (ref($settings->{'cancreate'}) eq 'HASH') {
6441: foreach my $item (@creators) {
6442: $checked{$item} = $settings->{'cancreate'}{$item};
6443: }
6444: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
6445: foreach my $item (@creators) {
6446: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
6447: $checked{$item} = 'none';
6448: }
6449: }
6450: }
6451: }
6452: my $rownum = 0;
6453: foreach my $item (@creators) {
6454: $rownum ++;
1.224 raeburn 6455: if ($checked{$item} eq '') {
6456: $checked{$item} = 'any';
1.34 raeburn 6457: }
6458: my $css_class;
6459: if ($rownum%2) {
6460: $css_class = '';
6461: } else {
6462: $css_class = ' class="LC_odd_row" ';
6463: }
6464: $datatable .= '<tr'.$css_class.'>'.
6465: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 6466: '</span></td><td style="text-align: right">';
1.224 raeburn 6467: my @options = ('any');
6468: if (ref($rules) eq 'HASH') {
6469: if (keys(%{$rules}) > 0) {
6470: push(@options,('official','unofficial'));
1.37 raeburn 6471: }
6472: }
1.224 raeburn 6473: push(@options,'none');
1.37 raeburn 6474: foreach my $option (@options) {
1.50 raeburn 6475: my $type = 'radio';
1.34 raeburn 6476: my $check = ' ';
1.224 raeburn 6477: if ($checked{$item} eq $option) {
6478: $check = ' checked="checked" ';
1.34 raeburn 6479: }
6480: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 6481: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 6482: $item.'" value="'.$option.'"'.$check.'/> '.
6483: $lt{$option}.'</label> </span>';
6484: }
6485: $datatable .= '</td></tr>';
6486: }
1.28 raeburn 6487: } else {
6488: my @contexts = ('author','course','domain');
6489: my @authtypes = ('int','krb4','krb5','loc');
6490: my %checked;
6491: if (ref($settings) eq 'HASH') {
6492: if (ref($settings->{'authtypes'}) eq 'HASH') {
6493: foreach my $item (@contexts) {
6494: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
6495: foreach my $auth (@authtypes) {
6496: if ($settings->{'authtypes'}{$item}{$auth}) {
6497: $checked{$item}{$auth} = ' checked="checked" ';
6498: }
6499: }
6500: }
6501: }
1.27 raeburn 6502: }
1.35 raeburn 6503: } else {
6504: foreach my $item (@contexts) {
1.36 raeburn 6505: foreach my $auth (@authtypes) {
1.35 raeburn 6506: $checked{$item}{$auth} = ' checked="checked" ';
6507: }
6508: }
1.27 raeburn 6509: }
1.28 raeburn 6510: my %title = &context_names();
6511: my %authname = &authtype_names();
6512: my $rownum = 0;
6513: my $css_class;
6514: foreach my $item (@contexts) {
6515: if ($rownum%2) {
6516: $css_class = '';
6517: } else {
6518: $css_class = ' class="LC_odd_row" ';
6519: }
1.30 raeburn 6520: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 6521: '<td>'.$title{$item}.
6522: '</td><td class="LC_left_item">'.
6523: '<span class="LC_nobreak">';
6524: foreach my $auth (@authtypes) {
6525: $datatable .= '<label>'.
6526: '<input type="checkbox" name="'.$item.'_auth" '.
6527: $checked{$item}{$auth}.' value="'.$auth.'" />'.
6528: $authname{$auth}.'</label> ';
6529: }
6530: $datatable .= '</span></td></tr>';
6531: $rownum ++;
1.27 raeburn 6532: }
1.30 raeburn 6533: $$rowtotal += $rownum;
1.27 raeburn 6534: }
6535: return $datatable;
6536: }
6537:
1.224 raeburn 6538: sub print_selfcreation {
6539: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 6540: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
6541: $emaildomain,$datatable);
1.224 raeburn 6542: if (ref($settings) eq 'HASH') {
6543: if (ref($settings->{'cancreate'}) eq 'HASH') {
6544: $createsettings = $settings->{'cancreate'};
1.236 raeburn 6545: if (ref($createsettings) eq 'HASH') {
6546: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
6547: @selfcreate = @{$createsettings->{'selfcreate'}};
6548: } elsif ($createsettings->{'selfcreate'} ne '') {
6549: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
6550: @selfcreate = ('email','login','sso');
6551: } elsif ($createsettings->{'selfcreate'} ne 'none') {
6552: @selfcreate = ($createsettings->{'selfcreate'});
6553: }
6554: }
6555: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
6556: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 6557: }
1.305 raeburn 6558: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
6559: $emailoptions = $createsettings->{'emailoptions'};
6560: }
1.303 raeburn 6561: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
6562: $emailverified = $createsettings->{'emailverified'};
6563: }
6564: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
6565: $emaildomain = $createsettings->{'emaildomain'};
6566: }
1.224 raeburn 6567: }
6568: }
6569: }
6570: my %radiohash;
6571: my $numinrow = 4;
6572: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 6573: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 6574: if ($position eq 'top') {
6575: my %choices = &Apache::lonlocal::texthash (
6576: cancreate_login => 'Institutional Login',
6577: cancreate_sso => 'Institutional Single Sign On',
6578: );
6579: my @toggles = sort(keys(%choices));
6580: my %defaultchecked = (
6581: 'cancreate_login' => 'off',
6582: 'cancreate_sso' => 'off',
6583: );
1.228 raeburn 6584: my ($onclick,$itemcount);
1.224 raeburn 6585: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6586: \%choices,$itemcount,$onclick);
1.228 raeburn 6587: $$rowtotal += $itemcount;
6588:
1.224 raeburn 6589: if (ref($usertypes) eq 'HASH') {
6590: if (keys(%{$usertypes}) > 0) {
6591: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
6592: $dom,$numinrow,$othertitle,
1.305 raeburn 6593: 'statustocreate',$rowtotal);
1.224 raeburn 6594: $$rowtotal ++;
6595: }
6596: }
1.240 raeburn 6597: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
6598: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6599: $fieldtitles{'inststatus'} = &mt('Institutional status');
6600: my $rem;
6601: my $numperrow = 2;
6602: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
6603: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 6604: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 6605: '<td class="LC_left_item">'."\n".
6606: '<table><tr><td>'."\n";
6607: for (my $i=0; $i<@fields; $i++) {
6608: $rem = $i%($numperrow);
6609: if ($rem == 0) {
6610: if ($i > 0) {
6611: $datatable .= '</tr>';
6612: }
6613: $datatable .= '<tr>';
6614: }
6615: my $currval;
1.248 raeburn 6616: if (ref($createsettings) eq 'HASH') {
6617: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
6618: $currval = $createsettings->{'shibenv'}{$fields[$i]};
6619: }
1.240 raeburn 6620: }
6621: $datatable .= '<td class="LC_left_item">'.
6622: '<span class="LC_nobreak">'.
6623: '<input type="text" name="shibenv_'.$fields[$i].'" '.
6624: 'value="'.$currval.'" size="10" /> '.
6625: $fieldtitles{$fields[$i]}.'</span></td>';
6626: }
6627: my $colsleft = $numperrow - $rem;
6628: if ($colsleft > 1 ) {
6629: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6630: ' </td>';
6631: } elsif ($colsleft == 1) {
6632: $datatable .= '<td class="LC_left_item"> </td>';
6633: }
6634: $datatable .= '</tr></table></td></tr>';
6635: $$rowtotal ++;
1.224 raeburn 6636: } elsif ($position eq 'middle') {
6637: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 6638: my @posstypes;
1.224 raeburn 6639: if (ref($types) eq 'ARRAY') {
1.302 raeburn 6640: @posstypes = @{$types};
6641: }
6642: unless (grep(/^default$/,@posstypes)) {
6643: push(@posstypes,'default');
6644: }
6645: my %usertypeshash;
6646: if (ref($usertypes) eq 'HASH') {
6647: %usertypeshash = %{$usertypes};
6648: }
6649: $usertypeshash{'default'} = $othertitle;
6650: foreach my $status (@posstypes) {
6651: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
6652: $numinrow,$$rowtotal,\%usertypeshash);
6653: $$rowtotal ++;
1.224 raeburn 6654: }
6655: } else {
1.236 raeburn 6656: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 6657: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 6658: );
6659: my @toggles = sort(keys(%choices));
6660: my %defaultchecked = (
6661: 'cancreate_email' => 'off',
6662: );
1.305 raeburn 6663: my $customclass = 'LC_selfcreate_email';
6664: my $classprefix = 'LC_canmodify_emailusername_';
6665: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 6666: my $display = 'none';
1.305 raeburn 6667: my $rowstyle = 'display:none';
1.236 raeburn 6668: if (grep(/^\Qemail\E$/,@selfcreate)) {
6669: $display = 'block';
1.305 raeburn 6670: $rowstyle = 'display:table-row';
1.236 raeburn 6671: }
1.305 raeburn 6672: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
6673: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6674: \%choices,$$rowtotal,$onclick);
6675: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
6676: $rowstyle);
6677: $$rowtotal ++;
6678: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
6679: $rowstyle);
6680: $$rowtotal ++;
6681: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 6682: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 6683: my ($emailrules,$emailruleorder) =
6684: &Apache::lonnet::inst_userrules($dom,'email');
6685: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6686: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6687: if (ref($types) eq 'ARRAY') {
6688: @posstypes = @{$types};
6689: }
6690: if (@posstypes) {
6691: unless (grep(/^default$/,@posstypes)) {
6692: push(@posstypes,'default');
1.302 raeburn 6693: }
6694: if (ref($usertypes) eq 'HASH') {
6695: %usertypeshash = %{$usertypes};
6696: }
1.305 raeburn 6697: my $currassign;
6698: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
6699: $currassign = {
6700: selfassign => $domdefaults{'inststatusguest'},
6701: };
6702: @ordered = @{$domdefaults{'inststatusguest'}};
6703: } else {
6704: $currassign = { selfassign => [] };
6705: }
6706: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
6707: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
6708: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
6709: $numinrow,$othertitle,'selfassign',
6710: $rowtotal,$onclicktypes,$customclass,
6711: $rowstyle);
6712: $$rowtotal ++;
1.302 raeburn 6713: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 6714: foreach my $status (@posstypes) {
6715: my $css_class;
6716: if ($$rowtotal%2) {
6717: $css_class = 'LC_odd_row ';
6718: }
6719: $css_class .= $customclass;
6720: my $rowid = $optionsprefix.$status;
6721: my $hidden = 1;
6722: my $currstyle = 'display:none';
6723: if (grep(/^\Q$status\E$/,@ordered)) {
6724: $currstyle = $rowstyle;
6725: $hidden = 0;
6726: }
6727: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6728: $emailrules,$emailruleorder,$settings,$status,$rowid,
6729: $usertypeshash{$status},$css_class,$currstyle,$intdom);
6730: unless ($hidden) {
6731: $$rowtotal ++;
6732: }
1.224 raeburn 6733: }
1.302 raeburn 6734: } else {
1.305 raeburn 6735: my $css_class;
6736: if ($$rowtotal%2) {
6737: $css_class = 'LC_odd_row ';
6738: }
6739: $css_class .= $customclass;
1.302 raeburn 6740: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 6741: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6742: $emailrules,$emailruleorder,$settings,'default','',
6743: $othertitle,$css_class,$rowstyle,$intdom);
6744: $$rowtotal ++;
1.224 raeburn 6745: }
6746: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 6747: $numinrow = 1;
1.305 raeburn 6748: if (@posstypes) {
6749: foreach my $status (@posstypes) {
6750: my $rowid = $classprefix.$status;
6751: my $datarowstyle = 'display:none';
6752: if (grep(/^\Q$status\E$/,@ordered)) {
6753: $datarowstyle = $rowstyle;
6754: }
6755: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
6756: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
6757: $infotitles,$rowid,$customclass,$datarowstyle);
6758: unless ($datarowstyle eq 'display:none') {
6759: $$rowtotal ++;
6760: }
1.224 raeburn 6761: }
1.305 raeburn 6762: } else {
6763: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
6764: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
6765: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 6766: }
6767: }
6768: return $datatable;
6769: }
6770:
1.305 raeburn 6771: sub selfcreate_javascript {
6772: return <<"ENDSCRIPT";
6773:
6774: <script type="text/javascript">
6775: // <![CDATA[
6776:
6777: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
6778: var x = document.getElementsByClassName(target);
6779: var insttypes = 0;
6780: var insttypeRegExp = new RegExp(prefix);
6781: if ((x.length != undefined) && (x.length > 0)) {
6782: if (form.elements[radio].length != undefined) {
6783: for (var i=0; i<form.elements[radio].length; i++) {
6784: if (form.elements[radio][i].checked) {
6785: if (form.elements[radio][i].value == 1) {
6786: for (var j=0; j<x.length; j++) {
6787: if (x[j].id == 'undefined') {
6788: x[j].style.display = 'table-row';
6789: } else if (insttypeRegExp.test(x[j].id)) {
6790: insttypes ++;
6791: } else {
6792: x[j].style.display = 'table-row';
6793: }
6794: }
6795: } else {
6796: for (var j=0; j<x.length; j++) {
6797: x[j].style.display = 'none';
6798: }
1.236 raeburn 6799: }
1.305 raeburn 6800: break;
6801: }
6802: }
6803: if (insttypes > 0) {
6804: toggleDataRow(form,checkbox,target,altprefix);
6805: toggleDataRow(form,checkbox,target,prefix,1);
6806: }
6807: }
6808: }
6809: return;
6810: }
6811:
6812: function toggleDataRow(form,checkbox,target,prefix,docount) {
6813: if (form.elements[checkbox].length != undefined) {
6814: var count = 0;
6815: if (docount) {
6816: for (var i=0; i<form.elements[checkbox].length; i++) {
6817: if (form.elements[checkbox][i].checked) {
6818: count ++;
1.236 raeburn 6819: }
1.305 raeburn 6820: }
6821: }
6822: for (var i=0; i<form.elements[checkbox].length; i++) {
6823: var type = form.elements[checkbox][i].value;
6824: if (document.getElementById(prefix+type)) {
6825: if (form.elements[checkbox][i].checked) {
6826: document.getElementById(prefix+type).style.display = 'table-row';
6827: if (count % 2 == 1) {
6828: document.getElementById(prefix+type).className = target+' LC_odd_row';
6829: } else {
6830: document.getElementById(prefix+type).className = target;
1.236 raeburn 6831: }
1.305 raeburn 6832: count ++;
1.236 raeburn 6833: } else {
1.305 raeburn 6834: document.getElementById(prefix+type).style.display = 'none';
6835: }
6836: }
6837: }
6838: }
6839: return;
6840: }
6841:
6842: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
6843: var caller = radio+'_'+status;
6844: if (form.elements[caller].length != undefined) {
6845: for (var i=0; i<form.elements[caller].length; i++) {
6846: if (form.elements[caller][i].checked) {
6847: if (document.getElementById(altprefix+'_inst_'+status)) {
6848: var curr = form.elements[caller][i].value;
6849: if (prefix) {
6850: document.getElementById(prefix+'_'+status).style.display = 'none';
6851: }
6852: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
6853: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
6854: if (curr == 'custom') {
6855: if (prefix) {
6856: document.getElementById(prefix+'_'+status).style.display = 'inline';
6857: }
6858: } else if (curr == 'inst') {
6859: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
6860: } else if (curr == 'noninst') {
6861: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 6862: }
1.305 raeburn 6863: break;
1.236 raeburn 6864: }
6865: }
6866: }
6867: }
6868: }
6869:
1.305 raeburn 6870: // ]]>
6871: </script>
6872:
6873: ENDSCRIPT
6874: }
6875:
6876: sub noninst_users {
6877: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
6878: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
6879: my $class = 'LC_left_item';
6880: if ($css_class) {
6881: $css_class = ' class="'.$css_class.'"';
6882: }
6883: if ($rowid) {
6884: $rowid = ' id="'.$rowid.'"';
6885: }
6886: if ($rowstyle) {
6887: $rowstyle = ' style="'.$rowstyle.'"';
6888: }
6889: my ($output,$description);
6890: if ($type eq 'default') {
6891: $description = &mt('Requests for: [_1]',$typetitle);
6892: } else {
6893: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
6894: }
6895: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
6896: "<td>$description</td>\n".
6897: '<td class="'.$class.'" colspan="2">'.
6898: '<table><tr>';
6899: my %headers = &Apache::lonlocal::texthash(
6900: approve => 'Processing',
6901: email => 'E-mail',
6902: username => 'Username',
6903: );
6904: foreach my $item ('approve','email','username') {
6905: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 6906: }
1.305 raeburn 6907: $output .= '</tr><tr>';
6908: foreach my $item ('approve','email','username') {
1.306 raeburn 6909: $output .= '<td style="vertical-align: top">';
1.305 raeburn 6910: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
6911: if ($item eq 'approve') {
6912: %choices = &Apache::lonlocal::texthash (
6913: automatic => 'Automatically approved',
6914: approval => 'Queued for approval',
6915: );
6916: @options = ('automatic','approval');
6917: $hashref = $processing;
6918: $defoption = 'automatic';
6919: $name = 'cancreate_emailprocess_'.$type;
6920: } elsif ($item eq 'email') {
6921: %choices = &Apache::lonlocal::texthash (
6922: any => 'Any e-mail',
6923: inst => 'Institutional only',
6924: noninst => 'Non-institutional only',
6925: custom => 'Custom restrictions',
6926: );
6927: @options = ('any','inst','noninst');
6928: my $showcustom;
6929: if (ref($emailrules) eq 'HASH') {
6930: if (keys(%{$emailrules}) > 0) {
6931: push(@options,'custom');
6932: $showcustom = 'cancreate_emailrule';
6933: if (ref($settings) eq 'HASH') {
6934: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
6935: foreach my $rule (@{$settings->{'email_rule'}}) {
6936: if (exists($emailrules->{$rule})) {
6937: $hascustom ++;
6938: }
6939: }
6940: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
6941: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
6942: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
6943: if (exists($emailrules->{$rule})) {
6944: $hascustom ++;
6945: }
6946: }
6947: }
6948: }
6949: }
6950: }
6951: }
6952: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
6953: "'cancreate_emaildomain','$type'".');"';
6954: $hashref = $emailoptions;
6955: $defoption = 'any';
6956: $name = 'cancreate_emailoptions_'.$type;
6957: } elsif ($item eq 'username') {
6958: %choices = &Apache::lonlocal::texthash (
6959: all => 'Same as e-mail',
6960: first => 'Omit @domain',
6961: free => 'Free to choose',
6962: );
6963: @options = ('all','first','free');
6964: $hashref = $emailverified;
6965: $defoption = 'all';
6966: $name = 'cancreate_usernameoptions_'.$type;
6967: }
6968: foreach my $option (@options) {
6969: my $checked;
6970: if (ref($hashref) eq 'HASH') {
6971: if ($type eq '') {
6972: if (!exists($hashref->{'default'})) {
6973: if ($option eq $defoption) {
6974: $checked = ' checked="checked"';
6975: }
6976: } else {
6977: if ($hashref->{'default'} eq $option) {
6978: $checked = ' checked="checked"';
6979: }
1.303 raeburn 6980: }
6981: } else {
1.305 raeburn 6982: if (!exists($hashref->{$type})) {
6983: if ($option eq $defoption) {
6984: $checked = ' checked="checked"';
6985: }
6986: } else {
6987: if ($hashref->{$type} eq $option) {
6988: $checked = ' checked="checked"';
6989: }
1.303 raeburn 6990: }
6991: }
1.305 raeburn 6992: } elsif (($item eq 'email') && ($hascustom)) {
6993: if ($option eq 'custom') {
6994: $checked = ' checked="checked"';
6995: }
6996: } elsif ($option eq $defoption) {
6997: $checked = ' checked="checked"';
6998: }
6999: $output .= '<span class="LC_nobreak"><label>'.
7000: '<input type="radio" name="'.$name.'"'.
7001: $checked.' value="'.$option.'"'.$onclick.' />'.
7002: $choices{$option}.'</label></span><br />';
7003: if ($item eq 'email') {
7004: if ($option eq 'custom') {
7005: my $id = 'cancreate_emailrule_'.$type;
7006: my $display = 'none';
7007: if ($checked) {
7008: $display = 'inline';
1.303 raeburn 7009: }
1.305 raeburn 7010: my $numinrow = 2;
7011: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
7012: '<legend>'.&mt('Disallow').'</legend><table>'.
7013: &user_formats_row('email',$settings,$emailrules,
7014: $emailruleorder,$numinrow,'',$type);
7015: '</table></fieldset>';
7016: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
7017: my %text = &Apache::lonlocal::texthash (
7018: inst => 'must end:',
7019: noninst => 'cannot end:',
7020: );
7021: my $value;
7022: if (ref($emaildomain) eq 'HASH') {
7023: if (ref($emaildomain->{$type}) eq 'HASH') {
7024: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 7025: }
7026: }
1.305 raeburn 7027: if ($value eq '') {
7028: $value = '@'.$intdom;
7029: }
7030: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
7031: my $display = 'none';
7032: if ($checked) {
7033: $display = 'inline';
7034: }
7035: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
7036: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
7037: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
7038: '</div>';
1.303 raeburn 7039: }
7040: }
7041: }
1.305 raeburn 7042: $output .= '</td>'."\n";
1.303 raeburn 7043: }
1.305 raeburn 7044: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 7045: return $output;
7046: }
7047:
1.165 raeburn 7048: sub captcha_choice {
1.305 raeburn 7049: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 7050: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
7051: $vertext,$currver);
1.165 raeburn 7052: my %lt = &captcha_phrases();
7053: $keyentry = 'hidden';
7054: if ($context eq 'cancreate') {
1.224 raeburn 7055: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 7056: } elsif ($context eq 'login') {
7057: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 7058: }
7059: if (ref($settings) eq 'HASH') {
7060: if ($settings->{'captcha'}) {
7061: $checked{$settings->{'captcha'}} = ' checked="checked"';
7062: } else {
7063: $checked{'original'} = ' checked="checked"';
7064: }
7065: if ($settings->{'captcha'} eq 'recaptcha') {
7066: $pubtext = $lt{'pub'};
7067: $privtext = $lt{'priv'};
7068: $keyentry = 'text';
1.269 raeburn 7069: $vertext = $lt{'ver'};
7070: $currver = $settings->{'recaptchaversion'};
7071: if ($currver ne '2') {
7072: $currver = 1;
7073: }
1.165 raeburn 7074: }
7075: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
7076: $currpub = $settings->{'recaptchakeys'}{'public'};
7077: $currpriv = $settings->{'recaptchakeys'}{'private'};
7078: }
7079: } else {
7080: $checked{'original'} = ' checked="checked"';
7081: }
1.305 raeburn 7082: my $css_class;
7083: if ($itemcount%2) {
7084: $css_class = 'LC_odd_row';
7085: }
7086: if ($customcss) {
7087: $css_class .= " $customcss";
7088: }
7089: $css_class =~ s/^\s+//;
7090: if ($css_class) {
7091: $css_class = ' class="'.$css_class.'"';
7092: }
7093: if ($rowstyle) {
7094: $css_class .= ' style="'.$rowstyle.'"';
7095: }
1.169 raeburn 7096: my $output = '<tr'.$css_class.'>'.
7097: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 7098: '<table><tr><td>'."\n";
7099: foreach my $option ('original','recaptcha','notused') {
7100: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
7101: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
7102: $lt{$option}.'</label></span>';
7103: unless ($option eq 'notused') {
7104: $output .= (' 'x2)."\n";
7105: }
7106: }
7107: #
7108: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
7109: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 7110: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 7111: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 7112: #
1.165 raeburn 7113: $output .= '</td></tr>'."\n".
1.305 raeburn 7114: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 7115: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
7116: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
7117: $currpub.'" size="40" /></span><br />'."\n".
7118: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
7119: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 7120: $currpriv.'" size="40" /></span><br />'.
7121: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
7122: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
7123: $currver.'" size="3" /></span><br />'.
7124: '</td></tr></table>'."\n".
1.165 raeburn 7125: '</td></tr>';
7126: return $output;
7127: }
7128:
1.32 raeburn 7129: sub user_formats_row {
1.305 raeburn 7130: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 7131: my $output;
7132: my %text = (
7133: 'username' => 'new usernames',
7134: 'id' => 'IDs',
7135: );
1.305 raeburn 7136: unless ($type eq 'email') {
7137: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7138: $output = '<tr '.$css_class.'>'.
7139: '<td><span class="LC_nobreak">'.
7140: &mt("Format rules to check for $text{$type}: ").
7141: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 7142: }
1.27 raeburn 7143: my $rem;
7144: if (ref($ruleorder) eq 'ARRAY') {
7145: for (my $i=0; $i<@{$ruleorder}; $i++) {
7146: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
7147: my $rem = $i%($numinrow);
7148: if ($rem == 0) {
7149: if ($i > 0) {
7150: $output .= '</tr>';
7151: }
7152: $output .= '<tr>';
7153: }
7154: my $check = ' ';
1.39 raeburn 7155: if (ref($settings) eq 'HASH') {
7156: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
7157: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
7158: $check = ' checked="checked" ';
7159: }
1.305 raeburn 7160: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
7161: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
7162: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
7163: $check = ' checked="checked" ';
7164: }
7165: }
1.27 raeburn 7166: }
7167: }
1.305 raeburn 7168: my $name = $type.'_rule';
7169: if ($type eq 'email') {
7170: $name .= '_'.$status;
7171: }
1.27 raeburn 7172: $output .= '<td class="LC_left_item">'.
7173: '<span class="LC_nobreak"><label>'.
1.311 raeburn 7174: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 7175: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
7176: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
7177: }
7178: }
7179: $rem = @{$ruleorder}%($numinrow);
7180: }
1.305 raeburn 7181: my $colsleft;
7182: if ($rem) {
7183: $colsleft = $numinrow - $rem;
7184: }
1.27 raeburn 7185: if ($colsleft > 1 ) {
7186: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7187: ' </td>';
7188: } elsif ($colsleft == 1) {
7189: $output .= '<td class="LC_left_item"> </td>';
7190: }
1.305 raeburn 7191: $output .= '</tr></table>';
7192: unless ($type eq 'email') {
7193: $output .= '</td></tr>';
7194: }
1.27 raeburn 7195: return $output;
7196: }
7197:
1.34 raeburn 7198: sub usercreation_types {
7199: my %lt = &Apache::lonlocal::texthash (
7200: author => 'When adding a co-author',
7201: course => 'When adding a user to a course',
1.100 raeburn 7202: requestcrs => 'When requesting a course',
1.34 raeburn 7203: any => 'Any',
7204: official => 'Institutional only ',
7205: unofficial => 'Non-institutional only',
7206: none => 'None',
7207: );
7208: return %lt;
1.48 raeburn 7209: }
1.34 raeburn 7210:
1.224 raeburn 7211: sub selfcreation_types {
7212: my %lt = &Apache::lonlocal::texthash (
7213: selfcreate => 'User creates own account',
7214: any => 'Any',
7215: official => 'Institutional only ',
7216: unofficial => 'Non-institutional only',
7217: email => 'E-mail address',
7218: login => 'Institutional Login',
7219: sso => 'SSO',
7220: );
7221: }
7222:
1.28 raeburn 7223: sub authtype_names {
7224: my %lt = &Apache::lonlocal::texthash(
7225: int => 'Internal',
7226: krb4 => 'Kerberos 4',
7227: krb5 => 'Kerberos 5',
7228: loc => 'Local',
7229: );
7230: return %lt;
7231: }
7232:
7233: sub context_names {
7234: my %context_title = &Apache::lonlocal::texthash(
7235: author => 'Creating users when an Author',
7236: course => 'Creating users when in a course',
7237: domain => 'Creating users when a Domain Coordinator',
7238: );
7239: return %context_title;
7240: }
7241:
1.33 raeburn 7242: sub print_usermodification {
7243: my ($position,$dom,$settings,$rowtotal) = @_;
7244: my $numinrow = 4;
7245: my ($context,$datatable,$rowcount);
7246: if ($position eq 'top') {
7247: $rowcount = 0;
7248: $context = 'author';
7249: foreach my $role ('ca','aa') {
7250: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7251: $numinrow,$rowcount);
7252: $$rowtotal ++;
7253: $rowcount ++;
7254: }
1.230 raeburn 7255: } elsif ($position eq 'bottom') {
1.33 raeburn 7256: $context = 'course';
7257: $rowcount = 0;
7258: foreach my $role ('st','ep','ta','in','cr') {
7259: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7260: $numinrow,$rowcount);
7261: $$rowtotal ++;
7262: $rowcount ++;
7263: }
7264: }
7265: return $datatable;
7266: }
7267:
1.43 raeburn 7268: sub print_defaults {
1.236 raeburn 7269: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 7270: my $rownum = 0;
1.294 raeburn 7271: my ($datatable,$css_class,$titles);
7272: unless ($position eq 'bottom') {
7273: $titles = &defaults_titles($dom);
7274: }
1.236 raeburn 7275: if ($position eq 'top') {
7276: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
7277: 'datelocale_def','portal_def');
7278: my %defaults;
7279: if (ref($settings) eq 'HASH') {
7280: %defaults = %{$settings};
1.43 raeburn 7281: } else {
1.236 raeburn 7282: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
7283: foreach my $item (@items) {
7284: $defaults{$item} = $domdefaults{$item};
7285: }
1.43 raeburn 7286: }
1.236 raeburn 7287: foreach my $item (@items) {
7288: if ($rownum%2) {
7289: $css_class = '';
7290: } else {
7291: $css_class = ' class="LC_odd_row" ';
7292: }
7293: $datatable .= '<tr'.$css_class.'>'.
7294: '<td><span class="LC_nobreak">'.$titles->{$item}.
7295: '</span></td><td class="LC_right_item" colspan="3">';
7296: if ($item eq 'auth_def') {
7297: my @authtypes = ('internal','krb4','krb5','localauth');
7298: my %shortauth = (
7299: internal => 'int',
7300: krb4 => 'krb4',
7301: krb5 => 'krb5',
7302: localauth => 'loc'
7303: );
7304: my %authnames = &authtype_names();
7305: foreach my $auth (@authtypes) {
7306: my $checked = ' ';
7307: if ($defaults{$item} eq $auth) {
7308: $checked = ' checked="checked" ';
7309: }
7310: $datatable .= '<label><input type="radio" name="'.$item.
7311: '" value="'.$auth.'"'.$checked.'/>'.
7312: $authnames{$shortauth{$auth}}.'</label> ';
7313: }
7314: } elsif ($item eq 'timezone_def') {
7315: my $includeempty = 1;
7316: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
7317: } elsif ($item eq 'datelocale_def') {
7318: my $includeempty = 1;
7319: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
7320: } elsif ($item eq 'lang_def') {
1.263 raeburn 7321: my $includeempty = 1;
7322: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 7323: } else {
7324: my $size;
7325: if ($item eq 'portal_def') {
7326: $size = ' size="25"';
7327: }
7328: $datatable .= '<input type="text" name="'.$item.'" value="'.
7329: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 7330: }
1.236 raeburn 7331: $datatable .= '</td></tr>';
7332: $rownum ++;
7333: }
1.294 raeburn 7334: } elsif ($position eq 'middle') {
7335: my @items = ('intauth_cost','intauth_check','intauth_switch');
7336: my %defaults;
7337: if (ref($settings) eq 'HASH') {
7338: %defaults = %{$settings};
7339: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
7340: $defaults{'intauth_cost'} = 10;
7341: }
7342: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
7343: $defaults{'intauth_check'} = 0;
7344: }
7345: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
7346: $defaults{'intauth_switch'} = 0;
7347: }
7348: } else {
7349: %defaults = (
7350: 'intauth_cost' => 10,
7351: 'intauth_check' => 0,
7352: 'intauth_switch' => 0,
7353: );
7354: }
7355: foreach my $item (@items) {
7356: if ($rownum%2) {
7357: $css_class = '';
7358: } else {
7359: $css_class = ' class="LC_odd_row" ';
7360: }
7361: $datatable .= '<tr'.$css_class.'>'.
7362: '<td><span class="LC_nobreak">'.$titles->{$item}.
7363: '</span></td><td class="LC_left_item" colspan="3">';
7364: if ($item eq 'intauth_switch') {
7365: my @options = (0,1,2);
7366: my %optiondesc = &Apache::lonlocal::texthash (
7367: 0 => 'No',
7368: 1 => 'Yes',
7369: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
7370: );
7371: $datatable .= '<table width="100%">';
7372: foreach my $option (@options) {
7373: my $checked = ' ';
7374: if ($defaults{$item} eq $option) {
7375: $checked = ' checked="checked"';
7376: }
7377: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7378: '<label><input type="radio" name="'.$item.
7379: '" value="'.$option.'"'.$checked.' />'.
7380: $optiondesc{$option}.'</label></span></td></tr>';
7381: }
7382: $datatable .= '</table>';
7383: } elsif ($item eq 'intauth_check') {
7384: my @options = (0,1,2);
7385: my %optiondesc = &Apache::lonlocal::texthash (
7386: 0 => 'No',
7387: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
7388: 2 => 'Yes, disallow login if stored cost is less than domain default',
7389: );
7390: $datatable .= '<table wisth="100%">';
7391: foreach my $option (@options) {
7392: my $checked = ' ';
7393: my $onclick;
7394: if ($defaults{$item} eq $option) {
7395: $checked = ' checked="checked"';
7396: }
7397: if ($option == 2) {
7398: $onclick = ' onclick="javascript:warnIntAuth(this);"';
7399: }
7400: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7401: '<label><input type="radio" name="'.$item.
7402: '" value="'.$option.'"'.$checked.$onclick.' />'.
7403: $optiondesc{$option}.'</label></span></td></tr>';
7404: }
7405: $datatable .= '</table>';
7406: } else {
7407: $datatable .= '<input type="text" name="'.$item.'" value="'.
7408: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
7409: }
7410: $datatable .= '</td></tr>';
7411: $rownum ++;
7412: }
1.236 raeburn 7413: } else {
1.294 raeburn 7414: my %defaults;
1.236 raeburn 7415: if (ref($settings) eq 'HASH') {
1.305 raeburn 7416: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.236 raeburn 7417: my $maxnum = @{$settings->{'inststatusorder'}};
7418: for (my $i=0; $i<$maxnum; $i++) {
7419: $css_class = $rownum%2?' class="LC_odd_row"':'';
7420: my $item = $settings->{'inststatusorder'}->[$i];
7421: my $title = $settings->{'inststatustypes'}->{$item};
7422: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
7423: $datatable .= '<tr'.$css_class.'>'.
7424: '<td><span class="LC_nobreak">'.
7425: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
7426: for (my $k=0; $k<=$maxnum; $k++) {
7427: my $vpos = $k+1;
7428: my $selstr;
7429: if ($k == $i) {
7430: $selstr = ' selected="selected" ';
7431: }
7432: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7433: }
7434: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
7435: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
7436: &mt('delete').'</span></td>'.
1.305 raeburn 7437: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed:').
1.236 raeburn 7438: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.305 raeburn 7439: '</span></td></tr>';
1.236 raeburn 7440: }
7441: $css_class = $rownum%2?' class="LC_odd_row"':'';
7442: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
7443: $datatable .= '<tr '.$css_class.'>'.
7444: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
7445: for (my $k=0; $k<=$maxnum; $k++) {
7446: my $vpos = $k+1;
7447: my $selstr;
7448: if ($k == $maxnum) {
7449: $selstr = ' selected="selected" ';
7450: }
7451: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7452: }
7453: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 7454: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 7455: ' '.&mt('(new)').
1.305 raeburn 7456: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.236 raeburn 7457: &mt('Name displayed:').
7458: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
7459: '</tr>'."\n";
7460: $rownum ++;
1.141 raeburn 7461: }
1.43 raeburn 7462: }
7463: }
7464: $$rowtotal += $rownum;
7465: return $datatable;
7466: }
7467:
1.168 raeburn 7468: sub get_languages_hash {
7469: my %langchoices;
7470: foreach my $id (&Apache::loncommon::languageids()) {
7471: my $code = &Apache::loncommon::supportedlanguagecode($id);
7472: if ($code ne '') {
7473: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
7474: }
7475: }
7476: return %langchoices;
7477: }
7478:
1.43 raeburn 7479: sub defaults_titles {
1.141 raeburn 7480: my ($dom) = @_;
1.43 raeburn 7481: my %titles = &Apache::lonlocal::texthash (
7482: 'auth_def' => 'Default authentication type',
7483: 'auth_arg_def' => 'Default authentication argument',
7484: 'lang_def' => 'Default language',
1.54 raeburn 7485: 'timezone_def' => 'Default timezone',
1.68 raeburn 7486: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 7487: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 7488: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
7489: 'intauth_check' => 'Check bcrypt cost if authenticated',
7490: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 7491: );
1.141 raeburn 7492: if ($dom) {
7493: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
7494: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
7495: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
7496: $protocol = 'http' if ($protocol ne 'https');
7497: if ($uint_dom) {
7498: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
7499: $uint_dom);
7500: }
7501: }
1.43 raeburn 7502: return (\%titles);
7503: }
7504:
1.46 raeburn 7505: sub print_scantronformat {
7506: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
7507: my $itemcount = 1;
1.60 raeburn 7508: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
7509: %confhash);
1.46 raeburn 7510: my $switchserver = &check_switchserver($dom,$confname);
7511: my %lt = &Apache::lonlocal::texthash (
1.95 www 7512: default => 'Default bubblesheet format file error',
7513: custom => 'Custom bubblesheet format file error',
1.46 raeburn 7514: );
7515: my %scantronfiles = (
7516: default => 'default.tab',
7517: custom => 'custom.tab',
7518: );
7519: foreach my $key (keys(%scantronfiles)) {
7520: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
7521: .$scantronfiles{$key};
7522: }
7523: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
7524: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
7525: if (!$switchserver) {
7526: my $servadm = $r->dir_config('lonAdmEMail');
7527: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
7528: if ($configuserok eq 'ok') {
7529: if ($author_ok eq 'ok') {
7530: my %legacyfile = (
7531: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
7532: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
7533: );
7534: my %md5chk;
7535: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 7536: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
7537: chomp($md5chk{$type});
1.46 raeburn 7538: }
7539: if ($md5chk{'default'} ne $md5chk{'custom'}) {
7540: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 7541: ($scantronurls{$type},my $error) =
1.46 raeburn 7542: &legacy_scantronformat($r,$dom,$confname,
7543: $type,$legacyfile{$type},
7544: $scantronurls{$type},
7545: $scantronfiles{$type});
1.60 raeburn 7546: if ($error ne '') {
7547: $error{$type} = $error;
7548: }
7549: }
7550: if (keys(%error) == 0) {
7551: $is_custom = 1;
7552: $confhash{'scantron'}{'scantronformat'} =
7553: $scantronurls{'custom'};
7554: my $putresult =
7555: &Apache::lonnet::put_dom('configuration',
7556: \%confhash,$dom);
7557: if ($putresult ne 'ok') {
7558: $error{'custom'} =
7559: '<span class="LC_error">'.
7560: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7561: }
1.46 raeburn 7562: }
7563: } else {
1.60 raeburn 7564: ($scantronurls{'default'},my $error) =
1.46 raeburn 7565: &legacy_scantronformat($r,$dom,$confname,
7566: 'default',$legacyfile{'default'},
7567: $scantronurls{'default'},
7568: $scantronfiles{'default'});
1.60 raeburn 7569: if ($error eq '') {
7570: $confhash{'scantron'}{'scantronformat'} = '';
7571: my $putresult =
7572: &Apache::lonnet::put_dom('configuration',
7573: \%confhash,$dom);
7574: if ($putresult ne 'ok') {
7575: $error{'default'} =
7576: '<span class="LC_error">'.
7577: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7578: }
7579: } else {
7580: $error{'default'} = $error;
7581: }
1.46 raeburn 7582: }
7583: }
7584: }
7585: } else {
1.95 www 7586: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 7587: }
7588: }
7589: if (ref($settings) eq 'HASH') {
7590: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
7591: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
7592: if ((!@info) || ($info[0] eq 'no_such_dir')) {
7593: $scantronurl = '';
7594: } else {
7595: $scantronurl = $settings->{'scantronformat'};
7596: }
7597: $is_custom = 1;
7598: } else {
7599: $scantronurl = $scantronurls{'default'};
7600: }
7601: } else {
1.60 raeburn 7602: if ($is_custom) {
7603: $scantronurl = $scantronurls{'custom'};
7604: } else {
7605: $scantronurl = $scantronurls{'default'};
7606: }
1.46 raeburn 7607: }
7608: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7609: $datatable .= '<tr'.$css_class.'>';
7610: if (!$is_custom) {
1.65 raeburn 7611: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
7612: '<span class="LC_nobreak">';
1.46 raeburn 7613: if ($scantronurl) {
1.199 raeburn 7614: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
7615: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 7616: } else {
7617: $datatable = &mt('File unavailable for display');
7618: }
1.65 raeburn 7619: $datatable .= '</span></td>';
1.60 raeburn 7620: if (keys(%error) == 0) {
1.306 raeburn 7621: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 7622: if (!$switchserver) {
7623: $datatable .= &mt('Upload:').'<br />';
7624: }
7625: } else {
7626: my $errorstr;
7627: foreach my $key (sort(keys(%error))) {
7628: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7629: }
7630: $datatable .= '<td>'.$errorstr;
7631: }
1.46 raeburn 7632: } else {
7633: if (keys(%error) > 0) {
7634: my $errorstr;
7635: foreach my $key (sort(keys(%error))) {
7636: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7637: }
1.60 raeburn 7638: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 7639: } elsif ($scantronurl) {
1.199 raeburn 7640: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
7641: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 7642: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 7643: $link.
7644: '<label><input type="checkbox" name="scantronformat_del"'.
7645: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 7646: '<td><span class="LC_nobreak"> '.
7647: &mt('Replace:').'</span><br />';
1.46 raeburn 7648: }
7649: }
7650: if (keys(%error) == 0) {
7651: if ($switchserver) {
7652: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
7653: } else {
1.65 raeburn 7654: $datatable .='<span class="LC_nobreak"> '.
7655: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 7656: }
7657: }
7658: $datatable .= '</td></tr>';
7659: $$rowtotal ++;
7660: return $datatable;
7661: }
7662:
7663: sub legacy_scantronformat {
7664: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
7665: my ($url,$error);
7666: my @statinfo = &Apache::lonnet::stat_file($newurl);
7667: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
7668: (my $result,$url) =
7669: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
7670: '','',$newfile);
7671: if ($result ne 'ok') {
1.130 raeburn 7672: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 7673: }
7674: }
7675: return ($url,$error);
7676: }
1.43 raeburn 7677:
1.49 raeburn 7678: sub print_coursecategories {
1.57 raeburn 7679: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
7680: my $datatable;
7681: if ($position eq 'top') {
1.238 raeburn 7682: my (%checked);
7683: my @catitems = ('unauth','auth');
7684: my @cattypes = ('std','domonly','codesrch','none');
7685: $checked{'unauth'} = 'std';
7686: $checked{'auth'} = 'std';
7687: if (ref($settings) eq 'HASH') {
7688: foreach my $type (@cattypes) {
7689: if ($type eq $settings->{'unauth'}) {
7690: $checked{'unauth'} = $type;
7691: }
7692: if ($type eq $settings->{'auth'}) {
7693: $checked{'auth'} = $type;
7694: }
7695: }
7696: }
7697: my %lt = &Apache::lonlocal::texthash (
7698: unauth => 'Catalog type for unauthenticated users',
7699: auth => 'Catalog type for authenticated users',
7700: none => 'No catalog',
7701: std => 'Standard catalog',
7702: domonly => 'Domain-only catalog',
7703: codesrch => "Code search form",
7704: );
7705: my $itemcount = 0;
7706: foreach my $item (@catitems) {
7707: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
7708: $datatable .= '<tr '.$css_class.'>'.
7709: '<td>'.$lt{$item}.'</td>'.
7710: '<td class="LC_right_item"><span class="LC_nobreak">';
7711: foreach my $type (@cattypes) {
7712: my $ischecked;
7713: if ($checked{$item} eq $type) {
7714: $ischecked=' checked="checked"';
7715: }
7716: $datatable .= '<label>'.
7717: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
7718: ' />'.$lt{$type}.'</label> ';
7719: }
7720: $datatable .= '</td></tr>';
7721: $itemcount ++;
7722: }
7723: $$rowtotal += $itemcount;
7724: } elsif ($position eq 'middle') {
1.57 raeburn 7725: my $toggle_cats_crs = ' ';
7726: my $toggle_cats_dom = ' checked="checked" ';
7727: my $can_cat_crs = ' ';
7728: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 7729: my $toggle_catscomm_comm = ' ';
7730: my $toggle_catscomm_dom = ' checked="checked" ';
7731: my $can_catcomm_comm = ' ';
7732: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 7733: my $toggle_catsplace_place = ' ';
7734: my $toggle_catsplace_dom = ' checked="checked" ';
7735: my $can_catplace_place = ' ';
7736: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 7737:
1.57 raeburn 7738: if (ref($settings) eq 'HASH') {
7739: if ($settings->{'togglecats'} eq 'crs') {
7740: $toggle_cats_crs = $toggle_cats_dom;
7741: $toggle_cats_dom = ' ';
7742: }
7743: if ($settings->{'categorize'} eq 'crs') {
7744: $can_cat_crs = $can_cat_dom;
7745: $can_cat_dom = ' ';
7746: }
1.120 raeburn 7747: if ($settings->{'togglecatscomm'} eq 'comm') {
7748: $toggle_catscomm_comm = $toggle_catscomm_dom;
7749: $toggle_catscomm_dom = ' ';
7750: }
7751: if ($settings->{'categorizecomm'} eq 'comm') {
7752: $can_catcomm_comm = $can_catcomm_dom;
7753: $can_catcomm_dom = ' ';
7754: }
1.272 raeburn 7755: if ($settings->{'togglecatsplace'} eq 'place') {
7756: $toggle_catsplace_place = $toggle_catsplace_dom;
7757: $toggle_catsplace_dom = ' ';
7758: }
7759: if ($settings->{'categorizeplace'} eq 'place') {
7760: $can_catplace_place = $can_catplace_dom;
7761: $can_catplace_dom = ' ';
7762: }
1.57 raeburn 7763: }
7764: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 7765: togglecats => 'Show/Hide a course in catalog',
7766: togglecatscomm => 'Show/Hide a community in catalog',
7767: togglecatsplace => 'Show/Hide a placement test in catalog',
7768: categorize => 'Assign a category to a course',
7769: categorizecomm => 'Assign a category to a community',
7770: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 7771: );
7772: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 7773: dom => 'Set in Domain',
7774: crs => 'Set in Course',
7775: comm => 'Set in Community',
7776: place => 'Set in Placement Test',
1.57 raeburn 7777: );
7778: $datatable = '<tr class="LC_odd_row">'.
7779: '<td>'.$title{'togglecats'}.'</td>'.
7780: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7781: '<input type="radio" name="togglecats"'.
7782: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7783: '<label><input type="radio" name="togglecats"'.
7784: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
7785: '</tr><tr>'.
7786: '<td>'.$title{'categorize'}.'</td>'.
7787: '<td class="LC_right_item"><span class="LC_nobreak">'.
7788: '<label><input type="radio" name="categorize"'.
7789: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7790: '<label><input type="radio" name="categorize"'.
7791: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 7792: '</tr><tr class="LC_odd_row">'.
7793: '<td>'.$title{'togglecatscomm'}.'</td>'.
7794: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7795: '<input type="radio" name="togglecatscomm"'.
7796: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7797: '<label><input type="radio" name="togglecatscomm"'.
7798: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
7799: '</tr><tr>'.
7800: '<td>'.$title{'categorizecomm'}.'</td>'.
7801: '<td class="LC_right_item"><span class="LC_nobreak">'.
7802: '<label><input type="radio" name="categorizecomm"'.
7803: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7804: '<label><input type="radio" name="categorizecomm"'.
7805: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.272 raeburn 7806: '</tr><tr>'.
7807: '<td>'.$title{'togglecatsplace'}.'</td>'.
7808: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7809: '<input type="radio" name="togglecatsplace"'.
7810: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7811: '<label><input type="radio" name="togglecatscomm"'.
7812: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
7813: '</tr><tr>'.
7814: '<td>'.$title{'categorizeplace'}.'</td>'.
7815: '<td class="LC_right_item"><span class="LC_nobreak">'.
7816: '<label><input type="radio" name="categorizeplace"'.
7817: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7818: '<label><input type="radio" name="categorizeplace"'.
7819: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 7820: '</tr>';
1.272 raeburn 7821: $$rowtotal += 6;
1.57 raeburn 7822: } else {
7823: my $css_class;
7824: my $itemcount = 1;
7825: my $cathash;
7826: if (ref($settings) eq 'HASH') {
7827: $cathash = $settings->{'cats'};
7828: }
7829: if (ref($cathash) eq 'HASH') {
7830: my (@cats,@trails,%allitems,%idx,@jsarray);
7831: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
7832: \%allitems,\%idx,\@jsarray);
7833: my $maxdepth = scalar(@cats);
7834: my $colattrib = '';
7835: if ($maxdepth > 2) {
7836: $colattrib = ' colspan="2" ';
7837: }
7838: my @path;
7839: if (@cats > 0) {
7840: if (ref($cats[0]) eq 'ARRAY') {
7841: my $numtop = @{$cats[0]};
7842: my $maxnum = $numtop;
1.120 raeburn 7843: my %default_names = (
7844: instcode => &mt('Official courses'),
7845: communities => &mt('Communities'),
1.272 raeburn 7846: placement => &mt('Placement Tests'),
1.120 raeburn 7847: );
7848:
7849: if ((!grep(/^instcode$/,@{$cats[0]})) ||
7850: ($cathash->{'instcode::0'} eq '') ||
7851: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 7852: ($cathash->{'communities::0'} eq '') ||
7853: (!grep(/^placement$/,@{$cats[0]})) ||
7854: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 7855: $maxnum ++;
7856: }
7857: my $lastidx;
7858: for (my $i=0; $i<$numtop; $i++) {
7859: my $parent = $cats[0][$i];
7860: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7861: my $item = &escape($parent).'::0';
7862: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
7863: $lastidx = $idx{$item};
7864: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7865: .'<select name="'.$item.'"'.$chgstr.'>';
7866: for (my $k=0; $k<=$maxnum; $k++) {
7867: my $vpos = $k+1;
7868: my $selstr;
7869: if ($k == $i) {
7870: $selstr = ' selected="selected" ';
7871: }
7872: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7873: }
1.214 raeburn 7874: $datatable .= '</select></span></td><td>';
1.272 raeburn 7875: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 7876: $datatable .= '<span class="LC_nobreak">'
7877: .$default_names{$parent}.'</span>';
7878: if ($parent eq 'instcode') {
7879: $datatable .= '<br /><span class="LC_nobreak">('
7880: .&mt('with institutional codes')
7881: .')</span></td><td'.$colattrib.'>';
7882: } else {
7883: $datatable .= '<table><tr><td>';
7884: }
7885: $datatable .= '<span class="LC_nobreak">'
7886: .'<label><input type="radio" name="'
7887: .$parent.'" value="1" checked="checked" />'
7888: .&mt('Display').'</label>';
7889: if ($parent eq 'instcode') {
7890: $datatable .= ' ';
7891: } else {
7892: $datatable .= '</span></td></tr><tr><td>'
7893: .'<span class="LC_nobreak">';
7894: }
7895: $datatable .= '<label><input type="radio" name="'
7896: .$parent.'" value="0" />'
7897: .&mt('Do not display').'</label></span>';
1.272 raeburn 7898: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 7899: $datatable .= '</td></tr></table>';
7900: }
7901: $datatable .= '</td>';
1.57 raeburn 7902: } else {
7903: $datatable .= $parent
1.214 raeburn 7904: .' <span class="LC_nobreak"><label>'
7905: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 7906: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
7907: }
7908: my $depth = 1;
7909: push(@path,$parent);
7910: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
7911: pop(@path);
7912: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
7913: $itemcount ++;
7914: }
1.48 raeburn 7915: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 7916: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
7917: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 7918: for (my $k=0; $k<=$maxnum; $k++) {
7919: my $vpos = $k+1;
7920: my $selstr;
1.57 raeburn 7921: if ($k == $numtop) {
1.48 raeburn 7922: $selstr = ' selected="selected" ';
7923: }
7924: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7925: }
1.59 bisitz 7926: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 7927: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
7928: .'</tr>'."\n";
1.48 raeburn 7929: $itemcount ++;
1.272 raeburn 7930: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 7931: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
7932: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7933: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
7934: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
7935: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
7936: for (my $k=0; $k<=$maxnum; $k++) {
7937: my $vpos = $k+1;
7938: my $selstr;
7939: if ($k == $maxnum) {
7940: $selstr = ' selected="selected" ';
7941: }
7942: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 7943: }
1.120 raeburn 7944: $datatable .= '</select></span></td>'.
7945: '<td><span class="LC_nobreak">'.
7946: $default_names{$default}.'</span>';
7947: if ($default eq 'instcode') {
7948: $datatable .= '<br /><span class="LC_nobreak">('
7949: .&mt('with institutional codes').')</span>';
7950: }
7951: $datatable .= '</td>'
7952: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
7953: .&mt('Display').'</label> '
7954: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
7955: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 7956: }
7957: }
7958: }
1.57 raeburn 7959: } else {
7960: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 7961: }
7962: } else {
1.238 raeburn 7963: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 7964: .&initialize_categories($itemcount);
1.48 raeburn 7965: }
1.57 raeburn 7966: $$rowtotal += $itemcount;
1.48 raeburn 7967: }
7968: return $datatable;
7969: }
7970:
1.69 raeburn 7971: sub print_serverstatuses {
7972: my ($dom,$settings,$rowtotal) = @_;
7973: my $datatable;
7974: my @pages = &serverstatus_pages();
7975: my (%namedaccess,%machineaccess);
7976: foreach my $type (@pages) {
7977: $namedaccess{$type} = '';
7978: $machineaccess{$type}= '';
7979: }
7980: if (ref($settings) eq 'HASH') {
7981: foreach my $type (@pages) {
7982: if (exists($settings->{$type})) {
7983: if (ref($settings->{$type}) eq 'HASH') {
7984: foreach my $key (keys(%{$settings->{$type}})) {
7985: if ($key eq 'namedusers') {
7986: $namedaccess{$type} = $settings->{$type}->{$key};
7987: } elsif ($key eq 'machines') {
7988: $machineaccess{$type} = $settings->{$type}->{$key};
7989: }
7990: }
7991: }
7992: }
7993: }
7994: }
1.81 raeburn 7995: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7996: my $rownum = 0;
7997: my $css_class;
7998: foreach my $type (@pages) {
7999: $rownum ++;
8000: $css_class = $rownum%2?' class="LC_odd_row"':'';
8001: $datatable .= '<tr'.$css_class.'>'.
8002: '<td><span class="LC_nobreak">'.
8003: $titles->{$type}.'</span></td>'.
8004: '<td class="LC_left_item">'.
8005: '<input type="text" name="'.$type.'_namedusers" '.
8006: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
8007: '<td class="LC_right_item">'.
8008: '<span class="LC_nobreak">'.
8009: '<input type="text" name="'.$type.'_machines" '.
8010: 'value="'.$machineaccess{$type}.'" size="10" />'.
8011: '</td></tr>'."\n";
8012: }
8013: $$rowtotal += $rownum;
8014: return $datatable;
8015: }
8016:
8017: sub serverstatus_pages {
8018: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 8019: 'checksums','clusterstatus','certstatus','metadata_keywords',
8020: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
8021: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 8022: }
8023:
1.236 raeburn 8024: sub defaults_javascript {
8025: my ($settings) = @_;
1.294 raeburn 8026: my $intauthcheck = &mt('Warning: disallowing login for an authenticated user if the stored cost is less than the default will require a password reset by/for the user.');
8027: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
8028: &js_escape(\$intauthcheck);
8029: &js_escape(\$intauthcost);
8030: my $intauthjs = <<"ENDSCRIPT";
8031:
8032: function warnIntAuth(field) {
8033: if (field.name == 'intauth_check') {
8034: if (field.value == '2') {
8035: alert('$intauthcheck');
8036: }
8037: }
8038: if (field.name == 'intauth_cost') {
8039: field.value.replace(/\s/g,'');
8040: if (field.value != '') {
8041: var regexdigit=/^\\d+\$/;
8042: if (!regexdigit.test(field.value)) {
8043: alert('$intauthcost');
8044: }
8045: }
8046: }
8047: return;
8048: }
8049:
8050: ENDSCRIPT
8051:
8052: if (ref($settings) ne 'HASH') {
8053: return &Apache::lonhtmlcommon::scripttag($intauthjs);
8054: }
1.236 raeburn 8055: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
8056: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
8057: if ($maxnum eq '') {
8058: $maxnum = 0;
8059: }
8060: $maxnum ++;
1.249 raeburn 8061: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 8062: return <<"ENDSCRIPT";
8063: <script type="text/javascript">
8064: // <![CDATA[
8065: function reorderTypes(form,caller) {
8066: var changedVal;
8067: $jstext
8068: var newpos = 'addinststatus_pos';
8069: var current = new Array;
8070: var maxh = $maxnum;
8071: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8072: var oldVal;
8073: if (caller == newpos) {
8074: changedVal = newitemVal;
8075: } else {
8076: var curritem = 'inststatus_pos_'+caller;
8077: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
8078: current[newitemVal] = newpos;
8079: }
8080: for (var i=0; i<inststatuses.length; i++) {
8081: if (inststatuses[i] != caller) {
8082: var elementName = 'inststatus_pos_'+inststatuses[i];
8083: if (form.elements[elementName]) {
8084: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8085: current[currVal] = elementName;
8086: }
8087: }
8088: }
8089: for (var j=0; j<maxh; j++) {
8090: if (current[j] == undefined) {
8091: oldVal = j;
8092: }
8093: }
8094: if (oldVal < changedVal) {
8095: for (var k=oldVal+1; k<=changedVal ; k++) {
8096: var elementName = current[k];
8097: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8098: }
8099: } else {
8100: for (var k=changedVal; k<oldVal; k++) {
8101: var elementName = current[k];
8102: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8103: }
8104: }
8105: return;
8106: }
8107:
1.294 raeburn 8108: $intauthjs
8109:
1.236 raeburn 8110: // ]]>
8111: </script>
8112:
8113: ENDSCRIPT
1.294 raeburn 8114: } else {
8115: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 8116: }
8117: }
8118:
1.49 raeburn 8119: sub coursecategories_javascript {
8120: my ($settings) = @_;
1.57 raeburn 8121: my ($output,$jstext,$cathash);
1.49 raeburn 8122: if (ref($settings) eq 'HASH') {
1.57 raeburn 8123: $cathash = $settings->{'cats'};
8124: }
8125: if (ref($cathash) eq 'HASH') {
1.49 raeburn 8126: my (@cats,@jsarray,%idx);
1.57 raeburn 8127: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 8128: if (@jsarray > 0) {
8129: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
8130: for (my $i=0; $i<@jsarray; $i++) {
8131: if (ref($jsarray[$i]) eq 'ARRAY') {
8132: my $catstr = join('","',@{$jsarray[$i]});
8133: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
8134: }
8135: }
8136: }
8137: } else {
8138: $jstext = ' var categories = Array(1);'."\n".
8139: ' categories[0] = Array("instcode_pos");'."\n";
8140: }
1.237 bisitz 8141: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
8142: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 8143: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 8144: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
8145: &js_escape(\$instcode_reserved);
8146: &js_escape(\$communities_reserved);
1.272 raeburn 8147: &js_escape(\$placement_reserved);
1.265 damieng 8148: &js_escape(\$choose_again);
1.49 raeburn 8149: $output = <<"ENDSCRIPT";
8150: <script type="text/javascript">
1.109 raeburn 8151: // <![CDATA[
1.49 raeburn 8152: function reorderCats(form,parent,item,idx) {
8153: var changedVal;
8154: $jstext
8155: var newpos = 'addcategory_pos';
8156: if (parent == '') {
8157: var has_instcode = 0;
8158: var maxtop = categories[idx].length;
8159: for (var j=0; j<maxtop; j++) {
8160: if (categories[idx][j] == 'instcode::0') {
8161: has_instcode == 1;
8162: }
8163: }
8164: if (has_instcode == 0) {
8165: categories[idx][maxtop] = 'instcode_pos';
8166: }
8167: } else {
8168: newpos += '_'+parent;
8169: }
8170: var maxh = 1 + categories[idx].length;
8171: var current = new Array;
8172: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8173: if (item == newpos) {
8174: changedVal = newitemVal;
8175: } else {
8176: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
8177: current[newitemVal] = newpos;
8178: }
8179: for (var i=0; i<categories[idx].length; i++) {
8180: var elementName = categories[idx][i];
8181: if (elementName != item) {
8182: if (form.elements[elementName]) {
8183: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8184: current[currVal] = elementName;
8185: }
8186: }
8187: }
8188: var oldVal;
8189: for (var j=0; j<maxh; j++) {
8190: if (current[j] == undefined) {
8191: oldVal = j;
8192: }
8193: }
8194: if (oldVal < changedVal) {
8195: for (var k=oldVal+1; k<=changedVal ; k++) {
8196: var elementName = current[k];
8197: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8198: }
8199: } else {
8200: for (var k=changedVal; k<oldVal; k++) {
8201: var elementName = current[k];
8202: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8203: }
8204: }
8205: return;
8206: }
1.120 raeburn 8207:
8208: function categoryCheck(form) {
8209: if (form.elements['addcategory_name'].value == 'instcode') {
8210: alert('$instcode_reserved\\n$choose_again');
8211: return false;
8212: }
8213: if (form.elements['addcategory_name'].value == 'communities') {
8214: alert('$communities_reserved\\n$choose_again');
8215: return false;
8216: }
1.272 raeburn 8217: if (form.elements['addcategory_name'].value == 'placement') {
8218: alert('$placement_reserved\\n$choose_again');
8219: return false;
8220: }
1.120 raeburn 8221: return true;
8222: }
8223:
1.109 raeburn 8224: // ]]>
1.49 raeburn 8225: </script>
8226:
8227: ENDSCRIPT
8228: return $output;
8229: }
8230:
1.48 raeburn 8231: sub initialize_categories {
8232: my ($itemcount) = @_;
1.120 raeburn 8233: my ($datatable,$css_class,$chgstr);
8234: my %default_names = (
8235: instcode => 'Official courses (with institutional codes)',
8236: communities => 'Communities',
1.272 raeburn 8237: placement => 'Placement Tests',
1.120 raeburn 8238: );
8239: my $select0 = ' selected="selected"';
8240: my $select1 = '';
1.272 raeburn 8241: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 8242: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8243: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
1.272 raeburn 8244: if (($default eq 'communities') || ($default eq 'placement')) {
1.120 raeburn 8245: $select1 = $select0;
8246: $select0 = '';
8247: }
8248: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8249: .'<select name="'.$default.'_pos">'
8250: .'<option value="0"'.$select0.'>1</option>'
8251: .'<option value="1"'.$select1.'>2</option>'
8252: .'<option value="2">3</option></select> '
8253: .$default_names{$default}
8254: .'</span></td><td><span class="LC_nobreak">'
8255: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
8256: .&mt('Display').'</label> <label>'
8257: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 8258: .'</label></span></td></tr>';
1.120 raeburn 8259: $itemcount ++;
8260: }
1.48 raeburn 8261: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 8262: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 8263: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 8264: .'<select name="addcategory_pos"'.$chgstr.'>'
8265: .'<option value="0">1</option>'
8266: .'<option value="1">2</option>'
8267: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 8268: .&mt('Add category').'</td><td>'.&mt('Name:')
8269: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
8270: return $datatable;
8271: }
8272:
8273: sub build_category_rows {
1.49 raeburn 8274: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
8275: my ($text,$name,$item,$chgstr);
1.48 raeburn 8276: if (ref($cats) eq 'ARRAY') {
8277: my $maxdepth = scalar(@{$cats});
8278: if (ref($cats->[$depth]) eq 'HASH') {
8279: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
8280: my $numchildren = @{$cats->[$depth]{$parent}};
8281: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 8282: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 8283: my ($idxnum,$parent_name,$parent_item);
8284: my $higher = $depth - 1;
8285: if ($higher == 0) {
8286: $parent_name = &escape($parent).'::'.$higher;
8287: } else {
8288: if (ref($path) eq 'ARRAY') {
8289: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8290: }
8291: }
8292: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 8293: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 8294: if ($j < $numchildren) {
1.48 raeburn 8295: $name = $cats->[$depth]{$parent}[$j];
8296: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 8297: $idxnum = $idx->{$item};
8298: } else {
8299: $name = $parent_name;
8300: $item = $parent_item;
1.48 raeburn 8301: }
1.49 raeburn 8302: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
8303: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 8304: for (my $i=0; $i<=$numchildren; $i++) {
8305: my $vpos = $i+1;
8306: my $selstr;
8307: if ($j == $i) {
8308: $selstr = ' selected="selected" ';
8309: }
8310: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
8311: }
8312: $text .= '</select> ';
8313: if ($j < $numchildren) {
8314: my $deeper = $depth+1;
8315: $text .= $name.' '
8316: .'<label><input type="checkbox" name="deletecategory" value="'
8317: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
8318: if(ref($path) eq 'ARRAY') {
8319: push(@{$path},$name);
1.49 raeburn 8320: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 8321: pop(@{$path});
8322: }
8323: } else {
1.59 bisitz 8324: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 8325: if ($j == $numchildren) {
8326: $text .= $name;
8327: } else {
8328: $text .= $item;
8329: }
8330: $text .= '" value="" />';
8331: }
8332: $text .= '</td></tr>';
8333: }
8334: $text .= '</table></td>';
8335: } else {
8336: my $higher = $depth-1;
8337: if ($higher == 0) {
8338: $name = &escape($parent).'::'.$higher;
8339: } else {
8340: if (ref($path) eq 'ARRAY') {
8341: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8342: }
8343: }
8344: my $colspan;
8345: if ($parent ne 'instcode') {
8346: $colspan = $maxdepth - $depth - 1;
8347: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
8348: }
8349: }
8350: }
8351: }
8352: return $text;
8353: }
8354:
1.33 raeburn 8355: sub modifiable_userdata_row {
1.305 raeburn 8356: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
8357: $rowid,$customcss,$rowstyle) = @_;
1.228 raeburn 8358: my ($role,$rolename,$statustype);
8359: $role = $item;
1.224 raeburn 8360: if ($context eq 'cancreate') {
1.305 raeburn 8361: if ($item =~ /^(emailusername)_(.+)$/) {
8362: $role = $1;
8363: $statustype = $2;
1.228 raeburn 8364: if (ref($usertypes) eq 'HASH') {
8365: if ($usertypes->{$statustype}) {
8366: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
8367: } else {
8368: $rolename = &mt('Data provided by user');
8369: }
8370: }
1.224 raeburn 8371: }
8372: } elsif ($context eq 'selfcreate') {
1.63 raeburn 8373: if (ref($usertypes) eq 'HASH') {
8374: $rolename = $usertypes->{$role};
8375: } else {
8376: $rolename = $role;
8377: }
1.33 raeburn 8378: } else {
1.63 raeburn 8379: if ($role eq 'cr') {
8380: $rolename = &mt('Custom role');
8381: } else {
8382: $rolename = &Apache::lonnet::plaintext($role);
8383: }
1.33 raeburn 8384: }
1.224 raeburn 8385: my (@fields,%fieldtitles);
8386: if (ref($fieldsref) eq 'ARRAY') {
8387: @fields = @{$fieldsref};
8388: } else {
8389: @fields = ('lastname','firstname','middlename','generation',
8390: 'permanentemail','id');
8391: }
8392: if ((ref($titlesref) eq 'HASH')) {
8393: %fieldtitles = %{$titlesref};
8394: } else {
8395: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8396: }
1.33 raeburn 8397: my $output;
1.305 raeburn 8398: my $css_class;
8399: if ($rowcount%2) {
8400: $css_class = 'LC_odd_row';
8401: }
8402: if ($customcss) {
8403: $css_class .= " $customcss";
8404: }
8405: $css_class =~ s/^\s+//;
8406: if ($css_class) {
8407: $css_class = ' class="'.$css_class.'"';
8408: }
8409: if ($rowstyle) {
8410: $css_class .= ' style="'.$rowstyle.'"';
8411: }
8412: if ($rowid) {
8413: $rowid = ' id="'.$rowid.'"';
8414: }
8415: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 8416: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
8417: '<td class="LC_left_item" colspan="2"><table>';
8418: my $rem;
8419: my %checks;
8420: if (ref($settings) eq 'HASH') {
8421: if (ref($settings->{$context}) eq 'HASH') {
8422: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 8423: my $hashref = $settings->{$context}->{$role};
8424: if ($role eq 'emailusername') {
8425: if ($statustype) {
8426: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
8427: $hashref = $settings->{$context}->{$role}->{$statustype};
8428: if (ref($hashref) eq 'HASH') {
8429: foreach my $field (@fields) {
8430: if ($hashref->{$field}) {
8431: $checks{$field} = $hashref->{$field};
8432: }
8433: }
8434: }
8435: }
8436: }
8437: } else {
8438: if (ref($hashref) eq 'HASH') {
8439: foreach my $field (@fields) {
8440: if ($hashref->{$field}) {
8441: $checks{$field} = ' checked="checked" ';
8442: }
8443: }
1.33 raeburn 8444: }
8445: }
8446: }
8447: }
8448: }
1.305 raeburn 8449:
8450: my $total = scalar(@fields);
8451: for (my $i=0; $i<$total; $i++) {
8452: $rem = $i%($numinrow);
1.33 raeburn 8453: if ($rem == 0) {
8454: if ($i > 0) {
8455: $output .= '</tr>';
8456: }
8457: $output .= '<tr>';
8458: }
8459: my $check = ' ';
1.228 raeburn 8460: unless ($role eq 'emailusername') {
8461: if (exists($checks{$fields[$i]})) {
8462: $check = $checks{$fields[$i]}
8463: } else {
8464: if ($role eq 'st') {
8465: if (ref($settings) ne 'HASH') {
8466: $check = ' checked="checked" ';
8467: }
1.33 raeburn 8468: }
8469: }
8470: }
8471: $output .= '<td class="LC_left_item">'.
1.228 raeburn 8472: '<span class="LC_nobreak">';
8473: if ($role eq 'emailusername') {
8474: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
8475: $checks{$fields[$i]} = 'omit';
8476: }
8477: foreach my $option ('required','optional','omit') {
8478: my $checked='';
8479: if ($checks{$fields[$i]} eq $option) {
8480: $checked='checked="checked" ';
8481: }
8482: $output .= '<label>'.
8483: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
8484: &mt($option).'</label>'.(' ' x2);
8485: }
8486: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
8487: } else {
8488: $output .= '<label>'.
8489: '<input type="checkbox" name="canmodify_'.$role.'" '.
8490: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
8491: '</label>';
8492: }
8493: $output .= '</span></td>';
1.33 raeburn 8494: }
1.305 raeburn 8495: $rem = $total%$numinrow;
8496: my $colsleft;
8497: if ($rem) {
8498: $colsleft = $numinrow - $rem;
8499: }
8500: if ($colsleft > 1) {
1.33 raeburn 8501: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8502: ' </td>';
8503: } elsif ($colsleft == 1) {
8504: $output .= '<td class="LC_left_item"> </td>';
8505: }
8506: $output .= '</tr></table></td></tr>';
8507: return $output;
8508: }
1.28 raeburn 8509:
1.93 raeburn 8510: sub insttypes_row {
1.305 raeburn 8511: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
8512: $customcss,$rowstyle) = @_;
1.93 raeburn 8513: my %lt = &Apache::lonlocal::texthash (
8514: cansearch => 'Users allowed to search',
8515: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 8516: lockablenames => 'User preference to lock name',
1.305 raeburn 8517: selfassign => 'Self-reportable affiliations',
1.315 raeburn 8518: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 8519: );
8520: my $showdom;
8521: if ($context eq 'cansearch') {
8522: $showdom = ' ('.$dom.')';
8523: }
1.165 raeburn 8524: my $class = 'LC_left_item';
8525: if ($context eq 'statustocreate') {
8526: $class = 'LC_right_item';
8527: }
1.305 raeburn 8528: my $css_class;
8529: if ($$rowtotal%2) {
8530: $css_class = 'LC_odd_row';
8531: }
8532: if ($customcss) {
8533: $css_class .= ' '.$customcss;
8534: }
8535: $css_class =~ s/^\s+//;
8536: if ($css_class) {
8537: $css_class = ' class="'.$css_class.'"';
8538: }
8539: if ($rowstyle) {
8540: $css_class .= ' style="'.$rowstyle.'"';
8541: }
8542: if ($onclick) {
8543: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 8544: }
8545: my $output = '<tr'.$css_class.'>'.
8546: '<td>'.$lt{$context}.$showdom.
8547: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 8548: my $rem;
8549: if (ref($types) eq 'ARRAY') {
8550: for (my $i=0; $i<@{$types}; $i++) {
8551: if (defined($usertypes->{$types->[$i]})) {
8552: my $rem = $i%($numinrow);
8553: if ($rem == 0) {
8554: if ($i > 0) {
8555: $output .= '</tr>';
8556: }
8557: $output .= '<tr>';
1.23 raeburn 8558: }
1.26 raeburn 8559: my $check = ' ';
1.99 raeburn 8560: if (ref($settings) eq 'HASH') {
8561: if (ref($settings->{$context}) eq 'ARRAY') {
8562: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
8563: $check = ' checked="checked" ';
8564: }
1.315 raeburn 8565: } elsif (ref($settings->{$context}) eq 'HASH') {
8566: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
8567: $check = ' checked="checked" ';
8568: }
1.99 raeburn 8569: } elsif ($context eq 'statustocreate') {
1.26 raeburn 8570: $check = ' checked="checked" ';
8571: }
1.23 raeburn 8572: }
1.26 raeburn 8573: $output .= '<td class="LC_left_item">'.
8574: '<span class="LC_nobreak"><label>'.
1.93 raeburn 8575: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 8576: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 8577: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 8578: }
8579: }
1.26 raeburn 8580: $rem = @{$types}%($numinrow);
1.23 raeburn 8581: }
8582: my $colsleft = $numinrow - $rem;
1.315 raeburn 8583: if ($context eq 'overrides') {
8584: if ($colsleft > 1) {
8585: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8586: } else {
8587: $output .= '<td class="LC_left_item">';
8588: }
8589: $output .= ' ';
1.23 raeburn 8590: } else {
1.315 raeburn 8591: if (($rem == 0) && (@{$types} > 0)) {
8592: $output .= '<tr>';
8593: }
8594: if ($colsleft > 1) {
8595: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8596: } else {
8597: $output .= '<td class="LC_left_item">';
8598: }
8599: my $defcheck = ' ';
8600: if (ref($settings) eq 'HASH') {
8601: if (ref($settings->{$context}) eq 'ARRAY') {
8602: if (grep(/^default$/,@{$settings->{$context}})) {
8603: $defcheck = ' checked="checked" ';
8604: }
8605: } elsif ($context eq 'statustocreate') {
1.99 raeburn 8606: $defcheck = ' checked="checked" ';
8607: }
1.26 raeburn 8608: }
1.315 raeburn 8609: $output .= '<span class="LC_nobreak"><label>'.
8610: '<input type="checkbox" name="'.$context.'" '.
8611: 'value="default"'.$defcheck.$onclick.' />'.
8612: $othertitle.'</label></span>';
1.23 raeburn 8613: }
1.315 raeburn 8614: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 8615: return $output;
1.23 raeburn 8616: }
8617:
8618: sub sorted_searchtitles {
8619: my %searchtitles = &Apache::lonlocal::texthash(
8620: 'uname' => 'username',
8621: 'lastname' => 'last name',
8622: 'lastfirst' => 'last name, first name',
8623: );
8624: my @titleorder = ('uname','lastname','lastfirst');
8625: return (\%searchtitles,\@titleorder);
8626: }
8627:
1.25 raeburn 8628: sub sorted_searchtypes {
8629: my %srchtypes_desc = (
8630: exact => 'is exact match',
8631: contains => 'contains ..',
8632: begins => 'begins with ..',
8633: );
8634: my @srchtypeorder = ('exact','begins','contains');
8635: return (\%srchtypes_desc,\@srchtypeorder);
8636: }
8637:
1.3 raeburn 8638: sub usertype_update_row {
8639: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
8640: my $datatable;
8641: my $numinrow = 4;
8642: foreach my $type (@{$types}) {
8643: if (defined($usertypes->{$type})) {
8644: $$rownums ++;
8645: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
8646: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
8647: '</td><td class="LC_left_item"><table>';
8648: for (my $i=0; $i<@{$fields}; $i++) {
8649: my $rem = $i%($numinrow);
8650: if ($rem == 0) {
8651: if ($i > 0) {
8652: $datatable .= '</tr>';
8653: }
8654: $datatable .= '<tr>';
8655: }
8656: my $check = ' ';
1.39 raeburn 8657: if (ref($settings) eq 'HASH') {
8658: if (ref($settings->{'fields'}) eq 'HASH') {
8659: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
8660: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
8661: $check = ' checked="checked" ';
8662: }
1.3 raeburn 8663: }
8664: }
8665: }
8666:
8667: if ($i == @{$fields}-1) {
8668: my $colsleft = $numinrow - $rem;
8669: if ($colsleft > 1) {
8670: $datatable .= '<td colspan="'.$colsleft.'">';
8671: } else {
8672: $datatable .= '<td>';
8673: }
8674: } else {
8675: $datatable .= '<td>';
8676: }
1.8 raeburn 8677: $datatable .= '<span class="LC_nobreak"><label>'.
8678: '<input type="checkbox" name="updateable_'.$type.
8679: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
8680: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 8681: }
8682: $datatable .= '</tr></table></td></tr>';
8683: }
8684: }
8685: return $datatable;
1.1 raeburn 8686: }
8687:
8688: sub modify_login {
1.205 raeburn 8689: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 8690: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
8691: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
8692: %title = ( coursecatalog => 'Display course catalog',
8693: adminmail => 'Display administrator E-mail address',
1.188 raeburn 8694: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 8695: newuser => 'Link for visitors to create a user account',
8696: loginheader => 'Log-in box header');
8697: @offon = ('off','on');
1.112 raeburn 8698: if (ref($domconfig{login}) eq 'HASH') {
8699: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
8700: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
8701: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
8702: }
8703: }
8704: }
1.9 raeburn 8705: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
8706: \%domconfig,\%loginhash);
1.188 raeburn 8707: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 8708: foreach my $item (@toggles) {
8709: $loginhash{login}{$item} = $env{'form.'.$item};
8710: }
1.41 raeburn 8711: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 8712: if (ref($colchanges{'login'}) eq 'HASH') {
8713: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
8714: \%loginhash);
8715: }
1.110 raeburn 8716:
1.149 raeburn 8717: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 8718: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 8719: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 8720: if (keys(%servers) > 1) {
8721: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 8722: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
8723: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
8724: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
8725: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
8726: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
8727: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8728: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8729: $changes{'loginvia'}{$lonhost} = 1;
8730: } else {
8731: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
8732: $changes{'loginvia'}{$lonhost} = 1;
8733: }
8734: } else {
8735: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8736: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8737: $changes{'loginvia'}{$lonhost} = 1;
8738: }
8739: }
8740: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
8741: foreach my $item (@loginvia_attribs) {
8742: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
8743: }
8744: } else {
8745: foreach my $item (@loginvia_attribs) {
8746: my $new = $env{'form.'.$lonhost.'_'.$item};
8747: if (($item eq 'serverpath') && ($new eq 'custom')) {
8748: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
8749: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
8750: $new = '/';
8751: }
8752: }
8753: if (($item eq 'custompath') &&
8754: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
8755: $new = '';
8756: }
8757: if ($new ne $curr_loginvia{$lonhost}{$item}) {
8758: $changes{'loginvia'}{$lonhost} = 1;
8759: }
8760: if ($item eq 'exempt') {
1.256 raeburn 8761: $new = &check_exempt_addresses($new);
1.128 raeburn 8762: }
8763: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
8764: }
8765: }
1.112 raeburn 8766: } else {
1.128 raeburn 8767: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8768: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 8769: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 8770: foreach my $item (@loginvia_attribs) {
8771: my $new = $env{'form.'.$lonhost.'_'.$item};
8772: if (($item eq 'serverpath') && ($new eq 'custom')) {
8773: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
8774: $new = '/';
8775: }
8776: }
8777: if (($item eq 'custompath') &&
8778: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
8779: $new = '';
8780: }
8781: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
8782: }
1.110 raeburn 8783: }
8784: }
8785: }
8786: }
1.119 raeburn 8787:
1.168 raeburn 8788: my $servadm = $r->dir_config('lonAdmEMail');
8789: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
8790: if (ref($domconfig{'login'}) eq 'HASH') {
8791: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
8792: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
8793: if ($lang eq 'nolang') {
8794: push(@currlangs,$lang);
8795: } elsif (defined($langchoices{$lang})) {
8796: push(@currlangs,$lang);
8797: } else {
8798: next;
8799: }
8800: }
8801: }
8802: }
8803: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
8804: if (@currlangs > 0) {
8805: foreach my $lang (@currlangs) {
8806: if (grep(/^\Q$lang\E$/,@delurls)) {
8807: $changes{'helpurl'}{$lang} = 1;
8808: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
8809: $changes{'helpurl'}{$lang} = 1;
8810: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
8811: push(@newlangs,$lang);
8812: } else {
8813: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
8814: }
8815: }
8816: }
8817: unless (grep(/^nolang$/,@currlangs)) {
8818: if ($env{'form.loginhelpurl_nolang.filename'}) {
8819: $changes{'helpurl'}{'nolang'} = 1;
8820: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
8821: push(@newlangs,'nolang');
8822: }
8823: }
8824: if ($env{'form.loginhelpurl_add_lang'}) {
8825: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
8826: ($env{'form.loginhelpurl_add_file.filename'})) {
8827: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
8828: $addedfile = $env{'form.loginhelpurl_add_lang'};
8829: }
8830: }
8831: if ((@newlangs > 0) || ($addedfile)) {
8832: my $error;
8833: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8834: if ($configuserok eq 'ok') {
8835: if ($switchserver) {
8836: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
8837: } elsif ($author_ok eq 'ok') {
8838: my @allnew = @newlangs;
8839: if ($addedfile ne '') {
8840: push(@allnew,$addedfile);
8841: }
8842: foreach my $lang (@allnew) {
8843: my $formelem = 'loginhelpurl_'.$lang;
8844: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
8845: $formelem = 'loginhelpurl_add_file';
8846: }
8847: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
8848: "help/$lang",'','',$newfile{$lang});
8849: if ($result eq 'ok') {
8850: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
8851: $changes{'helpurl'}{$lang} = 1;
8852: } else {
8853: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
8854: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 8855: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 8856: (!grep(/^\Q$lang\E$/,@delurls))) {
8857: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
8858: }
8859: }
8860: }
8861: } else {
8862: $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);
8863: }
8864: } else {
8865: $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);
8866: }
8867: if ($error) {
8868: &Apache::lonnet::logthis($error);
8869: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8870: }
8871: }
1.256 raeburn 8872:
8873: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
8874: if (ref($domconfig{'login'}) eq 'HASH') {
8875: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
8876: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
8877: if ($domservers{$lonhost}) {
8878: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
8879: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 8880: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 8881: }
8882: }
8883: }
8884: }
8885: }
8886: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
8887: foreach my $lonhost (sort(keys(%domservers))) {
8888: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
8889: $changes{'headtag'}{$lonhost} = 1;
8890: } else {
8891: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
8892: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
8893: }
8894: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
8895: push(@newhosts,$lonhost);
8896: } elsif ($currheadtagurls{$lonhost}) {
8897: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
8898: if ($currexempt{$lonhost}) {
1.289 raeburn 8899: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 8900: $changes{'headtag'}{$lonhost} = 1;
8901: }
8902: } elsif ($possexempt{$lonhost}) {
8903: $changes{'headtag'}{$lonhost} = 1;
8904: }
8905: if ($possexempt{$lonhost}) {
8906: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
8907: }
8908: }
8909: }
8910: }
8911: if (@newhosts) {
8912: my $error;
8913: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8914: if ($configuserok eq 'ok') {
8915: if ($switchserver) {
8916: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
8917: } elsif ($author_ok eq 'ok') {
8918: foreach my $lonhost (@newhosts) {
8919: my $formelem = 'loginheadtag_'.$lonhost;
8920: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
8921: "login/headtag/$lonhost",'','',
8922: $env{'form.loginheadtag_'.$lonhost.'.filename'});
8923: if ($result eq 'ok') {
8924: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
8925: $changes{'headtag'}{$lonhost} = 1;
8926: if ($possexempt{$lonhost}) {
8927: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
8928: }
8929: } else {
8930: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
8931: $newheadtagurls{$lonhost},$result);
8932: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
8933: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
8934: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
8935: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
8936: }
8937: }
8938: }
8939: } else {
8940: $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);
8941: }
8942: } else {
8943: $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);
8944: }
8945: if ($error) {
8946: &Apache::lonnet::logthis($error);
8947: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8948: }
8949: }
1.169 raeburn 8950: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 8951:
8952: my $defaulthelpfile = '/adm/loginproblems.html';
8953: my $defaulttext = &mt('Default in use');
8954:
1.1 raeburn 8955: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
8956: $dom);
8957: if ($putresult eq 'ok') {
1.188 raeburn 8958: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 8959: my %defaultchecked = (
8960: 'coursecatalog' => 'on',
1.188 raeburn 8961: 'helpdesk' => 'on',
1.42 raeburn 8962: 'adminmail' => 'off',
1.43 raeburn 8963: 'newuser' => 'off',
1.42 raeburn 8964: );
1.55 raeburn 8965: if (ref($domconfig{'login'}) eq 'HASH') {
8966: foreach my $item (@toggles) {
8967: if ($defaultchecked{$item} eq 'on') {
8968: if (($domconfig{'login'}{$item} eq '0') &&
8969: ($env{'form.'.$item} eq '1')) {
8970: $changes{$item} = 1;
8971: } elsif (($domconfig{'login'}{$item} eq '' ||
8972: $domconfig{'login'}{$item} eq '1') &&
8973: ($env{'form.'.$item} eq '0')) {
8974: $changes{$item} = 1;
8975: }
8976: } elsif ($defaultchecked{$item} eq 'off') {
8977: if (($domconfig{'login'}{$item} eq '1') &&
8978: ($env{'form.'.$item} eq '0')) {
8979: $changes{$item} = 1;
8980: } elsif (($domconfig{'login'}{$item} eq '' ||
8981: $domconfig{'login'}{$item} eq '0') &&
8982: ($env{'form.'.$item} eq '1')) {
8983: $changes{$item} = 1;
8984: }
1.42 raeburn 8985: }
8986: }
1.41 raeburn 8987: }
1.6 raeburn 8988: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 8989: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8990: if (ref($lastactref) eq 'HASH') {
8991: $lastactref->{'domainconfig'} = 1;
8992: }
1.1 raeburn 8993: $resulttext = &mt('Changes made:').'<ul>';
8994: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 8995: if ($item eq 'loginvia') {
1.112 raeburn 8996: if (ref($changes{$item}) eq 'HASH') {
8997: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
8998: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 8999: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
9000: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
9001: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
9002: $protocol = 'http' if ($protocol ne 'https');
9003: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
9004:
9005: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
9006: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
9007: } else {
9008: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
9009: }
9010: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
9011: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
9012: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
9013: }
9014: $resulttext .= '</li>';
9015: } else {
9016: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
9017: }
1.112 raeburn 9018: } else {
1.128 raeburn 9019: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 9020: }
9021: }
1.128 raeburn 9022: $resulttext .= '</ul></li>';
1.112 raeburn 9023: }
1.168 raeburn 9024: } elsif ($item eq 'helpurl') {
9025: if (ref($changes{$item}) eq 'HASH') {
9026: foreach my $lang (sort(keys(%{$changes{$item}}))) {
9027: if (grep(/^\Q$lang\E$/,@delurls)) {
9028: my ($chg,$link);
9029: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
9030: if ($lang eq 'nolang') {
9031: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
9032: } else {
9033: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
9034: }
9035: $resulttext .= '<li>'.$chg.'</li>';
9036: } else {
9037: my $chg;
9038: if ($lang eq 'nolang') {
9039: $chg = &mt('custom log-in help file for no preferred language');
9040: } else {
9041: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
9042: }
9043: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
9044: $loginhash{'login'}{'helpurl'}{$lang}.
9045: '?inhibitmenu=yes',$chg,600,500).
9046: '</li>';
9047: }
9048: }
9049: }
1.256 raeburn 9050: } elsif ($item eq 'headtag') {
9051: if (ref($changes{$item}) eq 'HASH') {
9052: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
9053: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9054: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
9055: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9056: $resulttext .= '<li><a href="'.
9057: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
9058: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
9059: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
9060: if ($possexempt{$lonhost}) {
9061: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
9062: } else {
9063: $resulttext .= &mt('included for any client IP');
9064: }
9065: $resulttext .= '</li>';
9066: }
9067: }
9068: }
1.169 raeburn 9069: } elsif ($item eq 'captcha') {
9070: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 9071: my $chgtxt;
1.169 raeburn 9072: if ($loginhash{'login'}{$item} eq 'notused') {
9073: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
9074: } else {
9075: my %captchas = &captcha_phrases();
9076: if ($captchas{$loginhash{'login'}{$item}}) {
9077: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
9078: } else {
9079: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
9080: }
9081: }
9082: $resulttext .= '<li>'.$chgtxt.'</li>';
9083: }
9084: } elsif ($item eq 'recaptchakeys') {
9085: if (ref($loginhash{'login'}) eq 'HASH') {
9086: my ($privkey,$pubkey);
9087: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
9088: $pubkey = $loginhash{'login'}{$item}{'public'};
9089: $privkey = $loginhash{'login'}{$item}{'private'};
9090: }
9091: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
9092: if (!$pubkey) {
9093: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
9094: } else {
9095: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9096: }
9097: if (!$privkey) {
9098: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
9099: } else {
1.251 raeburn 9100: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 9101: }
9102: $chgtxt .= '</ul>';
9103: $resulttext .= '<li>'.$chgtxt.'</li>';
9104: }
1.269 raeburn 9105: } elsif ($item eq 'recaptchaversion') {
9106: if (ref($loginhash{'login'}) eq 'HASH') {
9107: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 9108: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 9109: '</li>';
9110: }
9111: }
1.41 raeburn 9112: } else {
9113: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
9114: }
1.1 raeburn 9115: }
1.6 raeburn 9116: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 9117: } else {
9118: $resulttext = &mt('No changes made to log-in page settings');
9119: }
9120: } else {
1.11 albertel 9121: $resulttext = '<span class="LC_error">'.
9122: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9123: }
1.6 raeburn 9124: if ($errors) {
1.9 raeburn 9125: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 9126: $errors.'</ul>';
9127: }
9128: return $resulttext;
9129: }
9130:
1.256 raeburn 9131: sub check_exempt_addresses {
9132: my ($iplist) = @_;
9133: $iplist =~ s/^\s+//;
9134: $iplist =~ s/\s+$//;
9135: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
9136: my (@okips,$new);
9137: foreach my $ip (@poss_ips) {
9138: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
9139: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
9140: push(@okips,$ip);
9141: }
9142: }
9143: }
9144: if (@okips > 0) {
9145: $new = join(',',@okips);
9146: } else {
9147: $new = '';
9148: }
9149: return $new;
9150: }
9151:
1.6 raeburn 9152: sub color_font_choices {
9153: my %choices =
9154: &Apache::lonlocal::texthash (
9155: img => "Header",
9156: bgs => "Background colors",
9157: links => "Link colors",
1.55 raeburn 9158: images => "Images",
1.6 raeburn 9159: font => "Font color",
1.201 raeburn 9160: fontmenu => "Font menu",
1.76 raeburn 9161: pgbg => "Page",
1.6 raeburn 9162: tabbg => "Header",
9163: sidebg => "Border",
9164: link => "Link",
9165: alink => "Active link",
9166: vlink => "Visited link",
9167: );
9168: return %choices;
9169: }
9170:
9171: sub modify_rolecolors {
1.205 raeburn 9172: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 9173: my ($resulttext,%rolehash);
9174: $rolehash{'rolecolors'} = {};
1.55 raeburn 9175: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
9176: if ($domconfig{'rolecolors'} eq '') {
9177: $domconfig{'rolecolors'} = {};
9178: }
9179: }
1.9 raeburn 9180: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 9181: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
9182: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
9183: $dom);
9184: if ($putresult eq 'ok') {
9185: if (keys(%changes) > 0) {
1.41 raeburn 9186: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9187: if (ref($lastactref) eq 'HASH') {
9188: $lastactref->{'domainconfig'} = 1;
9189: }
1.6 raeburn 9190: $resulttext = &display_colorchgs($dom,\%changes,$roles,
9191: $rolehash{'rolecolors'});
9192: } else {
9193: $resulttext = &mt('No changes made to default color schemes');
9194: }
9195: } else {
1.11 albertel 9196: $resulttext = '<span class="LC_error">'.
9197: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 9198: }
9199: if ($errors) {
9200: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9201: $errors.'</ul>';
9202: }
9203: return $resulttext;
9204: }
9205:
9206: sub modify_colors {
1.9 raeburn 9207: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 9208: my (%changes,%choices);
1.51 raeburn 9209: my @bgs;
1.6 raeburn 9210: my @links = ('link','alink','vlink');
1.41 raeburn 9211: my @logintext;
1.6 raeburn 9212: my @images;
9213: my $servadm = $r->dir_config('lonAdmEMail');
9214: my $errors;
1.200 raeburn 9215: my %defaults;
1.6 raeburn 9216: foreach my $role (@{$roles}) {
9217: if ($role eq 'login') {
1.12 raeburn 9218: %choices = &login_choices();
1.41 raeburn 9219: @logintext = ('textcol','bgcol');
1.12 raeburn 9220: } else {
9221: %choices = &color_font_choices();
9222: }
9223: if ($role eq 'login') {
1.41 raeburn 9224: @images = ('img','logo','domlogo','login');
1.51 raeburn 9225: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 9226: } else {
9227: @images = ('img');
1.200 raeburn 9228: @bgs = ('pgbg','tabbg','sidebg');
9229: }
9230: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
9231: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
9232: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
9233: }
9234: if ($role eq 'login') {
9235: foreach my $item (@logintext) {
1.234 raeburn 9236: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9237: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9238: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9239: }
9240: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 9241: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9242: }
9243: }
9244: } else {
1.234 raeburn 9245: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
9246: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
9247: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
9248: }
9249: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 9250: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
9251: }
1.6 raeburn 9252: }
1.200 raeburn 9253: foreach my $item (@bgs) {
1.234 raeburn 9254: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9255: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9256: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9257: }
9258: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 9259: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9260: }
9261: }
9262: foreach my $item (@links) {
1.234 raeburn 9263: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9264: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9265: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9266: }
9267: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 9268: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9269: }
1.6 raeburn 9270: }
1.46 raeburn 9271: my ($configuserok,$author_ok,$switchserver) =
9272: &config_check($dom,$confname,$servadm);
1.9 raeburn 9273: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 9274: if (ref($domconfig->{$role}) ne 'HASH') {
9275: $domconfig->{$role} = {};
9276: }
1.8 raeburn 9277: foreach my $img (@images) {
1.70 raeburn 9278: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
9279: if (defined($env{'form.login_showlogo_'.$img})) {
9280: $confhash->{$role}{'showlogo'}{$img} = 1;
9281: } else {
9282: $confhash->{$role}{'showlogo'}{$img} = 0;
9283: }
9284: }
1.18 albertel 9285: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
9286: && !defined($domconfig->{$role}{$img})
9287: && !$env{'form.'.$role.'_del_'.$img}
9288: && $env{'form.'.$role.'_import_'.$img}) {
9289: # import the old configured image from the .tab setting
9290: # if they haven't provided a new one
9291: $domconfig->{$role}{$img} =
9292: $env{'form.'.$role.'_import_'.$img};
9293: }
1.6 raeburn 9294: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 9295: my $error;
1.6 raeburn 9296: if ($configuserok eq 'ok') {
1.9 raeburn 9297: if ($switchserver) {
1.12 raeburn 9298: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 9299: } else {
9300: if ($author_ok eq 'ok') {
9301: my ($result,$logourl) =
9302: &publishlogo($r,'upload',$role.'_'.$img,
9303: $dom,$confname,$img,$width,$height);
9304: if ($result eq 'ok') {
9305: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 9306: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9307: } else {
1.12 raeburn 9308: $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 9309: }
9310: } else {
1.46 raeburn 9311: $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 9312: }
9313: }
9314: } else {
1.46 raeburn 9315: $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 9316: }
9317: if ($error) {
1.8 raeburn 9318: &Apache::lonnet::logthis($error);
1.11 albertel 9319: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 9320: }
9321: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 9322: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
9323: my $error;
9324: if ($configuserok eq 'ok') {
9325: # is confname an author?
9326: if ($switchserver eq '') {
9327: if ($author_ok eq 'ok') {
9328: my ($result,$logourl) =
9329: &publishlogo($r,'copy',$domconfig->{$role}{$img},
9330: $dom,$confname,$img,$width,$height);
9331: if ($result eq 'ok') {
9332: $confhash->{$role}{$img} = $logourl;
1.18 albertel 9333: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9334: }
9335: }
9336: }
9337: }
1.6 raeburn 9338: }
9339: }
9340: }
9341: if (ref($domconfig) eq 'HASH') {
9342: if (ref($domconfig->{$role}) eq 'HASH') {
9343: foreach my $img (@images) {
9344: if ($domconfig->{$role}{$img} ne '') {
9345: if ($env{'form.'.$role.'_del_'.$img}) {
9346: $confhash->{$role}{$img} = '';
1.12 raeburn 9347: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 9348: } else {
1.9 raeburn 9349: if ($confhash->{$role}{$img} eq '') {
9350: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
9351: }
1.6 raeburn 9352: }
9353: } else {
9354: if ($env{'form.'.$role.'_del_'.$img}) {
9355: $confhash->{$role}{$img} = '';
1.12 raeburn 9356: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 9357: }
9358: }
1.70 raeburn 9359: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
9360: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
9361: if ($confhash->{$role}{'showlogo'}{$img} ne
9362: $domconfig->{$role}{'showlogo'}{$img}) {
9363: $changes{$role}{'showlogo'}{$img} = 1;
9364: }
9365: } else {
9366: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
9367: $changes{$role}{'showlogo'}{$img} = 1;
9368: }
9369: }
9370: }
9371: }
1.6 raeburn 9372: if ($domconfig->{$role}{'font'} ne '') {
9373: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
9374: $changes{$role}{'font'} = 1;
9375: }
9376: } else {
9377: if ($confhash->{$role}{'font'}) {
9378: $changes{$role}{'font'} = 1;
9379: }
9380: }
1.107 raeburn 9381: if ($role ne 'login') {
9382: if ($domconfig->{$role}{'fontmenu'} ne '') {
9383: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
9384: $changes{$role}{'fontmenu'} = 1;
9385: }
9386: } else {
9387: if ($confhash->{$role}{'fontmenu'}) {
9388: $changes{$role}{'fontmenu'} = 1;
9389: }
1.97 tempelho 9390: }
9391: }
1.6 raeburn 9392: foreach my $item (@bgs) {
9393: if ($domconfig->{$role}{$item} ne '') {
9394: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9395: $changes{$role}{'bgs'}{$item} = 1;
9396: }
9397: } else {
9398: if ($confhash->{$role}{$item}) {
9399: $changes{$role}{'bgs'}{$item} = 1;
9400: }
9401: }
9402: }
9403: foreach my $item (@links) {
9404: if ($domconfig->{$role}{$item} ne '') {
9405: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9406: $changes{$role}{'links'}{$item} = 1;
9407: }
9408: } else {
9409: if ($confhash->{$role}{$item}) {
9410: $changes{$role}{'links'}{$item} = 1;
9411: }
9412: }
9413: }
1.41 raeburn 9414: foreach my $item (@logintext) {
9415: if ($domconfig->{$role}{$item} ne '') {
9416: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9417: $changes{$role}{'logintext'}{$item} = 1;
9418: }
9419: } else {
9420: if ($confhash->{$role}{$item}) {
9421: $changes{$role}{'logintext'}{$item} = 1;
9422: }
9423: }
9424: }
1.6 raeburn 9425: } else {
9426: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 9427: \@logintext,$confhash,\%changes);
1.6 raeburn 9428: }
9429: } else {
9430: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 9431: \@logintext,$confhash,\%changes);
1.6 raeburn 9432: }
9433: }
9434: return ($errors,%changes);
9435: }
9436:
1.46 raeburn 9437: sub config_check {
9438: my ($dom,$confname,$servadm) = @_;
9439: my ($configuserok,$author_ok,$switchserver,%currroles);
9440: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
9441: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
9442: $confname,$servadm);
9443: if ($configuserok eq 'ok') {
9444: $switchserver = &check_switchserver($dom,$confname);
9445: if ($switchserver eq '') {
9446: $author_ok = &check_authorstatus($dom,$confname,%currroles);
9447: }
9448: }
9449: return ($configuserok,$author_ok,$switchserver);
9450: }
9451:
1.6 raeburn 9452: sub default_change_checker {
1.41 raeburn 9453: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 9454: foreach my $item (@{$links}) {
9455: if ($confhash->{$role}{$item}) {
9456: $changes->{$role}{'links'}{$item} = 1;
9457: }
9458: }
9459: foreach my $item (@{$bgs}) {
9460: if ($confhash->{$role}{$item}) {
9461: $changes->{$role}{'bgs'}{$item} = 1;
9462: }
9463: }
1.41 raeburn 9464: foreach my $item (@{$logintext}) {
9465: if ($confhash->{$role}{$item}) {
9466: $changes->{$role}{'logintext'}{$item} = 1;
9467: }
9468: }
1.6 raeburn 9469: foreach my $img (@{$images}) {
9470: if ($env{'form.'.$role.'_del_'.$img}) {
9471: $confhash->{$role}{$img} = '';
1.12 raeburn 9472: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 9473: }
1.70 raeburn 9474: if ($role eq 'login') {
9475: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
9476: $changes->{$role}{'showlogo'}{$img} = 1;
9477: }
9478: }
1.6 raeburn 9479: }
9480: if ($confhash->{$role}{'font'}) {
9481: $changes->{$role}{'font'} = 1;
9482: }
1.48 raeburn 9483: }
1.6 raeburn 9484:
9485: sub display_colorchgs {
9486: my ($dom,$changes,$roles,$confhash) = @_;
9487: my (%choices,$resulttext);
9488: if (!grep(/^login$/,@{$roles})) {
9489: $resulttext = &mt('Changes made:').'<br />';
9490: }
9491: foreach my $role (@{$roles}) {
9492: if ($role eq 'login') {
9493: %choices = &login_choices();
9494: } else {
9495: %choices = &color_font_choices();
9496: }
9497: if (ref($changes->{$role}) eq 'HASH') {
9498: if ($role ne 'login') {
9499: $resulttext .= '<h4>'.&mt($role).'</h4>';
9500: }
9501: foreach my $key (sort(keys(%{$changes->{$role}}))) {
9502: if ($role ne 'login') {
9503: $resulttext .= '<ul>';
9504: }
9505: if (ref($changes->{$role}{$key}) eq 'HASH') {
9506: if ($role ne 'login') {
9507: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
9508: }
9509: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 9510: if (($role eq 'login') && ($key eq 'showlogo')) {
9511: if ($confhash->{$role}{$key}{$item}) {
9512: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
9513: } else {
9514: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
9515: }
9516: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 9517: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
9518: } else {
1.12 raeburn 9519: my $newitem = $confhash->{$role}{$item};
9520: if ($key eq 'images') {
1.306 raeburn 9521: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 9522: }
9523: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 9524: }
9525: }
9526: if ($role ne 'login') {
9527: $resulttext .= '</ul></li>';
9528: }
9529: } else {
9530: if ($confhash->{$role}{$key} eq '') {
9531: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
9532: } else {
9533: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
9534: }
9535: }
9536: if ($role ne 'login') {
9537: $resulttext .= '</ul>';
9538: }
9539: }
9540: }
9541: }
1.3 raeburn 9542: return $resulttext;
1.1 raeburn 9543: }
9544:
1.9 raeburn 9545: sub thumb_dimensions {
9546: return ('200','50');
9547: }
9548:
1.16 raeburn 9549: sub check_dimensions {
9550: my ($inputfile) = @_;
9551: my ($fullwidth,$fullheight);
9552: if ($inputfile =~ m|^[/\w.\-]+$|) {
9553: if (open(PIPE,"identify $inputfile 2>&1 |")) {
9554: my $imageinfo = <PIPE>;
9555: if (!close(PIPE)) {
9556: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
9557: }
9558: chomp($imageinfo);
9559: my ($fullsize) =
1.21 raeburn 9560: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 9561: if ($fullsize) {
9562: ($fullwidth,$fullheight) = split(/x/,$fullsize);
9563: }
9564: }
9565: }
9566: return ($fullwidth,$fullheight);
9567: }
9568:
1.9 raeburn 9569: sub check_configuser {
9570: my ($uhome,$dom,$confname,$servadm) = @_;
9571: my ($configuserok,%currroles);
9572: if ($uhome eq 'no_host') {
9573: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
9574: my $configpass = &LONCAPA::Enrollment::create_password();
9575: $configuserok =
9576: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
9577: $configpass,'','','','','',undef,$servadm);
9578: } else {
9579: $configuserok = 'ok';
9580: %currroles =
9581: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
9582: }
9583: return ($configuserok,%currroles);
9584: }
9585:
9586: sub check_authorstatus {
9587: my ($dom,$confname,%currroles) = @_;
9588: my $author_ok;
1.40 raeburn 9589: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 9590: my $start = time;
9591: my $end = 0;
9592: $author_ok =
9593: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 9594: 'au',$end,$start,'','','domconfig');
1.9 raeburn 9595: } else {
9596: $author_ok = 'ok';
9597: }
9598: return $author_ok;
9599: }
9600:
9601: sub publishlogo {
1.46 raeburn 9602: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 9603: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 9604: if ($action eq 'upload') {
9605: $fname=$env{'form.'.$formname.'.filename'};
9606: chop($env{'form.'.$formname});
9607: } else {
9608: ($fname) = ($formname =~ /([^\/]+)$/);
9609: }
1.46 raeburn 9610: if ($savefileas ne '') {
9611: $fname = $savefileas;
9612: }
1.9 raeburn 9613: $fname=&Apache::lonnet::clean_filename($fname);
9614: # See if there is anything left
9615: unless ($fname) { return ('error: no uploaded file'); }
9616: $fname="$subdir/$fname";
1.210 raeburn 9617: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 9618: my $filepath="$docroot/priv";
9619: my $relpath = "$dom/$confname";
1.9 raeburn 9620: my ($fnamepath,$file,$fetchthumb);
9621: $file=$fname;
9622: if ($fname=~m|/|) {
9623: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
9624: }
1.164 raeburn 9625: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 9626: my $count;
1.164 raeburn 9627: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 9628: $filepath.="/$parts[$count]";
9629: if ((-e $filepath)!=1) {
9630: mkdir($filepath,02770);
9631: }
9632: }
9633: # Check for bad extension and disallow upload
9634: if ($file=~/\.(\w+)$/ &&
9635: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
9636: $output =
1.207 bisitz 9637: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 9638: } elsif ($file=~/\.(\w+)$/ &&
9639: !defined(&Apache::loncommon::fileembstyle($1))) {
9640: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
9641: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 9642: $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 9643: } elsif (-d "$filepath/$file") {
1.195 bisitz 9644: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 9645: } else {
9646: my $source = $filepath.'/'.$file;
9647: my $logfile;
1.316 raeburn 9648: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 9649: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 9650: }
9651: print $logfile
9652: "\n================= Publish ".localtime()." ================\n".
9653: $env{'user.name'}.':'.$env{'user.domain'}."\n";
9654: # Save the file
1.316 raeburn 9655: if (!open(FH,">",$source)) {
1.9 raeburn 9656: &Apache::lonnet::logthis('Failed to create '.$source);
9657: return (&mt('Failed to create file'));
9658: }
9659: if ($action eq 'upload') {
9660: if (!print FH ($env{'form.'.$formname})) {
9661: &Apache::lonnet::logthis('Failed to write to '.$source);
9662: return (&mt('Failed to write file'));
9663: }
9664: } else {
9665: my $original = &Apache::lonnet::filelocation('',$formname);
9666: if(!copy($original,$source)) {
9667: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
9668: return (&mt('Failed to write file'));
9669: }
9670: }
9671: close(FH);
9672: chmod(0660, $source); # Permissions to rw-rw---.
9673:
9674: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
9675: my $copyfile=$targetdir.'/'.$file;
9676:
9677: my @parts=split(/\//,$targetdir);
9678: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
9679: for (my $count=5;$count<=$#parts;$count++) {
9680: $path.="/$parts[$count]";
9681: if (!-e $path) {
9682: print $logfile "\nCreating directory ".$path;
9683: mkdir($path,02770);
9684: }
9685: }
9686: my $versionresult;
9687: if (-e $copyfile) {
9688: $versionresult = &logo_versioning($targetdir,$file,$logfile);
9689: } else {
9690: $versionresult = 'ok';
9691: }
9692: if ($versionresult eq 'ok') {
9693: if (copy($source,$copyfile)) {
9694: print $logfile "\nCopied original source to ".$copyfile."\n";
9695: $output = 'ok';
9696: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 9697: push(@{$modified_urls},[$copyfile,$source]);
9698: my $metaoutput =
9699: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
9700: unless ($registered_cleanup) {
9701: my $handlers = $r->get_handlers('PerlCleanupHandler');
9702: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9703: $registered_cleanup=1;
9704: }
1.9 raeburn 9705: } else {
9706: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
9707: $output = &mt('Failed to copy file to RES space').", $!";
9708: }
9709: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
9710: my $inputfile = $filepath.'/'.$file;
9711: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 9712: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
9713: if ($fullwidth ne '' && $fullheight ne '') {
9714: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
9715: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 9716: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
9717: system({$args[0]} @args);
1.16 raeburn 9718: chmod(0660, $filepath.'/tn-'.$file);
9719: if (-e $outfile) {
9720: my $copyfile=$targetdir.'/tn-'.$file;
9721: if (copy($outfile,$copyfile)) {
9722: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 9723: my $thumb_metaoutput =
9724: &write_metadata($dom,$confname,$formname,
9725: $targetdir,'tn-'.$file,$logfile);
9726: push(@{$modified_urls},[$copyfile,$outfile]);
9727: unless ($registered_cleanup) {
9728: my $handlers = $r->get_handlers('PerlCleanupHandler');
9729: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9730: $registered_cleanup=1;
9731: }
1.267 raeburn 9732: $madethumb = 1;
1.16 raeburn 9733: } else {
9734: print $logfile "\nUnable to write ".$copyfile.
9735: ':'.$!."\n";
9736: }
9737: }
1.9 raeburn 9738: }
9739: }
9740: }
9741: } else {
9742: $output = $versionresult;
9743: }
9744: }
1.267 raeburn 9745: return ($output,$logourl,$madethumb);
1.9 raeburn 9746: }
9747:
9748: sub logo_versioning {
9749: my ($targetdir,$file,$logfile) = @_;
9750: my $target = $targetdir.'/'.$file;
9751: my ($maxversion,$fn,$extn,$output);
9752: $maxversion = 0;
9753: if ($file =~ /^(.+)\.(\w+)$/) {
9754: $fn=$1;
9755: $extn=$2;
9756: }
9757: opendir(DIR,$targetdir);
9758: while (my $filename=readdir(DIR)) {
9759: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
9760: $maxversion=($1>$maxversion)?$1:$maxversion;
9761: }
9762: }
9763: $maxversion++;
9764: print $logfile "\nCreating old version ".$maxversion."\n";
9765: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
9766: if (copy($target,$copyfile)) {
9767: print $logfile "Copied old target to ".$copyfile."\n";
9768: $copyfile=$copyfile.'.meta';
9769: if (copy($target.'.meta',$copyfile)) {
9770: print $logfile "Copied old target metadata to ".$copyfile."\n";
9771: $output = 'ok';
9772: } else {
9773: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
9774: $output = &mt('Failed to copy old meta').", $!, ";
9775: }
9776: } else {
9777: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
9778: $output = &mt('Failed to copy old target').", $!, ";
9779: }
9780: return $output;
9781: }
9782:
9783: sub write_metadata {
9784: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
9785: my (%metadatafields,%metadatakeys,$output);
9786: $metadatafields{'title'}=$formname;
9787: $metadatafields{'creationdate'}=time;
9788: $metadatafields{'lastrevisiondate'}=time;
9789: $metadatafields{'copyright'}='public';
9790: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
9791: $env{'user.domain'};
9792: $metadatafields{'authorspace'}=$confname.':'.$dom;
9793: $metadatafields{'domain'}=$dom;
9794: {
9795: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
9796: my $mfh;
1.316 raeburn 9797: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 9798: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 9799: unless ($_=~/\./) {
9800: my $unikey=$_;
9801: $unikey=~/^([A-Za-z]+)/;
9802: my $tag=$1;
9803: $tag=~tr/A-Z/a-z/;
9804: print $mfh "\n\<$tag";
9805: foreach (split(/\,/,$metadatakeys{$unikey})) {
9806: my $value=$metadatafields{$unikey.'.'.$_};
9807: $value=~s/\"/\'\'/g;
9808: print $mfh ' '.$_.'="'.$value.'"';
9809: }
9810: print $mfh '>'.
9811: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
9812: .'</'.$tag.'>';
9813: }
9814: }
9815: $output = 'ok';
9816: print $logfile "\nWrote metadata";
9817: close($mfh);
9818: } else {
9819: print $logfile "\nFailed to open metadata file";
1.9 raeburn 9820: $output = &mt('Could not write metadata');
9821: }
9822: }
1.155 raeburn 9823: return $output;
9824: }
9825:
9826: sub notifysubscribed {
9827: foreach my $targetsource (@{$modified_urls}){
9828: next unless (ref($targetsource) eq 'ARRAY');
9829: my ($target,$source)=@{$targetsource};
9830: if ($source ne '') {
1.316 raeburn 9831: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 9832: print $logfh "\nCleanup phase: Notifications\n";
9833: my @subscribed=&subscribed_hosts($target);
9834: foreach my $subhost (@subscribed) {
9835: print $logfh "\nNotifying host ".$subhost.':';
9836: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
9837: print $logfh $reply;
9838: }
9839: my @subscribedmeta=&subscribed_hosts("$target.meta");
9840: foreach my $subhost (@subscribedmeta) {
9841: print $logfh "\nNotifying host for metadata only ".$subhost.':';
9842: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
9843: $subhost);
9844: print $logfh $reply;
9845: }
9846: print $logfh "\n============ Done ============\n";
1.160 raeburn 9847: close($logfh);
1.155 raeburn 9848: }
9849: }
9850: }
9851: return OK;
9852: }
9853:
9854: sub subscribed_hosts {
9855: my ($target) = @_;
9856: my @subscribed;
1.316 raeburn 9857: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 9858: while (my $subline=<$fh>) {
9859: if ($subline =~ /^($match_lonid):/) {
9860: my $host = $1;
9861: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
9862: unless (grep(/^\Q$host\E$/,@subscribed)) {
9863: push(@subscribed,$host);
9864: }
9865: }
9866: }
9867: }
9868: }
9869: return @subscribed;
1.9 raeburn 9870: }
9871:
9872: sub check_switchserver {
9873: my ($dom,$confname) = @_;
9874: my ($allowed,$switchserver);
9875: my $home = &Apache::lonnet::homeserver($confname,$dom);
9876: if ($home eq 'no_host') {
9877: $home = &Apache::lonnet::domain($dom,'primary');
9878: }
9879: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 9880: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
9881: if (!$allowed) {
1.180 raeburn 9882: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 9883: }
9884: return $switchserver;
9885: }
9886:
1.1 raeburn 9887: sub modify_quotas {
1.216 raeburn 9888: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 9889: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 9890: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 9891: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
9892: $validationfieldsref);
1.86 raeburn 9893: if ($action eq 'quotas') {
9894: $context = 'tools';
1.163 raeburn 9895: } else {
1.86 raeburn 9896: $context = $action;
9897: }
9898: if ($context eq 'requestcourses') {
1.271 raeburn 9899: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 9900: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 9901: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
9902: %titles = &courserequest_titles();
9903: $toolregexp = join('|',@usertools);
9904: %conditions = &courserequest_conditions();
1.216 raeburn 9905: $confname = $dom.'-domainconfig';
9906: my $servadm = $r->dir_config('lonAdmEMail');
9907: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 9908: ($validationitemsref,$validationnamesref,$validationfieldsref) =
9909: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 9910: } elsif ($context eq 'requestauthor') {
9911: @usertools = ('author');
9912: %titles = &authorrequest_titles();
1.86 raeburn 9913: } else {
1.162 raeburn 9914: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 9915: %titles = &tool_titles();
1.86 raeburn 9916: }
1.212 raeburn 9917: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 9918: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 9919: foreach my $key (keys(%env)) {
1.101 raeburn 9920: if ($context eq 'requestcourses') {
9921: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
9922: my $item = $1;
9923: my $type = $2;
9924: if ($type =~ /^limit_(.+)/) {
9925: $limithash{$item}{$1} = $env{$key};
9926: } else {
9927: $confhash{$item}{$type} = $env{$key};
9928: }
9929: }
1.163 raeburn 9930: } elsif ($context eq 'requestauthor') {
9931: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
9932: $confhash{$1} = $env{$key};
9933: }
1.101 raeburn 9934: } else {
1.86 raeburn 9935: if ($key =~ /^form\.quota_(.+)$/) {
9936: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 9937: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
9938: $confhash{'authorquota'}{$1} = $env{$key};
9939: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 9940: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
9941: }
1.72 raeburn 9942: }
9943: }
1.163 raeburn 9944: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 9945: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 9946: @approvalnotify = sort(@approvalnotify);
9947: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.271 raeburn 9948: my @crstypes = ('official','unofficial','community','textbook','placement');
1.218 raeburn 9949: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
9950: foreach my $type (@hasuniquecode) {
9951: if (grep(/^\Q$type\E$/,@crstypes)) {
9952: $confhash{'uniquecode'}{$type} = 1;
9953: }
1.216 raeburn 9954: }
1.242 raeburn 9955: my (%newbook,%allpos);
1.216 raeburn 9956: if ($context eq 'requestcourses') {
1.242 raeburn 9957: foreach my $type ('textbooks','templates') {
9958: @{$allpos{$type}} = ();
9959: my $invalid;
9960: if ($type eq 'textbooks') {
9961: $invalid = &mt('Invalid LON-CAPA course for textbook');
9962: } else {
9963: $invalid = &mt('Invalid LON-CAPA course for template');
9964: }
9965: if ($env{'form.'.$type.'_addbook'}) {
9966: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
9967: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
9968: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
9969: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
9970: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
9971: } else {
9972: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
9973: my $position = $env{'form.'.$type.'_addbook_pos'};
9974: $position =~ s/\D+//g;
9975: if ($position ne '') {
9976: $allpos{$type}[$position] = $newbook{$type};
9977: }
1.216 raeburn 9978: }
1.242 raeburn 9979: } else {
9980: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 9981: }
9982: }
1.242 raeburn 9983: }
1.216 raeburn 9984: }
1.102 raeburn 9985: if (ref($domconfig{$action}) eq 'HASH') {
9986: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
9987: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
9988: $changes{'notify'}{'approval'} = 1;
9989: }
9990: } else {
1.144 raeburn 9991: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 9992: $changes{'notify'}{'approval'} = 1;
9993: }
9994: }
1.218 raeburn 9995: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
9996: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9997: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
9998: unless ($confhash{'uniquecode'}{$crstype}) {
9999: $changes{'uniquecode'} = 1;
10000: }
10001: }
10002: unless ($changes{'uniquecode'}) {
10003: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
10004: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
10005: $changes{'uniquecode'} = 1;
10006: }
10007: }
10008: }
10009: } else {
10010: $changes{'uniquecode'} = 1;
10011: }
10012: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
10013: $changes{'uniquecode'} = 1;
1.216 raeburn 10014: }
10015: if ($context eq 'requestcourses') {
1.242 raeburn 10016: foreach my $type ('textbooks','templates') {
10017: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10018: my %deletions;
10019: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
10020: if (@todelete) {
10021: map { $deletions{$_} = 1; } @todelete;
10022: }
10023: my %imgdeletions;
10024: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
10025: if (@todeleteimages) {
10026: map { $imgdeletions{$_} = 1; } @todeleteimages;
10027: }
10028: my $maxnum = $env{'form.'.$type.'_maxnum'};
10029: for (my $i=0; $i<=$maxnum; $i++) {
10030: my $itemid = $env{'form.'.$type.'_id_'.$i};
10031: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
10032: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
10033: if ($deletions{$key}) {
10034: if ($domconfig{$action}{$type}{$key}{'image'}) {
10035: #FIXME need to obsolete item in RES space
10036: }
10037: next;
10038: } else {
10039: my $newpos = $env{'form.'.$itemid};
10040: $newpos =~ s/\D+//g;
1.243 raeburn 10041: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 10042: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 10043: ($type eq 'templates'));
1.242 raeburn 10044: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
10045: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
10046: $changes{$type}{$key} = 1;
10047: }
10048: }
10049: $allpos{$type}[$newpos] = $key;
10050: }
10051: if ($imgdeletions{$key}) {
10052: $changes{$type}{$key} = 1;
1.216 raeburn 10053: #FIXME need to obsolete item in RES space
1.242 raeburn 10054: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
10055: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 10056: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10057: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10058: } else {
10059: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
10060: $cdom,$cnum,$type,$configuserok,
10061: $switchserver,$author_ok);
10062: if ($imgurl) {
10063: $confhash{$type}{$key}{'image'} = $imgurl;
10064: $changes{$type}{$key} = 1;
10065: }
10066: if ($error) {
10067: &Apache::lonnet::logthis($error);
10068: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10069: }
10070: }
1.242 raeburn 10071: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
10072: $confhash{$type}{$key}{'image'} =
10073: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 10074: }
10075: }
10076: }
10077: }
10078: }
10079: }
1.102 raeburn 10080: } else {
1.144 raeburn 10081: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10082: $changes{'notify'}{'approval'} = 1;
10083: }
1.218 raeburn 10084: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 10085: $changes{'uniquecode'} = 1;
10086: }
10087: }
10088: if ($context eq 'requestcourses') {
1.242 raeburn 10089: foreach my $type ('textbooks','templates') {
10090: if ($newbook{$type}) {
10091: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 10092: foreach my $item ('subject','title','publisher','author') {
10093: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10094: ($type eq 'template'));
1.242 raeburn 10095: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
10096: if ($env{'form.'.$type.'_addbook_'.$item}) {
10097: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
10098: }
10099: }
10100: if ($type eq 'textbooks') {
10101: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
10102: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 10103: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10104: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10105: } else {
10106: my ($imageurl,$error) =
10107: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
10108: $configuserok,$switchserver,$author_ok);
10109: if ($imageurl) {
10110: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
10111: }
10112: if ($error) {
10113: &Apache::lonnet::logthis($error);
10114: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10115: }
1.242 raeburn 10116: }
10117: }
1.216 raeburn 10118: }
10119: }
1.242 raeburn 10120: if (@{$allpos{$type}} > 0) {
10121: my $idx = 0;
10122: foreach my $item (@{$allpos{$type}}) {
10123: if ($item ne '') {
10124: $confhash{$type}{$item}{'order'} = $idx;
10125: if (ref($domconfig{$action}) eq 'HASH') {
10126: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10127: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
10128: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
10129: $changes{$type}{$item} = 1;
10130: }
1.216 raeburn 10131: }
10132: }
10133: }
1.242 raeburn 10134: $idx ++;
1.216 raeburn 10135: }
10136: }
10137: }
10138: }
1.235 raeburn 10139: if (ref($validationitemsref) eq 'ARRAY') {
10140: foreach my $item (@{$validationitemsref}) {
10141: if ($item eq 'fields') {
10142: my @changed;
10143: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
10144: if (@{$confhash{'validation'}{$item}} > 0) {
10145: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
10146: }
1.266 raeburn 10147: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10148: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10149: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
10150: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
10151: $domconfig{'requestcourses'}{'validation'}{$item});
10152: } else {
10153: @changed = @{$confhash{'validation'}{$item}};
10154: }
1.235 raeburn 10155: } else {
10156: @changed = @{$confhash{'validation'}{$item}};
10157: }
10158: } else {
10159: @changed = @{$confhash{'validation'}{$item}};
10160: }
10161: if (@changed) {
10162: if ($confhash{'validation'}{$item}) {
10163: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
10164: } else {
10165: $changes{'validation'}{$item} = &mt('None');
10166: }
10167: }
10168: } else {
10169: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
10170: if ($item eq 'markup') {
10171: if ($env{'form.requestcourses_validation_'.$item}) {
10172: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10173: }
10174: }
1.266 raeburn 10175: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10176: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10177: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
10178: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10179: }
10180: } else {
10181: if ($confhash{'validation'}{$item} ne '') {
10182: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10183: }
1.235 raeburn 10184: }
10185: } else {
10186: if ($confhash{'validation'}{$item} ne '') {
10187: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10188: }
10189: }
10190: }
10191: }
10192: }
10193: if ($env{'form.validationdc'}) {
10194: my $newval = $env{'form.validationdc'};
1.285 raeburn 10195: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 10196: if (exists($domcoords{$newval})) {
10197: $confhash{'validation'}{'dc'} = $newval;
10198: }
10199: }
10200: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 10201: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10202: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10203: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10204: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
10205: if ($confhash{'validation'}{'dc'} eq '') {
10206: $changes{'validation'}{'dc'} = &mt('None');
10207: } else {
10208: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10209: }
1.235 raeburn 10210: }
1.266 raeburn 10211: } elsif ($confhash{'validation'}{'dc'} ne '') {
10212: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 10213: }
10214: } elsif ($confhash{'validation'}{'dc'} ne '') {
10215: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10216: }
10217: } elsif ($confhash{'validation'}{'dc'} ne '') {
10218: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 10219: }
1.266 raeburn 10220: } else {
10221: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10222: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10223: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10224: $changes{'validation'}{'dc'} = &mt('None');
10225: }
10226: }
1.235 raeburn 10227: }
10228: }
1.102 raeburn 10229: }
10230: } else {
1.86 raeburn 10231: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 10232: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 10233: }
1.72 raeburn 10234: foreach my $item (@usertools) {
10235: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 10236: my $unset;
1.101 raeburn 10237: if ($context eq 'requestcourses') {
1.104 raeburn 10238: $unset = '0';
10239: if ($type eq '_LC_adv') {
10240: $unset = '';
10241: }
1.101 raeburn 10242: if ($confhash{$item}{$type} eq 'autolimit') {
10243: $confhash{$item}{$type} .= '=';
10244: unless ($limithash{$item}{$type} =~ /\D/) {
10245: $confhash{$item}{$type} .= $limithash{$item}{$type};
10246: }
10247: }
1.163 raeburn 10248: } elsif ($context eq 'requestauthor') {
10249: $unset = '0';
10250: if ($type eq '_LC_adv') {
10251: $unset = '';
10252: }
1.72 raeburn 10253: } else {
1.101 raeburn 10254: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
10255: $confhash{$item}{$type} = 1;
10256: } else {
10257: $confhash{$item}{$type} = 0;
10258: }
1.72 raeburn 10259: }
1.86 raeburn 10260: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 10261: if ($action eq 'requestauthor') {
10262: if ($domconfig{$action}{$type} ne $confhash{$type}) {
10263: $changes{$type} = 1;
10264: }
10265: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 10266: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
10267: $changes{$item}{$type} = 1;
10268: }
10269: } else {
10270: if ($context eq 'requestcourses') {
1.104 raeburn 10271: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 10272: $changes{$item}{$type} = 1;
10273: }
10274: } else {
10275: if (!$confhash{$item}{$type}) {
10276: $changes{$item}{$type} = 1;
10277: }
10278: }
10279: }
10280: } else {
10281: if ($context eq 'requestcourses') {
1.104 raeburn 10282: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 10283: $changes{$item}{$type} = 1;
10284: }
1.163 raeburn 10285: } elsif ($context eq 'requestauthor') {
10286: if ($confhash{$type} ne $unset) {
10287: $changes{$type} = 1;
10288: }
1.72 raeburn 10289: } else {
10290: if (!$confhash{$item}{$type}) {
10291: $changes{$item}{$type} = 1;
10292: }
10293: }
10294: }
1.1 raeburn 10295: }
10296: }
1.163 raeburn 10297: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 10298: if (ref($domconfig{'quotas'}) eq 'HASH') {
10299: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10300: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
10301: if (exists($confhash{'defaultquota'}{$key})) {
10302: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
10303: $changes{'defaultquota'}{$key} = 1;
10304: }
10305: } else {
10306: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 10307: }
10308: }
1.86 raeburn 10309: } else {
10310: foreach my $key (keys(%{$domconfig{'quotas'}})) {
10311: if (exists($confhash{'defaultquota'}{$key})) {
10312: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
10313: $changes{'defaultquota'}{$key} = 1;
10314: }
10315: } else {
10316: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 10317: }
1.1 raeburn 10318: }
10319: }
1.197 raeburn 10320: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10321: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
10322: if (exists($confhash{'authorquota'}{$key})) {
10323: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
10324: $changes{'authorquota'}{$key} = 1;
10325: }
10326: } else {
10327: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
10328: }
10329: }
10330: }
1.1 raeburn 10331: }
1.86 raeburn 10332: if (ref($confhash{'defaultquota'}) eq 'HASH') {
10333: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
10334: if (ref($domconfig{'quotas'}) eq 'HASH') {
10335: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10336: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
10337: $changes{'defaultquota'}{$key} = 1;
10338: }
10339: } else {
10340: if (!exists($domconfig{'quotas'}{$key})) {
10341: $changes{'defaultquota'}{$key} = 1;
10342: }
1.72 raeburn 10343: }
10344: } else {
1.86 raeburn 10345: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 10346: }
1.1 raeburn 10347: }
10348: }
1.197 raeburn 10349: if (ref($confhash{'authorquota'}) eq 'HASH') {
10350: foreach my $key (keys(%{$confhash{'authorquota'}})) {
10351: if (ref($domconfig{'quotas'}) eq 'HASH') {
10352: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10353: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
10354: $changes{'authorquota'}{$key} = 1;
10355: }
10356: } else {
10357: $changes{'authorquota'}{$key} = 1;
10358: }
10359: } else {
10360: $changes{'authorquota'}{$key} = 1;
10361: }
10362: }
10363: }
1.1 raeburn 10364: }
1.72 raeburn 10365:
1.163 raeburn 10366: if ($context eq 'requestauthor') {
10367: $domdefaults{'requestauthor'} = \%confhash;
10368: } else {
10369: foreach my $key (keys(%confhash)) {
1.242 raeburn 10370: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 10371: $domdefaults{$key} = $confhash{$key};
10372: }
1.163 raeburn 10373: }
1.72 raeburn 10374: }
1.163 raeburn 10375:
1.1 raeburn 10376: my %quotahash = (
1.86 raeburn 10377: $action => { %confhash }
1.1 raeburn 10378: );
10379: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
10380: $dom);
10381: if ($putresult eq 'ok') {
10382: if (keys(%changes) > 0) {
1.72 raeburn 10383: my $cachetime = 24*60*60;
10384: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 10385: if (ref($lastactref) eq 'HASH') {
10386: $lastactref->{'domdefaults'} = 1;
10387: }
1.1 raeburn 10388: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 10389: unless (($context eq 'requestcourses') ||
1.163 raeburn 10390: ($context eq 'requestauthor')) {
1.86 raeburn 10391: if (ref($changes{'defaultquota'}) eq 'HASH') {
10392: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
10393: foreach my $type (@{$types},'default') {
10394: if (defined($changes{'defaultquota'}{$type})) {
10395: my $typetitle = $usertypes->{$type};
10396: if ($type eq 'default') {
10397: $typetitle = $othertitle;
10398: }
1.213 raeburn 10399: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 10400: }
10401: }
1.86 raeburn 10402: $resulttext .= '</ul></li>';
1.72 raeburn 10403: }
1.197 raeburn 10404: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 10405: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 10406: foreach my $type (@{$types},'default') {
10407: if (defined($changes{'authorquota'}{$type})) {
10408: my $typetitle = $usertypes->{$type};
10409: if ($type eq 'default') {
10410: $typetitle = $othertitle;
10411: }
1.213 raeburn 10412: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 10413: }
10414: }
10415: $resulttext .= '</ul></li>';
10416: }
1.72 raeburn 10417: }
1.80 raeburn 10418: my %newenv;
1.72 raeburn 10419: foreach my $item (@usertools) {
1.163 raeburn 10420: my (%haschgs,%inconf);
10421: if ($context eq 'requestauthor') {
10422: %haschgs = %changes;
1.210 raeburn 10423: %inconf = %confhash;
1.163 raeburn 10424: } else {
10425: if (ref($changes{$item}) eq 'HASH') {
10426: %haschgs = %{$changes{$item}};
10427: }
10428: if (ref($confhash{$item}) eq 'HASH') {
10429: %inconf = %{$confhash{$item}};
10430: }
10431: }
10432: if (keys(%haschgs) > 0) {
1.80 raeburn 10433: my $newacc =
10434: &Apache::lonnet::usertools_access($env{'user.name'},
10435: $env{'user.domain'},
1.86 raeburn 10436: $item,'reload',$context);
1.210 raeburn 10437: if (($context eq 'requestcourses') ||
1.163 raeburn 10438: ($context eq 'requestauthor')) {
1.108 raeburn 10439: if ($env{'environment.canrequest.'.$item} ne $newacc) {
10440: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 10441: }
10442: } else {
10443: if ($env{'environment.availabletools.'.$item} ne $newacc) {
10444: $newenv{'environment.availabletools.'.$item} = $newacc;
10445: }
1.80 raeburn 10446: }
1.163 raeburn 10447: unless ($context eq 'requestauthor') {
10448: $resulttext .= '<li>'.$titles{$item}.'<ul>';
10449: }
1.72 raeburn 10450: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 10451: if ($haschgs{$type}) {
1.72 raeburn 10452: my $typetitle = $usertypes->{$type};
10453: if ($type eq 'default') {
10454: $typetitle = $othertitle;
10455: } elsif ($type eq '_LC_adv') {
10456: $typetitle = 'LON-CAPA Advanced Users';
10457: }
1.163 raeburn 10458: if ($inconf{$type}) {
1.101 raeburn 10459: if ($context eq 'requestcourses') {
10460: my $cond;
1.163 raeburn 10461: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 10462: if ($1 eq '') {
10463: $cond = &mt('(Automatic processing of any request).');
10464: } else {
10465: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
10466: }
10467: } else {
1.163 raeburn 10468: $cond = $conditions{$inconf{$type}};
1.101 raeburn 10469: }
10470: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 10471: } elsif ($context eq 'requestauthor') {
10472: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
10473: $titles{$inconf{$type}},$typetitle);
10474:
1.101 raeburn 10475: } else {
10476: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
10477: }
1.72 raeburn 10478: } else {
1.104 raeburn 10479: if ($type eq '_LC_adv') {
1.163 raeburn 10480: if ($inconf{$type} eq '0') {
1.104 raeburn 10481: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
10482: } else {
10483: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
10484: }
10485: } else {
10486: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
10487: }
1.72 raeburn 10488: }
10489: }
1.26 raeburn 10490: }
1.163 raeburn 10491: unless ($context eq 'requestauthor') {
10492: $resulttext .= '</ul></li>';
10493: }
1.26 raeburn 10494: }
1.1 raeburn 10495: }
1.163 raeburn 10496: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 10497: if (ref($changes{'notify'}) eq 'HASH') {
10498: if ($changes{'notify'}{'approval'}) {
10499: if (ref($confhash{'notify'}) eq 'HASH') {
10500: if ($confhash{'notify'}{'approval'}) {
10501: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
10502: } else {
1.163 raeburn 10503: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 10504: }
10505: }
10506: }
10507: }
10508: }
1.216 raeburn 10509: if ($action eq 'requestcourses') {
10510: my @offon = ('off','on');
10511: if ($changes{'uniquecode'}) {
1.218 raeburn 10512: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10513: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
10514: $resulttext .= '<li>'.
10515: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
10516: '</li>';
10517: } else {
10518: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
10519: '</li>';
10520: }
1.216 raeburn 10521: }
1.242 raeburn 10522: foreach my $type ('textbooks','templates') {
10523: if (ref($changes{$type}) eq 'HASH') {
10524: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
10525: foreach my $key (sort(keys(%{$changes{$type}}))) {
10526: my %coursehash = &Apache::lonnet::coursedescription($key);
10527: my $coursetitle = $coursehash{'description'};
10528: my $position = $confhash{$type}{$key}{'order'} + 1;
10529: $resulttext .= '<li>';
1.243 raeburn 10530: foreach my $item ('subject','title','publisher','author') {
10531: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10532: ($type eq 'templates'));
1.242 raeburn 10533: my $name = $item.':';
10534: $name =~ s/^(\w)/\U$1/;
10535: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
10536: }
10537: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
10538: if ($type eq 'textbooks') {
10539: if ($confhash{$type}{$key}{'image'}) {
10540: $resulttext .= ' '.&mt('Image: [_1]',
10541: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
10542: ' alt="Textbook cover" />').'<br />';
10543: }
10544: }
10545: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 10546: }
1.242 raeburn 10547: $resulttext .= '</ul></li>';
1.216 raeburn 10548: }
10549: }
1.235 raeburn 10550: if (ref($changes{'validation'}) eq 'HASH') {
10551: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
10552: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
10553: foreach my $item (@{$validationitemsref}) {
10554: if (exists($changes{'validation'}{$item})) {
10555: if ($item eq 'markup') {
10556: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10557: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
10558: } else {
10559: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10560: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
10561: }
10562: }
10563: }
10564: if (exists($changes{'validation'}{'dc'})) {
10565: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
10566: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
10567: }
10568: }
10569: }
1.216 raeburn 10570: }
1.1 raeburn 10571: $resulttext .= '</ul>';
1.80 raeburn 10572: if (keys(%newenv)) {
10573: &Apache::lonnet::appenv(\%newenv);
10574: }
1.1 raeburn 10575: } else {
1.86 raeburn 10576: if ($context eq 'requestcourses') {
10577: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 10578: } elsif ($context eq 'requestauthor') {
10579: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 10580: } else {
1.90 weissno 10581: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 10582: }
1.1 raeburn 10583: }
10584: } else {
1.11 albertel 10585: $resulttext = '<span class="LC_error">'.
10586: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10587: }
1.216 raeburn 10588: if ($errors) {
10589: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
10590: '<ul>'.$errors.'</ul></p>';
10591: }
1.3 raeburn 10592: return $resulttext;
1.1 raeburn 10593: }
10594:
1.216 raeburn 10595: sub process_textbook_image {
1.242 raeburn 10596: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 10597: my $filename = $env{'form.'.$caller.'.filename'};
10598: my ($error,$url);
10599: my ($width,$height) = (50,50);
10600: if ($configuserok eq 'ok') {
10601: if ($switchserver) {
10602: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
10603: $switchserver);
10604: } elsif ($author_ok eq 'ok') {
10605: my ($result,$imageurl) =
10606: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 10607: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 10608: if ($result eq 'ok') {
10609: $url = $imageurl;
10610: } else {
10611: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
10612: }
10613: } else {
10614: $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);
10615: }
10616: } else {
10617: $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);
10618: }
10619: return ($url,$error);
10620: }
10621:
1.267 raeburn 10622: sub modify_ltitools {
10623: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
10624: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 10625: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 10626: my $confname = $dom.'-domainconfig';
10627: my $servadm = $r->dir_config('lonAdmEMail');
10628: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10629: my (%posslti,%possfield);
10630: my @courseroles = ('cc','in','ta','ep','st');
10631: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
10632: map { $posslti{$_} = 1; } @ltiroles;
10633: my @allfields = ('fullname','firstname','lastname','email','user','roles');
10634: map { $possfield{$_} = 1; } @allfields;
10635: my %lt = <itools_names();
10636: if ($env{'form.ltitools_add'}) {
10637: my $title = $env{'form.ltitools_add_title'};
10638: $title =~ s/(`)/'/g;
10639: ($newid,my $error) = &get_ltitools_id($dom,$title);
10640: if ($newid) {
10641: my $position = $env{'form.ltitools_add_pos'};
10642: $position =~ s/\D+//g;
10643: if ($position ne '') {
10644: $allpos[$position] = $newid;
10645: }
10646: $changes{$newid} = 1;
10647: foreach my $item ('title','url','key','secret') {
10648: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
10649: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 10650: if (($item eq 'key') || ($item eq 'secret')) {
10651: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10652: } else {
10653: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10654: }
1.267 raeburn 10655: }
10656: }
10657: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
10658: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
10659: }
10660: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
10661: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
10662: }
1.296 raeburn 10663: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 10664: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
10665: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 10666: if (($item eq 'width') || ($item eq 'height')) {
10667: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
10668: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10669: }
10670: } else {
10671: if ($env{'form.ltitools_add_'.$item} ne '') {
10672: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10673: }
1.267 raeburn 10674: }
10675: }
10676: if ($env{'form.ltitools_add_target'} eq 'window') {
10677: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 10678: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
10679: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 10680: } else {
10681: $confhash{$newid}{'display'}{'target'} = 'iframe';
10682: }
10683: foreach my $item ('passback','roster') {
1.319 raeburn 10684: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 10685: $confhash{$newid}{$item} = 1;
1.319 raeburn 10686: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
10687: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
10688: $lifetime =~ s/^\s+|\s+$//g;
10689: if ($lifetime =~ /^\d+\.?\d*$/) {
10690: $confhash{$newid}{$item.'valid'} = $lifetime;
10691: }
10692: }
1.267 raeburn 10693: }
10694: }
10695: if ($env{'form.ltitools_add_image.filename'} ne '') {
10696: my ($imageurl,$error) =
1.307 raeburn 10697: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 10698: $configuserok,$switchserver,$author_ok);
10699: if ($imageurl) {
10700: $confhash{$newid}{'image'} = $imageurl;
10701: }
10702: if ($error) {
10703: &Apache::lonnet::logthis($error);
10704: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10705: }
10706: }
10707: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
10708: foreach my $field (@fields) {
10709: if ($possfield{$field}) {
10710: if ($field eq 'roles') {
10711: foreach my $role (@courseroles) {
10712: my $choice = $env{'form.ltitools_add_roles_'.$role};
10713: if (($choice ne '') && ($posslti{$choice})) {
10714: $confhash{$newid}{'roles'}{$role} = $choice;
10715: if ($role eq 'cc') {
10716: $confhash{$newid}{'roles'}{'co'} = $choice;
10717: }
10718: }
10719: }
10720: } else {
10721: $confhash{$newid}{'fields'}{$field} = 1;
10722: }
10723: }
10724: }
1.273 raeburn 10725: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
10726: foreach my $item (@courseconfig) {
10727: $confhash{$newid}{'crsconf'}{$item} = 1;
10728: }
1.267 raeburn 10729: if ($env{'form.ltitools_add_custom'}) {
10730: my $name = $env{'form.ltitools_add_custom_name'};
10731: my $value = $env{'form.ltitools_add_custom_value'};
10732: $value =~ s/(`)/'/g;
10733: $name =~ s/(`)/'/g;
10734: $confhash{$newid}{'custom'}{$name} = $value;
10735: }
10736: } else {
10737: my $error = &mt('Failed to acquire unique ID for new external tool');
10738: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10739: }
10740: }
10741: if (ref($domconfig{$action}) eq 'HASH') {
10742: my %deletions;
10743: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
10744: if (@todelete) {
10745: map { $deletions{$_} = 1; } @todelete;
10746: }
10747: my %customadds;
10748: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
10749: if (@newcustom) {
10750: map { $customadds{$_} = 1; } @newcustom;
10751: }
10752: my %imgdeletions;
10753: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
10754: if (@todeleteimages) {
10755: map { $imgdeletions{$_} = 1; } @todeleteimages;
10756: }
10757: my $maxnum = $env{'form.ltitools_maxnum'};
10758: for (my $i=0; $i<=$maxnum; $i++) {
10759: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 10760: $itemid =~ s/\D+//g;
1.267 raeburn 10761: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
10762: if ($deletions{$itemid}) {
10763: if ($domconfig{$action}{$itemid}{'image'}) {
10764: #FIXME need to obsolete item in RES space
10765: }
10766: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
10767: next;
10768: } else {
10769: my $newpos = $env{'form.ltitools_'.$itemid};
10770: $newpos =~ s/\D+//g;
1.297 raeburn 10771: foreach my $item ('title','url') {
1.267 raeburn 10772: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10773: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
10774: $changes{$itemid} = 1;
10775: }
10776: }
1.297 raeburn 10777: foreach my $item ('key','secret') {
10778: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10779: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
10780: $changes{$itemid} = 1;
10781: }
10782: }
1.267 raeburn 10783: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
10784: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
10785: }
10786: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
10787: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
10788: }
10789: foreach my $size ('width','height') {
10790: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
10791: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
10792: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
10793: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
10794: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10795: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
10796: $changes{$itemid} = 1;
10797: }
10798: } else {
10799: $changes{$itemid} = 1;
10800: }
1.296 raeburn 10801: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10802: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
10803: $changes{$itemid} = 1;
10804: }
10805: }
10806: }
10807: foreach my $item ('linktext','explanation') {
10808: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
10809: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
10810: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
10811: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10812: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10813: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
10814: $changes{$itemid} = 1;
10815: }
10816: } else {
10817: $changes{$itemid} = 1;
10818: }
10819: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10820: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
10821: $changes{$itemid} = 1;
10822: }
1.267 raeburn 10823: }
10824: }
10825: if ($env{'form.ltitools_target_'.$i} eq 'window') {
10826: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 10827: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
10828: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 10829: } else {
10830: $confhash{$itemid}{'display'}{'target'} = 'iframe';
10831: }
10832: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10833: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
10834: $changes{$itemid} = 1;
10835: }
10836: } else {
10837: $changes{$itemid} = 1;
10838: }
10839: foreach my $extra ('passback','roster') {
10840: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
10841: $confhash{$itemid}{$extra} = 1;
1.319 raeburn 10842: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
10843: my $lifetime = $env{'form.ltitools_'.$extra.'valid_add'};
10844: $lifetime =~ s/^\s+|\s+$//g;
10845: if ($lifetime =~ /^\d+\.?\d*$/) {
10846: $confhash{$itemid}{$extra.'valid'} = $lifetime;
10847: }
10848: }
1.267 raeburn 10849: }
10850: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
10851: $changes{$itemid} = 1;
10852: }
1.319 raeburn 10853: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
10854: $changes{$itemid} = 1;
10855: }
1.267 raeburn 10856: }
1.273 raeburn 10857: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 10858: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 10859: if (grep(/^\Q$item\E$/,@courseconfig)) {
10860: $confhash{$itemid}{'crsconf'}{$item} = 1;
10861: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
10862: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
10863: $changes{$itemid} = 1;
10864: }
10865: } else {
10866: $changes{$itemid} = 1;
10867: }
10868: }
10869: }
1.267 raeburn 10870: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
10871: foreach my $field (@fields) {
10872: if ($possfield{$field}) {
10873: if ($field eq 'roles') {
10874: foreach my $role (@courseroles) {
10875: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
10876: if (($choice ne '') && ($posslti{$choice})) {
10877: $confhash{$itemid}{'roles'}{$role} = $choice;
10878: if ($role eq 'cc') {
10879: $confhash{$itemid}{'roles'}{'co'} = $choice;
10880: }
10881: }
10882: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
10883: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
10884: $changes{$itemid} = 1;
10885: }
10886: } elsif ($confhash{$itemid}{'roles'}{$role}) {
10887: $changes{$itemid} = 1;
10888: }
10889: }
10890: } else {
10891: $confhash{$itemid}{'fields'}{$field} = 1;
10892: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
10893: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
10894: $changes{$itemid} = 1;
10895: }
10896: } else {
10897: $changes{$itemid} = 1;
10898: }
10899: }
10900: }
10901: }
10902: $allpos[$newpos] = $itemid;
10903: }
10904: if ($imgdeletions{$itemid}) {
10905: $changes{$itemid} = 1;
10906: #FIXME need to obsolete item in RES space
10907: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
10908: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
10909: $itemid,$configuserok,$switchserver,
10910: $author_ok);
10911: if ($imgurl) {
10912: $confhash{$itemid}{'image'} = $imgurl;
10913: $changes{$itemid} = 1;
10914: }
10915: if ($error) {
10916: &Apache::lonnet::logthis($error);
10917: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10918: }
10919: } elsif ($domconfig{$action}{$itemid}{'image'}) {
10920: $confhash{$itemid}{'image'} =
10921: $domconfig{$action}{$itemid}{'image'};
10922: }
10923: if ($customadds{$i}) {
10924: my $name = $env{'form.ltitools_custom_name_'.$i};
10925: $name =~ s/(`)/'/g;
10926: $name =~ s/^\s+//;
10927: $name =~ s/\s+$//;
10928: my $value = $env{'form.ltitools_custom_value_'.$i};
10929: $value =~ s/(`)/'/g;
10930: $value =~ s/^\s+//;
10931: $value =~ s/\s+$//;
10932: if ($name ne '') {
10933: $confhash{$itemid}{'custom'}{$name} = $value;
10934: $changes{$itemid} = 1;
10935: }
10936: }
10937: my %customdels;
10938: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
10939: if (@customdeletions) {
10940: $changes{$itemid} = 1;
10941: }
10942: map { $customdels{$_} = 1; } @customdeletions;
10943: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
10944: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
10945: unless ($customdels{$key}) {
10946: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
10947: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
10948: }
10949: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
10950: $changes{$itemid} = 1;
10951: }
10952: }
10953: }
10954: }
10955: unless ($changes{$itemid}) {
10956: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
10957: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
10958: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
10959: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
10960: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
10961: $changes{$itemid} = 1;
10962: last;
10963: }
10964: }
10965: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
10966: $changes{$itemid} = 1;
10967: }
10968: }
10969: last if ($changes{$itemid});
10970: }
10971: }
10972: }
10973: }
10974: }
10975: if (@allpos > 0) {
10976: my $idx = 0;
10977: foreach my $itemid (@allpos) {
10978: if ($itemid ne '') {
10979: $confhash{$itemid}{'order'} = $idx;
10980: if (ref($domconfig{$action}) eq 'HASH') {
10981: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
10982: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
10983: $changes{$itemid} = 1;
10984: }
10985: }
10986: }
10987: $idx ++;
10988: }
10989: }
10990: }
10991: my %ltitoolshash = (
10992: $action => { %confhash }
10993: );
10994: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
10995: $dom);
10996: if ($putresult eq 'ok') {
1.297 raeburn 10997: my %ltienchash = (
10998: $action => { %encconfig }
10999: );
11000: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267 raeburn 11001: if (keys(%changes) > 0) {
11002: my $cachetime = 24*60*60;
1.297 raeburn 11003: my %ltiall = %confhash;
11004: foreach my $id (keys(%ltiall)) {
11005: if (ref($encconfig{$id}) eq 'HASH') {
11006: foreach my $item ('key','secret') {
11007: $ltiall{$id}{$item} = $encconfig{$id}{$item};
11008: }
11009: }
11010: }
11011: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 11012: if (ref($lastactref) eq 'HASH') {
11013: $lastactref->{'ltitools'} = 1;
11014: }
11015: $resulttext = &mt('Changes made:').'<ul>';
11016: my %bynum;
11017: foreach my $itemid (sort(keys(%changes))) {
11018: my $position = $confhash{$itemid}{'order'};
11019: $bynum{$position} = $itemid;
11020: }
11021: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
11022: my $itemid = $bynum{$pos};
11023: if (ref($confhash{$itemid}) ne 'HASH') {
11024: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
11025: } else {
11026: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
11027: if ($confhash{$itemid}{'image'}) {
11028: $resulttext .= ' '.
11029: '<img src="'.$confhash{$itemid}{'image'}.'"'.
11030: ' alt="'.&mt('Tool Provider icon').'" />';
11031: }
11032: $resulttext .= '</li><ul>';
11033: my $position = $pos + 1;
11034: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.297 raeburn 11035: foreach my $item ('version','msgtype','url') {
1.267 raeburn 11036: if ($confhash{$itemid}{$item} ne '') {
11037: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
11038: }
11039: }
1.297 raeburn 11040: if ($encconfig{$itemid}{'key'} ne '') {
11041: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
11042: }
11043: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 11044: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 11045: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 11046: $resulttext .= ('*'x$num).'</li>';
11047: }
1.273 raeburn 11048: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 11049: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 11050: my $numconfig = 0;
11051: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
11052: foreach my $item (@possconfig) {
11053: if ($confhash{$itemid}{'crsconf'}{$item}) {
11054: $numconfig ++;
1.296 raeburn 11055: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 11056: }
11057: }
11058: }
11059: if (!$numconfig) {
11060: $resulttext .= &mt('None');
11061: }
11062: $resulttext .= '</li>';
1.267 raeburn 11063: foreach my $item ('passback','roster') {
11064: $resulttext .= '<li>'.$lt{$item}.' ';
11065: if ($confhash{$itemid}{$item}) {
11066: $resulttext .= &mt('Yes');
1.319 raeburn 11067: if ($confhash{$itemid}{$item.'valid'}) {
11068: if ($item eq 'passback') {
11069: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
11070: $confhash{$itemid}{$item.'valid'});
11071: } else {
11072: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
11073: $confhash{$itemid}{$item.'valid'});
11074: }
11075: }
1.267 raeburn 11076: } else {
11077: $resulttext .= &mt('No');
11078: }
11079: $resulttext .= '</li>';
11080: }
11081: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
11082: my $displaylist;
11083: if ($confhash{$itemid}{'display'}{'target'}) {
11084: $displaylist = &mt('Display target').': '.
11085: $confhash{$itemid}{'display'}{'target'}.',';
11086: }
11087: foreach my $size ('width','height') {
11088: if ($confhash{$itemid}{'display'}{$size}) {
11089: $displaylist .= (' 'x2).$lt{$size}.': '.
11090: $confhash{$itemid}{'display'}{$size}.',';
11091: }
11092: }
11093: if ($displaylist) {
11094: $displaylist =~ s/,$//;
11095: $resulttext .= '<li>'.$displaylist.'</li>';
11096: }
1.296 raeburn 11097: foreach my $item ('linktext','explanation') {
11098: if ($confhash{$itemid}{'display'}{$item}) {
11099: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
11100: }
11101: }
11102: }
1.267 raeburn 11103: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
11104: my $fieldlist;
11105: foreach my $field (@allfields) {
11106: if ($confhash{$itemid}{'fields'}{$field}) {
11107: $fieldlist .= (' 'x2).$lt{$field}.',';
11108: }
11109: }
11110: if ($fieldlist) {
11111: $fieldlist =~ s/,$//;
11112: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
11113: }
11114: }
11115: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
11116: my $rolemaps;
11117: foreach my $role (@courseroles) {
11118: if ($confhash{$itemid}{'roles'}{$role}) {
11119: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
11120: $confhash{$itemid}{'roles'}{$role}.',';
11121: }
11122: }
11123: if ($rolemaps) {
11124: $rolemaps =~ s/,$//;
11125: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
11126: }
11127: }
11128: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
11129: my $customlist;
11130: if (keys(%{$confhash{$itemid}{'custom'}})) {
11131: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
11132: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
11133: }
11134: }
11135: if ($customlist) {
1.317 raeburn 11136: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 11137: }
11138: }
11139: $resulttext .= '</ul></li>';
11140: }
11141: }
11142: $resulttext .= '</ul>';
11143: } else {
11144: $resulttext = &mt('No changes made.');
11145: }
11146: } else {
11147: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
11148: }
11149: if ($errors) {
11150: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11151: $errors.'</ul>';
11152: }
11153: return $resulttext;
11154: }
11155:
11156: sub process_ltitools_image {
11157: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
11158: my $filename = $env{'form.'.$caller.'.filename'};
11159: my ($error,$url);
11160: my ($width,$height) = (21,21);
11161: if ($configuserok eq 'ok') {
11162: if ($switchserver) {
11163: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
11164: $switchserver);
11165: } elsif ($author_ok eq 'ok') {
11166: my ($result,$imageurl,$madethumb) =
11167: &publishlogo($r,'upload',$caller,$dom,$confname,
11168: "ltitools/$itemid/icon",$width,$height);
11169: if ($result eq 'ok') {
11170: if ($madethumb) {
11171: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
11172: my $imagethumb = "$path/tn-".$imagefile;
11173: $url = $imagethumb;
11174: } else {
11175: $url = $imageurl;
11176: }
11177: } else {
11178: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
11179: }
11180: } else {
11181: $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);
11182: }
11183: } else {
11184: $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);
11185: }
11186: return ($url,$error);
11187: }
11188:
11189: sub get_ltitools_id {
11190: my ($cdom,$title) = @_;
11191: # get lock on ltitools db
11192: my $lockhash = {
11193: lock => $env{'user.name'}.
11194: ':'.$env{'user.domain'},
11195: };
11196: my $tries = 0;
11197: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11198: my ($id,$error);
11199:
11200: while (($gotlock ne 'ok') && ($tries<10)) {
11201: $tries ++;
11202: sleep (0.1);
11203: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11204: }
11205: if ($gotlock eq 'ok') {
11206: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
11207: if ($currids{'lock'}) {
11208: delete($currids{'lock'});
11209: if (keys(%currids)) {
11210: my @curr = sort { $a <=> $b } keys(%currids);
11211: if ($curr[-1] =~ /^\d+$/) {
11212: $id = 1 + $curr[-1];
11213: }
11214: } else {
11215: $id = 1;
11216: }
11217: if ($id) {
11218: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
11219: $error = 'nostore';
11220: }
11221: } else {
11222: $error = 'nonumber';
11223: }
11224: }
11225: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
11226: } else {
11227: $error = 'nolock';
11228: }
11229: return ($id,$error);
11230: }
11231:
1.320 raeburn 11232: sub modify_lti {
11233: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
11234: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11235: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
11236: my (%posslti,%posslticrs,%posscrstype);
11237: my @courseroles = ('cc','in','ta','ep','st');
11238: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
11239: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
11240: my @coursetypes = ('official','unofficial','community','textbook','placement');
11241: my %coursetypetitles = &Apache::lonlocal::texthash (
11242: official => 'Official',
11243: unofficial => 'Unofficial',
11244: community => 'Community',
11245: textbook => 'Textbook',
11246: placement => 'Placement Test',
11247: );
11248: my %lt = <i_names();
11249: map { $posslti{$_} = 1; } @ltiroles;
11250: map { $posslticrs{$_} = 1; } @lticourseroles;
11251: map { $posscrstype{$_} = 1; } @coursetypes;
11252:
11253: my (@items,%deletions,%itemids);
11254: if ($env{'form.lti_add'}) {
11255: my $consumer = $env{'form.lti_consumer_add'};
11256: $consumer =~ s/(`)/'/g;
11257: ($newid,my $error) = &get_lti_id($dom,$consumer);
11258: if ($newid) {
11259: $itemids{'add'} = $newid;
11260: push(@items,'add');
11261: $changes{$newid} = 1;
11262: } else {
11263: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
11264: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11265: }
11266: }
11267: if (ref($domconfig{$action}) eq 'HASH') {
11268: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
11269: if (@todelete) {
11270: map { $deletions{$_} = 1; } @todelete;
11271: }
11272: my $maxnum = $env{'form.lti_maxnum'};
11273: for (my $i=0; $i<=$maxnum; $i++) {
11274: my $itemid = $env{'form.lti_id_'.$i};
11275: $itemid =~ s/\D+//g;
11276: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11277: if ($deletions{$itemid}) {
11278: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
11279: } else {
11280: push(@items,$i);
11281: $itemids{$i} = $itemid;
11282: }
11283: }
11284: }
11285: }
11286: foreach my $idx (@items) {
11287: my $itemid = $itemids{$idx};
11288: next unless ($itemid);
11289: my $position = $env{'form.lti_pos_'.$idx};
11290: $position =~ s/\D+//g;
11291: if ($position ne '') {
11292: $allpos[$position] = $itemid;
11293: }
11294: foreach my $item ('consumer','key','secret','lifetime') {
11295: my $formitem = 'form.lti_'.$item.'_'.$idx;
11296: $env{$formitem} =~ s/(`)/'/g;
11297: if ($item eq 'lifetime') {
11298: $env{$formitem} =~ s/[^\d.]//g;
11299: }
11300: if ($env{$formitem} ne '') {
11301: if (($item eq 'key') || ($item eq 'secret')) {
11302: $encconfig{$itemid}{$item} = $env{$formitem};
11303: } else {
11304: $confhash{$itemid}{$item} = $env{$formitem};
11305: unless (($idx eq 'add') || ($changes{$itemid})) {
11306: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
11307: $changes{$itemid} = 1;
11308: }
11309: }
11310: }
11311: }
11312: }
11313: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
11314: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
11315: }
11316: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
11317: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
11318: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
11319: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
11320: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
11321: my $mapuser = $env{'form.lti_customuser_'.$idx};
11322: $mapuser =~ s/(`)/'/g;
11323: $mapuser =~ s/^\s+|\s+$//g;
11324: $confhash{$itemid}{'mapuser'} = $mapuser;
11325: }
11326: foreach my $ltirole (@lticourseroles) {
11327: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
11328: if (grep(/^\Q$possrole\E$/,@courseroles)) {
11329: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
11330: }
11331: }
11332: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
11333: my @makeuser;
11334: foreach my $ltirole (sort(@possmakeuser)) {
11335: if ($posslti{$ltirole}) {
11336: push(@makeuser,$ltirole);
11337: }
11338: }
11339: $confhash{$itemid}{'makeuser'} = \@makeuser;
11340: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
11341: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
11342: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
11343: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
11344: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
11345: $mapcrs =~ s/(`)/'/g;
11346: $mapcrs =~ s/^\s+|\s+$//g;
11347: $confhash{$itemid}{'mapcrs'} = $mapcrs;
11348: }
11349: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
11350: my @crstypes;
11351: foreach my $type (sort(@posstypes)) {
11352: if ($posscrstype{$type}) {
11353: push(@crstypes,$type);
11354: }
11355: }
11356: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
11357: if ($env{'form.lti_makecrs_'.$idx}) {
11358: $confhash{$itemid}{'makecrs'} = 1;
11359: }
11360: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
11361: my @selfenroll;
11362: foreach my $type (sort(@possenroll)) {
11363: if ($posslticrs{$type}) {
11364: push(@selfenroll,$type);
11365: }
11366: }
11367: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
11368: if ($env{'form.lti_crssec_'.$idx}) {
11369: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
11370: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
11371: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
11372: my $section = $env{'form.lti_customsection_'.$idx};
11373: $section =~ s/(`)/'/g;
11374: $section =~ s/^\s+|\s+$//g;
11375: if ($section ne '') {
11376: $confhash{$itemid}{'section'} = $section;
11377: }
11378: }
11379: }
11380: foreach my $field ('passback','roster') {
1.321 ! raeburn 11381: if ($env{'form.lti_'.$field.'_'.$idx}) {
1.320 raeburn 11382: $confhash{$itemid}{$field} = 1;
11383: }
11384: }
11385: unless (($idx eq 'add') || ($changes{$itemid})) {
11386: foreach my $field ('mapuser','mapcrs','section','passback','roster') {
11387: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
11388: $changes{$itemid} = 1;
11389: }
11390: }
11391: foreach my $field ('makeuser','mapcrstype','selfenroll') {
11392: unless ($changes{$itemid}) {
11393: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
11394: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
11395: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
11396: $confhash{$itemid}{$field});
11397: if (@diffs) {
11398: $changes{$itemid} = 1;
11399: }
11400: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
11401: $changes{$itemid} = 1;
11402: }
11403: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
11404: if (@{$confhash{$itemid}{$field}} > 0) {
11405: $changes{$itemid} = 1;
11406: }
11407: }
11408: }
11409: }
11410: unless ($changes{$itemid}) {
11411: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
11412: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11413: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
11414: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
11415: $confhash{$itemid}{'maproles'}{$ltirole}) {
11416: $changes{$itemid} = 1;
11417: last;
11418: }
11419: }
11420: unless ($changes{$itemid}) {
11421: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
11422: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
11423: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
11424: $changes{$itemid} = 1;
11425: last;
11426: }
11427: }
11428: }
11429: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
11430: $changes{$itemid} = 1;
11431: }
11432: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11433: unless ($changes{$itemid}) {
11434: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
11435: $changes{$itemid} = 1;
11436: }
11437: }
11438: }
11439: }
11440: }
11441: }
11442: if (@allpos > 0) {
11443: my $idx = 0;
11444: foreach my $itemid (@allpos) {
11445: if ($itemid ne '') {
11446: $confhash{$itemid}{'order'} = $idx;
11447: if (ref($domconfig{$action}) eq 'HASH') {
11448: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11449: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
11450: $changes{$itemid} = 1;
11451: }
11452: }
11453: }
11454: $idx ++;
11455: }
11456: }
11457: }
11458: my %ltihash = (
11459: $action => { %confhash }
11460: );
11461: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
11462: $dom);
11463: if ($putresult eq 'ok') {
11464: my %ltienchash = (
11465: $action => { %encconfig }
11466: );
11467: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
11468: if (keys(%changes) > 0) {
11469: my $cachetime = 24*60*60;
11470: my %ltiall = %confhash;
11471: foreach my $id (keys(%ltiall)) {
11472: if (ref($encconfig{$id}) eq 'HASH') {
11473: foreach my $item ('key','secret') {
11474: $ltiall{$id}{$item} = $encconfig{$id}{$item};
11475: }
11476: }
11477: }
11478: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
11479: if (ref($lastactref) eq 'HASH') {
11480: $lastactref->{'lti'} = 1;
11481: }
11482: $resulttext = &mt('Changes made:').'<ul>';
11483: my %bynum;
11484: foreach my $itemid (sort(keys(%changes))) {
11485: my $position = $confhash{$itemid}{'order'};
11486: $bynum{$position} = $itemid;
11487: }
11488: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
11489: my $itemid = $bynum{$pos};
11490: if (ref($confhash{$itemid}) ne 'HASH') {
11491: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
11492: } else {
11493: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b></li><ul>';
11494: my $position = $pos + 1;
11495: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
11496: foreach my $item ('version','lifetime') {
11497: if ($confhash{$itemid}{$item} ne '') {
11498: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
11499: }
11500: }
11501: if ($encconfig{$itemid}{'key'} ne '') {
11502: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
11503: }
11504: if ($encconfig{$itemid}{'secret'} ne '') {
11505: $resulttext .= '<li>'.$lt{'secret'}.': ';
11506: my $num = length($encconfig{$itemid}{'secret'});
11507: $resulttext .= ('*'x$num).'</li>';
11508: }
11509: if ($confhash{$itemid}{'mapuser'}) {
11510: my $shownmapuser;
11511: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
11512: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
11513: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
11514: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
11515: } else {
11516: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
11517: }
11518: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
11519: }
11520: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11521: my $rolemaps;
11522: foreach my $role (@ltiroles) {
11523: if ($confhash{$itemid}{'maproles'}{$role}) {
11524: $rolemaps .= (' 'x2).$role.'='.
11525: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
11526: 'Course').',';
11527: }
11528: }
11529: if ($rolemaps) {
11530: $rolemaps =~ s/,$//;
11531: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
11532: }
11533: }
11534: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
11535: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
11536: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
11537: join(', ',@{$confhash{$itemid}{'makeuser'}})).'</li>';
11538: } else {
11539: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
11540: }
11541: }
11542: if ($confhash{$itemid}{'mapcrs'}) {
11543: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
11544: }
11545: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
11546: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
11547: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
11548: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
11549: '</li>';
11550: } else {
11551: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
11552: }
11553: }
11554: if ($confhash{$itemid}{'makecrs'}) {
11555: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
11556: } else {
11557: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
11558: }
11559: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
11560: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
11561: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
11562: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
11563: '</li>';
11564: } else {
11565: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
11566: }
11567: }
11568: if ($confhash{$itemid}{'section'}) {
11569: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
11570: $resulttext .= '<li>'.&mt('User section from standard field:').
11571: ' (course_section_sourcedid)'.'</li>';
11572: } else {
11573: $resulttext .= '<li>'.&mt('User section from:').' '.
11574: $confhash{$itemid}{'section'}.'</li>';
11575: }
11576: } else {
11577: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
11578: }
11579: foreach my $item ('passback','roster') {
11580: $resulttext .= '<li>'.$lt{$item}.' ';
11581: if ($confhash{$itemid}{$item}) {
11582: $resulttext .= &mt('Yes');
11583: } else {
11584: $resulttext .= &mt('No');
11585: }
11586: $resulttext .= '</li>';
11587: }
11588: $resulttext .= '</ul></li>';
11589: }
11590: }
11591: $resulttext .= '</ul>';
11592: } else {
11593: $resulttext = &mt('No changes made.');
11594: }
11595: } else {
11596: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
11597: }
11598: if ($errors) {
11599: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11600: $errors.'</ul>';
11601: }
11602: return $resulttext;
11603: }
11604:
11605: sub get_lti_id {
11606: my ($domain,$consumer) = @_;
11607: # get lock on lti db
11608: my $lockhash = {
11609: lock => $env{'user.name'}.
11610: ':'.$env{'user.domain'},
11611: };
11612: my $tries = 0;
11613: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
11614: my ($id,$error);
11615:
11616: while (($gotlock ne 'ok') && ($tries<10)) {
11617: $tries ++;
11618: sleep (0.1);
11619: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
11620: }
11621: if ($gotlock eq 'ok') {
11622: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
11623: if ($currids{'lock'}) {
11624: delete($currids{'lock'});
11625: if (keys(%currids)) {
11626: my @curr = sort { $a <=> $b } keys(%currids);
11627: if ($curr[-1] =~ /^\d+$/) {
11628: $id = 1 + $curr[-1];
11629: }
11630: } else {
11631: $id = 1;
11632: }
11633: if ($id) {
11634: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
11635: $error = 'nostore';
11636: }
11637: } else {
11638: $error = 'nonumber';
11639: }
11640: }
11641: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
11642: } else {
11643: $error = 'nolock';
11644: }
11645: return ($id,$error);
11646: }
11647:
1.3 raeburn 11648: sub modify_autoenroll {
1.205 raeburn 11649: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 11650: my ($resulttext,%changes);
11651: my %currautoenroll;
11652: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
11653: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
11654: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
11655: }
11656: }
11657: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
11658: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 11659: sender => 'Sender for notification messages',
1.274 raeburn 11660: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
11661: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 11662: my @offon = ('off','on');
1.17 raeburn 11663: my $sender_uname = $env{'form.sender_uname'};
11664: my $sender_domain = $env{'form.sender_domain'};
11665: if ($sender_domain eq '') {
11666: $sender_uname = '';
11667: } elsif ($sender_uname eq '') {
11668: $sender_domain = '';
11669: }
1.129 raeburn 11670: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 11671: my $failsafe = $env{'form.autoenroll_failsafe'};
11672: $failsafe =~ s{^\s+|\s+$}{}g;
11673: if ($failsafe =~ /\D/) {
11674: undef($failsafe);
11675: }
1.1 raeburn 11676: my %autoenrollhash = (
1.129 raeburn 11677: autoenroll => { 'run' => $env{'form.autoenroll_run'},
11678: 'sender_uname' => $sender_uname,
11679: 'sender_domain' => $sender_domain,
11680: 'co-owners' => $coowners,
1.274 raeburn 11681: 'autofailsafe' => $failsafe,
1.1 raeburn 11682: }
11683: );
1.4 raeburn 11684: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
11685: $dom);
1.1 raeburn 11686: if ($putresult eq 'ok') {
11687: if (exists($currautoenroll{'run'})) {
11688: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
11689: $changes{'run'} = 1;
11690: }
11691: } elsif ($autorun) {
11692: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 11693: $changes{'run'} = 1;
1.1 raeburn 11694: }
11695: }
1.17 raeburn 11696: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 11697: $changes{'sender'} = 1;
11698: }
1.17 raeburn 11699: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 11700: $changes{'sender'} = 1;
11701: }
1.129 raeburn 11702: if ($currautoenroll{'co-owners'} ne '') {
11703: if ($currautoenroll{'co-owners'} ne $coowners) {
11704: $changes{'coowners'} = 1;
11705: }
11706: } elsif ($coowners) {
11707: $changes{'coowners'} = 1;
1.274 raeburn 11708: }
11709: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
11710: $changes{'autofailsafe'} = 1;
11711: }
1.1 raeburn 11712: if (keys(%changes) > 0) {
11713: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 11714: if ($changes{'run'}) {
1.1 raeburn 11715: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
11716: }
11717: if ($changes{'sender'}) {
1.17 raeburn 11718: if ($sender_uname eq '' || $sender_domain eq '') {
11719: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
11720: } else {
11721: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
11722: }
1.1 raeburn 11723: }
1.129 raeburn 11724: if ($changes{'coowners'}) {
11725: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
11726: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 11727: if (ref($lastactref) eq 'HASH') {
11728: $lastactref->{'domainconfig'} = 1;
11729: }
1.129 raeburn 11730: }
1.274 raeburn 11731: if ($changes{'autofailsafe'}) {
11732: if ($failsafe ne '') {
1.299 raeburn 11733: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 11734: } else {
1.299 raeburn 11735: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 11736: }
11737: &Apache::lonnet::get_domain_defaults($dom,1);
11738: if (ref($lastactref) eq 'HASH') {
11739: $lastactref->{'domdefaults'} = 1;
11740: }
11741: }
1.1 raeburn 11742: $resulttext .= '</ul>';
11743: } else {
11744: $resulttext = &mt('No changes made to auto-enrollment settings');
11745: }
11746: } else {
1.11 albertel 11747: $resulttext = '<span class="LC_error">'.
11748: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11749: }
1.3 raeburn 11750: return $resulttext;
1.1 raeburn 11751: }
11752:
11753: sub modify_autoupdate {
1.3 raeburn 11754: my ($dom,%domconfig) = @_;
1.1 raeburn 11755: my ($resulttext,%currautoupdate,%fields,%changes);
11756: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
11757: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
11758: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
11759: }
11760: }
11761: my @offon = ('off','on');
11762: my %title = &Apache::lonlocal::texthash (
11763: run => 'Auto-update:',
11764: classlists => 'Updates to user information in classlists?'
11765: );
1.44 raeburn 11766: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 11767: my %fieldtitles = &Apache::lonlocal::texthash (
11768: id => 'Student/Employee ID',
1.20 raeburn 11769: permanentemail => 'E-mail address',
1.1 raeburn 11770: lastname => 'Last Name',
11771: firstname => 'First Name',
11772: middlename => 'Middle Name',
1.132 raeburn 11773: generation => 'Generation',
1.1 raeburn 11774: );
1.142 raeburn 11775: $othertitle = &mt('All users');
1.1 raeburn 11776: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 11777: $othertitle = &mt('Other users');
1.1 raeburn 11778: }
11779: foreach my $key (keys(%env)) {
11780: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 11781: my ($usertype,$item) = ($1,$2);
11782: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
11783: if ($usertype eq 'default') {
11784: push(@{$fields{$1}},$2);
11785: } elsif (ref($types) eq 'ARRAY') {
11786: if (grep(/^\Q$usertype\E$/,@{$types})) {
11787: push(@{$fields{$1}},$2);
11788: }
11789: }
11790: }
1.1 raeburn 11791: }
11792: }
1.131 raeburn 11793: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
11794: @lockablenames = sort(@lockablenames);
11795: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
11796: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
11797: if (@changed) {
11798: $changes{'lockablenames'} = 1;
11799: }
11800: } else {
11801: if (@lockablenames) {
11802: $changes{'lockablenames'} = 1;
11803: }
11804: }
1.1 raeburn 11805: my %updatehash = (
11806: autoupdate => { run => $env{'form.autoupdate_run'},
11807: classlists => $env{'form.classlists'},
11808: fields => {%fields},
1.131 raeburn 11809: lockablenames => \@lockablenames,
1.1 raeburn 11810: }
11811: );
11812: foreach my $key (keys(%currautoupdate)) {
11813: if (($key eq 'run') || ($key eq 'classlists')) {
11814: if (exists($updatehash{autoupdate}{$key})) {
11815: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
11816: $changes{$key} = 1;
11817: }
11818: }
11819: } elsif ($key eq 'fields') {
11820: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 11821: foreach my $item (@{$types},'default') {
1.1 raeburn 11822: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
11823: my $change = 0;
11824: foreach my $type (@{$currautoupdate{$key}{$item}}) {
11825: if (!exists($fields{$item})) {
11826: $change = 1;
1.132 raeburn 11827: last;
1.1 raeburn 11828: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 11829: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 11830: $change = 1;
1.132 raeburn 11831: last;
1.1 raeburn 11832: }
11833: }
11834: }
11835: if ($change) {
11836: push(@{$changes{$key}},$item);
11837: }
1.26 raeburn 11838: }
1.1 raeburn 11839: }
11840: }
1.131 raeburn 11841: } elsif ($key eq 'lockablenames') {
11842: if (ref($currautoupdate{$key}) eq 'ARRAY') {
11843: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
11844: if (@changed) {
11845: $changes{'lockablenames'} = 1;
11846: }
11847: } else {
11848: if (@lockablenames) {
11849: $changes{'lockablenames'} = 1;
11850: }
11851: }
11852: }
11853: }
11854: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
11855: if (@lockablenames) {
11856: $changes{'lockablenames'} = 1;
1.1 raeburn 11857: }
11858: }
1.26 raeburn 11859: foreach my $item (@{$types},'default') {
11860: if (defined($fields{$item})) {
11861: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 11862: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
11863: my $change = 0;
11864: if (ref($fields{$item}) eq 'ARRAY') {
11865: foreach my $type (@{$fields{$item}}) {
11866: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
11867: $change = 1;
11868: last;
11869: }
11870: }
11871: }
11872: if ($change) {
11873: push(@{$changes{'fields'}},$item);
11874: }
11875: } else {
1.26 raeburn 11876: push(@{$changes{'fields'}},$item);
11877: }
11878: } else {
11879: push(@{$changes{'fields'}},$item);
1.1 raeburn 11880: }
11881: }
11882: }
11883: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
11884: $dom);
11885: if ($putresult eq 'ok') {
11886: if (keys(%changes) > 0) {
11887: $resulttext = &mt('Changes made:').'<ul>';
11888: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 11889: if ($key eq 'lockablenames') {
11890: $resulttext .= '<li>';
11891: if (@lockablenames) {
11892: $usertypes->{'default'} = $othertitle;
11893: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
11894: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
11895: } else {
11896: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
11897: }
11898: $resulttext .= '</li>';
11899: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 11900: foreach my $item (@{$changes{$key}}) {
11901: my @newvalues;
11902: foreach my $type (@{$fields{$item}}) {
11903: push(@newvalues,$fieldtitles{$type});
11904: }
1.3 raeburn 11905: my $newvaluestr;
11906: if (@newvalues > 0) {
11907: $newvaluestr = join(', ',@newvalues);
11908: } else {
11909: $newvaluestr = &mt('none');
1.6 raeburn 11910: }
1.1 raeburn 11911: if ($item eq 'default') {
1.26 raeburn 11912: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 11913: } else {
1.26 raeburn 11914: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 11915: }
11916: }
11917: } else {
11918: my $newvalue;
11919: if ($key eq 'run') {
11920: $newvalue = $offon[$env{'form.autoupdate_run'}];
11921: } else {
11922: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 11923: }
1.1 raeburn 11924: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
11925: }
11926: }
11927: $resulttext .= '</ul>';
11928: } else {
1.3 raeburn 11929: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 11930: }
11931: } else {
1.11 albertel 11932: $resulttext = '<span class="LC_error">'.
11933: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11934: }
1.3 raeburn 11935: return $resulttext;
1.1 raeburn 11936: }
11937:
1.125 raeburn 11938: sub modify_autocreate {
11939: my ($dom,%domconfig) = @_;
11940: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
11941: if (ref($domconfig{'autocreate'}) eq 'HASH') {
11942: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
11943: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
11944: }
11945: }
11946: my %title= ( xml => 'Auto-creation of courses in XML course description files',
11947: req => 'Auto-creation of validated requests for official courses',
11948: xmldc => 'Identity of course creator of courses from XML files',
11949: );
11950: my @types = ('xml','req');
11951: foreach my $item (@types) {
11952: $newvals{$item} = $env{'form.autocreate_'.$item};
11953: $newvals{$item} =~ s/\D//g;
11954: $newvals{$item} = 0 if ($newvals{$item} eq '');
11955: }
11956: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 11957: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 11958: unless (exists($domcoords{$newvals{'xmldc'}})) {
11959: $newvals{'xmldc'} = '';
11960: }
11961: %autocreatehash = (
11962: autocreate => { xml => $newvals{'xml'},
11963: req => $newvals{'req'},
11964: }
11965: );
11966: if ($newvals{'xmldc'} ne '') {
11967: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
11968: }
11969: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
11970: $dom);
11971: if ($putresult eq 'ok') {
11972: my @items = @types;
11973: if ($newvals{'xml'}) {
11974: push(@items,'xmldc');
11975: }
11976: foreach my $item (@items) {
11977: if (exists($currautocreate{$item})) {
11978: if ($currautocreate{$item} ne $newvals{$item}) {
11979: $changes{$item} = 1;
11980: }
11981: } elsif ($newvals{$item}) {
11982: $changes{$item} = 1;
11983: }
11984: }
11985: if (keys(%changes) > 0) {
11986: my @offon = ('off','on');
11987: $resulttext = &mt('Changes made:').'<ul>';
11988: foreach my $item (@types) {
11989: if ($changes{$item}) {
11990: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 11991: $resulttext .= '<li>'.
11992: &mt("$title{$item} set to [_1]$newtxt [_2]",
11993: '<b>','</b>').
11994: '</li>';
1.125 raeburn 11995: }
11996: }
11997: if ($changes{'xmldc'}) {
11998: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
11999: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 12000: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 12001: }
12002: $resulttext .= '</ul>';
12003: } else {
12004: $resulttext = &mt('No changes made to auto-creation settings');
12005: }
12006: } else {
12007: $resulttext = '<span class="LC_error">'.
12008: &mt('An error occurred: [_1]',$putresult).'</span>';
12009: }
12010: return $resulttext;
12011: }
12012:
1.23 raeburn 12013: sub modify_directorysrch {
1.295 raeburn 12014: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 12015: my ($resulttext,%changes);
12016: my %currdirsrch;
12017: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
12018: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
12019: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
12020: }
12021: }
1.277 raeburn 12022: my %title = ( available => 'Institutional directory search available',
12023: localonly => 'Other domains can search institution',
12024: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 12025: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 12026: searchby => 'Search types',
12027: searchtypes => 'Search latitude');
12028: my @offon = ('off','on');
1.24 raeburn 12029: my @otherdoms = ('Yes','No');
1.23 raeburn 12030:
1.25 raeburn 12031: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 12032: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
12033: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
12034:
1.44 raeburn 12035: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 12036: if (keys(%{$usertypes}) == 0) {
12037: @cansearch = ('default');
12038: } else {
12039: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
12040: foreach my $type (@{$currdirsrch{'cansearch'}}) {
12041: if (!grep(/^\Q$type\E$/,@cansearch)) {
12042: push(@{$changes{'cansearch'}},$type);
12043: }
1.23 raeburn 12044: }
1.26 raeburn 12045: foreach my $type (@cansearch) {
12046: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
12047: push(@{$changes{'cansearch'}},$type);
12048: }
1.23 raeburn 12049: }
1.26 raeburn 12050: } else {
12051: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 12052: }
12053: }
12054:
12055: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
12056: foreach my $by (@{$currdirsrch{'searchby'}}) {
12057: if (!grep(/^\Q$by\E$/,@searchby)) {
12058: push(@{$changes{'searchby'}},$by);
12059: }
12060: }
12061: foreach my $by (@searchby) {
12062: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
12063: push(@{$changes{'searchby'}},$by);
12064: }
12065: }
12066: } else {
12067: push(@{$changes{'searchby'}},@searchby);
12068: }
1.25 raeburn 12069:
12070: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
12071: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
12072: if (!grep(/^\Q$type\E$/,@searchtypes)) {
12073: push(@{$changes{'searchtypes'}},$type);
12074: }
12075: }
12076: foreach my $type (@searchtypes) {
12077: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
12078: push(@{$changes{'searchtypes'}},$type);
12079: }
12080: }
12081: } else {
12082: if (exists($currdirsrch{'searchtypes'})) {
12083: foreach my $type (@searchtypes) {
12084: if ($type ne $currdirsrch{'searchtypes'}) {
12085: push(@{$changes{'searchtypes'}},$type);
12086: }
12087: }
12088: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
12089: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
12090: }
12091: } else {
12092: push(@{$changes{'searchtypes'}},@searchtypes);
12093: }
12094: }
12095:
1.23 raeburn 12096: my %dirsrch_hash = (
12097: directorysrch => { available => $env{'form.dirsrch_available'},
12098: cansearch => \@cansearch,
1.277 raeburn 12099: localonly => $env{'form.dirsrch_instlocalonly'},
12100: lclocalonly => $env{'form.dirsrch_domlocalonly'},
12101: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 12102: searchby => \@searchby,
1.25 raeburn 12103: searchtypes => \@searchtypes,
1.23 raeburn 12104: }
12105: );
12106: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
12107: $dom);
12108: if ($putresult eq 'ok') {
12109: if (exists($currdirsrch{'available'})) {
12110: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
12111: $changes{'available'} = 1;
12112: }
12113: } else {
12114: if ($env{'form.dirsrch_available'} eq '1') {
12115: $changes{'available'} = 1;
12116: }
12117: }
1.277 raeburn 12118: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 12119: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
12120: $changes{'lcavailable'} = 1;
12121: }
1.277 raeburn 12122: } else {
12123: if ($env{'form.dirsrch_lcavailable'} eq '1') {
12124: $changes{'lcavailable'} = 1;
12125: }
12126: }
1.24 raeburn 12127: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 12128: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
12129: $changes{'localonly'} = 1;
12130: }
1.24 raeburn 12131: } else {
1.277 raeburn 12132: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 12133: $changes{'localonly'} = 1;
12134: }
12135: }
1.277 raeburn 12136: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 12137: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
12138: $changes{'lclocalonly'} = 1;
12139: }
1.277 raeburn 12140: } else {
12141: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
12142: $changes{'lclocalonly'} = 1;
12143: }
12144: }
1.23 raeburn 12145: if (keys(%changes) > 0) {
12146: $resulttext = &mt('Changes made:').'<ul>';
12147: if ($changes{'available'}) {
12148: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
12149: }
1.277 raeburn 12150: if ($changes{'lcavailable'}) {
12151: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
12152: }
1.24 raeburn 12153: if ($changes{'localonly'}) {
1.277 raeburn 12154: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 12155: }
1.277 raeburn 12156: if ($changes{'lclocalonly'}) {
12157: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 12158: }
1.23 raeburn 12159: if (ref($changes{'cansearch'}) eq 'ARRAY') {
12160: my $chgtext;
1.26 raeburn 12161: if (ref($usertypes) eq 'HASH') {
12162: if (keys(%{$usertypes}) > 0) {
12163: foreach my $type (@{$types}) {
12164: if (grep(/^\Q$type\E$/,@cansearch)) {
12165: $chgtext .= $usertypes->{$type}.'; ';
12166: }
12167: }
12168: if (grep(/^default$/,@cansearch)) {
12169: $chgtext .= $othertitle;
12170: } else {
12171: $chgtext =~ s/\; $//;
12172: }
1.210 raeburn 12173: $resulttext .=
1.178 raeburn 12174: '<li>'.
12175: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
12176: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
12177: '</li>';
1.23 raeburn 12178: }
12179: }
12180: }
12181: if (ref($changes{'searchby'}) eq 'ARRAY') {
12182: my ($searchtitles,$titleorder) = &sorted_searchtitles();
12183: my $chgtext;
12184: foreach my $type (@{$titleorder}) {
12185: if (grep(/^\Q$type\E$/,@searchby)) {
12186: if (defined($searchtitles->{$type})) {
12187: $chgtext .= $searchtitles->{$type}.'; ';
12188: }
12189: }
12190: }
12191: $chgtext =~ s/\; $//;
12192: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
12193: }
1.25 raeburn 12194: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
12195: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
12196: my $chgtext;
12197: foreach my $type (@{$srchtypeorder}) {
12198: if (grep(/^\Q$type\E$/,@searchtypes)) {
12199: if (defined($srchtypes_desc->{$type})) {
12200: $chgtext .= $srchtypes_desc->{$type}.'; ';
12201: }
12202: }
12203: }
12204: $chgtext =~ s/\; $//;
1.178 raeburn 12205: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 12206: }
12207: $resulttext .= '</ul>';
1.295 raeburn 12208: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
12209: if (ref($lastactref) eq 'HASH') {
12210: $lastactref->{'directorysrch'} = 1;
12211: }
1.23 raeburn 12212: } else {
1.277 raeburn 12213: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 12214: }
12215: } else {
12216: $resulttext = '<span class="LC_error">'.
1.27 raeburn 12217: &mt('An error occurred: [_1]',$putresult).'</span>';
12218: }
12219: return $resulttext;
12220: }
12221:
1.28 raeburn 12222: sub modify_contacts {
1.205 raeburn 12223: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 12224: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
12225: if (ref($domconfig{'contacts'}) eq 'HASH') {
12226: foreach my $key (keys(%{$domconfig{'contacts'}})) {
12227: $currsetting{$key} = $domconfig{'contacts'}{$key};
12228: }
12229: }
1.286 raeburn 12230: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 12231: my @contacts = ('supportemail','adminemail');
1.286 raeburn 12232: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
12233: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.203 raeburn 12234: my @toggles = ('reporterrors','reportupdates');
1.286 raeburn 12235: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 12236: foreach my $type (@mailings) {
12237: @{$newsetting{$type}} =
12238: &Apache::loncommon::get_env_multiple('form.'.$type);
12239: foreach my $item (@contacts) {
12240: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
12241: $contacts_hash{contacts}{$type}{$item} = 1;
12242: } else {
12243: $contacts_hash{contacts}{$type}{$item} = 0;
12244: }
1.289 raeburn 12245: }
1.28 raeburn 12246: $others{$type} = $env{'form.'.$type.'_others'};
12247: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 12248: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12249: $bcc{$type} = $env{'form.'.$type.'_bcc'};
12250: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 12251: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
12252: $includestr{$type} = $env{'form.'.$type.'_includestr'};
12253: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
12254: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12255: }
1.134 raeburn 12256: }
1.28 raeburn 12257: }
12258: foreach my $item (@contacts) {
12259: $to{$item} = $env{'form.'.$item};
12260: $contacts_hash{'contacts'}{$item} = $to{$item};
12261: }
1.203 raeburn 12262: foreach my $item (@toggles) {
12263: if ($env{'form.'.$item} =~ /^(0|1)$/) {
12264: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
12265: }
12266: }
1.286 raeburn 12267: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
12268: foreach my $field (@{$fields}) {
12269: if (ref($possoptions->{$field}) eq 'ARRAY') {
12270: my $value = $env{'form.helpform_'.$field};
12271: $value =~ s/^\s+|\s+$//g;
12272: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 12273: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 12274: if ($field eq 'screenshot') {
12275: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
12276: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 12277: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 12278: }
12279: }
12280: }
12281: }
12282: }
12283: }
1.315 raeburn 12284: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12285: my (@statuses,%usertypeshash,@overrides);
12286: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
12287: @statuses = @{$types};
12288: if (ref($usertypes) eq 'HASH') {
12289: %usertypeshash = %{$usertypes};
12290: }
12291: }
12292: if (@statuses) {
12293: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
12294: foreach my $type (@possoverrides) {
12295: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
12296: push(@overrides,$type);
12297: }
12298: }
12299: if (@overrides) {
12300: foreach my $type (@overrides) {
12301: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
12302: foreach my $item (@contacts) {
12303: if (grep(/^\Q$item\E$/,@standard)) {
12304: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
12305: $newsetting{'override_'.$type}{$item} = 1;
12306: } else {
12307: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
12308: $newsetting{'override_'.$type}{$item} = 0;
12309: }
12310: }
12311: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
12312: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12313: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
12314: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12315: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
12316: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
12317: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
12318: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12319: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
12320: }
12321: }
12322: }
12323: }
1.28 raeburn 12324: if (keys(%currsetting) > 0) {
12325: foreach my $item (@contacts) {
12326: if ($to{$item} ne $currsetting{$item}) {
12327: $changes{$item} = 1;
12328: }
12329: }
12330: foreach my $type (@mailings) {
12331: foreach my $item (@contacts) {
12332: if (ref($currsetting{$type}) eq 'HASH') {
12333: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
12334: push(@{$changes{$type}},$item);
12335: }
12336: } else {
12337: push(@{$changes{$type}},@{$newsetting{$type}});
12338: }
12339: }
12340: if ($others{$type} ne $currsetting{$type}{'others'}) {
12341: push(@{$changes{$type}},'others');
12342: }
1.289 raeburn 12343: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12344: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
12345: push(@{$changes{$type}},'bcc');
12346: }
1.286 raeburn 12347: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
12348: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
12349: push(@{$changes{$type}},'include');
12350: }
12351: }
12352: }
12353: if (ref($fields) eq 'ARRAY') {
12354: if (ref($currsetting{'helpform'}) eq 'HASH') {
12355: foreach my $field (@{$fields}) {
12356: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
12357: push(@{$changes{'helpform'}},$field);
12358: }
12359: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12360: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
12361: push(@{$changes{'helpform'}},'maxsize');
12362: }
12363: }
12364: }
12365: } else {
12366: foreach my $field (@{$fields}) {
12367: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12368: push(@{$changes{'helpform'}},$field);
12369: }
12370: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12371: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12372: push(@{$changes{'helpform'}},'maxsize');
12373: }
12374: }
12375: }
1.134 raeburn 12376: }
1.28 raeburn 12377: }
1.315 raeburn 12378: if (@statuses) {
12379: if (ref($currsetting{'overrides'}) eq 'HASH') {
12380: foreach my $key (keys(%{$currsetting{'overrides'}})) {
12381: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
12382: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
12383: foreach my $item (@contacts,'bcc','others','include') {
12384: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
12385: push(@{$changes{'overrides'}},$key);
12386: last;
12387: }
12388: }
12389: } else {
12390: push(@{$changes{'overrides'}},$key);
12391: }
12392: }
12393: }
12394: foreach my $key (@overrides) {
12395: unless (exists($currsetting{'overrides'}{$key})) {
12396: push(@{$changes{'overrides'}},$key);
12397: }
12398: }
12399: } else {
12400: foreach my $key (@overrides) {
12401: push(@{$changes{'overrides'}},$key);
12402: }
12403: }
12404: }
1.28 raeburn 12405: } else {
12406: my %default;
12407: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
12408: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
12409: $default{'errormail'} = 'adminemail';
12410: $default{'packagesmail'} = 'adminemail';
12411: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 12412: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 12413: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 12414: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 12415: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 12416: foreach my $item (@contacts) {
12417: if ($to{$item} ne $default{$item}) {
1.286 raeburn 12418: $changes{$item} = 1;
1.203 raeburn 12419: }
1.28 raeburn 12420: }
12421: foreach my $type (@mailings) {
12422: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
12423: push(@{$changes{$type}},@{$newsetting{$type}});
12424: }
12425: if ($others{$type} ne '') {
12426: push(@{$changes{$type}},'others');
1.134 raeburn 12427: }
1.286 raeburn 12428: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12429: if ($bcc{$type} ne '') {
12430: push(@{$changes{$type}},'bcc');
12431: }
1.286 raeburn 12432: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
12433: push(@{$changes{$type}},'include');
12434: }
1.134 raeburn 12435: }
1.28 raeburn 12436: }
1.286 raeburn 12437: if (ref($fields) eq 'ARRAY') {
12438: foreach my $field (@{$fields}) {
12439: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12440: push(@{$changes{'helpform'}},$field);
12441: }
12442: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12443: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12444: push(@{$changes{'helpform'}},'maxsize');
12445: }
12446: }
12447: }
1.289 raeburn 12448: }
1.28 raeburn 12449: }
1.203 raeburn 12450: foreach my $item (@toggles) {
12451: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
12452: $changes{$item} = 1;
12453: } elsif ((!$env{'form.'.$item}) &&
12454: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
12455: $changes{$item} = 1;
12456: }
12457: }
1.28 raeburn 12458: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
12459: $dom);
12460: if ($putresult eq 'ok') {
12461: if (keys(%changes) > 0) {
1.205 raeburn 12462: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12463: if (ref($lastactref) eq 'HASH') {
12464: $lastactref->{'domainconfig'} = 1;
12465: }
1.28 raeburn 12466: my ($titles,$short_titles) = &contact_titles();
12467: $resulttext = &mt('Changes made:').'<ul>';
12468: foreach my $item (@contacts) {
12469: if ($changes{$item}) {
12470: $resulttext .= '<li>'.$titles->{$item}.
12471: &mt(' set to: ').
12472: '<span class="LC_cusr_emph">'.
12473: $to{$item}.'</span></li>';
12474: }
12475: }
12476: foreach my $type (@mailings) {
12477: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 12478: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 12479: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 12480: } else {
12481: $resulttext .= '<li>'.$titles->{$type}.': ';
12482: }
1.28 raeburn 12483: my @text;
12484: foreach my $item (@{$newsetting{$type}}) {
12485: push(@text,$short_titles->{$item});
12486: }
12487: if ($others{$type} ne '') {
12488: push(@text,$others{$type});
12489: }
1.286 raeburn 12490: if (@text) {
12491: $resulttext .= '<span class="LC_cusr_emph">'.
12492: join(', ',@text).'</span>';
12493: }
12494: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12495: if ($bcc{$type} ne '') {
1.286 raeburn 12496: my $bcctext;
12497: if (@text) {
1.289 raeburn 12498: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 12499: } else {
12500: $bcctext = '(Bcc)';
12501: }
12502: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
12503: } elsif (!@text) {
12504: $resulttext .= &mt('No one');
12505: }
1.289 raeburn 12506: if ($includestr{$type} ne '') {
1.286 raeburn 12507: if ($includeloc{$type} eq 'b') {
12508: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
12509: } elsif ($includeloc{$type} eq 's') {
12510: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
12511: }
1.134 raeburn 12512: }
1.286 raeburn 12513: } elsif (!@text) {
12514: $resulttext .= &mt('No recipients');
1.134 raeburn 12515: }
12516: $resulttext .= '</li>';
1.28 raeburn 12517: }
12518: }
1.315 raeburn 12519: if (ref($changes{'overrides'}) eq 'ARRAY') {
12520: my @deletions;
12521: foreach my $type (@{$changes{'overrides'}}) {
12522: if ($usertypeshash{$type}) {
12523: if (grep(/^\Q$type\E/,@overrides)) {
12524: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
12525: $usertypeshash{$type}).'<ul><li>';
12526: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
12527: my @text;
12528: foreach my $item (@contacts) {
12529: if ($newsetting{'override_'.$type}{$item}) {
12530: push(@text,$short_titles->{$item});
12531: }
12532: }
12533: if ($newsetting{'override_'.$type}{'others'} ne '') {
12534: push(@text,$newsetting{'override_'.$type}{'others'});
12535: }
12536:
12537: if (@text) {
12538: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
12539: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
12540: }
12541: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
12542: my $bcctext;
12543: if (@text) {
12544: $bcctext = ' '.&mt('with Bcc to');
12545: } else {
12546: $bcctext = '(Bcc)';
12547: }
12548: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
12549: } elsif (!@text) {
12550: $resulttext .= &mt('Helpdesk e-mail sent to no one');
12551: }
12552: $resulttext .= '</li>';
12553: if ($newsetting{'override_'.$type}{'include'} ne '') {
12554: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
12555: if ($loc eq 'b') {
12556: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
12557: } elsif ($loc eq 's') {
12558: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
12559: }
12560: }
12561: }
12562: $resulttext .= '</li></ul></li>';
12563: } else {
12564: push(@deletions,$usertypeshash{$type});
12565: }
12566: }
12567: }
12568: if (@deletions) {
12569: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
12570: join(', ',@deletions)).'</li>';
12571: }
12572: }
1.203 raeburn 12573: my @offon = ('off','on');
12574: if ($changes{'reporterrors'}) {
12575: $resulttext .= '<li>'.
12576: &mt('E-mail error reports to [_1] set to "'.
12577: $offon[$env{'form.reporterrors'}].'".',
12578: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
12579: &mt('LON-CAPA core group - MSU'),600,500)).
12580: '</li>';
12581: }
12582: if ($changes{'reportupdates'}) {
12583: $resulttext .= '<li>'.
12584: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
12585: $offon[$env{'form.reportupdates'}].'".',
12586: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
12587: &mt('LON-CAPA core group - MSU'),600,500)).
12588: '</li>';
12589: }
1.286 raeburn 12590: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
12591: my (@optional,@required,@unused,$maxsizechg);
12592: foreach my $field (@{$changes{'helpform'}}) {
12593: if ($field eq 'maxsize') {
12594: $maxsizechg = 1;
12595: next;
12596: }
12597: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 12598: push(@optional,$field);
1.286 raeburn 12599: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
12600: push(@unused,$field);
12601: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 12602: push(@required,$field);
1.286 raeburn 12603: }
12604: }
12605: if (@optional) {
12606: $resulttext .= '<li>'.
12607: &mt('Help form fields changed to "Optional": [_1].',
12608: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
12609: '</li>';
12610: }
12611: if (@required) {
12612: $resulttext .= '<li>'.
12613: &mt('Help form fields changed to "Required": [_1].',
12614: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
12615: '</li>';
12616: }
12617: if (@unused) {
12618: $resulttext .= '<li>'.
12619: &mt('Help form fields changed to "Not shown": [_1].',
12620: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
12621: '</li>';
12622: }
12623: if ($maxsizechg) {
12624: $resulttext .= '<li>'.
12625: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
12626: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
12627: '</li>';
12628: }
12629: }
1.28 raeburn 12630: $resulttext .= '</ul>';
12631: } else {
1.288 raeburn 12632: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 12633: }
12634: } else {
12635: $resulttext = '<span class="LC_error">'.
12636: &mt('An error occurred: [_1].',$putresult).'</span>';
12637: }
12638: return $resulttext;
12639: }
12640:
12641: sub modify_usercreation {
1.27 raeburn 12642: my ($dom,%domconfig) = @_;
1.224 raeburn 12643: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 12644: my $warningmsg;
1.27 raeburn 12645: if (ref($domconfig{'usercreation'}) eq 'HASH') {
12646: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 12647: if ($key eq 'cancreate') {
12648: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
12649: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 12650: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
12651: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
12652: } else {
1.224 raeburn 12653: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
12654: }
12655: }
12656: }
12657: } elsif ($key eq 'email_rule') {
12658: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
12659: } else {
12660: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
12661: }
1.27 raeburn 12662: }
12663: }
12664: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 12665: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 12666: my @contexts = ('author','course','requestcrs');
1.34 raeburn 12667: foreach my $item(@contexts) {
1.224 raeburn 12668: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 12669: }
1.34 raeburn 12670: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
12671: foreach my $item (@contexts) {
1.224 raeburn 12672: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
12673: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 12674: }
1.27 raeburn 12675: }
1.34 raeburn 12676: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
12677: foreach my $item (@contexts) {
1.43 raeburn 12678: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 12679: if ($cancreate{$item} ne 'any') {
12680: push(@{$changes{'cancreate'}},$item);
12681: }
12682: } else {
12683: if ($cancreate{$item} ne 'none') {
12684: push(@{$changes{'cancreate'}},$item);
12685: }
1.27 raeburn 12686: }
12687: }
12688: } else {
1.43 raeburn 12689: foreach my $item (@contexts) {
1.34 raeburn 12690: push(@{$changes{'cancreate'}},$item);
12691: }
1.27 raeburn 12692: }
1.34 raeburn 12693:
1.27 raeburn 12694: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
12695: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
12696: if (!grep(/^\Q$type\E$/,@username_rule)) {
12697: push(@{$changes{'username_rule'}},$type);
12698: }
12699: }
12700: foreach my $type (@username_rule) {
12701: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
12702: push(@{$changes{'username_rule'}},$type);
12703: }
12704: }
12705: } else {
12706: push(@{$changes{'username_rule'}},@username_rule);
12707: }
12708:
1.32 raeburn 12709: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
12710: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
12711: if (!grep(/^\Q$type\E$/,@id_rule)) {
12712: push(@{$changes{'id_rule'}},$type);
12713: }
12714: }
12715: foreach my $type (@id_rule) {
12716: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
12717: push(@{$changes{'id_rule'}},$type);
12718: }
12719: }
12720: } else {
12721: push(@{$changes{'id_rule'}},@id_rule);
12722: }
12723:
1.43 raeburn 12724: my @authen_contexts = ('author','course','domain');
1.28 raeburn 12725: my @authtypes = ('int','krb4','krb5','loc');
12726: my %authhash;
1.43 raeburn 12727: foreach my $item (@authen_contexts) {
1.28 raeburn 12728: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
12729: foreach my $auth (@authtypes) {
12730: if (grep(/^\Q$auth\E$/,@authallowed)) {
12731: $authhash{$item}{$auth} = 1;
12732: } else {
12733: $authhash{$item}{$auth} = 0;
12734: }
12735: }
12736: }
12737: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 12738: foreach my $item (@authen_contexts) {
1.28 raeburn 12739: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
12740: foreach my $auth (@authtypes) {
12741: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
12742: push(@{$changes{'authtypes'}},$item);
12743: last;
12744: }
12745: }
12746: }
12747: }
12748: } else {
1.43 raeburn 12749: foreach my $item (@authen_contexts) {
1.28 raeburn 12750: push(@{$changes{'authtypes'}},$item);
12751: }
12752: }
12753:
1.224 raeburn 12754: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
12755: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
12756: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
12757: $save_usercreate{'id_rule'} = \@id_rule;
12758: $save_usercreate{'username_rule'} = \@username_rule,
12759: $save_usercreate{'authtypes'} = \%authhash;
12760:
1.27 raeburn 12761: my %usercreation_hash = (
1.224 raeburn 12762: usercreation => \%save_usercreate,
12763: );
1.27 raeburn 12764:
12765: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
12766: $dom);
1.50 raeburn 12767:
1.224 raeburn 12768: if ($putresult eq 'ok') {
12769: if (keys(%changes) > 0) {
12770: $resulttext = &mt('Changes made:').'<ul>';
12771: if (ref($changes{'cancreate'}) eq 'ARRAY') {
12772: my %lt = &usercreation_types();
12773: foreach my $type (@{$changes{'cancreate'}}) {
12774: my $chgtext = $lt{$type}.', ';
12775: if ($cancreate{$type} eq 'none') {
12776: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
12777: } elsif ($cancreate{$type} eq 'any') {
12778: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
12779: } elsif ($cancreate{$type} eq 'official') {
12780: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
12781: } elsif ($cancreate{$type} eq 'unofficial') {
12782: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
12783: }
12784: $resulttext .= '<li>'.$chgtext.'</li>';
12785: }
12786: }
12787: if (ref($changes{'username_rule'}) eq 'ARRAY') {
12788: my ($rules,$ruleorder) =
12789: &Apache::lonnet::inst_userrules($dom,'username');
12790: my $chgtext = '<ul>';
12791: foreach my $type (@username_rule) {
12792: if (ref($rules->{$type}) eq 'HASH') {
12793: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
12794: }
12795: }
12796: $chgtext .= '</ul>';
12797: if (@username_rule > 0) {
12798: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
12799: } else {
12800: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
12801: }
12802: }
12803: if (ref($changes{'id_rule'}) eq 'ARRAY') {
12804: my ($idrules,$idruleorder) =
12805: &Apache::lonnet::inst_userrules($dom,'id');
12806: my $chgtext = '<ul>';
12807: foreach my $type (@id_rule) {
12808: if (ref($idrules->{$type}) eq 'HASH') {
12809: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
12810: }
12811: }
12812: $chgtext .= '</ul>';
12813: if (@id_rule > 0) {
12814: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
12815: } else {
12816: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
12817: }
12818: }
12819: my %authname = &authtype_names();
12820: my %context_title = &context_names();
12821: if (ref($changes{'authtypes'}) eq 'ARRAY') {
12822: my $chgtext = '<ul>';
12823: foreach my $type (@{$changes{'authtypes'}}) {
12824: my @allowed;
12825: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
12826: foreach my $auth (@authtypes) {
12827: if ($authhash{$type}{$auth}) {
12828: push(@allowed,$authname{$auth});
12829: }
12830: }
12831: if (@allowed > 0) {
12832: $chgtext .= join(', ',@allowed).'</li>';
12833: } else {
12834: $chgtext .= &mt('none').'</li>';
12835: }
12836: }
12837: $chgtext .= '</ul>';
12838: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
12839: $resulttext .= '</li>';
12840: }
12841: $resulttext .= '</ul>';
12842: } else {
12843: $resulttext = &mt('No changes made to user creation settings');
12844: }
12845: } else {
12846: $resulttext = '<span class="LC_error">'.
12847: &mt('An error occurred: [_1]',$putresult).'</span>';
12848: }
12849: if ($warningmsg ne '') {
12850: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
12851: }
12852: return $resulttext;
12853: }
12854:
12855: sub modify_selfcreation {
1.305 raeburn 12856: my ($dom,$lastactref,%domconfig) = @_;
12857: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
12858: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
12859: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 12860: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
12861: if (ref($typesref) eq 'ARRAY') {
12862: @types = @{$typesref};
12863: }
12864: if (ref($usertypesref) eq 'HASH') {
12865: %usertypes = %{$usertypesref};
1.228 raeburn 12866: }
1.303 raeburn 12867: $usertypes{'default'} = $othertitle;
1.224 raeburn 12868: #
12869: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
12870: #
12871: if (ref($domconfig{'usercreation'}) eq 'HASH') {
12872: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
12873: if ($key eq 'cancreate') {
12874: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
12875: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
12876: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 12877: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
12878: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
12879: ($item eq 'emailusername') || ($item eq 'shibenv') ||
12880: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 12881: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 12882: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
12883: } else {
12884: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
12885: }
12886: }
12887: }
12888: } elsif ($key eq 'email_rule') {
12889: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
12890: } else {
12891: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
12892: }
12893: }
12894: }
12895: #
12896: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
12897: #
12898: if (ref($domconfig{'usermodification'}) eq 'HASH') {
12899: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
12900: if ($key eq 'selfcreate') {
12901: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
12902: } else {
12903: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
12904: }
12905: }
12906: }
1.305 raeburn 12907: #
12908: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
12909: #
12910: if (ref($domconfig{'inststatus'}) eq 'HASH') {
12911: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
12912: if ($key eq 'inststatusguest') {
12913: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
12914: } else {
12915: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
12916: }
12917: }
12918: }
1.224 raeburn 12919:
12920: my @contexts = ('selfcreate');
12921: @{$cancreate{'selfcreate'}} = ();
12922: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 12923: if (@types) {
12924: @{$cancreate{'statustocreate'}} = ();
12925: }
1.236 raeburn 12926: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 12927: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 12928: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 12929: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 12930: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 12931: my %selfcreatetypes = (
12932: sso => 'users authenticated by institutional single sign on',
12933: login => 'users authenticated by institutional log-in',
1.303 raeburn 12934: email => 'users verified by e-mail',
1.50 raeburn 12935: );
1.224 raeburn 12936: #
12937: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
12938: # is permitted.
12939: #
1.305 raeburn 12940: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 12941:
1.305 raeburn 12942: my (@statuses,%email_rule);
1.228 raeburn 12943: foreach my $item ('login','sso','email') {
1.224 raeburn 12944: if ($item eq 'email') {
1.236 raeburn 12945: if ($env{'form.cancreate_email'}) {
1.305 raeburn 12946: if (@types) {
12947: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
12948: foreach my $status (@poss_statuses) {
12949: if (grep(/^\Q$status\E$/,(@types,'default'))) {
12950: push(@statuses,$status);
12951: }
12952: }
12953: $save_inststatus{'inststatusguest'} = \@statuses;
12954: } else {
12955: push(@statuses,'default');
12956: }
12957: if (@statuses) {
12958: my %curr_rule;
12959: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
12960: foreach my $type (@statuses) {
12961: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 12962: }
1.305 raeburn 12963: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
12964: foreach my $type (@statuses) {
12965: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
12966: }
12967: }
12968: push(@{$cancreate{'selfcreate'}},'email');
12969: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
12970: my %curremaildom;
12971: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
12972: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
12973: }
12974: foreach my $type (@statuses) {
12975: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
12976: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
12977: }
12978: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
12979: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
12980: }
12981: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
12982: #
12983: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
12984: #
12985: my $chosen = $1;
12986: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
12987: my $emaildom;
12988: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
12989: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
12990: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
12991: if (ref($curremaildom{$type}) eq 'HASH') {
12992: if (exists($curremaildom{$type}{$chosen})) {
12993: if ($curremaildom{$type}{$chosen} ne $emaildom) {
12994: push(@{$changes{'cancreate'}},'emaildomain');
12995: }
12996: } elsif ($emaildom ne '') {
12997: push(@{$changes{'cancreate'}},'emaildomain');
12998: }
12999: } elsif ($emaildom ne '') {
13000: push(@{$changes{'cancreate'}},'emaildomain');
13001: }
13002: }
13003: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13004: } elsif ($chosen eq 'custom') {
13005: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
13006: $email_rule{$type} = [];
13007: if (ref($emailrules) eq 'HASH') {
13008: foreach my $rule (@possemail_rules) {
13009: if (exists($emailrules->{$rule})) {
13010: push(@{$email_rule{$type}},$rule);
13011: }
13012: }
13013: }
13014: if (@{$email_rule{$type}}) {
13015: $cancreate{'emailoptions'}{$type} = 'custom';
13016: if (ref($curr_rule{$type}) eq 'ARRAY') {
13017: if (@{$curr_rule{$type}} > 0) {
13018: foreach my $rule (@{$curr_rule{$type}}) {
13019: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
13020: push(@{$changes{'email_rule'}},$type);
13021: }
13022: }
13023: }
13024: foreach my $type (@{$email_rule{$type}}) {
13025: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
13026: push(@{$changes{'email_rule'}},$type);
13027: }
13028: }
13029: } else {
13030: push(@{$changes{'email_rule'}},$type);
13031: }
13032: }
13033: } else {
13034: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13035: }
13036: }
13037: }
13038: if (@types) {
13039: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13040: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
13041: if (@changed) {
13042: push(@{$changes{'inststatus'}},'inststatusguest');
13043: }
13044: } else {
13045: push(@{$changes{'inststatus'}},'inststatusguest');
13046: }
13047: }
13048: } else {
13049: delete($env{'form.cancreate_email'});
13050: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13051: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13052: push(@{$changes{'inststatus'}},'inststatusguest');
13053: }
13054: }
13055: }
13056: } else {
13057: $save_inststatus{'inststatusguest'} = [];
13058: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13059: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13060: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 13061: }
13062: }
1.224 raeburn 13063: }
13064: } else {
13065: if ($env{'form.cancreate_'.$item}) {
13066: push(@{$cancreate{'selfcreate'}},$item);
13067: }
13068: }
13069: }
1.305 raeburn 13070: my (%userinfo,%savecaptcha);
1.224 raeburn 13071: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
13072: #
1.228 raeburn 13073: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
13074: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 13075: #
1.236 raeburn 13076:
1.244 raeburn 13077: if ($env{'form.cancreate_email'}) {
1.228 raeburn 13078: push(@contexts,'emailusername');
1.305 raeburn 13079: if (@statuses) {
13080: foreach my $type (@statuses) {
1.228 raeburn 13081: if (ref($infofields) eq 'ARRAY') {
13082: foreach my $field (@{$infofields}) {
13083: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
13084: $cancreate{'emailusername'}{$type}{$field} = $1;
13085: }
13086: }
1.224 raeburn 13087: }
13088: }
13089: }
13090: #
13091: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 13092: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 13093: #
13094:
13095: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
13096: @approvalnotify = sort(@approvalnotify);
13097: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
13098: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13099: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
13100: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
13101: push(@{$changes{'cancreate'}},'notify');
13102: }
13103: } else {
13104: if ($cancreate{'notify'}{'approval'}) {
13105: push(@{$changes{'cancreate'}},'notify');
13106: }
13107: }
13108: } elsif ($cancreate{'notify'}{'approval'}) {
13109: push(@{$changes{'cancreate'}},'notify');
13110: }
13111:
13112: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
13113: }
13114: #
1.236 raeburn 13115: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 13116: # institutional log-in.
13117: #
13118: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
13119: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
13120: ($domdefaults{'auth_def'} eq 'localauth'))) {
13121: $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.').' '.
13122: &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.');
13123: }
13124: }
13125: my @fields = ('lastname','firstname','middlename','generation',
13126: 'permanentemail','id');
1.240 raeburn 13127: my @shibfields = (@fields,'inststatus');
1.224 raeburn 13128: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13129: #
13130: # Where usernames may created for institutional log-in and/or institutional single sign on:
13131: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
13132: # may self-create accounts
13133: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
13134: # which the user may supply, if institutional data is unavailable.
13135: #
13136: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 13137: if (@types) {
1.305 raeburn 13138: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
13139: push(@contexts,'statustocreate');
1.303 raeburn 13140: foreach my $type (@types) {
1.224 raeburn 13141: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
13142: foreach my $field (@fields) {
13143: if (grep(/^\Q$field\E$/,@modifiable)) {
13144: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
13145: } else {
13146: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
13147: }
13148: }
13149: }
13150: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 13151: foreach my $type (@types) {
1.224 raeburn 13152: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
13153: foreach my $field (@fields) {
13154: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
13155: $curr_usermodify{'selfcreate'}{$type}{$field}) {
13156: push(@{$changes{'selfcreate'}},$type);
13157: last;
13158: }
13159: }
13160: }
13161: }
13162: } else {
1.303 raeburn 13163: foreach my $type (@types) {
1.224 raeburn 13164: push(@{$changes{'selfcreate'}},$type);
13165: }
13166: }
13167: }
1.240 raeburn 13168: foreach my $field (@shibfields) {
13169: if ($env{'form.shibenv_'.$field} ne '') {
13170: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
13171: }
13172: }
13173: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13174: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
13175: foreach my $field (@shibfields) {
13176: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
13177: push(@{$changes{'cancreate'}},'shibenv');
13178: }
13179: }
13180: } else {
13181: foreach my $field (@shibfields) {
13182: if ($env{'form.shibenv_'.$field}) {
13183: push(@{$changes{'cancreate'}},'shibenv');
13184: last;
13185: }
13186: }
13187: }
13188: }
1.224 raeburn 13189: }
13190: foreach my $item (@contexts) {
13191: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
13192: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
13193: if (ref($cancreate{$item}) eq 'ARRAY') {
13194: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
13195: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13196: push(@{$changes{'cancreate'}},$item);
13197: }
13198: }
13199: }
13200: }
13201: if (ref($cancreate{$item}) eq 'ARRAY') {
13202: foreach my $type (@{$cancreate{$item}}) {
13203: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
13204: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13205: push(@{$changes{'cancreate'}},$item);
13206: }
13207: }
13208: }
13209: }
13210: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
13211: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 13212: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
13213: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13214: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
13215: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 13216: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13217: push(@{$changes{'cancreate'}},$item);
13218: }
13219: }
13220: }
1.305 raeburn 13221: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13222: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 13223: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13224: push(@{$changes{'cancreate'}},$item);
13225: }
1.224 raeburn 13226: }
13227: }
13228: }
1.305 raeburn 13229: foreach my $type (keys(%{$cancreate{$item}})) {
13230: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13231: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13232: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13233: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 13234: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13235: push(@{$changes{'cancreate'}},$item);
13236: }
13237: }
13238: } else {
13239: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13240: push(@{$changes{'cancreate'}},$item);
13241: }
13242: }
13243: }
1.305 raeburn 13244: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13245: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 13246: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13247: push(@{$changes{'cancreate'}},$item);
13248: }
1.224 raeburn 13249: }
13250: }
13251: }
13252: }
13253: } elsif ($curr_usercreation{'cancreate'}{$item}) {
13254: if (ref($cancreate{$item}) eq 'ARRAY') {
13255: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
13256: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13257: push(@{$changes{'cancreate'}},$item);
13258: }
13259: }
1.305 raeburn 13260: }
13261: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13262: if (ref($cancreate{$item}) eq 'HASH') {
13263: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13264: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 13265: }
13266: }
13267: } elsif ($item eq 'emailusername') {
1.228 raeburn 13268: if (ref($cancreate{$item}) eq 'HASH') {
13269: foreach my $type (keys(%{$cancreate{$item}})) {
13270: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13271: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13272: if ($cancreate{$item}{$type}{$field}) {
13273: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13274: push(@{$changes{'cancreate'}},$item);
13275: }
13276: last;
13277: }
13278: }
13279: }
13280: }
1.224 raeburn 13281: }
13282: }
13283: }
13284: #
13285: # Populate %save_usercreate hash with updates to self-creation configuration.
13286: #
13287: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
13288: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 13289: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 13290: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
13291: if (ref($cancreate{'notify'}) eq 'HASH') {
13292: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
13293: }
1.236 raeburn 13294: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
13295: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
13296: }
1.303 raeburn 13297: if (ref($cancreate{'emailverified'}) eq 'HASH') {
13298: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
13299: }
1.305 raeburn 13300: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
13301: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
13302: }
1.303 raeburn 13303: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
13304: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
13305: }
1.224 raeburn 13306: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13307: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
13308: }
1.240 raeburn 13309: if (ref($cancreate{'shibenv'}) eq 'HASH') {
13310: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
13311: }
1.224 raeburn 13312: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 13313: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 13314:
13315: my %userconfig_hash = (
13316: usercreation => \%save_usercreate,
13317: usermodification => \%save_usermodify,
1.305 raeburn 13318: inststatus => \%save_inststatus,
1.224 raeburn 13319: );
1.305 raeburn 13320:
1.224 raeburn 13321: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
13322: $dom);
13323: #
1.305 raeburn 13324: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 13325: #
1.27 raeburn 13326: if ($putresult eq 'ok') {
13327: if (keys(%changes) > 0) {
13328: $resulttext = &mt('Changes made:').'<ul>';
13329: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 13330: my %lt = &selfcreation_types();
1.34 raeburn 13331: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 13332: my $chgtext = '';
1.45 raeburn 13333: if ($type eq 'selfcreate') {
1.50 raeburn 13334: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 13335: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 13336: } else {
1.224 raeburn 13337: $chgtext .= &mt('Self-creation of a new account is permitted for:').
13338: '<ul>';
1.50 raeburn 13339: foreach my $case (@{$cancreate{$type}}) {
13340: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
13341: }
13342: $chgtext .= '</ul>';
1.100 raeburn 13343: if (ref($cancreate{$type}) eq 'ARRAY') {
13344: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
13345: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13346: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 13347: $chgtext .= '<span class="LC_warning">'.
13348: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
13349: '</span><br />';
13350: }
13351: }
13352: }
13353: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 13354: if (!@statuses) {
13355: $chgtext .= '<span class="LC_warning">'.
13356: &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.").
13357: '</span><br />';
1.303 raeburn 13358:
1.100 raeburn 13359: }
13360: }
13361: }
1.43 raeburn 13362: }
1.240 raeburn 13363: } elsif ($type eq 'shibenv') {
13364: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 13365: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 13366: } else {
13367: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
13368: '<ul>';
13369: foreach my $field (@shibfields) {
13370: next if ($cancreate{$type}{$field} eq '');
13371: if ($field eq 'inststatus') {
13372: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
13373: } else {
13374: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
13375: }
13376: }
13377: $chgtext .= '</ul>';
1.303 raeburn 13378: }
1.93 raeburn 13379: } elsif ($type eq 'statustocreate') {
1.96 raeburn 13380: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
13381: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
13382: if (@{$cancreate{'selfcreate'}} > 0) {
13383: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 13384: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 13385: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 13386: $chgtext .= '<br />'.
13387: '<span class="LC_warning">'.
13388: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
13389: '</span>';
13390: }
1.303 raeburn 13391: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 13392: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 13393: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
13394: } else {
13395: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
13396: }
13397: $chgtext .= '<ul>';
13398: foreach my $case (@{$cancreate{$type}}) {
13399: if ($case eq 'default') {
13400: $chgtext .= '<li>'.$othertitle.'</li>';
13401: } else {
1.303 raeburn 13402: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 13403: }
13404: }
1.100 raeburn 13405: $chgtext .= '</ul>';
13406: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 13407: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 13408: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
13409: '</span>';
1.100 raeburn 13410: }
13411: }
13412: } else {
13413: if (@{$cancreate{$type}} == 0) {
13414: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
13415: } else {
13416: $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 13417: }
13418: }
1.303 raeburn 13419: $chgtext .= '<br />';
1.93 raeburn 13420: }
1.236 raeburn 13421: } elsif ($type eq 'selfcreateprocessing') {
13422: my %choices = &Apache::lonlocal::texthash (
13423: automatic => 'Automatic approval',
13424: approval => 'Queued for approval',
13425: );
1.305 raeburn 13426: if (@types) {
13427: if (@statuses) {
1.303 raeburn 13428: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 13429: '<ul>';
1.305 raeburn 13430: foreach my $status (@statuses) {
13431: if ($status eq 'default') {
13432: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 13433: } else {
1.305 raeburn 13434: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 13435: }
13436: }
13437: $chgtext .= '</ul>';
13438: }
13439: } else {
13440: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
13441: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
13442: }
13443: } elsif ($type eq 'emailverified') {
13444: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 13445: all => 'Same as e-mail',
13446: first => 'Omit @domain',
13447: free => 'Free to choose',
1.303 raeburn 13448: );
1.305 raeburn 13449: if (@types) {
13450: if (@statuses) {
1.303 raeburn 13451: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
13452: '<ul>';
1.305 raeburn 13453: foreach my $status (@statuses) {
1.303 raeburn 13454: if ($type eq 'default') {
1.305 raeburn 13455: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 13456: } else {
1.305 raeburn 13457: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 13458: }
13459: }
13460: $chgtext .= '</ul>';
13461: }
13462: } else {
1.305 raeburn 13463: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 13464: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 13465: }
1.305 raeburn 13466: } elsif ($type eq 'emailoptions') {
13467: my %options = &Apache::lonlocal::texthash (
13468: any => 'Any e-mail',
13469: inst => 'Institutional only',
13470: noninst => 'Non-institutional only',
13471: custom => 'Custom restrictions',
13472: );
13473: if (@types) {
13474: if (@statuses) {
13475: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
13476: '<ul>';
13477: foreach my $status (@statuses) {
13478: if ($type eq 'default') {
13479: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
13480: } else {
13481: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 13482: }
13483: }
1.305 raeburn 13484: $chgtext .= '</ul>';
13485: }
13486: } else {
13487: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
13488: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
13489: } else {
13490: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
13491: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 13492: }
1.305 raeburn 13493: }
13494: } elsif ($type eq 'emaildomain') {
13495: my $output;
13496: if (@statuses) {
13497: foreach my $type (@statuses) {
13498: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
13499: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
13500: if ($type eq 'default') {
13501: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13502: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13503: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13504: } else {
13505: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
13506: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13507: }
1.303 raeburn 13508: } else {
1.305 raeburn 13509: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13510: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13511: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13512: } else {
13513: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
13514: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13515: }
1.303 raeburn 13516: }
1.305 raeburn 13517: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
13518: if ($type eq 'default') {
13519: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13520: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13521: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13522: } else {
13523: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
13524: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13525: }
1.303 raeburn 13526: } else {
1.305 raeburn 13527: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13528: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13529: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13530: } else {
13531: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
13532: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13533: }
1.303 raeburn 13534: }
13535: }
13536: }
13537: }
1.305 raeburn 13538: }
13539: if ($output ne '') {
13540: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
13541: '<ul>'.$output.'</ul>';
1.236 raeburn 13542: }
1.165 raeburn 13543: } elsif ($type eq 'captcha') {
1.224 raeburn 13544: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 13545: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
13546: } else {
13547: my %captchas = &captcha_phrases();
1.224 raeburn 13548: if ($captchas{$savecaptcha{$type}}) {
13549: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 13550: } else {
1.210 raeburn 13551: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 13552: }
13553: }
13554: } elsif ($type eq 'recaptchakeys') {
13555: my ($privkey,$pubkey);
1.224 raeburn 13556: if (ref($savecaptcha{$type}) eq 'HASH') {
13557: $pubkey = $savecaptcha{$type}{'public'};
13558: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 13559: }
13560: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
13561: if (!$pubkey) {
13562: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
13563: } else {
13564: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
13565: }
13566: if (!$privkey) {
13567: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
13568: } else {
13569: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
13570: }
13571: $chgtext .= '</ul>';
1.269 raeburn 13572: } elsif ($type eq 'recaptchaversion') {
13573: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 13574: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 13575: }
1.224 raeburn 13576: } elsif ($type eq 'emailusername') {
13577: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 13578: if (@statuses) {
13579: foreach my $type (@statuses) {
1.228 raeburn 13580: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
13581: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 13582: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 13583: '<ul>';
13584: foreach my $field (@{$infofields}) {
13585: if ($cancreate{'emailusername'}{$type}{$field}) {
13586: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
13587: }
13588: }
1.245 raeburn 13589: $chgtext .= '</ul>';
13590: } else {
1.303 raeburn 13591: $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 13592: }
13593: } else {
1.303 raeburn 13594: $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 13595: }
13596: }
13597: }
13598: }
13599: } elsif ($type eq 'notify') {
1.303 raeburn 13600: my $numapprove = 0;
1.224 raeburn 13601: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13602: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
13603: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 13604: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
13605: $numapprove ++;
1.224 raeburn 13606: }
13607: }
1.43 raeburn 13608: }
1.303 raeburn 13609: unless ($numapprove) {
13610: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
13611: }
1.34 raeburn 13612: }
1.224 raeburn 13613: if ($chgtext) {
13614: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 13615: }
13616: }
13617: }
1.305 raeburn 13618: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 13619: my ($emailrules,$emailruleorder) =
13620: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 13621: foreach my $type (@{$changes{'email_rule'}}) {
13622: if (ref($email_rule{$type}) eq 'ARRAY') {
13623: my $chgtext = '<ul>';
13624: foreach my $rule (@{$email_rule{$type}}) {
13625: if (ref($emailrules->{$rule}) eq 'HASH') {
13626: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
13627: }
13628: }
13629: $chgtext .= '</ul>';
1.310 raeburn 13630: my $typename;
1.305 raeburn 13631: if (@types) {
13632: if ($type eq 'default') {
13633: $typename = $othertitle;
13634: } else {
13635: $typename = $usertypes{$type};
13636: }
13637: $chgtext .= &mt('(Affiliation: [_1])',$typename);
13638: }
13639: if (@{$email_rule{$type}} > 0) {
13640: $resulttext .= '<li>'.
13641: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
13642: $usertypes{$type}).
13643: $chgtext.
13644: '</li>';
13645: } else {
13646: $resulttext .= '<li>'.
1.310 raeburn 13647: &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 13648: '</li>'.
1.310 raeburn 13649: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 13650: }
1.43 raeburn 13651: }
13652: }
1.305 raeburn 13653: }
13654: if (ref($changes{'inststatus'}) eq 'ARRAY') {
13655: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
13656: if (@{$save_inststatus{'inststatusguest'}} > 0) {
13657: my $chgtext = '<ul>';
13658: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
13659: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
13660: }
13661: $chgtext .= '</ul>';
13662: $resulttext .= '<li>'.
13663: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
13664: $chgtext.
13665: '</li>';
13666: } else {
13667: $resulttext .= '<li>'.
13668: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
13669: '</li>';
13670: }
1.43 raeburn 13671: }
13672: }
1.224 raeburn 13673: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
13674: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
13675: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13676: foreach my $type (@{$changes{'selfcreate'}}) {
13677: my $typename = $type;
1.303 raeburn 13678: if (keys(%usertypes) > 0) {
13679: if ($usertypes{$type} ne '') {
13680: $typename = $usertypes{$type};
1.224 raeburn 13681: }
13682: }
13683: my @modifiable;
13684: $resulttext .= '<li>'.
13685: &mt('Self-creation of account by users with status: [_1]',
13686: '<span class="LC_cusr_emph">'.$typename.'</span>').
13687: ' - '.&mt('modifiable fields (if institutional data blank): ');
13688: foreach my $field (@fields) {
13689: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
13690: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 13691: }
13692: }
1.224 raeburn 13693: if (@modifiable > 0) {
13694: $resulttext .= join(', ',@modifiable);
1.43 raeburn 13695: } else {
1.224 raeburn 13696: $resulttext .= &mt('none');
1.43 raeburn 13697: }
1.224 raeburn 13698: $resulttext .= '</li>';
1.28 raeburn 13699: }
1.224 raeburn 13700: $resulttext .= '</ul></li>';
1.28 raeburn 13701: }
1.27 raeburn 13702: $resulttext .= '</ul>';
1.305 raeburn 13703: my $cachetime = 24*60*60;
13704: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
13705: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13706: if (ref($lastactref) eq 'HASH') {
13707: $lastactref->{'domdefaults'} = 1;
13708: }
1.27 raeburn 13709: } else {
1.224 raeburn 13710: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 13711: }
13712: } else {
13713: $resulttext = '<span class="LC_error">'.
1.23 raeburn 13714: &mt('An error occurred: [_1]',$putresult).'</span>';
13715: }
1.43 raeburn 13716: if ($warningmsg ne '') {
13717: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
13718: }
1.23 raeburn 13719: return $resulttext;
13720: }
13721:
1.165 raeburn 13722: sub process_captcha {
13723: my ($container,$changes,$newsettings,$current) = @_;
13724: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
13725: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
13726: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
13727: $newsettings->{'captcha'} = 'original';
13728: }
13729: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 13730: if ($container eq 'cancreate') {
1.169 raeburn 13731: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
13732: push(@{$changes->{'cancreate'}},'captcha');
13733: } elsif (!defined($changes->{'cancreate'})) {
13734: $changes->{'cancreate'} = ['captcha'];
13735: }
13736: } else {
13737: $changes->{'captcha'} = 1;
1.165 raeburn 13738: }
13739: }
1.269 raeburn 13740: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 13741: if ($newsettings->{'captcha'} eq 'recaptcha') {
13742: $newpub = $env{'form.'.$container.'_recaptchapub'};
13743: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 13744: $newpub =~ s/[^\w\-]//g;
13745: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 13746: $newsettings->{'recaptchakeys'} = {
13747: public => $newpub,
13748: private => $newpriv,
13749: };
1.269 raeburn 13750: $newversion = $env{'form.'.$container.'_recaptchaversion'};
13751: $newversion =~ s/\D//g;
13752: if ($newversion ne '2') {
13753: $newversion = 1;
13754: }
13755: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 13756: }
13757: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
13758: $currpub = $current->{'recaptchakeys'}{'public'};
13759: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 13760: unless ($newsettings->{'captcha'} eq 'recaptcha') {
13761: $newsettings->{'recaptchakeys'} = {
13762: public => '',
13763: private => '',
13764: }
13765: }
1.165 raeburn 13766: }
1.269 raeburn 13767: if ($current->{'captcha'} eq 'recaptcha') {
13768: $currversion = $current->{'recaptchaversion'};
13769: if ($currversion ne '2') {
13770: $currversion = 1;
13771: }
13772: }
13773: if ($currversion ne $newversion) {
13774: if ($container eq 'cancreate') {
13775: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
13776: push(@{$changes->{'cancreate'}},'recaptchaversion');
13777: } elsif (!defined($changes->{'cancreate'})) {
13778: $changes->{'cancreate'} = ['recaptchaversion'];
13779: }
13780: } else {
13781: $changes->{'recaptchaversion'} = 1;
13782: }
13783: }
1.165 raeburn 13784: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 13785: if ($container eq 'cancreate') {
13786: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
13787: push(@{$changes->{'cancreate'}},'recaptchakeys');
13788: } elsif (!defined($changes->{'cancreate'})) {
13789: $changes->{'cancreate'} = ['recaptchakeys'];
13790: }
13791: } else {
1.210 raeburn 13792: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 13793: }
13794: }
13795: return;
13796: }
13797:
1.33 raeburn 13798: sub modify_usermodification {
13799: my ($dom,%domconfig) = @_;
1.224 raeburn 13800: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 13801: if (ref($domconfig{'usermodification'}) eq 'HASH') {
13802: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 13803: if ($key eq 'selfcreate') {
13804: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
13805: } else {
13806: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
13807: }
1.33 raeburn 13808: }
13809: }
1.224 raeburn 13810: my @contexts = ('author','course');
1.33 raeburn 13811: my %context_title = (
13812: author => 'In author context',
13813: course => 'In course context',
13814: );
13815: my @fields = ('lastname','firstname','middlename','generation',
13816: 'permanentemail','id');
13817: my %roles = (
13818: author => ['ca','aa'],
13819: course => ['st','ep','ta','in','cr'],
13820: );
13821: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13822: foreach my $context (@contexts) {
13823: foreach my $role (@{$roles{$context}}) {
13824: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
13825: foreach my $item (@fields) {
13826: if (grep(/^\Q$item\E$/,@modifiable)) {
13827: $modifyhash{$context}{$role}{$item} = 1;
13828: } else {
13829: $modifyhash{$context}{$role}{$item} = 0;
13830: }
13831: }
13832: }
13833: if (ref($curr_usermodification{$context}) eq 'HASH') {
13834: foreach my $role (@{$roles{$context}}) {
13835: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
13836: foreach my $field (@fields) {
13837: if ($modifyhash{$context}{$role}{$field} ne
13838: $curr_usermodification{$context}{$role}{$field}) {
13839: push(@{$changes{$context}},$role);
13840: last;
13841: }
13842: }
13843: }
13844: }
13845: } else {
13846: foreach my $context (@contexts) {
13847: foreach my $role (@{$roles{$context}}) {
13848: push(@{$changes{$context}},$role);
13849: }
13850: }
13851: }
13852: }
13853: my %usermodification_hash = (
13854: usermodification => \%modifyhash,
13855: );
13856: my $putresult = &Apache::lonnet::put_dom('configuration',
13857: \%usermodification_hash,$dom);
13858: if ($putresult eq 'ok') {
13859: if (keys(%changes) > 0) {
13860: $resulttext = &mt('Changes made: ').'<ul>';
13861: foreach my $context (@contexts) {
13862: if (ref($changes{$context}) eq 'ARRAY') {
13863: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
13864: if (ref($changes{$context}) eq 'ARRAY') {
13865: foreach my $role (@{$changes{$context}}) {
13866: my $rolename;
1.224 raeburn 13867: if ($role eq 'cr') {
13868: $rolename = &mt('Custom');
1.33 raeburn 13869: } else {
1.224 raeburn 13870: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 13871: }
13872: my @modifiable;
1.224 raeburn 13873: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 13874: foreach my $field (@fields) {
13875: if ($modifyhash{$context}{$role}{$field}) {
13876: push(@modifiable,$fieldtitles{$field});
13877: }
13878: }
13879: if (@modifiable > 0) {
13880: $resulttext .= join(', ',@modifiable);
13881: } else {
13882: $resulttext .= &mt('none');
13883: }
13884: $resulttext .= '</li>';
13885: }
13886: $resulttext .= '</ul></li>';
13887: }
13888: }
13889: }
13890: $resulttext .= '</ul>';
13891: } else {
13892: $resulttext = &mt('No changes made to user modification settings');
13893: }
13894: } else {
13895: $resulttext = '<span class="LC_error">'.
13896: &mt('An error occurred: [_1]',$putresult).'</span>';
13897: }
13898: return $resulttext;
13899: }
13900:
1.43 raeburn 13901: sub modify_defaults {
1.212 raeburn 13902: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 13903: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 13904: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 13905: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
13906: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.43 raeburn 13907: my @authtypes = ('internal','krb4','krb5','localauth');
13908: foreach my $item (@items) {
13909: $newvalues{$item} = $env{'form.'.$item};
13910: if ($item eq 'auth_def') {
13911: if ($newvalues{$item} ne '') {
13912: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
13913: push(@errors,$item);
13914: }
13915: }
13916: } elsif ($item eq 'lang_def') {
13917: if ($newvalues{$item} ne '') {
13918: if ($newvalues{$item} =~ /^(\w+)/) {
13919: my $langcode = $1;
1.103 raeburn 13920: if ($langcode ne 'x_chef') {
13921: if (code2language($langcode) eq '') {
13922: push(@errors,$item);
13923: }
1.43 raeburn 13924: }
13925: } else {
13926: push(@errors,$item);
13927: }
13928: }
1.54 raeburn 13929: } elsif ($item eq 'timezone_def') {
13930: if ($newvalues{$item} ne '') {
1.62 raeburn 13931: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 13932: push(@errors,$item);
13933: }
13934: }
1.68 raeburn 13935: } elsif ($item eq 'datelocale_def') {
13936: if ($newvalues{$item} ne '') {
13937: my @datelocale_ids = DateTime::Locale->ids();
13938: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
13939: push(@errors,$item);
13940: }
13941: }
1.141 raeburn 13942: } elsif ($item eq 'portal_def') {
13943: if ($newvalues{$item} ne '') {
13944: 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])\/?$/) {
13945: push(@errors,$item);
13946: }
13947: }
1.294 raeburn 13948: } elsif ($item eq 'intauth_cost') {
13949: if ($newvalues{$item} ne '') {
13950: if ($newvalues{$item} =~ /\D/) {
13951: push(@errors,$item);
13952: }
13953: }
13954: } elsif ($item eq 'intauth_check') {
13955: if ($newvalues{$item} ne '') {
13956: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
13957: push(@errors,$item);
13958: }
13959: }
13960: } elsif ($item eq 'intauth_switch') {
13961: if ($newvalues{$item} ne '') {
13962: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
13963: push(@errors,$item);
13964: }
13965: }
1.43 raeburn 13966: }
13967: if (grep(/^\Q$item\E$/,@errors)) {
13968: $newvalues{$item} = $domdefaults{$item};
13969: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
13970: $changes{$item} = 1;
13971: }
1.72 raeburn 13972: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 13973: }
13974: my %defaults_hash = (
1.72 raeburn 13975: defaults => \%newvalues,
13976: );
1.43 raeburn 13977: my $title = &defaults_titles();
1.236 raeburn 13978:
13979: my $currinststatus;
13980: if (ref($domconfig{'inststatus'}) eq 'HASH') {
13981: $currinststatus = $domconfig{'inststatus'};
13982: } else {
13983: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13984: $currinststatus = {
13985: inststatustypes => $usertypes,
13986: inststatusorder => $types,
13987: inststatusguest => [],
13988: };
13989: }
13990: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
13991: my @allpos;
13992: my %alltypes;
1.305 raeburn 13993: my @inststatusguest;
13994: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
13995: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
13996: unless (grep(/^\Q$type\E$/,@todelete)) {
13997: push(@inststatusguest,$type);
13998: }
13999: }
14000: }
14001: my ($currtitles,$currorder);
1.236 raeburn 14002: if (ref($currinststatus) eq 'HASH') {
14003: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
14004: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
14005: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
14006: if ($currinststatus->{inststatustypes}->{$type} ne '') {
14007: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
14008: }
14009: }
14010: unless (grep(/^\Q$type\E$/,@todelete)) {
14011: my $position = $env{'form.inststatus_pos_'.$type};
14012: $position =~ s/\D+//g;
14013: $allpos[$position] = $type;
14014: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
14015: $alltypes{$type} =~ s/`//g;
14016: }
14017: }
14018: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
14019: $currtitles =~ s/,$//;
14020: }
14021: }
14022: if ($env{'form.addinststatus'}) {
14023: my $newtype = $env{'form.addinststatus'};
14024: $newtype =~ s/\W//g;
14025: unless (exists($alltypes{$newtype})) {
14026: $alltypes{$newtype} = $env{'form.addinststatus_title'};
14027: $alltypes{$newtype} =~ s/`//g;
14028: my $position = $env{'form.addinststatus_pos'};
14029: $position =~ s/\D+//g;
14030: if ($position ne '') {
14031: $allpos[$position] = $newtype;
14032: }
14033: }
14034: }
1.305 raeburn 14035: my @orderedstatus;
1.236 raeburn 14036: foreach my $type (@allpos) {
14037: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
14038: push(@orderedstatus,$type);
14039: }
14040: }
14041: foreach my $type (keys(%alltypes)) {
14042: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
14043: delete($alltypes{$type});
14044: }
14045: }
14046: $defaults_hash{'inststatus'} = {
14047: inststatustypes => \%alltypes,
14048: inststatusorder => \@orderedstatus,
1.305 raeburn 14049: inststatusguest => \@inststatusguest,
1.236 raeburn 14050: };
14051: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
14052: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
14053: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
14054: }
14055: }
14056: if ($currorder ne join(',',@orderedstatus)) {
14057: $changes{'inststatus'}{'inststatusorder'} = 1;
14058: }
14059: my $newtitles;
14060: foreach my $item (@orderedstatus) {
14061: $newtitles .= $alltypes{$item}.',';
14062: }
14063: $newtitles =~ s/,$//;
14064: if ($currtitles ne $newtitles) {
14065: $changes{'inststatus'}{'inststatustypes'} = 1;
14066: }
1.43 raeburn 14067: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
14068: $dom);
14069: if ($putresult eq 'ok') {
14070: if (keys(%changes) > 0) {
14071: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 14072: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 14073: 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";
14074: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 14075: if ($item eq 'inststatus') {
14076: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 14077: if (@orderedstatus) {
1.236 raeburn 14078: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
14079: foreach my $type (@orderedstatus) {
14080: $resulttext .= $alltypes{$type}.', ';
14081: }
14082: $resulttext =~ s/, $//;
14083: $resulttext .= '</li>';
1.305 raeburn 14084: } else {
14085: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 14086: }
14087: }
14088: } else {
14089: my $value = $env{'form.'.$item};
14090: if ($value eq '') {
14091: $value = &mt('none');
14092: } elsif ($item eq 'auth_def') {
14093: my %authnames = &authtype_names();
14094: my %shortauth = (
14095: internal => 'int',
14096: krb4 => 'krb4',
14097: krb5 => 'krb5',
14098: localauth => 'loc',
14099: );
14100: $value = $authnames{$shortauth{$value}};
1.294 raeburn 14101: } elsif ($item eq 'intauth_switch') {
14102: my %optiondesc = &Apache::lonlocal::texthash (
14103: 0 => 'No',
14104: 1 => 'Yes',
14105: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
14106: );
14107: if ($value =~ /^(0|1|2)$/) {
14108: $value = $optiondesc{$value};
14109: } else {
14110: $value = &mt('none -- defaults to No');
14111: }
14112: } elsif ($item eq 'intauth_check') {
14113: my %optiondesc = &Apache::lonlocal::texthash (
14114: 0 => 'No',
14115: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
14116: 2 => 'Yes, disallow login if stored cost is less than domain default',
14117: );
14118: if ($value =~ /^(0|1|2)$/) {
14119: $value = $optiondesc{$value};
14120: } else {
14121: $value = &mt('none -- defaults to No');
14122: }
1.236 raeburn 14123: }
14124: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
14125: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 14126: }
14127: }
14128: $resulttext .= '</ul>';
14129: $mailmsgtext .= "\n";
14130: my $cachetime = 24*60*60;
1.72 raeburn 14131: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14132: if (ref($lastactref) eq 'HASH') {
14133: $lastactref->{'domdefaults'} = 1;
14134: }
1.68 raeburn 14135: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 14136: my $notify = 1;
14137: if (ref($domconfig{'contacts'}) eq 'HASH') {
14138: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
14139: $notify = 0;
14140: }
14141: }
14142: if ($notify) {
14143: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
14144: "LON-CAPA Domain Settings Change - $dom",
14145: $mailmsgtext);
14146: }
1.54 raeburn 14147: }
1.43 raeburn 14148: } else {
1.54 raeburn 14149: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 14150: }
14151: } else {
14152: $resulttext = '<span class="LC_error">'.
14153: &mt('An error occurred: [_1]',$putresult).'</span>';
14154: }
14155: if (@errors > 0) {
14156: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
14157: foreach my $item (@errors) {
14158: $resulttext .= ' "'.$title->{$item}.'",';
14159: }
14160: $resulttext =~ s/,$//;
14161: }
14162: return $resulttext;
14163: }
14164:
1.46 raeburn 14165: sub modify_scantron {
1.205 raeburn 14166: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 14167: my ($resulttext,%confhash,%changes,$errors);
14168: my $custom = 'custom.tab';
14169: my $default = 'default.tab';
14170: my $servadm = $r->dir_config('lonAdmEMail');
14171: my ($configuserok,$author_ok,$switchserver) =
14172: &config_check($dom,$confname,$servadm);
14173: if ($env{'form.scantronformat.filename'} ne '') {
14174: my $error;
14175: if ($configuserok eq 'ok') {
14176: if ($switchserver) {
1.130 raeburn 14177: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 14178: } else {
14179: if ($author_ok eq 'ok') {
14180: my ($result,$scantronurl) =
14181: &publishlogo($r,'upload','scantronformat',$dom,
14182: $confname,'scantron','','',$custom);
14183: if ($result eq 'ok') {
14184: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 14185: $changes{'scantronformat'} = 1;
1.46 raeburn 14186: } else {
14187: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
14188: }
14189: } else {
14190: $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);
14191: }
14192: }
14193: } else {
14194: $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);
14195: }
14196: if ($error) {
14197: &Apache::lonnet::logthis($error);
14198: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14199: }
14200: }
1.48 raeburn 14201: if (ref($domconfig{'scantron'}) eq 'HASH') {
14202: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
14203: if ($env{'form.scantronformat_del'}) {
14204: $confhash{'scantron'}{'scantronformat'} = '';
14205: $changes{'scantronformat'} = 1;
1.46 raeburn 14206: }
14207: }
14208: }
14209: if (keys(%confhash) > 0) {
14210: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
14211: $dom);
14212: if ($putresult eq 'ok') {
14213: if (keys(%changes) > 0) {
1.48 raeburn 14214: if (ref($confhash{'scantron'}) eq 'HASH') {
14215: $resulttext = &mt('Changes made:').'<ul>';
14216: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 14217: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 14218: } else {
1.130 raeburn 14219: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 14220: }
1.48 raeburn 14221: $resulttext .= '</ul>';
14222: } else {
1.130 raeburn 14223: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 14224: }
14225: $resulttext .= '</ul>';
14226: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 14227: if (ref($lastactref) eq 'HASH') {
14228: $lastactref->{'domainconfig'} = 1;
14229: }
1.46 raeburn 14230: } else {
1.130 raeburn 14231: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 14232: }
14233: } else {
14234: $resulttext = '<span class="LC_error">'.
14235: &mt('An error occurred: [_1]',$putresult).'</span>';
14236: }
14237: } else {
1.130 raeburn 14238: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 14239: }
14240: if ($errors) {
14241: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14242: $errors.'</ul>';
14243: }
14244: return $resulttext;
14245: }
14246:
1.48 raeburn 14247: sub modify_coursecategories {
1.239 raeburn 14248: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 14249: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
14250: $cathash);
1.48 raeburn 14251: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 14252: my @catitems = ('unauth','auth');
14253: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 14254: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 14255: $cathash = $domconfig{'coursecategories'}{'cats'};
14256: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
14257: $changes{'togglecats'} = 1;
14258: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
14259: }
14260: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
14261: $changes{'categorize'} = 1;
14262: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
14263: }
1.120 raeburn 14264: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
14265: $changes{'togglecatscomm'} = 1;
14266: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
14267: }
14268: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
14269: $changes{'categorizecomm'} = 1;
14270: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 14271:
14272: }
14273: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
14274: $changes{'togglecatsplace'} = 1;
14275: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
14276: }
14277: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
14278: $changes{'categorizeplace'} = 1;
14279: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 14280: }
1.238 raeburn 14281: foreach my $item (@catitems) {
14282: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14283: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
14284: $changes{$item} = 1;
14285: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14286: }
14287: }
14288: }
1.57 raeburn 14289: } else {
14290: $changes{'togglecats'} = 1;
14291: $changes{'categorize'} = 1;
1.124 raeburn 14292: $changes{'togglecatscomm'} = 1;
14293: $changes{'categorizecomm'} = 1;
1.272 raeburn 14294: $changes{'togglecatsplace'} = 1;
14295: $changes{'categorizeplace'} = 1;
1.87 raeburn 14296: $domconfig{'coursecategories'} = {
14297: togglecats => $env{'form.togglecats'},
14298: categorize => $env{'form.categorize'},
1.124 raeburn 14299: togglecatscomm => $env{'form.togglecatscomm'},
14300: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 14301: togglecatsplace => $env{'form.togglecatsplace'},
14302: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 14303: };
1.238 raeburn 14304: foreach my $item (@catitems) {
14305: if ($env{'form.coursecat_'.$item} ne 'std') {
14306: $changes{$item} = 1;
14307: }
14308: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14309: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14310: }
14311: }
1.57 raeburn 14312: }
14313: if (ref($cathash) eq 'HASH') {
14314: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 14315: push (@deletecategory,'instcode::0');
14316: }
1.120 raeburn 14317: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
14318: push(@deletecategory,'communities::0');
14319: }
1.272 raeburn 14320: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
14321: push(@deletecategory,'placement::0');
14322: }
1.48 raeburn 14323: }
1.57 raeburn 14324: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
14325: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14326: if (@deletecategory > 0) {
14327: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 14328: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 14329: foreach my $item (@deletecategory) {
1.57 raeburn 14330: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
14331: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 14332: $deletions{$item} = 1;
1.57 raeburn 14333: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 14334: }
14335: }
14336: }
1.57 raeburn 14337: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 14338: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 14339: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 14340: $reorderings{$item} = 1;
1.57 raeburn 14341: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 14342: }
14343: if ($env{'form.addcategory_name_'.$item} ne '') {
14344: my $newcat = $env{'form.addcategory_name_'.$item};
14345: my $newdepth = $depth+1;
14346: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14347: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 14348: $adds{$newitem} = 1;
14349: }
14350: if ($env{'form.subcat_'.$item} ne '') {
14351: my $newcat = $env{'form.subcat_'.$item};
14352: my $newdepth = $depth+1;
14353: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14354: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 14355: $adds{$newitem} = 1;
14356: }
14357: }
14358: }
14359: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 14360: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14361: my $newitem = 'instcode::0';
1.57 raeburn 14362: if ($cathash->{$newitem} eq '') {
14363: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14364: $adds{$newitem} = 1;
14365: }
14366: } else {
14367: my $newitem = 'instcode::0';
1.57 raeburn 14368: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14369: $adds{$newitem} = 1;
14370: }
14371: }
1.120 raeburn 14372: if ($env{'form.communities'} eq '1') {
14373: if (ref($cathash) eq 'HASH') {
14374: my $newitem = 'communities::0';
14375: if ($cathash->{$newitem} eq '') {
14376: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14377: $adds{$newitem} = 1;
14378: }
14379: } else {
14380: my $newitem = 'communities::0';
14381: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14382: $adds{$newitem} = 1;
14383: }
14384: }
1.272 raeburn 14385: if ($env{'form.placement'} eq '1') {
14386: if (ref($cathash) eq 'HASH') {
14387: my $newitem = 'placement::0';
14388: if ($cathash->{$newitem} eq '') {
14389: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
14390: $adds{$newitem} = 1;
14391: }
14392: } else {
14393: my $newitem = 'placement::0';
14394: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
14395: $adds{$newitem} = 1;
14396: }
14397: }
1.48 raeburn 14398: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 14399: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 14400: ($env{'form.addcategory_name'} ne 'communities') &&
14401: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 14402: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
14403: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
14404: $adds{$newitem} = 1;
14405: }
1.48 raeburn 14406: }
1.57 raeburn 14407: my $putresult;
1.48 raeburn 14408: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14409: if (keys(%deletions) > 0) {
14410: foreach my $key (keys(%deletions)) {
14411: if ($predelallitems{$key} ne '') {
14412: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
14413: }
14414: }
14415: }
14416: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 14417: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 14418: if (ref($chkcats[0]) eq 'ARRAY') {
14419: my $depth = 0;
14420: my $chg = 0;
14421: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
14422: my $name = $chkcats[0][$i];
14423: my $item;
14424: if ($name eq '') {
14425: $chg ++;
14426: } else {
14427: $item = &escape($name).'::0';
14428: if ($chg) {
1.57 raeburn 14429: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 14430: }
14431: $depth ++;
1.57 raeburn 14432: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 14433: $depth --;
14434: }
14435: }
14436: }
1.57 raeburn 14437: }
14438: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14439: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 14440: if ($putresult eq 'ok') {
1.57 raeburn 14441: my %title = (
1.120 raeburn 14442: togglecats => 'Show/Hide a course in catalog',
14443: categorize => 'Assign a category to a course',
14444: togglecatscomm => 'Show/Hide a community in catalog',
14445: categorizecomm => 'Assign a category to a community',
1.57 raeburn 14446: );
14447: my %level = (
1.120 raeburn 14448: dom => 'set in Domain ("Modify Course/Community")',
14449: crs => 'set in Course ("Course Configuration")',
14450: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 14451: none => 'No catalog',
14452: std => 'Standard catalog',
14453: domonly => 'Domain-only catalog',
14454: codesrch => 'Code search form',
1.57 raeburn 14455: );
1.48 raeburn 14456: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 14457: if ($changes{'togglecats'}) {
14458: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
14459: }
14460: if ($changes{'categorize'}) {
14461: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 14462: }
1.120 raeburn 14463: if ($changes{'togglecatscomm'}) {
14464: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
14465: }
14466: if ($changes{'categorizecomm'}) {
14467: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
14468: }
1.238 raeburn 14469: if ($changes{'unauth'}) {
14470: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
14471: }
14472: if ($changes{'auth'}) {
14473: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
14474: }
1.57 raeburn 14475: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14476: my $cathash;
14477: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
14478: $cathash = $domconfig{'coursecategories'}{'cats'};
14479: } else {
14480: $cathash = {};
14481: }
14482: my (@cats,@trails,%allitems);
14483: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
14484: if (keys(%deletions) > 0) {
14485: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
14486: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
14487: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
14488: }
14489: $resulttext .= '</ul></li>';
14490: }
14491: if (keys(%reorderings) > 0) {
14492: my %sort_by_trail;
14493: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
14494: foreach my $key (keys(%reorderings)) {
14495: if ($allitems{$key} ne '') {
14496: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
14497: }
1.48 raeburn 14498: }
1.57 raeburn 14499: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
14500: $resulttext .= '<li>'.$trails[$trail].'</li>';
14501: }
14502: $resulttext .= '</ul></li>';
1.48 raeburn 14503: }
1.57 raeburn 14504: if (keys(%adds) > 0) {
14505: my %sort_by_trail;
14506: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
14507: foreach my $key (keys(%adds)) {
14508: if ($allitems{$key} ne '') {
14509: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
14510: }
14511: }
14512: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
14513: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 14514: }
1.57 raeburn 14515: $resulttext .= '</ul></li>';
1.48 raeburn 14516: }
14517: }
14518: $resulttext .= '</ul>';
1.239 raeburn 14519: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 14520: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
14521: if ($changes{'auth'}) {
14522: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
14523: }
14524: if ($changes{'unauth'}) {
14525: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
14526: }
14527: my $cachetime = 24*60*60;
14528: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 14529: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 14530: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 14531: }
14532: }
1.48 raeburn 14533: } else {
14534: $resulttext = '<span class="LC_error">'.
1.57 raeburn 14535: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 14536: }
14537: } else {
1.120 raeburn 14538: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 14539: }
14540: return $resulttext;
14541: }
14542:
1.69 raeburn 14543: sub modify_serverstatuses {
14544: my ($dom,%domconfig) = @_;
14545: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
14546: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
14547: %currserverstatus = %{$domconfig{'serverstatuses'}};
14548: }
14549: my @pages = &serverstatus_pages();
14550: foreach my $type (@pages) {
14551: $newserverstatus{$type}{'namedusers'} = '';
14552: $newserverstatus{$type}{'machines'} = '';
14553: if (defined($env{'form.'.$type.'_namedusers'})) {
14554: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
14555: my @okusers;
14556: foreach my $user (@users) {
14557: my ($uname,$udom) = split(/:/,$user);
14558: if (($udom =~ /^$match_domain$/) &&
14559: (&Apache::lonnet::domain($udom)) &&
14560: ($uname =~ /^$match_username$/)) {
14561: if (!grep(/^\Q$user\E/,@okusers)) {
14562: push(@okusers,$user);
14563: }
14564: }
14565: }
14566: if (@okusers > 0) {
14567: @okusers = sort(@okusers);
14568: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
14569: }
14570: }
14571: if (defined($env{'form.'.$type.'_machines'})) {
14572: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
14573: my @okmachines;
14574: foreach my $ip (@machines) {
14575: my @parts = split(/\./,$ip);
14576: next if (@parts < 4);
14577: my $badip = 0;
14578: for (my $i=0; $i<4; $i++) {
14579: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
14580: $badip = 1;
14581: last;
14582: }
14583: }
14584: if (!$badip) {
14585: push(@okmachines,$ip);
14586: }
14587: }
14588: @okmachines = sort(@okmachines);
14589: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
14590: }
14591: }
14592: my %serverstatushash = (
14593: serverstatuses => \%newserverstatus,
14594: );
14595: foreach my $type (@pages) {
1.83 raeburn 14596: foreach my $setting ('namedusers','machines') {
1.84 raeburn 14597: my (@current,@new);
1.83 raeburn 14598: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 14599: if ($currserverstatus{$type}{$setting} ne '') {
14600: @current = split(/,/,$currserverstatus{$type}{$setting});
14601: }
14602: }
14603: if ($newserverstatus{$type}{$setting} ne '') {
14604: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 14605: }
14606: if (@current > 0) {
14607: if (@new > 0) {
14608: foreach my $item (@current) {
14609: if (!grep(/^\Q$item\E$/,@new)) {
14610: $changes{$type}{$setting} = 1;
1.82 raeburn 14611: last;
14612: }
14613: }
1.84 raeburn 14614: foreach my $item (@new) {
14615: if (!grep(/^\Q$item\E$/,@current)) {
14616: $changes{$type}{$setting} = 1;
14617: last;
1.82 raeburn 14618: }
14619: }
14620: } else {
1.83 raeburn 14621: $changes{$type}{$setting} = 1;
1.69 raeburn 14622: }
1.83 raeburn 14623: } elsif (@new > 0) {
14624: $changes{$type}{$setting} = 1;
1.69 raeburn 14625: }
14626: }
14627: }
14628: if (keys(%changes) > 0) {
1.81 raeburn 14629: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 14630: my $putresult = &Apache::lonnet::put_dom('configuration',
14631: \%serverstatushash,$dom);
14632: if ($putresult eq 'ok') {
14633: $resulttext .= &mt('Changes made:').'<ul>';
14634: foreach my $type (@pages) {
1.84 raeburn 14635: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 14636: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 14637: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 14638: if ($newserverstatus{$type}{'namedusers'} eq '') {
14639: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
14640: } else {
14641: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
14642: }
1.84 raeburn 14643: }
14644: if ($changes{$type}{'machines'}) {
1.69 raeburn 14645: if ($newserverstatus{$type}{'machines'} eq '') {
14646: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
14647: } else {
14648: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
14649: }
14650:
14651: }
14652: $resulttext .= '</ul></li>';
14653: }
14654: }
14655: $resulttext .= '</ul>';
14656: } else {
14657: $resulttext = '<span class="LC_error">'.
14658: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
14659:
14660: }
14661: } else {
14662: $resulttext = &mt('No changes made to access to server status pages');
14663: }
14664: return $resulttext;
14665: }
14666:
1.118 jms 14667: sub modify_helpsettings {
1.285 raeburn 14668: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 14669: my ($resulttext,$errors,%changes,%helphash);
14670: my %defaultchecked = ('submitbugs' => 'on');
14671: my @offon = ('off','on');
1.118 jms 14672: my @toggles = ('submitbugs');
1.285 raeburn 14673: my %current = ('submitbugs' => '',
14674: 'adhoc' => {},
14675: );
1.118 jms 14676: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 14677: %current = %{$domconfig{'helpsettings'}};
14678: }
1.285 raeburn 14679: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 14680: foreach my $item (@toggles) {
14681: if ($defaultchecked{$item} eq 'on') {
14682: if ($current{$item} eq '') {
14683: if ($env{'form.'.$item} eq '0') {
14684: $changes{$item} = 1;
14685: }
14686: } elsif ($current{$item} ne $env{'form.'.$item}) {
14687: $changes{$item} = 1;
14688: }
14689: } elsif ($defaultchecked{$item} eq 'off') {
14690: if ($current{$item} eq '') {
14691: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 14692: $changes{$item} = 1;
14693: }
1.282 raeburn 14694: } elsif ($current{$item} ne $env{'form.'.$item}) {
14695: $changes{$item} = 1;
14696: }
14697: }
14698: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
14699: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
14700: }
14701: }
1.285 raeburn 14702: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 14703: my $confname = $dom.'-domainconfig';
14704: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 14705: my (@allpos,%newsettings,%changedprivs,$newrole);
14706: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 14707: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 14708: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 14709: my %lt = &Apache::lonlocal::texthash(
14710: s => 'system',
14711: d => 'domain',
14712: order => 'Display order',
14713: access => 'Role usage',
1.291 raeburn 14714: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 14715: dh => 'All with domain helpdesk role',
14716: da => 'All with domain helpdesk assistant role',
1.285 raeburn 14717: none => 'None',
14718: status => 'Determined based on institutional status',
14719: inc => 'Include all, but exclude specific personnel',
14720: exc => 'Exclude all, but include specific personnel',
14721: );
14722: for (my $num=0; $num<=$maxnum; $num++) {
14723: my ($prefix,$identifier,$rolename,%curr);
14724: if ($num == $maxnum) {
14725: next unless ($env{'form.newcusthelp'} == $maxnum);
14726: $identifier = 'custhelp'.$num;
14727: $prefix = 'helproles_'.$num;
14728: $rolename = $env{'form.custhelpname'.$num};
14729: $rolename=~s/[^A-Za-z0-9]//gs;
14730: next if ($rolename eq '');
14731: next if (exists($existing{'rolesdef_'.$rolename}));
14732: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
14733: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
14734: $newprivs{'c'},$confname,$dom);
14735: if ($result ne 'ok') {
14736: $errors .= '<li><span class="LC_error">'.
14737: &mt('An error occurred storing the new custom role: [_1]',
14738: $result).'</span></li>';
14739: next;
14740: } else {
14741: $changedprivs{$rolename} = \%newprivs;
14742: $newrole = $rolename;
14743: }
14744: } else {
14745: $prefix = 'helproles_'.$num;
14746: $rolename = $env{'form.'.$prefix};
14747: next if ($rolename eq '');
14748: next unless (exists($existing{'rolesdef_'.$rolename}));
14749: $identifier = 'custhelp'.$num;
14750: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
14751: my %currprivs;
1.289 raeburn 14752: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 14753: split(/\_/,$existing{'rolesdef_'.$rolename});
14754: foreach my $level ('c','d','s') {
14755: if ($newprivs{$level} ne $currprivs{$level}) {
14756: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
14757: $newprivs{'c'},$confname,$dom);
14758: if ($result ne 'ok') {
14759: $errors .= '<li><span class="LC_error">'.
14760: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
14761: $rolename,$result).'</span></li>';
14762: } else {
14763: $changedprivs{$rolename} = \%newprivs;
14764: }
14765: last;
14766: }
14767: }
14768: if (ref($current{'adhoc'}) eq 'HASH') {
14769: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
14770: %curr = %{$current{'adhoc'}{$rolename}};
14771: }
14772: }
14773: }
14774: my $newpos = $env{'form.'.$prefix.'_pos'};
14775: $newpos =~ s/\D+//g;
14776: $allpos[$newpos] = $rolename;
14777: my $newdesc = $env{'form.'.$prefix.'_desc'};
14778: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
14779: if ($curr{'desc'}) {
14780: if ($curr{'desc'} ne $newdesc) {
14781: $changes{'customrole'}{$rolename}{'desc'} = 1;
14782: $newsettings{$rolename}{'desc'} = $newdesc;
14783: }
14784: } elsif ($newdesc ne '') {
14785: $changes{'customrole'}{$rolename}{'desc'} = 1;
14786: $newsettings{$rolename}{'desc'} = $newdesc;
14787: }
14788: my $access = $env{'form.'.$prefix.'_access'};
14789: if (grep(/^\Q$access\E$/,@accesstypes)) {
14790: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
14791: if ($access eq 'status') {
14792: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
14793: if (scalar(@statuses) == 0) {
1.289 raeburn 14794: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 14795: } else {
14796: my (@shownstatus,$numtypes);
14797: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
14798: if (ref($types) eq 'ARRAY') {
14799: $numtypes = scalar(@{$types});
14800: foreach my $type (sort(@statuses)) {
14801: if ($type eq 'default') {
14802: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
14803: } elsif (grep(/^\Q$type\E$/,@{$types})) {
14804: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
14805: push(@shownstatus,$usertypes->{$type});
14806: }
14807: }
14808: }
14809: if (grep(/^default$/,@statuses)) {
14810: push(@shownstatus,$othertitle);
14811: }
14812: if (scalar(@shownstatus) == 1+$numtypes) {
14813: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
14814: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
14815: } else {
14816: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
14817: if (ref($curr{'status'}) eq 'ARRAY') {
14818: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
14819: if (@diffs) {
14820: $changes{'customrole'}{$rolename}{$access} = 1;
14821: }
14822: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
14823: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 14824: }
1.166 raeburn 14825: }
14826: }
1.285 raeburn 14827: } elsif (($access eq 'inc') || ($access eq 'exc')) {
14828: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
14829: my @newspecstaff;
14830: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
14831: foreach my $person (sort(@personnel)) {
14832: if ($domhelpdesk{$person}) {
14833: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
14834: }
14835: }
14836: if (ref($curr{$access}) eq 'ARRAY') {
14837: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
14838: if (@diffs) {
14839: $changes{'customrole'}{$rolename}{$access} = 1;
14840: }
14841: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
14842: $changes{'customrole'}{$rolename}{$access} = 1;
14843: }
14844: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
14845: my ($uname,$udom) = split(/:/,$person);
14846: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
14847: }
14848: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 14849: }
1.285 raeburn 14850: } else {
14851: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
14852: }
14853: unless ($curr{'access'} eq $access) {
14854: $changes{'customrole'}{$rolename}{'access'} = 1;
14855: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 14856: }
14857: }
1.285 raeburn 14858: if (@allpos > 0) {
14859: my $idx = 0;
14860: foreach my $rolename (@allpos) {
14861: if ($rolename ne '') {
14862: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
14863: if (ref($current{'adhoc'}) eq 'HASH') {
14864: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
14865: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
14866: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 14867: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 14868: }
14869: }
1.282 raeburn 14870: }
1.285 raeburn 14871: $idx ++;
1.166 raeburn 14872: }
14873: }
1.118 jms 14874: }
1.123 jms 14875: my $putresult;
14876: if (keys(%changes) > 0) {
1.166 raeburn 14877: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 14878: if ($putresult eq 'ok') {
1.285 raeburn 14879: if (ref($helphash{'helpsettings'}) eq 'HASH') {
14880: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
14881: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
14882: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
14883: }
14884: }
14885: my $cachetime = 24*60*60;
14886: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14887: if (ref($lastactref) eq 'HASH') {
14888: $lastactref->{'domdefaults'} = 1;
14889: }
14890: } else {
14891: $errors .= '<li><span class="LC_error">'.
14892: &mt('An error occurred storing the settings: [_1]',
14893: $putresult).'</span></li>';
14894: }
14895: }
14896: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
14897: $resulttext = &mt('Changes made:').'<ul>';
14898: my (%shownprivs,@levelorder);
14899: @levelorder = ('c','d','s');
14900: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 14901: foreach my $item (sort(keys(%changes))) {
14902: if ($item eq 'submitbugs') {
14903: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
14904: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
14905: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 14906: } elsif ($item eq 'customrole') {
14907: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 14908: my @keyorder = ('order','desc','access','status','exc','inc');
14909: my %keytext = &Apache::lonlocal::texthash(
14910: order => 'Order',
14911: desc => 'Role description',
14912: access => 'Role usage',
1.300 droeschl 14913: status => 'Allowed institutional types',
1.285 raeburn 14914: exc => 'Allowed personnel',
14915: inc => 'Disallowed personnel',
14916: );
1.282 raeburn 14917: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 14918: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
14919: if ($role eq $newrole) {
14920: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
14921: $role).'<ul>';
14922: } else {
14923: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
14924: $role).'<ul>';
14925: }
14926: foreach my $key (@keyorder) {
14927: if ($changes{'customrole'}{$role}{$key}) {
14928: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
14929: $keytext{$key},$newsettings{$role}{$key}).
14930: '</li>';
14931: }
14932: }
14933: if (ref($changedprivs{$role}) eq 'HASH') {
14934: $shownprivs{$role} = 1;
14935: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
14936: foreach my $level (@levelorder) {
14937: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
14938: next if ($item eq '');
14939: my ($priv) = split(/\&/,$item,2);
14940: if (&Apache::lonnet::plaintext($priv)) {
14941: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
14942: unless ($level eq 'c') {
14943: $resulttext .= ' ('.$lt{$level}.')';
14944: }
14945: $resulttext .= '</li>';
14946: }
14947: }
14948: }
14949: $resulttext .= '</ul>';
14950: }
14951: $resulttext .= '</ul></li>';
14952: }
14953: }
14954: }
14955: }
14956: }
14957: }
14958: if (keys(%changedprivs)) {
14959: foreach my $role (sort(keys(%changedprivs))) {
14960: unless ($shownprivs{$role}) {
14961: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
14962: $role).'<ul>'.
14963: '<li>'.&mt('Privileges set to :').'<ul>';
14964: foreach my $level (@levelorder) {
14965: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
14966: next if ($item eq '');
14967: my ($priv) = split(/\&/,$item,2);
14968: if (&Apache::lonnet::plaintext($priv)) {
14969: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
14970: unless ($level eq 'c') {
14971: $resulttext .= ' ('.$lt{$level}.')';
14972: }
14973: $resulttext .= '</li>';
14974: }
1.282 raeburn 14975: }
14976: }
1.285 raeburn 14977: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 14978: }
14979: }
14980: }
1.285 raeburn 14981: $resulttext .= '</ul>';
14982: } else {
14983: $resulttext = &mt('No changes made to help settings');
1.118 jms 14984: }
14985: if ($errors) {
1.168 raeburn 14986: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 14987: $errors.'</ul>';
1.118 jms 14988: }
14989: return $resulttext;
14990: }
14991:
1.121 raeburn 14992: sub modify_coursedefaults {
1.212 raeburn 14993: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 14994: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 14995: my %defaultchecked = (
14996: 'canuse_pdfforms' => 'off',
14997: 'uselcmath' => 'on',
14998: 'usejsme' => 'on'
14999: );
15000: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 15001: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 15002: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
15003: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
15004: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 15005: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 15006: my %staticdefaults = (
15007: anonsurvey_threshold => 10,
15008: uploadquota => 500,
1.257 raeburn 15009: postsubmit => 60,
1.276 raeburn 15010: mysqltables => 172800,
1.198 raeburn 15011: );
1.314 raeburn 15012: my %texoptions = (
15013: MathJax => 'MathJax',
15014: mimetex => &mt('Convert to Images'),
15015: tth => &mt('TeX to HTML'),
15016: );
1.121 raeburn 15017: $defaultshash{'coursedefaults'} = {};
15018:
15019: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
15020: if ($domconfig{'coursedefaults'} eq '') {
15021: $domconfig{'coursedefaults'} = {};
15022: }
15023: }
15024:
15025: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
15026: foreach my $item (@toggles) {
15027: if ($defaultchecked{$item} eq 'on') {
15028: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15029: ($env{'form.'.$item} eq '0')) {
15030: $changes{$item} = 1;
1.192 raeburn 15031: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 15032: $changes{$item} = 1;
15033: }
15034: } elsif ($defaultchecked{$item} eq 'off') {
15035: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15036: ($env{'form.'.$item} eq '1')) {
15037: $changes{$item} = 1;
15038: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
15039: $changes{$item} = 1;
15040: }
15041: }
15042: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
15043: }
1.198 raeburn 15044: foreach my $item (@numbers) {
15045: my ($currdef,$newdef);
1.208 raeburn 15046: $newdef = $env{'form.'.$item};
1.198 raeburn 15047: if ($item eq 'anonsurvey_threshold') {
15048: $currdef = $domconfig{'coursedefaults'}{$item};
15049: $newdef =~ s/\D//g;
15050: if ($newdef eq '' || $newdef < 1) {
15051: $newdef = 1;
15052: }
15053: $defaultshash{'coursedefaults'}{$item} = $newdef;
15054: } else {
1.276 raeburn 15055: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
15056: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
15057: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 15058: }
15059: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 15060: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 15061: }
15062: if ($currdef ne $newdef) {
15063: my $staticdef;
15064: if ($item eq 'anonsurvey_threshold') {
15065: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
15066: $changes{$item} = 1;
15067: }
1.276 raeburn 15068: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 15069: my $setting = $1;
1.276 raeburn 15070: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
15071: $changes{$setting} = 1;
1.198 raeburn 15072: }
15073: }
1.139 raeburn 15074: }
15075: }
1.314 raeburn 15076: my $texengine;
15077: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
15078: $texengine = $env{'form.texengine'};
15079: if ($defaultshash{'coursedefaults'}{'texengine'} eq '') {
15080: unless ($texengine eq 'MathJax') {
15081: $changes{'texengine'} = 1;
15082: }
15083: } elsif ($defaultshash{'coursedefaults'}{'texengine'} ne $texengine) {
15084: $changes{'texengine'} = 1;
15085: }
15086: }
15087: if ($texengine ne '') {
15088: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
15089: }
1.264 raeburn 15090: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
15091: my @currclonecode;
15092: if (ref($currclone) eq 'HASH') {
15093: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
15094: @currclonecode = @{$currclone->{'instcode'}};
15095: }
15096: }
15097: my $newclone;
1.289 raeburn 15098: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 15099: $newclone = $env{'form.canclone'};
15100: }
15101: if ($newclone eq 'instcode') {
15102: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
15103: my (%codedefaults,@code_order,@clonecode);
15104: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
15105: \@code_order);
15106: foreach my $item (@code_order) {
15107: if (grep(/^\Q$item\E$/,@newcodes)) {
15108: push(@clonecode,$item);
15109: }
15110: }
15111: if (@clonecode) {
15112: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
15113: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
15114: if (@diffs) {
15115: $changes{'canclone'} = 1;
15116: }
15117: } else {
15118: $newclone eq '';
15119: }
15120: } elsif ($newclone ne '') {
1.289 raeburn 15121: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
15122: }
1.264 raeburn 15123: if ($newclone ne $currclone) {
15124: $changes{'canclone'} = 1;
15125: }
1.257 raeburn 15126: my %credits;
15127: foreach my $type (@types) {
15128: unless ($type eq 'community') {
15129: $credits{$type} = $env{'form.'.$type.'_credits'};
15130: $credits{$type} =~ s/[^\d.]+//g;
15131: }
15132: }
15133: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
15134: ($env{'form.coursecredits'} eq '1')) {
15135: $changes{'coursecredits'} = 1;
15136: foreach my $type (keys(%credits)) {
15137: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15138: }
15139: } else {
1.289 raeburn 15140: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 15141: foreach my $type (@types) {
15142: unless ($type eq 'community') {
1.289 raeburn 15143: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 15144: $changes{'coursecredits'} = 1;
15145: }
15146: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15147: }
15148: }
15149: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15150: foreach my $type (@types) {
15151: unless ($type eq 'community') {
15152: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
15153: $changes{'coursecredits'} = 1;
15154: last;
15155: }
15156: }
15157: }
15158: }
15159: }
15160: if ($env{'form.postsubmit'} eq '1') {
15161: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
15162: my %currtimeout;
15163: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15164: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
15165: $changes{'postsubmit'} = 1;
15166: }
15167: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15168: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
15169: }
15170: } else {
15171: $changes{'postsubmit'} = 1;
15172: }
15173: foreach my $type (@types) {
15174: my $timeout = $env{'form.'.$type.'_timeout'};
15175: $timeout =~ s/\D//g;
15176: if ($timeout == $staticdefaults{'postsubmit'}) {
15177: $timeout = '';
15178: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
15179: $timeout = '0';
15180: }
15181: unless ($timeout eq '') {
15182: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
15183: }
15184: if (exists($currtimeout{$type})) {
15185: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 15186: $changes{'postsubmit'} = 1;
1.257 raeburn 15187: }
15188: } elsif ($timeout ne '') {
15189: $changes{'postsubmit'} = 1;
15190: }
15191: }
15192: } else {
15193: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
15194: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15195: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
15196: $changes{'postsubmit'} = 1;
15197: }
15198: } else {
15199: $changes{'postsubmit'} = 1;
15200: }
1.192 raeburn 15201: }
1.121 raeburn 15202: }
15203: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
15204: $dom);
15205: if ($putresult eq 'ok') {
15206: if (keys(%changes) > 0) {
1.213 raeburn 15207: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 15208: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 15209: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314 raeburn 15210: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
15211: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257 raeburn 15212: if ($changes{$item}) {
15213: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
15214: }
1.289 raeburn 15215: }
1.192 raeburn 15216: if ($changes{'coursecredits'}) {
15217: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 15218: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
15219: $domdefaults{$type.'credits'} =
15220: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
15221: }
15222: }
15223: }
15224: if ($changes{'postsubmit'}) {
15225: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15226: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
15227: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15228: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
15229: $domdefaults{$type.'postsubtimeout'} =
15230: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15231: }
15232: }
1.192 raeburn 15233: }
15234: }
1.198 raeburn 15235: if ($changes{'uploadquota'}) {
15236: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15237: foreach my $type (@types) {
15238: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
15239: }
15240: }
15241: }
1.264 raeburn 15242: if ($changes{'canclone'}) {
15243: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15244: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15245: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
15246: if (@clonecodes) {
15247: $domdefaults{'canclone'} = join('+',@clonecodes);
15248: }
15249: }
15250: } else {
15251: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
15252: }
15253: }
1.121 raeburn 15254: my $cachetime = 24*60*60;
15255: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 15256: if (ref($lastactref) eq 'HASH') {
15257: $lastactref->{'domdefaults'} = 1;
15258: }
1.121 raeburn 15259: }
15260: $resulttext = &mt('Changes made:').'<ul>';
15261: foreach my $item (sort(keys(%changes))) {
15262: if ($item eq 'canuse_pdfforms') {
15263: if ($env{'form.'.$item} eq '1') {
15264: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
15265: } else {
15266: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
15267: }
1.257 raeburn 15268: } elsif ($item eq 'uselcmath') {
15269: if ($env{'form.'.$item} eq '1') {
15270: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
15271: } else {
15272: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
15273: }
15274: } elsif ($item eq 'usejsme') {
15275: if ($env{'form.'.$item} eq '1') {
15276: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
15277: } else {
1.289 raeburn 15278: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 15279: }
1.314 raeburn 15280: } elsif ($item eq 'texengine') {
15281: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
15282: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
15283: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
15284: }
1.139 raeburn 15285: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 15286: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 15287: } elsif ($item eq 'uploadquota') {
15288: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15289: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
15290: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
15291: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 15292: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 15293: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 15294: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
15295: '</ul>'.
15296: '</li>';
15297: } else {
15298: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
15299: }
1.276 raeburn 15300: } elsif ($item eq 'mysqltables') {
15301: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
15302: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
15303: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
15304: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
15305: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
15306: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
15307: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
15308: '</ul>'.
15309: '</li>';
15310: } else {
15311: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
15312: }
1.257 raeburn 15313: } elsif ($item eq 'postsubmit') {
15314: if ($domdefaults{'postsubmit'} eq 'off') {
15315: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
15316: } else {
15317: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 15318: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 15319: $resulttext .= &mt('durations:').'<ul>';
15320: foreach my $type (@types) {
15321: $resulttext .= '<li>';
15322: my $timeout;
15323: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15324: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15325: }
15326: my $display;
15327: if ($timeout eq '0') {
15328: $display = &mt('unlimited');
15329: } elsif ($timeout eq '') {
15330: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
15331: } else {
15332: $display = &mt('[quant,_1,second]',$timeout);
15333: }
15334: if ($type eq 'community') {
15335: $resulttext .= &mt('Communities');
15336: } elsif ($type eq 'official') {
15337: $resulttext .= &mt('Official courses');
15338: } elsif ($type eq 'unofficial') {
15339: $resulttext .= &mt('Unofficial courses');
15340: } elsif ($type eq 'textbook') {
15341: $resulttext .= &mt('Textbook courses');
1.271 raeburn 15342: } elsif ($type eq 'placement') {
15343: $resulttext .= &mt('Placement tests');
1.257 raeburn 15344: }
15345: $resulttext .= ' -- '.$display.'</li>';
15346: }
15347: $resulttext .= '</ul>';
15348: }
1.289 raeburn 15349: $resulttext .= '</li>';
1.257 raeburn 15350: }
1.192 raeburn 15351: } elsif ($item eq 'coursecredits') {
15352: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15353: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 15354: ($domdefaults{'unofficialcredits'} eq '') &&
15355: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 15356: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15357: } else {
15358: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
15359: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
15360: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 15361: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 15362: '</ul>'.
15363: '</li>';
15364: }
15365: } else {
15366: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15367: }
1.264 raeburn 15368: } elsif ($item eq 'canclone') {
15369: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15370: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15371: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
15372: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
15373: }
15374: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
15375: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
15376: } else {
1.289 raeburn 15377: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 15378: }
1.140 raeburn 15379: }
1.121 raeburn 15380: }
15381: $resulttext .= '</ul>';
15382: } else {
15383: $resulttext = &mt('No changes made to course defaults');
15384: }
15385: } else {
15386: $resulttext = '<span class="LC_error">'.
15387: &mt('An error occurred: [_1]',$putresult).'</span>';
15388: }
15389: return $resulttext;
15390: }
15391:
1.231 raeburn 15392: sub modify_selfenrollment {
15393: my ($dom,$lastactref,%domconfig) = @_;
15394: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 15395: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 15396: my %titles = &tool_titles();
1.232 raeburn 15397: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
15398: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 15399: $ordered{'default'} = ['types','registered','approval','limit'];
15400:
15401: my (%roles,%shown,%toplevel);
15402: $roles{'0'} = &Apache::lonnet::plaintext('dc');
15403:
15404: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
15405: if ($domconfig{'selfenrollment'} eq '') {
15406: $domconfig{'selfenrollment'} = {};
15407: }
15408: }
15409: %toplevel = (
15410: admin => 'Configuration Rights',
15411: default => 'Default settings',
15412: validation => 'Validation of self-enrollment requests',
15413: );
1.233 raeburn 15414: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 15415:
15416: if (ref($ordered{'admin'}) eq 'ARRAY') {
15417: foreach my $item (@{$ordered{'admin'}}) {
15418: foreach my $type (@types) {
15419: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
15420: $selfenrollhash{'admin'}{$type}{$item} = 1;
15421: } else {
15422: $selfenrollhash{'admin'}{$type}{$item} = 0;
15423: }
15424: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
15425: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
15426: if ($selfenrollhash{'admin'}{$type}{$item} ne
15427: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
15428: push(@{$changes{'admin'}{$type}},$item);
15429: }
15430: } else {
15431: if (!$selfenrollhash{'admin'}{$type}{$item}) {
15432: push(@{$changes{'admin'}{$type}},$item);
15433: }
15434: }
15435: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
15436: push(@{$changes{'admin'}{$type}},$item);
15437: }
15438: }
15439: }
15440: }
15441:
15442: foreach my $item (@{$ordered{'default'}}) {
15443: foreach my $type (@types) {
15444: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
15445: if ($item eq 'types') {
15446: unless (($value eq 'all') || ($value eq 'dom')) {
15447: $value = '';
15448: }
15449: } elsif ($item eq 'registered') {
15450: unless ($value eq '1') {
15451: $value = 0;
15452: }
15453: } elsif ($item eq 'approval') {
15454: unless ($value =~ /^[012]$/) {
15455: $value = 0;
15456: }
15457: } else {
15458: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15459: $value = 'none';
15460: }
15461: }
15462: $selfenrollhash{'default'}{$type}{$item} = $value;
15463: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
15464: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15465: if ($selfenrollhash{'default'}{$type}{$item} ne
15466: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
15467: push(@{$changes{'default'}{$type}},$item);
15468: }
15469: } else {
15470: push(@{$changes{'default'}{$type}},$item);
15471: }
15472: } else {
15473: push(@{$changes{'default'}{$type}},$item);
15474: }
15475: if ($item eq 'limit') {
15476: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15477: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
15478: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
15479: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
15480: }
15481: } else {
15482: $selfenrollhash{'default'}{$type}{'cap'} = '';
15483: }
15484: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15485: if ($selfenrollhash{'default'}{$type}{'cap'} ne
15486: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
15487: push(@{$changes{'default'}{$type}},'cap');
15488: }
15489: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
15490: push(@{$changes{'default'}{$type}},'cap');
15491: }
15492: }
15493: }
15494: }
15495:
15496: foreach my $item (@{$itemsref}) {
15497: if ($item eq 'fields') {
15498: my @changed;
15499: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
15500: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
15501: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
15502: }
15503: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
15504: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
15505: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
15506: $domconfig{'selfenrollment'}{'validation'}{$item});
15507: } else {
15508: @changed = @{$selfenrollhash{'validation'}{$item}};
15509: }
15510: } else {
15511: @changed = @{$selfenrollhash{'validation'}{$item}};
15512: }
15513: if (@changed) {
15514: if ($selfenrollhash{'validation'}{$item}) {
15515: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
15516: } else {
15517: $changes{'validation'}{$item} = &mt('None');
15518: }
15519: }
15520: } else {
15521: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
15522: if ($item eq 'markup') {
15523: if ($env{'form.selfenroll_validation_'.$item}) {
15524: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
15525: }
15526: }
15527: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
15528: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
15529: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
15530: }
15531: }
15532: }
15533: }
15534:
15535: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
15536: $dom);
15537: if ($putresult eq 'ok') {
15538: if (keys(%changes) > 0) {
15539: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15540: $resulttext = &mt('Changes made:').'<ul>';
15541: foreach my $key ('admin','default','validation') {
15542: if (ref($changes{$key}) eq 'HASH') {
15543: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
15544: if ($key eq 'validation') {
15545: foreach my $item (@{$itemsref}) {
15546: if (exists($changes{$key}{$item})) {
15547: if ($item eq 'markup') {
15548: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
15549: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
15550: } else {
15551: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
15552: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
15553: }
15554: }
15555: }
15556: } else {
15557: foreach my $type (@types) {
15558: if ($type eq 'community') {
15559: $roles{'1'} = &mt('Community personnel');
15560: } else {
15561: $roles{'1'} = &mt('Course personnel');
15562: }
15563: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 15564: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
15565: if ($key eq 'admin') {
15566: my @mgrdc = ();
15567: if (ref($ordered{$key}) eq 'ARRAY') {
15568: foreach my $item (@{$ordered{'admin'}}) {
15569: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
15570: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
15571: push(@mgrdc,$item);
15572: }
15573: }
15574: }
15575: if (@mgrdc) {
15576: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
15577: } else {
15578: delete($domdefaults{$type.'selfenrolladmdc'});
15579: }
15580: }
15581: } else {
15582: if (ref($ordered{$key}) eq 'ARRAY') {
15583: foreach my $item (@{$ordered{$key}}) {
15584: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
15585: $domdefaults{$type.'selfenroll'.$item} =
15586: $selfenrollhash{$key}{$type}{$item};
15587: }
15588: }
15589: }
15590: }
15591: }
1.231 raeburn 15592: $resulttext .= '<li>'.$titles{$type}.'<ul>';
15593: foreach my $item (@{$ordered{$key}}) {
15594: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
15595: $resulttext .= '<li>';
15596: if ($key eq 'admin') {
15597: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
15598: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
15599: } else {
15600: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
15601: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
15602: }
15603: $resulttext .= '</li>';
15604: }
15605: }
15606: $resulttext .= '</ul></li>';
15607: }
15608: }
15609: $resulttext .= '</ul></li>';
15610: }
15611: }
1.305 raeburn 15612: }
15613: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
15614: my $cachetime = 24*60*60;
15615: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15616: if (ref($lastactref) eq 'HASH') {
15617: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 15618: }
1.231 raeburn 15619: }
15620: $resulttext .= '</ul>';
15621: } else {
15622: $resulttext = &mt('No changes made to self-enrollment settings');
15623: }
15624: } else {
15625: $resulttext = '<span class="LC_error">'.
15626: &mt('An error occurred: [_1]',$putresult).'</span>';
15627: }
15628: return $resulttext;
15629: }
15630:
1.137 raeburn 15631: sub modify_usersessions {
1.212 raeburn 15632: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 15633: my @hostingtypes = ('version','excludedomain','includedomain');
15634: my @offloadtypes = ('primary','default');
15635: my %types = (
15636: remote => \@hostingtypes,
15637: hosted => \@hostingtypes,
15638: spares => \@offloadtypes,
15639: );
15640: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 15641: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 15642: my (%by_ip,%by_location,@intdoms,@instdoms);
15643: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 15644: my @locations = sort(keys(%by_location));
1.137 raeburn 15645: my (%defaultshash,%changes);
15646: foreach my $prefix (@prefixes) {
15647: $defaultshash{'usersessions'}{$prefix} = {};
15648: }
1.212 raeburn 15649: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 15650: my $resulttext;
1.138 raeburn 15651: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 15652: foreach my $prefix (@prefixes) {
1.145 raeburn 15653: next if ($prefix eq 'spares');
15654: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 15655: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
15656: if ($type eq 'version') {
15657: my $value = $env{'form.'.$prefix.'_'.$type};
15658: my $okvalue;
15659: if ($value ne '') {
15660: if (grep(/^\Q$value\E$/,@lcversions)) {
15661: $okvalue = $value;
15662: }
15663: }
15664: if (ref($domconfig{'usersessions'}) eq 'HASH') {
15665: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
15666: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
15667: if ($inuse == 0) {
15668: $changes{$prefix}{$type} = 1;
15669: } else {
15670: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
15671: $changes{$prefix}{$type} = 1;
15672: }
15673: if ($okvalue ne '') {
15674: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
15675: }
15676: }
15677: } else {
15678: if (($inuse == 1) && ($okvalue ne '')) {
15679: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
15680: $changes{$prefix}{$type} = 1;
15681: }
15682: }
15683: } else {
15684: if (($inuse == 1) && ($okvalue ne '')) {
15685: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
15686: $changes{$prefix}{$type} = 1;
15687: }
15688: }
15689: } else {
15690: if (($inuse == 1) && ($okvalue ne '')) {
15691: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
15692: $changes{$prefix}{$type} = 1;
15693: }
15694: }
15695: } else {
15696: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
15697: my @okvals;
15698: foreach my $val (@vals) {
1.138 raeburn 15699: if ($val =~ /:/) {
15700: my @items = split(/:/,$val);
15701: foreach my $item (@items) {
15702: if (ref($by_location{$item}) eq 'ARRAY') {
15703: push(@okvals,$item);
15704: }
15705: }
15706: } else {
15707: if (ref($by_location{$val}) eq 'ARRAY') {
15708: push(@okvals,$val);
15709: }
1.137 raeburn 15710: }
15711: }
15712: @okvals = sort(@okvals);
15713: if (ref($domconfig{'usersessions'}) eq 'HASH') {
15714: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
15715: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
15716: if ($inuse == 0) {
15717: $changes{$prefix}{$type} = 1;
15718: } else {
15719: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
15720: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
15721: if (@changed > 0) {
15722: $changes{$prefix}{$type} = 1;
15723: }
15724: }
15725: } else {
15726: if ($inuse == 1) {
15727: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
15728: $changes{$prefix}{$type} = 1;
15729: }
15730: }
15731: } else {
15732: if ($inuse == 1) {
15733: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
15734: $changes{$prefix}{$type} = 1;
15735: }
15736: }
15737: } else {
15738: if ($inuse == 1) {
15739: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
15740: $changes{$prefix}{$type} = 1;
15741: }
15742: }
15743: }
15744: }
15745: }
1.145 raeburn 15746:
15747: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 15748: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 15749: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
15750: my $savespares;
15751:
15752: foreach my $lonhost (sort(keys(%servers))) {
15753: my $serverhomeID =
15754: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 15755: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 15756: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
15757: my %spareschg;
15758: foreach my $type (@{$types{'spares'}}) {
15759: my @okspares;
15760: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
15761: foreach my $server (@checked) {
1.152 raeburn 15762: if (&Apache::lonnet::hostname($server) ne '') {
15763: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
15764: unless (grep(/^\Q$server\E$/,@okspares)) {
15765: push(@okspares,$server);
15766: }
1.145 raeburn 15767: }
15768: }
15769: }
15770: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
15771: my $newspare;
1.152 raeburn 15772: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
15773: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 15774: $newspare = $new;
15775: }
15776: }
1.152 raeburn 15777: my @spares;
15778: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
15779: @spares = sort(@okspares,$newspare);
15780: } else {
15781: @spares = sort(@okspares);
15782: }
15783: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 15784: if (ref($spareid{$lonhost}) eq 'HASH') {
15785: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 15786: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 15787: if (@diffs > 0) {
15788: $spareschg{$type} = 1;
15789: }
15790: }
15791: }
15792: }
15793: if (keys(%spareschg) > 0) {
15794: $changes{'spares'}{$lonhost} = \%spareschg;
15795: }
15796: }
1.261 raeburn 15797: $defaultshash{'usersessions'}{'offloadnow'} = {};
15798: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
15799: my @okoffload;
15800: if (@offloadnow) {
15801: foreach my $server (@offloadnow) {
15802: if (&Apache::lonnet::hostname($server) ne '') {
15803: unless (grep(/^\Q$server\E$/,@okoffload)) {
15804: push(@okoffload,$server);
15805: }
15806: }
15807: }
15808: if (@okoffload) {
15809: foreach my $lonhost (@okoffload) {
15810: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
15811: }
15812: }
15813: }
1.145 raeburn 15814: if (ref($domconfig{'usersessions'}) eq 'HASH') {
15815: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
15816: if (ref($changes{'spares'}) eq 'HASH') {
15817: if (keys(%{$changes{'spares'}}) > 0) {
15818: $savespares = 1;
15819: }
15820: }
15821: } else {
15822: $savespares = 1;
15823: }
1.261 raeburn 15824: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
15825: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
15826: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
15827: $changes{'offloadnow'} = 1;
15828: last;
15829: }
15830: }
15831: unless ($changes{'offloadnow'}) {
1.289 raeburn 15832: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 15833: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
15834: $changes{'offloadnow'} = 1;
15835: last;
15836: }
15837: }
15838: }
15839: } elsif (@okoffload) {
15840: $changes{'offloadnow'} = 1;
15841: }
15842: } elsif (@okoffload) {
15843: $changes{'offloadnow'} = 1;
1.145 raeburn 15844: }
1.147 raeburn 15845: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
15846: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 15847: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
15848: $dom);
15849: if ($putresult eq 'ok') {
15850: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
15851: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
15852: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
15853: }
15854: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
15855: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
15856: }
1.261 raeburn 15857: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
15858: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
15859: }
1.137 raeburn 15860: }
15861: my $cachetime = 24*60*60;
15862: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 15863: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 15864: if (ref($lastactref) eq 'HASH') {
15865: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 15866: $lastactref->{'usersessions'} = 1;
1.212 raeburn 15867: }
1.147 raeburn 15868: if (keys(%changes) > 0) {
15869: my %lt = &usersession_titles();
15870: $resulttext = &mt('Changes made:').'<ul>';
15871: foreach my $prefix (@prefixes) {
15872: if (ref($changes{$prefix}) eq 'HASH') {
15873: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
15874: if ($prefix eq 'spares') {
15875: if (ref($changes{$prefix}) eq 'HASH') {
15876: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
15877: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 15878: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 15879: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
15880: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 15881: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
15882: foreach my $type (@{$types{$prefix}}) {
15883: if ($changes{$prefix}{$lonhost}{$type}) {
15884: my $offloadto = &mt('None');
15885: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
15886: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
15887: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
15888: }
1.145 raeburn 15889: }
1.147 raeburn 15890: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 15891: }
1.137 raeburn 15892: }
15893: }
1.147 raeburn 15894: $resulttext .= '</li>';
1.137 raeburn 15895: }
15896: }
1.147 raeburn 15897: } else {
15898: foreach my $type (@{$types{$prefix}}) {
15899: if (defined($changes{$prefix}{$type})) {
15900: my $newvalue;
15901: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
15902: if (ref($defaultshash{'usersessions'}{$prefix})) {
15903: if ($type eq 'version') {
15904: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
15905: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
15906: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
15907: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
15908: }
1.145 raeburn 15909: }
15910: }
15911: }
1.147 raeburn 15912: if ($newvalue eq '') {
15913: if ($type eq 'version') {
15914: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
15915: } else {
15916: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
15917: }
1.145 raeburn 15918: } else {
1.147 raeburn 15919: if ($type eq 'version') {
15920: $newvalue .= ' '.&mt('(or later)');
15921: }
15922: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 15923: }
1.137 raeburn 15924: }
15925: }
15926: }
1.147 raeburn 15927: $resulttext .= '</ul>';
1.137 raeburn 15928: }
15929: }
1.261 raeburn 15930: if ($changes{'offloadnow'}) {
15931: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
15932: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
15933: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
15934: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
15935: $resulttext .= '<li>'.$lonhost.'</li>';
15936: }
15937: $resulttext .= '</ul>';
15938: } else {
15939: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
15940: }
15941: } else {
15942: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
15943: }
15944: }
1.147 raeburn 15945: $resulttext .= '</ul>';
15946: } else {
15947: $resulttext = $nochgmsg;
1.137 raeburn 15948: }
15949: } else {
15950: $resulttext = '<span class="LC_error">'.
15951: &mt('An error occurred: [_1]',$putresult).'</span>';
15952: }
15953: } else {
1.147 raeburn 15954: $resulttext = $nochgmsg;
1.137 raeburn 15955: }
15956: return $resulttext;
15957: }
15958:
1.275 raeburn 15959: sub modify_ssl {
15960: my ($dom,$lastactref,%domconfig) = @_;
15961: my (%by_ip,%by_location,@intdoms,@instdoms);
15962: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
15963: my @locations = sort(keys(%by_location));
15964: my %servers = &Apache::lonnet::internet_dom_servers($dom);
15965: my (%defaultshash,%changes);
15966: my $action = 'ssl';
1.293 raeburn 15967: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 15968: foreach my $prefix (@prefixes) {
15969: $defaultshash{$action}{$prefix} = {};
15970: }
15971: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15972: my $resulttext;
15973: my %iphost = &Apache::lonnet::get_iphost();
15974: my @reptypes = ('certreq','nocertreq');
15975: my @connecttypes = ('dom','intdom','other');
15976: my %types = (
1.293 raeburn 15977: connto => \@connecttypes,
15978: connfrom => \@connecttypes,
15979: replication => \@reptypes,
1.275 raeburn 15980: );
15981: foreach my $prefix (sort(keys(%types))) {
15982: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 15983: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 15984: my $value = 'yes';
15985: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
15986: $value = $env{'form.'.$prefix.'_'.$type};
15987: }
15988: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
15989: if ($domconfig{$action}{$prefix}{$type} ne '') {
15990: if ($value ne $domconfig{$action}{$prefix}{$type}) {
15991: $changes{$prefix}{$type} = 1;
15992: }
15993: $defaultshash{$action}{$prefix}{$type} = $value;
15994: } else {
15995: $defaultshash{$action}{$prefix}{$type} = $value;
15996: $changes{$prefix}{$type} = 1;
15997: }
15998: } else {
15999: $defaultshash{$action}{$prefix}{$type} = $value;
16000: $changes{$prefix}{$type} = 1;
16001: }
16002: if (($type eq 'dom') && (keys(%servers) == 1)) {
16003: delete($changes{$prefix}{$type});
16004: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
16005: delete($changes{$prefix}{$type});
16006: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
16007: delete($changes{$prefix}{$type});
16008: }
16009: } elsif ($prefix eq 'replication') {
16010: if (@locations > 0) {
16011: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16012: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16013: my @okvals;
16014: foreach my $val (@vals) {
16015: if ($val =~ /:/) {
16016: my @items = split(/:/,$val);
16017: foreach my $item (@items) {
16018: if (ref($by_location{$item}) eq 'ARRAY') {
16019: push(@okvals,$item);
16020: }
16021: }
16022: } else {
16023: if (ref($by_location{$val}) eq 'ARRAY') {
16024: push(@okvals,$val);
16025: }
16026: }
16027: }
16028: @okvals = sort(@okvals);
16029: if (ref($domconfig{$action}) eq 'HASH') {
16030: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
16031: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
16032: if ($inuse == 0) {
16033: $changes{$prefix}{$type} = 1;
16034: } else {
16035: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16036: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
16037: if (@changed > 0) {
16038: $changes{$prefix}{$type} = 1;
16039: }
16040: }
16041: } else {
16042: if ($inuse == 1) {
16043: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16044: $changes{$prefix}{$type} = 1;
16045: }
16046: }
16047: } else {
16048: if ($inuse == 1) {
16049: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16050: $changes{$prefix}{$type} = 1;
16051: }
16052: }
16053: } else {
16054: if ($inuse == 1) {
16055: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16056: $changes{$prefix}{$type} = 1;
16057: }
16058: }
16059: }
16060: }
16061: }
16062: }
16063: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
16064: if (keys(%changes) > 0) {
16065: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16066: $dom);
16067: if ($putresult eq 'ok') {
16068: if (ref($defaultshash{$action}) eq 'HASH') {
16069: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
16070: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
16071: }
1.293 raeburn 16072: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
16073: $domdefaults{'connto'} = $domconfig{$action}{'connto'};
16074: }
16075: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
16076: $domdefaults{'connfrom'} = $domconfig{$action}{'connfrom'};
1.275 raeburn 16077: }
16078: }
16079: my $cachetime = 24*60*60;
16080: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16081: if (ref($lastactref) eq 'HASH') {
16082: $lastactref->{'domdefaults'} = 1;
16083: }
16084: if (keys(%changes) > 0) {
16085: my %titles = &ssl_titles();
16086: $resulttext = &mt('Changes made:').'<ul>';
16087: foreach my $prefix (@prefixes) {
16088: if (ref($changes{$prefix}) eq 'HASH') {
16089: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
16090: foreach my $type (@{$types{$prefix}}) {
16091: if (defined($changes{$prefix}{$type})) {
16092: my $newvalue;
16093: if (ref($defaultshash{$action}) eq 'HASH') {
16094: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 16095: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 16096: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
16097: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
16098: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
16099: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
16100: }
16101: }
16102: }
16103: if ($newvalue eq '') {
16104: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
16105: } else {
16106: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
16107: }
16108: }
16109: }
16110: }
16111: $resulttext .= '</ul>';
16112: }
16113: }
16114: } else {
16115: $resulttext = $nochgmsg;
16116: }
16117: } else {
16118: $resulttext = '<span class="LC_error">'.
16119: &mt('An error occurred: [_1]',$putresult).'</span>';
16120: }
16121: } else {
16122: $resulttext = $nochgmsg;
16123: }
16124: return $resulttext;
16125: }
16126:
1.279 raeburn 16127: sub modify_trust {
16128: my ($dom,$lastactref,%domconfig) = @_;
16129: my (%by_ip,%by_location,@intdoms,@instdoms);
16130: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
16131: my @locations = sort(keys(%by_location));
16132: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
16133: my @types = ('exc','inc');
16134: my (%defaultshash,%changes);
16135: foreach my $prefix (@prefixes) {
16136: $defaultshash{'trust'}{$prefix} = {};
16137: }
16138: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16139: my $resulttext;
16140: foreach my $prefix (@prefixes) {
16141: foreach my $type (@types) {
16142: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16143: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16144: my @okvals;
16145: foreach my $val (@vals) {
16146: if ($val =~ /:/) {
16147: my @items = split(/:/,$val);
16148: foreach my $item (@items) {
16149: if (ref($by_location{$item}) eq 'ARRAY') {
16150: push(@okvals,$item);
16151: }
16152: }
16153: } else {
16154: if (ref($by_location{$val}) eq 'ARRAY') {
16155: push(@okvals,$val);
16156: }
16157: }
16158: }
16159: @okvals = sort(@okvals);
16160: if (ref($domconfig{'trust'}) eq 'HASH') {
16161: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
16162: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
16163: if ($inuse == 0) {
16164: $changes{$prefix}{$type} = 1;
16165: } else {
16166: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16167: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
16168: if (@changed > 0) {
16169: $changes{$prefix}{$type} = 1;
16170: }
16171: }
16172: } else {
16173: if ($inuse == 1) {
16174: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16175: $changes{$prefix}{$type} = 1;
16176: }
16177: }
16178: } else {
16179: if ($inuse == 1) {
16180: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16181: $changes{$prefix}{$type} = 1;
16182: }
16183: }
16184: } else {
16185: if ($inuse == 1) {
16186: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16187: $changes{$prefix}{$type} = 1;
16188: }
16189: }
16190: }
16191: }
16192: my $nochgmsg = &mt('No changes made to trust settings.');
16193: if (keys(%changes) > 0) {
16194: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16195: $dom);
16196: if ($putresult eq 'ok') {
16197: if (ref($defaultshash{'trust'}) eq 'HASH') {
16198: foreach my $prefix (@prefixes) {
16199: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
16200: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
16201: }
16202: }
16203: }
16204: my $cachetime = 24*60*60;
16205: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16206: if (ref($lastactref) eq 'HASH') {
16207: $lastactref->{'domdefaults'} = 1;
16208: }
16209: if (keys(%changes) > 0) {
16210: my %lt = &trust_titles();
16211: $resulttext = &mt('Changes made:').'<ul>';
16212: foreach my $prefix (@prefixes) {
16213: if (ref($changes{$prefix}) eq 'HASH') {
16214: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
16215: foreach my $type (@types) {
16216: if (defined($changes{$prefix}{$type})) {
16217: my $newvalue;
16218: if (ref($defaultshash{'trust'}) eq 'HASH') {
16219: if (ref($defaultshash{'trust'}{$prefix})) {
16220: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
16221: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
16222: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
16223: }
16224: }
16225: }
16226: }
16227: if ($newvalue eq '') {
16228: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
16229: } else {
16230: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
16231: }
16232: }
16233: }
16234: $resulttext .= '</ul>';
16235: }
16236: }
16237: $resulttext .= '</ul>';
16238: } else {
16239: $resulttext = $nochgmsg;
16240: }
16241: } else {
16242: $resulttext = '<span class="LC_error">'.
16243: &mt('An error occurred: [_1]',$putresult).'</span>';
16244: }
16245: } else {
16246: $resulttext = $nochgmsg;
16247: }
16248: return $resulttext;
16249: }
16250:
1.150 raeburn 16251: sub modify_loadbalancing {
16252: my ($dom,%domconfig) = @_;
16253: my $primary_id = &Apache::lonnet::domain($dom,'primary');
16254: my $intdom = &Apache::lonnet::internet_dom($primary_id);
16255: my ($othertitle,$usertypes,$types) =
16256: &Apache::loncommon::sorted_inst_types($dom);
16257: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 16258: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 16259: my @sparestypes = ('primary','default');
16260: my %typetitles = &sparestype_titles();
16261: my $resulttext;
1.171 raeburn 16262: my (%currbalancer,%currtargets,%currrules,%existing);
16263: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16264: %existing = %{$domconfig{'loadbalancing'}};
16265: }
16266: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
16267: \%currtargets,\%currrules);
16268: my ($saveloadbalancing,%defaultshash,%changes);
16269: my ($alltypes,$othertypes,$titles) =
16270: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
16271: my %ruletitles = &offloadtype_text();
16272: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
16273: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
16274: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
16275: if ($balancer eq '') {
16276: next;
16277: }
1.210 raeburn 16278: if (!exists($servers{$balancer})) {
1.171 raeburn 16279: if (exists($currbalancer{$balancer})) {
16280: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 16281: }
1.171 raeburn 16282: next;
16283: }
16284: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
16285: push(@{$changes{'delete'}},$balancer);
16286: next;
16287: }
16288: if (!exists($currbalancer{$balancer})) {
16289: push(@{$changes{'add'}},$balancer);
16290: }
16291: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
16292: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
16293: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
16294: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16295: $saveloadbalancing = 1;
16296: }
16297: foreach my $sparetype (@sparestypes) {
16298: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
16299: my @offloadto;
16300: foreach my $target (@targets) {
16301: if (($servers{$target}) && ($target ne $balancer)) {
16302: if ($sparetype eq 'default') {
16303: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
16304: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 16305: }
16306: }
1.171 raeburn 16307: unless(grep(/^\Q$target\E$/,@offloadto)) {
16308: push(@offloadto,$target);
16309: }
1.150 raeburn 16310: }
16311: }
1.284 raeburn 16312: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
16313: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
16314: push(@offloadto,$balancer);
16315: }
16316: }
16317: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 16318: }
1.171 raeburn 16319: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 16320: foreach my $sparetype (@sparestypes) {
1.171 raeburn 16321: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
16322: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 16323: if (@targetdiffs > 0) {
1.171 raeburn 16324: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 16325: }
1.171 raeburn 16326: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16327: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16328: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 16329: }
16330: }
16331: }
16332: } else {
1.171 raeburn 16333: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 16334: foreach my $sparetype (@sparestypes) {
1.171 raeburn 16335: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16336: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16337: $changes{'curr'}{$balancer}{'targets'} = 1;
16338: }
1.150 raeburn 16339: }
16340: }
1.210 raeburn 16341: }
1.150 raeburn 16342: }
16343: my $ishomedom;
1.171 raeburn 16344: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
16345: $ishomedom = 1;
1.150 raeburn 16346: }
16347: if (ref($alltypes) eq 'ARRAY') {
16348: foreach my $type (@{$alltypes}) {
16349: my $rule;
1.210 raeburn 16350: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 16351: (!$ishomedom)) {
1.171 raeburn 16352: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
16353: }
16354: if ($rule eq 'specific') {
1.255 raeburn 16355: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 16356: if (exists($servers{$specifiedhost})) {
1.255 raeburn 16357: $rule = $specifiedhost;
16358: }
1.150 raeburn 16359: }
1.171 raeburn 16360: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
16361: if (ref($currrules{$balancer}) eq 'HASH') {
16362: if ($rule ne $currrules{$balancer}{$type}) {
16363: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 16364: }
16365: } elsif ($rule ne '') {
1.171 raeburn 16366: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 16367: }
16368: }
16369: }
1.171 raeburn 16370: }
16371: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
16372: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
16373: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
16374: $defaultshash{'loadbalancing'} = {};
16375: }
16376: my $putresult = &Apache::lonnet::put_dom('configuration',
16377: \%defaultshash,$dom);
16378: if ($putresult eq 'ok') {
16379: if (keys(%changes) > 0) {
1.252 raeburn 16380: my %toupdate;
1.171 raeburn 16381: if (ref($changes{'delete'}) eq 'ARRAY') {
16382: foreach my $balancer (sort(@{$changes{'delete'}})) {
16383: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 16384: $toupdate{$balancer} = 1;
1.150 raeburn 16385: }
1.171 raeburn 16386: }
16387: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 16388: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 16389: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 16390: $toupdate{$balancer} = 1;
1.171 raeburn 16391: }
16392: }
16393: if (ref($changes{'curr'}) eq 'HASH') {
16394: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 16395: $toupdate{$balancer} = 1;
1.171 raeburn 16396: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
16397: if ($changes{'curr'}{$balancer}{'targets'}) {
16398: my %offloadstr;
16399: foreach my $sparetype (@sparestypes) {
16400: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16401: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16402: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
16403: }
16404: }
1.150 raeburn 16405: }
1.171 raeburn 16406: if (keys(%offloadstr) == 0) {
16407: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 16408: } else {
1.171 raeburn 16409: my $showoffload;
16410: foreach my $sparetype (@sparestypes) {
16411: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
16412: if (defined($offloadstr{$sparetype})) {
16413: $showoffload .= $offloadstr{$sparetype};
16414: } else {
16415: $showoffload .= &mt('None');
16416: }
16417: $showoffload .= (' 'x3);
16418: }
16419: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 16420: }
16421: }
16422: }
1.171 raeburn 16423: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
16424: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
16425: foreach my $type (@{$alltypes}) {
16426: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
16427: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
16428: my $balancetext;
16429: if ($rule eq '') {
16430: $balancetext = $ruletitles{'default'};
1.209 raeburn 16431: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 16432: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 16433: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 16434: foreach my $sparetype (@sparestypes) {
16435: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16436: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
16437: }
16438: }
1.253 raeburn 16439: foreach my $item (@{$alltypes}) {
16440: next if ($item =~ /^_LC_ipchange/);
16441: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
16442: if ($hasrule eq 'homeserver') {
16443: map { $toupdate{$_} = 1; } (keys(%libraryservers));
16444: } else {
16445: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
16446: if ($servers{$hasrule}) {
16447: $toupdate{$hasrule} = 1;
16448: }
16449: }
16450: }
16451: }
1.254 raeburn 16452: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
16453: $balancetext = $ruletitles{$rule};
16454: } else {
16455: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
16456: $balancetext = $ruletitles{'particular'}.' '.$receiver;
16457: if ($receiver) {
16458: $toupdate{$receiver};
16459: }
16460: }
16461: } else {
16462: $balancetext = $ruletitles{$rule};
1.252 raeburn 16463: }
1.171 raeburn 16464: } else {
16465: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
16466: }
1.210 raeburn 16467: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 16468: }
16469: }
16470: }
16471: }
1.252 raeburn 16472: if (keys(%toupdate)) {
16473: my %thismachine;
16474: my $updatedhere;
16475: my $cachetime = 60*60*24;
16476: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
16477: foreach my $lonhost (keys(%toupdate)) {
16478: if ($thismachine{$lonhost}) {
16479: unless ($updatedhere) {
16480: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
16481: $defaultshash{'loadbalancing'},
16482: $cachetime);
16483: $updatedhere = 1;
16484: }
16485: } else {
16486: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
16487: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
16488: }
16489: }
16490: }
1.150 raeburn 16491: }
1.171 raeburn 16492: }
16493: if ($resulttext ne '') {
16494: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 16495: } else {
16496: $resulttext = $nochgmsg;
16497: }
16498: } else {
1.171 raeburn 16499: $resulttext = $nochgmsg;
1.150 raeburn 16500: }
16501: } else {
1.171 raeburn 16502: $resulttext = '<span class="LC_error">'.
16503: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 16504: }
16505: } else {
1.171 raeburn 16506: $resulttext = $nochgmsg;
1.150 raeburn 16507: }
16508: return $resulttext;
16509: }
16510:
1.48 raeburn 16511: sub recurse_check {
16512: my ($chkcats,$categories,$depth,$name) = @_;
16513: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
16514: my $chg = 0;
16515: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
16516: my $category = $chkcats->[$depth]{$name}[$j];
16517: my $item;
16518: if ($category eq '') {
16519: $chg ++;
16520: } else {
16521: my $deeper = $depth + 1;
16522: $item = &escape($category).':'.&escape($name).':'.$depth;
16523: if ($chg) {
16524: $categories->{$item} -= $chg;
16525: }
16526: &recurse_check($chkcats,$categories,$deeper,$category);
16527: $deeper --;
16528: }
16529: }
16530: }
16531: return;
16532: }
16533:
16534: sub recurse_cat_deletes {
16535: my ($item,$coursecategories,$deletions) = @_;
16536: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
16537: my $subdepth = $depth + 1;
16538: if (ref($coursecategories) eq 'HASH') {
16539: foreach my $subitem (keys(%{$coursecategories})) {
16540: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
16541: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
16542: delete($coursecategories->{$subitem});
16543: $deletions->{$subitem} = 1;
16544: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 16545: }
1.48 raeburn 16546: }
16547: }
16548: return;
16549: }
16550:
1.125 raeburn 16551: sub active_dc_picker {
1.191 raeburn 16552: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 16553: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 16554: my @domcoord = keys(%domcoords);
16555: if (keys(%currhash)) {
16556: foreach my $dc (keys(%currhash)) {
16557: unless (exists($domcoords{$dc})) {
16558: push(@domcoord,$dc);
16559: }
16560: }
16561: }
16562: @domcoord = sort(@domcoord);
1.210 raeburn 16563: my $numdcs = scalar(@domcoord);
1.191 raeburn 16564: my $rows = 0;
16565: my $table;
1.125 raeburn 16566: if ($numdcs > 1) {
1.191 raeburn 16567: $table = '<table>';
16568: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 16569: my $rem = $i%($numinrow);
16570: if ($rem == 0) {
16571: if ($i > 0) {
1.191 raeburn 16572: $table .= '</tr>';
1.125 raeburn 16573: }
1.191 raeburn 16574: $table .= '<tr>';
16575: $rows ++;
1.125 raeburn 16576: }
1.191 raeburn 16577: my $check = '';
16578: if ($inputtype eq 'radio') {
16579: if (keys(%currhash) == 0) {
16580: if (!$i) {
16581: $check = ' checked="checked"';
16582: }
16583: } elsif (exists($currhash{$domcoord[$i]})) {
16584: $check = ' checked="checked"';
16585: }
16586: } else {
16587: if (exists($currhash{$domcoord[$i]})) {
16588: $check = ' checked="checked"';
1.125 raeburn 16589: }
16590: }
1.191 raeburn 16591: if ($i == @domcoord - 1) {
1.125 raeburn 16592: my $colsleft = $numinrow - $rem;
16593: if ($colsleft > 1) {
1.191 raeburn 16594: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 16595: } else {
1.191 raeburn 16596: $table .= '<td class="LC_left_item">';
1.125 raeburn 16597: }
16598: } else {
1.191 raeburn 16599: $table .= '<td class="LC_left_item">';
16600: }
16601: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
16602: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
16603: $table .= '<span class="LC_nobreak"><label>'.
16604: '<input type="'.$inputtype.'" name="'.$name.'"'.
16605: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
16606: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 16607: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 16608: }
1.219 raeburn 16609: $table .= '</label></span></td>';
1.191 raeburn 16610: }
16611: $table .= '</tr></table>';
16612: } elsif ($numdcs == 1) {
1.219 raeburn 16613: my ($dcname,$dcdom) = split(':',$domcoord[0]);
16614: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 16615: if ($inputtype eq 'radio') {
1.247 raeburn 16616: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 16617: if ($user ne $dcname.':'.$dcdom) {
16618: $table .= ' ('.$dcname.':'.$dcdom.')';
16619: }
1.191 raeburn 16620: } else {
16621: my $check;
16622: if (exists($currhash{$domcoord[0]})) {
16623: $check = ' checked="checked"';
1.125 raeburn 16624: }
1.247 raeburn 16625: $table = '<span class="LC_nobreak"><label>'.
16626: '<input type="checkbox" name="'.$name.'" '.
16627: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 16628: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 16629: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 16630: }
1.220 raeburn 16631: $table .= '</label></span>';
1.191 raeburn 16632: $rows ++;
1.125 raeburn 16633: }
16634: }
1.191 raeburn 16635: return ($numdcs,$table,$rows);
1.125 raeburn 16636: }
16637:
1.137 raeburn 16638: sub usersession_titles {
16639: return &Apache::lonlocal::texthash(
16640: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
16641: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 16642: spares => 'Servers offloaded to, when busy',
1.137 raeburn 16643: version => 'LON-CAPA version requirement',
1.138 raeburn 16644: excludedomain => 'Allow all, but exclude specific domains',
16645: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 16646: primary => 'Primary (checked first)',
1.154 raeburn 16647: default => 'Default',
1.137 raeburn 16648: );
16649: }
16650:
1.152 raeburn 16651: sub id_for_thisdom {
16652: my (%servers) = @_;
16653: my %altids;
16654: foreach my $server (keys(%servers)) {
16655: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
16656: if ($serverhome ne $server) {
16657: $altids{$serverhome} = $server;
16658: }
16659: }
16660: return %altids;
16661: }
16662:
1.150 raeburn 16663: sub count_servers {
16664: my ($currbalancer,%servers) = @_;
16665: my (@spares,$numspares);
16666: foreach my $lonhost (sort(keys(%servers))) {
16667: next if ($currbalancer eq $lonhost);
16668: push(@spares,$lonhost);
16669: }
16670: if ($currbalancer) {
16671: $numspares = scalar(@spares);
16672: } else {
16673: $numspares = scalar(@spares) - 1;
16674: }
16675: return ($numspares,@spares);
16676: }
16677:
16678: sub lonbalance_targets_js {
1.171 raeburn 16679: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 16680: my $select = &mt('Select');
16681: my ($alltargets,$allishome,$allinsttypes,@alltypes);
16682: if (ref($servers) eq 'HASH') {
16683: $alltargets = join("','",sort(keys(%{$servers})));
16684: my @homedoms;
16685: foreach my $server (sort(keys(%{$servers}))) {
16686: if (&Apache::lonnet::host_domain($server) eq $dom) {
16687: push(@homedoms,'1');
16688: } else {
16689: push(@homedoms,'0');
16690: }
16691: }
16692: $allishome = join("','",@homedoms);
16693: }
16694: if (ref($types) eq 'ARRAY') {
16695: if (@{$types} > 0) {
16696: @alltypes = @{$types};
16697: }
16698: }
16699: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
16700: $allinsttypes = join("','",@alltypes);
1.171 raeburn 16701: my (%currbalancer,%currtargets,%currrules,%existing);
16702: if (ref($settings) eq 'HASH') {
16703: %existing = %{$settings};
16704: }
16705: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
16706: \%currtargets,\%currrules);
1.210 raeburn 16707: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 16708: return <<"END";
16709:
16710: <script type="text/javascript">
16711: // <![CDATA[
16712:
1.171 raeburn 16713: currBalancers = new Array('$balancers');
16714:
16715: function toggleTargets(balnum) {
16716: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
16717: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
16718: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
16719: var prevbalancer = prevhostitem.value;
16720: var baltotal = document.getElementById('loadbalancing_total').value;
16721: prevhostitem.value = balancer;
16722: if (prevbalancer != '') {
16723: var prevIdx = currBalancers.indexOf(prevbalancer);
16724: if (prevIdx != -1) {
16725: currBalancers.splice(prevIdx,1);
16726: }
16727: }
1.150 raeburn 16728: if (balancer == '') {
1.171 raeburn 16729: hideSpares(balnum);
1.150 raeburn 16730: } else {
1.171 raeburn 16731: var currIdx = currBalancers.indexOf(balancer);
16732: if (currIdx == -1) {
16733: currBalancers.push(balancer);
16734: }
1.150 raeburn 16735: var homedoms = new Array('$allishome');
1.171 raeburn 16736: var ishomedom = homedoms[lonhostitem.selectedIndex];
16737: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 16738: }
1.171 raeburn 16739: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 16740: return;
16741: }
16742:
1.171 raeburn 16743: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 16744: var alltargets = new Array('$alltargets');
16745: var insttypes = new Array('$allinsttypes');
1.151 raeburn 16746: var offloadtypes = new Array('primary','default');
16747:
1.171 raeburn 16748: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
16749: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 16750:
1.151 raeburn 16751: for (var i=0; i<offloadtypes.length; i++) {
16752: var count = 0;
16753: for (var j=0; j<alltargets.length; j++) {
16754: if (alltargets[j] != balancer) {
1.171 raeburn 16755: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
16756: item.value = alltargets[j];
16757: item.style.textAlign='left';
16758: item.style.textFace='normal';
16759: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
16760: if (currBalancers.indexOf(alltargets[j]) == -1) {
16761: item.disabled = '';
16762: } else {
16763: item.disabled = 'disabled';
16764: item.checked = false;
16765: }
1.151 raeburn 16766: count ++;
16767: }
1.150 raeburn 16768: }
16769: }
1.151 raeburn 16770: for (var k=0; k<insttypes.length; k++) {
16771: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 16772: if (ishomedom == 1) {
1.171 raeburn 16773: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
16774: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 16775: } else {
1.171 raeburn 16776: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
16777: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 16778: }
16779: } else {
1.171 raeburn 16780: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
16781: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 16782: }
1.151 raeburn 16783: if ((insttypes[k] != '_LC_external') &&
16784: ((insttypes[k] != '_LC_internetdom') ||
16785: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 16786: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
16787: item.options.length = 0;
16788: item.options[0] = new Option("","",true,true);
1.210 raeburn 16789: var idx = 0;
1.151 raeburn 16790: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 16791: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
16792: idx ++;
16793: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 16794: }
16795: }
16796: }
16797: }
16798: return;
16799: }
16800:
1.171 raeburn 16801: function hideSpares(balnum) {
1.150 raeburn 16802: var alltargets = new Array('$alltargets');
16803: var insttypes = new Array('$allinsttypes');
16804: var offloadtypes = new Array('primary','default');
16805:
1.171 raeburn 16806: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
16807: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 16808:
16809: var total = alltargets.length - 1;
16810: for (var i=0; i<offloadtypes; i++) {
16811: for (var j=0; j<total; j++) {
1.171 raeburn 16812: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
16813: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
16814: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 16815: }
1.150 raeburn 16816: }
16817: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 16818: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
16819: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 16820: if (insttypes[k] != '_LC_external') {
1.171 raeburn 16821: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
16822: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 16823: }
16824: }
16825: return;
16826: }
16827:
1.171 raeburn 16828: function checkOffloads(item,balnum,type) {
1.150 raeburn 16829: var alltargets = new Array('$alltargets');
16830: var offloadtypes = new Array('primary','default');
16831: if (item.checked) {
16832: var total = alltargets.length - 1;
16833: var other;
16834: if (type == offloadtypes[0]) {
1.151 raeburn 16835: other = offloadtypes[1];
1.150 raeburn 16836: } else {
1.151 raeburn 16837: other = offloadtypes[0];
1.150 raeburn 16838: }
16839: for (var i=0; i<total; i++) {
1.171 raeburn 16840: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 16841: if (server == item.value) {
1.171 raeburn 16842: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
16843: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 16844: }
16845: }
16846: }
16847: }
16848: return;
16849: }
16850:
1.171 raeburn 16851: function singleServerToggle(balnum,type) {
16852: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 16853: if (offloadtoSelIdx == 0) {
1.171 raeburn 16854: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
16855: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 16856:
16857: } else {
1.171 raeburn 16858: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
16859: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 16860: }
16861: return;
16862: }
16863:
1.171 raeburn 16864: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 16865: if (type == '_LC_external') {
1.171 raeburn 16866: return;
1.150 raeburn 16867: }
1.171 raeburn 16868: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 16869: for (var i=0; i<typesRules.length; i++) {
16870: if (formname.elements[typesRules[i]].checked) {
16871: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 16872: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
16873: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 16874: } else {
1.171 raeburn 16875: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
16876: }
16877: }
16878: }
16879: return;
16880: }
16881:
16882: function balancerDeleteChange(balnum) {
16883: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
16884: var baltotal = document.getElementById('loadbalancing_total').value;
16885: var addtarget;
16886: var removetarget;
16887: var action = 'delete';
16888: if (document.getElementById('loadbalancing_delete_'+balnum)) {
16889: var lonhost = hostitem.value;
16890: var currIdx = currBalancers.indexOf(lonhost);
16891: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
16892: if (currIdx != -1) {
16893: currBalancers.splice(currIdx,1);
16894: }
16895: addtarget = lonhost;
16896: } else {
16897: if (currIdx == -1) {
16898: currBalancers.push(lonhost);
16899: }
16900: removetarget = lonhost;
16901: action = 'undelete';
16902: }
16903: balancerChange(balnum,baltotal,action,addtarget,removetarget);
16904: }
16905: return;
16906: }
16907:
16908: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
16909: if (baltotal > 1) {
16910: var offloadtypes = new Array('primary','default');
16911: var alltargets = new Array('$alltargets');
16912: var insttypes = new Array('$allinsttypes');
16913: for (var i=0; i<baltotal; i++) {
16914: if (i != balnum) {
16915: for (var j=0; j<offloadtypes.length; j++) {
16916: var total = alltargets.length - 1;
16917: for (var k=0; k<total; k++) {
16918: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
16919: var server = serveritem.value;
16920: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
16921: if (server == addtarget) {
16922: serveritem.disabled = '';
16923: }
16924: }
16925: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
16926: if (server == removetarget) {
16927: serveritem.disabled = 'disabled';
16928: serveritem.checked = false;
16929: }
16930: }
16931: }
16932: }
16933: for (var j=0; j<insttypes.length; j++) {
16934: if (insttypes[j] != '_LC_external') {
16935: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
16936: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
16937: var currSel = singleserver.selectedIndex;
16938: var currVal = singleserver.options[currSel].value;
16939: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
16940: var numoptions = singleserver.options.length;
16941: var needsnew = 1;
16942: for (var k=0; k<numoptions; k++) {
16943: if (singleserver.options[k] == addtarget) {
16944: needsnew = 0;
16945: break;
16946: }
16947: }
16948: if (needsnew == 1) {
16949: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
16950: }
16951: }
16952: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
16953: singleserver.options.length = 0;
16954: if ((currVal) && (currVal != removetarget)) {
16955: singleserver.options[0] = new Option("","",false,false);
16956: } else {
16957: singleserver.options[0] = new Option("","",true,true);
16958: }
16959: var idx = 0;
16960: for (var m=0; m<alltargets.length; m++) {
16961: if (currBalancers.indexOf(alltargets[m]) == -1) {
16962: idx ++;
16963: if (currVal == alltargets[m]) {
16964: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
16965: } else {
16966: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
16967: }
16968: }
16969: }
16970: }
16971: }
16972: }
16973: }
1.150 raeburn 16974: }
16975: }
16976: }
16977: return;
16978: }
16979:
1.152 raeburn 16980: // ]]>
16981: </script>
16982:
16983: END
16984: }
16985:
16986: sub new_spares_js {
16987: my @sparestypes = ('primary','default');
16988: my $types = join("','",@sparestypes);
16989: my $select = &mt('Select');
16990: return <<"END";
16991:
16992: <script type="text/javascript">
16993: // <![CDATA[
16994:
16995: function updateNewSpares(formname,lonhost) {
16996: var types = new Array('$types');
16997: var include = new Array();
16998: var exclude = new Array();
16999: for (var i=0; i<types.length; i++) {
17000: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
17001: for (var j=0; j<spareboxes.length; j++) {
17002: if (formname.elements[spareboxes[j]].checked) {
17003: exclude.push(formname.elements[spareboxes[j]].value);
17004: } else {
17005: include.push(formname.elements[spareboxes[j]].value);
17006: }
17007: }
17008: }
17009: for (var i=0; i<types.length; i++) {
17010: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
17011: var selIdx = newSpare.selectedIndex;
17012: var currnew = newSpare.options[selIdx].value;
17013: var okSpares = new Array();
17014: for (var j=0; j<newSpare.options.length; j++) {
17015: var possible = newSpare.options[j].value;
17016: if (possible != '') {
17017: if (exclude.indexOf(possible) == -1) {
17018: okSpares.push(possible);
17019: } else {
17020: if (currnew == possible) {
17021: selIdx = 0;
17022: }
17023: }
17024: }
17025: }
17026: for (var k=0; k<include.length; k++) {
17027: if (okSpares.indexOf(include[k]) == -1) {
17028: okSpares.push(include[k]);
17029: }
17030: }
17031: okSpares.sort();
17032: newSpare.options.length = 0;
17033: if (selIdx == 0) {
17034: newSpare.options[0] = new Option("$select","",true,true);
17035: } else {
17036: newSpare.options[0] = new Option("$select","",false,false);
17037: }
17038: for (var m=0; m<okSpares.length; m++) {
17039: var idx = m+1;
17040: var selThis = 0;
17041: if (selIdx != 0) {
17042: if (okSpares[m] == currnew) {
17043: selThis = 1;
17044: }
17045: }
17046: if (selThis == 1) {
17047: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
17048: } else {
17049: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
17050: }
17051: }
17052: }
17053: return;
17054: }
17055:
17056: function checkNewSpares(lonhost,type) {
17057: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
17058: var chosen = newSpare.options[newSpare.selectedIndex].value;
17059: if (chosen != '') {
17060: var othertype;
17061: var othernewSpare;
17062: if (type == 'primary') {
17063: othernewSpare = document.getElementById('newspare_default_'+lonhost);
17064: }
17065: if (type == 'default') {
17066: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
17067: }
17068: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
17069: othernewSpare.selectedIndex = 0;
17070: }
17071: }
17072: return;
17073: }
17074:
17075: // ]]>
17076: </script>
17077:
17078: END
17079:
17080: }
17081:
17082: sub common_domprefs_js {
17083: return <<"END";
17084:
17085: <script type="text/javascript">
17086: // <![CDATA[
17087:
1.150 raeburn 17088: function getIndicesByName(formname,item) {
1.152 raeburn 17089: var group = new Array();
1.150 raeburn 17090: for (var i=0;i<formname.elements.length;i++) {
17091: if (formname.elements[i].name == item) {
1.152 raeburn 17092: group.push(formname.elements[i].id);
1.150 raeburn 17093: }
17094: }
1.152 raeburn 17095: return group;
1.150 raeburn 17096: }
17097:
17098: // ]]>
17099: </script>
17100:
17101: END
1.152 raeburn 17102:
1.150 raeburn 17103: }
17104:
1.165 raeburn 17105: sub recaptcha_js {
17106: my %lt = &captcha_phrases();
17107: return <<"END";
17108:
17109: <script type="text/javascript">
17110: // <![CDATA[
17111:
17112: function updateCaptcha(caller,context) {
17113: var privitem;
17114: var pubitem;
17115: var privtext;
17116: var pubtext;
1.269 raeburn 17117: var versionitem;
17118: var versiontext;
1.165 raeburn 17119: if (document.getElementById(context+'_recaptchapub')) {
17120: pubitem = document.getElementById(context+'_recaptchapub');
17121: } else {
17122: return;
17123: }
17124: if (document.getElementById(context+'_recaptchapriv')) {
17125: privitem = document.getElementById(context+'_recaptchapriv');
17126: } else {
17127: return;
17128: }
17129: if (document.getElementById(context+'_recaptchapubtxt')) {
17130: pubtext = document.getElementById(context+'_recaptchapubtxt');
17131: } else {
17132: return;
17133: }
17134: if (document.getElementById(context+'_recaptchaprivtxt')) {
17135: privtext = document.getElementById(context+'_recaptchaprivtxt');
17136: } else {
17137: return;
17138: }
1.269 raeburn 17139: if (document.getElementById(context+'_recaptchaversion')) {
17140: versionitem = document.getElementById(context+'_recaptchaversion');
17141: } else {
17142: return;
17143: }
17144: if (document.getElementById(context+'_recaptchavertxt')) {
17145: versiontext = document.getElementById(context+'_recaptchavertxt');
17146: } else {
17147: return;
17148: }
1.165 raeburn 17149: if (caller.checked) {
17150: if (caller.value == 'recaptcha') {
17151: pubitem.type = 'text';
17152: privitem.type = 'text';
17153: pubitem.size = '40';
17154: privitem.size = '40';
17155: pubtext.innerHTML = "$lt{'pub'}";
17156: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 17157: versionitem.type = 'text';
17158: versionitem.size = '3';
1.289 raeburn 17159: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 17160: } else {
17161: pubitem.type = 'hidden';
17162: privitem.type = 'hidden';
1.269 raeburn 17163: versionitem.type = 'hidden';
1.165 raeburn 17164: pubtext.innerHTML = '';
17165: privtext.innerHTML = '';
1.269 raeburn 17166: versiontext.innerHTML = '';
1.165 raeburn 17167: }
17168: }
17169: return;
17170: }
17171:
17172: // ]]>
17173: </script>
17174:
17175: END
17176:
17177: }
17178:
1.236 raeburn 17179: sub toggle_display_js {
1.192 raeburn 17180: return <<"END";
17181:
17182: <script type="text/javascript">
17183: // <![CDATA[
17184:
1.236 raeburn 17185: function toggleDisplay(domForm,caller) {
17186: if (document.getElementById(caller)) {
17187: var divitem = document.getElementById(caller);
17188: var optionsElement = domForm.coursecredits;
1.264 raeburn 17189: var checkval = 1;
17190: var dispval = 'block';
1.303 raeburn 17191: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 17192: if (caller == 'emailoptions') {
17193: optionsElement = domForm.cancreate_email;
17194: }
1.257 raeburn 17195: if (caller == 'studentsubmission') {
17196: optionsElement = domForm.postsubmit;
17197: }
1.264 raeburn 17198: if (caller == 'cloneinstcode') {
17199: optionsElement = domForm.canclone;
17200: checkval = 'instcode';
17201: }
1.303 raeburn 17202: if (selfcreateRegExp.test(caller)) {
17203: optionsElement = domForm.elements[caller];
17204: checkval = 'other';
17205: dispval = 'inline'
17206: }
1.236 raeburn 17207: if (optionsElement.length) {
1.192 raeburn 17208: var currval;
1.236 raeburn 17209: for (var i=0; i<optionsElement.length; i++) {
17210: if (optionsElement[i].checked) {
17211: currval = optionsElement[i].value;
1.192 raeburn 17212: }
17213: }
1.264 raeburn 17214: if (currval == checkval) {
17215: divitem.style.display = dispval;
1.192 raeburn 17216: } else {
1.236 raeburn 17217: divitem.style.display = 'none';
1.192 raeburn 17218: }
17219: }
17220: }
17221: return;
17222: }
17223:
17224: // ]]>
17225: </script>
17226:
17227: END
17228:
17229: }
17230:
1.165 raeburn 17231: sub captcha_phrases {
17232: return &Apache::lonlocal::texthash (
17233: priv => 'Private key',
17234: pub => 'Public key',
17235: original => 'original (CAPTCHA)',
17236: recaptcha => 'successor (ReCAPTCHA)',
17237: notused => 'unused',
1.289 raeburn 17238: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 17239: );
17240: }
17241:
1.205 raeburn 17242: sub devalidate_remote_domconfs {
1.212 raeburn 17243: my ($dom,$cachekeys) = @_;
17244: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 17245: my %servers = &Apache::lonnet::internet_dom_servers($dom);
17246: my %thismachine;
17247: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.295 raeburn 17248: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
1.260 raeburn 17249: if (keys(%servers)) {
1.205 raeburn 17250: foreach my $server (keys(%servers)) {
17251: next if ($thismachine{$server});
1.212 raeburn 17252: my @cached;
17253: foreach my $name (@posscached) {
17254: if ($cachekeys->{$name}) {
17255: push(@cached,&escape($name).':'.&escape($dom));
17256: }
17257: }
17258: if (@cached) {
17259: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
17260: }
1.205 raeburn 17261: }
17262: }
17263: return;
17264: }
17265:
1.3 raeburn 17266: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>