Annotation of loncom/interface/domainprefs.pm, revision 1.279
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.279 ! raeburn 4: # $Id: domainprefs.pm,v 1.278 2016/09/11 14:51:42 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
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
1.101 raeburn 31: =pod
32:
33: =head1 NAME
34:
35: Apache::domainprefs.pm
36:
37: =head1 SYNOPSIS
38:
39: Handles configuration of a LON-CAPA domain.
40:
41: This is part of the LearningOnline Network with CAPA project
42: described at http://www.lon-capa.org.
43:
44:
45: =head1 OVERVIEW
46:
47: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 48: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 49: may define a default set of logos and a color scheme which can be used to "brand"
50: the LON-CAPA instance. In addition, an institution will typically have a language
51: and timezone which are used for the majority of courses.
52:
53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
54: host of other domain-wide settings which determine the types of functionality
55: available to users and courses in the domain.
56:
57: There is also a mechanism to configure cataloging of courses in the domain, and
58: controls on the operation of automated processes which govern such things as
59: roster updates, user directory updates and processing of course requests.
60:
61: The domain coordination manual which is built dynamically on install/update of
62: LON-CAPA from the relevant help items provides more information about domain
63: configuration.
64:
65: Most of the domain settings are stored in the configuration.db GDBM file which is
66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
67: where $dom is the domain. The configuration.db stores settings in a number of
68: frozen hashes of hashes. In a few cases, domain information must be uploaded to
69: the domain as files (e.g., image files for logos etc., or plain text files for
70: bubblesheet formats). In this case the domainprefs.pm must be running in a user
71: session hosted on the primary library server in the domain, as these files are
72: stored in author space belonging to a special $dom-domainconfig user.
73:
74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
75: the current settings, and provides an interface to make modifications.
76:
77: =head1 SUBROUTINES
78:
79: =over
80:
81: =item print_quotas()
82:
83: Inputs: 4
84:
85: $dom,$settings,$rowtotal,$action.
86:
87: $dom is the domain, $settings is a reference to a hash of current settings for
88: the current context, $rowtotal is a reference to the scalar used to record the
1.210 raeburn 89: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 90: requestcourses or requestauthor).
1.101 raeburn 91:
92: The print_quotas routine was orginally created to display/store information
93: about default quota sizes for portfolio spaces for the different types of
94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
95: but is now also used to manage availability of user tools:
96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.197 raeburn 97: used by course owners to request creation of a course, and to display/store
1.223 bisitz 98: default quota sizes for Authoring Spaces.
1.101 raeburn 99:
100: Outputs: 1
101:
102: $datatable - HTML containing form elements which allow settings to be changed.
103:
104: In the case of course requests, radio buttons are displayed for each institutional
105: affiliate type (and also default, and _LC_adv) for each of the course types
1.271 raeburn 106: (official, unofficial, community, textbook, and placement).
107: In each case the radio buttons allow the selection of one of four values:
1.101 raeburn 108:
1.104 raeburn 109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 110: which have the following effects:
111:
112: 0
113:
114: =over
115:
116: - course requests are not allowed for this course types/affiliation
117:
118: =back
119:
1.104 raeburn 120: approval
1.101 raeburn 121:
122: =over
123:
124: - course requests must be approved by a Doman Coordinator in the
125: course's domain
126:
127: =back
128:
129: validate
130:
131: =over
132:
133: - an institutional validation (e.g., check requestor is instructor
134: of record) needs to be passed before the course will be created. The required
135: validation is in localenroll.pm on the primary library server for the course
136: domain.
137:
138: =back
139:
140: autolimit
141:
142: =over
143:
1.143 raeburn 144: - course requests will be processed automatically up to a limit of
1.101 raeburn 145: N requests for the course type for the particular requestor.
146: If N is undefined, there is no limit to the number of course requests
147: which a course owner may submit and have processed automatically.
148:
149: =back
150:
151: =item modify_quotas()
152:
153: =back
154:
155: =cut
156:
1.1 raeburn 157: package Apache::domainprefs;
158:
159: use strict;
160: use Apache::Constants qw(:common :http);
161: use Apache::lonnet;
162: use Apache::loncommon();
163: use Apache::lonhtmlcommon();
164: use Apache::lonlocal;
1.43 raeburn 165: use Apache::lonmsg();
1.91 raeburn 166: use Apache::lonconfigsettings;
1.232 raeburn 167: use Apache::lonuserutils();
1.235 raeburn 168: use Apache::loncoursequeueadmin();
1.69 raeburn 169: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 170: use LONCAPA::Enrollment;
1.81 raeburn 171: use LONCAPA::lonauthcgi();
1.275 raeburn 172: use LONCAPA::SSL;
1.9 raeburn 173: use File::Copy;
1.43 raeburn 174: use Locale::Language;
1.62 raeburn 175: use DateTime::TimeZone;
1.68 raeburn 176: use DateTime::Locale;
1.267 raeburn 177: use Time::HiRes qw( sleep );
1.1 raeburn 178:
1.155 raeburn 179: my $registered_cleanup;
180: my $modified_urls;
181:
1.1 raeburn 182: sub handler {
183: my $r=shift;
184: if ($r->header_only) {
185: &Apache::loncommon::content_type($r,'text/html');
186: $r->send_http_header;
187: return OK;
188: }
189:
1.91 raeburn 190: my $context = 'domain';
1.1 raeburn 191: my $dom = $env{'request.role.domain'};
1.5 albertel 192: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 193: if (&Apache::lonnet::allowed('mau',$dom)) {
194: &Apache::loncommon::content_type($r,'text/html');
195: $r->send_http_header;
196: } else {
197: $env{'user.error.msg'}=
198: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
199: return HTTP_NOT_ACCEPTABLE;
200: }
1.155 raeburn 201:
202: $registered_cleanup=0;
203: @{$modified_urls}=();
204:
1.1 raeburn 205: &Apache::lonhtmlcommon::clear_breadcrumbs();
206: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 207: ['phase','actions']);
1.30 raeburn 208: my $phase = 'pickactions';
1.3 raeburn 209: if ( exists($env{'form.phase'}) ) {
210: $phase = $env{'form.phase'};
211: }
1.150 raeburn 212: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 213: my %domconfig =
1.6 raeburn 214: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 215: 'quotas','autoenroll','autoupdate','autocreate',
216: 'directorysrch','usercreation','usermodification',
217: 'contacts','defaults','scantron','coursecategories',
218: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 219: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 220: 'requestauthor','selfenrollment','inststatus',
1.279 ! raeburn 221: 'ltitools','ssl','trust'],$dom);
1.43 raeburn 222: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 223: 'autoupdate','autocreate','directorysrch','contacts',
1.224 raeburn 224: 'usercreation','selfcreation','usermodification','scantron',
1.163 raeburn 225: 'requestcourses','requestauthor','coursecategories',
1.267 raeburn 226: 'serverstatuses','helpsettings','coursedefaults',
1.279 ! raeburn 227: 'ltitools','selfenrollment','usersessions','ssl','trust');
1.171 raeburn 228: my %existing;
229: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
230: %existing = %{$domconfig{'loadbalancing'}};
231: }
232: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 233: push(@prefs_order,'loadbalancing');
234: }
1.30 raeburn 235: my %prefs = (
236: 'rolecolors' =>
237: { text => 'Default color schemes',
1.67 raeburn 238: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 239: header => [{col1 => 'Student Settings',
240: col2 => '',},
241: {col1 => 'Coordinator Settings',
242: col2 => '',},
243: {col1 => 'Author Settings',
244: col2 => '',},
245: {col1 => 'Administrator Settings',
246: col2 => '',}],
1.230 raeburn 247: print => \&print_rolecolors,
248: modify => \&modify_rolecolors,
1.30 raeburn 249: },
1.110 raeburn 250: 'login' =>
1.30 raeburn 251: { text => 'Log-in page options',
1.67 raeburn 252: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 253: header => [{col1 => 'Log-in Page Items',
254: col2 => '',},
255: {col1 => 'Log-in Help',
1.256 raeburn 256: col2 => 'Value'},
257: {col1 => 'Custom HTML in document head',
1.168 raeburn 258: col2 => 'Value'}],
1.230 raeburn 259: print => \&print_login,
260: modify => \&modify_login,
1.30 raeburn 261: },
1.43 raeburn 262: 'defaults' =>
1.236 raeburn 263: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 264: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 265: header => [{col1 => 'Setting',
1.236 raeburn 266: col2 => 'Value'},
267: {col1 => 'Institutional user types',
268: col2 => 'Assignable to e-mail usernames'}],
1.230 raeburn 269: print => \&print_defaults,
270: modify => \&modify_defaults,
1.43 raeburn 271: },
1.30 raeburn 272: 'quotas' =>
1.197 raeburn 273: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 274: help => 'Domain_Configuration_Quotas',
1.77 raeburn 275: header => [{col1 => 'User affiliation',
1.72 raeburn 276: col2 => 'Available tools',
1.213 raeburn 277: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 278: print => \&print_quotas,
279: modify => \&modify_quotas,
1.30 raeburn 280: },
281: 'autoenroll' =>
282: { text => 'Auto-enrollment settings',
1.67 raeburn 283: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 284: header => [{col1 => 'Configuration setting',
285: col2 => 'Value(s)'}],
1.230 raeburn 286: print => \&print_autoenroll,
287: modify => \&modify_autoenroll,
1.30 raeburn 288: },
289: 'autoupdate' =>
290: { text => 'Auto-update settings',
1.67 raeburn 291: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 292: header => [{col1 => 'Setting',
293: col2 => 'Value',},
1.131 raeburn 294: {col1 => 'Setting',
295: col2 => 'Affiliation'},
1.43 raeburn 296: {col1 => 'User population',
1.227 bisitz 297: col2 => 'Updatable user data'}],
1.230 raeburn 298: print => \&print_autoupdate,
299: modify => \&modify_autoupdate,
1.30 raeburn 300: },
1.125 raeburn 301: 'autocreate' =>
302: { text => 'Auto-course creation settings',
303: help => 'Domain_Configuration_Auto_Creation',
304: header => [{col1 => 'Configuration Setting',
305: col2 => 'Value',}],
1.230 raeburn 306: print => \&print_autocreate,
307: modify => \&modify_autocreate,
1.125 raeburn 308: },
1.30 raeburn 309: 'directorysrch' =>
1.277 raeburn 310: { text => 'Directory searches',
1.67 raeburn 311: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 312: header => [{col1 => 'Institutional Directory Setting',
313: col2 => 'Value',},
314: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 315: col2 => 'Value',}],
1.230 raeburn 316: print => \&print_directorysrch,
317: modify => \&modify_directorysrch,
1.30 raeburn 318: },
319: 'contacts' =>
320: { text => 'Contact Information',
1.67 raeburn 321: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 322: header => [{col1 => 'Setting',
323: col2 => 'Value',}],
1.230 raeburn 324: print => \&print_contacts,
325: modify => \&modify_contacts,
1.30 raeburn 326: },
327: 'usercreation' =>
328: { text => 'User creation',
1.67 raeburn 329: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 330: header => [{col1 => 'Format rule type',
331: col2 => 'Format rules in force'},
1.34 raeburn 332: {col1 => 'User account creation',
333: col2 => 'Usernames which may be created',},
1.30 raeburn 334: {col1 => 'Context',
1.43 raeburn 335: col2 => 'Assignable authentication types'}],
1.230 raeburn 336: print => \&print_usercreation,
337: modify => \&modify_usercreation,
1.30 raeburn 338: },
1.224 raeburn 339: 'selfcreation' =>
340: { text => 'Users self-creating accounts',
341: help => 'Domain_Configuration_Self_Creation',
342: header => [{col1 => 'Self-creation with institutional username',
343: col2 => 'Enabled?'},
344: {col1 => 'Institutional user type (login/SSO self-creation)',
345: col2 => 'Information user can enter'},
346: {col1 => 'Self-creation with e-mail as username',
347: col2 => 'Settings'}],
1.230 raeburn 348: print => \&print_selfcreation,
349: modify => \&modify_selfcreation,
1.224 raeburn 350: },
1.69 raeburn 351: 'usermodification' =>
1.33 raeburn 352: { text => 'User modification',
1.67 raeburn 353: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 354: header => [{col1 => 'Target user has role',
1.227 bisitz 355: col2 => 'User information updatable in author context'},
1.33 raeburn 356: {col1 => 'Target user has role',
1.227 bisitz 357: col2 => 'User information updatable in course context'}],
1.230 raeburn 358: print => \&print_usermodification,
359: modify => \&modify_usermodification,
1.33 raeburn 360: },
1.69 raeburn 361: 'scantron' =>
1.95 www 362: { text => 'Bubblesheet format file',
1.67 raeburn 363: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 364: header => [ {col1 => 'Item',
365: col2 => '',
366: }],
1.230 raeburn 367: print => \&print_scantron,
368: modify => \&modify_scantron,
1.46 raeburn 369: },
1.86 raeburn 370: 'requestcourses' =>
371: {text => 'Request creation of courses',
372: help => 'Domain_Configuration_Request_Courses',
373: header => [{col1 => 'User affiliation',
1.102 raeburn 374: col2 => 'Availability/Processing of requests',},
375: {col1 => 'Setting',
1.216 raeburn 376: col2 => 'Value'},
377: {col1 => 'Available textbooks',
1.235 raeburn 378: col2 => ''},
1.242 raeburn 379: {col1 => 'Available templates',
380: col2 => ''},
1.235 raeburn 381: {col1 => 'Validation (not official courses)',
382: col2 => 'Value'},],
1.230 raeburn 383: print => \&print_quotas,
384: modify => \&modify_quotas,
1.86 raeburn 385: },
1.163 raeburn 386: 'requestauthor' =>
1.223 bisitz 387: {text => 'Request Authoring Space',
1.163 raeburn 388: help => 'Domain_Configuration_Request_Author',
389: header => [{col1 => 'User affiliation',
390: col2 => 'Availability/Processing of requests',},
391: {col1 => 'Setting',
392: col2 => 'Value'}],
1.230 raeburn 393: print => \&print_quotas,
394: modify => \&modify_quotas,
1.163 raeburn 395: },
1.69 raeburn 396: 'coursecategories' =>
1.120 raeburn 397: { text => 'Cataloging of courses/communities',
1.67 raeburn 398: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 399: header => [{col1 => 'Catalog type/availability',
400: col2 => '',},
401: {col1 => 'Category settings for standard catalog',
1.57 raeburn 402: col2 => '',},
403: {col1 => 'Categories',
404: col2 => '',
405: }],
1.230 raeburn 406: print => \&print_coursecategories,
407: modify => \&modify_coursecategories,
1.69 raeburn 408: },
409: 'serverstatuses' =>
1.77 raeburn 410: {text => 'Access to server status pages',
1.69 raeburn 411: help => 'Domain_Configuration_Server_Status',
412: header => [{col1 => 'Status Page',
413: col2 => 'Other named users',
414: col3 => 'Specific IPs',
415: }],
1.230 raeburn 416: print => \&print_serverstatuses,
417: modify => \&modify_serverstatuses,
1.69 raeburn 418: },
1.118 jms 419: 'helpsettings' =>
420: {text => 'Help page settings',
421: help => 'Domain_Configuration_Help_Settings',
1.166 raeburn 422: header => [{col1 => 'Help Settings (logged-in users)',
423: col2 => 'Value'}],
1.230 raeburn 424: print => \&print_helpsettings,
425: modify => \&modify_helpsettings,
1.118 jms 426: },
1.121 raeburn 427: 'coursedefaults' =>
428: {text => 'Course/Community defaults',
429: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 430: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
431: col2 => 'Value',},
432: {col1 => 'Defaults which can be overridden for each course by a DC',
433: col2 => 'Value',},],
1.230 raeburn 434: print => \&print_coursedefaults,
435: modify => \&modify_coursedefaults,
1.121 raeburn 436: },
1.231 raeburn 437: 'selfenrollment' =>
438: {text => 'Self-enrollment in Course/Community',
439: help => 'Domain_Configuration_Selfenrollment',
440: header => [{col1 => 'Configuration Rights',
441: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
442: {col1 => 'Defaults',
443: col2 => 'Value'},
444: {col1 => 'Self-enrollment validation (optional)',
445: col2 => 'Value'},],
446: print => \&print_selfenrollment,
447: modify => \&modify_selfenrollment,
448: },
1.120 raeburn 449: 'privacy' =>
450: {text => 'User Privacy',
451: help => 'Domain_Configuration_User_Privacy',
452: header => [{col1 => 'Setting',
453: col2 => 'Value',}],
1.230 raeburn 454: print => \&print_privacy,
455: modify => \&modify_privacy,
1.120 raeburn 456: },
1.141 raeburn 457: 'usersessions' =>
1.145 raeburn 458: {text => 'User session hosting/offloading',
1.137 raeburn 459: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 460: header => [{col1 => 'Domain server',
461: col2 => 'Servers to offload sessions to when busy'},
462: {col1 => 'Hosting of users from other domains',
1.137 raeburn 463: col2 => 'Rules'},
464: {col1 => "Hosting domain's own users elsewhere",
465: col2 => 'Rules'}],
1.230 raeburn 466: print => \&print_usersessions,
467: modify => \&modify_usersessions,
1.137 raeburn 468: },
1.279 ! raeburn 469: 'loadbalancing' =>
1.185 raeburn 470: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 471: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 472: header => [{col1 => 'Balancers',
1.150 raeburn 473: col2 => 'Default destinations',
1.183 bisitz 474: col3 => 'User affiliation',
1.150 raeburn 475: col4 => 'Overrides'},
476: ],
1.230 raeburn 477: print => \&print_loadbalancing,
478: modify => \&modify_loadbalancing,
1.150 raeburn 479: },
1.279 ! raeburn 480: 'ltitools' =>
1.267 raeburn 481: {text => 'External Tools (LTI)',
482: help => 'Domain_configuration_LTI_Tools',
483: header => [{col1 => 'Setting',
484: col2 => 'Value',}],
485: print => \&print_ltitools,
486: modify => \&modify_ltitools,
487: },
1.279 ! raeburn 488: 'ssl' =>
1.275 raeburn 489: {text => 'LON-CAPA Network (SSL)',
490: help => 'Domain_Configuration_Network_SSL',
491: header => [{col1 => 'Server',
492: col2 => 'Certificate Status'},
493: {col1 => 'Connections to other servers',
494: col2 => 'Rules'},
495: {col1 => "Replicating domain's published content",
496: col2 => 'Rules'}],
497: print => \&print_ssl,
498: modify => \&modify_ssl,
499: },
1.279 ! raeburn 500: 'trust' =>
! 501: {text => 'Trust Settings',
! 502: help => 'Domain_Configuration_Trust',
! 503: header => [{col1 => "Access to this domain's content by others",
! 504: col2 => 'Rules'},
! 505: {col1 => "Access to other domain's content by this domain",
! 506: col2 => 'Rules'},
! 507: {col1 => "Enrollment in this domain's courses by others",
! 508: col2 => 'Rules',},
! 509: {col1 => "Co-author roles in this domain for others",
! 510: col2 => 'Rules',},
! 511: {col1 => "Co-author roles for this domain's users elsewhere",
! 512: col2 => 'Rules',},
! 513: {col1 => "Domain roles in this domain assignable to others",
! 514: col2 => 'Rules'},
! 515: {col1 => "Course catalog for this domain displayed elsewhere",
! 516: col2 => 'Rules'},
! 517: {col1 => "Requests for creation of courses in this domain by others",
! 518: col2 => 'Rules'},
! 519: {col1 => "Users in other domains can send messages to this domain",
! 520: col2 => 'Rules'},],
! 521: print => \&print_trust,
! 522: modify => \&modify_trust,
! 523: },
1.3 raeburn 524: );
1.110 raeburn 525: if (keys(%servers) > 1) {
526: $prefs{'login'} = { text => 'Log-in page options',
527: help => 'Domain_Configuration_Login_Page',
528: header => [{col1 => 'Log-in Service',
529: col2 => 'Server Setting',},
530: {col1 => 'Log-in Page Items',
1.168 raeburn 531: col2 => ''},
532: {col1 => 'Log-in Help',
1.256 raeburn 533: col2 => 'Value'},
534: {col1 => 'Custom HTML in document head',
1.168 raeburn 535: col2 => 'Value'}],
1.230 raeburn 536: print => \&print_login,
537: modify => \&modify_login,
1.110 raeburn 538: };
539: }
1.174 foxr 540:
1.6 raeburn 541: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 542: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 543: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 544: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 545: text=>"Settings to display/modify"});
1.9 raeburn 546: my $confname = $dom.'-domainconfig';
1.174 foxr 547:
1.3 raeburn 548: if ($phase eq 'process') {
1.212 raeburn 549: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
550: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 551: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 552: $r->rflush();
1.212 raeburn 553: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 554: }
1.30 raeburn 555: } elsif ($phase eq 'display') {
1.192 raeburn 556: my $js = &recaptcha_js().
1.236 raeburn 557: &toggle_display_js();
1.171 raeburn 558: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 559: my ($othertitle,$usertypes,$types) =
560: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 561: $js .= &lonbalance_targets_js($dom,$types,\%servers,
562: $domconfig{'loadbalancing'}).
1.170 raeburn 563: &new_spares_js().
564: &common_domprefs_js().
565: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 566: }
1.216 raeburn 567: if (grep(/^requestcourses$/,@actions)) {
568: my $javascript_validations;
569: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
570: $js .= <<END;
571: <script type="text/javascript">
572: $javascript_validations
573: </script>
574: $coursebrowserjs
575: END
576: }
1.150 raeburn 577: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 578: } else {
1.180 raeburn 579: # check if domconfig user exists for the domain.
580: my $servadm = $r->dir_config('lonAdmEMail');
581: my ($configuserok,$author_ok,$switchserver) =
582: &config_check($dom,$confname,$servadm);
583: unless ($configuserok eq 'ok') {
1.181 raeburn 584: &Apache::lonconfigsettings::print_header($r,$phase,$context);
585: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 586: $confname).
1.181 raeburn 587: '<br />'
588: );
1.180 raeburn 589: if ($switchserver) {
1.181 raeburn 590: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
591: '<br />'.
592: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
593: '<br />'.
594: &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).
595: '<br />'.
596: &mt('To do that now, use the following link: [_1]',$switchserver)
597: );
598: } else {
599: $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.').
600: '<br />'.
601: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
602: );
1.180 raeburn 603: }
604: $r->print(&Apache::loncommon::end_page());
605: return OK;
606: }
1.21 raeburn 607: if (keys(%domconfig) == 0) {
608: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 609: my @ids=&Apache::lonnet::current_machine_ids();
610: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 611: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 612: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 613: my $custom_img_count = 0;
614: foreach my $img (@loginimages) {
615: if ($designhash{$dom.'.login.'.$img} ne '') {
616: $custom_img_count ++;
617: }
618: }
619: foreach my $role (@roles) {
620: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
621: $custom_img_count ++;
622: }
623: }
624: if ($custom_img_count > 0) {
1.94 raeburn 625: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 626: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 627: $r->print(
628: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
629: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
630: &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 />'.
631: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
632: if ($switch_server) {
1.30 raeburn 633: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 634: }
1.91 raeburn 635: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 636: return OK;
637: }
638: }
639: }
1.91 raeburn 640: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 641: }
642: return OK;
643: }
644:
645: sub process_changes {
1.205 raeburn 646: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 647: my %domconfig;
648: if (ref($values) eq 'HASH') {
649: %domconfig = %{$values};
650: }
1.3 raeburn 651: my $output;
652: if ($action eq 'login') {
1.205 raeburn 653: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 654: } elsif ($action eq 'rolecolors') {
1.9 raeburn 655: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 656: $lastactref,%domconfig);
1.3 raeburn 657: } elsif ($action eq 'quotas') {
1.216 raeburn 658: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 659: } elsif ($action eq 'autoenroll') {
1.205 raeburn 660: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 661: } elsif ($action eq 'autoupdate') {
662: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 663: } elsif ($action eq 'autocreate') {
664: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 665: } elsif ($action eq 'directorysrch') {
666: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 667: } elsif ($action eq 'usercreation') {
1.28 raeburn 668: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 669: } elsif ($action eq 'selfcreation') {
670: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 671: } elsif ($action eq 'usermodification') {
672: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 673: } elsif ($action eq 'contacts') {
1.205 raeburn 674: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 675: } elsif ($action eq 'defaults') {
1.212 raeburn 676: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 677: } elsif ($action eq 'scantron') {
1.205 raeburn 678: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 679: } elsif ($action eq 'coursecategories') {
1.239 raeburn 680: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 681: } elsif ($action eq 'serverstatuses') {
682: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 683: } elsif ($action eq 'requestcourses') {
1.216 raeburn 684: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 685: } elsif ($action eq 'requestauthor') {
1.216 raeburn 686: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 687: } elsif ($action eq 'helpsettings') {
1.122 jms 688: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 689: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 690: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 691: } elsif ($action eq 'selfenrollment') {
692: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 693: } elsif ($action eq 'usersessions') {
1.212 raeburn 694: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 695: } elsif ($action eq 'loadbalancing') {
696: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 697: } elsif ($action eq 'ltitools') {
698: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 699: } elsif ($action eq 'ssl') {
700: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 ! raeburn 701: } elsif ($action eq 'trust') {
! 702: $output = &modify_trust($dom,$lastactref,%domconfig);
1.3 raeburn 703: }
704: return $output;
705: }
706:
707: sub print_config_box {
1.9 raeburn 708: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 709: my $rowtotal = 0;
1.49 raeburn 710: my $output;
711: if ($action eq 'coursecategories') {
712: $output = &coursecategories_javascript($settings);
1.236 raeburn 713: } elsif ($action eq 'defaults') {
714: $output = &defaults_javascript($settings);
1.91 raeburn 715: }
1.236 raeburn 716: $output .=
1.30 raeburn 717: '<table class="LC_nested_outer">
1.3 raeburn 718: <tr>
1.66 raeburn 719: <th align="left" valign="middle"><span class="LC_nobreak">'.
720: &mt($item->{text}).' '.
721: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
722: '</tr>';
1.30 raeburn 723: $rowtotal ++;
1.110 raeburn 724: my $numheaders = 1;
725: if (ref($item->{'header'}) eq 'ARRAY') {
726: $numheaders = scalar(@{$item->{'header'}});
727: }
728: if ($numheaders > 1) {
1.64 raeburn 729: my $colspan = '';
1.145 raeburn 730: my $rightcolspan = '';
1.238 raeburn 731: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 732: ($action eq 'directorysrch') ||
1.256 raeburn 733: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 734: $colspan = ' colspan="2"';
735: }
1.145 raeburn 736: if ($action eq 'usersessions') {
737: $rightcolspan = ' colspan="3"';
738: }
1.30 raeburn 739: $output .= '
1.3 raeburn 740: <tr>
741: <td>
742: <table class="LC_nested">
743: <tr class="LC_info_row">
1.59 bisitz 744: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 745: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 746: </tr>';
1.69 raeburn 747: $rowtotal ++;
1.230 raeburn 748: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 749: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 750: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.279 ! raeburn 751: ($action eq 'directorysrch') || ($action eq 'trust')) {
1.230 raeburn 752: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 753: } elsif ($action eq 'coursecategories') {
1.230 raeburn 754: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 755: } elsif ($action eq 'login') {
1.256 raeburn 756: if ($numheaders == 4) {
1.168 raeburn 757: $colspan = ' colspan="2"';
758: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
759: } else {
760: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
761: }
1.230 raeburn 762: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 763: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 764: } elsif ($action eq 'rolecolors') {
1.30 raeburn 765: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 766: }
1.30 raeburn 767: $output .= '
1.6 raeburn 768: </table>
769: </td>
770: </tr>
771: <tr>
772: <td>
773: <table class="LC_nested">
774: <tr class="LC_info_row">
1.230 raeburn 775: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 776: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 777: </tr>';
778: $rowtotal ++;
1.230 raeburn 779: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
780: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 781: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.279 ! raeburn 782: ($action eq 'ssl') || ($action eq 'trust')) {
1.238 raeburn 783: if ($action eq 'coursecategories') {
784: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
785: $colspan = ' colspan="2"';
1.279 ! raeburn 786: } elsif ($action eq 'trust') {
! 787: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.238 raeburn 788: } else {
789: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
790: }
1.279 ! raeburn 791: if ($action eq 'trust') {
! 792: $output .= '
! 793: </table>
! 794: </td>
! 795: </tr>';
! 796: my @trusthdrs = qw(2 3 4 5 6 7);
! 797: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
! 798: for (my $i=0; $i<@trusthdrs; $i++) {
! 799: $output .= '
! 800: <tr>
! 801: <td>
! 802: <table class="LC_nested">
! 803: <tr class="LC_info_row">
! 804: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
! 805: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
! 806: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
! 807: </table>
! 808: </td>
! 809: </tr>';
! 810: }
! 811: $output .= '
! 812: <tr>
! 813: <td>
! 814: <table class="LC_nested">
! 815: <tr class="LC_info_row">
! 816: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
! 817: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
! 818: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
! 819: } else {
! 820: $output .= '
1.63 raeburn 821: </table>
822: </td>
823: </tr>
824: <tr>
825: <td>
826: <table class="LC_nested">
827: <tr class="LC_info_row">
828: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 829: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 830: </tr>'."\n";
1.279 ! raeburn 831: if ($action eq 'coursecategories') {
! 832: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
! 833: } else {
! 834: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
! 835: }
1.238 raeburn 836: }
1.63 raeburn 837: $rowtotal ++;
1.236 raeburn 838: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.277 raeburn 839: ($action eq 'defaults') || ($action eq 'directorysrch')) {
1.230 raeburn 840: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 841: } elsif ($action eq 'login') {
1.256 raeburn 842: if ($numheaders == 4) {
1.168 raeburn 843: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
844: </table>
845: </td>
846: </tr>
847: <tr>
848: <td>
849: <table class="LC_nested">
850: <tr class="LC_info_row">
851: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 852: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 853: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
854: $rowtotal ++;
855: } else {
856: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
857: }
1.256 raeburn 858: $output .= '
859: </table>
860: </td>
861: </tr>
862: <tr>
863: <td>
864: <table class="LC_nested">
865: <tr class="LC_info_row">';
866: if ($numheaders == 4) {
867: $output .= '
868: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
869: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
870: </tr>';
871: } else {
872: $output .= '
873: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
874: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
875: </tr>';
876: }
877: $rowtotal ++;
878: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 879: } elsif ($action eq 'requestcourses') {
1.247 raeburn 880: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
881: $rowtotal ++;
882: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 883: </table>
884: </td>
885: </tr>
886: <tr>
887: <td>
888: <table class="LC_nested">
889: <tr class="LC_info_row">
890: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
891: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 892: &textbookcourses_javascript($settings).
893: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
894: </table>
895: </td>
896: </tr>
897: <tr>
898: <td>
899: <table class="LC_nested">
900: <tr class="LC_info_row">
901: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
902: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
903: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 904: </table>
905: </td>
906: </tr>
907: <tr>
908: <td>
909: <table class="LC_nested">
910: <tr class="LC_info_row">
1.242 raeburn 911: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
912: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 913: </tr>'.
914: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 915: } elsif ($action eq 'requestauthor') {
916: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 917: $rowtotal ++;
1.122 jms 918: } elsif ($action eq 'rolecolors') {
1.30 raeburn 919: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 920: </table>
921: </td>
922: </tr>
923: <tr>
924: <td>
925: <table class="LC_nested">
926: <tr class="LC_info_row">
1.69 raeburn 927: <td class="LC_left_item"'.$colspan.' valign="top">'.
928: &mt($item->{'header'}->[2]->{'col1'}).'</td>
929: <td class="LC_right_item" valign="top">'.
930: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 931: </tr>'.
1.30 raeburn 932: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 933: </table>
934: </td>
935: </tr>
936: <tr>
937: <td>
938: <table class="LC_nested">
939: <tr class="LC_info_row">
1.59 bisitz 940: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
941: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 942: </tr>'.
1.30 raeburn 943: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
944: $rowtotal += 2;
1.6 raeburn 945: }
1.3 raeburn 946: } else {
1.30 raeburn 947: $output .= '
1.3 raeburn 948: <tr>
949: <td>
950: <table class="LC_nested">
1.30 raeburn 951: <tr class="LC_info_row">';
1.277 raeburn 952: if ($action eq 'login') {
1.30 raeburn 953: $output .= '
1.59 bisitz 954: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 955: } elsif ($action eq 'serverstatuses') {
956: $output .= '
957: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
958: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
959:
1.6 raeburn 960: } else {
1.30 raeburn 961: $output .= '
1.69 raeburn 962: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
963: }
1.72 raeburn 964: if (defined($item->{'header'}->[0]->{'col3'})) {
965: $output .= '<td class="LC_left_item" valign="top">'.
966: &mt($item->{'header'}->[0]->{'col2'});
967: if ($action eq 'serverstatuses') {
968: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
969: }
1.69 raeburn 970: } else {
971: $output .= '<td class="LC_right_item" valign="top">'.
972: &mt($item->{'header'}->[0]->{'col2'});
973: }
974: $output .= '</td>';
975: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 976: if (defined($item->{'header'}->[0]->{'col4'})) {
977: $output .= '<td class="LC_left_item" valign="top">'.
978: &mt($item->{'header'}->[0]->{'col3'});
979: } else {
980: $output .= '<td class="LC_right_item" valign="top">'.
981: &mt($item->{'header'}->[0]->{'col3'});
982: }
1.69 raeburn 983: if ($action eq 'serverstatuses') {
984: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
985: }
986: $output .= '</td>';
1.6 raeburn 987: }
1.150 raeburn 988: if ($item->{'header'}->[0]->{'col4'}) {
989: $output .= '<td class="LC_right_item" valign="top">'.
990: &mt($item->{'header'}->[0]->{'col4'});
991: }
1.69 raeburn 992: $output .= '</tr>';
1.48 raeburn 993: $rowtotal ++;
1.168 raeburn 994: if ($action eq 'quotas') {
1.86 raeburn 995: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 996: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
997: ($action eq 'contacts') || ($action eq 'serverstatuses') ||
998: ($action eq 'loadbalancing') || ($action eq 'ltitools')) {
1.230 raeburn 999: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 1000: } elsif ($action eq 'scantron') {
1001: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.118 jms 1002: } elsif ($action eq 'helpsettings') {
1.168 raeburn 1003: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.121 raeburn 1004: }
1.3 raeburn 1005: }
1.30 raeburn 1006: $output .= '
1.3 raeburn 1007: </table>
1008: </td>
1009: </tr>
1.30 raeburn 1010: </table><br />';
1011: return ($output,$rowtotal);
1.1 raeburn 1012: }
1013:
1.3 raeburn 1014: sub print_login {
1.168 raeburn 1015: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 1016: my ($css_class,$datatable);
1.6 raeburn 1017: my %choices = &login_choices();
1.110 raeburn 1018:
1.168 raeburn 1019: if ($caller eq 'service') {
1.149 raeburn 1020: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1021: my $choice = $choices{'disallowlogin'};
1022: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1023: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 1024: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1025: '<th>'.$choices{'server'}.'</th>'.
1026: '<th>'.$choices{'serverpath'}.'</th>'.
1027: '<th>'.$choices{'custompath'}.'</th>'.
1028: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1029: my %disallowed;
1030: if (ref($settings) eq 'HASH') {
1031: if (ref($settings->{'loginvia'}) eq 'HASH') {
1032: %disallowed = %{$settings->{'loginvia'}};
1033: }
1034: }
1035: foreach my $lonhost (sort(keys(%servers))) {
1036: my $direct = 'selected="selected"';
1.128 raeburn 1037: if (ref($disallowed{$lonhost}) eq 'HASH') {
1038: if ($disallowed{$lonhost}{'server'} ne '') {
1039: $direct = '';
1040: }
1.110 raeburn 1041: }
1.115 raeburn 1042: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1043: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1044: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1045: '</option>';
1.184 raeburn 1046: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1047: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1048: my $selected = '';
1.128 raeburn 1049: if (ref($disallowed{$lonhost}) eq 'HASH') {
1050: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1051: $selected = 'selected="selected"';
1052: }
1.110 raeburn 1053: }
1054: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1055: $servers{$hostid}.'</option>';
1056: }
1.128 raeburn 1057: $datatable .= '</select></td>'.
1058: '<td><select name="'.$lonhost.'_serverpath">';
1059: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1060: my $pathname = $path;
1061: if ($path eq 'custom') {
1062: $pathname = &mt('Custom Path').' ->';
1063: }
1064: my $selected = '';
1065: if (ref($disallowed{$lonhost}) eq 'HASH') {
1066: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1067: $selected = 'selected="selected"';
1068: }
1069: } elsif ($path eq '') {
1070: $selected = 'selected="selected"';
1071: }
1072: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1073: }
1074: $datatable .= '</select></td>';
1075: my ($custom,$exempt);
1076: if (ref($disallowed{$lonhost}) eq 'HASH') {
1077: $custom = $disallowed{$lonhost}{'custompath'};
1078: $exempt = $disallowed{$lonhost}{'exempt'};
1079: }
1080: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1081: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1082: '</tr>';
1.110 raeburn 1083: }
1084: $datatable .= '</table></td></tr>';
1085: return $datatable;
1.168 raeburn 1086: } elsif ($caller eq 'page') {
1087: my %defaultchecked = (
1088: 'coursecatalog' => 'on',
1.188 raeburn 1089: 'helpdesk' => 'on',
1.168 raeburn 1090: 'adminmail' => 'off',
1091: 'newuser' => 'off',
1092: );
1.188 raeburn 1093: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1094: my (%checkedon,%checkedoff);
1.42 raeburn 1095: foreach my $item (@toggles) {
1.168 raeburn 1096: if ($defaultchecked{$item} eq 'on') {
1097: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1098: $checkedoff{$item} = ' ';
1.168 raeburn 1099: } elsif ($defaultchecked{$item} eq 'off') {
1100: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1101: $checkedon{$item} = ' ';
1102: }
1.1 raeburn 1103: }
1.168 raeburn 1104: my @images = ('img','logo','domlogo','login');
1105: my @logintext = ('textcol','bgcol');
1106: my @bgs = ('pgbg','mainbg','sidebg');
1107: my @links = ('link','alink','vlink');
1108: my %designhash = &Apache::loncommon::get_domainconf($dom);
1109: my %defaultdesign = %Apache::loncommon::defaultdesign;
1110: my (%is_custom,%designs);
1111: my %defaults = (
1112: font => $defaultdesign{'login.font'},
1113: );
1.6 raeburn 1114: foreach my $item (@images) {
1.168 raeburn 1115: $defaults{$item} = $defaultdesign{'login.'.$item};
1116: $defaults{'showlogo'}{$item} = 1;
1117: }
1118: foreach my $item (@bgs) {
1119: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1120: }
1.41 raeburn 1121: foreach my $item (@logintext) {
1.168 raeburn 1122: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1123: }
1.168 raeburn 1124: foreach my $item (@links) {
1125: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1126: }
1.168 raeburn 1127: if (ref($settings) eq 'HASH') {
1128: foreach my $item (@toggles) {
1129: if ($settings->{$item} eq '1') {
1130: $checkedon{$item} = ' checked="checked" ';
1131: $checkedoff{$item} = ' ';
1132: } elsif ($settings->{$item} eq '0') {
1133: $checkedoff{$item} = ' checked="checked" ';
1134: $checkedon{$item} = ' ';
1135: }
1136: }
1137: foreach my $item (@images) {
1138: if (defined($settings->{$item})) {
1139: $designs{$item} = $settings->{$item};
1140: $is_custom{$item} = 1;
1141: }
1142: if (defined($settings->{'showlogo'}{$item})) {
1143: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1144: }
1145: }
1146: foreach my $item (@logintext) {
1147: if ($settings->{$item} ne '') {
1148: $designs{'logintext'}{$item} = $settings->{$item};
1149: $is_custom{$item} = 1;
1150: }
1151: }
1152: if ($settings->{'font'} ne '') {
1153: $designs{'font'} = $settings->{'font'};
1154: $is_custom{'font'} = 1;
1155: }
1156: foreach my $item (@bgs) {
1157: if ($settings->{$item} ne '') {
1158: $designs{'bgs'}{$item} = $settings->{$item};
1159: $is_custom{$item} = 1;
1160: }
1161: }
1162: foreach my $item (@links) {
1163: if ($settings->{$item} ne '') {
1164: $designs{'links'}{$item} = $settings->{$item};
1165: $is_custom{$item} = 1;
1166: }
1167: }
1168: } else {
1169: if ($designhash{$dom.'.login.font'} ne '') {
1170: $designs{'font'} = $designhash{$dom.'.login.font'};
1171: $is_custom{'font'} = 1;
1172: }
1173: foreach my $item (@images) {
1174: if ($designhash{$dom.'.login.'.$item} ne '') {
1175: $designs{$item} = $designhash{$dom.'.login.'.$item};
1176: $is_custom{$item} = 1;
1177: }
1178: }
1179: foreach my $item (@bgs) {
1180: if ($designhash{$dom.'.login.'.$item} ne '') {
1181: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1182: $is_custom{$item} = 1;
1183: }
1.6 raeburn 1184: }
1.168 raeburn 1185: foreach my $item (@links) {
1186: if ($designhash{$dom.'.login.'.$item} ne '') {
1187: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1188: $is_custom{$item} = 1;
1189: }
1.6 raeburn 1190: }
1191: }
1.168 raeburn 1192: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1193: logo => 'Institution Logo',
1194: domlogo => 'Domain Logo',
1195: login => 'Login box');
1196: my $itemcount = 1;
1197: foreach my $item (@toggles) {
1198: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1199: $datatable .=
1200: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1201: '</td><td>'.
1202: '<span class="LC_nobreak"><label><input type="radio" name="'.
1203: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1204: '</label> <label><input type="radio" name="'.$item.'"'.
1205: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1206: '</tr>';
1207: $itemcount ++;
1.6 raeburn 1208: }
1.168 raeburn 1209: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1210: $datatable .= '</tr></table></td></tr>';
1211: } elsif ($caller eq 'help') {
1212: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1213: my $switchserver = &check_switchserver($dom,$confname);
1214: my $itemcount = 1;
1215: $defaulturl = '/adm/loginproblems.html';
1216: $defaulttype = 'default';
1217: %lt = &Apache::lonlocal::texthash (
1218: del => 'Delete?',
1219: rep => 'Replace:',
1220: upl => 'Upload:',
1221: default => 'Default',
1222: custom => 'Custom',
1223: );
1224: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1225: my @currlangs;
1226: if (ref($settings) eq 'HASH') {
1227: if (ref($settings->{'helpurl'}) eq 'HASH') {
1228: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1229: next if ($settings->{'helpurl'}{$key} eq '');
1230: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1231: $type{$key} = 'custom';
1232: unless ($key eq 'nolang') {
1233: push(@currlangs,$key);
1234: }
1235: }
1236: } elsif ($settings->{'helpurl'} ne '') {
1237: $type{'nolang'} = 'custom';
1238: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1239: }
1240: }
1.168 raeburn 1241: foreach my $lang ('nolang',sort(@currlangs)) {
1242: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1243: $datatable .= '<tr'.$css_class.'>';
1244: if ($url{$lang} eq '') {
1245: $url{$lang} = $defaulturl;
1246: }
1247: if ($type{$lang} eq '') {
1248: $type{$lang} = $defaulttype;
1249: }
1250: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1251: if ($lang eq 'nolang') {
1252: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1253: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1254: } else {
1255: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1256: $langchoices{$lang},
1257: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1258: }
1259: $datatable .= '</span></td>'."\n".
1260: '<td class="LC_left_item">';
1261: if ($type{$lang} eq 'custom') {
1262: $datatable .= '<span class="LC_nobreak"><label>'.
1263: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1264: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1265: } else {
1266: $datatable .= $lt{'upl'};
1267: }
1268: $datatable .='<br />';
1269: if ($switchserver) {
1270: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1271: } else {
1272: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1273: }
1.168 raeburn 1274: $datatable .= '</td></tr>';
1275: $itemcount ++;
1.6 raeburn 1276: }
1.168 raeburn 1277: my @addlangs;
1278: foreach my $lang (sort(keys(%langchoices))) {
1279: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1280: push(@addlangs,$lang);
1281: }
1282: if (@addlangs > 0) {
1283: my %toadd;
1284: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1285: $toadd{''} = &mt('Select');
1286: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1287: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1288: &mt('Add log-in help page for a specific language:').' '.
1289: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1290: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1291: if ($switchserver) {
1292: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1293: } else {
1294: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1295: }
1.168 raeburn 1296: $datatable .= '</td></tr>';
1.169 raeburn 1297: $itemcount ++;
1.6 raeburn 1298: }
1.169 raeburn 1299: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1300: } elsif ($caller eq 'headtag') {
1301: my %domservers = &Apache::lonnet::get_servers($dom);
1302: my $choice = $choices{'headtag'};
1303: $css_class = ' class="LC_odd_row"';
1304: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1305: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1306: '<th>'.$choices{'current'}.'</th>'.
1307: '<th>'.$choices{'action'}.'</th>'.
1308: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1309: my (%currurls,%currexempt);
1310: if (ref($settings) eq 'HASH') {
1311: if (ref($settings->{'headtag'}) eq 'HASH') {
1312: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1313: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1314: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1315: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1316: }
1317: }
1318: }
1319: }
1320: my %lt = &Apache::lonlocal::texthash(
1321: del => 'Delete?',
1322: rep => 'Replace:',
1323: upl => 'Upload:',
1324: curr => 'View contents',
1325: none => 'None',
1326: );
1327: my $switchserver = &check_switchserver($dom,$confname);
1328: foreach my $lonhost (sort(keys(%domservers))) {
1329: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1330: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1331: if ($currurls{$lonhost}) {
1332: $datatable .= '<td class="LC_right_item"><a href="'.
1333: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1334: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1335: '">'.$lt{'curr'}.'</a></td>'.
1336: '<td><span class="LC_nobreak"><label>'.
1337: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1338: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1339: } else {
1340: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1341: }
1342: $datatable .='<br />';
1343: if ($switchserver) {
1344: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1345: } else {
1346: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1347: }
1348: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1349: }
1350: $datatable .= '</table></td></tr>';
1.1 raeburn 1351: }
1.6 raeburn 1352: return $datatable;
1353: }
1354:
1355: sub login_choices {
1356: my %choices =
1357: &Apache::lonlocal::texthash (
1.116 bisitz 1358: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1359: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1360: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1361: disallowlogin => "Login page requests redirected",
1362: hostid => "Server",
1.128 raeburn 1363: server => "Redirect to:",
1364: serverpath => "Path",
1365: custompath => "Custom",
1366: exempt => "Exempt IP(s)",
1.110 raeburn 1367: directlogin => "No redirect",
1368: newuser => "Link to create a user account",
1369: img => "Header",
1370: logo => "Main Logo",
1371: domlogo => "Domain Logo",
1372: login => "Log-in Header",
1373: textcol => "Text color",
1374: bgcol => "Box color",
1375: bgs => "Background colors",
1376: links => "Link colors",
1377: font => "Font color",
1378: pgbg => "Header",
1379: mainbg => "Page",
1380: sidebg => "Login box",
1381: link => "Link",
1382: alink => "Active link",
1383: vlink => "Visited link",
1.256 raeburn 1384: headtag => "Custom markup",
1385: action => "Action",
1386: current => "Current",
1.6 raeburn 1387: );
1388: return %choices;
1389: }
1390:
1391: sub print_rolecolors {
1.30 raeburn 1392: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1393: my %choices = &color_font_choices();
1394: my @bgs = ('pgbg','tabbg','sidebg');
1395: my @links = ('link','alink','vlink');
1396: my @images = ('img');
1397: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1398: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1399: my %defaultdesign = %Apache::loncommon::defaultdesign;
1400: my (%is_custom,%designs);
1.200 raeburn 1401: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1402: if (ref($settings) eq 'HASH') {
1403: if (ref($settings->{$role}) eq 'HASH') {
1404: if ($settings->{$role}->{'img'} ne '') {
1405: $designs{'img'} = $settings->{$role}->{'img'};
1406: $is_custom{'img'} = 1;
1407: }
1408: if ($settings->{$role}->{'font'} ne '') {
1409: $designs{'font'} = $settings->{$role}->{'font'};
1410: $is_custom{'font'} = 1;
1411: }
1.97 tempelho 1412: if ($settings->{$role}->{'fontmenu'} ne '') {
1413: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1414: $is_custom{'fontmenu'} = 1;
1415: }
1.6 raeburn 1416: foreach my $item (@bgs) {
1417: if ($settings->{$role}->{$item} ne '') {
1418: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1419: $is_custom{$item} = 1;
1420: }
1421: }
1422: foreach my $item (@links) {
1423: if ($settings->{$role}->{$item} ne '') {
1424: $designs{'links'}{$item} = $settings->{$role}->{$item};
1425: $is_custom{$item} = 1;
1426: }
1427: }
1428: }
1429: } else {
1430: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1431: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1432: $is_custom{'img'} = 1;
1433: }
1.97 tempelho 1434: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1435: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1436: $is_custom{'fontmenu'} = 1;
1437: }
1.6 raeburn 1438: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1439: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1440: $is_custom{'font'} = 1;
1441: }
1442: foreach my $item (@bgs) {
1443: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1444: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1445: $is_custom{$item} = 1;
1446:
1447: }
1448: }
1449: foreach my $item (@links) {
1450: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1451: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1452: $is_custom{$item} = 1;
1453: }
1454: }
1455: }
1456: my $itemcount = 1;
1.30 raeburn 1457: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1458: $datatable .= '</tr></table></td></tr>';
1459: return $datatable;
1460: }
1461:
1.200 raeburn 1462: sub role_defaults {
1463: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1464: my %defaults;
1465: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1466: return %defaults;
1467: }
1468: my %defaultdesign = %Apache::loncommon::defaultdesign;
1469: if ($role eq 'login') {
1470: %defaults = (
1471: font => $defaultdesign{$role.'.font'},
1472: );
1473: if (ref($logintext) eq 'ARRAY') {
1474: foreach my $item (@{$logintext}) {
1475: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1476: }
1477: }
1478: foreach my $item (@{$images}) {
1479: $defaults{'showlogo'}{$item} = 1;
1480: }
1481: } else {
1482: %defaults = (
1483: img => $defaultdesign{$role.'.img'},
1484: font => $defaultdesign{$role.'.font'},
1485: fontmenu => $defaultdesign{$role.'.fontmenu'},
1486: );
1487: }
1488: foreach my $item (@{$bgs}) {
1489: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1490: }
1491: foreach my $item (@{$links}) {
1492: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1493: }
1494: foreach my $item (@{$images}) {
1495: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1496: }
1497: return %defaults;
1498: }
1499:
1.6 raeburn 1500: sub display_color_options {
1.9 raeburn 1501: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1502: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1503: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1504: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1505: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1506: '<td>'.$choices->{'font'}.'</td>';
1507: if (!$is_custom->{'font'}) {
1.30 raeburn 1508: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1509: } else {
1510: $datatable .= '<td> </td>';
1511: }
1.174 foxr 1512: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1513:
1.8 raeburn 1514: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1515: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1516: ' value="'.$current_color.'" /> '.
1.174 foxr 1517: ' </td></tr>';
1.107 raeburn 1518: unless ($role eq 'login') {
1519: $datatable .= '<tr'.$css_class.'>'.
1520: '<td>'.$choices->{'fontmenu'}.'</td>';
1521: if (!$is_custom->{'fontmenu'}) {
1522: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1523: } else {
1524: $datatable .= '<td> </td>';
1525: }
1.202 raeburn 1526: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1527: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1528: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1529: '<input class="colorchooser" type="text" size="10" name="'
1530: .$role.'_fontmenu"'.
1531: ' value="'.$current_color.'" /> '.
1532: ' </td></tr>';
1.97 tempelho 1533: }
1.9 raeburn 1534: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1535: foreach my $img (@{$images}) {
1.18 albertel 1536: $itemcount ++;
1.6 raeburn 1537: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1538: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1539: '<td>'.$choices->{$img};
1.41 raeburn 1540: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1541: if ($role eq 'login') {
1542: if ($img eq 'login') {
1543: $login_hdr_pick =
1.135 bisitz 1544: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1545: $logincolors =
1546: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1547: $designs,$defaults);
1.70 raeburn 1548: } elsif ($img ne 'domlogo') {
1549: $datatable.= &logo_display_options($img,$defaults,$designs);
1550: }
1551: }
1552: $datatable .= '</td>';
1.6 raeburn 1553: if ($designs->{$img} ne '') {
1554: $imgfile = $designs->{$img};
1.18 albertel 1555: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1556: } else {
1557: $imgfile = $defaults->{$img};
1558: }
1559: if ($imgfile) {
1.9 raeburn 1560: my ($showfile,$fullsize);
1561: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1562: my $urldir = $1;
1563: my $filename = $2;
1564: my @info = &Apache::lonnet::stat_file($designs->{$img});
1565: if (@info) {
1566: my $thumbfile = 'tn-'.$filename;
1567: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1568: if (@thumb) {
1569: $showfile = $urldir.'/'.$thumbfile;
1570: } else {
1571: $showfile = $imgfile;
1572: }
1573: } else {
1574: $showfile = '';
1575: }
1576: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1577: $showfile = $imgfile;
1.6 raeburn 1578: my $imgdir = $1;
1579: my $filename = $2;
1.159 raeburn 1580: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1581: $showfile = "/$imgdir/tn-".$filename;
1582: } else {
1.159 raeburn 1583: my $input = $londocroot.$imgfile;
1584: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1585: if (!-e $output) {
1.9 raeburn 1586: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1587: my ($fullwidth,$fullheight) = &check_dimensions($input);
1588: if ($fullwidth ne '' && $fullheight ne '') {
1589: if ($fullwidth > $width && $fullheight > $height) {
1590: my $size = $width.'x'.$height;
1591: system("convert -sample $size $input $output");
1.159 raeburn 1592: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1593: }
1594: }
1.6 raeburn 1595: }
1596: }
1.16 raeburn 1597: }
1.6 raeburn 1598: if ($showfile) {
1.40 raeburn 1599: if ($showfile =~ m{^/(adm|res)/}) {
1600: if ($showfile =~ m{^/res/}) {
1601: my $local_showfile =
1602: &Apache::lonnet::filelocation('',$showfile);
1603: &Apache::lonnet::repcopy($local_showfile);
1604: }
1605: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1606: }
1607: if ($imgfile) {
1608: if ($imgfile =~ m{^/(adm|res)/}) {
1609: if ($imgfile =~ m{^/res/}) {
1610: my $local_imgfile =
1611: &Apache::lonnet::filelocation('',$imgfile);
1612: &Apache::lonnet::repcopy($local_imgfile);
1613: }
1614: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1615: } else {
1616: $fullsize = $imgfile;
1617: }
1618: }
1.41 raeburn 1619: $datatable .= '<td>';
1620: if ($img eq 'login') {
1.135 bisitz 1621: $datatable .= $login_hdr_pick;
1622: }
1.41 raeburn 1623: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1624: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1625: } else {
1.201 raeburn 1626: $datatable .= '<td> </td><td class="LC_left_item">'.
1627: &mt('Upload:').'<br />';
1.6 raeburn 1628: }
1629: } else {
1.201 raeburn 1630: $datatable .= '<td> </td><td class="LC_left_item">'.
1631: &mt('Upload:').'<br />';
1.6 raeburn 1632: }
1.9 raeburn 1633: if ($switchserver) {
1634: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1635: } else {
1.135 bisitz 1636: if ($img ne 'login') { # suppress file selection for Log-in header
1637: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1638: }
1.9 raeburn 1639: }
1640: $datatable .= '</td></tr>';
1.6 raeburn 1641: }
1642: $itemcount ++;
1643: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1644: $datatable .= '<tr'.$css_class.'>'.
1645: '<td>'.$choices->{'bgs'}.'</td>';
1646: my $bgs_def;
1647: foreach my $item (@{$bgs}) {
1648: if (!$is_custom->{$item}) {
1.70 raeburn 1649: $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 1650: }
1651: }
1652: if ($bgs_def) {
1.8 raeburn 1653: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1654: } else {
1655: $datatable .= '<td> </td>';
1656: }
1657: $datatable .= '<td class="LC_right_item">'.
1658: '<table border="0"><tr>';
1.174 foxr 1659:
1.6 raeburn 1660: foreach my $item (@{$bgs}) {
1.201 raeburn 1661: $datatable .= '<td align="center">'.$choices->{$item};
1.174 foxr 1662: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1663: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1664: $datatable .= ' ';
1.6 raeburn 1665: }
1.174 foxr 1666: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1667: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1668: }
1669: $datatable .= '</tr></table></td></tr>';
1670: $itemcount ++;
1671: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1672: $datatable .= '<tr'.$css_class.'>'.
1673: '<td>'.$choices->{'links'}.'</td>';
1674: my $links_def;
1675: foreach my $item (@{$links}) {
1676: if (!$is_custom->{$item}) {
1.30 raeburn 1677: $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 1678: }
1679: }
1680: if ($links_def) {
1.8 raeburn 1681: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1682: } else {
1683: $datatable .= '<td> </td>';
1684: }
1685: $datatable .= '<td class="LC_right_item">'.
1686: '<table border="0"><tr>';
1687: foreach my $item (@{$links}) {
1.234 raeburn 1688: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.201 raeburn 1689: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1690: if ($designs->{'links'}{$item}) {
1.174 foxr 1691: $datatable.=' ';
1.6 raeburn 1692: }
1.174 foxr 1693: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1694: '" /></td>';
1695: }
1.30 raeburn 1696: $$rowtotal += $itemcount;
1.3 raeburn 1697: return $datatable;
1698: }
1699:
1.70 raeburn 1700: sub logo_display_options {
1701: my ($img,$defaults,$designs) = @_;
1702: my $checkedon;
1703: if (ref($defaults) eq 'HASH') {
1704: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1705: if ($defaults->{'showlogo'}{$img}) {
1706: $checkedon = 'checked="checked" ';
1707: }
1708: }
1709: }
1710: if (ref($designs) eq 'HASH') {
1711: if (ref($designs->{'showlogo'}) eq 'HASH') {
1712: if (defined($designs->{'showlogo'}{$img})) {
1713: if ($designs->{'showlogo'}{$img} == 0) {
1714: $checkedon = '';
1715: } elsif ($designs->{'showlogo'}{$img} == 1) {
1716: $checkedon = 'checked="checked" ';
1717: }
1718: }
1719: }
1720: }
1721: return '<br /><label> <input type="checkbox" name="'.
1722: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1723: &mt('show').'</label>'."\n";
1724: }
1725:
1.41 raeburn 1726: sub login_header_options {
1.135 bisitz 1727: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1728: my $output = '';
1.41 raeburn 1729: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1730: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1731: if (!$is_custom->{'textcol'}) {
1732: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1733: ' ';
1734: }
1735: if (!$is_custom->{'bgcol'}) {
1736: $output .= $choices->{'bgcol'}.': '.
1737: '<span id="css_'.$role.'_font" style="background-color: '.
1738: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1739: }
1740: $output .= '<br />';
1741: }
1742: $output .='<br />';
1743: return $output;
1744: }
1745:
1746: sub login_text_colors {
1.201 raeburn 1747: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1748: my $color_menu = '<table border="0"><tr>';
1749: foreach my $item (@{$logintext}) {
1.201 raeburn 1750: $color_menu .= '<td align="center">'.$choices->{$item};
1751: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1752: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1753: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1754: }
1755: $color_menu .= '</tr></table><br />';
1756: return $color_menu;
1757: }
1758:
1759: sub image_changes {
1760: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1761: my $output;
1.135 bisitz 1762: if ($img eq 'login') {
1763: # suppress image for Log-in header
1764: } elsif (!$is_custom) {
1.70 raeburn 1765: if ($img ne 'domlogo') {
1.41 raeburn 1766: $output .= &mt('Default image:').'<br />';
1767: } else {
1768: $output .= &mt('Default in use:').'<br />';
1769: }
1770: }
1.135 bisitz 1771: if ($img eq 'login') { # suppress image for Log-in header
1772: $output .= '<td>'.$logincolors;
1.41 raeburn 1773: } else {
1.135 bisitz 1774: if ($img_import) {
1775: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1776: }
1777: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1778: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1779: if ($is_custom) {
1780: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1781: '<input type="checkbox" name="'.
1782: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1783: '</label> '.&mt('Replace:').'</span><br />';
1784: } else {
1.201 raeburn 1785: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1786: }
1.41 raeburn 1787: }
1788: return $output;
1789: }
1790:
1.3 raeburn 1791: sub print_quotas {
1.86 raeburn 1792: my ($dom,$settings,$rowtotal,$action) = @_;
1793: my $context;
1794: if ($action eq 'quotas') {
1795: $context = 'tools';
1796: } else {
1797: $context = $action;
1798: }
1.197 raeburn 1799: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1800: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1801: my $typecount = 0;
1.101 raeburn 1802: my ($css_class,%titles);
1.86 raeburn 1803: if ($context eq 'requestcourses') {
1.271 raeburn 1804: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 1805: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1806: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1807: %titles = &courserequest_titles();
1.163 raeburn 1808: } elsif ($context eq 'requestauthor') {
1809: @usertools = ('author');
1810: @options = ('norequest','approval','automatic');
1.210 raeburn 1811: %titles = &authorrequest_titles();
1.86 raeburn 1812: } else {
1.162 raeburn 1813: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1814: %titles = &tool_titles();
1.86 raeburn 1815: }
1.26 raeburn 1816: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1817: foreach my $type (@{$types}) {
1.197 raeburn 1818: my ($currdefquota,$currauthorquota);
1.163 raeburn 1819: unless (($context eq 'requestcourses') ||
1820: ($context eq 'requestauthor')) {
1.86 raeburn 1821: if (ref($settings) eq 'HASH') {
1822: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1823: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1824: } else {
1825: $currdefquota = $settings->{$type};
1826: }
1.197 raeburn 1827: if (ref($settings->{authorquota}) eq 'HASH') {
1828: $currauthorquota = $settings->{authorquota}->{$type};
1829: }
1.78 raeburn 1830: }
1.72 raeburn 1831: }
1.3 raeburn 1832: if (defined($usertypes->{$type})) {
1833: $typecount ++;
1834: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1835: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1836: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1837: '<td class="LC_left_item">';
1.101 raeburn 1838: if ($context eq 'requestcourses') {
1839: $datatable .= '<table><tr>';
1840: }
1841: my %cell;
1.72 raeburn 1842: foreach my $item (@usertools) {
1.101 raeburn 1843: if ($context eq 'requestcourses') {
1844: my ($curroption,$currlimit);
1845: if (ref($settings) eq 'HASH') {
1846: if (ref($settings->{$item}) eq 'HASH') {
1847: $curroption = $settings->{$item}->{$type};
1848: if ($curroption =~ /^autolimit=(\d*)$/) {
1849: $currlimit = $1;
1850: }
1851: }
1852: }
1853: if (!$curroption) {
1854: $curroption = 'norequest';
1855: }
1856: $datatable .= '<th>'.$titles{$item}.'</th>';
1857: foreach my $option (@options) {
1858: my $val = $option;
1859: if ($option eq 'norequest') {
1860: $val = 0;
1861: }
1862: if ($option eq 'validate') {
1863: my $canvalidate = 0;
1864: if (ref($validations{$item}) eq 'HASH') {
1865: if ($validations{$item}{$type}) {
1866: $canvalidate = 1;
1867: }
1868: }
1869: next if (!$canvalidate);
1870: }
1871: my $checked = '';
1872: if ($option eq $curroption) {
1873: $checked = ' checked="checked"';
1874: } elsif ($option eq 'autolimit') {
1875: if ($curroption =~ /^autolimit/) {
1876: $checked = ' checked="checked"';
1877: }
1878: }
1879: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1880: '<input type="radio" name="crsreq_'.$item.
1881: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1882: $titles{$option}.'</label>';
1.101 raeburn 1883: if ($option eq 'autolimit') {
1.127 raeburn 1884: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1885: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1886: 'value="'.$currlimit.'" />';
1.101 raeburn 1887: }
1.127 raeburn 1888: $cell{$item} .= '</span> ';
1.103 raeburn 1889: if ($option eq 'autolimit') {
1.127 raeburn 1890: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1891: }
1.101 raeburn 1892: }
1.163 raeburn 1893: } elsif ($context eq 'requestauthor') {
1894: my $curroption;
1895: if (ref($settings) eq 'HASH') {
1896: $curroption = $settings->{$type};
1897: }
1898: if (!$curroption) {
1899: $curroption = 'norequest';
1900: }
1901: foreach my $option (@options) {
1902: my $val = $option;
1903: if ($option eq 'norequest') {
1904: $val = 0;
1905: }
1906: my $checked = '';
1907: if ($option eq $curroption) {
1908: $checked = ' checked="checked"';
1909: }
1910: $datatable .= '<span class="LC_nobreak"><label>'.
1911: '<input type="radio" name="authorreq_'.$type.
1912: '" value="'.$val.'"'.$checked.' />'.
1913: $titles{$option}.'</label></span> ';
1914: }
1.101 raeburn 1915: } else {
1916: my $checked = 'checked="checked" ';
1917: if (ref($settings) eq 'HASH') {
1918: if (ref($settings->{$item}) eq 'HASH') {
1919: if ($settings->{$item}->{$type} == 0) {
1920: $checked = '';
1921: } elsif ($settings->{$item}->{$type} == 1) {
1922: $checked = 'checked="checked" ';
1923: }
1.78 raeburn 1924: }
1.72 raeburn 1925: }
1.101 raeburn 1926: $datatable .= '<span class="LC_nobreak"><label>'.
1927: '<input type="checkbox" name="'.$context.'_'.$item.
1928: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1929: '</label></span> ';
1.72 raeburn 1930: }
1.101 raeburn 1931: }
1932: if ($context eq 'requestcourses') {
1933: $datatable .= '</tr><tr>';
1934: foreach my $item (@usertools) {
1.106 raeburn 1935: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1936: }
1937: $datatable .= '</tr></table>';
1.72 raeburn 1938: }
1.86 raeburn 1939: $datatable .= '</td>';
1.163 raeburn 1940: unless (($context eq 'requestcourses') ||
1941: ($context eq 'requestauthor')) {
1.86 raeburn 1942: $datatable .=
1.197 raeburn 1943: '<td class="LC_right_item">'.
1944: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1945: '<input type="text" name="quota_'.$type.
1.72 raeburn 1946: '" value="'.$currdefquota.
1.197 raeburn 1947: '" size="5" /></span>'.(' ' x 2).
1948: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1949: '<input type="text" name="authorquota_'.$type.
1950: '" value="'.$currauthorquota.
1951: '" size="5" /></span></td>';
1.86 raeburn 1952: }
1953: $datatable .= '</tr>';
1.3 raeburn 1954: }
1955: }
1956: }
1.163 raeburn 1957: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1958: $defaultquota = '20';
1.197 raeburn 1959: $authorquota = '500';
1.86 raeburn 1960: if (ref($settings) eq 'HASH') {
1961: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1962: $defaultquota = $settings->{'defaultquota'}->{'default'};
1963: } elsif (defined($settings->{'default'})) {
1964: $defaultquota = $settings->{'default'};
1965: }
1.197 raeburn 1966: if (ref($settings->{'authorquota'}) eq 'HASH') {
1967: $authorquota = $settings->{'authorquota'}->{'default'};
1968: }
1.3 raeburn 1969: }
1970: }
1971: $typecount ++;
1972: $css_class = $typecount%2?' class="LC_odd_row"':'';
1973: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1974: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1975: '<td class="LC_left_item">';
1.101 raeburn 1976: if ($context eq 'requestcourses') {
1977: $datatable .= '<table><tr>';
1978: }
1979: my %defcell;
1.72 raeburn 1980: foreach my $item (@usertools) {
1.101 raeburn 1981: if ($context eq 'requestcourses') {
1982: my ($curroption,$currlimit);
1983: if (ref($settings) eq 'HASH') {
1984: if (ref($settings->{$item}) eq 'HASH') {
1985: $curroption = $settings->{$item}->{'default'};
1986: if ($curroption =~ /^autolimit=(\d*)$/) {
1987: $currlimit = $1;
1988: }
1989: }
1990: }
1991: if (!$curroption) {
1992: $curroption = 'norequest';
1993: }
1994: $datatable .= '<th>'.$titles{$item}.'</th>';
1995: foreach my $option (@options) {
1996: my $val = $option;
1997: if ($option eq 'norequest') {
1998: $val = 0;
1999: }
2000: if ($option eq 'validate') {
2001: my $canvalidate = 0;
2002: if (ref($validations{$item}) eq 'HASH') {
2003: if ($validations{$item}{'default'}) {
2004: $canvalidate = 1;
2005: }
2006: }
2007: next if (!$canvalidate);
2008: }
2009: my $checked = '';
2010: if ($option eq $curroption) {
2011: $checked = ' checked="checked"';
2012: } elsif ($option eq 'autolimit') {
2013: if ($curroption =~ /^autolimit/) {
2014: $checked = ' checked="checked"';
2015: }
2016: }
2017: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2018: '<input type="radio" name="crsreq_'.$item.
2019: '_default" value="'.$val.'"'.$checked.' />'.
2020: $titles{$option}.'</label>';
2021: if ($option eq 'autolimit') {
1.127 raeburn 2022: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2023: $item.'_limit_default" size="1" '.
2024: 'value="'.$currlimit.'" />';
2025: }
1.127 raeburn 2026: $defcell{$item} .= '</span> ';
1.104 raeburn 2027: if ($option eq 'autolimit') {
1.127 raeburn 2028: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2029: }
1.101 raeburn 2030: }
1.163 raeburn 2031: } elsif ($context eq 'requestauthor') {
2032: my $curroption;
2033: if (ref($settings) eq 'HASH') {
1.172 raeburn 2034: $curroption = $settings->{'default'};
1.163 raeburn 2035: }
2036: if (!$curroption) {
2037: $curroption = 'norequest';
2038: }
2039: foreach my $option (@options) {
2040: my $val = $option;
2041: if ($option eq 'norequest') {
2042: $val = 0;
2043: }
2044: my $checked = '';
2045: if ($option eq $curroption) {
2046: $checked = ' checked="checked"';
2047: }
2048: $datatable .= '<span class="LC_nobreak"><label>'.
2049: '<input type="radio" name="authorreq_default"'.
2050: ' value="'.$val.'"'.$checked.' />'.
2051: $titles{$option}.'</label></span> ';
2052: }
1.101 raeburn 2053: } else {
2054: my $checked = 'checked="checked" ';
2055: if (ref($settings) eq 'HASH') {
2056: if (ref($settings->{$item}) eq 'HASH') {
2057: if ($settings->{$item}->{'default'} == 0) {
2058: $checked = '';
2059: } elsif ($settings->{$item}->{'default'} == 1) {
2060: $checked = 'checked="checked" ';
2061: }
1.78 raeburn 2062: }
1.72 raeburn 2063: }
1.101 raeburn 2064: $datatable .= '<span class="LC_nobreak"><label>'.
2065: '<input type="checkbox" name="'.$context.'_'.$item.
2066: '" value="default" '.$checked.'/>'.$titles{$item}.
2067: '</label></span> ';
2068: }
2069: }
2070: if ($context eq 'requestcourses') {
2071: $datatable .= '</tr><tr>';
2072: foreach my $item (@usertools) {
1.106 raeburn 2073: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2074: }
1.101 raeburn 2075: $datatable .= '</tr></table>';
1.72 raeburn 2076: }
1.86 raeburn 2077: $datatable .= '</td>';
1.163 raeburn 2078: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2079: $datatable .= '<td class="LC_right_item">'.
2080: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2081: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2082: $defaultquota.'" size="5" /></span>'.(' ' x2).
2083: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2084: '<input type="text" name="authorquota" value="'.
2085: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2086: }
2087: $datatable .= '</tr>';
1.72 raeburn 2088: $typecount ++;
2089: $css_class = $typecount%2?' class="LC_odd_row"':'';
2090: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2091: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2092: if ($context eq 'requestcourses') {
1.109 raeburn 2093: $datatable .= &mt('(overrides affiliation, if set)').
2094: '</td>'.
2095: '<td class="LC_left_item">'.
2096: '<table><tr>';
1.101 raeburn 2097: } else {
1.109 raeburn 2098: $datatable .= &mt('(overrides affiliation, if checked)').
2099: '</td>'.
2100: '<td class="LC_left_item" colspan="2">'.
2101: '<br />';
1.101 raeburn 2102: }
2103: my %advcell;
1.72 raeburn 2104: foreach my $item (@usertools) {
1.101 raeburn 2105: if ($context eq 'requestcourses') {
2106: my ($curroption,$currlimit);
2107: if (ref($settings) eq 'HASH') {
2108: if (ref($settings->{$item}) eq 'HASH') {
2109: $curroption = $settings->{$item}->{'_LC_adv'};
2110: if ($curroption =~ /^autolimit=(\d*)$/) {
2111: $currlimit = $1;
2112: }
2113: }
2114: }
2115: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2116: my $checked = '';
2117: if ($curroption eq '') {
2118: $checked = ' checked="checked"';
2119: }
2120: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2121: '<input type="radio" name="crsreq_'.$item.
2122: '__LC_adv" value=""'.$checked.' />'.
2123: &mt('No override set').'</label></span> ';
1.101 raeburn 2124: foreach my $option (@options) {
2125: my $val = $option;
2126: if ($option eq 'norequest') {
2127: $val = 0;
2128: }
2129: if ($option eq 'validate') {
2130: my $canvalidate = 0;
2131: if (ref($validations{$item}) eq 'HASH') {
2132: if ($validations{$item}{'_LC_adv'}) {
2133: $canvalidate = 1;
2134: }
2135: }
2136: next if (!$canvalidate);
2137: }
2138: my $checked = '';
1.104 raeburn 2139: if ($val eq $curroption) {
1.101 raeburn 2140: $checked = ' checked="checked"';
2141: } elsif ($option eq 'autolimit') {
2142: if ($curroption =~ /^autolimit/) {
2143: $checked = ' checked="checked"';
2144: }
2145: }
2146: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2147: '<input type="radio" name="crsreq_'.$item.
2148: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2149: $titles{$option}.'</label>';
2150: if ($option eq 'autolimit') {
1.127 raeburn 2151: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2152: $item.'_limit__LC_adv" size="1" '.
2153: 'value="'.$currlimit.'" />';
2154: }
1.127 raeburn 2155: $advcell{$item} .= '</span> ';
1.104 raeburn 2156: if ($option eq 'autolimit') {
1.127 raeburn 2157: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2158: }
1.101 raeburn 2159: }
1.163 raeburn 2160: } elsif ($context eq 'requestauthor') {
2161: my $curroption;
2162: if (ref($settings) eq 'HASH') {
2163: $curroption = $settings->{'_LC_adv'};
2164: }
2165: my $checked = '';
2166: if ($curroption eq '') {
2167: $checked = ' checked="checked"';
2168: }
2169: $datatable .= '<span class="LC_nobreak"><label>'.
2170: '<input type="radio" name="authorreq__LC_adv"'.
2171: ' value=""'.$checked.' />'.
2172: &mt('No override set').'</label></span> ';
2173: foreach my $option (@options) {
2174: my $val = $option;
2175: if ($option eq 'norequest') {
2176: $val = 0;
2177: }
2178: my $checked = '';
2179: if ($val eq $curroption) {
2180: $checked = ' checked="checked"';
2181: }
2182: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2183: '<input type="radio" name="authorreq__LC_adv"'.
2184: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2185: $titles{$option}.'</label></span> ';
2186: }
1.101 raeburn 2187: } else {
2188: my $checked = 'checked="checked" ';
2189: if (ref($settings) eq 'HASH') {
2190: if (ref($settings->{$item}) eq 'HASH') {
2191: if ($settings->{$item}->{'_LC_adv'} == 0) {
2192: $checked = '';
2193: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2194: $checked = 'checked="checked" ';
2195: }
1.79 raeburn 2196: }
1.72 raeburn 2197: }
1.101 raeburn 2198: $datatable .= '<span class="LC_nobreak"><label>'.
2199: '<input type="checkbox" name="'.$context.'_'.$item.
2200: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2201: '</label></span> ';
2202: }
2203: }
2204: if ($context eq 'requestcourses') {
2205: $datatable .= '</tr><tr>';
2206: foreach my $item (@usertools) {
1.106 raeburn 2207: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2208: }
1.101 raeburn 2209: $datatable .= '</tr></table>';
1.72 raeburn 2210: }
1.98 raeburn 2211: $datatable .= '</td></tr>';
1.30 raeburn 2212: $$rowtotal += $typecount;
1.3 raeburn 2213: return $datatable;
2214: }
2215:
1.163 raeburn 2216: sub print_requestmail {
2217: my ($dom,$action,$settings,$rowtotal) = @_;
1.208 raeburn 2218: my ($now,$datatable,%currapp);
1.102 raeburn 2219: $now = time;
2220: if (ref($settings) eq 'HASH') {
2221: if (ref($settings->{'notify'}) eq 'HASH') {
2222: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2223: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2224: }
2225: }
2226: }
1.191 raeburn 2227: my $numinrow = 2;
1.224 raeburn 2228: my $css_class;
2229: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.163 raeburn 2230: my $text;
2231: if ($action eq 'requestcourses') {
2232: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2233: } elsif ($action eq 'requestauthor') {
2234: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2235: } else {
1.224 raeburn 2236: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2237: }
1.224 raeburn 2238: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2239: ' <td>'.$text.'</td>'.
1.102 raeburn 2240: ' <td class="LC_left_item">';
1.191 raeburn 2241: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2242: $action.'notifyapproval',%currapp);
1.191 raeburn 2243: if ($numdc > 0) {
2244: $datatable .= $table;
1.102 raeburn 2245: } else {
2246: $datatable .= &mt('There are no active Domain Coordinators');
2247: }
2248: $datatable .='</td></tr>';
2249: return $datatable;
2250: }
2251:
1.216 raeburn 2252: sub print_studentcode {
2253: my ($settings,$rowtotal) = @_;
2254: my $rownum = 0;
1.218 raeburn 2255: my ($output,%current);
1.271 raeburn 2256: my @crstypes = ('official','unofficial','community','textbook','placement');
1.248 raeburn 2257: if (ref($settings) eq 'HASH') {
2258: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2259: foreach my $type (@crstypes) {
2260: $current{$type} = $settings->{'uniquecode'}{$type};
2261: }
1.218 raeburn 2262: }
2263: }
2264: $output .= '<tr>'.
2265: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2266: '<td class="LC_left_item">';
2267: foreach my $type (@crstypes) {
2268: my $check = ' ';
2269: if ($current{$type}) {
2270: $check = ' checked="checked" ';
2271: }
2272: $output .= '<span class="LC_nobreak"><label>'.
2273: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2274: &mt($type).'</label></span>'.(' 'x2).' ';
2275: }
2276: $output .= '</td></tr>';
2277: $$rowtotal ++;
2278: return $output;
1.216 raeburn 2279: }
2280:
2281: sub print_textbookcourses {
1.242 raeburn 2282: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2283: my $rownum = 0;
2284: my $css_class;
2285: my $itemcount = 1;
2286: my $maxnum = 0;
2287: my $bookshash;
2288: if (ref($settings) eq 'HASH') {
1.242 raeburn 2289: $bookshash = $settings->{$type};
1.216 raeburn 2290: }
2291: my %ordered;
2292: if (ref($bookshash) eq 'HASH') {
2293: foreach my $item (keys(%{$bookshash})) {
2294: if (ref($bookshash->{$item}) eq 'HASH') {
2295: my $num = $bookshash->{$item}{'order'};
2296: $ordered{$num} = $item;
2297: }
2298: }
2299: }
2300: my $confname = $dom.'-domainconfig';
2301: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2302: my $maxnum = scalar(keys(%ordered));
2303: my $datatable;
1.216 raeburn 2304: if (keys(%ordered)) {
2305: my @items = sort { $a <=> $b } keys(%ordered);
2306: for (my $i=0; $i<@items; $i++) {
2307: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2308: my $key = $ordered{$items[$i]};
2309: my %coursehash=&Apache::lonnet::coursedescription($key);
2310: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2311: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2312: if (ref($bookshash->{$key}) eq 'HASH') {
2313: $subject = $bookshash->{$key}->{'subject'};
2314: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2315: if ($type eq 'textbooks') {
1.243 raeburn 2316: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2317: $author = $bookshash->{$key}->{'author'};
2318: $image = $bookshash->{$key}->{'image'};
2319: if ($image ne '') {
2320: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2321: my $imagethumb = "$path/tn-".$imagefile;
2322: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2323: }
1.216 raeburn 2324: }
2325: }
1.242 raeburn 2326: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2327: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2328: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2329: for (my $k=0; $k<=$maxnum; $k++) {
2330: my $vpos = $k+1;
2331: my $selstr;
2332: if ($k == $i) {
2333: $selstr = ' selected="selected" ';
2334: }
2335: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2336: }
2337: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2338: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2339: &mt('Delete?').'</label></span></td>'.
2340: '<td colspan="2">'.
1.242 raeburn 2341: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2342: (' 'x2).
1.242 raeburn 2343: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2344: if ($type eq 'textbooks') {
2345: $datatable .= (' 'x2).
1.243 raeburn 2346: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2347: (' 'x2).
1.242 raeburn 2348: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2349: (' 'x2).
2350: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2351: if ($image) {
1.267 raeburn 2352: $datatable .= $imgsrc.
1.242 raeburn 2353: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2354: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2355: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2356: }
2357: if ($switchserver) {
2358: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2359: } else {
2360: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2361: }
1.216 raeburn 2362: }
1.242 raeburn 2363: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2364: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2365: $coursetitle.'</span></td></tr>'."\n";
2366: $itemcount ++;
2367: }
2368: }
2369: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2370: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2371: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2372: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2373: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2374: for (my $k=0; $k<$maxnum+1; $k++) {
2375: my $vpos = $k+1;
2376: my $selstr;
2377: if ($k == $maxnum) {
2378: $selstr = ' selected="selected" ';
2379: }
2380: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2381: }
2382: $datatable .= '</select> '."\n".
1.242 raeburn 2383: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.216 raeburn 2384: '<td colspan="2">'.
1.242 raeburn 2385: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2386: (' 'x2).
1.242 raeburn 2387: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2388: (' 'x2);
2389: if ($type eq 'textbooks') {
1.243 raeburn 2390: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2391: (' 'x2).
2392: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2393: (' 'x2).
2394: '<span class="LC_nobreak">'.&mt('Image:').' ';
2395: if ($switchserver) {
2396: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2397: } else {
2398: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2399: }
1.216 raeburn 2400: }
2401: $datatable .= '</span>'."\n".
2402: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2403: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2404: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2405: &Apache::loncommon::selectcourse_link
1.242 raeburn 2406: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.216 raeburn 2407: '</span></td>'."\n".
2408: '</tr>'."\n";
2409: $itemcount ++;
2410: return $datatable;
2411: }
2412:
1.217 raeburn 2413: sub textbookcourses_javascript {
1.242 raeburn 2414: my ($settings) = @_;
2415: return unless(ref($settings) eq 'HASH');
2416: my (%ordered,%total,%jstext);
2417: foreach my $type ('textbooks','templates') {
2418: $total{$type} = 0;
2419: if (ref($settings->{$type}) eq 'HASH') {
2420: foreach my $item (keys(%{$settings->{$type}})) {
2421: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2422: my $num = $settings->{$type}->{$item}{'order'};
2423: $ordered{$type}{$num} = $item;
2424: }
2425: }
2426: $total{$type} = scalar(keys(%{$settings->{$type}}));
2427: }
2428: my @jsarray = ();
2429: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2430: push(@jsarray,$ordered{$type}{$item});
2431: }
2432: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2433: }
2434: return <<"ENDSCRIPT";
2435: <script type="text/javascript">
2436: // <![CDATA[
1.242 raeburn 2437: function reorderBooks(form,item,caller) {
1.217 raeburn 2438: var changedVal;
1.242 raeburn 2439: $jstext{'textbooks'};
2440: $jstext{'templates'};
2441: var newpos;
2442: var maxh;
2443: if (caller == 'textbooks') {
2444: newpos = 'textbooks_addbook_pos';
2445: maxh = 1 + $total{'textbooks'};
2446: } else {
2447: newpos = 'templates_addbook_pos';
2448: maxh = 1 + $total{'templates'};
2449: }
1.217 raeburn 2450: var current = new Array;
2451: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2452: if (item == newpos) {
2453: changedVal = newitemVal;
2454: } else {
2455: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2456: current[newitemVal] = newpos;
2457: }
1.242 raeburn 2458: if (caller == 'textbooks') {
2459: for (var i=0; i<textbooks.length; i++) {
2460: var elementName = 'textbooks_'+textbooks[i];
2461: if (elementName != item) {
2462: if (form.elements[elementName]) {
2463: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2464: current[currVal] = elementName;
2465: }
2466: }
2467: }
2468: }
2469: if (caller == 'templates') {
2470: for (var i=0; i<templates.length; i++) {
2471: var elementName = 'templates_'+templates[i];
2472: if (elementName != item) {
2473: if (form.elements[elementName]) {
2474: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2475: current[currVal] = elementName;
2476: }
1.217 raeburn 2477: }
2478: }
2479: }
2480: var oldVal;
2481: for (var j=0; j<maxh; j++) {
2482: if (current[j] == undefined) {
2483: oldVal = j;
2484: }
2485: }
2486: if (oldVal < changedVal) {
2487: for (var k=oldVal+1; k<=changedVal ; k++) {
2488: var elementName = current[k];
2489: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2490: }
2491: } else {
2492: for (var k=changedVal; k<oldVal; k++) {
2493: var elementName = current[k];
2494: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2495: }
2496: }
2497: return;
2498: }
2499:
2500: // ]]>
2501: </script>
2502:
2503: ENDSCRIPT
2504: }
2505:
1.267 raeburn 2506: sub ltitools_javascript {
2507: my ($settings) = @_;
2508: return unless(ref($settings) eq 'HASH');
2509: my (%ordered,$total,%jstext);
2510: $total = 0;
2511: foreach my $item (keys(%{$settings})) {
2512: if (ref($settings->{$item}) eq 'HASH') {
2513: my $num = $settings->{$item}{'order'};
2514: $ordered{$num} = $item;
2515: }
2516: }
2517: $total = scalar(keys(%{$settings}));
2518: my @jsarray = ();
2519: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2520: push(@jsarray,$ordered{$item});
2521: }
2522: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2523: return <<"ENDSCRIPT";
2524: <script type="text/javascript">
2525: // <![CDATA[
2526: function reorderLTI(form,item) {
2527: var changedVal;
2528: $jstext
2529: var newpos = 'ltitools_add_pos';
2530: var maxh = 1 + $total;
2531: var current = new Array;
2532: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2533: if (item == newpos) {
2534: changedVal = newitemVal;
2535: } else {
2536: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2537: current[newitemVal] = newpos;
2538: }
2539: for (var i=0; i<ltitools.length; i++) {
2540: var elementName = 'ltitools_'+ltitools[i];
2541: if (elementName != item) {
2542: if (form.elements[elementName]) {
2543: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2544: current[currVal] = elementName;
2545: }
2546: }
2547: }
2548: var oldVal;
2549: for (var j=0; j<maxh; j++) {
2550: if (current[j] == undefined) {
2551: oldVal = j;
2552: }
2553: }
2554: if (oldVal < changedVal) {
2555: for (var k=oldVal+1; k<=changedVal ; k++) {
2556: var elementName = current[k];
2557: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2558: }
2559: } else {
2560: for (var k=changedVal; k<oldVal; k++) {
2561: var elementName = current[k];
2562: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2563: }
2564: }
2565: return;
2566: }
2567:
2568: // ]]>
2569: </script>
2570:
2571: ENDSCRIPT
2572: }
2573:
1.3 raeburn 2574: sub print_autoenroll {
1.30 raeburn 2575: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2576: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 2577: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2578: if (ref($settings) eq 'HASH') {
2579: if (exists($settings->{'run'})) {
2580: if ($settings->{'run'} eq '0') {
2581: $runoff = ' checked="checked" ';
2582: $runon = ' ';
2583: } else {
2584: $runon = ' checked="checked" ';
2585: $runoff = ' ';
2586: }
2587: } else {
2588: if ($autorun) {
2589: $runon = ' checked="checked" ';
2590: $runoff = ' ';
2591: } else {
2592: $runoff = ' checked="checked" ';
2593: $runon = ' ';
2594: }
2595: }
1.129 raeburn 2596: if (exists($settings->{'co-owners'})) {
2597: if ($settings->{'co-owners'} eq '0') {
2598: $coownersoff = ' checked="checked" ';
2599: $coownerson = ' ';
2600: } else {
2601: $coownerson = ' checked="checked" ';
2602: $coownersoff = ' ';
2603: }
2604: } else {
2605: $coownersoff = ' checked="checked" ';
2606: $coownerson = ' ';
2607: }
1.3 raeburn 2608: if (exists($settings->{'sender_domain'})) {
2609: $defdom = $settings->{'sender_domain'};
2610: }
1.274 raeburn 2611: if (exists($settings->{'autofailsafe'})) {
2612: $failsafe = $settings->{'autofailsafe'};
2613: }
1.14 raeburn 2614: } else {
2615: if ($autorun) {
2616: $runon = ' checked="checked" ';
2617: $runoff = ' ';
2618: } else {
2619: $runoff = ' checked="checked" ';
2620: $runon = ' ';
2621: }
1.3 raeburn 2622: }
2623: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2624: my $notif_sender;
2625: if (ref($settings) eq 'HASH') {
2626: $notif_sender = $settings->{'sender_uname'};
2627: }
1.3 raeburn 2628: my $datatable='<tr class="LC_odd_row">'.
2629: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2630: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2631: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2632: $runon.' value="1" />'.&mt('Yes').'</label> '.
2633: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2634: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2635: '</tr><tr>'.
2636: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2637: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2638: &mt('username').': '.
2639: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2640: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2641: ': '.$domform.'</span></td></tr>'.
2642: '<tr class="LC_odd_row">'.
2643: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2644: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2645: '<input type="radio" name="autoassign_coowners"'.
2646: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2647: '<label><input type="radio" name="autoassign_coowners"'.
2648: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 2649: '</tr><tr>'.
2650: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2651: '<td class="LC_right_item"><span class="LC_nobreak">'.
2652: '<input type="text" name="autoenroll_failsafe"'.
2653: ' value="'.$failsafe.'" size="4" /></td></tr>';
2654: $$rowtotal += 4;
1.3 raeburn 2655: return $datatable;
2656: }
2657:
2658: sub print_autoupdate {
1.30 raeburn 2659: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2660: my $datatable;
2661: if ($position eq 'top') {
2662: my $updateon = ' ';
2663: my $updateoff = ' checked="checked" ';
2664: my $classlistson = ' ';
2665: my $classlistsoff = ' checked="checked" ';
2666: if (ref($settings) eq 'HASH') {
2667: if ($settings->{'run'} eq '1') {
2668: $updateon = $updateoff;
2669: $updateoff = ' ';
2670: }
2671: if ($settings->{'classlists'} eq '1') {
2672: $classlistson = $classlistsoff;
2673: $classlistsoff = ' ';
2674: }
2675: }
2676: my %title = (
2677: run => 'Auto-update active?',
2678: classlists => 'Update information in classlists?',
2679: );
2680: $datatable = '<tr class="LC_odd_row">'.
2681: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2682: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2683: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2684: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2685: '<label><input type="radio" name="autoupdate_run"'.
2686: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2687: '</tr><tr>'.
2688: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2689: '<td class="LC_right_item"><span class="LC_nobreak">'.
2690: '<label><input type="radio" name="classlists"'.
2691: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2692: '<label><input type="radio" name="classlists"'.
2693: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2694: '</tr>';
1.30 raeburn 2695: $$rowtotal += 2;
1.131 raeburn 2696: } elsif ($position eq 'middle') {
2697: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2698: my $numinrow = 3;
2699: my $locknamesettings;
2700: $datatable .= &insttypes_row($settings,$types,$usertypes,
2701: $dom,$numinrow,$othertitle,
2702: 'lockablenames');
2703: $$rowtotal ++;
1.3 raeburn 2704: } else {
1.44 raeburn 2705: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2706: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2707: 'permanentemail','id');
1.33 raeburn 2708: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2709: my $numrows = 0;
1.26 raeburn 2710: if (ref($types) eq 'ARRAY') {
2711: if (@{$types} > 0) {
2712: $datatable =
2713: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2714: \@fields,$types,\$numrows);
1.30 raeburn 2715: $$rowtotal += @{$types};
1.26 raeburn 2716: }
1.3 raeburn 2717: }
2718: $datatable .=
2719: &usertype_update_row($settings,{'default' => $othertitle},
2720: \%fieldtitles,\@fields,['default'],
2721: \$numrows);
1.30 raeburn 2722: $$rowtotal ++;
1.3 raeburn 2723: }
2724: return $datatable;
2725: }
2726:
1.125 raeburn 2727: sub print_autocreate {
2728: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 2729: my (%createon,%createoff,%currhash);
1.125 raeburn 2730: my @types = ('xml','req');
2731: if (ref($settings) eq 'HASH') {
2732: foreach my $item (@types) {
2733: $createoff{$item} = ' checked="checked" ';
2734: $createon{$item} = ' ';
2735: if (exists($settings->{$item})) {
2736: if ($settings->{$item}) {
2737: $createon{$item} = ' checked="checked" ';
2738: $createoff{$item} = ' ';
2739: }
2740: }
2741: }
1.210 raeburn 2742: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 2743: $currhash{$settings->{'xmldc'}} = 1;
2744: }
1.125 raeburn 2745: } else {
2746: foreach my $item (@types) {
2747: $createoff{$item} = ' checked="checked" ';
2748: $createon{$item} = ' ';
2749: }
2750: }
2751: $$rowtotal += 2;
1.191 raeburn 2752: my $numinrow = 2;
1.125 raeburn 2753: my $datatable='<tr class="LC_odd_row">'.
2754: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2755: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2756: '<input type="radio" name="autocreate_xml"'.
2757: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2758: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2759: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2760: '</td></tr><tr>'.
2761: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2762: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2763: '<input type="radio" name="autocreate_req"'.
2764: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2765: '<label><input type="radio" name="autocreate_req"'.
2766: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 2767: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2768: 'autocreate_xmldc',%currhash);
1.247 raeburn 2769: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2770: if ($numdc > 1) {
1.247 raeburn 2771: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2772: '</td><td class="LC_left_item">';
1.125 raeburn 2773: } else {
1.247 raeburn 2774: $datatable .= &mt('Course creation processed as:').
2775: '</td><td class="LC_right_item">';
1.125 raeburn 2776: }
1.247 raeburn 2777: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 2778: $$rowtotal += $rows;
1.125 raeburn 2779: return $datatable;
2780: }
2781:
1.23 raeburn 2782: sub print_directorysrch {
1.277 raeburn 2783: my ($position,$dom,$settings,$rowtotal) = @_;
2784: my $datatable;
2785: if ($position eq 'top') {
2786: my $instsrchon = ' ';
2787: my $instsrchoff = ' checked="checked" ';
2788: my ($exacton,$containson,$beginson);
2789: my $instlocalon = ' ';
2790: my $instlocaloff = ' checked="checked" ';
2791: if (ref($settings) eq 'HASH') {
2792: if ($settings->{'available'} eq '1') {
2793: $instsrchon = $instsrchoff;
2794: $instsrchoff = ' ';
2795: }
2796: if ($settings->{'localonly'} eq '1') {
2797: $instlocalon = $instlocaloff;
2798: $instlocaloff = ' ';
2799: }
2800: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2801: foreach my $type (@{$settings->{'searchtypes'}}) {
2802: if ($type eq 'exact') {
2803: $exacton = ' checked="checked" ';
2804: } elsif ($type eq 'contains') {
2805: $containson = ' checked="checked" ';
2806: } elsif ($type eq 'begins') {
2807: $beginson = ' checked="checked" ';
2808: }
2809: }
2810: } else {
2811: if ($settings->{'searchtypes'} eq 'exact') {
2812: $exacton = ' checked="checked" ';
2813: } elsif ($settings->{'searchtypes'} eq 'contains') {
2814: $containson = ' checked="checked" ';
2815: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 2816: $exacton = ' checked="checked" ';
2817: $containson = ' checked="checked" ';
2818: }
2819: }
1.277 raeburn 2820: }
2821: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2822: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2823:
2824: my $numinrow = 4;
2825: my $cansrchrow = 0;
2826: $datatable='<tr class="LC_odd_row">'.
2827: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
2828: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2829: '<input type="radio" name="dirsrch_available"'.
2830: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
2831: '<label><input type="radio" name="dirsrch_available"'.
2832: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2833: '</tr><tr>'.
2834: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
2835: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2836: '<input type="radio" name="dirsrch_instlocalonly"'.
2837: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2838: '<label><input type="radio" name="dirsrch_instlocalonly"'.
2839: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2840: '</tr>';
2841: $$rowtotal += 2;
2842: if (ref($usertypes) eq 'HASH') {
2843: if (keys(%{$usertypes}) > 0) {
2844: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2845: $numinrow,$othertitle,'cansearch');
2846: $cansrchrow = 1;
1.25 raeburn 2847: }
1.23 raeburn 2848: }
1.277 raeburn 2849: if ($cansrchrow) {
2850: $$rowtotal ++;
2851: $datatable .= '<tr>';
2852: } else {
2853: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 2854: }
1.277 raeburn 2855: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2856: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2857: foreach my $title (@{$titleorder}) {
2858: if (defined($searchtitles->{$title})) {
2859: my $check = ' ';
2860: if (ref($settings) eq 'HASH') {
2861: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2862: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2863: $check = ' checked="checked" ';
2864: }
1.39 raeburn 2865: }
1.25 raeburn 2866: }
1.277 raeburn 2867: $datatable .= '<td class="LC_left_item">'.
2868: '<span class="LC_nobreak"><label>'.
2869: '<input type="checkbox" name="searchby" '.
2870: 'value="'.$title.'"'.$check.'/>'.
2871: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 2872: }
2873: }
1.277 raeburn 2874: $datatable .= '</tr></table></td></tr>';
2875: $$rowtotal ++;
2876: if ($cansrchrow) {
2877: $datatable .= '<tr class="LC_odd_row">';
2878: } else {
2879: $datatable .= '<tr>';
2880: }
2881: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2882: '<td class="LC_left_item" colspan="2">'.
2883: '<span class="LC_nobreak"><label>'.
2884: '<input type="checkbox" name="searchtypes" '.
2885: $exacton.' value="exact" />'.&mt('Exact match').
2886: '</label> '.
2887: '<label><input type="checkbox" name="searchtypes" '.
2888: $beginson.' value="begins" />'.&mt('Begins with').
2889: '</label> '.
2890: '<label><input type="checkbox" name="searchtypes" '.
2891: $containson.' value="contains" />'.&mt('Contains').
2892: '</label></span></td></tr>';
2893: $$rowtotal ++;
1.26 raeburn 2894: } else {
1.277 raeburn 2895: my $domsrchon = ' checked="checked" ';
2896: my $domsrchoff = ' ';
2897: my $domlocalon = ' ';
2898: my $domlocaloff = ' checked="checked" ';
2899: if (ref($settings) eq 'HASH') {
2900: if ($settings->{'lclocalonly'} eq '1') {
2901: $domlocalon = $domlocaloff;
2902: $domlocaloff = ' ';
2903: }
2904: if ($settings->{'lcavailable'} eq '0') {
2905: $domsrchoff = $domsrchon;
2906: $domsrchon = ' ';
2907: }
2908: }
2909: $datatable='<tr class="LC_odd_row">'.
2910: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
2911: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2912: '<input type="radio" name="dirsrch_domavailable"'.
2913: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
2914: '<label><input type="radio" name="dirsrch_domavailable"'.
2915: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2916: '</tr><tr>'.
2917: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
2918: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2919: '<input type="radio" name="dirsrch_domlocalonly"'.
2920: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2921: '<label><input type="radio" name="dirsrch_domlocalonly"'.
2922: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2923: '</tr>';
2924: $$rowtotal += 2;
1.26 raeburn 2925: }
1.25 raeburn 2926: return $datatable;
2927: }
2928:
1.28 raeburn 2929: sub print_contacts {
1.30 raeburn 2930: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2931: my $datatable;
2932: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2933: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2934: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.203 raeburn 2935: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2936: foreach my $type (@mailings) {
2937: $otheremails{$type} = '';
2938: }
1.134 raeburn 2939: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2940: if (ref($settings) eq 'HASH') {
2941: foreach my $item (@contacts) {
2942: if (exists($settings->{$item})) {
2943: $to{$item} = $settings->{$item};
2944: }
2945: }
2946: foreach my $type (@mailings) {
2947: if (exists($settings->{$type})) {
2948: if (ref($settings->{$type}) eq 'HASH') {
2949: foreach my $item (@contacts) {
2950: if ($settings->{$type}{$item}) {
2951: $checked{$type}{$item} = ' checked="checked" ';
2952: }
2953: }
2954: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2955: if ($type eq 'helpdeskmail') {
2956: $bccemails{$type} = $settings->{$type}{'bcc'};
2957: }
1.28 raeburn 2958: }
1.89 raeburn 2959: } elsif ($type eq 'lonstatusmail') {
2960: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2961: }
2962: }
2963: } else {
2964: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2965: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2966: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2967: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2968: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2969: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2970: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.190 raeburn 2971: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.203 raeburn 2972: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2973: }
2974: my ($titles,$short_titles) = &contact_titles();
2975: my $rownum = 0;
2976: my $css_class;
2977: foreach my $item (@contacts) {
1.69 raeburn 2978: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2979: $datatable .= '<tr'.$css_class.'>'.
2980: '<td><span class="LC_nobreak">'.$titles->{$item}.
2981: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2982: '<input type="text" name="'.$item.'" value="'.
2983: $to{$item}.'" /></td></tr>';
1.203 raeburn 2984: $rownum ++;
1.28 raeburn 2985: }
2986: foreach my $type (@mailings) {
1.69 raeburn 2987: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2988: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2989: '<td><span class="LC_nobreak">'.
2990: $titles->{$type}.': </span></td>'.
1.28 raeburn 2991: '<td class="LC_left_item">'.
2992: '<span class="LC_nobreak">';
2993: foreach my $item (@contacts) {
2994: $datatable .= '<label>'.
2995: '<input type="checkbox" name="'.$type.'"'.
2996: $checked{$type}{$item}.
2997: ' value="'.$item.'" />'.$short_titles->{$item}.
2998: '</label> ';
2999: }
3000: $datatable .= '</span><br />'.&mt('Others').': '.
3001: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 3002: 'value="'.$otheremails{$type}.'" />';
3003: if ($type eq 'helpdeskmail') {
1.136 raeburn 3004: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 3005: '<input type="text" name="'.$type.'_bcc" '.
3006: 'value="'.$bccemails{$type}.'" />';
3007: }
3008: $datatable .= '</td></tr>'."\n";
1.203 raeburn 3009: $rownum ++;
1.28 raeburn 3010: }
1.203 raeburn 3011: my %choices;
3012: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
3013: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3014: &mt('LON-CAPA core group - MSU'),600,500));
3015: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
3016: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3017: &mt('LON-CAPA core group - MSU'),600,500));
3018: my @toggles = ('reporterrors','reportupdates');
3019: my %defaultchecked = ('reporterrors' => 'on',
3020: 'reportupdates' => 'on');
3021: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3022: \%choices,$rownum);
3023: $datatable .= $reports;
1.30 raeburn 3024: $$rowtotal += $rownum;
1.28 raeburn 3025: return $datatable;
3026: }
3027:
1.118 jms 3028: sub print_helpsettings {
1.168 raeburn 3029: my ($dom,$confname,$settings,$rowtotal) = @_;
3030: my ($datatable,$itemcount);
1.166 raeburn 3031: $itemcount = 1;
1.168 raeburn 3032: my (%choices,%defaultchecked,@toggles);
3033: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3034: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3035: &mt('LON-CAPA bug tracker'),600,500));
3036: %defaultchecked = ('submitbugs' => 'on');
3037: @toggles = ('submitbugs',);
1.166 raeburn 3038:
1.168 raeburn 3039: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3040: \%choices,$itemcount);
1.166 raeburn 3041: return $datatable;
1.121 raeburn 3042: }
3043:
3044: sub radiobutton_prefs {
1.192 raeburn 3045: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 3046: $additional,$align) = @_;
1.121 raeburn 3047: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3048: (ref($choices) eq 'HASH'));
3049:
1.170 raeburn 3050: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 3051:
3052: foreach my $item (@{$toggles}) {
3053: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3054: $checkedon{$item} = ' checked="checked" ';
3055: $checkedoff{$item} = ' ';
1.121 raeburn 3056: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3057: $checkedoff{$item} = ' checked="checked" ';
3058: $checkedon{$item} = ' ';
3059: }
3060: }
3061: if (ref($settings) eq 'HASH') {
1.121 raeburn 3062: foreach my $item (@{$toggles}) {
1.118 jms 3063: if ($settings->{$item} eq '1') {
3064: $checkedon{$item} = ' checked="checked" ';
3065: $checkedoff{$item} = ' ';
3066: } elsif ($settings->{$item} eq '0') {
3067: $checkedoff{$item} = ' checked="checked" ';
3068: $checkedon{$item} = ' ';
3069: }
3070: }
1.121 raeburn 3071: }
1.192 raeburn 3072: if ($onclick) {
3073: $onclick = ' onclick="'.$onclick.'"';
3074: }
1.121 raeburn 3075: foreach my $item (@{$toggles}) {
1.118 jms 3076: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3077: $datatable .=
1.192 raeburn 3078: '<tr'.$css_class.'><td valign="top">'.
3079: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 3080: '</span></td>';
3081: if ($align eq 'left') {
3082: $datatable .= '<td class="LC_left_item">';
3083: } else {
3084: $datatable .= '<td class="LC_right_item">';
3085: }
3086: $datatable .=
3087: '<span class="LC_nobreak">'.
1.118 jms 3088: '<label><input type="radio" name="'.
1.192 raeburn 3089: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3090: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 3091: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3092: '</span>'.$additional.
3093: '</td>'.
1.118 jms 3094: '</tr>';
3095: $itemcount ++;
1.121 raeburn 3096: }
3097: return ($datatable,$itemcount);
3098: }
3099:
1.267 raeburn 3100: sub print_ltitools {
3101: my ($dom,$settings,$rowtotal) = @_;
3102: my $rownum = 0;
3103: my $css_class;
3104: my $itemcount = 1;
3105: my $maxnum = 0;
3106: my %ordered;
3107: if (ref($settings) eq 'HASH') {
3108: foreach my $item (keys(%{$settings})) {
3109: if (ref($settings->{$item}) eq 'HASH') {
3110: my $num = $settings->{$item}{'order'};
3111: $ordered{$num} = $item;
3112: }
3113: }
3114: }
3115: my $confname = $dom.'-domainconfig';
3116: my $switchserver = &check_switchserver($dom,$confname);
3117: my $maxnum = scalar(keys(%ordered));
3118: my $datatable = <itools_javascript($settings);
3119: my %lt = <itools_names();
3120: my @courseroles = ('cc','in','ta','ep','st');
3121: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
3122: my @fields = ('fullname','firstname','lastname','email','user','roles');
3123: if (keys(%ordered)) {
3124: my @items = sort { $a <=> $b } keys(%ordered);
3125: for (my $i=0; $i<@items; $i++) {
3126: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3127: my $item = $ordered{$items[$i]};
3128: my ($title,$key,$secret,$url,$imgsrc,$version);
3129: if (ref($settings->{$item}) eq 'HASH') {
3130: $title = $settings->{$item}->{'title'};
3131: $url = $settings->{$item}->{'url'};
3132: $key = $settings->{$item}->{'key'};
3133: $secret = $settings->{$item}->{'secret'};
3134: my $image = $settings->{$item}->{'image'};
3135: if ($image ne '') {
3136: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
3137: }
3138: }
3139: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_".$item."'".');"';
3140: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3141: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
3142: for (my $k=0; $k<=$maxnum; $k++) {
3143: my $vpos = $k+1;
3144: my $selstr;
3145: if ($k == $i) {
3146: $selstr = ' selected="selected" ';
3147: }
3148: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3149: }
3150: $datatable .= '</select>'.(' 'x2).
3151: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
3152: &mt('Delete?').'</label></span></td>'.
3153: '<td colspan="2">'.
3154: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3155: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
3156: (' 'x2).
3157: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
3158: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
3159: (' 'x2).
3160: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
3161: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3162: '<br /><br />'.
3163: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_url_'.$i.'"'.
3164: ' value="'.$url.'" /></span>'.
3165: (' 'x2).
3166: '<span class="LC_nobreak">'.$lt{'key'}.
3167: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
3168: (' 'x2).
3169: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
3170: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
3171: '<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>'.
3172: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
3173: '</fieldset>'.
3174: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3175: '<span class="LC_nobreak">'.&mt('Display target:');
3176: my %currdisp;
3177: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
3178: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
3179: $currdisp{'window'} = ' checked="checked"';
3180: } else {
3181: $currdisp{'iframe'} = ' checked="checked"';
3182: }
3183: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
3184: $currdisp{'width'} = $1;
3185: }
3186: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
3187: $currdisp{'height'} = $1;
3188: }
3189: } else {
3190: $currdisp{'iframe'} = ' checked="checked"';
3191: }
3192: foreach my $disp ('iframe','window') {
3193: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
3194: $lt{$disp}.'</label>'.(' 'x2);
3195: }
3196: $datatable .= (' 'x4);
3197: foreach my $dimen ('width','height') {
3198: $datatable .= '<label>'.$lt{$dimen}.' '.
3199: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
3200: (' 'x2);
3201: }
3202: $datatable .= '<br />';
3203: foreach my $extra ('passback','roster') {
3204: my $checkedon = '';
3205: my $checkedoff = ' checked="checked"';
3206: if ($settings->{$item}->{$extra}) {
3207: $checkedon = $checkedoff;
3208: $checkedoff = '';
3209: }
3210: $datatable .= $lt{$extra}.' '.
3211: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.' />'.
3212: &mt('Yes').'</label>'.(' 'x2).
3213: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.' />'.
3214: &mt('No').'</label>'.(' 'x4);
3215: }
3216: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': ';
3217: if ($imgsrc) {
3218: $datatable .= $imgsrc.
3219: '<label><input type="checkbox" name="ltitools_image_del"'.
3220: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
3221: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
3222: } else {
3223: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3224: }
3225: if ($switchserver) {
3226: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3227: } else {
3228: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
3229: }
3230: $datatable .= '</span></fieldset>';
3231: my (%checkedfields,%rolemaps);
3232: if (ref($settings->{$item}) eq 'HASH') {
3233: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
3234: %checkedfields = %{$settings->{$item}->{'fields'}};
3235: }
3236: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
3237: %rolemaps = %{$settings->{$item}->{'roles'}};
3238: $checkedfields{'roles'} = 1;
3239: }
3240: }
3241: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3242: '<span class="LC_nobreak">';
3243: foreach my $field (@fields) {
3244: my $checked;
3245: if ($checkedfields{$field}) {
3246: $checked = ' checked="checked"';
3247: }
3248: $datatable .= '<label>'.
3249: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
3250: $lt{$field}.'</label>'.(' ' x2);
3251: }
3252: $datatable .= '</span></fieldset>'.
3253: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3254: foreach my $role (@courseroles) {
3255: my ($selected,$selectnone);
3256: if (!$rolemaps{$role}) {
3257: $selectnone = ' selected="selected"';
3258: }
3259: $datatable .= '<td align="center">'.
3260: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3261: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
3262: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
3263: foreach my $ltirole (@ltiroles) {
3264: unless ($selectnone) {
3265: if ($rolemaps{$role} eq $ltirole) {
3266: $selected = ' selected="selected"';
3267: } else {
3268: $selected = '';
3269: }
3270: }
3271: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
3272: }
3273: $datatable .= '</select></td>';
3274: }
1.273 raeburn 3275: $datatable .= '</tr></table></fieldset>';
3276: my %courseconfig;
3277: if (ref($settings->{$item}) eq 'HASH') {
3278: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
3279: %courseconfig = %{$settings->{$item}->{'crsconf'}};
3280: }
3281: }
3282: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
3283: foreach my $item ('label','title','target') {
3284: my $checked;
3285: if ($courseconfig{$item}) {
3286: $checked = ' checked="checked"';
3287: }
3288: $datatable .= '<label>'.
3289: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
3290: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3291: }
3292: $datatable .= '</span></fieldset>'.
1.267 raeburn 3293: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3294: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
3295: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
3296: my %custom = %{$settings->{$item}->{'custom'}};
3297: if (keys(%custom) > 0) {
3298: foreach my $key (sort(keys(%custom))) {
3299: $datatable .= '<tr><td><span class="LC_nobreak">'.
3300: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
3301: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
3302: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
3303: ' value="'.$custom{$key}.'" /></td></tr>';
3304: }
3305: }
3306: }
3307: $datatable .= '<tr><td><span class="LC_nobreak">'.
3308: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
3309: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
3310: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
3311: $datatable .= '</table></fieldset></td></tr>'."\n";
3312: $itemcount ++;
3313: }
3314: }
3315: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3316: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_add_pos'".');"';
3317: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
3318: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
3319: '<select name="ltitools_add_pos"'.$chgstr.'>';
3320: for (my $k=0; $k<$maxnum+1; $k++) {
3321: my $vpos = $k+1;
3322: my $selstr;
3323: if ($k == $maxnum) {
3324: $selstr = ' selected="selected" ';
3325: }
3326: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3327: }
3328: $datatable .= '</select> '."\n".
3329: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
3330: '<td colspan="2">'.
3331: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3332: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
3333: (' 'x2).
3334: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
3335: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
3336: (' 'x2).
3337: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
3338: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3339: '<br />'.
3340: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
3341: (' 'x2).
3342: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
3343: (' 'x2).
3344: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
3345: '<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".
3346: '</fieldset>'.
3347: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3348: '<span class="LC_nobreak">'.&mt('Display target:');
3349: my %defaultdisp;
3350: $defaultdisp{'iframe'} = ' checked="checked"';
3351: foreach my $disp ('iframe','window') {
3352: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
3353: $lt{$disp}.'</label>'.(' 'x2);
3354: }
3355: $datatable .= (' 'x4);
3356: foreach my $dimen ('width','height') {
3357: $datatable .= '<label>'.$lt{$dimen}.' '.
3358: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
3359: (' 'x2);
3360: }
3361: $datatable .= '<br />';
3362: foreach my $extra ('passback','roster') {
3363: $datatable .= $lt{$extra}.' '.
3364: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="1" />'.
3365: &mt('Yes').'</label>'.(' 'x2).
3366: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="0" checked="checked" />'.
3367: &mt('No').'</label>'.(' 'x4);
3368: }
3369: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': '.
3370: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3371: if ($switchserver) {
3372: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3373: } else {
3374: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
3375: }
3376: $datatable .= '</span></fieldset>'.
3377: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3378: '<span class="LC_nobreak">';
3379: foreach my $field (@fields) {
3380: $datatable .= '<label>'.
3381: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
3382: $lt{$field}.'</label>'.(' ' x2);
3383: }
3384: $datatable .= '</span></fieldset>'.
3385: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3386: foreach my $role (@courseroles) {
3387: my ($checked,$checkednone);
3388: $datatable .= '<td align="center">'.
3389: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3390: '<select name="ltitools_add_roles_'.$role.'">'.
3391: '<option value="" selected="selected">'.&mt('Select').'</option>';
3392: foreach my $ltirole (@ltiroles) {
3393: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
3394: }
3395: $datatable .= '</select></td>';
3396: }
3397: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 3398: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
3399: foreach my $item ('label','title','target') {
3400: $datatable .= '<label>'.
3401: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
3402: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3403: }
3404: $datatable .= '</span></fieldset>'.
1.267 raeburn 3405: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3406: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
3407: '<tr><td><span class="LC_nobreak">'.
3408: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
3409: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
3410: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
3411: '</table></fieldset></td></tr>'."\n".
3412: '</td>'."\n".
3413: '</tr>'."\n";
3414: $itemcount ++;
3415: return $datatable;
3416: }
3417:
3418: sub ltitools_names {
3419: my %lt = &Apache::lonlocal::texthash(
3420: 'title' => 'Title',
3421: 'version' => 'Version',
3422: 'msgtype' => 'Message Type',
3423: 'url' => 'URL',
3424: 'key' => 'Key',
3425: 'secret' => 'Secret',
3426: 'icon' => 'Icon',
3427: 'user' => 'Username:domain',
3428: 'fullname' => 'Full Name',
3429: 'firstname' => 'First Name',
3430: 'lastname' => 'Last Name',
3431: 'email' => 'E-mail',
3432: 'roles' => 'Role',
3433: 'window' => 'Window/Tab',
3434: 'iframe' => 'iFrame',
3435: 'height' => 'Height',
3436: 'width' => 'Width',
3437: 'passback' => 'Tool can return grades:',
3438: 'roster' => 'Tool can retrieve roster:',
1.273 raeburn 3439: 'crstarget' => 'Display target',
3440: 'crslabel' => 'Course label',
3441: 'crstitle' => 'Course title',
1.267 raeburn 3442: );
3443: return %lt;
3444: }
3445:
1.121 raeburn 3446: sub print_coursedefaults {
1.139 raeburn 3447: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 3448: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 3449: my $itemcount = 1;
1.192 raeburn 3450: my %choices = &Apache::lonlocal::texthash (
3451: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 3452: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 3453: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
3454: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 3455: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
3456: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
3457: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 3458: canclone => "People who may clone a course (besides course's owner and coordinators)",
3459: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 3460: );
1.198 raeburn 3461: my %staticdefaults = (
3462: anonsurvey_threshold => 10,
3463: uploadquota => 500,
1.257 raeburn 3464: postsubmit => 60,
1.276 raeburn 3465: mysqltables => 172800,
1.198 raeburn 3466: );
1.139 raeburn 3467: if ($position eq 'top') {
1.257 raeburn 3468: %defaultchecked = (
3469: 'canuse_pdfforms' => 'off',
3470: 'uselcmath' => 'on',
3471: 'usejsme' => 'on',
1.264 raeburn 3472: 'canclone' => 'none',
1.257 raeburn 3473: );
3474: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.139 raeburn 3475: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 3476: \%choices,$itemcount);
1.264 raeburn 3477: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3478: $datatable .=
3479: '<tr'.$css_class.'><td valign="top">'.
3480: '<span class="LC_nobreak">'.$choices{'canclone'}.
3481: '</span></td><td class="LC_left_item">';
3482: my $currcanclone = 'none';
3483: my $onclick;
3484: my @cloneoptions = ('none','domain');
3485: my %clonetitles = (
3486: none => 'No additional course requesters',
3487: domain => "Any course requester in course's domain",
3488: instcode => 'Course requests for official courses ...',
3489: );
3490: my (%codedefaults,@code_order,@posscodes);
3491: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
3492: \@code_order) eq 'ok') {
3493: if (@code_order > 0) {
3494: push(@cloneoptions,'instcode');
3495: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
3496: }
3497: }
3498: if (ref($settings) eq 'HASH') {
3499: if ($settings->{'canclone'}) {
3500: if (ref($settings->{'canclone'}) eq 'HASH') {
3501: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
3502: if (@code_order > 0) {
3503: $currcanclone = 'instcode';
3504: @posscodes = @{$settings->{'canclone'}{'instcode'}};
3505: }
3506: }
3507: } elsif ($settings->{'canclone'} eq 'domain') {
3508: $currcanclone = $settings->{'canclone'};
3509: }
3510: }
3511: }
3512: foreach my $option (@cloneoptions) {
3513: my ($checked,$additional);
3514: if ($currcanclone eq $option) {
3515: $checked = ' checked="checked"';
3516: }
3517: if ($option eq 'instcode') {
3518: if (@code_order) {
3519: my $show = 'none';
3520: if ($checked) {
3521: $show = 'block';
3522: }
3523: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
3524: &mt('Institutional codes for new and cloned course have identical:').
3525: '<br />';
3526: foreach my $item (@code_order) {
3527: my $codechk;
3528: if ($checked) {
3529: if (grep(/^\Q$item\E$/,@posscodes)) {
3530: $codechk = ' checked="checked"';
3531: }
3532: }
3533: $additional .= '<label>'.
3534: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
3535: $item.'</label>';
3536: }
3537: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
3538: }
3539: }
3540: $datatable .=
3541: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
3542: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
3543: '</label> '.$additional.'</span><br />';
3544: }
3545: $datatable .= '</td>'.
3546: '</tr>';
3547: $itemcount ++;
1.139 raeburn 3548: } else {
3549: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 3550: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 3551: my $currusecredits = 0;
1.257 raeburn 3552: my $postsubmitclient = 1;
1.271 raeburn 3553: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 3554: if (ref($settings) eq 'HASH') {
3555: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 3556: if (ref($settings->{'uploadquota'}) eq 'HASH') {
3557: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
3558: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
3559: }
3560: }
1.192 raeburn 3561: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 3562: foreach my $type (@types) {
3563: next if ($type eq 'community');
3564: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
3565: if ($defcredits{$type} ne '') {
3566: $currusecredits = 1;
3567: }
3568: }
3569: }
3570: if (ref($settings->{'postsubmit'}) eq 'HASH') {
3571: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
3572: $postsubmitclient = 0;
3573: foreach my $type (@types) {
3574: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3575: }
3576: } else {
3577: foreach my $type (@types) {
3578: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
3579: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
3580: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
3581: } else {
3582: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3583: }
3584: } else {
3585: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3586: }
3587: }
3588: }
3589: } else {
3590: foreach my $type (@types) {
3591: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 3592: }
3593: }
1.276 raeburn 3594: if (ref($settings->{'mysqltables'}) eq 'HASH') {
3595: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
3596: $currmysql{$type} = $settings->{'mysqltables'}{$type};
3597: }
3598: } else {
3599: foreach my $type (@types) {
3600: $currmysql{$type} = $staticdefaults{'mysqltables'};
3601: }
3602: }
1.258 raeburn 3603: } else {
3604: foreach my $type (@types) {
3605: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3606: }
1.139 raeburn 3607: }
3608: if (!$currdefresponder) {
1.198 raeburn 3609: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 3610: } elsif ($currdefresponder < 1) {
3611: $currdefresponder = 1;
3612: }
1.198 raeburn 3613: foreach my $type (@types) {
3614: if ($curruploadquota{$type} eq '') {
3615: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
3616: }
3617: }
1.139 raeburn 3618: $datatable .=
1.192 raeburn 3619: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3620: $choices{'anonsurvey_threshold'}.
1.139 raeburn 3621: '</span></td>'.
3622: '<td class="LC_right_item"><span class="LC_nobreak">'.
3623: '<input type="text" name="anonsurvey_threshold"'.
3624: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 3625: '</td></tr>'."\n";
3626: $itemcount ++;
3627: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3628: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3629: $choices{'uploadquota'}.
3630: '</span></td>'.
3631: '<td align="right" class="LC_right_item">'.
3632: '<table><tr>';
1.198 raeburn 3633: foreach my $type (@types) {
3634: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3635: '<input type="text" name="uploadquota_'.$type.'"'.
3636: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
3637: }
3638: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 3639: $itemcount ++;
1.236 raeburn 3640: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 3641: my $display = 'none';
1.192 raeburn 3642: if ($currusecredits) {
3643: $display = 'block';
3644: }
3645: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 3646: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
3647: foreach my $type (@types) {
3648: next if ($type eq 'community');
3649: $additional .= '<td align="center">'.&mt($type).'<br />'.
3650: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 3651: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 3652: }
3653: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 3654: %defaultchecked = ('coursecredits' => 'off');
3655: @toggles = ('coursecredits');
3656: my $current = {
3657: 'coursecredits' => $currusecredits,
3658: };
3659: (my $table,$itemcount) =
3660: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 3661: \%choices,$itemcount,$onclick,$additional,'left');
3662: $datatable .= $table;
3663: $onclick = "toggleDisplay(this.form,'studentsubmission');";
3664: my $display = 'none';
3665: if ($postsubmitclient) {
3666: $display = 'block';
3667: }
3668: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 3669: &mt('Number of seconds submit is disabled').'<br />'.
3670: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
3671: '<table><tr>';
1.257 raeburn 3672: foreach my $type (@types) {
3673: $additional .= '<td align="center">'.&mt($type).'<br />'.
3674: '<input type="text" name="'.$type.'_timeout" value="'.
3675: $deftimeout{$type}.'" size="5" /></td>';
3676: }
3677: $additional .= '</tr></table></div>'."\n";
3678: %defaultchecked = ('postsubmit' => 'on');
3679: @toggles = ('postsubmit');
3680: my $current = {
3681: 'postsubmit' => $postsubmitclient,
3682: };
3683: ($table,$itemcount) =
3684: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3685: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 3686: $datatable .= $table;
1.276 raeburn 3687: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3688: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3689: $choices{'mysqltables'}.
3690: '</span></td>'.
3691: '<td align="right" class="LC_right_item">'.
3692: '<table><tr>';
3693: foreach my $type (@types) {
3694: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3695: '<input type="text" name="mysqltables_'.$type.'"'.
3696: ' value="'.$currmysql{$type}.'" size="5" /></td>';
3697: }
3698: $datatable .= '</tr></table></td></tr>'."\n";
3699: $itemcount ++;
3700:
1.139 raeburn 3701: }
1.192 raeburn 3702: $$rowtotal += $itemcount;
1.121 raeburn 3703: return $datatable;
1.118 jms 3704: }
3705:
1.231 raeburn 3706: sub print_selfenrollment {
3707: my ($position,$dom,$settings,$rowtotal) = @_;
3708: my ($css_class,$datatable);
3709: my $itemcount = 1;
1.271 raeburn 3710: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 3711: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 3712: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3713: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 3714: my @rows;
3715: my $key;
3716: if ($position eq 'top') {
3717: $key = 'admin';
3718: if (ref($rowsref) eq 'ARRAY') {
3719: @rows = @{$rowsref};
3720: }
3721: } elsif ($position eq 'middle') {
3722: $key = 'default';
3723: @rows = ('types','registered','approval','limit');
3724: }
3725: foreach my $row (@rows) {
3726: if (defined($titlesref->{$row})) {
3727: $itemcount ++;
3728: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3729: $datatable .= '<tr'.$css_class.'>'.
3730: '<td>'.$titlesref->{$row}.'</td>'.
3731: '<td class="LC_left_item">'.
3732: '<table><tr>';
3733: my (%current,%currentcap);
3734: if (ref($settings) eq 'HASH') {
3735: if (ref($settings->{$key}) eq 'HASH') {
3736: foreach my $type (@types) {
3737: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3738: $current{$type} = $settings->{$key}->{$type}->{$row};
3739: }
3740: if (($row eq 'limit') && ($key eq 'default')) {
3741: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3742: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
3743: }
3744: }
3745: }
3746: }
3747: }
3748: my %roles = (
3749: '0' => &Apache::lonnet::plaintext('dc'),
3750: );
3751:
3752: foreach my $type (@types) {
3753: unless (($row eq 'registered') && ($key eq 'default')) {
3754: $datatable .= '<th>'.&mt($type).'</th>';
3755: }
3756: }
3757: unless (($row eq 'registered') && ($key eq 'default')) {
3758: $datatable .= '</tr><tr>';
3759: }
3760: foreach my $type (@types) {
3761: if ($type eq 'community') {
3762: $roles{'1'} = &mt('Community personnel');
3763: } else {
3764: $roles{'1'} = &mt('Course personnel');
3765: }
3766: $datatable .= '<td style="vertical-align: top">';
3767: if ($position eq 'top') {
3768: my %checked;
3769: if ($current{$type} eq '0') {
3770: $checked{'0'} = ' checked="checked"';
3771: } else {
3772: $checked{'1'} = ' checked="checked"';
3773: }
3774: foreach my $role ('1','0') {
3775: $datatable .= '<span class="LC_nobreak"><label>'.
3776: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
3777: 'value="'.$role.'"'.$checked{$role}.' />'.
3778: $roles{$role}.'</label></span> ';
3779: }
3780: } else {
3781: if ($row eq 'types') {
3782: my %checked;
3783: if ($current{$type} =~ /^(all|dom)$/) {
3784: $checked{$1} = ' checked="checked"';
3785: } else {
3786: $checked{''} = ' checked="checked"';
3787: }
3788: foreach my $val ('','dom','all') {
3789: $datatable .= '<span class="LC_nobreak"><label>'.
3790: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3791: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3792: }
3793: } elsif ($row eq 'registered') {
3794: my %checked;
3795: if ($current{$type} eq '1') {
3796: $checked{'1'} = ' checked="checked"';
3797: } else {
3798: $checked{'0'} = ' checked="checked"';
3799: }
3800: foreach my $val ('0','1') {
3801: $datatable .= '<span class="LC_nobreak"><label>'.
3802: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3803: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3804: }
3805: } elsif ($row eq 'approval') {
3806: my %checked;
3807: if ($current{$type} =~ /^([12])$/) {
3808: $checked{$1} = ' checked="checked"';
3809: } else {
3810: $checked{'0'} = ' checked="checked"';
3811: }
3812: for my $val (0..2) {
3813: $datatable .= '<span class="LC_nobreak"><label>'.
3814: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3815: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3816: }
3817: } elsif ($row eq 'limit') {
3818: my %checked;
3819: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3820: $checked{$1} = ' checked="checked"';
3821: } else {
3822: $checked{'none'} = ' checked="checked"';
3823: }
3824: my $cap;
3825: if ($currentcap{$type} =~ /^\d+$/) {
3826: $cap = $currentcap{$type};
3827: }
3828: foreach my $val ('none','allstudents','selfenrolled') {
3829: $datatable .= '<span class="LC_nobreak"><label>'.
3830: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3831: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3832: }
3833: $datatable .= '<br />'.
3834: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3835: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3836: '</span>';
3837: }
3838: }
3839: $datatable .= '</td>';
3840: }
3841: $datatable .= '</tr>';
3842: }
3843: $datatable .= '</table></td></tr>';
3844: }
3845: } elsif ($position eq 'bottom') {
1.235 raeburn 3846: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3847: }
3848: $$rowtotal += $itemcount;
3849: return $datatable;
3850: }
3851:
3852: sub print_validation_rows {
3853: my ($caller,$dom,$settings,$rowtotal) = @_;
3854: my ($itemsref,$namesref,$fieldsref);
3855: if ($caller eq 'selfenroll') {
3856: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3857: } elsif ($caller eq 'requestcourses') {
3858: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3859: }
3860: my %currvalidation;
3861: if (ref($settings) eq 'HASH') {
3862: if (ref($settings->{'validation'}) eq 'HASH') {
3863: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 3864: }
1.235 raeburn 3865: }
3866: my $datatable;
3867: my $itemcount = 0;
3868: foreach my $item (@{$itemsref}) {
3869: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3870: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3871: $namesref->{$item}.
3872: '</span></td>'.
3873: '<td class="LC_left_item">';
3874: if (($item eq 'url') || ($item eq 'button')) {
3875: $datatable .= '<span class="LC_nobreak">'.
3876: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3877: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3878: } elsif ($item eq 'fields') {
3879: my @currfields;
3880: if (ref($currvalidation{$item}) eq 'ARRAY') {
3881: @currfields = @{$currvalidation{$item}};
3882: }
3883: foreach my $field (@{$fieldsref}) {
3884: my $check = '';
3885: if (grep(/^\Q$field\E$/,@currfields)) {
3886: $check = ' checked="checked"';
3887: }
3888: $datatable .= '<span class="LC_nobreak"><label>'.
3889: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3890: ' value="'.$field.'"'.$check.' />'.$field.
3891: '</label></span> ';
3892: }
3893: } elsif ($item eq 'markup') {
3894: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3895: $currvalidation{$item}.
1.231 raeburn 3896: '</textarea>';
1.235 raeburn 3897: }
3898: $datatable .= '</td></tr>'."\n";
3899: if (ref($rowtotal)) {
1.231 raeburn 3900: $itemcount ++;
3901: }
3902: }
1.235 raeburn 3903: if ($caller eq 'requestcourses') {
3904: my %currhash;
1.248 raeburn 3905: if (ref($settings) eq 'HASH') {
3906: if (ref($settings->{'validation'}) eq 'HASH') {
3907: if ($settings->{'validation'}{'dc'} ne '') {
3908: $currhash{$settings->{'validation'}{'dc'}} = 1;
3909: }
1.235 raeburn 3910: }
3911: }
3912: my $numinrow = 2;
3913: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3914: 'validationdc',%currhash);
1.247 raeburn 3915: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3916: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235 raeburn 3917: if ($numdc > 1) {
1.247 raeburn 3918: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 3919: } else {
1.247 raeburn 3920: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 3921: }
1.247 raeburn 3922: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 3923: $itemcount ++;
3924: }
3925: if (ref($rowtotal)) {
3926: $$rowtotal += $itemcount;
3927: }
1.231 raeburn 3928: return $datatable;
3929: }
3930:
1.137 raeburn 3931: sub print_usersessions {
3932: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 ! raeburn 3933: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 3934: my (%by_ip,%by_location,@intdoms,@instdoms);
3935: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 3936:
3937: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3938: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3939: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3940: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3941: if ($position eq 'top') {
1.152 raeburn 3942: if (keys(%serverhomes) > 1) {
1.145 raeburn 3943: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 3944: my $curroffloadnow;
3945: if (ref($settings) eq 'HASH') {
3946: if (ref($settings->{'offloadnow'}) eq 'HASH') {
3947: $curroffloadnow = $settings->{'offloadnow'};
3948: }
3949: }
3950: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 3951: } else {
1.140 raeburn 3952: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 ! raeburn 3953: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
! 3954: '</td></tr>';
1.140 raeburn 3955: }
1.137 raeburn 3956: } else {
1.279 ! raeburn 3957: my %titles = &usersession_titles();
! 3958: my ($prefix,@types);
! 3959: if ($position eq 'bottom') {
! 3960: $prefix = 'remote';
! 3961: @types = ('version','excludedomain','includedomain');
1.145 raeburn 3962: } else {
1.279 ! raeburn 3963: $prefix = 'hosted';
! 3964: @types = ('excludedomain','includedomain');
! 3965: }
! 3966: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
! 3967: }
! 3968: $$rowtotal += $itemcount;
! 3969: return $datatable;
! 3970: }
! 3971:
! 3972: sub rules_by_location {
! 3973: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
! 3974: my ($datatable,$itemcount,$css_class);
! 3975: if (keys(%{$by_location}) == 0) {
! 3976: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
! 3977: $datatable = '<tr'.$css_class.'><td colspan="2">'.
! 3978: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
! 3979: '</td></tr>';
! 3980: $itemcount = 1;
! 3981: } else {
! 3982: $itemcount = 0;
! 3983: my $numinrow = 5;
! 3984: my (%current,%checkedon,%checkedoff);
! 3985: my @locations = sort(keys(%{$by_location}));
! 3986: foreach my $type (@{$types}) {
! 3987: $checkedon{$type} = '';
! 3988: $checkedoff{$type} = ' checked="checked"';
! 3989: }
! 3990: if (ref($settings) eq 'HASH') {
! 3991: if (ref($settings->{$prefix}) eq 'HASH') {
! 3992: foreach my $key (keys(%{$settings->{$prefix}})) {
! 3993: $current{$key} = $settings->{$prefix}{$key};
! 3994: if ($key eq 'version') {
! 3995: if ($current{$key} ne '') {
1.145 raeburn 3996: $checkedon{$key} = ' checked="checked"';
3997: $checkedoff{$key} = '';
3998: }
1.279 ! raeburn 3999: } elsif (ref($current{$key}) eq 'ARRAY') {
! 4000: $checkedon{$key} = ' checked="checked"';
! 4001: $checkedoff{$key} = '';
1.137 raeburn 4002: }
4003: }
4004: }
1.279 ! raeburn 4005: }
! 4006: foreach my $type (@{$types}) {
! 4007: next if ($type ne 'version' && !@locations);
! 4008: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
! 4009: $datatable .= '<tr'.$css_class.'>
! 4010: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
! 4011: <span class="LC_nobreak">
! 4012: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
! 4013: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
! 4014: if ($type eq 'version') {
! 4015: my @lcversions = &Apache::lonnet::all_loncaparevs();
! 4016: my $selector = '<select name="'.$prefix.'_version">';
! 4017: foreach my $version (@lcversions) {
! 4018: my $selected = '';
! 4019: if ($current{'version'} eq $version) {
! 4020: $selected = ' selected="selected"';
1.145 raeburn 4021: }
1.279 ! raeburn 4022: $selector .= ' <option value="'.$version.'"'.
! 4023: $selected.'>'.$version.'</option>';
! 4024: }
! 4025: $selector .= '</select> ';
! 4026: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
! 4027: } else {
! 4028: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
! 4029: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
! 4030: ' />'.(' 'x2).
! 4031: '<input type="button" value="'.&mt('uncheck all').'" '.
! 4032: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
! 4033: "\n".
! 4034: '</div><div><table>';
! 4035: my $rem;
! 4036: for (my $i=0; $i<@locations; $i++) {
! 4037: my ($showloc,$value,$checkedtype);
! 4038: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
! 4039: my $ip = $by_location->{$locations[$i]}->[0];
! 4040: if (ref($by_ip->{$ip}) eq 'ARRAY') {
! 4041: $value = join(':',@{$by_ip->{$ip}});
! 4042: $showloc = join(', ',@{$by_ip->{$ip}});
! 4043: if (ref($current{$type}) eq 'ARRAY') {
! 4044: foreach my $loc (@{$by_ip->{$ip}}) {
! 4045: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
! 4046: $checkedtype = ' checked="checked"';
! 4047: last;
1.145 raeburn 4048: }
1.138 raeburn 4049: }
4050: }
4051: }
1.137 raeburn 4052: }
1.279 ! raeburn 4053: $rem = $i%($numinrow);
! 4054: if ($rem == 0) {
! 4055: if ($i > 0) {
! 4056: $datatable .= '</tr>';
! 4057: }
! 4058: $datatable .= '<tr>';
! 4059: }
! 4060: $datatable .= '<td class="LC_left_item">'.
! 4061: '<span class="LC_nobreak"><label>'.
! 4062: '<input type="checkbox" name="'.$prefix.'_'.$type.
! 4063: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
! 4064: '</label></span></td>';
! 4065: }
! 4066: $rem = @locations%($numinrow);
! 4067: my $colsleft = $numinrow - $rem;
! 4068: if ($colsleft > 1 ) {
! 4069: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
! 4070: ' </td>';
! 4071: } elsif ($colsleft == 1) {
! 4072: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4073: }
1.279 ! raeburn 4074: $datatable .= '</tr></table>';
1.137 raeburn 4075: }
1.279 ! raeburn 4076: $datatable .= '</td></tr>';
! 4077: $itemcount ++;
1.137 raeburn 4078: }
4079: }
1.279 ! raeburn 4080: return ($datatable,$itemcount);
1.137 raeburn 4081: }
4082:
1.275 raeburn 4083: sub print_ssl {
4084: my ($position,$dom,$settings,$rowtotal) = @_;
4085: my ($css_class,$datatable);
4086: my $lonhost = '';
4087: my $itemcount = 1;
4088: if ($position eq 'top') {
4089: my %domservers = &Apache::lonnet::get_servers($dom);
4090: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.279 ! raeburn 4091: $datatable = '<tr'.$css_class.'><td colspan="2">'.
! 4092: &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs').
! 4093: '</td></tr>';
1.275 raeburn 4094: $itemcount ++;
4095: } else {
4096: my %titles = &ssl_titles();
4097: my (%by_ip,%by_location,@intdoms,@instdoms);
4098: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
4099: my @alldoms = &Apache::lonnet::all_domains();
4100: my %serverhomes = %Apache::lonnet::serverhomeIDs;
4101: my @domservers = &Apache::lonnet::get_servers($dom);
4102: my %servers = &Apache::lonnet::internet_dom_servers($dom);
4103: my %altids = &id_for_thisdom(%servers);
4104: if ($position eq 'middle') {
4105: foreach my $type ('dom','intdom','other') {
4106: my %checked;
4107: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4108: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
4109: '<td class="LC_right_item">';
4110: my $skip;
4111: if ($type eq 'dom') {
4112: unless (keys(%servers) > 1) {
4113: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
4114: $skip = 1;
4115: }
4116: }
4117: if ($type eq 'intdom') {
4118: unless (@instdoms > 1) {
4119: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
4120: $skip = 1;
4121: }
4122: } elsif ($type eq 'other') {
4123: if (keys(%by_location) == 0) {
4124: $datatable .= &mt('Nothing to set here, as there are no other institutions');
4125: $skip = 1;
4126: }
4127: }
4128: unless ($skip) {
4129: $checked{'yes'} = ' checked="checked"';
4130: if (ref($settings) eq 'HASH') {
4131: if (ref($settings->{'connect'}) eq 'HASH') {
4132: if ($settings->{'connect'}->{$type} =~ /^(no|req)$/) {
4133: $checked{$1} = $checked{'yes'};
4134: delete($checked{'yes'});
4135: }
4136: }
4137: }
4138: foreach my $option ('no','yes','req') {
4139: $datatable .= '<span class="LC_nobreak"><label>'.
4140: '<input type="radio" name="connect_'.$type.'" '.
4141: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
4142: '</label></span>'.(' 'x2);
4143: }
4144: }
4145: $datatable .= '</td></tr>';
4146: $itemcount ++;
4147: }
4148: } else {
4149: my $prefix = 'replication';
4150: my @types = ('certreq','nocertreq');
1.279 ! raeburn 4151: if (keys(%by_location) == 0) {
! 4152: $datatable .= '<tr'.$css_class.'><td>'.
! 4153: &mt('Nothing to set here, as there are no other institutions').
! 4154: '</td></tr>';
! 4155: $itemcount ++;
1.275 raeburn 4156: } else {
1.279 ! raeburn 4157: ($datatable,$itemcount) =
! 4158: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 4159: }
4160: }
4161: }
4162: $$rowtotal += $itemcount;
4163: return $datatable;
4164: }
4165:
4166: sub ssl_titles {
4167: return &Apache::lonlocal::texthash (
4168: dom => 'LON-CAPA servers/VMs from same domain',
4169: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
4170: other => 'External LON-CAPA servers/VMs',
4171: connect => 'Connections to other servers',
4172: replication => 'Replicating content to other institutions',
4173: certreq => 'Client certificate required, but specific domains exempt',
4174: nocertreq => 'No client certificate required, except for specific domains',
4175: no => 'SSL not used',
4176: yes => 'SSL Optional (used if available)',
4177: req => 'SSL Required',
4178: );
1.279 ! raeburn 4179: }
! 4180:
! 4181: sub print_trust {
! 4182: my ($prefix,$dom,$settings,$rowtotal) = @_;
! 4183: my ($css_class,$datatable,%checked,%choices);
! 4184: my (%by_ip,%by_location,@intdoms,@instdoms);
! 4185: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
! 4186: my $itemcount = 1;
! 4187: my %titles = &trust_titles();
! 4188: my @types = ('exc','inc');
! 4189: if ($prefix eq 'top') {
! 4190: $prefix = 'content';
! 4191: } elsif ($prefix eq 'bottom') {
! 4192: $prefix = 'msg';
! 4193: }
! 4194: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
! 4195: $$rowtotal += $itemcount;
! 4196: return $datatable;
! 4197: }
! 4198:
! 4199: sub trust_titles {
! 4200: return &Apache::lonlocal::texthash(
! 4201: content => "Access to this domain's content by others",
! 4202: shared => "Access to other domain's content by this domain",
! 4203: enroll => "Enrollment in this domain's courses by others",
! 4204: othcoau => "Co-author roles in this domain for others",
! 4205: coaurem => "Co-author roles for this domain's users elsewhere",
! 4206: domroles => "Domain roles in this domain assignable to others",
! 4207: catalog => "Course Catalog for this domain displayed elsewhere",
! 4208: reqcrs => "Requests for creation of courses in this domain by others",
! 4209: msg => "Users in other domains can send messages to this domain",
! 4210: exc => "Allow all, but exclude specific domains",
! 4211: inc => "Deny all, but include specific domains",
! 4212: );
1.275 raeburn 4213: }
4214:
1.138 raeburn 4215: sub build_location_hashes {
1.275 raeburn 4216: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 4217: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 4218: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 4219: my %iphost = &Apache::lonnet::get_iphost();
4220: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4221: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4222: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4223: foreach my $id (@{$iphost{$primary_ip}}) {
4224: my $intdom = &Apache::lonnet::internet_dom($id);
4225: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4226: push(@{$intdoms},$intdom);
4227: }
4228: }
4229: }
4230: foreach my $ip (keys(%iphost)) {
4231: if (ref($iphost{$ip}) eq 'ARRAY') {
4232: foreach my $id (@{$iphost{$ip}}) {
4233: my $location = &Apache::lonnet::internet_dom($id);
4234: if ($location) {
1.275 raeburn 4235: if (grep(/^\Q$location\E$/,@{$intdoms})) {
4236: my $dom = &Apache::lonnet::host_domain($id);
4237: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
4238: push(@{$instdoms},$dom);
4239: }
4240: next;
4241: }
1.138 raeburn 4242: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4243: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4244: push(@{$by_ip->{$ip}},$location);
4245: }
4246: } else {
4247: $by_ip->{$ip} = [$location];
4248: }
4249: }
4250: }
4251: }
4252: }
4253: foreach my $ip (sort(keys(%{$by_ip}))) {
4254: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4255: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4256: my $first = $by_ip->{$ip}->[0];
4257: if (ref($by_location->{$first}) eq 'ARRAY') {
4258: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4259: push(@{$by_location->{$first}},$ip);
4260: }
4261: } else {
4262: $by_location->{$first} = [$ip];
4263: }
4264: }
4265: }
4266: return;
4267: }
4268:
1.145 raeburn 4269: sub current_offloads_to {
4270: my ($dom,$settings,$servers) = @_;
4271: my (%spareid,%otherdomconfigs);
1.152 raeburn 4272: if (ref($servers) eq 'HASH') {
1.145 raeburn 4273: foreach my $lonhost (sort(keys(%{$servers}))) {
4274: my $gotspares;
1.152 raeburn 4275: if (ref($settings) eq 'HASH') {
4276: if (ref($settings->{'spares'}) eq 'HASH') {
4277: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4278: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4279: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4280: $gotspares = 1;
4281: }
1.145 raeburn 4282: }
4283: }
4284: unless ($gotspares) {
4285: my $gotspares;
4286: my $serverhomeID =
4287: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4288: my $serverhomedom =
4289: &Apache::lonnet::host_domain($serverhomeID);
4290: if ($serverhomedom ne $dom) {
4291: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4292: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4293: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4294: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4295: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4296: $gotspares = 1;
4297: }
4298: }
4299: } else {
4300: $otherdomconfigs{$serverhomedom} =
4301: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4302: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4303: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4304: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4305: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4306: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4307: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4308: $gotspares = 1;
4309: }
4310: }
4311: }
4312: }
4313: }
4314: }
4315: }
4316: unless ($gotspares) {
4317: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4318: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4319: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4320: } else {
4321: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4322: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4323: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4324: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4325: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4326: } else {
1.150 raeburn 4327: my %what = (
4328: spareid => 1,
4329: );
4330: my ($result,$returnhash) =
4331: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4332: if ($result eq 'ok') {
4333: if (ref($returnhash) eq 'HASH') {
4334: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4335: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4336: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4337: }
4338: }
1.145 raeburn 4339: }
4340: }
4341: }
4342: }
4343: }
4344: }
4345: return %spareid;
4346: }
4347:
4348: sub spares_row {
1.261 raeburn 4349: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4350: my $css_class;
4351: my $numinrow = 4;
4352: my $itemcount = 1;
4353: my $datatable;
1.152 raeburn 4354: my %typetitles = &sparestype_titles();
4355: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 4356: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 4357: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
4358: my ($othercontrol,$serverdom);
4359: if ($serverhome ne $server) {
4360: $serverdom = &Apache::lonnet::host_domain($serverhome);
4361: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4362: } else {
4363: $serverdom = &Apache::lonnet::host_domain($server);
4364: if ($serverdom ne $dom) {
4365: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4366: }
4367: }
4368: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 4369: my $checkednow;
4370: if (ref($curroffloadnow) eq 'HASH') {
4371: if ($curroffloadnow->{$server}) {
4372: $checkednow = ' checked="checked"';
4373: }
4374: }
1.145 raeburn 4375: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4376: $datatable .= '<tr'.$css_class.'>
4377: <td rowspan="2">
1.183 bisitz 4378: <span class="LC_nobreak">'.
4379: &mt('[_1] when busy, offloads to:'
1.261 raeburn 4380: ,'<b>'.$server.'</b>').'</span><br />'.
4381: '<span class="LC_nobreak">'."\n".
4382: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
4383: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 4384: "\n";
1.145 raeburn 4385: my (%current,%canselect);
1.152 raeburn 4386: my @choices =
4387: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
4388: foreach my $type ('primary','default') {
4389: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 4390: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
4391: my @spares = @{$spareid->{$server}{$type}};
4392: if (@spares > 0) {
1.152 raeburn 4393: if ($othercontrol) {
4394: $current{$type} = join(', ',@spares);
4395: } else {
4396: $current{$type} .= '<table>';
4397: my $numspares = scalar(@spares);
4398: for (my $i=0; $i<@spares; $i++) {
4399: my $rem = $i%($numinrow);
4400: if ($rem == 0) {
4401: if ($i > 0) {
4402: $current{$type} .= '</tr>';
4403: }
4404: $current{$type} .= '<tr>';
1.145 raeburn 4405: }
1.152 raeburn 4406: $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'".');" /> '.
4407: $spareid->{$server}{$type}[$i].
4408: '</label></td>'."\n";
4409: }
4410: my $rem = @spares%($numinrow);
4411: my $colsleft = $numinrow - $rem;
4412: if ($colsleft > 1 ) {
4413: $current{$type} .= '<td colspan="'.$colsleft.
4414: '" class="LC_left_item">'.
4415: ' </td>';
4416: } elsif ($colsleft == 1) {
4417: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 4418: }
1.152 raeburn 4419: $current{$type} .= '</tr></table>';
1.150 raeburn 4420: }
1.145 raeburn 4421: }
4422: }
4423: if ($current{$type} eq '') {
4424: $current{$type} = &mt('None specified');
4425: }
1.152 raeburn 4426: if ($othercontrol) {
4427: if ($type eq 'primary') {
4428: $canselect{$type} = $othercontrol;
4429: }
4430: } else {
4431: $canselect{$type} =
4432: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
4433: '<select name="newspare_'.$type.'_'.$server.'" '.
4434: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
4435: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
4436: if (@choices > 0) {
4437: foreach my $lonhost (@choices) {
4438: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
4439: }
4440: }
4441: $canselect{$type} .= '</select>'."\n";
4442: }
4443: } else {
4444: $current{$type} = &mt('Could not be determined');
4445: if ($type eq 'primary') {
4446: $canselect{$type} = $othercontrol;
4447: }
1.145 raeburn 4448: }
1.152 raeburn 4449: if ($type eq 'default') {
4450: $datatable .= '<tr'.$css_class.'>';
4451: }
4452: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
4453: '<td>'.$current{$type}.'</td>'."\n".
4454: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 4455: }
4456: $itemcount ++;
4457: }
4458: }
4459: $$rowtotal += $itemcount;
4460: return $datatable;
4461: }
4462:
1.152 raeburn 4463: sub possible_newspares {
4464: my ($server,$currspares,$serverhomes,$altids) = @_;
4465: my $serverhostname = &Apache::lonnet::hostname($server);
4466: my %excluded;
4467: if ($serverhostname ne '') {
4468: %excluded = (
4469: $serverhostname => 1,
4470: );
4471: }
4472: if (ref($currspares) eq 'HASH') {
4473: foreach my $type (keys(%{$currspares})) {
4474: if (ref($currspares->{$type}) eq 'ARRAY') {
4475: if (@{$currspares->{$type}} > 0) {
4476: foreach my $curr (@{$currspares->{$type}}) {
4477: my $hostname = &Apache::lonnet::hostname($curr);
4478: $excluded{$hostname} = 1;
4479: }
4480: }
4481: }
4482: }
4483: }
4484: my @choices;
4485: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
4486: if (keys(%{$serverhomes}) > 1) {
4487: foreach my $name (sort(keys(%{$serverhomes}))) {
4488: unless ($excluded{$name}) {
4489: if (exists($altids->{$serverhomes->{$name}})) {
4490: push(@choices,$altids->{$serverhomes->{$name}});
4491: } else {
4492: push(@choices,$serverhomes->{$name});
1.145 raeburn 4493: }
4494: }
4495: }
4496: }
4497: }
1.152 raeburn 4498: return sort(@choices);
1.145 raeburn 4499: }
4500:
1.150 raeburn 4501: sub print_loadbalancing {
4502: my ($dom,$settings,$rowtotal) = @_;
4503: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4504: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4505: my $numinrow = 1;
4506: my $datatable;
4507: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 4508: my (%currbalancer,%currtargets,%currrules,%existing);
4509: if (ref($settings) eq 'HASH') {
4510: %existing = %{$settings};
4511: }
4512: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
4513: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
4514: \%currtargets,\%currrules);
1.150 raeburn 4515: } else {
4516: return;
4517: }
4518: my ($othertitle,$usertypes,$types) =
4519: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 4520: my $rownum = 8;
1.150 raeburn 4521: if (ref($types) eq 'ARRAY') {
4522: $rownum += scalar(@{$types});
4523: }
1.171 raeburn 4524: my @css_class = ('LC_odd_row','LC_even_row');
4525: my $balnum = 0;
4526: my $islast;
4527: my (@toshow,$disabledtext);
4528: if (keys(%currbalancer) > 0) {
4529: @toshow = sort(keys(%currbalancer));
4530: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
4531: push(@toshow,'');
4532: }
4533: } else {
4534: @toshow = ('');
4535: $disabledtext = &mt('No existing load balancer');
4536: }
4537: foreach my $lonhost (@toshow) {
4538: if ($balnum == scalar(@toshow)-1) {
4539: $islast = 1;
4540: } else {
4541: $islast = 0;
4542: }
4543: my $cssidx = $balnum%2;
4544: my $targets_div_style = 'display: none';
4545: my $disabled_div_style = 'display: block';
4546: my $homedom_div_style = 'display: none';
4547: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
4548: '<td rowspan="'.$rownum.'" valign="top">'.
4549: '<p>';
4550: if ($lonhost eq '') {
1.210 raeburn 4551: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 4552: if (keys(%currbalancer) > 0) {
4553: $datatable .= &mt('Add balancer:');
4554: } else {
4555: $datatable .= &mt('Enable balancer:');
4556: }
4557: $datatable .= ' '.
4558: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
4559: ' id="loadbalancing_lonhost_'.$balnum.'"'.
4560: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
4561: '<option value="" selected="selected">'.&mt('None').
4562: '</option>'."\n";
4563: foreach my $server (sort(keys(%servers))) {
4564: next if ($currbalancer{$server});
4565: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
4566: }
1.210 raeburn 4567: $datatable .=
1.171 raeburn 4568: '</select>'."\n".
4569: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
4570: } else {
4571: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
4572: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
4573: &mt('Stop balancing').'</label>'.
4574: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
4575: $targets_div_style = 'display: block';
4576: $disabled_div_style = 'display: none';
4577: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
4578: $homedom_div_style = 'display: block';
4579: }
4580: }
4581: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
4582: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
4583: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
4584: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
4585: my ($numspares,@spares) = &count_servers($lonhost,%servers);
4586: my @sparestypes = ('primary','default');
4587: my %typetitles = &sparestype_titles();
4588: foreach my $sparetype (@sparestypes) {
4589: my $targettable;
4590: for (my $i=0; $i<$numspares; $i++) {
4591: my $checked;
4592: if (ref($currtargets{$lonhost}) eq 'HASH') {
4593: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4594: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
4595: $checked = ' checked="checked"';
4596: }
4597: }
4598: }
4599: my ($chkboxval,$disabled);
4600: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
4601: $chkboxval = $spares[$i];
4602: }
4603: if (exists($currbalancer{$spares[$i]})) {
4604: $disabled = ' disabled="disabled"';
4605: }
1.210 raeburn 4606: $targettable .=
1.253 raeburn 4607: '<td><span class="LC_nobreak"><label>'.
4608: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 4609: $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 4610: '</span></label></span></td>';
1.171 raeburn 4611: my $rem = $i%($numinrow);
4612: if ($rem == 0) {
4613: if (($i > 0) && ($i < $numspares-1)) {
4614: $targettable .= '</tr>';
4615: }
4616: if ($i < $numspares-1) {
4617: $targettable .= '<tr>';
1.150 raeburn 4618: }
4619: }
4620: }
1.171 raeburn 4621: if ($targettable ne '') {
4622: my $rem = $numspares%($numinrow);
4623: my $colsleft = $numinrow - $rem;
4624: if ($colsleft > 1 ) {
4625: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4626: ' </td>';
4627: } elsif ($colsleft == 1) {
4628: $targettable .= '<td class="LC_left_item"> </td>';
4629: }
4630: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
4631: '<table><tr>'.$targettable.'</tr></table><br />';
4632: }
4633: }
4634: $datatable .= '</div></td></tr>'.
4635: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
4636: $othertitle,$usertypes,$types,\%servers,
4637: \%currbalancer,$lonhost,
4638: $targets_div_style,$homedom_div_style,
4639: $css_class[$cssidx],$balnum,$islast);
4640: $$rowtotal += $rownum;
4641: $balnum ++;
4642: }
4643: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
4644: return $datatable;
4645: }
4646:
4647: sub get_loadbalancers_config {
4648: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
4649: return unless ((ref($servers) eq 'HASH') &&
4650: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
4651: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
4652: if (keys(%{$existing}) > 0) {
4653: my $oldlonhost;
4654: foreach my $key (sort(keys(%{$existing}))) {
4655: if ($key eq 'lonhost') {
4656: $oldlonhost = $existing->{'lonhost'};
4657: $currbalancer->{$oldlonhost} = 1;
4658: } elsif ($key eq 'targets') {
4659: if ($oldlonhost) {
4660: $currtargets->{$oldlonhost} = $existing->{'targets'};
4661: }
4662: } elsif ($key eq 'rules') {
4663: if ($oldlonhost) {
4664: $currrules->{$oldlonhost} = $existing->{'rules'};
4665: }
4666: } elsif (ref($existing->{$key}) eq 'HASH') {
4667: $currbalancer->{$key} = 1;
4668: $currtargets->{$key} = $existing->{$key}{'targets'};
4669: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 4670: }
4671: }
1.171 raeburn 4672: } else {
4673: my ($balancerref,$targetsref) =
4674: &Apache::lonnet::get_lonbalancer_config($servers);
4675: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
4676: foreach my $server (sort(keys(%{$balancerref}))) {
4677: $currbalancer->{$server} = 1;
4678: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 4679: }
4680: }
4681: }
1.171 raeburn 4682: return;
1.150 raeburn 4683: }
4684:
4685: sub loadbalancing_rules {
4686: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 4687: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
4688: $css_class,$balnum,$islast) = @_;
1.150 raeburn 4689: my $output;
1.171 raeburn 4690: my $num = 0;
1.210 raeburn 4691: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 4692: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
4693: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
4694: foreach my $type (@{$alltypes}) {
1.171 raeburn 4695: $num ++;
1.150 raeburn 4696: my $current;
4697: if (ref($currrules) eq 'HASH') {
4698: $current = $currrules->{$type};
4699: }
1.253 raeburn 4700: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 4701: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 4702: $current = '';
4703: }
4704: }
4705: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 4706: $servers,$currbalancer,$lonhost,$dom,
4707: $targets_div_style,$homedom_div_style,
4708: $css_class,$balnum,$num,$islast);
1.150 raeburn 4709: }
4710: }
4711: return $output;
4712: }
4713:
4714: sub loadbalancing_titles {
4715: my ($dom,$intdom,$usertypes,$types) = @_;
4716: my %othertypes = (
4717: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
4718: '_LC_author' => &mt('Users from [_1] with author role',$dom),
4719: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
4720: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 4721: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
4722: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 4723: );
1.209 raeburn 4724: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 4725: if (ref($types) eq 'ARRAY') {
4726: unshift(@alltypes,@{$types},'default');
4727: }
4728: my %titles;
4729: foreach my $type (@alltypes) {
4730: if ($type =~ /^_LC_/) {
4731: $titles{$type} = $othertypes{$type};
4732: } elsif ($type eq 'default') {
4733: $titles{$type} = &mt('All users from [_1]',$dom);
4734: if (ref($types) eq 'ARRAY') {
4735: if (@{$types} > 0) {
4736: $titles{$type} = &mt('Other users from [_1]',$dom);
4737: }
4738: }
4739: } elsif (ref($usertypes) eq 'HASH') {
4740: $titles{$type} = $usertypes->{$type};
4741: }
4742: }
4743: return (\@alltypes,\%othertypes,\%titles);
4744: }
4745:
4746: sub loadbalance_rule_row {
1.171 raeburn 4747: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
4748: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 4749: my @rulenames;
1.150 raeburn 4750: my %ruletitles = &offloadtype_text();
1.209 raeburn 4751: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 4752: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 4753: } else {
1.209 raeburn 4754: @rulenames = ('default','homeserver');
4755: if ($type eq '_LC_external') {
4756: push(@rulenames,'externalbalancer');
4757: } else {
4758: push(@rulenames,'specific');
4759: }
4760: push(@rulenames,'none');
1.150 raeburn 4761: }
4762: my $style = $targets_div_style;
1.253 raeburn 4763: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 4764: $style = $homedom_div_style;
4765: }
1.171 raeburn 4766: my $space;
4767: if ($islast && $num == 1) {
4768: $space = '<div display="inline-block"> </div>';
4769: }
1.210 raeburn 4770: my $output =
1.171 raeburn 4771: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
4772: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
4773: '<td valaign="top">'.$space.
4774: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 4775: for (my $i=0; $i<@rulenames; $i++) {
4776: my $rule = $rulenames[$i];
4777: my ($checked,$extra);
4778: if ($rulenames[$i] eq 'default') {
4779: $rule = '';
4780: }
4781: if ($rulenames[$i] eq 'specific') {
4782: if (ref($servers) eq 'HASH') {
4783: my $default;
4784: if (($current ne '') && (exists($servers->{$current}))) {
4785: $checked = ' checked="checked"';
4786: }
4787: unless ($checked) {
4788: $default = ' selected="selected"';
4789: }
1.210 raeburn 4790: $extra =
1.171 raeburn 4791: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
4792: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
4793: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
4794: '<option value=""'.$default.'></option>'."\n";
4795: foreach my $server (sort(keys(%{$servers}))) {
4796: if (ref($currbalancer) eq 'HASH') {
4797: next if (exists($currbalancer->{$server}));
4798: }
1.150 raeburn 4799: my $selected;
1.171 raeburn 4800: if ($server eq $current) {
1.150 raeburn 4801: $selected = ' selected="selected"';
4802: }
1.171 raeburn 4803: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 4804: }
4805: $extra .= '</select>';
4806: }
4807: } elsif ($rule eq $current) {
4808: $checked = ' checked="checked"';
4809: }
4810: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 4811: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
4812: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
4813: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 4814: ')"'.$checked.' /> ';
4815: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
4816: $output .= $ruletitles{'particular'};
4817: } else {
4818: $output .= $ruletitles{$rulenames[$i]};
4819: }
4820: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 4821: }
4822: $output .= '</div></td></tr>'."\n";
4823: return $output;
4824: }
4825:
4826: sub offloadtype_text {
4827: my %ruletitles = &Apache::lonlocal::texthash (
4828: 'default' => 'Offloads to default destinations',
4829: 'homeserver' => "Offloads to user's home server",
4830: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
4831: 'specific' => 'Offloads to specific server',
1.161 raeburn 4832: 'none' => 'No offload',
1.209 raeburn 4833: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
4834: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 4835: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 4836: );
4837: return %ruletitles;
4838: }
4839:
4840: sub sparestype_titles {
4841: my %typestitles = &Apache::lonlocal::texthash (
4842: 'primary' => 'primary',
4843: 'default' => 'default',
4844: );
4845: return %typestitles;
4846: }
4847:
1.28 raeburn 4848: sub contact_titles {
4849: my %titles = &Apache::lonlocal::texthash (
4850: 'supportemail' => 'Support E-mail address',
1.69 raeburn 4851: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 4852: 'errormail' => 'Error reports to be e-mailed to',
4853: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 4854: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
4855: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 4856: 'requestsmail' => 'E-mail from course requests requiring approval',
1.190 raeburn 4857: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 4858: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 4859: );
4860: my %short_titles = &Apache::lonlocal::texthash (
4861: adminemail => 'Admin E-mail address',
4862: supportemail => 'Support E-mail',
4863: );
4864: return (\%titles,\%short_titles);
4865: }
4866:
1.72 raeburn 4867: sub tool_titles {
4868: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 4869: aboutme => 'Personal web page',
1.86 raeburn 4870: blog => 'Blog',
1.162 raeburn 4871: webdav => 'WebDAV',
1.86 raeburn 4872: portfolio => 'Portfolio',
1.88 bisitz 4873: official => 'Official courses (with institutional codes)',
4874: unofficial => 'Unofficial courses',
1.98 raeburn 4875: community => 'Communities',
1.216 raeburn 4876: textbook => 'Textbook courses',
1.271 raeburn 4877: placement => 'Placement tests',
1.86 raeburn 4878: );
1.72 raeburn 4879: return %titles;
4880: }
4881:
1.101 raeburn 4882: sub courserequest_titles {
4883: my %titles = &Apache::lonlocal::texthash (
4884: official => 'Official',
4885: unofficial => 'Unofficial',
4886: community => 'Communities',
1.216 raeburn 4887: textbook => 'Textbook',
1.271 raeburn 4888: placement => 'Placement tests',
1.101 raeburn 4889: norequest => 'Not allowed',
1.104 raeburn 4890: approval => 'Approval by Dom. Coord.',
1.101 raeburn 4891: validate => 'With validation',
4892: autolimit => 'Numerical limit',
1.103 raeburn 4893: unlimited => '(blank for unlimited)',
1.101 raeburn 4894: );
4895: return %titles;
4896: }
4897:
1.163 raeburn 4898: sub authorrequest_titles {
4899: my %titles = &Apache::lonlocal::texthash (
4900: norequest => 'Not allowed',
4901: approval => 'Approval by Dom. Coord.',
4902: automatic => 'Automatic approval',
4903: );
4904: return %titles;
1.210 raeburn 4905: }
1.163 raeburn 4906:
1.101 raeburn 4907: sub courserequest_conditions {
4908: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 4909: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 4910: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 4911: );
4912: return %conditions;
4913: }
4914:
4915:
1.27 raeburn 4916: sub print_usercreation {
1.30 raeburn 4917: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 4918: my $numinrow = 4;
1.28 raeburn 4919: my $datatable;
4920: if ($position eq 'top') {
1.30 raeburn 4921: $$rowtotal ++;
1.34 raeburn 4922: my $rowcount = 0;
1.32 raeburn 4923: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 4924: if (ref($rules) eq 'HASH') {
4925: if (keys(%{$rules}) > 0) {
1.32 raeburn 4926: $datatable .= &user_formats_row('username',$settings,$rules,
4927: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 4928: $$rowtotal ++;
1.32 raeburn 4929: $rowcount ++;
4930: }
4931: }
4932: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
4933: if (ref($idrules) eq 'HASH') {
4934: if (keys(%{$idrules}) > 0) {
4935: $datatable .= &user_formats_row('id',$settings,$idrules,
4936: $idruleorder,$numinrow,$rowcount);
4937: $$rowtotal ++;
4938: $rowcount ++;
1.28 raeburn 4939: }
4940: }
1.39 raeburn 4941: if ($rowcount == 0) {
4942: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
4943: $$rowtotal ++;
4944: $rowcount ++;
4945: }
1.34 raeburn 4946: } elsif ($position eq 'middle') {
1.224 raeburn 4947: my @creators = ('author','course','requestcrs');
1.37 raeburn 4948: my ($rules,$ruleorder) =
4949: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 4950: my %lt = &usercreation_types();
4951: my %checked;
4952: if (ref($settings) eq 'HASH') {
4953: if (ref($settings->{'cancreate'}) eq 'HASH') {
4954: foreach my $item (@creators) {
4955: $checked{$item} = $settings->{'cancreate'}{$item};
4956: }
4957: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4958: foreach my $item (@creators) {
4959: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4960: $checked{$item} = 'none';
4961: }
4962: }
4963: }
4964: }
4965: my $rownum = 0;
4966: foreach my $item (@creators) {
4967: $rownum ++;
1.224 raeburn 4968: if ($checked{$item} eq '') {
4969: $checked{$item} = 'any';
1.34 raeburn 4970: }
4971: my $css_class;
4972: if ($rownum%2) {
4973: $css_class = '';
4974: } else {
4975: $css_class = ' class="LC_odd_row" ';
4976: }
4977: $datatable .= '<tr'.$css_class.'>'.
4978: '<td><span class="LC_nobreak">'.$lt{$item}.
4979: '</span></td><td align="right">';
1.224 raeburn 4980: my @options = ('any');
4981: if (ref($rules) eq 'HASH') {
4982: if (keys(%{$rules}) > 0) {
4983: push(@options,('official','unofficial'));
1.37 raeburn 4984: }
4985: }
1.224 raeburn 4986: push(@options,'none');
1.37 raeburn 4987: foreach my $option (@options) {
1.50 raeburn 4988: my $type = 'radio';
1.34 raeburn 4989: my $check = ' ';
1.224 raeburn 4990: if ($checked{$item} eq $option) {
4991: $check = ' checked="checked" ';
1.34 raeburn 4992: }
4993: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4994: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4995: $item.'" value="'.$option.'"'.$check.'/> '.
4996: $lt{$option}.'</label> </span>';
4997: }
4998: $datatable .= '</td></tr>';
4999: }
1.28 raeburn 5000: } else {
5001: my @contexts = ('author','course','domain');
5002: my @authtypes = ('int','krb4','krb5','loc');
5003: my %checked;
5004: if (ref($settings) eq 'HASH') {
5005: if (ref($settings->{'authtypes'}) eq 'HASH') {
5006: foreach my $item (@contexts) {
5007: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
5008: foreach my $auth (@authtypes) {
5009: if ($settings->{'authtypes'}{$item}{$auth}) {
5010: $checked{$item}{$auth} = ' checked="checked" ';
5011: }
5012: }
5013: }
5014: }
1.27 raeburn 5015: }
1.35 raeburn 5016: } else {
5017: foreach my $item (@contexts) {
1.36 raeburn 5018: foreach my $auth (@authtypes) {
1.35 raeburn 5019: $checked{$item}{$auth} = ' checked="checked" ';
5020: }
5021: }
1.27 raeburn 5022: }
1.28 raeburn 5023: my %title = &context_names();
5024: my %authname = &authtype_names();
5025: my $rownum = 0;
5026: my $css_class;
5027: foreach my $item (@contexts) {
5028: if ($rownum%2) {
5029: $css_class = '';
5030: } else {
5031: $css_class = ' class="LC_odd_row" ';
5032: }
1.30 raeburn 5033: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 5034: '<td>'.$title{$item}.
5035: '</td><td class="LC_left_item">'.
5036: '<span class="LC_nobreak">';
5037: foreach my $auth (@authtypes) {
5038: $datatable .= '<label>'.
5039: '<input type="checkbox" name="'.$item.'_auth" '.
5040: $checked{$item}{$auth}.' value="'.$auth.'" />'.
5041: $authname{$auth}.'</label> ';
5042: }
5043: $datatable .= '</span></td></tr>';
5044: $rownum ++;
1.27 raeburn 5045: }
1.30 raeburn 5046: $$rowtotal += $rownum;
1.27 raeburn 5047: }
5048: return $datatable;
5049: }
5050:
1.224 raeburn 5051: sub print_selfcreation {
5052: my ($position,$dom,$settings,$rowtotal) = @_;
1.236 raeburn 5053: my (@selfcreate,$createsettings,$processing,$datatable);
1.224 raeburn 5054: if (ref($settings) eq 'HASH') {
5055: if (ref($settings->{'cancreate'}) eq 'HASH') {
5056: $createsettings = $settings->{'cancreate'};
1.236 raeburn 5057: if (ref($createsettings) eq 'HASH') {
5058: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
5059: @selfcreate = @{$createsettings->{'selfcreate'}};
5060: } elsif ($createsettings->{'selfcreate'} ne '') {
5061: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
5062: @selfcreate = ('email','login','sso');
5063: } elsif ($createsettings->{'selfcreate'} ne 'none') {
5064: @selfcreate = ($createsettings->{'selfcreate'});
5065: }
5066: }
5067: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5068: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 5069: }
5070: }
5071: }
5072: }
5073: my %radiohash;
5074: my $numinrow = 4;
5075: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
5076: if ($position eq 'top') {
5077: my %choices = &Apache::lonlocal::texthash (
5078: cancreate_login => 'Institutional Login',
5079: cancreate_sso => 'Institutional Single Sign On',
5080: );
5081: my @toggles = sort(keys(%choices));
5082: my %defaultchecked = (
5083: 'cancreate_login' => 'off',
5084: 'cancreate_sso' => 'off',
5085: );
1.228 raeburn 5086: my ($onclick,$itemcount);
1.224 raeburn 5087: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5088: \%choices,$itemcount,$onclick);
1.228 raeburn 5089: $$rowtotal += $itemcount;
5090:
1.224 raeburn 5091: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5092:
5093: if (ref($usertypes) eq 'HASH') {
5094: if (keys(%{$usertypes}) > 0) {
5095: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5096: $dom,$numinrow,$othertitle,
1.228 raeburn 5097: 'statustocreate',$$rowtotal);
1.224 raeburn 5098: $$rowtotal ++;
5099: }
5100: }
1.240 raeburn 5101: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5102: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5103: $fieldtitles{'inststatus'} = &mt('Institutional status');
5104: my $rem;
5105: my $numperrow = 2;
5106: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5107: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 5108: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 5109: '<td class="LC_left_item">'."\n".
5110: '<table><tr><td>'."\n";
5111: for (my $i=0; $i<@fields; $i++) {
5112: $rem = $i%($numperrow);
5113: if ($rem == 0) {
5114: if ($i > 0) {
5115: $datatable .= '</tr>';
5116: }
5117: $datatable .= '<tr>';
5118: }
5119: my $currval;
1.248 raeburn 5120: if (ref($createsettings) eq 'HASH') {
5121: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5122: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5123: }
1.240 raeburn 5124: }
5125: $datatable .= '<td class="LC_left_item">'.
5126: '<span class="LC_nobreak">'.
5127: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5128: 'value="'.$currval.'" size="10" /> '.
5129: $fieldtitles{$fields[$i]}.'</span></td>';
5130: }
5131: my $colsleft = $numperrow - $rem;
5132: if ($colsleft > 1 ) {
5133: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5134: ' </td>';
5135: } elsif ($colsleft == 1) {
5136: $datatable .= '<td class="LC_left_item"> </td>';
5137: }
5138: $datatable .= '</tr></table></td></tr>';
5139: $$rowtotal ++;
1.224 raeburn 5140: } elsif ($position eq 'middle') {
5141: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
5142: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5143: $usertypes->{'default'} = $othertitle;
5144: if (ref($types) eq 'ARRAY') {
5145: push(@{$types},'default');
5146: $usertypes->{'default'} = $othertitle;
5147: foreach my $status (@{$types}) {
5148: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.228 raeburn 5149: $numinrow,$$rowtotal,$usertypes);
1.240 raeburn 5150: $$rowtotal ++;
1.224 raeburn 5151: }
5152: }
5153: } else {
1.236 raeburn 5154: my %choices = &Apache::lonlocal::texthash (
5155: cancreate_email => 'E-mail address as username',
5156: );
5157: my @toggles = sort(keys(%choices));
5158: my %defaultchecked = (
5159: 'cancreate_email' => 'off',
5160: );
5161: my $itemcount = 0;
5162: my $display = 'none';
5163: if (grep(/^\Qemail\E$/,@selfcreate)) {
5164: $display = 'block';
5165: }
5166: my $onclick = "toggleDisplay(this.form,'emailoptions');";
5167: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
5168: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
5169: my $usertypes = {};
5170: my $order = [];
5171: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
5172: $usertypes = $domdefaults{'inststatustypes'};
5173: $order = $domdefaults{'inststatusguest'};
5174: }
5175: if (ref($order) eq 'ARRAY') {
5176: push(@{$order},'default');
5177: if (@{$order} > 1) {
5178: $usertypes->{'default'} = &mt('Other users');
5179: $additional .= '<table><tr>';
5180: foreach my $status (@{$order}) {
5181: $additional .= '<th>'.$usertypes->{$status}.'</th>';
5182: }
5183: $additional .= '</tr><tr>';
5184: foreach my $status (@{$order}) {
5185: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.224 raeburn 5186: }
1.236 raeburn 5187: $additional .= '</tr></table>';
1.224 raeburn 5188: } else {
1.236 raeburn 5189: $usertypes->{'default'} = &mt('All users');
5190: $additional .= &email_as_username($rowtotal,$processing);
1.224 raeburn 5191: }
5192: }
1.236 raeburn 5193: $additional .= '</div>'."\n";
5194:
5195: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.240 raeburn 5196: \%choices,$$rowtotal,$onclick,$additional);
5197: $$rowtotal ++;
1.236 raeburn 5198: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228 raeburn 5199: $$rowtotal ++;
1.224 raeburn 5200: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 5201: $numinrow = 1;
1.236 raeburn 5202: if (ref($order) eq 'ARRAY') {
5203: foreach my $status (@{$order}) {
1.228 raeburn 5204: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5205: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
5206: $$rowtotal ++;
5207: }
5208: }
1.224 raeburn 5209: my ($emailrules,$emailruleorder) =
5210: &Apache::lonnet::inst_userrules($dom,'email');
5211: if (ref($emailrules) eq 'HASH') {
5212: if (keys(%{$emailrules}) > 0) {
5213: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228 raeburn 5214: $emailruleorder,$numinrow,$$rowtotal);
1.224 raeburn 5215: $$rowtotal ++;
5216: }
5217: }
1.228 raeburn 5218: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224 raeburn 5219: }
5220: return $datatable;
5221: }
5222:
1.236 raeburn 5223: sub email_as_username {
5224: my ($rowtotal,$processing,$type) = @_;
5225: my %choices =
5226: &Apache::lonlocal::texthash (
5227: automatic => 'Automatic approval',
5228: approval => 'Queued for approval',
5229: );
5230: my $output;
5231: foreach my $option ('automatic','approval') {
5232: my $checked;
5233: if (ref($processing) eq 'HASH') {
5234: if ($type eq '') {
5235: if (!exists($processing->{'default'})) {
5236: if ($option eq 'automatic') {
5237: $checked = ' checked="checked"';
5238: }
5239: } else {
5240: if ($processing->{'default'} eq $option) {
5241: $checked = ' checked="checked"';
5242: }
5243: }
5244: } else {
5245: if (!exists($processing->{$type})) {
5246: if ($option eq 'automatic') {
5247: $checked = ' checked="checked"';
5248: }
5249: } else {
5250: if ($processing->{$type} eq $option) {
5251: $checked = ' checked="checked"';
5252: }
5253: }
5254: }
5255: } elsif ($option eq 'automatic') {
5256: $checked = ' checked="checked"';
5257: }
5258: my $name = 'cancreate_emailprocess';
5259: if (($type ne '') && ($type ne 'default')) {
5260: $name .= '_'.$type;
5261: }
5262: $output .= '<span class="LC_nobreak"><label>'.
5263: '<input type="radio" name="'.$name.'"'.
5264: $checked.' value="'.$option.'" />'.
5265: $choices{$option}.'</label></span>';
5266: if ($type eq '') {
5267: $output .= ' ';
5268: } else {
5269: $output .= '<br />';
5270: }
5271: }
5272: $$rowtotal ++;
5273: return $output;
5274: }
5275:
1.165 raeburn 5276: sub captcha_choice {
1.169 raeburn 5277: my ($context,$settings,$itemcount) = @_;
1.269 raeburn 5278: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
5279: $vertext,$currver);
1.165 raeburn 5280: my %lt = &captcha_phrases();
5281: $keyentry = 'hidden';
5282: if ($context eq 'cancreate') {
1.224 raeburn 5283: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 5284: } elsif ($context eq 'login') {
5285: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 5286: }
5287: if (ref($settings) eq 'HASH') {
5288: if ($settings->{'captcha'}) {
5289: $checked{$settings->{'captcha'}} = ' checked="checked"';
5290: } else {
5291: $checked{'original'} = ' checked="checked"';
5292: }
5293: if ($settings->{'captcha'} eq 'recaptcha') {
5294: $pubtext = $lt{'pub'};
5295: $privtext = $lt{'priv'};
5296: $keyentry = 'text';
1.269 raeburn 5297: $vertext = $lt{'ver'};
5298: $currver = $settings->{'recaptchaversion'};
5299: if ($currver ne '2') {
5300: $currver = 1;
5301: }
1.165 raeburn 5302: }
5303: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
5304: $currpub = $settings->{'recaptchakeys'}{'public'};
5305: $currpriv = $settings->{'recaptchakeys'}{'private'};
5306: }
5307: } else {
5308: $checked{'original'} = ' checked="checked"';
5309: }
1.169 raeburn 5310: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
5311: my $output = '<tr'.$css_class.'>'.
5312: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 5313: '<table><tr><td>'."\n";
5314: foreach my $option ('original','recaptcha','notused') {
5315: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
5316: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
5317: $lt{$option}.'</label></span>';
5318: unless ($option eq 'notused') {
5319: $output .= (' 'x2)."\n";
5320: }
5321: }
5322: #
5323: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
5324: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 5325: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 5326: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 5327: #
1.165 raeburn 5328: $output .= '</td></tr>'."\n".
5329: '<tr><td>'."\n".
5330: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
5331: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
5332: $currpub.'" size="40" /></span><br />'."\n".
5333: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
5334: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 5335: $currpriv.'" size="40" /></span><br />'.
5336: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
5337: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
5338: $currver.'" size="3" /></span><br />'.
5339: '</td></tr></table>'."\n".
1.165 raeburn 5340: '</td></tr>';
5341: return $output;
5342: }
5343:
1.32 raeburn 5344: sub user_formats_row {
5345: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
5346: my $output;
5347: my %text = (
5348: 'username' => 'new usernames',
5349: 'id' => 'IDs',
1.45 raeburn 5350: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 5351: );
5352: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5353: $output = '<tr '.$css_class.'>'.
1.63 raeburn 5354: '<td><span class="LC_nobreak">';
5355: if ($type eq 'email') {
5356: $output .= &mt("Formats disallowed for $text{$type}: ");
5357: } else {
5358: $output .= &mt("Format rules to check for $text{$type}: ");
5359: }
5360: $output .= '</span></td>'.
5361: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 5362: my $rem;
5363: if (ref($ruleorder) eq 'ARRAY') {
5364: for (my $i=0; $i<@{$ruleorder}; $i++) {
5365: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
5366: my $rem = $i%($numinrow);
5367: if ($rem == 0) {
5368: if ($i > 0) {
5369: $output .= '</tr>';
5370: }
5371: $output .= '<tr>';
5372: }
5373: my $check = ' ';
1.39 raeburn 5374: if (ref($settings) eq 'HASH') {
5375: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
5376: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
5377: $check = ' checked="checked" ';
5378: }
1.27 raeburn 5379: }
5380: }
5381: $output .= '<td class="LC_left_item">'.
5382: '<span class="LC_nobreak"><label>'.
1.32 raeburn 5383: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 5384: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
5385: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
5386: }
5387: }
5388: $rem = @{$ruleorder}%($numinrow);
5389: }
5390: my $colsleft = $numinrow - $rem;
5391: if ($colsleft > 1 ) {
5392: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5393: ' </td>';
5394: } elsif ($colsleft == 1) {
5395: $output .= '<td class="LC_left_item"> </td>';
5396: }
5397: $output .= '</tr></table></td></tr>';
5398: return $output;
5399: }
5400:
1.34 raeburn 5401: sub usercreation_types {
5402: my %lt = &Apache::lonlocal::texthash (
5403: author => 'When adding a co-author',
5404: course => 'When adding a user to a course',
1.100 raeburn 5405: requestcrs => 'When requesting a course',
1.34 raeburn 5406: any => 'Any',
5407: official => 'Institutional only ',
5408: unofficial => 'Non-institutional only',
5409: none => 'None',
5410: );
5411: return %lt;
1.48 raeburn 5412: }
1.34 raeburn 5413:
1.224 raeburn 5414: sub selfcreation_types {
5415: my %lt = &Apache::lonlocal::texthash (
5416: selfcreate => 'User creates own account',
5417: any => 'Any',
5418: official => 'Institutional only ',
5419: unofficial => 'Non-institutional only',
5420: email => 'E-mail address',
5421: login => 'Institutional Login',
5422: sso => 'SSO',
5423: );
5424: }
5425:
1.28 raeburn 5426: sub authtype_names {
5427: my %lt = &Apache::lonlocal::texthash(
5428: int => 'Internal',
5429: krb4 => 'Kerberos 4',
5430: krb5 => 'Kerberos 5',
5431: loc => 'Local',
5432: );
5433: return %lt;
5434: }
5435:
5436: sub context_names {
5437: my %context_title = &Apache::lonlocal::texthash(
5438: author => 'Creating users when an Author',
5439: course => 'Creating users when in a course',
5440: domain => 'Creating users when a Domain Coordinator',
5441: );
5442: return %context_title;
5443: }
5444:
1.33 raeburn 5445: sub print_usermodification {
5446: my ($position,$dom,$settings,$rowtotal) = @_;
5447: my $numinrow = 4;
5448: my ($context,$datatable,$rowcount);
5449: if ($position eq 'top') {
5450: $rowcount = 0;
5451: $context = 'author';
5452: foreach my $role ('ca','aa') {
5453: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5454: $numinrow,$rowcount);
5455: $$rowtotal ++;
5456: $rowcount ++;
5457: }
1.230 raeburn 5458: } elsif ($position eq 'bottom') {
1.33 raeburn 5459: $context = 'course';
5460: $rowcount = 0;
5461: foreach my $role ('st','ep','ta','in','cr') {
5462: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5463: $numinrow,$rowcount);
5464: $$rowtotal ++;
5465: $rowcount ++;
5466: }
5467: }
5468: return $datatable;
5469: }
5470:
1.43 raeburn 5471: sub print_defaults {
1.236 raeburn 5472: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 5473: my $rownum = 0;
5474: my ($datatable,$css_class);
1.236 raeburn 5475: if ($position eq 'top') {
5476: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
5477: 'datelocale_def','portal_def');
5478: my %defaults;
5479: if (ref($settings) eq 'HASH') {
5480: %defaults = %{$settings};
1.43 raeburn 5481: } else {
1.236 raeburn 5482: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
5483: foreach my $item (@items) {
5484: $defaults{$item} = $domdefaults{$item};
5485: }
1.43 raeburn 5486: }
1.236 raeburn 5487: my $titles = &defaults_titles($dom);
5488: foreach my $item (@items) {
5489: if ($rownum%2) {
5490: $css_class = '';
5491: } else {
5492: $css_class = ' class="LC_odd_row" ';
5493: }
5494: $datatable .= '<tr'.$css_class.'>'.
5495: '<td><span class="LC_nobreak">'.$titles->{$item}.
5496: '</span></td><td class="LC_right_item" colspan="3">';
5497: if ($item eq 'auth_def') {
5498: my @authtypes = ('internal','krb4','krb5','localauth');
5499: my %shortauth = (
5500: internal => 'int',
5501: krb4 => 'krb4',
5502: krb5 => 'krb5',
5503: localauth => 'loc'
5504: );
5505: my %authnames = &authtype_names();
5506: foreach my $auth (@authtypes) {
5507: my $checked = ' ';
5508: if ($defaults{$item} eq $auth) {
5509: $checked = ' checked="checked" ';
5510: }
5511: $datatable .= '<label><input type="radio" name="'.$item.
5512: '" value="'.$auth.'"'.$checked.'/>'.
5513: $authnames{$shortauth{$auth}}.'</label> ';
5514: }
5515: } elsif ($item eq 'timezone_def') {
5516: my $includeempty = 1;
5517: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
5518: } elsif ($item eq 'datelocale_def') {
5519: my $includeempty = 1;
5520: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
5521: } elsif ($item eq 'lang_def') {
1.263 raeburn 5522: my $includeempty = 1;
5523: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 5524: } else {
5525: my $size;
5526: if ($item eq 'portal_def') {
5527: $size = ' size="25"';
5528: }
5529: $datatable .= '<input type="text" name="'.$item.'" value="'.
5530: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 5531: }
1.236 raeburn 5532: $datatable .= '</td></tr>';
5533: $rownum ++;
5534: }
5535: } else {
5536: my (%defaults);
5537: if (ref($settings) eq 'HASH') {
5538: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
5539: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
5540: my $maxnum = @{$settings->{'inststatusorder'}};
5541: for (my $i=0; $i<$maxnum; $i++) {
5542: $css_class = $rownum%2?' class="LC_odd_row"':'';
5543: my $item = $settings->{'inststatusorder'}->[$i];
5544: my $title = $settings->{'inststatustypes'}->{$item};
5545: my $guestok;
5546: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
5547: $guestok = 1;
5548: }
5549: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
5550: $datatable .= '<tr'.$css_class.'>'.
5551: '<td><span class="LC_nobreak">'.
5552: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
5553: for (my $k=0; $k<=$maxnum; $k++) {
5554: my $vpos = $k+1;
5555: my $selstr;
5556: if ($k == $i) {
5557: $selstr = ' selected="selected" ';
5558: }
5559: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5560: }
5561: my ($checkedon,$checkedoff);
5562: $checkedoff = ' checked="checked"';
5563: if ($guestok) {
5564: $checkedon = $checkedoff;
5565: $checkedoff = '';
5566: }
5567: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
5568: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
5569: &mt('delete').'</span></td>'.
5570: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
5571: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
5572: '</span></td>'.
5573: '<td class="LC_right_item"><span class="LC_nobreak">'.
5574: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
5575: &mt('Yes').'</label>'.(' 'x2).
5576: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
5577: &mt('No').'</label></span></td></tr>';
5578: }
5579: $css_class = $rownum%2?' class="LC_odd_row"':'';
5580: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
5581: $datatable .= '<tr '.$css_class.'>'.
5582: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
5583: for (my $k=0; $k<=$maxnum; $k++) {
5584: my $vpos = $k+1;
5585: my $selstr;
5586: if ($k == $maxnum) {
5587: $selstr = ' selected="selected" ';
5588: }
5589: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5590: }
5591: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 5592: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 5593: ' '.&mt('(new)').
5594: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
5595: &mt('Name displayed:').
5596: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
5597: '<td class="LC_right_item"><span class="LC_nobreak">'.
5598: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
5599: &mt('Yes').'</label>'.(' 'x2).
5600: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
5601: &mt('No').'</label></span></td></tr>';
5602: '</tr>'."\n";
5603: $rownum ++;
1.141 raeburn 5604: }
1.43 raeburn 5605: }
5606: }
5607: $$rowtotal += $rownum;
5608: return $datatable;
5609: }
5610:
1.168 raeburn 5611: sub get_languages_hash {
5612: my %langchoices;
5613: foreach my $id (&Apache::loncommon::languageids()) {
5614: my $code = &Apache::loncommon::supportedlanguagecode($id);
5615: if ($code ne '') {
5616: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5617: }
5618: }
5619: return %langchoices;
5620: }
5621:
1.43 raeburn 5622: sub defaults_titles {
1.141 raeburn 5623: my ($dom) = @_;
1.43 raeburn 5624: my %titles = &Apache::lonlocal::texthash (
5625: 'auth_def' => 'Default authentication type',
5626: 'auth_arg_def' => 'Default authentication argument',
5627: 'lang_def' => 'Default language',
1.54 raeburn 5628: 'timezone_def' => 'Default timezone',
1.68 raeburn 5629: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 5630: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 5631: );
1.141 raeburn 5632: if ($dom) {
5633: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
5634: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
5635: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
5636: $protocol = 'http' if ($protocol ne 'https');
5637: if ($uint_dom) {
5638: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
5639: $uint_dom);
5640: }
5641: }
1.43 raeburn 5642: return (\%titles);
5643: }
5644:
1.46 raeburn 5645: sub print_scantronformat {
5646: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
5647: my $itemcount = 1;
1.60 raeburn 5648: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
5649: %confhash);
1.46 raeburn 5650: my $switchserver = &check_switchserver($dom,$confname);
5651: my %lt = &Apache::lonlocal::texthash (
1.95 www 5652: default => 'Default bubblesheet format file error',
5653: custom => 'Custom bubblesheet format file error',
1.46 raeburn 5654: );
5655: my %scantronfiles = (
5656: default => 'default.tab',
5657: custom => 'custom.tab',
5658: );
5659: foreach my $key (keys(%scantronfiles)) {
5660: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
5661: .$scantronfiles{$key};
5662: }
5663: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
5664: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
5665: if (!$switchserver) {
5666: my $servadm = $r->dir_config('lonAdmEMail');
5667: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
5668: if ($configuserok eq 'ok') {
5669: if ($author_ok eq 'ok') {
5670: my %legacyfile = (
5671: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
5672: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
5673: );
5674: my %md5chk;
5675: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5676: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
5677: chomp($md5chk{$type});
1.46 raeburn 5678: }
5679: if ($md5chk{'default'} ne $md5chk{'custom'}) {
5680: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5681: ($scantronurls{$type},my $error) =
1.46 raeburn 5682: &legacy_scantronformat($r,$dom,$confname,
5683: $type,$legacyfile{$type},
5684: $scantronurls{$type},
5685: $scantronfiles{$type});
1.60 raeburn 5686: if ($error ne '') {
5687: $error{$type} = $error;
5688: }
5689: }
5690: if (keys(%error) == 0) {
5691: $is_custom = 1;
5692: $confhash{'scantron'}{'scantronformat'} =
5693: $scantronurls{'custom'};
5694: my $putresult =
5695: &Apache::lonnet::put_dom('configuration',
5696: \%confhash,$dom);
5697: if ($putresult ne 'ok') {
5698: $error{'custom'} =
5699: '<span class="LC_error">'.
5700: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5701: }
1.46 raeburn 5702: }
5703: } else {
1.60 raeburn 5704: ($scantronurls{'default'},my $error) =
1.46 raeburn 5705: &legacy_scantronformat($r,$dom,$confname,
5706: 'default',$legacyfile{'default'},
5707: $scantronurls{'default'},
5708: $scantronfiles{'default'});
1.60 raeburn 5709: if ($error eq '') {
5710: $confhash{'scantron'}{'scantronformat'} = '';
5711: my $putresult =
5712: &Apache::lonnet::put_dom('configuration',
5713: \%confhash,$dom);
5714: if ($putresult ne 'ok') {
5715: $error{'default'} =
5716: '<span class="LC_error">'.
5717: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5718: }
5719: } else {
5720: $error{'default'} = $error;
5721: }
1.46 raeburn 5722: }
5723: }
5724: }
5725: } else {
1.95 www 5726: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 5727: }
5728: }
5729: if (ref($settings) eq 'HASH') {
5730: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
5731: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
5732: if ((!@info) || ($info[0] eq 'no_such_dir')) {
5733: $scantronurl = '';
5734: } else {
5735: $scantronurl = $settings->{'scantronformat'};
5736: }
5737: $is_custom = 1;
5738: } else {
5739: $scantronurl = $scantronurls{'default'};
5740: }
5741: } else {
1.60 raeburn 5742: if ($is_custom) {
5743: $scantronurl = $scantronurls{'custom'};
5744: } else {
5745: $scantronurl = $scantronurls{'default'};
5746: }
1.46 raeburn 5747: }
5748: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5749: $datatable .= '<tr'.$css_class.'>';
5750: if (!$is_custom) {
1.65 raeburn 5751: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
5752: '<span class="LC_nobreak">';
1.46 raeburn 5753: if ($scantronurl) {
1.199 raeburn 5754: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
5755: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 5756: } else {
5757: $datatable = &mt('File unavailable for display');
5758: }
1.65 raeburn 5759: $datatable .= '</span></td>';
1.60 raeburn 5760: if (keys(%error) == 0) {
5761: $datatable .= '<td valign="bottom">';
5762: if (!$switchserver) {
5763: $datatable .= &mt('Upload:').'<br />';
5764: }
5765: } else {
5766: my $errorstr;
5767: foreach my $key (sort(keys(%error))) {
5768: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5769: }
5770: $datatable .= '<td>'.$errorstr;
5771: }
1.46 raeburn 5772: } else {
5773: if (keys(%error) > 0) {
5774: my $errorstr;
5775: foreach my $key (sort(keys(%error))) {
5776: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5777: }
1.60 raeburn 5778: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 5779: } elsif ($scantronurl) {
1.199 raeburn 5780: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
5781: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 5782: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 5783: $link.
5784: '<label><input type="checkbox" name="scantronformat_del"'.
5785: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 5786: '<td><span class="LC_nobreak"> '.
5787: &mt('Replace:').'</span><br />';
1.46 raeburn 5788: }
5789: }
5790: if (keys(%error) == 0) {
5791: if ($switchserver) {
5792: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5793: } else {
1.65 raeburn 5794: $datatable .='<span class="LC_nobreak"> '.
5795: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 5796: }
5797: }
5798: $datatable .= '</td></tr>';
5799: $$rowtotal ++;
5800: return $datatable;
5801: }
5802:
5803: sub legacy_scantronformat {
5804: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
5805: my ($url,$error);
5806: my @statinfo = &Apache::lonnet::stat_file($newurl);
5807: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
5808: (my $result,$url) =
5809: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
5810: '','',$newfile);
5811: if ($result ne 'ok') {
1.130 raeburn 5812: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 5813: }
5814: }
5815: return ($url,$error);
5816: }
1.43 raeburn 5817:
1.49 raeburn 5818: sub print_coursecategories {
1.57 raeburn 5819: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
5820: my $datatable;
5821: if ($position eq 'top') {
1.238 raeburn 5822: my (%checked);
5823: my @catitems = ('unauth','auth');
5824: my @cattypes = ('std','domonly','codesrch','none');
5825: $checked{'unauth'} = 'std';
5826: $checked{'auth'} = 'std';
5827: if (ref($settings) eq 'HASH') {
5828: foreach my $type (@cattypes) {
5829: if ($type eq $settings->{'unauth'}) {
5830: $checked{'unauth'} = $type;
5831: }
5832: if ($type eq $settings->{'auth'}) {
5833: $checked{'auth'} = $type;
5834: }
5835: }
5836: }
5837: my %lt = &Apache::lonlocal::texthash (
5838: unauth => 'Catalog type for unauthenticated users',
5839: auth => 'Catalog type for authenticated users',
5840: none => 'No catalog',
5841: std => 'Standard catalog',
5842: domonly => 'Domain-only catalog',
5843: codesrch => "Code search form",
5844: );
5845: my $itemcount = 0;
5846: foreach my $item (@catitems) {
5847: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
5848: $datatable .= '<tr '.$css_class.'>'.
5849: '<td>'.$lt{$item}.'</td>'.
5850: '<td class="LC_right_item"><span class="LC_nobreak">';
5851: foreach my $type (@cattypes) {
5852: my $ischecked;
5853: if ($checked{$item} eq $type) {
5854: $ischecked=' checked="checked"';
5855: }
5856: $datatable .= '<label>'.
5857: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
5858: ' />'.$lt{$type}.'</label> ';
5859: }
5860: $datatable .= '</td></tr>';
5861: $itemcount ++;
5862: }
5863: $$rowtotal += $itemcount;
5864: } elsif ($position eq 'middle') {
1.57 raeburn 5865: my $toggle_cats_crs = ' ';
5866: my $toggle_cats_dom = ' checked="checked" ';
5867: my $can_cat_crs = ' ';
5868: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 5869: my $toggle_catscomm_comm = ' ';
5870: my $toggle_catscomm_dom = ' checked="checked" ';
5871: my $can_catcomm_comm = ' ';
5872: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 5873: my $toggle_catsplace_place = ' ';
5874: my $toggle_catsplace_dom = ' checked="checked" ';
5875: my $can_catplace_place = ' ';
5876: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 5877:
1.57 raeburn 5878: if (ref($settings) eq 'HASH') {
5879: if ($settings->{'togglecats'} eq 'crs') {
5880: $toggle_cats_crs = $toggle_cats_dom;
5881: $toggle_cats_dom = ' ';
5882: }
5883: if ($settings->{'categorize'} eq 'crs') {
5884: $can_cat_crs = $can_cat_dom;
5885: $can_cat_dom = ' ';
5886: }
1.120 raeburn 5887: if ($settings->{'togglecatscomm'} eq 'comm') {
5888: $toggle_catscomm_comm = $toggle_catscomm_dom;
5889: $toggle_catscomm_dom = ' ';
5890: }
5891: if ($settings->{'categorizecomm'} eq 'comm') {
5892: $can_catcomm_comm = $can_catcomm_dom;
5893: $can_catcomm_dom = ' ';
5894: }
1.272 raeburn 5895: if ($settings->{'togglecatsplace'} eq 'place') {
5896: $toggle_catsplace_place = $toggle_catsplace_dom;
5897: $toggle_catsplace_dom = ' ';
5898: }
5899: if ($settings->{'categorizeplace'} eq 'place') {
5900: $can_catplace_place = $can_catplace_dom;
5901: $can_catplace_dom = ' ';
5902: }
1.57 raeburn 5903: }
5904: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 5905: togglecats => 'Show/Hide a course in catalog',
5906: togglecatscomm => 'Show/Hide a community in catalog',
5907: togglecatsplace => 'Show/Hide a placement test in catalog',
5908: categorize => 'Assign a category to a course',
5909: categorizecomm => 'Assign a category to a community',
5910: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 5911: );
5912: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 5913: dom => 'Set in Domain',
5914: crs => 'Set in Course',
5915: comm => 'Set in Community',
5916: place => 'Set in Placement Test',
1.57 raeburn 5917: );
5918: $datatable = '<tr class="LC_odd_row">'.
5919: '<td>'.$title{'togglecats'}.'</td>'.
5920: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5921: '<input type="radio" name="togglecats"'.
5922: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5923: '<label><input type="radio" name="togglecats"'.
5924: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
5925: '</tr><tr>'.
5926: '<td>'.$title{'categorize'}.'</td>'.
5927: '<td class="LC_right_item"><span class="LC_nobreak">'.
5928: '<label><input type="radio" name="categorize"'.
5929: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5930: '<label><input type="radio" name="categorize"'.
5931: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 5932: '</tr><tr class="LC_odd_row">'.
5933: '<td>'.$title{'togglecatscomm'}.'</td>'.
5934: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5935: '<input type="radio" name="togglecatscomm"'.
5936: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5937: '<label><input type="radio" name="togglecatscomm"'.
5938: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
5939: '</tr><tr>'.
5940: '<td>'.$title{'categorizecomm'}.'</td>'.
5941: '<td class="LC_right_item"><span class="LC_nobreak">'.
5942: '<label><input type="radio" name="categorizecomm"'.
5943: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5944: '<label><input type="radio" name="categorizecomm"'.
5945: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.272 raeburn 5946: '</tr><tr>'.
5947: '<td>'.$title{'togglecatsplace'}.'</td>'.
5948: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5949: '<input type="radio" name="togglecatsplace"'.
5950: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5951: '<label><input type="radio" name="togglecatscomm"'.
5952: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
5953: '</tr><tr>'.
5954: '<td>'.$title{'categorizeplace'}.'</td>'.
5955: '<td class="LC_right_item"><span class="LC_nobreak">'.
5956: '<label><input type="radio" name="categorizeplace"'.
5957: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5958: '<label><input type="radio" name="categorizeplace"'.
5959: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 5960: '</tr>';
1.272 raeburn 5961: $$rowtotal += 6;
1.57 raeburn 5962: } else {
5963: my $css_class;
5964: my $itemcount = 1;
5965: my $cathash;
5966: if (ref($settings) eq 'HASH') {
5967: $cathash = $settings->{'cats'};
5968: }
5969: if (ref($cathash) eq 'HASH') {
5970: my (@cats,@trails,%allitems,%idx,@jsarray);
5971: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
5972: \%allitems,\%idx,\@jsarray);
5973: my $maxdepth = scalar(@cats);
5974: my $colattrib = '';
5975: if ($maxdepth > 2) {
5976: $colattrib = ' colspan="2" ';
5977: }
5978: my @path;
5979: if (@cats > 0) {
5980: if (ref($cats[0]) eq 'ARRAY') {
5981: my $numtop = @{$cats[0]};
5982: my $maxnum = $numtop;
1.120 raeburn 5983: my %default_names = (
5984: instcode => &mt('Official courses'),
5985: communities => &mt('Communities'),
1.272 raeburn 5986: placement => &mt('Placement Tests'),
1.120 raeburn 5987: );
5988:
5989: if ((!grep(/^instcode$/,@{$cats[0]})) ||
5990: ($cathash->{'instcode::0'} eq '') ||
5991: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 5992: ($cathash->{'communities::0'} eq '') ||
5993: (!grep(/^placement$/,@{$cats[0]})) ||
5994: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 5995: $maxnum ++;
5996: }
5997: my $lastidx;
5998: for (my $i=0; $i<$numtop; $i++) {
5999: my $parent = $cats[0][$i];
6000: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6001: my $item = &escape($parent).'::0';
6002: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
6003: $lastidx = $idx{$item};
6004: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6005: .'<select name="'.$item.'"'.$chgstr.'>';
6006: for (my $k=0; $k<=$maxnum; $k++) {
6007: my $vpos = $k+1;
6008: my $selstr;
6009: if ($k == $i) {
6010: $selstr = ' selected="selected" ';
6011: }
6012: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6013: }
1.214 raeburn 6014: $datatable .= '</select></span></td><td>';
1.272 raeburn 6015: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 6016: $datatable .= '<span class="LC_nobreak">'
6017: .$default_names{$parent}.'</span>';
6018: if ($parent eq 'instcode') {
6019: $datatable .= '<br /><span class="LC_nobreak">('
6020: .&mt('with institutional codes')
6021: .')</span></td><td'.$colattrib.'>';
6022: } else {
6023: $datatable .= '<table><tr><td>';
6024: }
6025: $datatable .= '<span class="LC_nobreak">'
6026: .'<label><input type="radio" name="'
6027: .$parent.'" value="1" checked="checked" />'
6028: .&mt('Display').'</label>';
6029: if ($parent eq 'instcode') {
6030: $datatable .= ' ';
6031: } else {
6032: $datatable .= '</span></td></tr><tr><td>'
6033: .'<span class="LC_nobreak">';
6034: }
6035: $datatable .= '<label><input type="radio" name="'
6036: .$parent.'" value="0" />'
6037: .&mt('Do not display').'</label></span>';
1.272 raeburn 6038: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 6039: $datatable .= '</td></tr></table>';
6040: }
6041: $datatable .= '</td>';
1.57 raeburn 6042: } else {
6043: $datatable .= $parent
1.214 raeburn 6044: .' <span class="LC_nobreak"><label>'
6045: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 6046: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
6047: }
6048: my $depth = 1;
6049: push(@path,$parent);
6050: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
6051: pop(@path);
6052: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
6053: $itemcount ++;
6054: }
1.48 raeburn 6055: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 6056: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
6057: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 6058: for (my $k=0; $k<=$maxnum; $k++) {
6059: my $vpos = $k+1;
6060: my $selstr;
1.57 raeburn 6061: if ($k == $numtop) {
1.48 raeburn 6062: $selstr = ' selected="selected" ';
6063: }
6064: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6065: }
1.59 bisitz 6066: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 6067: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
6068: .'</tr>'."\n";
1.48 raeburn 6069: $itemcount ++;
1.272 raeburn 6070: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 6071: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
6072: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6073: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
6074: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
6075: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
6076: for (my $k=0; $k<=$maxnum; $k++) {
6077: my $vpos = $k+1;
6078: my $selstr;
6079: if ($k == $maxnum) {
6080: $selstr = ' selected="selected" ';
6081: }
6082: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 6083: }
1.120 raeburn 6084: $datatable .= '</select></span></td>'.
6085: '<td><span class="LC_nobreak">'.
6086: $default_names{$default}.'</span>';
6087: if ($default eq 'instcode') {
6088: $datatable .= '<br /><span class="LC_nobreak">('
6089: .&mt('with institutional codes').')</span>';
6090: }
6091: $datatable .= '</td>'
6092: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
6093: .&mt('Display').'</label> '
6094: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
6095: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 6096: }
6097: }
6098: }
1.57 raeburn 6099: } else {
6100: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 6101: }
6102: } else {
1.238 raeburn 6103: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 6104: .&initialize_categories($itemcount);
1.48 raeburn 6105: }
1.57 raeburn 6106: $$rowtotal += $itemcount;
1.48 raeburn 6107: }
6108: return $datatable;
6109: }
6110:
1.69 raeburn 6111: sub print_serverstatuses {
6112: my ($dom,$settings,$rowtotal) = @_;
6113: my $datatable;
6114: my @pages = &serverstatus_pages();
6115: my (%namedaccess,%machineaccess);
6116: foreach my $type (@pages) {
6117: $namedaccess{$type} = '';
6118: $machineaccess{$type}= '';
6119: }
6120: if (ref($settings) eq 'HASH') {
6121: foreach my $type (@pages) {
6122: if (exists($settings->{$type})) {
6123: if (ref($settings->{$type}) eq 'HASH') {
6124: foreach my $key (keys(%{$settings->{$type}})) {
6125: if ($key eq 'namedusers') {
6126: $namedaccess{$type} = $settings->{$type}->{$key};
6127: } elsif ($key eq 'machines') {
6128: $machineaccess{$type} = $settings->{$type}->{$key};
6129: }
6130: }
6131: }
6132: }
6133: }
6134: }
1.81 raeburn 6135: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 6136: my $rownum = 0;
6137: my $css_class;
6138: foreach my $type (@pages) {
6139: $rownum ++;
6140: $css_class = $rownum%2?' class="LC_odd_row"':'';
6141: $datatable .= '<tr'.$css_class.'>'.
6142: '<td><span class="LC_nobreak">'.
6143: $titles->{$type}.'</span></td>'.
6144: '<td class="LC_left_item">'.
6145: '<input type="text" name="'.$type.'_namedusers" '.
6146: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
6147: '<td class="LC_right_item">'.
6148: '<span class="LC_nobreak">'.
6149: '<input type="text" name="'.$type.'_machines" '.
6150: 'value="'.$machineaccess{$type}.'" size="10" />'.
6151: '</td></tr>'."\n";
6152: }
6153: $$rowtotal += $rownum;
6154: return $datatable;
6155: }
6156:
6157: sub serverstatus_pages {
6158: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 6159: 'checksums','clusterstatus','certstatus','metadata_keywords',
6160: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
6161: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 6162: }
6163:
1.236 raeburn 6164: sub defaults_javascript {
6165: my ($settings) = @_;
1.248 raeburn 6166: return unless (ref($settings) eq 'HASH');
1.236 raeburn 6167: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
6168: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
6169: if ($maxnum eq '') {
6170: $maxnum = 0;
6171: }
6172: $maxnum ++;
1.249 raeburn 6173: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 6174: return <<"ENDSCRIPT";
6175: <script type="text/javascript">
6176: // <![CDATA[
6177: function reorderTypes(form,caller) {
6178: var changedVal;
6179: $jstext
6180: var newpos = 'addinststatus_pos';
6181: var current = new Array;
6182: var maxh = $maxnum;
6183: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6184: var oldVal;
6185: if (caller == newpos) {
6186: changedVal = newitemVal;
6187: } else {
6188: var curritem = 'inststatus_pos_'+caller;
6189: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
6190: current[newitemVal] = newpos;
6191: }
6192: for (var i=0; i<inststatuses.length; i++) {
6193: if (inststatuses[i] != caller) {
6194: var elementName = 'inststatus_pos_'+inststatuses[i];
6195: if (form.elements[elementName]) {
6196: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6197: current[currVal] = elementName;
6198: }
6199: }
6200: }
6201: for (var j=0; j<maxh; j++) {
6202: if (current[j] == undefined) {
6203: oldVal = j;
6204: }
6205: }
6206: if (oldVal < changedVal) {
6207: for (var k=oldVal+1; k<=changedVal ; k++) {
6208: var elementName = current[k];
6209: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6210: }
6211: } else {
6212: for (var k=changedVal; k<oldVal; k++) {
6213: var elementName = current[k];
6214: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6215: }
6216: }
6217: return;
6218: }
6219:
6220: // ]]>
6221: </script>
6222:
6223: ENDSCRIPT
6224: }
6225: }
6226:
1.49 raeburn 6227: sub coursecategories_javascript {
6228: my ($settings) = @_;
1.57 raeburn 6229: my ($output,$jstext,$cathash);
1.49 raeburn 6230: if (ref($settings) eq 'HASH') {
1.57 raeburn 6231: $cathash = $settings->{'cats'};
6232: }
6233: if (ref($cathash) eq 'HASH') {
1.49 raeburn 6234: my (@cats,@jsarray,%idx);
1.57 raeburn 6235: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 6236: if (@jsarray > 0) {
6237: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
6238: for (my $i=0; $i<@jsarray; $i++) {
6239: if (ref($jsarray[$i]) eq 'ARRAY') {
6240: my $catstr = join('","',@{$jsarray[$i]});
6241: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
6242: }
6243: }
6244: }
6245: } else {
6246: $jstext = ' var categories = Array(1);'."\n".
6247: ' categories[0] = Array("instcode_pos");'."\n";
6248: }
1.237 bisitz 6249: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
6250: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 6251: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 6252: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
6253: &js_escape(\$instcode_reserved);
6254: &js_escape(\$communities_reserved);
1.272 raeburn 6255: &js_escape(\$placement_reserved);
1.265 damieng 6256: &js_escape(\$choose_again);
1.49 raeburn 6257: $output = <<"ENDSCRIPT";
6258: <script type="text/javascript">
1.109 raeburn 6259: // <![CDATA[
1.49 raeburn 6260: function reorderCats(form,parent,item,idx) {
6261: var changedVal;
6262: $jstext
6263: var newpos = 'addcategory_pos';
6264: if (parent == '') {
6265: var has_instcode = 0;
6266: var maxtop = categories[idx].length;
6267: for (var j=0; j<maxtop; j++) {
6268: if (categories[idx][j] == 'instcode::0') {
6269: has_instcode == 1;
6270: }
6271: }
6272: if (has_instcode == 0) {
6273: categories[idx][maxtop] = 'instcode_pos';
6274: }
6275: } else {
6276: newpos += '_'+parent;
6277: }
6278: var maxh = 1 + categories[idx].length;
6279: var current = new Array;
6280: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6281: if (item == newpos) {
6282: changedVal = newitemVal;
6283: } else {
6284: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
6285: current[newitemVal] = newpos;
6286: }
6287: for (var i=0; i<categories[idx].length; i++) {
6288: var elementName = categories[idx][i];
6289: if (elementName != item) {
6290: if (form.elements[elementName]) {
6291: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6292: current[currVal] = elementName;
6293: }
6294: }
6295: }
6296: var oldVal;
6297: for (var j=0; j<maxh; j++) {
6298: if (current[j] == undefined) {
6299: oldVal = j;
6300: }
6301: }
6302: if (oldVal < changedVal) {
6303: for (var k=oldVal+1; k<=changedVal ; k++) {
6304: var elementName = current[k];
6305: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6306: }
6307: } else {
6308: for (var k=changedVal; k<oldVal; k++) {
6309: var elementName = current[k];
6310: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6311: }
6312: }
6313: return;
6314: }
1.120 raeburn 6315:
6316: function categoryCheck(form) {
6317: if (form.elements['addcategory_name'].value == 'instcode') {
6318: alert('$instcode_reserved\\n$choose_again');
6319: return false;
6320: }
6321: if (form.elements['addcategory_name'].value == 'communities') {
6322: alert('$communities_reserved\\n$choose_again');
6323: return false;
6324: }
1.272 raeburn 6325: if (form.elements['addcategory_name'].value == 'placement') {
6326: alert('$placement_reserved\\n$choose_again');
6327: return false;
6328: }
1.120 raeburn 6329: return true;
6330: }
6331:
1.109 raeburn 6332: // ]]>
1.49 raeburn 6333: </script>
6334:
6335: ENDSCRIPT
6336: return $output;
6337: }
6338:
1.48 raeburn 6339: sub initialize_categories {
6340: my ($itemcount) = @_;
1.120 raeburn 6341: my ($datatable,$css_class,$chgstr);
6342: my %default_names = (
6343: instcode => 'Official courses (with institutional codes)',
6344: communities => 'Communities',
1.272 raeburn 6345: placement => 'Placement Tests',
1.120 raeburn 6346: );
6347: my $select0 = ' selected="selected"';
6348: my $select1 = '';
1.272 raeburn 6349: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 6350: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6351: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
1.272 raeburn 6352: if (($default eq 'communities') || ($default eq 'placement')) {
1.120 raeburn 6353: $select1 = $select0;
6354: $select0 = '';
6355: }
6356: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6357: .'<select name="'.$default.'_pos">'
6358: .'<option value="0"'.$select0.'>1</option>'
6359: .'<option value="1"'.$select1.'>2</option>'
6360: .'<option value="2">3</option></select> '
6361: .$default_names{$default}
6362: .'</span></td><td><span class="LC_nobreak">'
6363: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
6364: .&mt('Display').'</label> <label>'
6365: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 6366: .'</label></span></td></tr>';
1.120 raeburn 6367: $itemcount ++;
6368: }
1.48 raeburn 6369: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 6370: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 6371: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 6372: .'<select name="addcategory_pos"'.$chgstr.'>'
6373: .'<option value="0">1</option>'
6374: .'<option value="1">2</option>'
6375: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 6376: .&mt('Add category').'</td><td>'.&mt('Name:')
6377: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
6378: return $datatable;
6379: }
6380:
6381: sub build_category_rows {
1.49 raeburn 6382: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
6383: my ($text,$name,$item,$chgstr);
1.48 raeburn 6384: if (ref($cats) eq 'ARRAY') {
6385: my $maxdepth = scalar(@{$cats});
6386: if (ref($cats->[$depth]) eq 'HASH') {
6387: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
6388: my $numchildren = @{$cats->[$depth]{$parent}};
6389: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 6390: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 6391: my ($idxnum,$parent_name,$parent_item);
6392: my $higher = $depth - 1;
6393: if ($higher == 0) {
6394: $parent_name = &escape($parent).'::'.$higher;
6395: } else {
6396: if (ref($path) eq 'ARRAY') {
6397: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6398: }
6399: }
6400: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 6401: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 6402: if ($j < $numchildren) {
1.48 raeburn 6403: $name = $cats->[$depth]{$parent}[$j];
6404: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 6405: $idxnum = $idx->{$item};
6406: } else {
6407: $name = $parent_name;
6408: $item = $parent_item;
1.48 raeburn 6409: }
1.49 raeburn 6410: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
6411: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 6412: for (my $i=0; $i<=$numchildren; $i++) {
6413: my $vpos = $i+1;
6414: my $selstr;
6415: if ($j == $i) {
6416: $selstr = ' selected="selected" ';
6417: }
6418: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
6419: }
6420: $text .= '</select> ';
6421: if ($j < $numchildren) {
6422: my $deeper = $depth+1;
6423: $text .= $name.' '
6424: .'<label><input type="checkbox" name="deletecategory" value="'
6425: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
6426: if(ref($path) eq 'ARRAY') {
6427: push(@{$path},$name);
1.49 raeburn 6428: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 6429: pop(@{$path});
6430: }
6431: } else {
1.59 bisitz 6432: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 6433: if ($j == $numchildren) {
6434: $text .= $name;
6435: } else {
6436: $text .= $item;
6437: }
6438: $text .= '" value="" />';
6439: }
6440: $text .= '</td></tr>';
6441: }
6442: $text .= '</table></td>';
6443: } else {
6444: my $higher = $depth-1;
6445: if ($higher == 0) {
6446: $name = &escape($parent).'::'.$higher;
6447: } else {
6448: if (ref($path) eq 'ARRAY') {
6449: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6450: }
6451: }
6452: my $colspan;
6453: if ($parent ne 'instcode') {
6454: $colspan = $maxdepth - $depth - 1;
6455: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
6456: }
6457: }
6458: }
6459: }
6460: return $text;
6461: }
6462:
1.33 raeburn 6463: sub modifiable_userdata_row {
1.228 raeburn 6464: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
6465: my ($role,$rolename,$statustype);
6466: $role = $item;
1.224 raeburn 6467: if ($context eq 'cancreate') {
1.228 raeburn 6468: if ($item =~ /^emailusername_(.+)$/) {
6469: $statustype = $1;
6470: $role = 'emailusername';
6471: if (ref($usertypes) eq 'HASH') {
6472: if ($usertypes->{$statustype}) {
6473: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
6474: } else {
6475: $rolename = &mt('Data provided by user');
6476: }
6477: }
1.224 raeburn 6478: }
6479: } elsif ($context eq 'selfcreate') {
1.63 raeburn 6480: if (ref($usertypes) eq 'HASH') {
6481: $rolename = $usertypes->{$role};
6482: } else {
6483: $rolename = $role;
6484: }
1.33 raeburn 6485: } else {
1.63 raeburn 6486: if ($role eq 'cr') {
6487: $rolename = &mt('Custom role');
6488: } else {
6489: $rolename = &Apache::lonnet::plaintext($role);
6490: }
1.33 raeburn 6491: }
1.224 raeburn 6492: my (@fields,%fieldtitles);
6493: if (ref($fieldsref) eq 'ARRAY') {
6494: @fields = @{$fieldsref};
6495: } else {
6496: @fields = ('lastname','firstname','middlename','generation',
6497: 'permanentemail','id');
6498: }
6499: if ((ref($titlesref) eq 'HASH')) {
6500: %fieldtitles = %{$titlesref};
6501: } else {
6502: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6503: }
1.33 raeburn 6504: my $output;
6505: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6506: $output = '<tr '.$css_class.'>'.
6507: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
6508: '<td class="LC_left_item" colspan="2"><table>';
6509: my $rem;
6510: my %checks;
6511: if (ref($settings) eq 'HASH') {
6512: if (ref($settings->{$context}) eq 'HASH') {
6513: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 6514: my $hashref = $settings->{$context}->{$role};
6515: if ($role eq 'emailusername') {
6516: if ($statustype) {
6517: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
6518: $hashref = $settings->{$context}->{$role}->{$statustype};
6519: if (ref($hashref) eq 'HASH') {
6520: foreach my $field (@fields) {
6521: if ($hashref->{$field}) {
6522: $checks{$field} = $hashref->{$field};
6523: }
6524: }
6525: }
6526: }
6527: }
6528: } else {
6529: if (ref($hashref) eq 'HASH') {
6530: foreach my $field (@fields) {
6531: if ($hashref->{$field}) {
6532: $checks{$field} = ' checked="checked" ';
6533: }
6534: }
1.33 raeburn 6535: }
6536: }
6537: }
6538: }
6539: }
1.228 raeburn 6540:
1.33 raeburn 6541: for (my $i=0; $i<@fields; $i++) {
6542: my $rem = $i%($numinrow);
6543: if ($rem == 0) {
6544: if ($i > 0) {
6545: $output .= '</tr>';
6546: }
6547: $output .= '<tr>';
6548: }
6549: my $check = ' ';
1.228 raeburn 6550: unless ($role eq 'emailusername') {
6551: if (exists($checks{$fields[$i]})) {
6552: $check = $checks{$fields[$i]}
6553: } else {
6554: if ($role eq 'st') {
6555: if (ref($settings) ne 'HASH') {
6556: $check = ' checked="checked" ';
6557: }
1.33 raeburn 6558: }
6559: }
6560: }
6561: $output .= '<td class="LC_left_item">'.
1.228 raeburn 6562: '<span class="LC_nobreak">';
6563: if ($role eq 'emailusername') {
6564: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
6565: $checks{$fields[$i]} = 'omit';
6566: }
6567: foreach my $option ('required','optional','omit') {
6568: my $checked='';
6569: if ($checks{$fields[$i]} eq $option) {
6570: $checked='checked="checked" ';
6571: }
6572: $output .= '<label>'.
6573: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
6574: &mt($option).'</label>'.(' ' x2);
6575: }
6576: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
6577: } else {
6578: $output .= '<label>'.
6579: '<input type="checkbox" name="canmodify_'.$role.'" '.
6580: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
6581: '</label>';
6582: }
6583: $output .= '</span></td>';
1.33 raeburn 6584: $rem = @fields%($numinrow);
6585: }
6586: my $colsleft = $numinrow - $rem;
6587: if ($colsleft > 1 ) {
6588: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6589: ' </td>';
6590: } elsif ($colsleft == 1) {
6591: $output .= '<td class="LC_left_item"> </td>';
6592: }
6593: $output .= '</tr></table></td></tr>';
6594: return $output;
6595: }
1.28 raeburn 6596:
1.93 raeburn 6597: sub insttypes_row {
1.224 raeburn 6598: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 6599: my %lt = &Apache::lonlocal::texthash (
6600: cansearch => 'Users allowed to search',
6601: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 6602: lockablenames => 'User preference to lock name',
1.93 raeburn 6603: );
6604: my $showdom;
6605: if ($context eq 'cansearch') {
6606: $showdom = ' ('.$dom.')';
6607: }
1.165 raeburn 6608: my $class = 'LC_left_item';
6609: if ($context eq 'statustocreate') {
6610: $class = 'LC_right_item';
6611: }
1.224 raeburn 6612: my $css_class = ' class="LC_odd_row"';
6613: if ($rownum ne '') {
6614: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
6615: }
6616: my $output = '<tr'.$css_class.'>'.
6617: '<td>'.$lt{$context}.$showdom.
6618: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 6619: my $rem;
6620: if (ref($types) eq 'ARRAY') {
6621: for (my $i=0; $i<@{$types}; $i++) {
6622: if (defined($usertypes->{$types->[$i]})) {
6623: my $rem = $i%($numinrow);
6624: if ($rem == 0) {
6625: if ($i > 0) {
6626: $output .= '</tr>';
6627: }
6628: $output .= '<tr>';
1.23 raeburn 6629: }
1.26 raeburn 6630: my $check = ' ';
1.99 raeburn 6631: if (ref($settings) eq 'HASH') {
6632: if (ref($settings->{$context}) eq 'ARRAY') {
6633: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
6634: $check = ' checked="checked" ';
6635: }
6636: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6637: $check = ' checked="checked" ';
6638: }
1.23 raeburn 6639: }
1.26 raeburn 6640: $output .= '<td class="LC_left_item">'.
6641: '<span class="LC_nobreak"><label>'.
1.93 raeburn 6642: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 6643: 'value="'.$types->[$i].'"'.$check.'/>'.
6644: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 6645: }
6646: }
1.26 raeburn 6647: $rem = @{$types}%($numinrow);
1.23 raeburn 6648: }
6649: my $colsleft = $numinrow - $rem;
1.131 raeburn 6650: if (($rem == 0) && (@{$types} > 0)) {
6651: $output .= '<tr>';
6652: }
1.23 raeburn 6653: if ($colsleft > 1) {
1.25 raeburn 6654: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 6655: } else {
1.25 raeburn 6656: $output .= '<td class="LC_left_item">';
1.23 raeburn 6657: }
6658: my $defcheck = ' ';
1.99 raeburn 6659: if (ref($settings) eq 'HASH') {
6660: if (ref($settings->{$context}) eq 'ARRAY') {
6661: if (grep(/^default$/,@{$settings->{$context}})) {
6662: $defcheck = ' checked="checked" ';
6663: }
6664: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6665: $defcheck = ' checked="checked" ';
6666: }
1.23 raeburn 6667: }
1.25 raeburn 6668: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 6669: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 6670: 'value="default"'.$defcheck.'/>'.
6671: $othertitle.'</label></span></td>'.
6672: '</tr></table></td></tr>';
6673: return $output;
1.23 raeburn 6674: }
6675:
6676: sub sorted_searchtitles {
6677: my %searchtitles = &Apache::lonlocal::texthash(
6678: 'uname' => 'username',
6679: 'lastname' => 'last name',
6680: 'lastfirst' => 'last name, first name',
6681: );
6682: my @titleorder = ('uname','lastname','lastfirst');
6683: return (\%searchtitles,\@titleorder);
6684: }
6685:
1.25 raeburn 6686: sub sorted_searchtypes {
6687: my %srchtypes_desc = (
6688: exact => 'is exact match',
6689: contains => 'contains ..',
6690: begins => 'begins with ..',
6691: );
6692: my @srchtypeorder = ('exact','begins','contains');
6693: return (\%srchtypes_desc,\@srchtypeorder);
6694: }
6695:
1.3 raeburn 6696: sub usertype_update_row {
6697: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
6698: my $datatable;
6699: my $numinrow = 4;
6700: foreach my $type (@{$types}) {
6701: if (defined($usertypes->{$type})) {
6702: $$rownums ++;
6703: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
6704: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
6705: '</td><td class="LC_left_item"><table>';
6706: for (my $i=0; $i<@{$fields}; $i++) {
6707: my $rem = $i%($numinrow);
6708: if ($rem == 0) {
6709: if ($i > 0) {
6710: $datatable .= '</tr>';
6711: }
6712: $datatable .= '<tr>';
6713: }
6714: my $check = ' ';
1.39 raeburn 6715: if (ref($settings) eq 'HASH') {
6716: if (ref($settings->{'fields'}) eq 'HASH') {
6717: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
6718: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
6719: $check = ' checked="checked" ';
6720: }
1.3 raeburn 6721: }
6722: }
6723: }
6724:
6725: if ($i == @{$fields}-1) {
6726: my $colsleft = $numinrow - $rem;
6727: if ($colsleft > 1) {
6728: $datatable .= '<td colspan="'.$colsleft.'">';
6729: } else {
6730: $datatable .= '<td>';
6731: }
6732: } else {
6733: $datatable .= '<td>';
6734: }
1.8 raeburn 6735: $datatable .= '<span class="LC_nobreak"><label>'.
6736: '<input type="checkbox" name="updateable_'.$type.
6737: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
6738: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 6739: }
6740: $datatable .= '</tr></table></td></tr>';
6741: }
6742: }
6743: return $datatable;
1.1 raeburn 6744: }
6745:
6746: sub modify_login {
1.205 raeburn 6747: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 6748: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
6749: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
6750: %title = ( coursecatalog => 'Display course catalog',
6751: adminmail => 'Display administrator E-mail address',
1.188 raeburn 6752: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 6753: newuser => 'Link for visitors to create a user account',
6754: loginheader => 'Log-in box header');
6755: @offon = ('off','on');
1.112 raeburn 6756: if (ref($domconfig{login}) eq 'HASH') {
6757: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
6758: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
6759: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
6760: }
6761: }
6762: }
1.9 raeburn 6763: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
6764: \%domconfig,\%loginhash);
1.188 raeburn 6765: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6766: foreach my $item (@toggles) {
6767: $loginhash{login}{$item} = $env{'form.'.$item};
6768: }
1.41 raeburn 6769: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 6770: if (ref($colchanges{'login'}) eq 'HASH') {
6771: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
6772: \%loginhash);
6773: }
1.110 raeburn 6774:
1.149 raeburn 6775: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 6776: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 6777: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 6778: if (keys(%servers) > 1) {
6779: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 6780: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
6781: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
6782: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
6783: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
6784: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
6785: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6786: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6787: $changes{'loginvia'}{$lonhost} = 1;
6788: } else {
6789: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
6790: $changes{'loginvia'}{$lonhost} = 1;
6791: }
6792: } else {
6793: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6794: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6795: $changes{'loginvia'}{$lonhost} = 1;
6796: }
6797: }
6798: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
6799: foreach my $item (@loginvia_attribs) {
6800: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
6801: }
6802: } else {
6803: foreach my $item (@loginvia_attribs) {
6804: my $new = $env{'form.'.$lonhost.'_'.$item};
6805: if (($item eq 'serverpath') && ($new eq 'custom')) {
6806: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
6807: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6808: $new = '/';
6809: }
6810: }
6811: if (($item eq 'custompath') &&
6812: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6813: $new = '';
6814: }
6815: if ($new ne $curr_loginvia{$lonhost}{$item}) {
6816: $changes{'loginvia'}{$lonhost} = 1;
6817: }
6818: if ($item eq 'exempt') {
1.256 raeburn 6819: $new = &check_exempt_addresses($new);
1.128 raeburn 6820: }
6821: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6822: }
6823: }
1.112 raeburn 6824: } else {
1.128 raeburn 6825: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6826: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 6827: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 6828: foreach my $item (@loginvia_attribs) {
6829: my $new = $env{'form.'.$lonhost.'_'.$item};
6830: if (($item eq 'serverpath') && ($new eq 'custom')) {
6831: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6832: $new = '/';
6833: }
6834: }
6835: if (($item eq 'custompath') &&
6836: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6837: $new = '';
6838: }
6839: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6840: }
1.110 raeburn 6841: }
6842: }
6843: }
6844: }
1.119 raeburn 6845:
1.168 raeburn 6846: my $servadm = $r->dir_config('lonAdmEMail');
6847: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
6848: if (ref($domconfig{'login'}) eq 'HASH') {
6849: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
6850: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
6851: if ($lang eq 'nolang') {
6852: push(@currlangs,$lang);
6853: } elsif (defined($langchoices{$lang})) {
6854: push(@currlangs,$lang);
6855: } else {
6856: next;
6857: }
6858: }
6859: }
6860: }
6861: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
6862: if (@currlangs > 0) {
6863: foreach my $lang (@currlangs) {
6864: if (grep(/^\Q$lang\E$/,@delurls)) {
6865: $changes{'helpurl'}{$lang} = 1;
6866: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
6867: $changes{'helpurl'}{$lang} = 1;
6868: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
6869: push(@newlangs,$lang);
6870: } else {
6871: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6872: }
6873: }
6874: }
6875: unless (grep(/^nolang$/,@currlangs)) {
6876: if ($env{'form.loginhelpurl_nolang.filename'}) {
6877: $changes{'helpurl'}{'nolang'} = 1;
6878: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
6879: push(@newlangs,'nolang');
6880: }
6881: }
6882: if ($env{'form.loginhelpurl_add_lang'}) {
6883: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
6884: ($env{'form.loginhelpurl_add_file.filename'})) {
6885: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
6886: $addedfile = $env{'form.loginhelpurl_add_lang'};
6887: }
6888: }
6889: if ((@newlangs > 0) || ($addedfile)) {
6890: my $error;
6891: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6892: if ($configuserok eq 'ok') {
6893: if ($switchserver) {
6894: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
6895: } elsif ($author_ok eq 'ok') {
6896: my @allnew = @newlangs;
6897: if ($addedfile ne '') {
6898: push(@allnew,$addedfile);
6899: }
6900: foreach my $lang (@allnew) {
6901: my $formelem = 'loginhelpurl_'.$lang;
6902: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
6903: $formelem = 'loginhelpurl_add_file';
6904: }
6905: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6906: "help/$lang",'','',$newfile{$lang});
6907: if ($result eq 'ok') {
6908: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
6909: $changes{'helpurl'}{$lang} = 1;
6910: } else {
6911: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
6912: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 6913: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 6914: (!grep(/^\Q$lang\E$/,@delurls))) {
6915: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6916: }
6917: }
6918: }
6919: } else {
6920: $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);
6921: }
6922: } else {
6923: $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);
6924: }
6925: if ($error) {
6926: &Apache::lonnet::logthis($error);
6927: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6928: }
6929: }
1.256 raeburn 6930:
6931: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
6932: if (ref($domconfig{'login'}) eq 'HASH') {
6933: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
6934: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
6935: if ($domservers{$lonhost}) {
6936: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6937: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 6938: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 6939: }
6940: }
6941: }
6942: }
6943: }
6944: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
6945: foreach my $lonhost (sort(keys(%domservers))) {
6946: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6947: $changes{'headtag'}{$lonhost} = 1;
6948: } else {
6949: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
6950: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
6951: }
6952: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
6953: push(@newhosts,$lonhost);
6954: } elsif ($currheadtagurls{$lonhost}) {
6955: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
6956: if ($currexempt{$lonhost}) {
6957: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
6958: $changes{'headtag'}{$lonhost} = 1;
6959: }
6960: } elsif ($possexempt{$lonhost}) {
6961: $changes{'headtag'}{$lonhost} = 1;
6962: }
6963: if ($possexempt{$lonhost}) {
6964: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6965: }
6966: }
6967: }
6968: }
6969: if (@newhosts) {
6970: my $error;
6971: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6972: if ($configuserok eq 'ok') {
6973: if ($switchserver) {
6974: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
6975: } elsif ($author_ok eq 'ok') {
6976: foreach my $lonhost (@newhosts) {
6977: my $formelem = 'loginheadtag_'.$lonhost;
6978: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6979: "login/headtag/$lonhost",'','',
6980: $env{'form.loginheadtag_'.$lonhost.'.filename'});
6981: if ($result eq 'ok') {
6982: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
6983: $changes{'headtag'}{$lonhost} = 1;
6984: if ($possexempt{$lonhost}) {
6985: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6986: }
6987: } else {
6988: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
6989: $newheadtagurls{$lonhost},$result);
6990: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6991: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
6992: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
6993: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
6994: }
6995: }
6996: }
6997: } else {
6998: $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);
6999: }
7000: } else {
7001: $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);
7002: }
7003: if ($error) {
7004: &Apache::lonnet::logthis($error);
7005: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7006: }
7007: }
1.169 raeburn 7008: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 7009:
7010: my $defaulthelpfile = '/adm/loginproblems.html';
7011: my $defaulttext = &mt('Default in use');
7012:
1.1 raeburn 7013: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
7014: $dom);
7015: if ($putresult eq 'ok') {
1.188 raeburn 7016: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7017: my %defaultchecked = (
7018: 'coursecatalog' => 'on',
1.188 raeburn 7019: 'helpdesk' => 'on',
1.42 raeburn 7020: 'adminmail' => 'off',
1.43 raeburn 7021: 'newuser' => 'off',
1.42 raeburn 7022: );
1.55 raeburn 7023: if (ref($domconfig{'login'}) eq 'HASH') {
7024: foreach my $item (@toggles) {
7025: if ($defaultchecked{$item} eq 'on') {
7026: if (($domconfig{'login'}{$item} eq '0') &&
7027: ($env{'form.'.$item} eq '1')) {
7028: $changes{$item} = 1;
7029: } elsif (($domconfig{'login'}{$item} eq '' ||
7030: $domconfig{'login'}{$item} eq '1') &&
7031: ($env{'form.'.$item} eq '0')) {
7032: $changes{$item} = 1;
7033: }
7034: } elsif ($defaultchecked{$item} eq 'off') {
7035: if (($domconfig{'login'}{$item} eq '1') &&
7036: ($env{'form.'.$item} eq '0')) {
7037: $changes{$item} = 1;
7038: } elsif (($domconfig{'login'}{$item} eq '' ||
7039: $domconfig{'login'}{$item} eq '0') &&
7040: ($env{'form.'.$item} eq '1')) {
7041: $changes{$item} = 1;
7042: }
1.42 raeburn 7043: }
7044: }
1.41 raeburn 7045: }
1.6 raeburn 7046: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 7047: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7048: if (ref($lastactref) eq 'HASH') {
7049: $lastactref->{'domainconfig'} = 1;
7050: }
1.1 raeburn 7051: $resulttext = &mt('Changes made:').'<ul>';
7052: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 7053: if ($item eq 'loginvia') {
1.112 raeburn 7054: if (ref($changes{$item}) eq 'HASH') {
7055: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
7056: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 7057: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
7058: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
7059: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
7060: $protocol = 'http' if ($protocol ne 'https');
7061: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
7062:
7063: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
7064: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
7065: } else {
7066: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
7067: }
7068: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
7069: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
7070: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
7071: }
7072: $resulttext .= '</li>';
7073: } else {
7074: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
7075: }
1.112 raeburn 7076: } else {
1.128 raeburn 7077: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 7078: }
7079: }
1.128 raeburn 7080: $resulttext .= '</ul></li>';
1.112 raeburn 7081: }
1.168 raeburn 7082: } elsif ($item eq 'helpurl') {
7083: if (ref($changes{$item}) eq 'HASH') {
7084: foreach my $lang (sort(keys(%{$changes{$item}}))) {
7085: if (grep(/^\Q$lang\E$/,@delurls)) {
7086: my ($chg,$link);
7087: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
7088: if ($lang eq 'nolang') {
7089: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
7090: } else {
7091: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
7092: }
7093: $resulttext .= '<li>'.$chg.'</li>';
7094: } else {
7095: my $chg;
7096: if ($lang eq 'nolang') {
7097: $chg = &mt('custom log-in help file for no preferred language');
7098: } else {
7099: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
7100: }
7101: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
7102: $loginhash{'login'}{'helpurl'}{$lang}.
7103: '?inhibitmenu=yes',$chg,600,500).
7104: '</li>';
7105: }
7106: }
7107: }
1.256 raeburn 7108: } elsif ($item eq 'headtag') {
7109: if (ref($changes{$item}) eq 'HASH') {
7110: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
7111: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7112: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
7113: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7114: $resulttext .= '<li><a href="'.
7115: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
7116: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
7117: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
7118: if ($possexempt{$lonhost}) {
7119: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
7120: } else {
7121: $resulttext .= &mt('included for any client IP');
7122: }
7123: $resulttext .= '</li>';
7124: }
7125: }
7126: }
1.169 raeburn 7127: } elsif ($item eq 'captcha') {
7128: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 7129: my $chgtxt;
1.169 raeburn 7130: if ($loginhash{'login'}{$item} eq 'notused') {
7131: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
7132: } else {
7133: my %captchas = &captcha_phrases();
7134: if ($captchas{$loginhash{'login'}{$item}}) {
7135: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
7136: } else {
7137: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
7138: }
7139: }
7140: $resulttext .= '<li>'.$chgtxt.'</li>';
7141: }
7142: } elsif ($item eq 'recaptchakeys') {
7143: if (ref($loginhash{'login'}) eq 'HASH') {
7144: my ($privkey,$pubkey);
7145: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
7146: $pubkey = $loginhash{'login'}{$item}{'public'};
7147: $privkey = $loginhash{'login'}{$item}{'private'};
7148: }
7149: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
7150: if (!$pubkey) {
7151: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
7152: } else {
7153: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7154: }
7155: if (!$privkey) {
7156: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
7157: } else {
1.251 raeburn 7158: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 7159: }
7160: $chgtxt .= '</ul>';
7161: $resulttext .= '<li>'.$chgtxt.'</li>';
7162: }
1.269 raeburn 7163: } elsif ($item eq 'recaptchaversion') {
7164: if (ref($loginhash{'login'}) eq 'HASH') {
7165: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 7166: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 7167: '</li>';
7168: }
7169: }
1.41 raeburn 7170: } else {
7171: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7172: }
1.1 raeburn 7173: }
1.6 raeburn 7174: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 7175: } else {
7176: $resulttext = &mt('No changes made to log-in page settings');
7177: }
7178: } else {
1.11 albertel 7179: $resulttext = '<span class="LC_error">'.
7180: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7181: }
1.6 raeburn 7182: if ($errors) {
1.9 raeburn 7183: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 7184: $errors.'</ul>';
7185: }
7186: return $resulttext;
7187: }
7188:
1.256 raeburn 7189:
7190: sub check_exempt_addresses {
7191: my ($iplist) = @_;
7192: $iplist =~ s/^\s+//;
7193: $iplist =~ s/\s+$//;
7194: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
7195: my (@okips,$new);
7196: foreach my $ip (@poss_ips) {
7197: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
7198: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
7199: push(@okips,$ip);
7200: }
7201: }
7202: }
7203: if (@okips > 0) {
7204: $new = join(',',@okips);
7205: } else {
7206: $new = '';
7207: }
7208: return $new;
7209: }
7210:
1.6 raeburn 7211: sub color_font_choices {
7212: my %choices =
7213: &Apache::lonlocal::texthash (
7214: img => "Header",
7215: bgs => "Background colors",
7216: links => "Link colors",
1.55 raeburn 7217: images => "Images",
1.6 raeburn 7218: font => "Font color",
1.201 raeburn 7219: fontmenu => "Font menu",
1.76 raeburn 7220: pgbg => "Page",
1.6 raeburn 7221: tabbg => "Header",
7222: sidebg => "Border",
7223: link => "Link",
7224: alink => "Active link",
7225: vlink => "Visited link",
7226: );
7227: return %choices;
7228: }
7229:
7230: sub modify_rolecolors {
1.205 raeburn 7231: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 7232: my ($resulttext,%rolehash);
7233: $rolehash{'rolecolors'} = {};
1.55 raeburn 7234: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
7235: if ($domconfig{'rolecolors'} eq '') {
7236: $domconfig{'rolecolors'} = {};
7237: }
7238: }
1.9 raeburn 7239: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 7240: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
7241: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
7242: $dom);
7243: if ($putresult eq 'ok') {
7244: if (keys(%changes) > 0) {
1.41 raeburn 7245: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7246: if (ref($lastactref) eq 'HASH') {
7247: $lastactref->{'domainconfig'} = 1;
7248: }
1.6 raeburn 7249: $resulttext = &display_colorchgs($dom,\%changes,$roles,
7250: $rolehash{'rolecolors'});
7251: } else {
7252: $resulttext = &mt('No changes made to default color schemes');
7253: }
7254: } else {
1.11 albertel 7255: $resulttext = '<span class="LC_error">'.
7256: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 7257: }
7258: if ($errors) {
7259: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7260: $errors.'</ul>';
7261: }
7262: return $resulttext;
7263: }
7264:
7265: sub modify_colors {
1.9 raeburn 7266: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 7267: my (%changes,%choices);
1.51 raeburn 7268: my @bgs;
1.6 raeburn 7269: my @links = ('link','alink','vlink');
1.41 raeburn 7270: my @logintext;
1.6 raeburn 7271: my @images;
7272: my $servadm = $r->dir_config('lonAdmEMail');
7273: my $errors;
1.200 raeburn 7274: my %defaults;
1.6 raeburn 7275: foreach my $role (@{$roles}) {
7276: if ($role eq 'login') {
1.12 raeburn 7277: %choices = &login_choices();
1.41 raeburn 7278: @logintext = ('textcol','bgcol');
1.12 raeburn 7279: } else {
7280: %choices = &color_font_choices();
7281: }
7282: if ($role eq 'login') {
1.41 raeburn 7283: @images = ('img','logo','domlogo','login');
1.51 raeburn 7284: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 7285: } else {
7286: @images = ('img');
1.200 raeburn 7287: @bgs = ('pgbg','tabbg','sidebg');
7288: }
7289: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
7290: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
7291: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
7292: }
7293: if ($role eq 'login') {
7294: foreach my $item (@logintext) {
1.234 raeburn 7295: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7296: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7297: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7298: }
7299: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 7300: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7301: }
7302: }
7303: } else {
1.234 raeburn 7304: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
7305: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
7306: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
7307: }
7308: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 7309: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
7310: }
1.6 raeburn 7311: }
1.200 raeburn 7312: foreach my $item (@bgs) {
1.234 raeburn 7313: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7314: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7315: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7316: }
7317: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 7318: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7319: }
7320: }
7321: foreach my $item (@links) {
1.234 raeburn 7322: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7323: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7324: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7325: }
7326: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 7327: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7328: }
1.6 raeburn 7329: }
1.46 raeburn 7330: my ($configuserok,$author_ok,$switchserver) =
7331: &config_check($dom,$confname,$servadm);
1.9 raeburn 7332: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 7333: if (ref($domconfig->{$role}) ne 'HASH') {
7334: $domconfig->{$role} = {};
7335: }
1.8 raeburn 7336: foreach my $img (@images) {
1.70 raeburn 7337: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
7338: if (defined($env{'form.login_showlogo_'.$img})) {
7339: $confhash->{$role}{'showlogo'}{$img} = 1;
7340: } else {
7341: $confhash->{$role}{'showlogo'}{$img} = 0;
7342: }
7343: }
1.18 albertel 7344: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
7345: && !defined($domconfig->{$role}{$img})
7346: && !$env{'form.'.$role.'_del_'.$img}
7347: && $env{'form.'.$role.'_import_'.$img}) {
7348: # import the old configured image from the .tab setting
7349: # if they haven't provided a new one
7350: $domconfig->{$role}{$img} =
7351: $env{'form.'.$role.'_import_'.$img};
7352: }
1.6 raeburn 7353: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 7354: my $error;
1.6 raeburn 7355: if ($configuserok eq 'ok') {
1.9 raeburn 7356: if ($switchserver) {
1.12 raeburn 7357: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 7358: } else {
7359: if ($author_ok eq 'ok') {
7360: my ($result,$logourl) =
7361: &publishlogo($r,'upload',$role.'_'.$img,
7362: $dom,$confname,$img,$width,$height);
7363: if ($result eq 'ok') {
7364: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 7365: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7366: } else {
1.12 raeburn 7367: $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 7368: }
7369: } else {
1.46 raeburn 7370: $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 7371: }
7372: }
7373: } else {
1.46 raeburn 7374: $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 7375: }
7376: if ($error) {
1.8 raeburn 7377: &Apache::lonnet::logthis($error);
1.11 albertel 7378: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 7379: }
7380: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 7381: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
7382: my $error;
7383: if ($configuserok eq 'ok') {
7384: # is confname an author?
7385: if ($switchserver eq '') {
7386: if ($author_ok eq 'ok') {
7387: my ($result,$logourl) =
7388: &publishlogo($r,'copy',$domconfig->{$role}{$img},
7389: $dom,$confname,$img,$width,$height);
7390: if ($result eq 'ok') {
7391: $confhash->{$role}{$img} = $logourl;
1.18 albertel 7392: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7393: }
7394: }
7395: }
7396: }
1.6 raeburn 7397: }
7398: }
7399: }
7400: if (ref($domconfig) eq 'HASH') {
7401: if (ref($domconfig->{$role}) eq 'HASH') {
7402: foreach my $img (@images) {
7403: if ($domconfig->{$role}{$img} ne '') {
7404: if ($env{'form.'.$role.'_del_'.$img}) {
7405: $confhash->{$role}{$img} = '';
1.12 raeburn 7406: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7407: } else {
1.9 raeburn 7408: if ($confhash->{$role}{$img} eq '') {
7409: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
7410: }
1.6 raeburn 7411: }
7412: } else {
7413: if ($env{'form.'.$role.'_del_'.$img}) {
7414: $confhash->{$role}{$img} = '';
1.12 raeburn 7415: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7416: }
7417: }
1.70 raeburn 7418: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
7419: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
7420: if ($confhash->{$role}{'showlogo'}{$img} ne
7421: $domconfig->{$role}{'showlogo'}{$img}) {
7422: $changes{$role}{'showlogo'}{$img} = 1;
7423: }
7424: } else {
7425: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7426: $changes{$role}{'showlogo'}{$img} = 1;
7427: }
7428: }
7429: }
7430: }
1.6 raeburn 7431: if ($domconfig->{$role}{'font'} ne '') {
7432: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
7433: $changes{$role}{'font'} = 1;
7434: }
7435: } else {
7436: if ($confhash->{$role}{'font'}) {
7437: $changes{$role}{'font'} = 1;
7438: }
7439: }
1.107 raeburn 7440: if ($role ne 'login') {
7441: if ($domconfig->{$role}{'fontmenu'} ne '') {
7442: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
7443: $changes{$role}{'fontmenu'} = 1;
7444: }
7445: } else {
7446: if ($confhash->{$role}{'fontmenu'}) {
7447: $changes{$role}{'fontmenu'} = 1;
7448: }
1.97 tempelho 7449: }
7450: }
1.6 raeburn 7451: foreach my $item (@bgs) {
7452: if ($domconfig->{$role}{$item} ne '') {
7453: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7454: $changes{$role}{'bgs'}{$item} = 1;
7455: }
7456: } else {
7457: if ($confhash->{$role}{$item}) {
7458: $changes{$role}{'bgs'}{$item} = 1;
7459: }
7460: }
7461: }
7462: foreach my $item (@links) {
7463: if ($domconfig->{$role}{$item} ne '') {
7464: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7465: $changes{$role}{'links'}{$item} = 1;
7466: }
7467: } else {
7468: if ($confhash->{$role}{$item}) {
7469: $changes{$role}{'links'}{$item} = 1;
7470: }
7471: }
7472: }
1.41 raeburn 7473: foreach my $item (@logintext) {
7474: if ($domconfig->{$role}{$item} ne '') {
7475: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7476: $changes{$role}{'logintext'}{$item} = 1;
7477: }
7478: } else {
7479: if ($confhash->{$role}{$item}) {
7480: $changes{$role}{'logintext'}{$item} = 1;
7481: }
7482: }
7483: }
1.6 raeburn 7484: } else {
7485: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7486: \@logintext,$confhash,\%changes);
1.6 raeburn 7487: }
7488: } else {
7489: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7490: \@logintext,$confhash,\%changes);
1.6 raeburn 7491: }
7492: }
7493: return ($errors,%changes);
7494: }
7495:
1.46 raeburn 7496: sub config_check {
7497: my ($dom,$confname,$servadm) = @_;
7498: my ($configuserok,$author_ok,$switchserver,%currroles);
7499: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
7500: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
7501: $confname,$servadm);
7502: if ($configuserok eq 'ok') {
7503: $switchserver = &check_switchserver($dom,$confname);
7504: if ($switchserver eq '') {
7505: $author_ok = &check_authorstatus($dom,$confname,%currroles);
7506: }
7507: }
7508: return ($configuserok,$author_ok,$switchserver);
7509: }
7510:
1.6 raeburn 7511: sub default_change_checker {
1.41 raeburn 7512: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 7513: foreach my $item (@{$links}) {
7514: if ($confhash->{$role}{$item}) {
7515: $changes->{$role}{'links'}{$item} = 1;
7516: }
7517: }
7518: foreach my $item (@{$bgs}) {
7519: if ($confhash->{$role}{$item}) {
7520: $changes->{$role}{'bgs'}{$item} = 1;
7521: }
7522: }
1.41 raeburn 7523: foreach my $item (@{$logintext}) {
7524: if ($confhash->{$role}{$item}) {
7525: $changes->{$role}{'logintext'}{$item} = 1;
7526: }
7527: }
1.6 raeburn 7528: foreach my $img (@{$images}) {
7529: if ($env{'form.'.$role.'_del_'.$img}) {
7530: $confhash->{$role}{$img} = '';
1.12 raeburn 7531: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 7532: }
1.70 raeburn 7533: if ($role eq 'login') {
7534: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7535: $changes->{$role}{'showlogo'}{$img} = 1;
7536: }
7537: }
1.6 raeburn 7538: }
7539: if ($confhash->{$role}{'font'}) {
7540: $changes->{$role}{'font'} = 1;
7541: }
1.48 raeburn 7542: }
1.6 raeburn 7543:
7544: sub display_colorchgs {
7545: my ($dom,$changes,$roles,$confhash) = @_;
7546: my (%choices,$resulttext);
7547: if (!grep(/^login$/,@{$roles})) {
7548: $resulttext = &mt('Changes made:').'<br />';
7549: }
7550: foreach my $role (@{$roles}) {
7551: if ($role eq 'login') {
7552: %choices = &login_choices();
7553: } else {
7554: %choices = &color_font_choices();
7555: }
7556: if (ref($changes->{$role}) eq 'HASH') {
7557: if ($role ne 'login') {
7558: $resulttext .= '<h4>'.&mt($role).'</h4>';
7559: }
7560: foreach my $key (sort(keys(%{$changes->{$role}}))) {
7561: if ($role ne 'login') {
7562: $resulttext .= '<ul>';
7563: }
7564: if (ref($changes->{$role}{$key}) eq 'HASH') {
7565: if ($role ne 'login') {
7566: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
7567: }
7568: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 7569: if (($role eq 'login') && ($key eq 'showlogo')) {
7570: if ($confhash->{$role}{$key}{$item}) {
7571: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
7572: } else {
7573: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
7574: }
7575: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 7576: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
7577: } else {
1.12 raeburn 7578: my $newitem = $confhash->{$role}{$item};
7579: if ($key eq 'images') {
7580: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
7581: }
7582: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 7583: }
7584: }
7585: if ($role ne 'login') {
7586: $resulttext .= '</ul></li>';
7587: }
7588: } else {
7589: if ($confhash->{$role}{$key} eq '') {
7590: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
7591: } else {
7592: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
7593: }
7594: }
7595: if ($role ne 'login') {
7596: $resulttext .= '</ul>';
7597: }
7598: }
7599: }
7600: }
1.3 raeburn 7601: return $resulttext;
1.1 raeburn 7602: }
7603:
1.9 raeburn 7604: sub thumb_dimensions {
7605: return ('200','50');
7606: }
7607:
1.16 raeburn 7608: sub check_dimensions {
7609: my ($inputfile) = @_;
7610: my ($fullwidth,$fullheight);
7611: if ($inputfile =~ m|^[/\w.\-]+$|) {
7612: if (open(PIPE,"identify $inputfile 2>&1 |")) {
7613: my $imageinfo = <PIPE>;
7614: if (!close(PIPE)) {
7615: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
7616: }
7617: chomp($imageinfo);
7618: my ($fullsize) =
1.21 raeburn 7619: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 7620: if ($fullsize) {
7621: ($fullwidth,$fullheight) = split(/x/,$fullsize);
7622: }
7623: }
7624: }
7625: return ($fullwidth,$fullheight);
7626: }
7627:
1.9 raeburn 7628: sub check_configuser {
7629: my ($uhome,$dom,$confname,$servadm) = @_;
7630: my ($configuserok,%currroles);
7631: if ($uhome eq 'no_host') {
7632: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
7633: my $configpass = &LONCAPA::Enrollment::create_password();
7634: $configuserok =
7635: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
7636: $configpass,'','','','','',undef,$servadm);
7637: } else {
7638: $configuserok = 'ok';
7639: %currroles =
7640: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
7641: }
7642: return ($configuserok,%currroles);
7643: }
7644:
7645: sub check_authorstatus {
7646: my ($dom,$confname,%currroles) = @_;
7647: my $author_ok;
1.40 raeburn 7648: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 7649: my $start = time;
7650: my $end = 0;
7651: $author_ok =
7652: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 7653: 'au',$end,$start,'','','domconfig');
1.9 raeburn 7654: } else {
7655: $author_ok = 'ok';
7656: }
7657: return $author_ok;
7658: }
7659:
7660: sub publishlogo {
1.46 raeburn 7661: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 7662: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 7663: if ($action eq 'upload') {
7664: $fname=$env{'form.'.$formname.'.filename'};
7665: chop($env{'form.'.$formname});
7666: } else {
7667: ($fname) = ($formname =~ /([^\/]+)$/);
7668: }
1.46 raeburn 7669: if ($savefileas ne '') {
7670: $fname = $savefileas;
7671: }
1.9 raeburn 7672: $fname=&Apache::lonnet::clean_filename($fname);
7673: # See if there is anything left
7674: unless ($fname) { return ('error: no uploaded file'); }
7675: $fname="$subdir/$fname";
1.210 raeburn 7676: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 7677: my $filepath="$docroot/priv";
7678: my $relpath = "$dom/$confname";
1.9 raeburn 7679: my ($fnamepath,$file,$fetchthumb);
7680: $file=$fname;
7681: if ($fname=~m|/|) {
7682: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
7683: }
1.164 raeburn 7684: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 7685: my $count;
1.164 raeburn 7686: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 7687: $filepath.="/$parts[$count]";
7688: if ((-e $filepath)!=1) {
7689: mkdir($filepath,02770);
7690: }
7691: }
7692: # Check for bad extension and disallow upload
7693: if ($file=~/\.(\w+)$/ &&
7694: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7695: $output =
1.207 bisitz 7696: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 7697: } elsif ($file=~/\.(\w+)$/ &&
7698: !defined(&Apache::loncommon::fileembstyle($1))) {
7699: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7700: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 7701: $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 7702: } elsif (-d "$filepath/$file") {
1.195 bisitz 7703: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 7704: } else {
7705: my $source = $filepath.'/'.$file;
7706: my $logfile;
7707: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 7708: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 7709: }
7710: print $logfile
7711: "\n================= Publish ".localtime()." ================\n".
7712: $env{'user.name'}.':'.$env{'user.domain'}."\n";
7713: # Save the file
7714: if (!open(FH,'>'.$source)) {
7715: &Apache::lonnet::logthis('Failed to create '.$source);
7716: return (&mt('Failed to create file'));
7717: }
7718: if ($action eq 'upload') {
7719: if (!print FH ($env{'form.'.$formname})) {
7720: &Apache::lonnet::logthis('Failed to write to '.$source);
7721: return (&mt('Failed to write file'));
7722: }
7723: } else {
7724: my $original = &Apache::lonnet::filelocation('',$formname);
7725: if(!copy($original,$source)) {
7726: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
7727: return (&mt('Failed to write file'));
7728: }
7729: }
7730: close(FH);
7731: chmod(0660, $source); # Permissions to rw-rw---.
7732:
7733: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
7734: my $copyfile=$targetdir.'/'.$file;
7735:
7736: my @parts=split(/\//,$targetdir);
7737: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
7738: for (my $count=5;$count<=$#parts;$count++) {
7739: $path.="/$parts[$count]";
7740: if (!-e $path) {
7741: print $logfile "\nCreating directory ".$path;
7742: mkdir($path,02770);
7743: }
7744: }
7745: my $versionresult;
7746: if (-e $copyfile) {
7747: $versionresult = &logo_versioning($targetdir,$file,$logfile);
7748: } else {
7749: $versionresult = 'ok';
7750: }
7751: if ($versionresult eq 'ok') {
7752: if (copy($source,$copyfile)) {
7753: print $logfile "\nCopied original source to ".$copyfile."\n";
7754: $output = 'ok';
7755: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 7756: push(@{$modified_urls},[$copyfile,$source]);
7757: my $metaoutput =
7758: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
7759: unless ($registered_cleanup) {
7760: my $handlers = $r->get_handlers('PerlCleanupHandler');
7761: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7762: $registered_cleanup=1;
7763: }
1.9 raeburn 7764: } else {
7765: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
7766: $output = &mt('Failed to copy file to RES space').", $!";
7767: }
7768: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
7769: my $inputfile = $filepath.'/'.$file;
7770: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 7771: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
7772: if ($fullwidth ne '' && $fullheight ne '') {
7773: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
7774: my $thumbsize = $thumbwidth.'x'.$thumbheight;
7775: system("convert -sample $thumbsize $inputfile $outfile");
7776: chmod(0660, $filepath.'/tn-'.$file);
7777: if (-e $outfile) {
7778: my $copyfile=$targetdir.'/tn-'.$file;
7779: if (copy($outfile,$copyfile)) {
7780: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 7781: my $thumb_metaoutput =
7782: &write_metadata($dom,$confname,$formname,
7783: $targetdir,'tn-'.$file,$logfile);
7784: push(@{$modified_urls},[$copyfile,$outfile]);
7785: unless ($registered_cleanup) {
7786: my $handlers = $r->get_handlers('PerlCleanupHandler');
7787: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7788: $registered_cleanup=1;
7789: }
1.267 raeburn 7790: $madethumb = 1;
1.16 raeburn 7791: } else {
7792: print $logfile "\nUnable to write ".$copyfile.
7793: ':'.$!."\n";
7794: }
7795: }
1.9 raeburn 7796: }
7797: }
7798: }
7799: } else {
7800: $output = $versionresult;
7801: }
7802: }
1.267 raeburn 7803: return ($output,$logourl,$madethumb);
1.9 raeburn 7804: }
7805:
7806: sub logo_versioning {
7807: my ($targetdir,$file,$logfile) = @_;
7808: my $target = $targetdir.'/'.$file;
7809: my ($maxversion,$fn,$extn,$output);
7810: $maxversion = 0;
7811: if ($file =~ /^(.+)\.(\w+)$/) {
7812: $fn=$1;
7813: $extn=$2;
7814: }
7815: opendir(DIR,$targetdir);
7816: while (my $filename=readdir(DIR)) {
7817: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
7818: $maxversion=($1>$maxversion)?$1:$maxversion;
7819: }
7820: }
7821: $maxversion++;
7822: print $logfile "\nCreating old version ".$maxversion."\n";
7823: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
7824: if (copy($target,$copyfile)) {
7825: print $logfile "Copied old target to ".$copyfile."\n";
7826: $copyfile=$copyfile.'.meta';
7827: if (copy($target.'.meta',$copyfile)) {
7828: print $logfile "Copied old target metadata to ".$copyfile."\n";
7829: $output = 'ok';
7830: } else {
7831: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
7832: $output = &mt('Failed to copy old meta').", $!, ";
7833: }
7834: } else {
7835: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
7836: $output = &mt('Failed to copy old target').", $!, ";
7837: }
7838: return $output;
7839: }
7840:
7841: sub write_metadata {
7842: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
7843: my (%metadatafields,%metadatakeys,$output);
7844: $metadatafields{'title'}=$formname;
7845: $metadatafields{'creationdate'}=time;
7846: $metadatafields{'lastrevisiondate'}=time;
7847: $metadatafields{'copyright'}='public';
7848: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
7849: $env{'user.domain'};
7850: $metadatafields{'authorspace'}=$confname.':'.$dom;
7851: $metadatafields{'domain'}=$dom;
7852: {
7853: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
7854: my $mfh;
1.155 raeburn 7855: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 7856: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 7857: unless ($_=~/\./) {
7858: my $unikey=$_;
7859: $unikey=~/^([A-Za-z]+)/;
7860: my $tag=$1;
7861: $tag=~tr/A-Z/a-z/;
7862: print $mfh "\n\<$tag";
7863: foreach (split(/\,/,$metadatakeys{$unikey})) {
7864: my $value=$metadatafields{$unikey.'.'.$_};
7865: $value=~s/\"/\'\'/g;
7866: print $mfh ' '.$_.'="'.$value.'"';
7867: }
7868: print $mfh '>'.
7869: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
7870: .'</'.$tag.'>';
7871: }
7872: }
7873: $output = 'ok';
7874: print $logfile "\nWrote metadata";
7875: close($mfh);
7876: } else {
7877: print $logfile "\nFailed to open metadata file";
1.9 raeburn 7878: $output = &mt('Could not write metadata');
7879: }
7880: }
1.155 raeburn 7881: return $output;
7882: }
7883:
7884: sub notifysubscribed {
7885: foreach my $targetsource (@{$modified_urls}){
7886: next unless (ref($targetsource) eq 'ARRAY');
7887: my ($target,$source)=@{$targetsource};
7888: if ($source ne '') {
7889: if (open(my $logfh,'>>'.$source.'.log')) {
7890: print $logfh "\nCleanup phase: Notifications\n";
7891: my @subscribed=&subscribed_hosts($target);
7892: foreach my $subhost (@subscribed) {
7893: print $logfh "\nNotifying host ".$subhost.':';
7894: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
7895: print $logfh $reply;
7896: }
7897: my @subscribedmeta=&subscribed_hosts("$target.meta");
7898: foreach my $subhost (@subscribedmeta) {
7899: print $logfh "\nNotifying host for metadata only ".$subhost.':';
7900: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
7901: $subhost);
7902: print $logfh $reply;
7903: }
7904: print $logfh "\n============ Done ============\n";
1.160 raeburn 7905: close($logfh);
1.155 raeburn 7906: }
7907: }
7908: }
7909: return OK;
7910: }
7911:
7912: sub subscribed_hosts {
7913: my ($target) = @_;
7914: my @subscribed;
7915: if (open(my $fh,"<$target.subscription")) {
7916: while (my $subline=<$fh>) {
7917: if ($subline =~ /^($match_lonid):/) {
7918: my $host = $1;
7919: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
7920: unless (grep(/^\Q$host\E$/,@subscribed)) {
7921: push(@subscribed,$host);
7922: }
7923: }
7924: }
7925: }
7926: }
7927: return @subscribed;
1.9 raeburn 7928: }
7929:
7930: sub check_switchserver {
7931: my ($dom,$confname) = @_;
7932: my ($allowed,$switchserver);
7933: my $home = &Apache::lonnet::homeserver($confname,$dom);
7934: if ($home eq 'no_host') {
7935: $home = &Apache::lonnet::domain($dom,'primary');
7936: }
7937: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 7938: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7939: if (!$allowed) {
1.180 raeburn 7940: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 7941: }
7942: return $switchserver;
7943: }
7944:
1.1 raeburn 7945: sub modify_quotas {
1.216 raeburn 7946: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 7947: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 7948: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 7949: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
7950: $validationfieldsref);
1.86 raeburn 7951: if ($action eq 'quotas') {
7952: $context = 'tools';
1.163 raeburn 7953: } else {
1.86 raeburn 7954: $context = $action;
7955: }
7956: if ($context eq 'requestcourses') {
1.271 raeburn 7957: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 7958: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 7959: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
7960: %titles = &courserequest_titles();
7961: $toolregexp = join('|',@usertools);
7962: %conditions = &courserequest_conditions();
1.216 raeburn 7963: $confname = $dom.'-domainconfig';
7964: my $servadm = $r->dir_config('lonAdmEMail');
7965: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 7966: ($validationitemsref,$validationnamesref,$validationfieldsref) =
7967: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 7968: } elsif ($context eq 'requestauthor') {
7969: @usertools = ('author');
7970: %titles = &authorrequest_titles();
1.86 raeburn 7971: } else {
1.162 raeburn 7972: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 7973: %titles = &tool_titles();
1.86 raeburn 7974: }
1.212 raeburn 7975: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 7976: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7977: foreach my $key (keys(%env)) {
1.101 raeburn 7978: if ($context eq 'requestcourses') {
7979: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
7980: my $item = $1;
7981: my $type = $2;
7982: if ($type =~ /^limit_(.+)/) {
7983: $limithash{$item}{$1} = $env{$key};
7984: } else {
7985: $confhash{$item}{$type} = $env{$key};
7986: }
7987: }
1.163 raeburn 7988: } elsif ($context eq 'requestauthor') {
7989: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
7990: $confhash{$1} = $env{$key};
7991: }
1.101 raeburn 7992: } else {
1.86 raeburn 7993: if ($key =~ /^form\.quota_(.+)$/) {
7994: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 7995: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
7996: $confhash{'authorquota'}{$1} = $env{$key};
7997: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 7998: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
7999: }
1.72 raeburn 8000: }
8001: }
1.163 raeburn 8002: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 8003: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 8004: @approvalnotify = sort(@approvalnotify);
8005: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.271 raeburn 8006: my @crstypes = ('official','unofficial','community','textbook','placement');
1.218 raeburn 8007: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
8008: foreach my $type (@hasuniquecode) {
8009: if (grep(/^\Q$type\E$/,@crstypes)) {
8010: $confhash{'uniquecode'}{$type} = 1;
8011: }
1.216 raeburn 8012: }
1.242 raeburn 8013: my (%newbook,%allpos);
1.216 raeburn 8014: if ($context eq 'requestcourses') {
1.242 raeburn 8015: foreach my $type ('textbooks','templates') {
8016: @{$allpos{$type}} = ();
8017: my $invalid;
8018: if ($type eq 'textbooks') {
8019: $invalid = &mt('Invalid LON-CAPA course for textbook');
8020: } else {
8021: $invalid = &mt('Invalid LON-CAPA course for template');
8022: }
8023: if ($env{'form.'.$type.'_addbook'}) {
8024: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
8025: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
8026: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
8027: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
8028: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
8029: } else {
8030: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
8031: my $position = $env{'form.'.$type.'_addbook_pos'};
8032: $position =~ s/\D+//g;
8033: if ($position ne '') {
8034: $allpos{$type}[$position] = $newbook{$type};
8035: }
1.216 raeburn 8036: }
1.242 raeburn 8037: } else {
8038: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 8039: }
8040: }
1.242 raeburn 8041: }
1.216 raeburn 8042: }
1.102 raeburn 8043: if (ref($domconfig{$action}) eq 'HASH') {
8044: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
8045: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
8046: $changes{'notify'}{'approval'} = 1;
8047: }
8048: } else {
1.144 raeburn 8049: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8050: $changes{'notify'}{'approval'} = 1;
8051: }
8052: }
1.218 raeburn 8053: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
8054: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8055: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
8056: unless ($confhash{'uniquecode'}{$crstype}) {
8057: $changes{'uniquecode'} = 1;
8058: }
8059: }
8060: unless ($changes{'uniquecode'}) {
8061: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
8062: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
8063: $changes{'uniquecode'} = 1;
8064: }
8065: }
8066: }
8067: } else {
8068: $changes{'uniquecode'} = 1;
8069: }
8070: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
8071: $changes{'uniquecode'} = 1;
1.216 raeburn 8072: }
8073: if ($context eq 'requestcourses') {
1.242 raeburn 8074: foreach my $type ('textbooks','templates') {
8075: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8076: my %deletions;
8077: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
8078: if (@todelete) {
8079: map { $deletions{$_} = 1; } @todelete;
8080: }
8081: my %imgdeletions;
8082: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
8083: if (@todeleteimages) {
8084: map { $imgdeletions{$_} = 1; } @todeleteimages;
8085: }
8086: my $maxnum = $env{'form.'.$type.'_maxnum'};
8087: for (my $i=0; $i<=$maxnum; $i++) {
8088: my $itemid = $env{'form.'.$type.'_id_'.$i};
8089: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
8090: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
8091: if ($deletions{$key}) {
8092: if ($domconfig{$action}{$type}{$key}{'image'}) {
8093: #FIXME need to obsolete item in RES space
8094: }
8095: next;
8096: } else {
8097: my $newpos = $env{'form.'.$itemid};
8098: $newpos =~ s/\D+//g;
1.243 raeburn 8099: foreach my $item ('subject','title','publisher','author') {
8100: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8101: ($type eq 'templates'));
1.242 raeburn 8102: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
8103: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
8104: $changes{$type}{$key} = 1;
8105: }
8106: }
8107: $allpos{$type}[$newpos] = $key;
8108: }
8109: if ($imgdeletions{$key}) {
8110: $changes{$type}{$key} = 1;
1.216 raeburn 8111: #FIXME need to obsolete item in RES space
1.242 raeburn 8112: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
8113: my ($cdom,$cnum) = split(/_/,$key);
8114: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
8115: $cdom,$cnum,$type,$configuserok,
8116: $switchserver,$author_ok);
8117: if ($imgurl) {
8118: $confhash{$type}{$key}{'image'} = $imgurl;
8119: $changes{$type}{$key} = 1;
1.216 raeburn 8120: }
1.242 raeburn 8121: if ($error) {
8122: &Apache::lonnet::logthis($error);
8123: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8124: }
8125: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
8126: $confhash{$type}{$key}{'image'} =
8127: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 8128: }
8129: }
8130: }
8131: }
8132: }
8133: }
1.102 raeburn 8134: } else {
1.144 raeburn 8135: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8136: $changes{'notify'}{'approval'} = 1;
8137: }
1.218 raeburn 8138: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 8139: $changes{'uniquecode'} = 1;
8140: }
8141: }
8142: if ($context eq 'requestcourses') {
1.242 raeburn 8143: foreach my $type ('textbooks','templates') {
8144: if ($newbook{$type}) {
8145: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 8146: foreach my $item ('subject','title','publisher','author') {
8147: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8148: ($type eq 'template'));
1.242 raeburn 8149: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
8150: if ($env{'form.'.$type.'_addbook_'.$item}) {
8151: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
8152: }
8153: }
8154: if ($type eq 'textbooks') {
8155: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
8156: my ($cdom,$cnum) = split(/_/,$newbook{$type});
8157: my ($imageurl,$error) =
8158: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
8159: $configuserok,$switchserver,$author_ok);
8160: if ($imageurl) {
8161: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
8162: }
8163: if ($error) {
8164: &Apache::lonnet::logthis($error);
8165: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8166: }
8167: }
1.216 raeburn 8168: }
8169: }
1.242 raeburn 8170: if (@{$allpos{$type}} > 0) {
8171: my $idx = 0;
8172: foreach my $item (@{$allpos{$type}}) {
8173: if ($item ne '') {
8174: $confhash{$type}{$item}{'order'} = $idx;
8175: if (ref($domconfig{$action}) eq 'HASH') {
8176: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8177: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
8178: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
8179: $changes{$type}{$item} = 1;
8180: }
1.216 raeburn 8181: }
8182: }
8183: }
1.242 raeburn 8184: $idx ++;
1.216 raeburn 8185: }
8186: }
8187: }
8188: }
1.235 raeburn 8189: if (ref($validationitemsref) eq 'ARRAY') {
8190: foreach my $item (@{$validationitemsref}) {
8191: if ($item eq 'fields') {
8192: my @changed;
8193: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
8194: if (@{$confhash{'validation'}{$item}} > 0) {
8195: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
8196: }
1.266 raeburn 8197: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8198: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8199: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
8200: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
8201: $domconfig{'requestcourses'}{'validation'}{$item});
8202: } else {
8203: @changed = @{$confhash{'validation'}{$item}};
8204: }
1.235 raeburn 8205: } else {
8206: @changed = @{$confhash{'validation'}{$item}};
8207: }
8208: } else {
8209: @changed = @{$confhash{'validation'}{$item}};
8210: }
8211: if (@changed) {
8212: if ($confhash{'validation'}{$item}) {
8213: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
8214: } else {
8215: $changes{'validation'}{$item} = &mt('None');
8216: }
8217: }
8218: } else {
8219: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
8220: if ($item eq 'markup') {
8221: if ($env{'form.requestcourses_validation_'.$item}) {
8222: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
8223: }
8224: }
1.266 raeburn 8225: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8226: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8227: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
8228: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8229: }
8230: } else {
8231: if ($confhash{'validation'}{$item} ne '') {
8232: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8233: }
1.235 raeburn 8234: }
8235: } else {
8236: if ($confhash{'validation'}{$item} ne '') {
8237: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8238: }
8239: }
8240: }
8241: }
8242: }
8243: if ($env{'form.validationdc'}) {
8244: my $newval = $env{'form.validationdc'};
8245: my %domcoords = &get_active_dcs($dom);
8246: if (exists($domcoords{$newval})) {
8247: $confhash{'validation'}{'dc'} = $newval;
8248: }
8249: }
8250: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 8251: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8252: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8253: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8254: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
8255: if ($confhash{'validation'}{'dc'} eq '') {
8256: $changes{'validation'}{'dc'} = &mt('None');
8257: } else {
8258: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8259: }
1.235 raeburn 8260: }
1.266 raeburn 8261: } elsif ($confhash{'validation'}{'dc'} ne '') {
8262: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 8263: }
8264: } elsif ($confhash{'validation'}{'dc'} ne '') {
8265: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8266: }
8267: } elsif ($confhash{'validation'}{'dc'} ne '') {
8268: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.266 raeburn 8269: }
8270: } else {
8271: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8272: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8273: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8274: $changes{'validation'}{'dc'} = &mt('None');
8275: }
8276: }
1.235 raeburn 8277: }
8278: }
1.102 raeburn 8279: }
8280: } else {
1.86 raeburn 8281: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 8282: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 8283: }
1.72 raeburn 8284: foreach my $item (@usertools) {
8285: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 8286: my $unset;
1.101 raeburn 8287: if ($context eq 'requestcourses') {
1.104 raeburn 8288: $unset = '0';
8289: if ($type eq '_LC_adv') {
8290: $unset = '';
8291: }
1.101 raeburn 8292: if ($confhash{$item}{$type} eq 'autolimit') {
8293: $confhash{$item}{$type} .= '=';
8294: unless ($limithash{$item}{$type} =~ /\D/) {
8295: $confhash{$item}{$type} .= $limithash{$item}{$type};
8296: }
8297: }
1.163 raeburn 8298: } elsif ($context eq 'requestauthor') {
8299: $unset = '0';
8300: if ($type eq '_LC_adv') {
8301: $unset = '';
8302: }
1.72 raeburn 8303: } else {
1.101 raeburn 8304: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
8305: $confhash{$item}{$type} = 1;
8306: } else {
8307: $confhash{$item}{$type} = 0;
8308: }
1.72 raeburn 8309: }
1.86 raeburn 8310: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 8311: if ($action eq 'requestauthor') {
8312: if ($domconfig{$action}{$type} ne $confhash{$type}) {
8313: $changes{$type} = 1;
8314: }
8315: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 8316: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
8317: $changes{$item}{$type} = 1;
8318: }
8319: } else {
8320: if ($context eq 'requestcourses') {
1.104 raeburn 8321: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 8322: $changes{$item}{$type} = 1;
8323: }
8324: } else {
8325: if (!$confhash{$item}{$type}) {
8326: $changes{$item}{$type} = 1;
8327: }
8328: }
8329: }
8330: } else {
8331: if ($context eq 'requestcourses') {
1.104 raeburn 8332: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 8333: $changes{$item}{$type} = 1;
8334: }
1.163 raeburn 8335: } elsif ($context eq 'requestauthor') {
8336: if ($confhash{$type} ne $unset) {
8337: $changes{$type} = 1;
8338: }
1.72 raeburn 8339: } else {
8340: if (!$confhash{$item}{$type}) {
8341: $changes{$item}{$type} = 1;
8342: }
8343: }
8344: }
1.1 raeburn 8345: }
8346: }
1.163 raeburn 8347: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 8348: if (ref($domconfig{'quotas'}) eq 'HASH') {
8349: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8350: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
8351: if (exists($confhash{'defaultquota'}{$key})) {
8352: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
8353: $changes{'defaultquota'}{$key} = 1;
8354: }
8355: } else {
8356: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 8357: }
8358: }
1.86 raeburn 8359: } else {
8360: foreach my $key (keys(%{$domconfig{'quotas'}})) {
8361: if (exists($confhash{'defaultquota'}{$key})) {
8362: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
8363: $changes{'defaultquota'}{$key} = 1;
8364: }
8365: } else {
8366: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 8367: }
1.1 raeburn 8368: }
8369: }
1.197 raeburn 8370: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8371: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
8372: if (exists($confhash{'authorquota'}{$key})) {
8373: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
8374: $changes{'authorquota'}{$key} = 1;
8375: }
8376: } else {
8377: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
8378: }
8379: }
8380: }
1.1 raeburn 8381: }
1.86 raeburn 8382: if (ref($confhash{'defaultquota'}) eq 'HASH') {
8383: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
8384: if (ref($domconfig{'quotas'}) eq 'HASH') {
8385: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8386: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
8387: $changes{'defaultquota'}{$key} = 1;
8388: }
8389: } else {
8390: if (!exists($domconfig{'quotas'}{$key})) {
8391: $changes{'defaultquota'}{$key} = 1;
8392: }
1.72 raeburn 8393: }
8394: } else {
1.86 raeburn 8395: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 8396: }
1.1 raeburn 8397: }
8398: }
1.197 raeburn 8399: if (ref($confhash{'authorquota'}) eq 'HASH') {
8400: foreach my $key (keys(%{$confhash{'authorquota'}})) {
8401: if (ref($domconfig{'quotas'}) eq 'HASH') {
8402: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8403: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
8404: $changes{'authorquota'}{$key} = 1;
8405: }
8406: } else {
8407: $changes{'authorquota'}{$key} = 1;
8408: }
8409: } else {
8410: $changes{'authorquota'}{$key} = 1;
8411: }
8412: }
8413: }
1.1 raeburn 8414: }
1.72 raeburn 8415:
1.163 raeburn 8416: if ($context eq 'requestauthor') {
8417: $domdefaults{'requestauthor'} = \%confhash;
8418: } else {
8419: foreach my $key (keys(%confhash)) {
1.242 raeburn 8420: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 8421: $domdefaults{$key} = $confhash{$key};
8422: }
1.163 raeburn 8423: }
1.72 raeburn 8424: }
1.163 raeburn 8425:
1.1 raeburn 8426: my %quotahash = (
1.86 raeburn 8427: $action => { %confhash }
1.1 raeburn 8428: );
8429: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
8430: $dom);
8431: if ($putresult eq 'ok') {
8432: if (keys(%changes) > 0) {
1.72 raeburn 8433: my $cachetime = 24*60*60;
8434: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 8435: if (ref($lastactref) eq 'HASH') {
8436: $lastactref->{'domdefaults'} = 1;
8437: }
1.1 raeburn 8438: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 8439: unless (($context eq 'requestcourses') ||
1.163 raeburn 8440: ($context eq 'requestauthor')) {
1.86 raeburn 8441: if (ref($changes{'defaultquota'}) eq 'HASH') {
8442: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
8443: foreach my $type (@{$types},'default') {
8444: if (defined($changes{'defaultquota'}{$type})) {
8445: my $typetitle = $usertypes->{$type};
8446: if ($type eq 'default') {
8447: $typetitle = $othertitle;
8448: }
1.213 raeburn 8449: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 8450: }
8451: }
1.86 raeburn 8452: $resulttext .= '</ul></li>';
1.72 raeburn 8453: }
1.197 raeburn 8454: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 8455: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 8456: foreach my $type (@{$types},'default') {
8457: if (defined($changes{'authorquota'}{$type})) {
8458: my $typetitle = $usertypes->{$type};
8459: if ($type eq 'default') {
8460: $typetitle = $othertitle;
8461: }
1.213 raeburn 8462: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 8463: }
8464: }
8465: $resulttext .= '</ul></li>';
8466: }
1.72 raeburn 8467: }
1.80 raeburn 8468: my %newenv;
1.72 raeburn 8469: foreach my $item (@usertools) {
1.163 raeburn 8470: my (%haschgs,%inconf);
8471: if ($context eq 'requestauthor') {
8472: %haschgs = %changes;
1.210 raeburn 8473: %inconf = %confhash;
1.163 raeburn 8474: } else {
8475: if (ref($changes{$item}) eq 'HASH') {
8476: %haschgs = %{$changes{$item}};
8477: }
8478: if (ref($confhash{$item}) eq 'HASH') {
8479: %inconf = %{$confhash{$item}};
8480: }
8481: }
8482: if (keys(%haschgs) > 0) {
1.80 raeburn 8483: my $newacc =
8484: &Apache::lonnet::usertools_access($env{'user.name'},
8485: $env{'user.domain'},
1.86 raeburn 8486: $item,'reload',$context);
1.210 raeburn 8487: if (($context eq 'requestcourses') ||
1.163 raeburn 8488: ($context eq 'requestauthor')) {
1.108 raeburn 8489: if ($env{'environment.canrequest.'.$item} ne $newacc) {
8490: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 8491: }
8492: } else {
8493: if ($env{'environment.availabletools.'.$item} ne $newacc) {
8494: $newenv{'environment.availabletools.'.$item} = $newacc;
8495: }
1.80 raeburn 8496: }
1.163 raeburn 8497: unless ($context eq 'requestauthor') {
8498: $resulttext .= '<li>'.$titles{$item}.'<ul>';
8499: }
1.72 raeburn 8500: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 8501: if ($haschgs{$type}) {
1.72 raeburn 8502: my $typetitle = $usertypes->{$type};
8503: if ($type eq 'default') {
8504: $typetitle = $othertitle;
8505: } elsif ($type eq '_LC_adv') {
8506: $typetitle = 'LON-CAPA Advanced Users';
8507: }
1.163 raeburn 8508: if ($inconf{$type}) {
1.101 raeburn 8509: if ($context eq 'requestcourses') {
8510: my $cond;
1.163 raeburn 8511: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 8512: if ($1 eq '') {
8513: $cond = &mt('(Automatic processing of any request).');
8514: } else {
8515: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
8516: }
8517: } else {
1.163 raeburn 8518: $cond = $conditions{$inconf{$type}};
1.101 raeburn 8519: }
8520: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 8521: } elsif ($context eq 'requestauthor') {
8522: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
8523: $titles{$inconf{$type}},$typetitle);
8524:
1.101 raeburn 8525: } else {
8526: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
8527: }
1.72 raeburn 8528: } else {
1.104 raeburn 8529: if ($type eq '_LC_adv') {
1.163 raeburn 8530: if ($inconf{$type} eq '0') {
1.104 raeburn 8531: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8532: } else {
8533: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
8534: }
8535: } else {
8536: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8537: }
1.72 raeburn 8538: }
8539: }
1.26 raeburn 8540: }
1.163 raeburn 8541: unless ($context eq 'requestauthor') {
8542: $resulttext .= '</ul></li>';
8543: }
1.26 raeburn 8544: }
1.1 raeburn 8545: }
1.163 raeburn 8546: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 8547: if (ref($changes{'notify'}) eq 'HASH') {
8548: if ($changes{'notify'}{'approval'}) {
8549: if (ref($confhash{'notify'}) eq 'HASH') {
8550: if ($confhash{'notify'}{'approval'}) {
8551: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
8552: } else {
1.163 raeburn 8553: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 8554: }
8555: }
8556: }
8557: }
8558: }
1.216 raeburn 8559: if ($action eq 'requestcourses') {
8560: my @offon = ('off','on');
8561: if ($changes{'uniquecode'}) {
1.218 raeburn 8562: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8563: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
8564: $resulttext .= '<li>'.
8565: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
8566: '</li>';
8567: } else {
8568: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
8569: '</li>';
8570: }
1.216 raeburn 8571: }
1.242 raeburn 8572: foreach my $type ('textbooks','templates') {
8573: if (ref($changes{$type}) eq 'HASH') {
8574: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
8575: foreach my $key (sort(keys(%{$changes{$type}}))) {
8576: my %coursehash = &Apache::lonnet::coursedescription($key);
8577: my $coursetitle = $coursehash{'description'};
8578: my $position = $confhash{$type}{$key}{'order'} + 1;
8579: $resulttext .= '<li>';
1.243 raeburn 8580: foreach my $item ('subject','title','publisher','author') {
8581: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8582: ($type eq 'templates'));
1.242 raeburn 8583: my $name = $item.':';
8584: $name =~ s/^(\w)/\U$1/;
8585: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
8586: }
8587: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
8588: if ($type eq 'textbooks') {
8589: if ($confhash{$type}{$key}{'image'}) {
8590: $resulttext .= ' '.&mt('Image: [_1]',
8591: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
8592: ' alt="Textbook cover" />').'<br />';
8593: }
8594: }
8595: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 8596: }
1.242 raeburn 8597: $resulttext .= '</ul></li>';
1.216 raeburn 8598: }
8599: }
1.235 raeburn 8600: if (ref($changes{'validation'}) eq 'HASH') {
8601: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
8602: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
8603: foreach my $item (@{$validationitemsref}) {
8604: if (exists($changes{'validation'}{$item})) {
8605: if ($item eq 'markup') {
8606: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8607: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
8608: } else {
8609: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8610: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
8611: }
8612: }
8613: }
8614: if (exists($changes{'validation'}{'dc'})) {
8615: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
8616: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
8617: }
8618: }
8619: }
1.216 raeburn 8620: }
1.1 raeburn 8621: $resulttext .= '</ul>';
1.80 raeburn 8622: if (keys(%newenv)) {
8623: &Apache::lonnet::appenv(\%newenv);
8624: }
1.1 raeburn 8625: } else {
1.86 raeburn 8626: if ($context eq 'requestcourses') {
8627: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 8628: } elsif ($context eq 'requestauthor') {
8629: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 8630: } else {
1.90 weissno 8631: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 8632: }
1.1 raeburn 8633: }
8634: } else {
1.11 albertel 8635: $resulttext = '<span class="LC_error">'.
8636: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8637: }
1.216 raeburn 8638: if ($errors) {
8639: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
8640: '<ul>'.$errors.'</ul></p>';
8641: }
1.3 raeburn 8642: return $resulttext;
1.1 raeburn 8643: }
8644:
1.216 raeburn 8645: sub process_textbook_image {
1.242 raeburn 8646: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 8647: my $filename = $env{'form.'.$caller.'.filename'};
8648: my ($error,$url);
8649: my ($width,$height) = (50,50);
8650: if ($configuserok eq 'ok') {
8651: if ($switchserver) {
8652: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
8653: $switchserver);
8654: } elsif ($author_ok eq 'ok') {
8655: my ($result,$imageurl) =
8656: &publishlogo($r,'upload',$caller,$dom,$confname,
1.242 raeburn 8657: "$type/$dom/$cnum/cover",$width,$height);
1.216 raeburn 8658: if ($result eq 'ok') {
8659: $url = $imageurl;
8660: } else {
8661: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
8662: }
8663: } else {
8664: $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);
8665: }
8666: } else {
8667: $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);
8668: }
8669: return ($url,$error);
8670: }
8671:
1.267 raeburn 8672: sub modify_ltitools {
8673: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
8674: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8675: my ($newid,@allpos,%changes,%confhash,$errors,$resulttext);
8676: my $confname = $dom.'-domainconfig';
8677: my $servadm = $r->dir_config('lonAdmEMail');
8678: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8679: my (%posslti,%possfield);
8680: my @courseroles = ('cc','in','ta','ep','st');
8681: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
8682: map { $posslti{$_} = 1; } @ltiroles;
8683: my @allfields = ('fullname','firstname','lastname','email','user','roles');
8684: map { $possfield{$_} = 1; } @allfields;
8685: my %lt = <itools_names();
8686: if ($env{'form.ltitools_add'}) {
8687: my $title = $env{'form.ltitools_add_title'};
8688: $title =~ s/(`)/'/g;
8689: ($newid,my $error) = &get_ltitools_id($dom,$title);
8690: if ($newid) {
8691: my $position = $env{'form.ltitools_add_pos'};
8692: $position =~ s/\D+//g;
8693: if ($position ne '') {
8694: $allpos[$position] = $newid;
8695: }
8696: $changes{$newid} = 1;
8697: foreach my $item ('title','url','key','secret') {
8698: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
8699: if ($env{'form.ltitools_add_'.$item}) {
8700: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
8701: }
8702: }
8703: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
8704: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
8705: }
8706: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
8707: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
8708: }
8709: foreach my $item ('width','height') {
8710: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
8711: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
8712: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
8713: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
8714: }
8715: }
8716: if ($env{'form.ltitools_add_target'} eq 'window') {
8717: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
8718: } else {
8719: $confhash{$newid}{'display'}{'target'} = 'iframe';
8720: }
8721: foreach my $item ('passback','roster') {
8722: if ($env{'form.ltitools_add_'.$item}) {
8723: $confhash{$newid}{$item} = 1;
8724: }
8725: }
8726: if ($env{'form.ltitools_add_image.filename'} ne '') {
8727: my ($imageurl,$error) =
8728: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$dom,
8729: $configuserok,$switchserver,$author_ok);
8730: if ($imageurl) {
8731: $confhash{$newid}{'image'} = $imageurl;
8732: }
8733: if ($error) {
8734: &Apache::lonnet::logthis($error);
8735: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8736: }
8737: }
8738: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
8739: foreach my $field (@fields) {
8740: if ($possfield{$field}) {
8741: if ($field eq 'roles') {
8742: foreach my $role (@courseroles) {
8743: my $choice = $env{'form.ltitools_add_roles_'.$role};
8744: if (($choice ne '') && ($posslti{$choice})) {
8745: $confhash{$newid}{'roles'}{$role} = $choice;
8746: if ($role eq 'cc') {
8747: $confhash{$newid}{'roles'}{'co'} = $choice;
8748: }
8749: }
8750: }
8751: } else {
8752: $confhash{$newid}{'fields'}{$field} = 1;
8753: }
8754: }
8755: }
1.273 raeburn 8756: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
8757: foreach my $item (@courseconfig) {
8758: $confhash{$newid}{'crsconf'}{$item} = 1;
8759: }
1.267 raeburn 8760: if ($env{'form.ltitools_add_custom'}) {
8761: my $name = $env{'form.ltitools_add_custom_name'};
8762: my $value = $env{'form.ltitools_add_custom_value'};
8763: $value =~ s/(`)/'/g;
8764: $name =~ s/(`)/'/g;
8765: $confhash{$newid}{'custom'}{$name} = $value;
8766: }
8767: } else {
8768: my $error = &mt('Failed to acquire unique ID for new external tool');
8769: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8770: }
8771: }
8772: if (ref($domconfig{$action}) eq 'HASH') {
8773: my %deletions;
8774: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
8775: if (@todelete) {
8776: map { $deletions{$_} = 1; } @todelete;
8777: }
8778: my %customadds;
8779: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
8780: if (@newcustom) {
8781: map { $customadds{$_} = 1; } @newcustom;
8782: }
8783: my %imgdeletions;
8784: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
8785: if (@todeleteimages) {
8786: map { $imgdeletions{$_} = 1; } @todeleteimages;
8787: }
8788: my $maxnum = $env{'form.ltitools_maxnum'};
8789: for (my $i=0; $i<=$maxnum; $i++) {
8790: my $itemid = $env{'form.ltitools_id_'.$i};
8791: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
8792: if ($deletions{$itemid}) {
8793: if ($domconfig{$action}{$itemid}{'image'}) {
8794: #FIXME need to obsolete item in RES space
8795: }
8796: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
8797: next;
8798: } else {
8799: my $newpos = $env{'form.ltitools_'.$itemid};
8800: $newpos =~ s/\D+//g;
8801: foreach my $item ('title','url','key','secret') {
8802: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
8803: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
8804: $changes{$itemid} = 1;
8805: }
8806: }
8807: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
8808: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
8809: }
8810: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
8811: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
8812: }
8813: foreach my $size ('width','height') {
8814: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
8815: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
8816: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
8817: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
8818: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
8819: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
8820: $changes{$itemid} = 1;
8821: }
8822: } else {
8823: $changes{$itemid} = 1;
8824: }
8825: }
8826: }
8827: if ($env{'form.ltitools_target_'.$i} eq 'window') {
8828: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
8829: } else {
8830: $confhash{$itemid}{'display'}{'target'} = 'iframe';
8831: }
8832: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
8833: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
8834: $changes{$itemid} = 1;
8835: }
8836: } else {
8837: $changes{$itemid} = 1;
8838: }
8839: foreach my $extra ('passback','roster') {
8840: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
8841: $confhash{$itemid}{$extra} = 1;
8842: }
8843: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
8844: $changes{$itemid} = 1;
8845: }
8846: }
1.273 raeburn 8847: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
8848: foreach my $item ('label','title','target') {
8849: if (grep(/^\Q$item\E$/,@courseconfig)) {
8850: $confhash{$itemid}{'crsconf'}{$item} = 1;
8851: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
8852: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
8853: $changes{$itemid} = 1;
8854: }
8855: } else {
8856: $changes{$itemid} = 1;
8857: }
8858: }
8859: }
1.267 raeburn 8860: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
8861: foreach my $field (@fields) {
8862: if ($possfield{$field}) {
8863: if ($field eq 'roles') {
8864: foreach my $role (@courseroles) {
8865: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
8866: if (($choice ne '') && ($posslti{$choice})) {
8867: $confhash{$itemid}{'roles'}{$role} = $choice;
8868: if ($role eq 'cc') {
8869: $confhash{$itemid}{'roles'}{'co'} = $choice;
8870: }
8871: }
8872: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
8873: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
8874: $changes{$itemid} = 1;
8875: }
8876: } elsif ($confhash{$itemid}{'roles'}{$role}) {
8877: $changes{$itemid} = 1;
8878: }
8879: }
8880: } else {
8881: $confhash{$itemid}{'fields'}{$field} = 1;
8882: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
8883: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
8884: $changes{$itemid} = 1;
8885: }
8886: } else {
8887: $changes{$itemid} = 1;
8888: }
8889: }
8890: }
8891: }
8892: $allpos[$newpos] = $itemid;
8893: }
8894: if ($imgdeletions{$itemid}) {
8895: $changes{$itemid} = 1;
8896: #FIXME need to obsolete item in RES space
8897: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
8898: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
8899: $itemid,$configuserok,$switchserver,
8900: $author_ok);
8901: if ($imgurl) {
8902: $confhash{$itemid}{'image'} = $imgurl;
8903: $changes{$itemid} = 1;
8904: }
8905: if ($error) {
8906: &Apache::lonnet::logthis($error);
8907: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8908: }
8909: } elsif ($domconfig{$action}{$itemid}{'image'}) {
8910: $confhash{$itemid}{'image'} =
8911: $domconfig{$action}{$itemid}{'image'};
8912: }
8913: if ($customadds{$i}) {
8914: my $name = $env{'form.ltitools_custom_name_'.$i};
8915: $name =~ s/(`)/'/g;
8916: $name =~ s/^\s+//;
8917: $name =~ s/\s+$//;
8918: my $value = $env{'form.ltitools_custom_value_'.$i};
8919: $value =~ s/(`)/'/g;
8920: $value =~ s/^\s+//;
8921: $value =~ s/\s+$//;
8922: if ($name ne '') {
8923: $confhash{$itemid}{'custom'}{$name} = $value;
8924: $changes{$itemid} = 1;
8925: }
8926: }
8927: my %customdels;
8928: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
8929: if (@customdeletions) {
8930: $changes{$itemid} = 1;
8931: }
8932: map { $customdels{$_} = 1; } @customdeletions;
8933: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
8934: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
8935: unless ($customdels{$key}) {
8936: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
8937: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
8938: }
8939: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
8940: $changes{$itemid} = 1;
8941: }
8942: }
8943: }
8944: }
8945: unless ($changes{$itemid}) {
8946: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
8947: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
8948: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
8949: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
8950: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
8951: $changes{$itemid} = 1;
8952: last;
8953: }
8954: }
8955: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
8956: $changes{$itemid} = 1;
8957: }
8958: }
8959: last if ($changes{$itemid});
8960: }
8961: }
8962: }
8963: }
8964: }
8965: if (@allpos > 0) {
8966: my $idx = 0;
8967: foreach my $itemid (@allpos) {
8968: if ($itemid ne '') {
8969: $confhash{$itemid}{'order'} = $idx;
8970: if (ref($domconfig{$action}) eq 'HASH') {
8971: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
8972: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
8973: $changes{$itemid} = 1;
8974: }
8975: }
8976: }
8977: $idx ++;
8978: }
8979: }
8980: }
8981: my %ltitoolshash = (
8982: $action => { %confhash }
8983: );
8984: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
8985: $dom);
8986: if ($putresult eq 'ok') {
8987: if (keys(%changes) > 0) {
8988: my $cachetime = 24*60*60;
8989: &Apache::lonnet::do_cache_new('ltitools',$dom,\%confhash,$cachetime);
8990: if (ref($lastactref) eq 'HASH') {
8991: $lastactref->{'ltitools'} = 1;
8992: }
8993: $resulttext = &mt('Changes made:').'<ul>';
8994: my %bynum;
8995: foreach my $itemid (sort(keys(%changes))) {
8996: my $position = $confhash{$itemid}{'order'};
8997: $bynum{$position} = $itemid;
8998: }
8999: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
9000: my $itemid = $bynum{$pos};
9001: if (ref($confhash{$itemid}) ne 'HASH') {
9002: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
9003: } else {
9004: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
9005: if ($confhash{$itemid}{'image'}) {
9006: $resulttext .= ' '.
9007: '<img src="'.$confhash{$itemid}{'image'}.'"'.
9008: ' alt="'.&mt('Tool Provider icon').'" />';
9009: }
9010: $resulttext .= '</li><ul>';
9011: my $position = $pos + 1;
9012: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
9013: foreach my $item ('version','msgtype','url','key') {
9014: if ($confhash{$itemid}{$item} ne '') {
9015: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
9016: }
9017: }
9018: if ($confhash{$itemid}{'secret'} ne '') {
9019: $resulttext .= '<li>'.$lt{'secret'}.': ';
9020: my $num = length($confhash{$itemid}{'secret'});
9021: $resulttext .= ('*'x$num).'</li>';
9022: }
1.273 raeburn 9023: $resulttext .= '<li>'.&mt('Configurable in course:');
9024: my @possconfig = ('label','title','target');
9025: my $numconfig = 0;
9026: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
9027: foreach my $item (@possconfig) {
9028: if ($confhash{$itemid}{'crsconf'}{$item}) {
9029: $numconfig ++;
9030: $resulttext .= ' '.$lt{'crs'.$item};
9031: }
9032: }
9033: }
9034: if (!$numconfig) {
9035: $resulttext .= &mt('None');
9036: }
9037: $resulttext .= '</li>';
1.267 raeburn 9038: foreach my $item ('passback','roster') {
9039: $resulttext .= '<li>'.$lt{$item}.' ';
9040: if ($confhash{$itemid}{$item}) {
9041: $resulttext .= &mt('Yes');
9042: } else {
9043: $resulttext .= &mt('No');
9044: }
9045: $resulttext .= '</li>';
9046: }
9047: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
9048: my $displaylist;
9049: if ($confhash{$itemid}{'display'}{'target'}) {
9050: $displaylist = &mt('Display target').': '.
9051: $confhash{$itemid}{'display'}{'target'}.',';
9052: }
9053: foreach my $size ('width','height') {
9054: if ($confhash{$itemid}{'display'}{$size}) {
9055: $displaylist .= (' 'x2).$lt{$size}.': '.
9056: $confhash{$itemid}{'display'}{$size}.',';
9057: }
9058: }
9059: if ($displaylist) {
9060: $displaylist =~ s/,$//;
9061: $resulttext .= '<li>'.$displaylist.'</li>';
9062: }
9063: }
9064: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
9065: my $fieldlist;
9066: foreach my $field (@allfields) {
9067: if ($confhash{$itemid}{'fields'}{$field}) {
9068: $fieldlist .= (' 'x2).$lt{$field}.',';
9069: }
9070: }
9071: if ($fieldlist) {
9072: $fieldlist =~ s/,$//;
9073: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
9074: }
9075: }
9076: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
9077: my $rolemaps;
9078: foreach my $role (@courseroles) {
9079: if ($confhash{$itemid}{'roles'}{$role}) {
9080: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
9081: $confhash{$itemid}{'roles'}{$role}.',';
9082: }
9083: }
9084: if ($rolemaps) {
9085: $rolemaps =~ s/,$//;
9086: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
9087: }
9088: }
9089: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
9090: my $customlist;
9091: if (keys(%{$confhash{$itemid}{'custom'}})) {
9092: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
9093: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
9094: }
9095: }
9096: if ($customlist) {
9097: $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
9098: }
9099: }
9100: $resulttext .= '</ul></li>';
9101: }
9102: }
9103: $resulttext .= '</ul>';
9104: } else {
9105: $resulttext = &mt('No changes made.');
9106: }
9107: } else {
9108: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
9109: }
9110: if ($errors) {
9111: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9112: $errors.'</ul>';
9113: }
9114: return $resulttext;
9115: }
9116:
9117: sub process_ltitools_image {
9118: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
9119: my $filename = $env{'form.'.$caller.'.filename'};
9120: my ($error,$url);
9121: my ($width,$height) = (21,21);
9122: if ($configuserok eq 'ok') {
9123: if ($switchserver) {
9124: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
9125: $switchserver);
9126: } elsif ($author_ok eq 'ok') {
9127: my ($result,$imageurl,$madethumb) =
9128: &publishlogo($r,'upload',$caller,$dom,$confname,
9129: "ltitools/$itemid/icon",$width,$height);
9130: if ($result eq 'ok') {
9131: if ($madethumb) {
9132: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
9133: my $imagethumb = "$path/tn-".$imagefile;
9134: $url = $imagethumb;
9135: } else {
9136: $url = $imageurl;
9137: }
9138: } else {
9139: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9140: }
9141: } else {
9142: $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);
9143: }
9144: } else {
9145: $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);
9146: }
9147: return ($url,$error);
9148: }
9149:
9150: sub get_ltitools_id {
9151: my ($cdom,$title) = @_;
9152: # get lock on ltitools db
9153: my $lockhash = {
9154: lock => $env{'user.name'}.
9155: ':'.$env{'user.domain'},
9156: };
9157: my $tries = 0;
9158: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
9159: my ($id,$error);
9160:
9161: while (($gotlock ne 'ok') && ($tries<10)) {
9162: $tries ++;
9163: sleep (0.1);
9164: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
9165: }
9166: if ($gotlock eq 'ok') {
9167: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
9168: if ($currids{'lock'}) {
9169: delete($currids{'lock'});
9170: if (keys(%currids)) {
9171: my @curr = sort { $a <=> $b } keys(%currids);
9172: if ($curr[-1] =~ /^\d+$/) {
9173: $id = 1 + $curr[-1];
9174: }
9175: } else {
9176: $id = 1;
9177: }
9178: if ($id) {
9179: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
9180: $error = 'nostore';
9181: }
9182: } else {
9183: $error = 'nonumber';
9184: }
9185: }
9186: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
9187: } else {
9188: $error = 'nolock';
9189: }
9190: return ($id,$error);
9191: }
9192:
1.3 raeburn 9193: sub modify_autoenroll {
1.205 raeburn 9194: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 9195: my ($resulttext,%changes);
9196: my %currautoenroll;
9197: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
9198: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
9199: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
9200: }
9201: }
9202: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
9203: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 9204: sender => 'Sender for notification messages',
1.274 raeburn 9205: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
9206: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 9207: my @offon = ('off','on');
1.17 raeburn 9208: my $sender_uname = $env{'form.sender_uname'};
9209: my $sender_domain = $env{'form.sender_domain'};
9210: if ($sender_domain eq '') {
9211: $sender_uname = '';
9212: } elsif ($sender_uname eq '') {
9213: $sender_domain = '';
9214: }
1.129 raeburn 9215: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 9216: my $failsafe = $env{'form.autoenroll_failsafe'};
9217: $failsafe =~ s{^\s+|\s+$}{}g;
9218: if ($failsafe =~ /\D/) {
9219: undef($failsafe);
9220: }
1.1 raeburn 9221: my %autoenrollhash = (
1.129 raeburn 9222: autoenroll => { 'run' => $env{'form.autoenroll_run'},
9223: 'sender_uname' => $sender_uname,
9224: 'sender_domain' => $sender_domain,
9225: 'co-owners' => $coowners,
1.274 raeburn 9226: 'autofailsafe' => $failsafe,
1.1 raeburn 9227: }
9228: );
1.4 raeburn 9229: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
9230: $dom);
1.1 raeburn 9231: if ($putresult eq 'ok') {
9232: if (exists($currautoenroll{'run'})) {
9233: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
9234: $changes{'run'} = 1;
9235: }
9236: } elsif ($autorun) {
9237: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 9238: $changes{'run'} = 1;
1.1 raeburn 9239: }
9240: }
1.17 raeburn 9241: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 9242: $changes{'sender'} = 1;
9243: }
1.17 raeburn 9244: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 9245: $changes{'sender'} = 1;
9246: }
1.129 raeburn 9247: if ($currautoenroll{'co-owners'} ne '') {
9248: if ($currautoenroll{'co-owners'} ne $coowners) {
9249: $changes{'coowners'} = 1;
9250: }
9251: } elsif ($coowners) {
9252: $changes{'coowners'} = 1;
1.274 raeburn 9253: }
9254: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
9255: $changes{'autofailsafe'} = 1;
9256: }
1.1 raeburn 9257: if (keys(%changes) > 0) {
9258: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 9259: if ($changes{'run'}) {
1.1 raeburn 9260: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
9261: }
9262: if ($changes{'sender'}) {
1.17 raeburn 9263: if ($sender_uname eq '' || $sender_domain eq '') {
9264: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
9265: } else {
9266: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
9267: }
1.1 raeburn 9268: }
1.129 raeburn 9269: if ($changes{'coowners'}) {
9270: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
9271: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9272: if (ref($lastactref) eq 'HASH') {
9273: $lastactref->{'domainconfig'} = 1;
9274: }
1.129 raeburn 9275: }
1.274 raeburn 9276: if ($changes{'autofailsafe'}) {
9277: if ($failsafe ne '') {
9278: $resulttext .= '<li>'.&mt("$title{'failsafe'} set to [_1]",$failsafe).'</li>';
9279: } else {
9280: $resulttext .= '<li>'.&mt("$title{'failsafe'} deleted");
9281: }
9282: &Apache::lonnet::get_domain_defaults($dom,1);
9283: if (ref($lastactref) eq 'HASH') {
9284: $lastactref->{'domdefaults'} = 1;
9285: }
9286: }
1.1 raeburn 9287: $resulttext .= '</ul>';
9288: } else {
9289: $resulttext = &mt('No changes made to auto-enrollment settings');
9290: }
9291: } else {
1.11 albertel 9292: $resulttext = '<span class="LC_error">'.
9293: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9294: }
1.3 raeburn 9295: return $resulttext;
1.1 raeburn 9296: }
9297:
9298: sub modify_autoupdate {
1.3 raeburn 9299: my ($dom,%domconfig) = @_;
1.1 raeburn 9300: my ($resulttext,%currautoupdate,%fields,%changes);
9301: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
9302: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
9303: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
9304: }
9305: }
9306: my @offon = ('off','on');
9307: my %title = &Apache::lonlocal::texthash (
9308: run => 'Auto-update:',
9309: classlists => 'Updates to user information in classlists?'
9310: );
1.44 raeburn 9311: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 9312: my %fieldtitles = &Apache::lonlocal::texthash (
9313: id => 'Student/Employee ID',
1.20 raeburn 9314: permanentemail => 'E-mail address',
1.1 raeburn 9315: lastname => 'Last Name',
9316: firstname => 'First Name',
9317: middlename => 'Middle Name',
1.132 raeburn 9318: generation => 'Generation',
1.1 raeburn 9319: );
1.142 raeburn 9320: $othertitle = &mt('All users');
1.1 raeburn 9321: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 9322: $othertitle = &mt('Other users');
1.1 raeburn 9323: }
9324: foreach my $key (keys(%env)) {
9325: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 9326: my ($usertype,$item) = ($1,$2);
9327: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
9328: if ($usertype eq 'default') {
9329: push(@{$fields{$1}},$2);
9330: } elsif (ref($types) eq 'ARRAY') {
9331: if (grep(/^\Q$usertype\E$/,@{$types})) {
9332: push(@{$fields{$1}},$2);
9333: }
9334: }
9335: }
1.1 raeburn 9336: }
9337: }
1.131 raeburn 9338: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
9339: @lockablenames = sort(@lockablenames);
9340: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
9341: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9342: if (@changed) {
9343: $changes{'lockablenames'} = 1;
9344: }
9345: } else {
9346: if (@lockablenames) {
9347: $changes{'lockablenames'} = 1;
9348: }
9349: }
1.1 raeburn 9350: my %updatehash = (
9351: autoupdate => { run => $env{'form.autoupdate_run'},
9352: classlists => $env{'form.classlists'},
9353: fields => {%fields},
1.131 raeburn 9354: lockablenames => \@lockablenames,
1.1 raeburn 9355: }
9356: );
9357: foreach my $key (keys(%currautoupdate)) {
9358: if (($key eq 'run') || ($key eq 'classlists')) {
9359: if (exists($updatehash{autoupdate}{$key})) {
9360: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
9361: $changes{$key} = 1;
9362: }
9363: }
9364: } elsif ($key eq 'fields') {
9365: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 9366: foreach my $item (@{$types},'default') {
1.1 raeburn 9367: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
9368: my $change = 0;
9369: foreach my $type (@{$currautoupdate{$key}{$item}}) {
9370: if (!exists($fields{$item})) {
9371: $change = 1;
1.132 raeburn 9372: last;
1.1 raeburn 9373: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 9374: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 9375: $change = 1;
1.132 raeburn 9376: last;
1.1 raeburn 9377: }
9378: }
9379: }
9380: if ($change) {
9381: push(@{$changes{$key}},$item);
9382: }
1.26 raeburn 9383: }
1.1 raeburn 9384: }
9385: }
1.131 raeburn 9386: } elsif ($key eq 'lockablenames') {
9387: if (ref($currautoupdate{$key}) eq 'ARRAY') {
9388: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9389: if (@changed) {
9390: $changes{'lockablenames'} = 1;
9391: }
9392: } else {
9393: if (@lockablenames) {
9394: $changes{'lockablenames'} = 1;
9395: }
9396: }
9397: }
9398: }
9399: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
9400: if (@lockablenames) {
9401: $changes{'lockablenames'} = 1;
1.1 raeburn 9402: }
9403: }
1.26 raeburn 9404: foreach my $item (@{$types},'default') {
9405: if (defined($fields{$item})) {
9406: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 9407: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
9408: my $change = 0;
9409: if (ref($fields{$item}) eq 'ARRAY') {
9410: foreach my $type (@{$fields{$item}}) {
9411: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
9412: $change = 1;
9413: last;
9414: }
9415: }
9416: }
9417: if ($change) {
9418: push(@{$changes{'fields'}},$item);
9419: }
9420: } else {
1.26 raeburn 9421: push(@{$changes{'fields'}},$item);
9422: }
9423: } else {
9424: push(@{$changes{'fields'}},$item);
1.1 raeburn 9425: }
9426: }
9427: }
9428: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
9429: $dom);
9430: if ($putresult eq 'ok') {
9431: if (keys(%changes) > 0) {
9432: $resulttext = &mt('Changes made:').'<ul>';
9433: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 9434: if ($key eq 'lockablenames') {
9435: $resulttext .= '<li>';
9436: if (@lockablenames) {
9437: $usertypes->{'default'} = $othertitle;
9438: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
9439: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
9440: } else {
9441: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
9442: }
9443: $resulttext .= '</li>';
9444: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 9445: foreach my $item (@{$changes{$key}}) {
9446: my @newvalues;
9447: foreach my $type (@{$fields{$item}}) {
9448: push(@newvalues,$fieldtitles{$type});
9449: }
1.3 raeburn 9450: my $newvaluestr;
9451: if (@newvalues > 0) {
9452: $newvaluestr = join(', ',@newvalues);
9453: } else {
9454: $newvaluestr = &mt('none');
1.6 raeburn 9455: }
1.1 raeburn 9456: if ($item eq 'default') {
1.26 raeburn 9457: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 9458: } else {
1.26 raeburn 9459: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 9460: }
9461: }
9462: } else {
9463: my $newvalue;
9464: if ($key eq 'run') {
9465: $newvalue = $offon[$env{'form.autoupdate_run'}];
9466: } else {
9467: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 9468: }
1.1 raeburn 9469: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
9470: }
9471: }
9472: $resulttext .= '</ul>';
9473: } else {
1.3 raeburn 9474: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 9475: }
9476: } else {
1.11 albertel 9477: $resulttext = '<span class="LC_error">'.
9478: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9479: }
1.3 raeburn 9480: return $resulttext;
1.1 raeburn 9481: }
9482:
1.125 raeburn 9483: sub modify_autocreate {
9484: my ($dom,%domconfig) = @_;
9485: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
9486: if (ref($domconfig{'autocreate'}) eq 'HASH') {
9487: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
9488: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
9489: }
9490: }
9491: my %title= ( xml => 'Auto-creation of courses in XML course description files',
9492: req => 'Auto-creation of validated requests for official courses',
9493: xmldc => 'Identity of course creator of courses from XML files',
9494: );
9495: my @types = ('xml','req');
9496: foreach my $item (@types) {
9497: $newvals{$item} = $env{'form.autocreate_'.$item};
9498: $newvals{$item} =~ s/\D//g;
9499: $newvals{$item} = 0 if ($newvals{$item} eq '');
9500: }
9501: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
9502: my %domcoords = &get_active_dcs($dom);
9503: unless (exists($domcoords{$newvals{'xmldc'}})) {
9504: $newvals{'xmldc'} = '';
9505: }
9506: %autocreatehash = (
9507: autocreate => { xml => $newvals{'xml'},
9508: req => $newvals{'req'},
9509: }
9510: );
9511: if ($newvals{'xmldc'} ne '') {
9512: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
9513: }
9514: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
9515: $dom);
9516: if ($putresult eq 'ok') {
9517: my @items = @types;
9518: if ($newvals{'xml'}) {
9519: push(@items,'xmldc');
9520: }
9521: foreach my $item (@items) {
9522: if (exists($currautocreate{$item})) {
9523: if ($currautocreate{$item} ne $newvals{$item}) {
9524: $changes{$item} = 1;
9525: }
9526: } elsif ($newvals{$item}) {
9527: $changes{$item} = 1;
9528: }
9529: }
9530: if (keys(%changes) > 0) {
9531: my @offon = ('off','on');
9532: $resulttext = &mt('Changes made:').'<ul>';
9533: foreach my $item (@types) {
9534: if ($changes{$item}) {
9535: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 9536: $resulttext .= '<li>'.
9537: &mt("$title{$item} set to [_1]$newtxt [_2]",
9538: '<b>','</b>').
9539: '</li>';
1.125 raeburn 9540: }
9541: }
9542: if ($changes{'xmldc'}) {
9543: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
9544: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 9545: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 9546: }
9547: $resulttext .= '</ul>';
9548: } else {
9549: $resulttext = &mt('No changes made to auto-creation settings');
9550: }
9551: } else {
9552: $resulttext = '<span class="LC_error">'.
9553: &mt('An error occurred: [_1]',$putresult).'</span>';
9554: }
9555: return $resulttext;
9556: }
9557:
1.23 raeburn 9558: sub modify_directorysrch {
9559: my ($dom,%domconfig) = @_;
9560: my ($resulttext,%changes);
9561: my %currdirsrch;
9562: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
9563: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
9564: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
9565: }
9566: }
1.277 raeburn 9567: my %title = ( available => 'Institutional directory search available',
9568: localonly => 'Other domains can search institution',
9569: lcavailable => 'LON-CAPA directory search available',
9570: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 9571: searchby => 'Search types',
9572: searchtypes => 'Search latitude');
9573: my @offon = ('off','on');
1.24 raeburn 9574: my @otherdoms = ('Yes','No');
1.23 raeburn 9575:
1.25 raeburn 9576: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 9577: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
9578: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
9579:
1.44 raeburn 9580: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 9581: if (keys(%{$usertypes}) == 0) {
9582: @cansearch = ('default');
9583: } else {
9584: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
9585: foreach my $type (@{$currdirsrch{'cansearch'}}) {
9586: if (!grep(/^\Q$type\E$/,@cansearch)) {
9587: push(@{$changes{'cansearch'}},$type);
9588: }
1.23 raeburn 9589: }
1.26 raeburn 9590: foreach my $type (@cansearch) {
9591: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
9592: push(@{$changes{'cansearch'}},$type);
9593: }
1.23 raeburn 9594: }
1.26 raeburn 9595: } else {
9596: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 9597: }
9598: }
9599:
9600: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
9601: foreach my $by (@{$currdirsrch{'searchby'}}) {
9602: if (!grep(/^\Q$by\E$/,@searchby)) {
9603: push(@{$changes{'searchby'}},$by);
9604: }
9605: }
9606: foreach my $by (@searchby) {
9607: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
9608: push(@{$changes{'searchby'}},$by);
9609: }
9610: }
9611: } else {
9612: push(@{$changes{'searchby'}},@searchby);
9613: }
1.25 raeburn 9614:
9615: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
9616: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
9617: if (!grep(/^\Q$type\E$/,@searchtypes)) {
9618: push(@{$changes{'searchtypes'}},$type);
9619: }
9620: }
9621: foreach my $type (@searchtypes) {
9622: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
9623: push(@{$changes{'searchtypes'}},$type);
9624: }
9625: }
9626: } else {
9627: if (exists($currdirsrch{'searchtypes'})) {
9628: foreach my $type (@searchtypes) {
9629: if ($type ne $currdirsrch{'searchtypes'}) {
9630: push(@{$changes{'searchtypes'}},$type);
9631: }
9632: }
9633: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
9634: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
9635: }
9636: } else {
9637: push(@{$changes{'searchtypes'}},@searchtypes);
9638: }
9639: }
9640:
1.23 raeburn 9641: my %dirsrch_hash = (
9642: directorysrch => { available => $env{'form.dirsrch_available'},
9643: cansearch => \@cansearch,
1.277 raeburn 9644: localonly => $env{'form.dirsrch_instlocalonly'},
9645: lclocalonly => $env{'form.dirsrch_domlocalonly'},
9646: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 9647: searchby => \@searchby,
1.25 raeburn 9648: searchtypes => \@searchtypes,
1.23 raeburn 9649: }
9650: );
9651: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
9652: $dom);
9653: if ($putresult eq 'ok') {
9654: if (exists($currdirsrch{'available'})) {
9655: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
9656: $changes{'available'} = 1;
9657: }
9658: } else {
9659: if ($env{'form.dirsrch_available'} eq '1') {
9660: $changes{'available'} = 1;
9661: }
9662: }
1.277 raeburn 9663: if (exists($currdirsrch{'lcavailable'})) {
9664: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
9665: $changes{'lcavailable'} = 1;
9666: }
9667: } else {
9668: if ($env{'form.dirsrch_lcavailable'} eq '1') {
9669: $changes{'lcavailable'} = 1;
9670: }
9671: }
1.24 raeburn 9672: if (exists($currdirsrch{'localonly'})) {
1.277 raeburn 9673: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 9674: $changes{'localonly'} = 1;
9675: }
9676: } else {
1.277 raeburn 9677: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 9678: $changes{'localonly'} = 1;
9679: }
9680: }
1.277 raeburn 9681: if (exists($currdirsrch{'lclocalonly'})) {
9682: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
9683: $changes{'lclocalonly'} = 1;
9684: }
9685: } else {
9686: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
9687: $changes{'lclocalonly'} = 1;
9688: }
9689: }
1.23 raeburn 9690: if (keys(%changes) > 0) {
9691: $resulttext = &mt('Changes made:').'<ul>';
9692: if ($changes{'available'}) {
9693: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
9694: }
1.277 raeburn 9695: if ($changes{'lcavailable'}) {
9696: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
9697: }
1.24 raeburn 9698: if ($changes{'localonly'}) {
1.277 raeburn 9699: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 9700: }
1.277 raeburn 9701: if ($changes{'lclocalonly'}) {
9702: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
9703: }
1.23 raeburn 9704: if (ref($changes{'cansearch'}) eq 'ARRAY') {
9705: my $chgtext;
1.26 raeburn 9706: if (ref($usertypes) eq 'HASH') {
9707: if (keys(%{$usertypes}) > 0) {
9708: foreach my $type (@{$types}) {
9709: if (grep(/^\Q$type\E$/,@cansearch)) {
9710: $chgtext .= $usertypes->{$type}.'; ';
9711: }
9712: }
9713: if (grep(/^default$/,@cansearch)) {
9714: $chgtext .= $othertitle;
9715: } else {
9716: $chgtext =~ s/\; $//;
9717: }
1.210 raeburn 9718: $resulttext .=
1.178 raeburn 9719: '<li>'.
9720: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
9721: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
9722: '</li>';
1.23 raeburn 9723: }
9724: }
9725: }
9726: if (ref($changes{'searchby'}) eq 'ARRAY') {
9727: my ($searchtitles,$titleorder) = &sorted_searchtitles();
9728: my $chgtext;
9729: foreach my $type (@{$titleorder}) {
9730: if (grep(/^\Q$type\E$/,@searchby)) {
9731: if (defined($searchtitles->{$type})) {
9732: $chgtext .= $searchtitles->{$type}.'; ';
9733: }
9734: }
9735: }
9736: $chgtext =~ s/\; $//;
9737: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
9738: }
1.25 raeburn 9739: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
9740: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
9741: my $chgtext;
9742: foreach my $type (@{$srchtypeorder}) {
9743: if (grep(/^\Q$type\E$/,@searchtypes)) {
9744: if (defined($srchtypes_desc->{$type})) {
9745: $chgtext .= $srchtypes_desc->{$type}.'; ';
9746: }
9747: }
9748: }
9749: $chgtext =~ s/\; $//;
1.178 raeburn 9750: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 9751: }
9752: $resulttext .= '</ul>';
9753: } else {
1.277 raeburn 9754: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 9755: }
9756: } else {
9757: $resulttext = '<span class="LC_error">'.
1.27 raeburn 9758: &mt('An error occurred: [_1]',$putresult).'</span>';
9759: }
9760: return $resulttext;
9761: }
9762:
1.28 raeburn 9763: sub modify_contacts {
1.205 raeburn 9764: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 9765: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
9766: if (ref($domconfig{'contacts'}) eq 'HASH') {
9767: foreach my $key (keys(%{$domconfig{'contacts'}})) {
9768: $currsetting{$key} = $domconfig{'contacts'}{$key};
9769: }
9770: }
1.134 raeburn 9771: my (%others,%to,%bcc);
1.28 raeburn 9772: my @contacts = ('supportemail','adminemail');
1.102 raeburn 9773: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203 raeburn 9774: 'requestsmail','updatesmail','idconflictsmail');
9775: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 9776: foreach my $type (@mailings) {
9777: @{$newsetting{$type}} =
9778: &Apache::loncommon::get_env_multiple('form.'.$type);
9779: foreach my $item (@contacts) {
9780: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
9781: $contacts_hash{contacts}{$type}{$item} = 1;
9782: } else {
9783: $contacts_hash{contacts}{$type}{$item} = 0;
9784: }
9785: }
9786: $others{$type} = $env{'form.'.$type.'_others'};
9787: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 9788: if ($type eq 'helpdeskmail') {
9789: $bcc{$type} = $env{'form.'.$type.'_bcc'};
9790: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
9791: }
1.28 raeburn 9792: }
9793: foreach my $item (@contacts) {
9794: $to{$item} = $env{'form.'.$item};
9795: $contacts_hash{'contacts'}{$item} = $to{$item};
9796: }
1.203 raeburn 9797: foreach my $item (@toggles) {
9798: if ($env{'form.'.$item} =~ /^(0|1)$/) {
9799: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
9800: }
9801: }
1.28 raeburn 9802: if (keys(%currsetting) > 0) {
9803: foreach my $item (@contacts) {
9804: if ($to{$item} ne $currsetting{$item}) {
9805: $changes{$item} = 1;
9806: }
9807: }
9808: foreach my $type (@mailings) {
9809: foreach my $item (@contacts) {
9810: if (ref($currsetting{$type}) eq 'HASH') {
9811: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
9812: push(@{$changes{$type}},$item);
9813: }
9814: } else {
9815: push(@{$changes{$type}},@{$newsetting{$type}});
9816: }
9817: }
9818: if ($others{$type} ne $currsetting{$type}{'others'}) {
9819: push(@{$changes{$type}},'others');
9820: }
1.134 raeburn 9821: if ($type eq 'helpdeskmail') {
9822: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
9823: push(@{$changes{$type}},'bcc');
9824: }
9825: }
1.28 raeburn 9826: }
9827: } else {
9828: my %default;
9829: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
9830: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
9831: $default{'errormail'} = 'adminemail';
9832: $default{'packagesmail'} = 'adminemail';
9833: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 9834: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 9835: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 9836: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 9837: foreach my $item (@contacts) {
9838: if ($to{$item} ne $default{$item}) {
9839: $changes{$item} = 1;
1.203 raeburn 9840: }
1.28 raeburn 9841: }
9842: foreach my $type (@mailings) {
9843: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
9844:
9845: push(@{$changes{$type}},@{$newsetting{$type}});
9846: }
9847: if ($others{$type} ne '') {
9848: push(@{$changes{$type}},'others');
1.134 raeburn 9849: }
9850: if ($type eq 'helpdeskmail') {
9851: if ($bcc{$type} ne '') {
9852: push(@{$changes{$type}},'bcc');
9853: }
9854: }
1.28 raeburn 9855: }
9856: }
1.203 raeburn 9857: foreach my $item (@toggles) {
9858: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
9859: $changes{$item} = 1;
9860: } elsif ((!$env{'form.'.$item}) &&
9861: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
9862: $changes{$item} = 1;
9863: }
9864: }
1.28 raeburn 9865: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
9866: $dom);
9867: if ($putresult eq 'ok') {
9868: if (keys(%changes) > 0) {
1.205 raeburn 9869: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9870: if (ref($lastactref) eq 'HASH') {
9871: $lastactref->{'domainconfig'} = 1;
9872: }
1.28 raeburn 9873: my ($titles,$short_titles) = &contact_titles();
9874: $resulttext = &mt('Changes made:').'<ul>';
9875: foreach my $item (@contacts) {
9876: if ($changes{$item}) {
9877: $resulttext .= '<li>'.$titles->{$item}.
9878: &mt(' set to: ').
9879: '<span class="LC_cusr_emph">'.
9880: $to{$item}.'</span></li>';
9881: }
9882: }
9883: foreach my $type (@mailings) {
9884: if (ref($changes{$type}) eq 'ARRAY') {
9885: $resulttext .= '<li>'.$titles->{$type}.': ';
9886: my @text;
9887: foreach my $item (@{$newsetting{$type}}) {
9888: push(@text,$short_titles->{$item});
9889: }
9890: if ($others{$type} ne '') {
9891: push(@text,$others{$type});
9892: }
9893: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 9894: join(', ',@text).'</span>';
9895: if ($type eq 'helpdeskmail') {
9896: if ($bcc{$type} ne '') {
9897: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
9898: }
9899: }
9900: $resulttext .= '</li>';
1.28 raeburn 9901: }
9902: }
1.203 raeburn 9903: my @offon = ('off','on');
9904: if ($changes{'reporterrors'}) {
9905: $resulttext .= '<li>'.
9906: &mt('E-mail error reports to [_1] set to "'.
9907: $offon[$env{'form.reporterrors'}].'".',
9908: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9909: &mt('LON-CAPA core group - MSU'),600,500)).
9910: '</li>';
9911: }
9912: if ($changes{'reportupdates'}) {
9913: $resulttext .= '<li>'.
9914: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
9915: $offon[$env{'form.reportupdates'}].'".',
9916: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9917: &mt('LON-CAPA core group - MSU'),600,500)).
9918: '</li>';
9919: }
1.28 raeburn 9920: $resulttext .= '</ul>';
9921: } else {
1.34 raeburn 9922: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 9923: }
9924: } else {
9925: $resulttext = '<span class="LC_error">'.
9926: &mt('An error occurred: [_1].',$putresult).'</span>';
9927: }
9928: return $resulttext;
9929: }
9930:
9931: sub modify_usercreation {
1.27 raeburn 9932: my ($dom,%domconfig) = @_;
1.224 raeburn 9933: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 9934: my $warningmsg;
1.27 raeburn 9935: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9936: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 9937: if ($key eq 'cancreate') {
9938: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9939: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
9940: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.269 raeburn 9941: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
9942: ($item eq 'recaptchaversion')) {
1.224 raeburn 9943: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9944: } else {
9945: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9946: }
9947: }
9948: }
9949: } elsif ($key eq 'email_rule') {
9950: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9951: } else {
9952: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
9953: }
1.27 raeburn 9954: }
9955: }
9956: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 9957: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 9958: my @contexts = ('author','course','requestcrs');
1.34 raeburn 9959: foreach my $item(@contexts) {
1.224 raeburn 9960: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 9961: }
1.34 raeburn 9962: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9963: foreach my $item (@contexts) {
1.224 raeburn 9964: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
9965: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 9966: }
1.27 raeburn 9967: }
1.34 raeburn 9968: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
9969: foreach my $item (@contexts) {
1.43 raeburn 9970: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 9971: if ($cancreate{$item} ne 'any') {
9972: push(@{$changes{'cancreate'}},$item);
9973: }
9974: } else {
9975: if ($cancreate{$item} ne 'none') {
9976: push(@{$changes{'cancreate'}},$item);
9977: }
1.27 raeburn 9978: }
9979: }
9980: } else {
1.43 raeburn 9981: foreach my $item (@contexts) {
1.34 raeburn 9982: push(@{$changes{'cancreate'}},$item);
9983: }
1.27 raeburn 9984: }
1.34 raeburn 9985:
1.27 raeburn 9986: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
9987: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
9988: if (!grep(/^\Q$type\E$/,@username_rule)) {
9989: push(@{$changes{'username_rule'}},$type);
9990: }
9991: }
9992: foreach my $type (@username_rule) {
9993: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
9994: push(@{$changes{'username_rule'}},$type);
9995: }
9996: }
9997: } else {
9998: push(@{$changes{'username_rule'}},@username_rule);
9999: }
10000:
1.32 raeburn 10001: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
10002: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
10003: if (!grep(/^\Q$type\E$/,@id_rule)) {
10004: push(@{$changes{'id_rule'}},$type);
10005: }
10006: }
10007: foreach my $type (@id_rule) {
10008: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
10009: push(@{$changes{'id_rule'}},$type);
10010: }
10011: }
10012: } else {
10013: push(@{$changes{'id_rule'}},@id_rule);
10014: }
10015:
1.43 raeburn 10016: my @authen_contexts = ('author','course','domain');
1.28 raeburn 10017: my @authtypes = ('int','krb4','krb5','loc');
10018: my %authhash;
1.43 raeburn 10019: foreach my $item (@authen_contexts) {
1.28 raeburn 10020: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
10021: foreach my $auth (@authtypes) {
10022: if (grep(/^\Q$auth\E$/,@authallowed)) {
10023: $authhash{$item}{$auth} = 1;
10024: } else {
10025: $authhash{$item}{$auth} = 0;
10026: }
10027: }
10028: }
10029: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 10030: foreach my $item (@authen_contexts) {
1.28 raeburn 10031: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
10032: foreach my $auth (@authtypes) {
10033: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
10034: push(@{$changes{'authtypes'}},$item);
10035: last;
10036: }
10037: }
10038: }
10039: }
10040: } else {
1.43 raeburn 10041: foreach my $item (@authen_contexts) {
1.28 raeburn 10042: push(@{$changes{'authtypes'}},$item);
10043: }
10044: }
10045:
1.224 raeburn 10046: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
10047: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
10048: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
10049: $save_usercreate{'id_rule'} = \@id_rule;
10050: $save_usercreate{'username_rule'} = \@username_rule,
10051: $save_usercreate{'authtypes'} = \%authhash;
10052:
1.27 raeburn 10053: my %usercreation_hash = (
1.224 raeburn 10054: usercreation => \%save_usercreate,
10055: );
1.27 raeburn 10056:
10057: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
10058: $dom);
1.50 raeburn 10059:
1.224 raeburn 10060: if ($putresult eq 'ok') {
10061: if (keys(%changes) > 0) {
10062: $resulttext = &mt('Changes made:').'<ul>';
10063: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10064: my %lt = &usercreation_types();
10065: foreach my $type (@{$changes{'cancreate'}}) {
10066: my $chgtext = $lt{$type}.', ';
10067: if ($cancreate{$type} eq 'none') {
10068: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
10069: } elsif ($cancreate{$type} eq 'any') {
10070: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
10071: } elsif ($cancreate{$type} eq 'official') {
10072: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
10073: } elsif ($cancreate{$type} eq 'unofficial') {
10074: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
10075: }
10076: $resulttext .= '<li>'.$chgtext.'</li>';
10077: }
10078: }
10079: if (ref($changes{'username_rule'}) eq 'ARRAY') {
10080: my ($rules,$ruleorder) =
10081: &Apache::lonnet::inst_userrules($dom,'username');
10082: my $chgtext = '<ul>';
10083: foreach my $type (@username_rule) {
10084: if (ref($rules->{$type}) eq 'HASH') {
10085: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
10086: }
10087: }
10088: $chgtext .= '</ul>';
10089: if (@username_rule > 0) {
10090: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
10091: } else {
10092: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
10093: }
10094: }
10095: if (ref($changes{'id_rule'}) eq 'ARRAY') {
10096: my ($idrules,$idruleorder) =
10097: &Apache::lonnet::inst_userrules($dom,'id');
10098: my $chgtext = '<ul>';
10099: foreach my $type (@id_rule) {
10100: if (ref($idrules->{$type}) eq 'HASH') {
10101: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
10102: }
10103: }
10104: $chgtext .= '</ul>';
10105: if (@id_rule > 0) {
10106: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
10107: } else {
10108: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
10109: }
10110: }
10111: my %authname = &authtype_names();
10112: my %context_title = &context_names();
10113: if (ref($changes{'authtypes'}) eq 'ARRAY') {
10114: my $chgtext = '<ul>';
10115: foreach my $type (@{$changes{'authtypes'}}) {
10116: my @allowed;
10117: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
10118: foreach my $auth (@authtypes) {
10119: if ($authhash{$type}{$auth}) {
10120: push(@allowed,$authname{$auth});
10121: }
10122: }
10123: if (@allowed > 0) {
10124: $chgtext .= join(', ',@allowed).'</li>';
10125: } else {
10126: $chgtext .= &mt('none').'</li>';
10127: }
10128: }
10129: $chgtext .= '</ul>';
10130: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
10131: $resulttext .= '</li>';
10132: }
10133: $resulttext .= '</ul>';
10134: } else {
10135: $resulttext = &mt('No changes made to user creation settings');
10136: }
10137: } else {
10138: $resulttext = '<span class="LC_error">'.
10139: &mt('An error occurred: [_1]',$putresult).'</span>';
10140: }
10141: if ($warningmsg ne '') {
10142: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10143: }
10144: return $resulttext;
10145: }
10146:
10147: sub modify_selfcreation {
10148: my ($dom,%domconfig) = @_;
10149: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
10150: my (%save_usercreate,%save_usermodify);
1.228 raeburn 10151: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10152: if (ref($types) eq 'ARRAY') {
10153: $usertypes->{'default'} = $othertitle;
10154: push(@{$types},'default');
10155: }
1.224 raeburn 10156: #
10157: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
10158: #
10159: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10160: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
10161: if ($key eq 'cancreate') {
10162: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
10163: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
10164: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
10165: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.269 raeburn 10166: ($item eq 'recaptchaversion') ||
1.236 raeburn 10167: ($item eq 'emailusername') || ($item eq 'notify') ||
1.240 raeburn 10168: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.224 raeburn 10169: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10170: } else {
10171: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10172: }
10173: }
10174: }
10175: } elsif ($key eq 'email_rule') {
10176: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
10177: } else {
10178: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
10179: }
10180: }
10181: }
10182: #
10183: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
10184: #
10185: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10186: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
10187: if ($key eq 'selfcreate') {
10188: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
10189: } else {
10190: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
10191: }
10192: }
10193: }
10194:
10195: my @contexts = ('selfcreate');
10196: @{$cancreate{'selfcreate'}} = ();
10197: %{$cancreate{'emailusername'}} = ();
10198: @{$cancreate{'statustocreate'}} = ();
1.236 raeburn 10199: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 10200: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 10201: my %selfcreatetypes = (
10202: sso => 'users authenticated by institutional single sign on',
10203: login => 'users authenticated by institutional log-in',
1.236 raeburn 10204: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 10205: );
1.224 raeburn 10206: #
10207: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
10208: # is permitted.
10209: #
1.236 raeburn 10210:
10211: my @statuses;
10212: if (ref($domconfig{'inststatus'}) eq 'HASH') {
10213: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
10214: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
10215: }
10216: }
10217: push(@statuses,'default');
10218:
1.228 raeburn 10219: foreach my $item ('login','sso','email') {
1.224 raeburn 10220: if ($item eq 'email') {
1.236 raeburn 10221: if ($env{'form.cancreate_email'}) {
1.224 raeburn 10222: push(@{$cancreate{'selfcreate'}},'email');
1.236 raeburn 10223: push(@contexts,'selfcreateprocessing');
10224: foreach my $type (@statuses) {
10225: if ($type eq 'default') {
10226: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
10227: } else {
10228: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
10229: }
10230: }
1.224 raeburn 10231: }
10232: } else {
10233: if ($env{'form.cancreate_'.$item}) {
10234: push(@{$cancreate{'selfcreate'}},$item);
10235: }
10236: }
10237: }
10238: my (@email_rule,%userinfo,%savecaptcha);
10239: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
10240: #
1.228 raeburn 10241: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
10242: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 10243: #
1.236 raeburn 10244:
1.244 raeburn 10245: if ($env{'form.cancreate_email'}) {
1.228 raeburn 10246: push(@contexts,'emailusername');
10247: if (ref($types) eq 'ARRAY') {
10248: foreach my $type (@{$types}) {
10249: if (ref($infofields) eq 'ARRAY') {
10250: foreach my $field (@{$infofields}) {
10251: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
10252: $cancreate{'emailusername'}{$type}{$field} = $1;
10253: }
10254: }
1.224 raeburn 10255: }
10256: }
10257: }
10258: #
10259: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
10260: # queued requests for self-creation of account using e-mail address as username
10261: #
10262:
10263: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
10264: @approvalnotify = sort(@approvalnotify);
10265: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
10266: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10267: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
10268: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
10269: push(@{$changes{'cancreate'}},'notify');
10270: }
10271: } else {
10272: if ($cancreate{'notify'}{'approval'}) {
10273: push(@{$changes{'cancreate'}},'notify');
10274: }
10275: }
10276: } elsif ($cancreate{'notify'}{'approval'}) {
10277: push(@{$changes{'cancreate'}},'notify');
10278: }
10279:
10280: #
10281: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
10282: #
10283: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
10284: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
10285: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
10286: if (@{$curr_usercreation{'email_rule'}} > 0) {
10287: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
10288: if (!grep(/^\Q$type\E$/,@email_rule)) {
10289: push(@{$changes{'email_rule'}},$type);
10290: }
10291: }
10292: }
10293: if (@email_rule > 0) {
10294: foreach my $type (@email_rule) {
10295: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
10296: push(@{$changes{'email_rule'}},$type);
10297: }
10298: }
10299: }
10300: } elsif (@email_rule > 0) {
10301: push(@{$changes{'email_rule'}},@email_rule);
10302: }
10303: }
10304: #
1.236 raeburn 10305: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 10306: # institutional log-in.
10307: #
10308: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
10309: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10310: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
10311: ($domdefaults{'auth_def'} eq 'localauth'))) {
10312: $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.').' '.
10313: &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.');
10314: }
10315: }
10316: my @fields = ('lastname','firstname','middlename','generation',
10317: 'permanentemail','id');
1.240 raeburn 10318: my @shibfields = (@fields,'inststatus');
1.224 raeburn 10319: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10320: #
10321: # Where usernames may created for institutional log-in and/or institutional single sign on:
10322: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
10323: # may self-create accounts
10324: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
10325: # which the user may supply, if institutional data is unavailable.
10326: #
10327: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
10328: if (ref($types) eq 'ARRAY') {
1.228 raeburn 10329: if (@{$types} > 1) {
1.224 raeburn 10330: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
10331: push(@contexts,'statustocreate');
10332: } else {
10333: undef($cancreate{'statustocreate'});
10334: }
10335: foreach my $type (@{$types}) {
10336: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
10337: foreach my $field (@fields) {
10338: if (grep(/^\Q$field\E$/,@modifiable)) {
10339: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
10340: } else {
10341: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
10342: }
10343: }
10344: }
10345: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
10346: foreach my $type (@{$types}) {
10347: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
10348: foreach my $field (@fields) {
10349: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
10350: $curr_usermodify{'selfcreate'}{$type}{$field}) {
10351: push(@{$changes{'selfcreate'}},$type);
10352: last;
10353: }
10354: }
10355: }
10356: }
10357: } else {
10358: foreach my $type (@{$types}) {
10359: push(@{$changes{'selfcreate'}},$type);
10360: }
10361: }
10362: }
1.240 raeburn 10363: foreach my $field (@shibfields) {
10364: if ($env{'form.shibenv_'.$field} ne '') {
10365: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
10366: }
10367: }
10368: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10369: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
10370: foreach my $field (@shibfields) {
10371: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
10372: push(@{$changes{'cancreate'}},'shibenv');
10373: }
10374: }
10375: } else {
10376: foreach my $field (@shibfields) {
10377: if ($env{'form.shibenv_'.$field}) {
10378: push(@{$changes{'cancreate'}},'shibenv');
10379: last;
10380: }
10381: }
10382: }
10383: }
1.224 raeburn 10384: }
10385: foreach my $item (@contexts) {
10386: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
10387: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
10388: if (ref($cancreate{$item}) eq 'ARRAY') {
10389: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
10390: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10391: push(@{$changes{'cancreate'}},$item);
10392: }
10393: }
10394: }
10395: }
10396: if (ref($cancreate{$item}) eq 'ARRAY') {
10397: foreach my $type (@{$cancreate{$item}}) {
10398: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
10399: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10400: push(@{$changes{'cancreate'}},$item);
10401: }
10402: }
10403: }
10404: }
10405: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
10406: if (ref($cancreate{$item}) eq 'HASH') {
10407: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228 raeburn 10408: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
10409: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
10410: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
10411: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10412: push(@{$changes{'cancreate'}},$item);
10413: }
10414: }
10415: }
1.236 raeburn 10416: } elsif ($item eq 'selfcreateprocessing') {
10417: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
10418: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10419: push(@{$changes{'cancreate'}},$item);
10420: }
10421: }
1.228 raeburn 10422: } else {
10423: if (!$cancreate{$item}{$curr}) {
10424: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10425: push(@{$changes{'cancreate'}},$item);
10426: }
1.224 raeburn 10427: }
10428: }
10429: }
10430: foreach my $field (keys(%{$cancreate{$item}})) {
1.228 raeburn 10431: if (ref($cancreate{$item}{$field}) eq 'HASH') {
10432: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
10433: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
10434: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
10435: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10436: push(@{$changes{'cancreate'}},$item);
10437: }
10438: }
10439: } else {
10440: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10441: push(@{$changes{'cancreate'}},$item);
10442: }
10443: }
10444: }
1.236 raeburn 10445: } elsif ($item eq 'selfcreateprocessing') {
10446: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
10447: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10448: push(@{$changes{'cancreate'}},$item);
10449: }
10450: }
1.228 raeburn 10451: } else {
10452: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
10453: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10454: push(@{$changes{'cancreate'}},$item);
10455: }
1.224 raeburn 10456: }
10457: }
10458: }
10459: }
10460: } elsif ($curr_usercreation{'cancreate'}{$item}) {
10461: if (ref($cancreate{$item}) eq 'ARRAY') {
10462: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
10463: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10464: push(@{$changes{'cancreate'}},$item);
10465: }
10466: }
10467: } elsif (ref($cancreate{$item}) eq 'HASH') {
10468: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
10469: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10470: push(@{$changes{'cancreate'}},$item);
10471: }
10472: }
10473: }
10474: } elsif ($item eq 'emailusername') {
1.228 raeburn 10475: if (ref($cancreate{$item}) eq 'HASH') {
10476: foreach my $type (keys(%{$cancreate{$item}})) {
10477: if (ref($cancreate{$item}{$type}) eq 'HASH') {
10478: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
10479: if ($cancreate{$item}{$type}{$field}) {
10480: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10481: push(@{$changes{'cancreate'}},$item);
10482: }
10483: last;
10484: }
10485: }
10486: }
10487: }
1.224 raeburn 10488: }
10489: }
10490: }
10491: #
10492: # Populate %save_usercreate hash with updates to self-creation configuration.
10493: #
10494: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
10495: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 10496: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 10497: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
10498: if (ref($cancreate{'notify'}) eq 'HASH') {
10499: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
10500: }
1.236 raeburn 10501: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
10502: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
10503: }
1.224 raeburn 10504: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10505: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
10506: }
1.240 raeburn 10507: if (ref($cancreate{'shibenv'}) eq 'HASH') {
10508: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
10509: }
1.224 raeburn 10510: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
10511: $save_usercreate{'emailrule'} = \@email_rule;
10512:
10513: my %userconfig_hash = (
10514: usercreation => \%save_usercreate,
10515: usermodification => \%save_usermodify,
10516: );
10517: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
10518: $dom);
10519: #
10520: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
10521: #
1.27 raeburn 10522: if ($putresult eq 'ok') {
10523: if (keys(%changes) > 0) {
10524: $resulttext = &mt('Changes made:').'<ul>';
10525: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 10526: my %lt = &selfcreation_types();
1.34 raeburn 10527: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 10528: my $chgtext;
1.45 raeburn 10529: if ($type eq 'selfcreate') {
1.50 raeburn 10530: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 10531: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 10532: } else {
1.224 raeburn 10533: $chgtext .= &mt('Self-creation of a new account is permitted for:').
10534: '<ul>';
1.50 raeburn 10535: foreach my $case (@{$cancreate{$type}}) {
10536: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
10537: }
10538: $chgtext .= '</ul>';
1.100 raeburn 10539: if (ref($cancreate{$type}) eq 'ARRAY') {
10540: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
10541: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10542: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 raeburn 10543: $chgtext .= '<br />'.
10544: '<span class="LC_warning">'.
10545: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10546: '</span>';
1.100 raeburn 10547: }
10548: }
10549: }
10550: }
1.43 raeburn 10551: }
1.240 raeburn 10552: } elsif ($type eq 'shibenv') {
10553: if (keys(%{$cancreate{$type}}) == 0) {
10554: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
10555: } else {
10556: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
10557: '<ul>';
10558: foreach my $field (@shibfields) {
10559: next if ($cancreate{$type}{$field} eq '');
10560: if ($field eq 'inststatus') {
10561: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
10562: } else {
10563: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
10564: }
10565: }
10566: $chgtext .= '</ul>';
10567: }
1.93 raeburn 10568: } elsif ($type eq 'statustocreate') {
1.96 raeburn 10569: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
10570: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
10571: if (@{$cancreate{'selfcreate'}} > 0) {
10572: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 10573: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 10574: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 10575: $chgtext .= '<br />'.
10576: '<span class="LC_warning">'.
10577: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10578: '</span>';
10579: }
1.96 raeburn 10580: } elsif (ref($usertypes) eq 'HASH') {
10581: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 10582: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
10583: } else {
10584: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
10585: }
10586: $chgtext .= '<ul>';
10587: foreach my $case (@{$cancreate{$type}}) {
10588: if ($case eq 'default') {
10589: $chgtext .= '<li>'.$othertitle.'</li>';
10590: } else {
10591: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 10592: }
10593: }
1.100 raeburn 10594: $chgtext .= '</ul>';
10595: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 10596: $chgtext .= '<br /><span class="LC_warning">'.
10597: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
10598: '</span>';
1.100 raeburn 10599: }
10600: }
10601: } else {
10602: if (@{$cancreate{$type}} == 0) {
10603: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
10604: } else {
10605: $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 10606: }
10607: }
10608: }
1.236 raeburn 10609: } elsif ($type eq 'selfcreateprocessing') {
10610: my %choices = &Apache::lonlocal::texthash (
10611: automatic => 'Automatic approval',
10612: approval => 'Queued for approval',
10613: );
10614: if (@statuses > 1) {
10615: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
10616: '<ul>';
10617: foreach my $type (@statuses) {
10618: if ($type eq 'default') {
10619: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10620: } else {
10621: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10622: }
10623: }
10624: $chgtext .= '</ul>';
10625: } else {
10626: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
10627: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
10628: }
1.165 raeburn 10629: } elsif ($type eq 'captcha') {
1.224 raeburn 10630: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 10631: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
10632: } else {
10633: my %captchas = &captcha_phrases();
1.224 raeburn 10634: if ($captchas{$savecaptcha{$type}}) {
10635: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 10636: } else {
1.210 raeburn 10637: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 10638: }
10639: }
10640: } elsif ($type eq 'recaptchakeys') {
10641: my ($privkey,$pubkey);
1.224 raeburn 10642: if (ref($savecaptcha{$type}) eq 'HASH') {
10643: $pubkey = $savecaptcha{$type}{'public'};
10644: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 10645: }
10646: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
10647: if (!$pubkey) {
10648: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
10649: } else {
10650: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
10651: }
10652: if (!$privkey) {
10653: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
10654: } else {
10655: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
10656: }
10657: $chgtext .= '</ul>';
1.269 raeburn 10658: } elsif ($type eq 'recaptchaversion') {
10659: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 10660: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 10661: }
1.224 raeburn 10662: } elsif ($type eq 'emailusername') {
10663: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228 raeburn 10664: if (ref($types) eq 'ARRAY') {
10665: foreach my $type (@{$types}) {
10666: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
10667: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.245 raeburn 10668: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.228 raeburn 10669: '<ul>';
10670: foreach my $field (@{$infofields}) {
10671: if ($cancreate{'emailusername'}{$type}{$field}) {
10672: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
10673: }
10674: }
1.245 raeburn 10675: $chgtext .= '</ul>';
10676: } else {
10677: $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',"'$usertypes->{$type}'").'<br />';
1.228 raeburn 10678: }
10679: } else {
1.245 raeburn 10680: $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',"'$usertypes->{$type}'").'<br />';
1.224 raeburn 10681: }
10682: }
10683: }
10684: }
10685: } elsif ($type eq 'notify') {
10686: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
10687: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10688: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
10689: if ($cancreate{'notify'}{'approval'}) {
10690: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
10691: }
10692: }
1.43 raeburn 10693: }
1.34 raeburn 10694: }
1.224 raeburn 10695: if ($chgtext) {
10696: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 10697: }
10698: }
10699: }
1.43 raeburn 10700: if (ref($changes{'email_rule'}) eq 'ARRAY') {
10701: my ($emailrules,$emailruleorder) =
10702: &Apache::lonnet::inst_userrules($dom,'email');
10703: my $chgtext = '<ul>';
10704: foreach my $type (@email_rule) {
10705: if (ref($emailrules->{$type}) eq 'HASH') {
10706: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
10707: }
10708: }
10709: $chgtext .= '</ul>';
10710: if (@email_rule > 0) {
1.224 raeburn 10711: $resulttext .= '<li>'.
10712: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
10713: $chgtext.
10714: '</li>';
1.43 raeburn 10715: } else {
1.224 raeburn 10716: $resulttext .= '<li>'.
10717: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
10718: '</li>';
1.43 raeburn 10719: }
10720: }
1.224 raeburn 10721: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
10722: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
10723: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10724: foreach my $type (@{$changes{'selfcreate'}}) {
10725: my $typename = $type;
10726: if (ref($usertypes) eq 'HASH') {
10727: if ($usertypes->{$type} ne '') {
10728: $typename = $usertypes->{$type};
10729: }
10730: }
10731: my @modifiable;
10732: $resulttext .= '<li>'.
10733: &mt('Self-creation of account by users with status: [_1]',
10734: '<span class="LC_cusr_emph">'.$typename.'</span>').
10735: ' - '.&mt('modifiable fields (if institutional data blank): ');
10736: foreach my $field (@fields) {
10737: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
10738: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 10739: }
10740: }
1.224 raeburn 10741: if (@modifiable > 0) {
10742: $resulttext .= join(', ',@modifiable);
1.43 raeburn 10743: } else {
1.224 raeburn 10744: $resulttext .= &mt('none');
1.43 raeburn 10745: }
1.224 raeburn 10746: $resulttext .= '</li>';
1.28 raeburn 10747: }
1.224 raeburn 10748: $resulttext .= '</ul></li>';
1.28 raeburn 10749: }
1.27 raeburn 10750: $resulttext .= '</ul>';
10751: } else {
1.224 raeburn 10752: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 10753: }
10754: } else {
10755: $resulttext = '<span class="LC_error">'.
1.23 raeburn 10756: &mt('An error occurred: [_1]',$putresult).'</span>';
10757: }
1.43 raeburn 10758: if ($warningmsg ne '') {
10759: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10760: }
1.23 raeburn 10761: return $resulttext;
10762: }
10763:
1.165 raeburn 10764: sub process_captcha {
10765: my ($container,$changes,$newsettings,$current) = @_;
10766: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
10767: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
10768: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
10769: $newsettings->{'captcha'} = 'original';
10770: }
10771: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 10772: if ($container eq 'cancreate') {
1.169 raeburn 10773: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10774: push(@{$changes->{'cancreate'}},'captcha');
10775: } elsif (!defined($changes->{'cancreate'})) {
10776: $changes->{'cancreate'} = ['captcha'];
10777: }
10778: } else {
10779: $changes->{'captcha'} = 1;
1.165 raeburn 10780: }
10781: }
1.269 raeburn 10782: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 10783: if ($newsettings->{'captcha'} eq 'recaptcha') {
10784: $newpub = $env{'form.'.$container.'_recaptchapub'};
10785: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 10786: $newpub =~ s/[^\w\-]//g;
10787: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 10788: $newsettings->{'recaptchakeys'} = {
10789: public => $newpub,
10790: private => $newpriv,
10791: };
1.269 raeburn 10792: $newversion = $env{'form.'.$container.'_recaptchaversion'};
10793: $newversion =~ s/\D//g;
10794: if ($newversion ne '2') {
10795: $newversion = 1;
10796: }
10797: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 10798: }
10799: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
10800: $currpub = $current->{'recaptchakeys'}{'public'};
10801: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 10802: unless ($newsettings->{'captcha'} eq 'recaptcha') {
10803: $newsettings->{'recaptchakeys'} = {
10804: public => '',
10805: private => '',
10806: }
10807: }
1.165 raeburn 10808: }
1.269 raeburn 10809: if ($current->{'captcha'} eq 'recaptcha') {
10810: $currversion = $current->{'recaptchaversion'};
10811: if ($currversion ne '2') {
10812: $currversion = 1;
10813: }
10814: }
10815: if ($currversion ne $newversion) {
10816: if ($container eq 'cancreate') {
10817: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10818: push(@{$changes->{'cancreate'}},'recaptchaversion');
10819: } elsif (!defined($changes->{'cancreate'})) {
10820: $changes->{'cancreate'} = ['recaptchaversion'];
10821: }
10822: } else {
10823: $changes->{'recaptchaversion'} = 1;
10824: }
10825: }
1.165 raeburn 10826: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 10827: if ($container eq 'cancreate') {
10828: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10829: push(@{$changes->{'cancreate'}},'recaptchakeys');
10830: } elsif (!defined($changes->{'cancreate'})) {
10831: $changes->{'cancreate'} = ['recaptchakeys'];
10832: }
10833: } else {
1.210 raeburn 10834: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 10835: }
10836: }
10837: return;
10838: }
10839:
1.33 raeburn 10840: sub modify_usermodification {
10841: my ($dom,%domconfig) = @_;
1.224 raeburn 10842: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 10843: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10844: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 10845: if ($key eq 'selfcreate') {
10846: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
10847: } else {
10848: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
10849: }
1.33 raeburn 10850: }
10851: }
1.224 raeburn 10852: my @contexts = ('author','course');
1.33 raeburn 10853: my %context_title = (
10854: author => 'In author context',
10855: course => 'In course context',
10856: );
10857: my @fields = ('lastname','firstname','middlename','generation',
10858: 'permanentemail','id');
10859: my %roles = (
10860: author => ['ca','aa'],
10861: course => ['st','ep','ta','in','cr'],
10862: );
10863: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10864: foreach my $context (@contexts) {
10865: foreach my $role (@{$roles{$context}}) {
10866: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
10867: foreach my $item (@fields) {
10868: if (grep(/^\Q$item\E$/,@modifiable)) {
10869: $modifyhash{$context}{$role}{$item} = 1;
10870: } else {
10871: $modifyhash{$context}{$role}{$item} = 0;
10872: }
10873: }
10874: }
10875: if (ref($curr_usermodification{$context}) eq 'HASH') {
10876: foreach my $role (@{$roles{$context}}) {
10877: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
10878: foreach my $field (@fields) {
10879: if ($modifyhash{$context}{$role}{$field} ne
10880: $curr_usermodification{$context}{$role}{$field}) {
10881: push(@{$changes{$context}},$role);
10882: last;
10883: }
10884: }
10885: }
10886: }
10887: } else {
10888: foreach my $context (@contexts) {
10889: foreach my $role (@{$roles{$context}}) {
10890: push(@{$changes{$context}},$role);
10891: }
10892: }
10893: }
10894: }
10895: my %usermodification_hash = (
10896: usermodification => \%modifyhash,
10897: );
10898: my $putresult = &Apache::lonnet::put_dom('configuration',
10899: \%usermodification_hash,$dom);
10900: if ($putresult eq 'ok') {
10901: if (keys(%changes) > 0) {
10902: $resulttext = &mt('Changes made: ').'<ul>';
10903: foreach my $context (@contexts) {
10904: if (ref($changes{$context}) eq 'ARRAY') {
10905: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
10906: if (ref($changes{$context}) eq 'ARRAY') {
10907: foreach my $role (@{$changes{$context}}) {
10908: my $rolename;
1.224 raeburn 10909: if ($role eq 'cr') {
10910: $rolename = &mt('Custom');
1.33 raeburn 10911: } else {
1.224 raeburn 10912: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 10913: }
10914: my @modifiable;
1.224 raeburn 10915: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 10916: foreach my $field (@fields) {
10917: if ($modifyhash{$context}{$role}{$field}) {
10918: push(@modifiable,$fieldtitles{$field});
10919: }
10920: }
10921: if (@modifiable > 0) {
10922: $resulttext .= join(', ',@modifiable);
10923: } else {
10924: $resulttext .= &mt('none');
10925: }
10926: $resulttext .= '</li>';
10927: }
10928: $resulttext .= '</ul></li>';
10929: }
10930: }
10931: }
10932: $resulttext .= '</ul>';
10933: } else {
10934: $resulttext = &mt('No changes made to user modification settings');
10935: }
10936: } else {
10937: $resulttext = '<span class="LC_error">'.
10938: &mt('An error occurred: [_1]',$putresult).'</span>';
10939: }
10940: return $resulttext;
10941: }
10942:
1.43 raeburn 10943: sub modify_defaults {
1.212 raeburn 10944: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 10945: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 10946: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 10947: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 10948: my @authtypes = ('internal','krb4','krb5','localauth');
10949: foreach my $item (@items) {
10950: $newvalues{$item} = $env{'form.'.$item};
10951: if ($item eq 'auth_def') {
10952: if ($newvalues{$item} ne '') {
10953: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
10954: push(@errors,$item);
10955: }
10956: }
10957: } elsif ($item eq 'lang_def') {
10958: if ($newvalues{$item} ne '') {
10959: if ($newvalues{$item} =~ /^(\w+)/) {
10960: my $langcode = $1;
1.103 raeburn 10961: if ($langcode ne 'x_chef') {
10962: if (code2language($langcode) eq '') {
10963: push(@errors,$item);
10964: }
1.43 raeburn 10965: }
10966: } else {
10967: push(@errors,$item);
10968: }
10969: }
1.54 raeburn 10970: } elsif ($item eq 'timezone_def') {
10971: if ($newvalues{$item} ne '') {
1.62 raeburn 10972: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 10973: push(@errors,$item);
10974: }
10975: }
1.68 raeburn 10976: } elsif ($item eq 'datelocale_def') {
10977: if ($newvalues{$item} ne '') {
10978: my @datelocale_ids = DateTime::Locale->ids();
10979: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
10980: push(@errors,$item);
10981: }
10982: }
1.141 raeburn 10983: } elsif ($item eq 'portal_def') {
10984: if ($newvalues{$item} ne '') {
10985: 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])\/?$/) {
10986: push(@errors,$item);
10987: }
10988: }
1.43 raeburn 10989: }
10990: if (grep(/^\Q$item\E$/,@errors)) {
10991: $newvalues{$item} = $domdefaults{$item};
10992: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
10993: $changes{$item} = 1;
10994: }
1.72 raeburn 10995: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 10996: }
10997: my %defaults_hash = (
1.72 raeburn 10998: defaults => \%newvalues,
10999: );
1.43 raeburn 11000: my $title = &defaults_titles();
1.236 raeburn 11001:
11002: my $currinststatus;
11003: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11004: $currinststatus = $domconfig{'inststatus'};
11005: } else {
11006: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11007: $currinststatus = {
11008: inststatustypes => $usertypes,
11009: inststatusorder => $types,
11010: inststatusguest => [],
11011: };
11012: }
11013: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
11014: my @allpos;
11015: my %guests;
11016: my %alltypes;
11017: my ($currtitles,$currguests,$currorder);
11018: if (ref($currinststatus) eq 'HASH') {
11019: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
11020: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
11021: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
11022: if ($currinststatus->{inststatustypes}->{$type} ne '') {
11023: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
11024: }
11025: }
11026: unless (grep(/^\Q$type\E$/,@todelete)) {
11027: my $position = $env{'form.inststatus_pos_'.$type};
11028: $position =~ s/\D+//g;
11029: $allpos[$position] = $type;
11030: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
11031: $alltypes{$type} =~ s/`//g;
11032: if ($env{'form.inststatus_guest_'.$type}) {
11033: $guests{$type} = 1;
11034: }
11035: }
11036: }
11037: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
11038: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
11039: }
11040: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
11041: $currtitles =~ s/,$//;
11042: }
11043: }
11044: if ($env{'form.addinststatus'}) {
11045: my $newtype = $env{'form.addinststatus'};
11046: $newtype =~ s/\W//g;
11047: unless (exists($alltypes{$newtype})) {
11048: if ($env{'form.addinststatus_guest'}) {
11049: $guests{$newtype} = 1;
11050: }
11051: $alltypes{$newtype} = $env{'form.addinststatus_title'};
11052: $alltypes{$newtype} =~ s/`//g;
11053: my $position = $env{'form.addinststatus_pos'};
11054: $position =~ s/\D+//g;
11055: if ($position ne '') {
11056: $allpos[$position] = $newtype;
11057: }
11058: }
11059: }
11060: my (@orderedstatus,@orderedguests);
11061: foreach my $type (@allpos) {
11062: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
11063: push(@orderedstatus,$type);
11064: if ($guests{$type}) {
11065: push(@orderedguests,$type);
11066: }
11067: }
11068: }
11069: foreach my $type (keys(%alltypes)) {
11070: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
11071: delete($alltypes{$type});
11072: }
11073: }
11074: $defaults_hash{'inststatus'} = {
11075: inststatustypes => \%alltypes,
11076: inststatusorder => \@orderedstatus,
11077: inststatusguest => \@orderedguests,
11078: };
11079: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
11080: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
11081: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
11082: }
11083: }
11084: if ($currorder ne join(',',@orderedstatus)) {
11085: $changes{'inststatus'}{'inststatusorder'} = 1;
11086: }
11087: if ($currguests ne join(',',@orderedguests)) {
11088: $changes{'inststatus'}{'inststatusguest'} = 1;
11089: }
11090: my $newtitles;
11091: foreach my $item (@orderedstatus) {
11092: $newtitles .= $alltypes{$item}.',';
11093: }
11094: $newtitles =~ s/,$//;
11095: if ($currtitles ne $newtitles) {
11096: $changes{'inststatus'}{'inststatustypes'} = 1;
11097: }
1.43 raeburn 11098: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
11099: $dom);
11100: if ($putresult eq 'ok') {
11101: if (keys(%changes) > 0) {
11102: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 11103: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 11104: 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";
11105: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 11106: if ($item eq 'inststatus') {
11107: if (ref($changes{'inststatus'}) eq 'HASH') {
11108: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
11109: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
11110: foreach my $type (@orderedstatus) {
11111: $resulttext .= $alltypes{$type}.', ';
11112: }
11113: $resulttext =~ s/, $//;
11114: $resulttext .= '</li>';
11115: }
11116: if ($changes{'inststatus'}{'inststatusguest'}) {
11117: $resulttext .= '<li>';
11118: if (@orderedguests) {
11119: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
11120: foreach my $type (@orderedguests) {
11121: $resulttext .= $alltypes{$type}.', ';
11122: }
11123: $resulttext =~ s/, $//;
11124: } else {
11125: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
11126: }
11127: $resulttext .= '</li>';
11128: }
11129: }
11130: } else {
11131: my $value = $env{'form.'.$item};
11132: if ($value eq '') {
11133: $value = &mt('none');
11134: } elsif ($item eq 'auth_def') {
11135: my %authnames = &authtype_names();
11136: my %shortauth = (
11137: internal => 'int',
11138: krb4 => 'krb4',
11139: krb5 => 'krb5',
11140: localauth => 'loc',
11141: );
11142: $value = $authnames{$shortauth{$value}};
11143: }
11144: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
11145: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 11146: }
11147: }
11148: $resulttext .= '</ul>';
11149: $mailmsgtext .= "\n";
11150: my $cachetime = 24*60*60;
1.72 raeburn 11151: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 11152: if (ref($lastactref) eq 'HASH') {
11153: $lastactref->{'domdefaults'} = 1;
11154: }
1.68 raeburn 11155: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 11156: my $notify = 1;
11157: if (ref($domconfig{'contacts'}) eq 'HASH') {
11158: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
11159: $notify = 0;
11160: }
11161: }
11162: if ($notify) {
11163: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
11164: "LON-CAPA Domain Settings Change - $dom",
11165: $mailmsgtext);
11166: }
1.54 raeburn 11167: }
1.43 raeburn 11168: } else {
1.54 raeburn 11169: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 11170: }
11171: } else {
11172: $resulttext = '<span class="LC_error">'.
11173: &mt('An error occurred: [_1]',$putresult).'</span>';
11174: }
11175: if (@errors > 0) {
11176: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
11177: foreach my $item (@errors) {
11178: $resulttext .= ' "'.$title->{$item}.'",';
11179: }
11180: $resulttext =~ s/,$//;
11181: }
11182: return $resulttext;
11183: }
11184:
1.46 raeburn 11185: sub modify_scantron {
1.205 raeburn 11186: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 11187: my ($resulttext,%confhash,%changes,$errors);
11188: my $custom = 'custom.tab';
11189: my $default = 'default.tab';
11190: my $servadm = $r->dir_config('lonAdmEMail');
11191: my ($configuserok,$author_ok,$switchserver) =
11192: &config_check($dom,$confname,$servadm);
11193: if ($env{'form.scantronformat.filename'} ne '') {
11194: my $error;
11195: if ($configuserok eq 'ok') {
11196: if ($switchserver) {
1.130 raeburn 11197: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 11198: } else {
11199: if ($author_ok eq 'ok') {
11200: my ($result,$scantronurl) =
11201: &publishlogo($r,'upload','scantronformat',$dom,
11202: $confname,'scantron','','',$custom);
11203: if ($result eq 'ok') {
11204: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 11205: $changes{'scantronformat'} = 1;
1.46 raeburn 11206: } else {
11207: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
11208: }
11209: } else {
11210: $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);
11211: }
11212: }
11213: } else {
11214: $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);
11215: }
11216: if ($error) {
11217: &Apache::lonnet::logthis($error);
11218: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11219: }
11220: }
1.48 raeburn 11221: if (ref($domconfig{'scantron'}) eq 'HASH') {
11222: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
11223: if ($env{'form.scantronformat_del'}) {
11224: $confhash{'scantron'}{'scantronformat'} = '';
11225: $changes{'scantronformat'} = 1;
1.46 raeburn 11226: }
11227: }
11228: }
11229: if (keys(%confhash) > 0) {
11230: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
11231: $dom);
11232: if ($putresult eq 'ok') {
11233: if (keys(%changes) > 0) {
1.48 raeburn 11234: if (ref($confhash{'scantron'}) eq 'HASH') {
11235: $resulttext = &mt('Changes made:').'<ul>';
11236: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 11237: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 11238: } else {
1.130 raeburn 11239: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 11240: }
1.48 raeburn 11241: $resulttext .= '</ul>';
11242: } else {
1.130 raeburn 11243: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 11244: }
11245: $resulttext .= '</ul>';
11246: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 11247: if (ref($lastactref) eq 'HASH') {
11248: $lastactref->{'domainconfig'} = 1;
11249: }
1.46 raeburn 11250: } else {
1.130 raeburn 11251: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 11252: }
11253: } else {
11254: $resulttext = '<span class="LC_error">'.
11255: &mt('An error occurred: [_1]',$putresult).'</span>';
11256: }
11257: } else {
1.130 raeburn 11258: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 11259: }
11260: if ($errors) {
11261: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11262: $errors.'</ul>';
11263: }
11264: return $resulttext;
11265: }
11266:
1.48 raeburn 11267: sub modify_coursecategories {
1.239 raeburn 11268: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 11269: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
11270: $cathash);
1.48 raeburn 11271: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 11272: my @catitems = ('unauth','auth');
11273: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 11274: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 11275: $cathash = $domconfig{'coursecategories'}{'cats'};
11276: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
11277: $changes{'togglecats'} = 1;
11278: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
11279: }
11280: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
11281: $changes{'categorize'} = 1;
11282: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
11283: }
1.120 raeburn 11284: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
11285: $changes{'togglecatscomm'} = 1;
11286: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
11287: }
11288: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
11289: $changes{'categorizecomm'} = 1;
11290: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 11291:
11292: }
11293: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
11294: $changes{'togglecatsplace'} = 1;
11295: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
11296: }
11297: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
11298: $changes{'categorizeplace'} = 1;
11299: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 11300: }
1.238 raeburn 11301: foreach my $item (@catitems) {
11302: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
11303: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
11304: $changes{$item} = 1;
11305: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
11306: }
11307: }
11308: }
1.57 raeburn 11309: } else {
11310: $changes{'togglecats'} = 1;
11311: $changes{'categorize'} = 1;
1.124 raeburn 11312: $changes{'togglecatscomm'} = 1;
11313: $changes{'categorizecomm'} = 1;
1.272 raeburn 11314: $changes{'togglecatsplace'} = 1;
11315: $changes{'categorizeplace'} = 1;
1.87 raeburn 11316: $domconfig{'coursecategories'} = {
11317: togglecats => $env{'form.togglecats'},
11318: categorize => $env{'form.categorize'},
1.124 raeburn 11319: togglecatscomm => $env{'form.togglecatscomm'},
11320: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 11321: togglecatsplace => $env{'form.togglecatsplace'},
11322: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 11323: };
1.238 raeburn 11324: foreach my $item (@catitems) {
11325: if ($env{'form.coursecat_'.$item} ne 'std') {
11326: $changes{$item} = 1;
11327: }
11328: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
11329: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
11330: }
11331: }
1.57 raeburn 11332: }
11333: if (ref($cathash) eq 'HASH') {
11334: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 11335: push (@deletecategory,'instcode::0');
11336: }
1.120 raeburn 11337: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
11338: push(@deletecategory,'communities::0');
11339: }
1.272 raeburn 11340: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
11341: push(@deletecategory,'placement::0');
11342: }
1.48 raeburn 11343: }
1.57 raeburn 11344: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
11345: if (ref($cathash) eq 'HASH') {
1.48 raeburn 11346: if (@deletecategory > 0) {
11347: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 11348: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 11349: foreach my $item (@deletecategory) {
1.57 raeburn 11350: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
11351: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 11352: $deletions{$item} = 1;
1.57 raeburn 11353: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 11354: }
11355: }
11356: }
1.57 raeburn 11357: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 11358: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 11359: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 11360: $reorderings{$item} = 1;
1.57 raeburn 11361: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 11362: }
11363: if ($env{'form.addcategory_name_'.$item} ne '') {
11364: my $newcat = $env{'form.addcategory_name_'.$item};
11365: my $newdepth = $depth+1;
11366: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11367: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 11368: $adds{$newitem} = 1;
11369: }
11370: if ($env{'form.subcat_'.$item} ne '') {
11371: my $newcat = $env{'form.subcat_'.$item};
11372: my $newdepth = $depth+1;
11373: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11374: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 11375: $adds{$newitem} = 1;
11376: }
11377: }
11378: }
11379: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 11380: if (ref($cathash) eq 'HASH') {
1.48 raeburn 11381: my $newitem = 'instcode::0';
1.57 raeburn 11382: if ($cathash->{$newitem} eq '') {
11383: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11384: $adds{$newitem} = 1;
11385: }
11386: } else {
11387: my $newitem = 'instcode::0';
1.57 raeburn 11388: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11389: $adds{$newitem} = 1;
11390: }
11391: }
1.120 raeburn 11392: if ($env{'form.communities'} eq '1') {
11393: if (ref($cathash) eq 'HASH') {
11394: my $newitem = 'communities::0';
11395: if ($cathash->{$newitem} eq '') {
11396: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11397: $adds{$newitem} = 1;
11398: }
11399: } else {
11400: my $newitem = 'communities::0';
11401: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11402: $adds{$newitem} = 1;
11403: }
11404: }
1.272 raeburn 11405: if ($env{'form.placement'} eq '1') {
11406: if (ref($cathash) eq 'HASH') {
11407: my $newitem = 'placement::0';
11408: if ($cathash->{$newitem} eq '') {
11409: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
11410: $adds{$newitem} = 1;
11411: }
11412: } else {
11413: my $newitem = 'placement::0';
11414: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
11415: $adds{$newitem} = 1;
11416: }
11417: }
1.48 raeburn 11418: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 11419: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 11420: ($env{'form.addcategory_name'} ne 'communities') &&
11421: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 11422: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
11423: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
11424: $adds{$newitem} = 1;
11425: }
1.48 raeburn 11426: }
1.57 raeburn 11427: my $putresult;
1.48 raeburn 11428: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11429: if (keys(%deletions) > 0) {
11430: foreach my $key (keys(%deletions)) {
11431: if ($predelallitems{$key} ne '') {
11432: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
11433: }
11434: }
11435: }
11436: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 11437: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 11438: if (ref($chkcats[0]) eq 'ARRAY') {
11439: my $depth = 0;
11440: my $chg = 0;
11441: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
11442: my $name = $chkcats[0][$i];
11443: my $item;
11444: if ($name eq '') {
11445: $chg ++;
11446: } else {
11447: $item = &escape($name).'::0';
11448: if ($chg) {
1.57 raeburn 11449: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 11450: }
11451: $depth ++;
1.57 raeburn 11452: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 11453: $depth --;
11454: }
11455: }
11456: }
1.57 raeburn 11457: }
11458: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11459: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 11460: if ($putresult eq 'ok') {
1.57 raeburn 11461: my %title = (
1.120 raeburn 11462: togglecats => 'Show/Hide a course in catalog',
11463: categorize => 'Assign a category to a course',
11464: togglecatscomm => 'Show/Hide a community in catalog',
11465: categorizecomm => 'Assign a category to a community',
1.57 raeburn 11466: );
11467: my %level = (
1.120 raeburn 11468: dom => 'set in Domain ("Modify Course/Community")',
11469: crs => 'set in Course ("Course Configuration")',
11470: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 11471: none => 'No catalog',
11472: std => 'Standard catalog',
11473: domonly => 'Domain-only catalog',
11474: codesrch => 'Code search form',
1.57 raeburn 11475: );
1.48 raeburn 11476: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 11477: if ($changes{'togglecats'}) {
11478: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
11479: }
11480: if ($changes{'categorize'}) {
11481: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 11482: }
1.120 raeburn 11483: if ($changes{'togglecatscomm'}) {
11484: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
11485: }
11486: if ($changes{'categorizecomm'}) {
11487: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
11488: }
1.238 raeburn 11489: if ($changes{'unauth'}) {
11490: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
11491: }
11492: if ($changes{'auth'}) {
11493: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
11494: }
1.57 raeburn 11495: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11496: my $cathash;
11497: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
11498: $cathash = $domconfig{'coursecategories'}{'cats'};
11499: } else {
11500: $cathash = {};
11501: }
11502: my (@cats,@trails,%allitems);
11503: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
11504: if (keys(%deletions) > 0) {
11505: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
11506: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
11507: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
11508: }
11509: $resulttext .= '</ul></li>';
11510: }
11511: if (keys(%reorderings) > 0) {
11512: my %sort_by_trail;
11513: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
11514: foreach my $key (keys(%reorderings)) {
11515: if ($allitems{$key} ne '') {
11516: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11517: }
1.48 raeburn 11518: }
1.57 raeburn 11519: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11520: $resulttext .= '<li>'.$trails[$trail].'</li>';
11521: }
11522: $resulttext .= '</ul></li>';
1.48 raeburn 11523: }
1.57 raeburn 11524: if (keys(%adds) > 0) {
11525: my %sort_by_trail;
11526: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
11527: foreach my $key (keys(%adds)) {
11528: if ($allitems{$key} ne '') {
11529: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11530: }
11531: }
11532: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11533: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 11534: }
1.57 raeburn 11535: $resulttext .= '</ul></li>';
1.48 raeburn 11536: }
11537: }
11538: $resulttext .= '</ul>';
1.239 raeburn 11539: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 11540: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11541: if ($changes{'auth'}) {
11542: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
11543: }
11544: if ($changes{'unauth'}) {
11545: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
11546: }
11547: my $cachetime = 24*60*60;
11548: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 11549: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 11550: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 11551: }
11552: }
1.48 raeburn 11553: } else {
11554: $resulttext = '<span class="LC_error">'.
1.57 raeburn 11555: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 11556: }
11557: } else {
1.120 raeburn 11558: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 11559: }
11560: return $resulttext;
11561: }
11562:
1.69 raeburn 11563: sub modify_serverstatuses {
11564: my ($dom,%domconfig) = @_;
11565: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
11566: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
11567: %currserverstatus = %{$domconfig{'serverstatuses'}};
11568: }
11569: my @pages = &serverstatus_pages();
11570: foreach my $type (@pages) {
11571: $newserverstatus{$type}{'namedusers'} = '';
11572: $newserverstatus{$type}{'machines'} = '';
11573: if (defined($env{'form.'.$type.'_namedusers'})) {
11574: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
11575: my @okusers;
11576: foreach my $user (@users) {
11577: my ($uname,$udom) = split(/:/,$user);
11578: if (($udom =~ /^$match_domain$/) &&
11579: (&Apache::lonnet::domain($udom)) &&
11580: ($uname =~ /^$match_username$/)) {
11581: if (!grep(/^\Q$user\E/,@okusers)) {
11582: push(@okusers,$user);
11583: }
11584: }
11585: }
11586: if (@okusers > 0) {
11587: @okusers = sort(@okusers);
11588: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
11589: }
11590: }
11591: if (defined($env{'form.'.$type.'_machines'})) {
11592: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
11593: my @okmachines;
11594: foreach my $ip (@machines) {
11595: my @parts = split(/\./,$ip);
11596: next if (@parts < 4);
11597: my $badip = 0;
11598: for (my $i=0; $i<4; $i++) {
11599: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
11600: $badip = 1;
11601: last;
11602: }
11603: }
11604: if (!$badip) {
11605: push(@okmachines,$ip);
11606: }
11607: }
11608: @okmachines = sort(@okmachines);
11609: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
11610: }
11611: }
11612: my %serverstatushash = (
11613: serverstatuses => \%newserverstatus,
11614: );
11615: foreach my $type (@pages) {
1.83 raeburn 11616: foreach my $setting ('namedusers','machines') {
1.84 raeburn 11617: my (@current,@new);
1.83 raeburn 11618: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 11619: if ($currserverstatus{$type}{$setting} ne '') {
11620: @current = split(/,/,$currserverstatus{$type}{$setting});
11621: }
11622: }
11623: if ($newserverstatus{$type}{$setting} ne '') {
11624: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 11625: }
11626: if (@current > 0) {
11627: if (@new > 0) {
11628: foreach my $item (@current) {
11629: if (!grep(/^\Q$item\E$/,@new)) {
11630: $changes{$type}{$setting} = 1;
1.82 raeburn 11631: last;
11632: }
11633: }
1.84 raeburn 11634: foreach my $item (@new) {
11635: if (!grep(/^\Q$item\E$/,@current)) {
11636: $changes{$type}{$setting} = 1;
11637: last;
1.82 raeburn 11638: }
11639: }
11640: } else {
1.83 raeburn 11641: $changes{$type}{$setting} = 1;
1.69 raeburn 11642: }
1.83 raeburn 11643: } elsif (@new > 0) {
11644: $changes{$type}{$setting} = 1;
1.69 raeburn 11645: }
11646: }
11647: }
11648: if (keys(%changes) > 0) {
1.81 raeburn 11649: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11650: my $putresult = &Apache::lonnet::put_dom('configuration',
11651: \%serverstatushash,$dom);
11652: if ($putresult eq 'ok') {
11653: $resulttext .= &mt('Changes made:').'<ul>';
11654: foreach my $type (@pages) {
1.84 raeburn 11655: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 11656: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 11657: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 11658: if ($newserverstatus{$type}{'namedusers'} eq '') {
11659: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
11660: } else {
11661: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
11662: }
1.84 raeburn 11663: }
11664: if ($changes{$type}{'machines'}) {
1.69 raeburn 11665: if ($newserverstatus{$type}{'machines'} eq '') {
11666: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
11667: } else {
11668: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
11669: }
11670:
11671: }
11672: $resulttext .= '</ul></li>';
11673: }
11674: }
11675: $resulttext .= '</ul>';
11676: } else {
11677: $resulttext = '<span class="LC_error">'.
11678: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
11679:
11680: }
11681: } else {
11682: $resulttext = &mt('No changes made to access to server status pages');
11683: }
11684: return $resulttext;
11685: }
11686:
1.118 jms 11687: sub modify_helpsettings {
1.122 jms 11688: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 11689: my ($resulttext,$errors,%changes,%helphash);
11690: my %defaultchecked = ('submitbugs' => 'on');
11691: my @offon = ('off','on');
1.118 jms 11692: my @toggles = ('submitbugs');
11693: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
11694: foreach my $item (@toggles) {
1.166 raeburn 11695: if ($defaultchecked{$item} eq 'on') {
11696: if ($domconfig{'helpsettings'}{$item} eq '') {
11697: if ($env{'form.'.$item} eq '0') {
11698: $changes{$item} = 1;
11699: }
11700: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
11701: $changes{$item} = 1;
11702: }
11703: } elsif ($defaultchecked{$item} eq 'off') {
11704: if ($domconfig{'helpsettings'}{$item} eq '') {
11705: if ($env{'form.'.$item} eq '1') {
11706: $changes{$item} = 1;
11707: }
11708: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
11709: $changes{$item} = 1;
11710: }
11711: }
1.210 raeburn 11712: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
1.166 raeburn 11713: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
11714: }
11715: }
1.118 jms 11716: }
1.123 jms 11717: my $putresult;
11718: if (keys(%changes) > 0) {
1.166 raeburn 11719: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 11720: if ($putresult eq 'ok') {
1.166 raeburn 11721: $resulttext = &mt('Changes made:').'<ul>';
11722: foreach my $item (sort(keys(%changes))) {
11723: if ($item eq 'submitbugs') {
11724: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
11725: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
11726: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
11727: }
11728: }
11729: $resulttext .= '</ul>';
11730: } else {
11731: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 11732: $errors .= '<li><span class="LC_error">'.
11733: &mt('An error occurred storing the settings: [_1]',
11734: $putresult).'</span></li>';
1.166 raeburn 11735: }
1.118 jms 11736: }
11737: if ($errors) {
1.168 raeburn 11738: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 11739: $errors.'</ul>';
11740: }
11741: return $resulttext;
11742: }
11743:
1.121 raeburn 11744: sub modify_coursedefaults {
1.212 raeburn 11745: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 11746: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 11747: my %defaultchecked = (
11748: 'canuse_pdfforms' => 'off',
11749: 'uselcmath' => 'on',
11750: 'usejsme' => 'on'
11751: );
11752: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 11753: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 11754: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
11755: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
11756: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 11757: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 11758: my %staticdefaults = (
11759: anonsurvey_threshold => 10,
11760: uploadquota => 500,
1.257 raeburn 11761: postsubmit => 60,
1.276 raeburn 11762: mysqltables => 172800,
1.198 raeburn 11763: );
1.121 raeburn 11764:
11765: $defaultshash{'coursedefaults'} = {};
11766:
11767: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
11768: if ($domconfig{'coursedefaults'} eq '') {
11769: $domconfig{'coursedefaults'} = {};
11770: }
11771: }
11772:
11773: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
11774: foreach my $item (@toggles) {
11775: if ($defaultchecked{$item} eq 'on') {
11776: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11777: ($env{'form.'.$item} eq '0')) {
11778: $changes{$item} = 1;
1.192 raeburn 11779: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 11780: $changes{$item} = 1;
11781: }
11782: } elsif ($defaultchecked{$item} eq 'off') {
11783: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11784: ($env{'form.'.$item} eq '1')) {
11785: $changes{$item} = 1;
11786: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
11787: $changes{$item} = 1;
11788: }
11789: }
11790: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
11791: }
1.198 raeburn 11792: foreach my $item (@numbers) {
11793: my ($currdef,$newdef);
1.208 raeburn 11794: $newdef = $env{'form.'.$item};
1.198 raeburn 11795: if ($item eq 'anonsurvey_threshold') {
11796: $currdef = $domconfig{'coursedefaults'}{$item};
11797: $newdef =~ s/\D//g;
11798: if ($newdef eq '' || $newdef < 1) {
11799: $newdef = 1;
11800: }
11801: $defaultshash{'coursedefaults'}{$item} = $newdef;
11802: } else {
1.276 raeburn 11803: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
11804: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
11805: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 11806: }
11807: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 11808: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 11809: }
11810: if ($currdef ne $newdef) {
11811: my $staticdef;
11812: if ($item eq 'anonsurvey_threshold') {
11813: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
11814: $changes{$item} = 1;
11815: }
1.276 raeburn 11816: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
11817: my $setting = $1;
11818: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
11819: $changes{$setting} = 1;
1.198 raeburn 11820: }
11821: }
1.139 raeburn 11822: }
11823: }
1.264 raeburn 11824: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
11825: my @currclonecode;
11826: if (ref($currclone) eq 'HASH') {
11827: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
11828: @currclonecode = @{$currclone->{'instcode'}};
11829: }
11830: }
11831: my $newclone;
11832: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
11833: $newclone = $env{'form.canclone'};
11834: }
11835: if ($newclone eq 'instcode') {
11836: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
11837: my (%codedefaults,@code_order,@clonecode);
11838: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
11839: \@code_order);
11840: foreach my $item (@code_order) {
11841: if (grep(/^\Q$item\E$/,@newcodes)) {
11842: push(@clonecode,$item);
11843: }
11844: }
11845: if (@clonecode) {
11846: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
11847: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
11848: if (@diffs) {
11849: $changes{'canclone'} = 1;
11850: }
11851: } else {
11852: $newclone eq '';
11853: }
11854: } elsif ($newclone ne '') {
11855: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
11856: }
11857: if ($newclone ne $currclone) {
11858: $changes{'canclone'} = 1;
11859: }
1.257 raeburn 11860: my %credits;
11861: foreach my $type (@types) {
11862: unless ($type eq 'community') {
11863: $credits{$type} = $env{'form.'.$type.'_credits'};
11864: $credits{$type} =~ s/[^\d.]+//g;
11865: }
11866: }
11867: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
11868: ($env{'form.coursecredits'} eq '1')) {
11869: $changes{'coursecredits'} = 1;
11870: foreach my $type (keys(%credits)) {
11871: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11872: }
11873: } else {
11874: if ($env{'form.coursecredits'} eq '1') {
11875: foreach my $type (@types) {
11876: unless ($type eq 'community') {
11877: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
11878: $changes{'coursecredits'} = 1;
11879: }
11880: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11881: }
11882: }
11883: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
11884: foreach my $type (@types) {
11885: unless ($type eq 'community') {
11886: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
11887: $changes{'coursecredits'} = 1;
11888: last;
11889: }
11890: }
11891: }
11892: }
11893: }
11894: if ($env{'form.postsubmit'} eq '1') {
11895: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
11896: my %currtimeout;
11897: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11898: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
11899: $changes{'postsubmit'} = 1;
11900: }
11901: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11902: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
11903: }
11904: } else {
11905: $changes{'postsubmit'} = 1;
11906: }
11907: foreach my $type (@types) {
11908: my $timeout = $env{'form.'.$type.'_timeout'};
11909: $timeout =~ s/\D//g;
11910: if ($timeout == $staticdefaults{'postsubmit'}) {
11911: $timeout = '';
11912: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
11913: $timeout = '0';
11914: }
11915: unless ($timeout eq '') {
11916: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
11917: }
11918: if (exists($currtimeout{$type})) {
11919: if ($timeout ne $currtimeout{$type}) {
11920: $changes{'postsubmit'} = 1;
11921: }
11922: } elsif ($timeout ne '') {
11923: $changes{'postsubmit'} = 1;
11924: }
11925: }
11926: } else {
11927: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
11928: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11929: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
11930: $changes{'postsubmit'} = 1;
11931: }
11932: } else {
11933: $changes{'postsubmit'} = 1;
11934: }
1.192 raeburn 11935: }
1.121 raeburn 11936: }
11937: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
11938: $dom);
11939: if ($putresult eq 'ok') {
11940: if (keys(%changes) > 0) {
1.213 raeburn 11941: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 11942: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 11943: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.276 raeburn 11944: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.257 raeburn 11945: foreach my $item ('canuse_pdfforms','uselcmath','usejsme') {
11946: if ($changes{$item}) {
11947: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
11948: }
11949: }
1.192 raeburn 11950: if ($changes{'coursecredits'}) {
11951: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 11952: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
11953: $domdefaults{$type.'credits'} =
11954: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
11955: }
11956: }
11957: }
11958: if ($changes{'postsubmit'}) {
11959: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11960: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
11961: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11962: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
11963: $domdefaults{$type.'postsubtimeout'} =
11964: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
11965: }
11966: }
1.192 raeburn 11967: }
11968: }
1.198 raeburn 11969: if ($changes{'uploadquota'}) {
11970: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11971: foreach my $type (@types) {
11972: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
11973: }
11974: }
11975: }
1.264 raeburn 11976: if ($changes{'canclone'}) {
11977: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
11978: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
11979: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
11980: if (@clonecodes) {
11981: $domdefaults{'canclone'} = join('+',@clonecodes);
11982: }
11983: }
11984: } else {
11985: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
11986: }
11987: }
1.121 raeburn 11988: my $cachetime = 24*60*60;
11989: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 11990: if (ref($lastactref) eq 'HASH') {
11991: $lastactref->{'domdefaults'} = 1;
11992: }
1.121 raeburn 11993: }
11994: $resulttext = &mt('Changes made:').'<ul>';
11995: foreach my $item (sort(keys(%changes))) {
11996: if ($item eq 'canuse_pdfforms') {
11997: if ($env{'form.'.$item} eq '1') {
11998: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
11999: } else {
12000: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
12001: }
1.257 raeburn 12002: } elsif ($item eq 'uselcmath') {
12003: if ($env{'form.'.$item} eq '1') {
12004: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
12005: } else {
12006: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
12007: }
12008: } elsif ($item eq 'usejsme') {
12009: if ($env{'form.'.$item} eq '1') {
12010: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
12011: } else {
12012: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
12013: }
1.139 raeburn 12014: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 12015: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 12016: } elsif ($item eq 'uploadquota') {
12017: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
12018: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
12019: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
12020: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 12021: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 12022: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 12023: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
12024: '</ul>'.
12025: '</li>';
12026: } else {
12027: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
12028: }
1.276 raeburn 12029: } elsif ($item eq 'mysqltables') {
12030: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
12031: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
12032: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
12033: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
12034: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
12035: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
12036: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
12037: '</ul>'.
12038: '</li>';
12039: } else {
12040: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
12041: }
1.257 raeburn 12042: } elsif ($item eq 'postsubmit') {
12043: if ($domdefaults{'postsubmit'} eq 'off') {
12044: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
12045: } else {
12046: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
12047: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12048: $resulttext .= &mt('durations:').'<ul>';
12049: foreach my $type (@types) {
12050: $resulttext .= '<li>';
12051: my $timeout;
12052: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
12053: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
12054: }
12055: my $display;
12056: if ($timeout eq '0') {
12057: $display = &mt('unlimited');
12058: } elsif ($timeout eq '') {
12059: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
12060: } else {
12061: $display = &mt('[quant,_1,second]',$timeout);
12062: }
12063: if ($type eq 'community') {
12064: $resulttext .= &mt('Communities');
12065: } elsif ($type eq 'official') {
12066: $resulttext .= &mt('Official courses');
12067: } elsif ($type eq 'unofficial') {
12068: $resulttext .= &mt('Unofficial courses');
12069: } elsif ($type eq 'textbook') {
12070: $resulttext .= &mt('Textbook courses');
1.271 raeburn 12071: } elsif ($type eq 'placement') {
12072: $resulttext .= &mt('Placement tests');
1.257 raeburn 12073: }
12074: $resulttext .= ' -- '.$display.'</li>';
12075: }
12076: $resulttext .= '</ul>';
12077: }
12078: $resulttext .= '</li>';
12079: }
1.192 raeburn 12080: } elsif ($item eq 'coursecredits') {
12081: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
12082: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 12083: ($domdefaults{'unofficialcredits'} eq '') &&
12084: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 12085: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
12086: } else {
12087: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
12088: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
12089: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 12090: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 12091: '</ul>'.
12092: '</li>';
12093: }
12094: } else {
12095: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
12096: }
1.264 raeburn 12097: } elsif ($item eq 'canclone') {
12098: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
12099: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
12100: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
12101: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
12102: }
12103: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
12104: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
12105: } else {
12106: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
12107: }
1.140 raeburn 12108: }
1.121 raeburn 12109: }
12110: $resulttext .= '</ul>';
12111: } else {
12112: $resulttext = &mt('No changes made to course defaults');
12113: }
12114: } else {
12115: $resulttext = '<span class="LC_error">'.
12116: &mt('An error occurred: [_1]',$putresult).'</span>';
12117: }
12118: return $resulttext;
12119: }
12120:
1.231 raeburn 12121: sub modify_selfenrollment {
12122: my ($dom,$lastactref,%domconfig) = @_;
12123: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 12124: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 12125: my %titles = &tool_titles();
1.232 raeburn 12126: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
12127: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 12128: $ordered{'default'} = ['types','registered','approval','limit'];
12129:
12130: my (%roles,%shown,%toplevel);
12131: $roles{'0'} = &Apache::lonnet::plaintext('dc');
12132:
12133: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
12134: if ($domconfig{'selfenrollment'} eq '') {
12135: $domconfig{'selfenrollment'} = {};
12136: }
12137: }
12138: %toplevel = (
12139: admin => 'Configuration Rights',
12140: default => 'Default settings',
12141: validation => 'Validation of self-enrollment requests',
12142: );
1.233 raeburn 12143: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 12144:
12145: if (ref($ordered{'admin'}) eq 'ARRAY') {
12146: foreach my $item (@{$ordered{'admin'}}) {
12147: foreach my $type (@types) {
12148: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
12149: $selfenrollhash{'admin'}{$type}{$item} = 1;
12150: } else {
12151: $selfenrollhash{'admin'}{$type}{$item} = 0;
12152: }
12153: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
12154: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
12155: if ($selfenrollhash{'admin'}{$type}{$item} ne
12156: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
12157: push(@{$changes{'admin'}{$type}},$item);
12158: }
12159: } else {
12160: if (!$selfenrollhash{'admin'}{$type}{$item}) {
12161: push(@{$changes{'admin'}{$type}},$item);
12162: }
12163: }
12164: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
12165: push(@{$changes{'admin'}{$type}},$item);
12166: }
12167: }
12168: }
12169: }
12170:
12171: foreach my $item (@{$ordered{'default'}}) {
12172: foreach my $type (@types) {
12173: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
12174: if ($item eq 'types') {
12175: unless (($value eq 'all') || ($value eq 'dom')) {
12176: $value = '';
12177: }
12178: } elsif ($item eq 'registered') {
12179: unless ($value eq '1') {
12180: $value = 0;
12181: }
12182: } elsif ($item eq 'approval') {
12183: unless ($value =~ /^[012]$/) {
12184: $value = 0;
12185: }
12186: } else {
12187: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12188: $value = 'none';
12189: }
12190: }
12191: $selfenrollhash{'default'}{$type}{$item} = $value;
12192: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
12193: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12194: if ($selfenrollhash{'default'}{$type}{$item} ne
12195: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
12196: push(@{$changes{'default'}{$type}},$item);
12197: }
12198: } else {
12199: push(@{$changes{'default'}{$type}},$item);
12200: }
12201: } else {
12202: push(@{$changes{'default'}{$type}},$item);
12203: }
12204: if ($item eq 'limit') {
12205: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12206: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
12207: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
12208: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
12209: }
12210: } else {
12211: $selfenrollhash{'default'}{$type}{'cap'} = '';
12212: }
12213: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12214: if ($selfenrollhash{'default'}{$type}{'cap'} ne
12215: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
12216: push(@{$changes{'default'}{$type}},'cap');
12217: }
12218: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
12219: push(@{$changes{'default'}{$type}},'cap');
12220: }
12221: }
12222: }
12223: }
12224:
12225: foreach my $item (@{$itemsref}) {
12226: if ($item eq 'fields') {
12227: my @changed;
12228: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
12229: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
12230: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
12231: }
12232: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12233: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
12234: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
12235: $domconfig{'selfenrollment'}{'validation'}{$item});
12236: } else {
12237: @changed = @{$selfenrollhash{'validation'}{$item}};
12238: }
12239: } else {
12240: @changed = @{$selfenrollhash{'validation'}{$item}};
12241: }
12242: if (@changed) {
12243: if ($selfenrollhash{'validation'}{$item}) {
12244: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
12245: } else {
12246: $changes{'validation'}{$item} = &mt('None');
12247: }
12248: }
12249: } else {
12250: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
12251: if ($item eq 'markup') {
12252: if ($env{'form.selfenroll_validation_'.$item}) {
12253: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
12254: }
12255: }
12256: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12257: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
12258: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
12259: }
12260: }
12261: }
12262: }
12263:
12264: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
12265: $dom);
12266: if ($putresult eq 'ok') {
12267: if (keys(%changes) > 0) {
12268: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12269: $resulttext = &mt('Changes made:').'<ul>';
12270: foreach my $key ('admin','default','validation') {
12271: if (ref($changes{$key}) eq 'HASH') {
12272: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
12273: if ($key eq 'validation') {
12274: foreach my $item (@{$itemsref}) {
12275: if (exists($changes{$key}{$item})) {
12276: if ($item eq 'markup') {
12277: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12278: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
12279: } else {
12280: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12281: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
12282: }
12283: }
12284: }
12285: } else {
12286: foreach my $type (@types) {
12287: if ($type eq 'community') {
12288: $roles{'1'} = &mt('Community personnel');
12289: } else {
12290: $roles{'1'} = &mt('Course personnel');
12291: }
12292: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 12293: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12294: if ($key eq 'admin') {
12295: my @mgrdc = ();
12296: if (ref($ordered{$key}) eq 'ARRAY') {
12297: foreach my $item (@{$ordered{'admin'}}) {
12298: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12299: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
12300: push(@mgrdc,$item);
12301: }
12302: }
12303: }
12304: if (@mgrdc) {
12305: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
12306: } else {
12307: delete($domdefaults{$type.'selfenrolladmdc'});
12308: }
12309: }
12310: } else {
12311: if (ref($ordered{$key}) eq 'ARRAY') {
12312: foreach my $item (@{$ordered{$key}}) {
12313: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12314: $domdefaults{$type.'selfenroll'.$item} =
12315: $selfenrollhash{$key}{$type}{$item};
12316: }
12317: }
12318: }
12319: }
12320: }
1.231 raeburn 12321: $resulttext .= '<li>'.$titles{$type}.'<ul>';
12322: foreach my $item (@{$ordered{$key}}) {
12323: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12324: $resulttext .= '<li>';
12325: if ($key eq 'admin') {
12326: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
12327: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
12328: } else {
12329: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
12330: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
12331: }
12332: $resulttext .= '</li>';
12333: }
12334: }
12335: $resulttext .= '</ul></li>';
12336: }
12337: }
12338: $resulttext .= '</ul></li>';
12339: }
12340: }
1.232 raeburn 12341: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
12342: my $cachetime = 24*60*60;
12343: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12344: if (ref($lastactref) eq 'HASH') {
12345: $lastactref->{'domdefaults'} = 1;
12346: }
12347: }
1.231 raeburn 12348: }
12349: $resulttext .= '</ul>';
12350: } else {
12351: $resulttext = &mt('No changes made to self-enrollment settings');
12352: }
12353: } else {
12354: $resulttext = '<span class="LC_error">'.
12355: &mt('An error occurred: [_1]',$putresult).'</span>';
12356: }
12357: return $resulttext;
12358: }
12359:
1.137 raeburn 12360: sub modify_usersessions {
1.212 raeburn 12361: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 12362: my @hostingtypes = ('version','excludedomain','includedomain');
12363: my @offloadtypes = ('primary','default');
12364: my %types = (
12365: remote => \@hostingtypes,
12366: hosted => \@hostingtypes,
12367: spares => \@offloadtypes,
12368: );
12369: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 12370: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 12371: my (%by_ip,%by_location,@intdoms,@instdoms);
12372: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 12373: my @locations = sort(keys(%by_location));
1.137 raeburn 12374: my (%defaultshash,%changes);
12375: foreach my $prefix (@prefixes) {
12376: $defaultshash{'usersessions'}{$prefix} = {};
12377: }
1.212 raeburn 12378: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 12379: my $resulttext;
1.138 raeburn 12380: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 12381: foreach my $prefix (@prefixes) {
1.145 raeburn 12382: next if ($prefix eq 'spares');
12383: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 12384: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
12385: if ($type eq 'version') {
12386: my $value = $env{'form.'.$prefix.'_'.$type};
12387: my $okvalue;
12388: if ($value ne '') {
12389: if (grep(/^\Q$value\E$/,@lcversions)) {
12390: $okvalue = $value;
12391: }
12392: }
12393: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12394: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12395: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
12396: if ($inuse == 0) {
12397: $changes{$prefix}{$type} = 1;
12398: } else {
12399: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
12400: $changes{$prefix}{$type} = 1;
12401: }
12402: if ($okvalue ne '') {
12403: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12404: }
12405: }
12406: } else {
12407: if (($inuse == 1) && ($okvalue ne '')) {
12408: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12409: $changes{$prefix}{$type} = 1;
12410: }
12411: }
12412: } else {
12413: if (($inuse == 1) && ($okvalue ne '')) {
12414: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12415: $changes{$prefix}{$type} = 1;
12416: }
12417: }
12418: } else {
12419: if (($inuse == 1) && ($okvalue ne '')) {
12420: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12421: $changes{$prefix}{$type} = 1;
12422: }
12423: }
12424: } else {
12425: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
12426: my @okvals;
12427: foreach my $val (@vals) {
1.138 raeburn 12428: if ($val =~ /:/) {
12429: my @items = split(/:/,$val);
12430: foreach my $item (@items) {
12431: if (ref($by_location{$item}) eq 'ARRAY') {
12432: push(@okvals,$item);
12433: }
12434: }
12435: } else {
12436: if (ref($by_location{$val}) eq 'ARRAY') {
12437: push(@okvals,$val);
12438: }
1.137 raeburn 12439: }
12440: }
12441: @okvals = sort(@okvals);
12442: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12443: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12444: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12445: if ($inuse == 0) {
12446: $changes{$prefix}{$type} = 1;
12447: } else {
12448: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12449: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
12450: if (@changed > 0) {
12451: $changes{$prefix}{$type} = 1;
12452: }
12453: }
12454: } else {
12455: if ($inuse == 1) {
12456: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12457: $changes{$prefix}{$type} = 1;
12458: }
12459: }
12460: } else {
12461: if ($inuse == 1) {
12462: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12463: $changes{$prefix}{$type} = 1;
12464: }
12465: }
12466: } else {
12467: if ($inuse == 1) {
12468: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12469: $changes{$prefix}{$type} = 1;
12470: }
12471: }
12472: }
12473: }
12474: }
1.145 raeburn 12475:
12476: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 12477: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 12478: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
12479: my $savespares;
12480:
12481: foreach my $lonhost (sort(keys(%servers))) {
12482: my $serverhomeID =
12483: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 12484: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 12485: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
12486: my %spareschg;
12487: foreach my $type (@{$types{'spares'}}) {
12488: my @okspares;
12489: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
12490: foreach my $server (@checked) {
1.152 raeburn 12491: if (&Apache::lonnet::hostname($server) ne '') {
12492: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
12493: unless (grep(/^\Q$server\E$/,@okspares)) {
12494: push(@okspares,$server);
12495: }
1.145 raeburn 12496: }
12497: }
12498: }
12499: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
12500: my $newspare;
1.152 raeburn 12501: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
12502: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 12503: $newspare = $new;
12504: }
12505: }
1.152 raeburn 12506: my @spares;
12507: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
12508: @spares = sort(@okspares,$newspare);
12509: } else {
12510: @spares = sort(@okspares);
12511: }
12512: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 12513: if (ref($spareid{$lonhost}) eq 'HASH') {
12514: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 12515: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 12516: if (@diffs > 0) {
12517: $spareschg{$type} = 1;
12518: }
12519: }
12520: }
12521: }
12522: if (keys(%spareschg) > 0) {
12523: $changes{'spares'}{$lonhost} = \%spareschg;
12524: }
12525: }
1.261 raeburn 12526: $defaultshash{'usersessions'}{'offloadnow'} = {};
12527: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
12528: my @okoffload;
12529: if (@offloadnow) {
12530: foreach my $server (@offloadnow) {
12531: if (&Apache::lonnet::hostname($server) ne '') {
12532: unless (grep(/^\Q$server\E$/,@okoffload)) {
12533: push(@okoffload,$server);
12534: }
12535: }
12536: }
12537: if (@okoffload) {
12538: foreach my $lonhost (@okoffload) {
12539: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
12540: }
12541: }
12542: }
1.145 raeburn 12543: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12544: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
12545: if (ref($changes{'spares'}) eq 'HASH') {
12546: if (keys(%{$changes{'spares'}}) > 0) {
12547: $savespares = 1;
12548: }
12549: }
12550: } else {
12551: $savespares = 1;
12552: }
1.261 raeburn 12553: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
12554: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
12555: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
12556: $changes{'offloadnow'} = 1;
12557: last;
12558: }
12559: }
12560: unless ($changes{'offloadnow'}) {
12561: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
12562: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
12563: $changes{'offloadnow'} = 1;
12564: last;
12565: }
12566: }
12567: }
12568: } elsif (@okoffload) {
12569: $changes{'offloadnow'} = 1;
12570: }
12571: } elsif (@okoffload) {
12572: $changes{'offloadnow'} = 1;
1.145 raeburn 12573: }
1.147 raeburn 12574: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
12575: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 12576: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12577: $dom);
12578: if ($putresult eq 'ok') {
12579: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12580: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
12581: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
12582: }
12583: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
12584: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
12585: }
1.261 raeburn 12586: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12587: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
12588: }
1.137 raeburn 12589: }
12590: my $cachetime = 24*60*60;
12591: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 12592: if (ref($lastactref) eq 'HASH') {
12593: $lastactref->{'domdefaults'} = 1;
12594: }
1.147 raeburn 12595: if (keys(%changes) > 0) {
12596: my %lt = &usersession_titles();
12597: $resulttext = &mt('Changes made:').'<ul>';
12598: foreach my $prefix (@prefixes) {
12599: if (ref($changes{$prefix}) eq 'HASH') {
12600: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
12601: if ($prefix eq 'spares') {
12602: if (ref($changes{$prefix}) eq 'HASH') {
12603: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
12604: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 12605: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 12606: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
12607: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 12608: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
12609: foreach my $type (@{$types{$prefix}}) {
12610: if ($changes{$prefix}{$lonhost}{$type}) {
12611: my $offloadto = &mt('None');
12612: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
12613: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
12614: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
12615: }
1.145 raeburn 12616: }
1.147 raeburn 12617: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 12618: }
1.137 raeburn 12619: }
12620: }
1.147 raeburn 12621: $resulttext .= '</li>';
1.137 raeburn 12622: }
12623: }
1.147 raeburn 12624: } else {
12625: foreach my $type (@{$types{$prefix}}) {
12626: if (defined($changes{$prefix}{$type})) {
12627: my $newvalue;
12628: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12629: if (ref($defaultshash{'usersessions'}{$prefix})) {
12630: if ($type eq 'version') {
12631: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
12632: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12633: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
12634: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
12635: }
1.145 raeburn 12636: }
12637: }
12638: }
1.147 raeburn 12639: if ($newvalue eq '') {
12640: if ($type eq 'version') {
12641: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
12642: } else {
12643: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
12644: }
1.145 raeburn 12645: } else {
1.147 raeburn 12646: if ($type eq 'version') {
12647: $newvalue .= ' '.&mt('(or later)');
12648: }
12649: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 12650: }
1.137 raeburn 12651: }
12652: }
12653: }
1.147 raeburn 12654: $resulttext .= '</ul>';
1.137 raeburn 12655: }
12656: }
1.261 raeburn 12657: if ($changes{'offloadnow'}) {
12658: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12659: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
12660: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
12661: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
12662: $resulttext .= '<li>'.$lonhost.'</li>';
12663: }
12664: $resulttext .= '</ul>';
12665: } else {
12666: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
12667: }
12668: } else {
12669: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
12670: }
12671: }
1.147 raeburn 12672: $resulttext .= '</ul>';
12673: } else {
12674: $resulttext = $nochgmsg;
1.137 raeburn 12675: }
12676: } else {
12677: $resulttext = '<span class="LC_error">'.
12678: &mt('An error occurred: [_1]',$putresult).'</span>';
12679: }
12680: } else {
1.147 raeburn 12681: $resulttext = $nochgmsg;
1.137 raeburn 12682: }
12683: return $resulttext;
12684: }
12685:
1.275 raeburn 12686: sub modify_ssl {
12687: my ($dom,$lastactref,%domconfig) = @_;
12688: my (%by_ip,%by_location,@intdoms,@instdoms);
12689: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
12690: my @locations = sort(keys(%by_location));
12691: my %servers = &Apache::lonnet::internet_dom_servers($dom);
12692: my (%defaultshash,%changes);
12693: my $action = 'ssl';
12694: my @prefixes = ('connect','replication');
12695: foreach my $prefix (@prefixes) {
12696: $defaultshash{$action}{$prefix} = {};
12697: }
12698: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12699: my $resulttext;
12700: my %iphost = &Apache::lonnet::get_iphost();
12701: my @reptypes = ('certreq','nocertreq');
12702: my @connecttypes = ('dom','intdom','other');
12703: my %types = (
12704: connect => \@connecttypes,
12705: replication => \@reptypes,
12706: );
12707: foreach my $prefix (sort(keys(%types))) {
12708: foreach my $type (@{$types{$prefix}}) {
12709: if ($prefix eq 'connect') {
12710: my $value = 'yes';
12711: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
12712: $value = $env{'form.'.$prefix.'_'.$type};
12713: }
12714: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
12715: if ($domconfig{$action}{$prefix}{$type} ne '') {
12716: if ($value ne $domconfig{$action}{$prefix}{$type}) {
12717: $changes{$prefix}{$type} = 1;
12718: }
12719: $defaultshash{$action}{$prefix}{$type} = $value;
12720: } else {
12721: $defaultshash{$action}{$prefix}{$type} = $value;
12722: $changes{$prefix}{$type} = 1;
12723: }
12724: } else {
12725: $defaultshash{$action}{$prefix}{$type} = $value;
12726: $changes{$prefix}{$type} = 1;
12727: }
12728: if (($type eq 'dom') && (keys(%servers) == 1)) {
12729: delete($changes{$prefix}{$type});
12730: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
12731: delete($changes{$prefix}{$type});
12732: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
12733: delete($changes{$prefix}{$type});
12734: }
12735: } elsif ($prefix eq 'replication') {
12736: if (@locations > 0) {
12737: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
12738: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
12739: my @okvals;
12740: foreach my $val (@vals) {
12741: if ($val =~ /:/) {
12742: my @items = split(/:/,$val);
12743: foreach my $item (@items) {
12744: if (ref($by_location{$item}) eq 'ARRAY') {
12745: push(@okvals,$item);
12746: }
12747: }
12748: } else {
12749: if (ref($by_location{$val}) eq 'ARRAY') {
12750: push(@okvals,$val);
12751: }
12752: }
12753: }
12754: @okvals = sort(@okvals);
12755: if (ref($domconfig{$action}) eq 'HASH') {
12756: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
12757: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
12758: if ($inuse == 0) {
12759: $changes{$prefix}{$type} = 1;
12760: } else {
12761: $defaultshash{$action}{$prefix}{$type} = \@okvals;
12762: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
12763: if (@changed > 0) {
12764: $changes{$prefix}{$type} = 1;
12765: }
12766: }
12767: } else {
12768: if ($inuse == 1) {
12769: $defaultshash{$action}{$prefix}{$type} = \@okvals;
12770: $changes{$prefix}{$type} = 1;
12771: }
12772: }
12773: } else {
12774: if ($inuse == 1) {
12775: $defaultshash{$action}{$prefix}{$type} = \@okvals;
12776: $changes{$prefix}{$type} = 1;
12777: }
12778: }
12779: } else {
12780: if ($inuse == 1) {
12781: $defaultshash{$action}{$prefix}{$type} = \@okvals;
12782: $changes{$prefix}{$type} = 1;
12783: }
12784: }
12785: }
12786: }
12787: }
12788: }
12789: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
12790: if (keys(%changes) > 0) {
12791: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12792: $dom);
12793: if ($putresult eq 'ok') {
12794: if (ref($defaultshash{$action}) eq 'HASH') {
12795: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
12796: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
12797: }
12798: if (ref($defaultshash{$action}{'connect'}) eq 'HASH') {
12799: $domdefaults{'connect'} = $domconfig{$action}{'connect'};
12800: }
12801: }
12802: my $cachetime = 24*60*60;
12803: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12804: if (ref($lastactref) eq 'HASH') {
12805: $lastactref->{'domdefaults'} = 1;
12806: }
12807: if (keys(%changes) > 0) {
12808: my %titles = &ssl_titles();
12809: $resulttext = &mt('Changes made:').'<ul>';
12810: foreach my $prefix (@prefixes) {
12811: if (ref($changes{$prefix}) eq 'HASH') {
12812: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
12813: foreach my $type (@{$types{$prefix}}) {
12814: if (defined($changes{$prefix}{$type})) {
12815: my $newvalue;
12816: if (ref($defaultshash{$action}) eq 'HASH') {
12817: if (ref($defaultshash{$action}{$prefix})) {
12818: if ($prefix eq 'connect') {
12819: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
12820: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
12821: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
12822: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
12823: }
12824: }
12825: }
12826: if ($newvalue eq '') {
12827: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
12828: } else {
12829: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
12830: }
12831: }
12832: }
12833: }
12834: $resulttext .= '</ul>';
12835: }
12836: }
12837: } else {
12838: $resulttext = $nochgmsg;
12839: }
12840: } else {
12841: $resulttext = '<span class="LC_error">'.
12842: &mt('An error occurred: [_1]',$putresult).'</span>';
12843: }
12844: } else {
12845: $resulttext = $nochgmsg;
12846: }
12847: return $resulttext;
12848: }
12849:
1.279 ! raeburn 12850: sub modify_trust {
! 12851: my ($dom,$lastactref,%domconfig) = @_;
! 12852: my (%by_ip,%by_location,@intdoms,@instdoms);
! 12853: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
! 12854: my @locations = sort(keys(%by_location));
! 12855: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
! 12856: my @types = ('exc','inc');
! 12857: my (%defaultshash,%changes);
! 12858: foreach my $prefix (@prefixes) {
! 12859: $defaultshash{'trust'}{$prefix} = {};
! 12860: }
! 12861: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
! 12862: my $resulttext;
! 12863: foreach my $prefix (@prefixes) {
! 12864: foreach my $type (@types) {
! 12865: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
! 12866: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
! 12867: my @okvals;
! 12868: foreach my $val (@vals) {
! 12869: if ($val =~ /:/) {
! 12870: my @items = split(/:/,$val);
! 12871: foreach my $item (@items) {
! 12872: if (ref($by_location{$item}) eq 'ARRAY') {
! 12873: push(@okvals,$item);
! 12874: }
! 12875: }
! 12876: } else {
! 12877: if (ref($by_location{$val}) eq 'ARRAY') {
! 12878: push(@okvals,$val);
! 12879: }
! 12880: }
! 12881: }
! 12882: @okvals = sort(@okvals);
! 12883: if (ref($domconfig{'trust'}) eq 'HASH') {
! 12884: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
! 12885: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
! 12886: if ($inuse == 0) {
! 12887: $changes{$prefix}{$type} = 1;
! 12888: } else {
! 12889: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
! 12890: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
! 12891: if (@changed > 0) {
! 12892: $changes{$prefix}{$type} = 1;
! 12893: }
! 12894: }
! 12895: } else {
! 12896: if ($inuse == 1) {
! 12897: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
! 12898: $changes{$prefix}{$type} = 1;
! 12899: }
! 12900: }
! 12901: } else {
! 12902: if ($inuse == 1) {
! 12903: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
! 12904: $changes{$prefix}{$type} = 1;
! 12905: }
! 12906: }
! 12907: } else {
! 12908: if ($inuse == 1) {
! 12909: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
! 12910: $changes{$prefix}{$type} = 1;
! 12911: }
! 12912: }
! 12913: }
! 12914: }
! 12915: my $nochgmsg = &mt('No changes made to trust settings.');
! 12916: if (keys(%changes) > 0) {
! 12917: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
! 12918: $dom);
! 12919: if ($putresult eq 'ok') {
! 12920: if (ref($defaultshash{'trust'}) eq 'HASH') {
! 12921: foreach my $prefix (@prefixes) {
! 12922: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
! 12923: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
! 12924: }
! 12925: }
! 12926: }
! 12927: my $cachetime = 24*60*60;
! 12928: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
! 12929: if (ref($lastactref) eq 'HASH') {
! 12930: $lastactref->{'domdefaults'} = 1;
! 12931: }
! 12932: if (keys(%changes) > 0) {
! 12933: my %lt = &trust_titles();
! 12934: $resulttext = &mt('Changes made:').'<ul>';
! 12935: foreach my $prefix (@prefixes) {
! 12936: if (ref($changes{$prefix}) eq 'HASH') {
! 12937: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
! 12938: foreach my $type (@types) {
! 12939: if (defined($changes{$prefix}{$type})) {
! 12940: my $newvalue;
! 12941: if (ref($defaultshash{'trust'}) eq 'HASH') {
! 12942: if (ref($defaultshash{'trust'}{$prefix})) {
! 12943: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
! 12944: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
! 12945: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
! 12946: }
! 12947: }
! 12948: }
! 12949: }
! 12950: if ($newvalue eq '') {
! 12951: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
! 12952: } else {
! 12953: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
! 12954: }
! 12955: }
! 12956: }
! 12957: $resulttext .= '</ul>';
! 12958: }
! 12959: }
! 12960: $resulttext .= '</ul>';
! 12961: } else {
! 12962: $resulttext = $nochgmsg;
! 12963: }
! 12964: } else {
! 12965: $resulttext = '<span class="LC_error">'.
! 12966: &mt('An error occurred: [_1]',$putresult).'</span>';
! 12967: }
! 12968: } else {
! 12969: $resulttext = $nochgmsg;
! 12970: }
! 12971: return $resulttext;
! 12972: }
! 12973:
1.150 raeburn 12974: sub modify_loadbalancing {
12975: my ($dom,%domconfig) = @_;
12976: my $primary_id = &Apache::lonnet::domain($dom,'primary');
12977: my $intdom = &Apache::lonnet::internet_dom($primary_id);
12978: my ($othertitle,$usertypes,$types) =
12979: &Apache::loncommon::sorted_inst_types($dom);
12980: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 12981: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 12982: my @sparestypes = ('primary','default');
12983: my %typetitles = &sparestype_titles();
12984: my $resulttext;
1.171 raeburn 12985: my (%currbalancer,%currtargets,%currrules,%existing);
12986: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
12987: %existing = %{$domconfig{'loadbalancing'}};
12988: }
12989: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
12990: \%currtargets,\%currrules);
12991: my ($saveloadbalancing,%defaultshash,%changes);
12992: my ($alltypes,$othertypes,$titles) =
12993: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
12994: my %ruletitles = &offloadtype_text();
12995: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
12996: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
12997: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
12998: if ($balancer eq '') {
12999: next;
13000: }
1.210 raeburn 13001: if (!exists($servers{$balancer})) {
1.171 raeburn 13002: if (exists($currbalancer{$balancer})) {
13003: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 13004: }
1.171 raeburn 13005: next;
13006: }
13007: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
13008: push(@{$changes{'delete'}},$balancer);
13009: next;
13010: }
13011: if (!exists($currbalancer{$balancer})) {
13012: push(@{$changes{'add'}},$balancer);
13013: }
13014: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
13015: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
13016: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
13017: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
13018: $saveloadbalancing = 1;
13019: }
13020: foreach my $sparetype (@sparestypes) {
13021: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
13022: my @offloadto;
13023: foreach my $target (@targets) {
13024: if (($servers{$target}) && ($target ne $balancer)) {
13025: if ($sparetype eq 'default') {
13026: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
13027: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 13028: }
13029: }
1.171 raeburn 13030: unless(grep(/^\Q$target\E$/,@offloadto)) {
13031: push(@offloadto,$target);
13032: }
1.150 raeburn 13033: }
1.171 raeburn 13034: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 13035: }
13036: }
1.171 raeburn 13037: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 13038: foreach my $sparetype (@sparestypes) {
1.171 raeburn 13039: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
13040: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 13041: if (@targetdiffs > 0) {
1.171 raeburn 13042: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 13043: }
1.171 raeburn 13044: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
13045: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
13046: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 13047: }
13048: }
13049: }
13050: } else {
1.171 raeburn 13051: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 13052: foreach my $sparetype (@sparestypes) {
1.171 raeburn 13053: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
13054: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
13055: $changes{'curr'}{$balancer}{'targets'} = 1;
13056: }
1.150 raeburn 13057: }
13058: }
1.210 raeburn 13059: }
1.150 raeburn 13060: }
13061: my $ishomedom;
1.171 raeburn 13062: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
13063: $ishomedom = 1;
1.150 raeburn 13064: }
13065: if (ref($alltypes) eq 'ARRAY') {
13066: foreach my $type (@{$alltypes}) {
13067: my $rule;
1.210 raeburn 13068: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 13069: (!$ishomedom)) {
1.171 raeburn 13070: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
13071: }
13072: if ($rule eq 'specific') {
1.255 raeburn 13073: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
13074: if (exists($servers{$specifiedhost})) {
13075: $rule = $specifiedhost;
13076: }
1.150 raeburn 13077: }
1.171 raeburn 13078: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
13079: if (ref($currrules{$balancer}) eq 'HASH') {
13080: if ($rule ne $currrules{$balancer}{$type}) {
13081: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 13082: }
13083: } elsif ($rule ne '') {
1.171 raeburn 13084: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 13085: }
13086: }
13087: }
1.171 raeburn 13088: }
13089: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
13090: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
13091: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
13092: $defaultshash{'loadbalancing'} = {};
13093: }
13094: my $putresult = &Apache::lonnet::put_dom('configuration',
13095: \%defaultshash,$dom);
13096: if ($putresult eq 'ok') {
13097: if (keys(%changes) > 0) {
1.252 raeburn 13098: my %toupdate;
1.171 raeburn 13099: if (ref($changes{'delete'}) eq 'ARRAY') {
13100: foreach my $balancer (sort(@{$changes{'delete'}})) {
13101: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 13102: $toupdate{$balancer} = 1;
1.150 raeburn 13103: }
1.171 raeburn 13104: }
13105: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 13106: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 13107: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 13108: $toupdate{$balancer} = 1;
1.171 raeburn 13109: }
13110: }
13111: if (ref($changes{'curr'}) eq 'HASH') {
13112: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 13113: $toupdate{$balancer} = 1;
1.171 raeburn 13114: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
13115: if ($changes{'curr'}{$balancer}{'targets'}) {
13116: my %offloadstr;
13117: foreach my $sparetype (@sparestypes) {
13118: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
13119: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
13120: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
13121: }
13122: }
1.150 raeburn 13123: }
1.171 raeburn 13124: if (keys(%offloadstr) == 0) {
13125: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 13126: } else {
1.171 raeburn 13127: my $showoffload;
13128: foreach my $sparetype (@sparestypes) {
13129: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
13130: if (defined($offloadstr{$sparetype})) {
13131: $showoffload .= $offloadstr{$sparetype};
13132: } else {
13133: $showoffload .= &mt('None');
13134: }
13135: $showoffload .= (' 'x3);
13136: }
13137: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 13138: }
13139: }
13140: }
1.171 raeburn 13141: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
13142: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
13143: foreach my $type (@{$alltypes}) {
13144: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
13145: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
13146: my $balancetext;
13147: if ($rule eq '') {
13148: $balancetext = $ruletitles{'default'};
1.209 raeburn 13149: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.254 raeburn 13150: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
13151: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 13152: foreach my $sparetype (@sparestypes) {
13153: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
13154: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
13155: }
13156: }
1.253 raeburn 13157: foreach my $item (@{$alltypes}) {
13158: next if ($item =~ /^_LC_ipchange/);
13159: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
13160: if ($hasrule eq 'homeserver') {
13161: map { $toupdate{$_} = 1; } (keys(%libraryservers));
13162: } else {
13163: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
13164: if ($servers{$hasrule}) {
13165: $toupdate{$hasrule} = 1;
13166: }
13167: }
13168: }
13169: }
1.254 raeburn 13170: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
13171: $balancetext = $ruletitles{$rule};
13172: } else {
13173: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
13174: $balancetext = $ruletitles{'particular'}.' '.$receiver;
13175: if ($receiver) {
13176: $toupdate{$receiver};
13177: }
13178: }
13179: } else {
13180: $balancetext = $ruletitles{$rule};
1.252 raeburn 13181: }
1.171 raeburn 13182: } else {
13183: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
13184: }
1.210 raeburn 13185: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 13186: }
13187: }
13188: }
13189: }
1.252 raeburn 13190: if (keys(%toupdate)) {
13191: my %thismachine;
13192: my $updatedhere;
13193: my $cachetime = 60*60*24;
13194: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
13195: foreach my $lonhost (keys(%toupdate)) {
13196: if ($thismachine{$lonhost}) {
13197: unless ($updatedhere) {
13198: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
13199: $defaultshash{'loadbalancing'},
13200: $cachetime);
13201: $updatedhere = 1;
13202: }
13203: } else {
13204: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
13205: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
13206: }
13207: }
13208: }
1.150 raeburn 13209: }
1.171 raeburn 13210: }
13211: if ($resulttext ne '') {
13212: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 13213: } else {
13214: $resulttext = $nochgmsg;
13215: }
13216: } else {
1.171 raeburn 13217: $resulttext = $nochgmsg;
1.150 raeburn 13218: }
13219: } else {
1.171 raeburn 13220: $resulttext = '<span class="LC_error">'.
13221: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 13222: }
13223: } else {
1.171 raeburn 13224: $resulttext = $nochgmsg;
1.150 raeburn 13225: }
13226: return $resulttext;
13227: }
13228:
1.48 raeburn 13229: sub recurse_check {
13230: my ($chkcats,$categories,$depth,$name) = @_;
13231: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
13232: my $chg = 0;
13233: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
13234: my $category = $chkcats->[$depth]{$name}[$j];
13235: my $item;
13236: if ($category eq '') {
13237: $chg ++;
13238: } else {
13239: my $deeper = $depth + 1;
13240: $item = &escape($category).':'.&escape($name).':'.$depth;
13241: if ($chg) {
13242: $categories->{$item} -= $chg;
13243: }
13244: &recurse_check($chkcats,$categories,$deeper,$category);
13245: $deeper --;
13246: }
13247: }
13248: }
13249: return;
13250: }
13251:
13252: sub recurse_cat_deletes {
13253: my ($item,$coursecategories,$deletions) = @_;
13254: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13255: my $subdepth = $depth + 1;
13256: if (ref($coursecategories) eq 'HASH') {
13257: foreach my $subitem (keys(%{$coursecategories})) {
13258: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
13259: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
13260: delete($coursecategories->{$subitem});
13261: $deletions->{$subitem} = 1;
13262: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 13263: }
1.48 raeburn 13264: }
13265: }
13266: return;
13267: }
13268:
1.125 raeburn 13269: sub get_active_dcs {
13270: my ($dom) = @_;
1.191 raeburn 13271: my $now = time;
13272: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 13273: my %domcoords;
13274: my $numdcs = 0;
13275: foreach my $server (keys(%dompersonnel)) {
13276: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
13277: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191 raeburn 13278: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 13279: }
13280: }
13281: return %domcoords;
13282: }
13283:
13284: sub active_dc_picker {
1.191 raeburn 13285: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.235 raeburn 13286: my %domcoords = &get_active_dcs($dom);
1.191 raeburn 13287: my @domcoord = keys(%domcoords);
13288: if (keys(%currhash)) {
13289: foreach my $dc (keys(%currhash)) {
13290: unless (exists($domcoords{$dc})) {
13291: push(@domcoord,$dc);
13292: }
13293: }
13294: }
13295: @domcoord = sort(@domcoord);
1.210 raeburn 13296: my $numdcs = scalar(@domcoord);
1.191 raeburn 13297: my $rows = 0;
13298: my $table;
1.125 raeburn 13299: if ($numdcs > 1) {
1.191 raeburn 13300: $table = '<table>';
13301: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 13302: my $rem = $i%($numinrow);
13303: if ($rem == 0) {
13304: if ($i > 0) {
1.191 raeburn 13305: $table .= '</tr>';
1.125 raeburn 13306: }
1.191 raeburn 13307: $table .= '<tr>';
13308: $rows ++;
1.125 raeburn 13309: }
1.191 raeburn 13310: my $check = '';
13311: if ($inputtype eq 'radio') {
13312: if (keys(%currhash) == 0) {
13313: if (!$i) {
13314: $check = ' checked="checked"';
13315: }
13316: } elsif (exists($currhash{$domcoord[$i]})) {
13317: $check = ' checked="checked"';
13318: }
13319: } else {
13320: if (exists($currhash{$domcoord[$i]})) {
13321: $check = ' checked="checked"';
1.125 raeburn 13322: }
13323: }
1.191 raeburn 13324: if ($i == @domcoord - 1) {
1.125 raeburn 13325: my $colsleft = $numinrow - $rem;
13326: if ($colsleft > 1) {
1.191 raeburn 13327: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 13328: } else {
1.191 raeburn 13329: $table .= '<td class="LC_left_item">';
1.125 raeburn 13330: }
13331: } else {
1.191 raeburn 13332: $table .= '<td class="LC_left_item">';
13333: }
13334: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
13335: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
13336: $table .= '<span class="LC_nobreak"><label>'.
13337: '<input type="'.$inputtype.'" name="'.$name.'"'.
13338: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
13339: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 13340: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 13341: }
1.219 raeburn 13342: $table .= '</label></span></td>';
1.191 raeburn 13343: }
13344: $table .= '</tr></table>';
13345: } elsif ($numdcs == 1) {
1.219 raeburn 13346: my ($dcname,$dcdom) = split(':',$domcoord[0]);
13347: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 13348: if ($inputtype eq 'radio') {
1.247 raeburn 13349: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 13350: if ($user ne $dcname.':'.$dcdom) {
13351: $table .= ' ('.$dcname.':'.$dcdom.')';
13352: }
1.191 raeburn 13353: } else {
13354: my $check;
13355: if (exists($currhash{$domcoord[0]})) {
13356: $check = ' checked="checked"';
1.125 raeburn 13357: }
1.247 raeburn 13358: $table = '<span class="LC_nobreak"><label>'.
13359: '<input type="checkbox" name="'.$name.'" '.
13360: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 13361: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 13362: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 13363: }
1.220 raeburn 13364: $table .= '</label></span>';
1.191 raeburn 13365: $rows ++;
1.125 raeburn 13366: }
13367: }
1.191 raeburn 13368: return ($numdcs,$table,$rows);
1.125 raeburn 13369: }
13370:
1.137 raeburn 13371: sub usersession_titles {
13372: return &Apache::lonlocal::texthash(
13373: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
13374: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 13375: spares => 'Servers offloaded to, when busy',
1.137 raeburn 13376: version => 'LON-CAPA version requirement',
1.138 raeburn 13377: excludedomain => 'Allow all, but exclude specific domains',
13378: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 13379: primary => 'Primary (checked first)',
1.154 raeburn 13380: default => 'Default',
1.137 raeburn 13381: );
13382: }
13383:
1.152 raeburn 13384: sub id_for_thisdom {
13385: my (%servers) = @_;
13386: my %altids;
13387: foreach my $server (keys(%servers)) {
13388: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
13389: if ($serverhome ne $server) {
13390: $altids{$serverhome} = $server;
13391: }
13392: }
13393: return %altids;
13394: }
13395:
1.150 raeburn 13396: sub count_servers {
13397: my ($currbalancer,%servers) = @_;
13398: my (@spares,$numspares);
13399: foreach my $lonhost (sort(keys(%servers))) {
13400: next if ($currbalancer eq $lonhost);
13401: push(@spares,$lonhost);
13402: }
13403: if ($currbalancer) {
13404: $numspares = scalar(@spares);
13405: } else {
13406: $numspares = scalar(@spares) - 1;
13407: }
13408: return ($numspares,@spares);
13409: }
13410:
13411: sub lonbalance_targets_js {
1.171 raeburn 13412: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 13413: my $select = &mt('Select');
13414: my ($alltargets,$allishome,$allinsttypes,@alltypes);
13415: if (ref($servers) eq 'HASH') {
13416: $alltargets = join("','",sort(keys(%{$servers})));
13417: my @homedoms;
13418: foreach my $server (sort(keys(%{$servers}))) {
13419: if (&Apache::lonnet::host_domain($server) eq $dom) {
13420: push(@homedoms,'1');
13421: } else {
13422: push(@homedoms,'0');
13423: }
13424: }
13425: $allishome = join("','",@homedoms);
13426: }
13427: if (ref($types) eq 'ARRAY') {
13428: if (@{$types} > 0) {
13429: @alltypes = @{$types};
13430: }
13431: }
13432: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
13433: $allinsttypes = join("','",@alltypes);
1.171 raeburn 13434: my (%currbalancer,%currtargets,%currrules,%existing);
13435: if (ref($settings) eq 'HASH') {
13436: %existing = %{$settings};
13437: }
13438: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
13439: \%currtargets,\%currrules);
1.210 raeburn 13440: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 13441: return <<"END";
13442:
13443: <script type="text/javascript">
13444: // <![CDATA[
13445:
1.171 raeburn 13446: currBalancers = new Array('$balancers');
13447:
13448: function toggleTargets(balnum) {
13449: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13450: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
13451: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
13452: var prevbalancer = prevhostitem.value;
13453: var baltotal = document.getElementById('loadbalancing_total').value;
13454: prevhostitem.value = balancer;
13455: if (prevbalancer != '') {
13456: var prevIdx = currBalancers.indexOf(prevbalancer);
13457: if (prevIdx != -1) {
13458: currBalancers.splice(prevIdx,1);
13459: }
13460: }
1.150 raeburn 13461: if (balancer == '') {
1.171 raeburn 13462: hideSpares(balnum);
1.150 raeburn 13463: } else {
1.171 raeburn 13464: var currIdx = currBalancers.indexOf(balancer);
13465: if (currIdx == -1) {
13466: currBalancers.push(balancer);
13467: }
1.150 raeburn 13468: var homedoms = new Array('$allishome');
1.171 raeburn 13469: var ishomedom = homedoms[lonhostitem.selectedIndex];
13470: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 13471: }
1.171 raeburn 13472: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 13473: return;
13474: }
13475:
1.171 raeburn 13476: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 13477: var alltargets = new Array('$alltargets');
13478: var insttypes = new Array('$allinsttypes');
1.151 raeburn 13479: var offloadtypes = new Array('primary','default');
13480:
1.171 raeburn 13481: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
13482: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 13483:
1.151 raeburn 13484: for (var i=0; i<offloadtypes.length; i++) {
13485: var count = 0;
13486: for (var j=0; j<alltargets.length; j++) {
13487: if (alltargets[j] != balancer) {
1.171 raeburn 13488: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
13489: item.value = alltargets[j];
13490: item.style.textAlign='left';
13491: item.style.textFace='normal';
13492: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
13493: if (currBalancers.indexOf(alltargets[j]) == -1) {
13494: item.disabled = '';
13495: } else {
13496: item.disabled = 'disabled';
13497: item.checked = false;
13498: }
1.151 raeburn 13499: count ++;
13500: }
1.150 raeburn 13501: }
13502: }
1.151 raeburn 13503: for (var k=0; k<insttypes.length; k++) {
13504: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 13505: if (ishomedom == 1) {
1.171 raeburn 13506: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13507: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13508: } else {
1.171 raeburn 13509: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13510: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 13511: }
13512: } else {
1.171 raeburn 13513: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13514: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13515: }
1.151 raeburn 13516: if ((insttypes[k] != '_LC_external') &&
13517: ((insttypes[k] != '_LC_internetdom') ||
13518: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 13519: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
13520: item.options.length = 0;
13521: item.options[0] = new Option("","",true,true);
1.210 raeburn 13522: var idx = 0;
1.151 raeburn 13523: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 13524: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
13525: idx ++;
13526: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 13527: }
13528: }
13529: }
13530: }
13531: return;
13532: }
13533:
1.171 raeburn 13534: function hideSpares(balnum) {
1.150 raeburn 13535: var alltargets = new Array('$alltargets');
13536: var insttypes = new Array('$allinsttypes');
13537: var offloadtypes = new Array('primary','default');
13538:
1.171 raeburn 13539: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
13540: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 13541:
13542: var total = alltargets.length - 1;
13543: for (var i=0; i<offloadtypes; i++) {
13544: for (var j=0; j<total; j++) {
1.171 raeburn 13545: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
13546: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
13547: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 13548: }
1.150 raeburn 13549: }
13550: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 13551: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13552: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 13553: if (insttypes[k] != '_LC_external') {
1.171 raeburn 13554: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
13555: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 13556: }
13557: }
13558: return;
13559: }
13560:
1.171 raeburn 13561: function checkOffloads(item,balnum,type) {
1.150 raeburn 13562: var alltargets = new Array('$alltargets');
13563: var offloadtypes = new Array('primary','default');
13564: if (item.checked) {
13565: var total = alltargets.length - 1;
13566: var other;
13567: if (type == offloadtypes[0]) {
1.151 raeburn 13568: other = offloadtypes[1];
1.150 raeburn 13569: } else {
1.151 raeburn 13570: other = offloadtypes[0];
1.150 raeburn 13571: }
13572: for (var i=0; i<total; i++) {
1.171 raeburn 13573: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 13574: if (server == item.value) {
1.171 raeburn 13575: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
13576: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 13577: }
13578: }
13579: }
13580: }
13581: return;
13582: }
13583:
1.171 raeburn 13584: function singleServerToggle(balnum,type) {
13585: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 13586: if (offloadtoSelIdx == 0) {
1.171 raeburn 13587: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
13588: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13589:
13590: } else {
1.171 raeburn 13591: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
13592: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 13593: }
13594: return;
13595: }
13596:
1.171 raeburn 13597: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 13598: if (type == '_LC_external') {
1.171 raeburn 13599: return;
1.150 raeburn 13600: }
1.171 raeburn 13601: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 13602: for (var i=0; i<typesRules.length; i++) {
13603: if (formname.elements[typesRules[i]].checked) {
13604: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 13605: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
13606: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13607: } else {
1.171 raeburn 13608: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
13609: }
13610: }
13611: }
13612: return;
13613: }
13614:
13615: function balancerDeleteChange(balnum) {
13616: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13617: var baltotal = document.getElementById('loadbalancing_total').value;
13618: var addtarget;
13619: var removetarget;
13620: var action = 'delete';
13621: if (document.getElementById('loadbalancing_delete_'+balnum)) {
13622: var lonhost = hostitem.value;
13623: var currIdx = currBalancers.indexOf(lonhost);
13624: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
13625: if (currIdx != -1) {
13626: currBalancers.splice(currIdx,1);
13627: }
13628: addtarget = lonhost;
13629: } else {
13630: if (currIdx == -1) {
13631: currBalancers.push(lonhost);
13632: }
13633: removetarget = lonhost;
13634: action = 'undelete';
13635: }
13636: balancerChange(balnum,baltotal,action,addtarget,removetarget);
13637: }
13638: return;
13639: }
13640:
13641: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
13642: if (baltotal > 1) {
13643: var offloadtypes = new Array('primary','default');
13644: var alltargets = new Array('$alltargets');
13645: var insttypes = new Array('$allinsttypes');
13646: for (var i=0; i<baltotal; i++) {
13647: if (i != balnum) {
13648: for (var j=0; j<offloadtypes.length; j++) {
13649: var total = alltargets.length - 1;
13650: for (var k=0; k<total; k++) {
13651: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
13652: var server = serveritem.value;
13653: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13654: if (server == addtarget) {
13655: serveritem.disabled = '';
13656: }
13657: }
13658: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13659: if (server == removetarget) {
13660: serveritem.disabled = 'disabled';
13661: serveritem.checked = false;
13662: }
13663: }
13664: }
13665: }
13666: for (var j=0; j<insttypes.length; j++) {
13667: if (insttypes[j] != '_LC_external') {
13668: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
13669: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
13670: var currSel = singleserver.selectedIndex;
13671: var currVal = singleserver.options[currSel].value;
13672: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13673: var numoptions = singleserver.options.length;
13674: var needsnew = 1;
13675: for (var k=0; k<numoptions; k++) {
13676: if (singleserver.options[k] == addtarget) {
13677: needsnew = 0;
13678: break;
13679: }
13680: }
13681: if (needsnew == 1) {
13682: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
13683: }
13684: }
13685: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13686: singleserver.options.length = 0;
13687: if ((currVal) && (currVal != removetarget)) {
13688: singleserver.options[0] = new Option("","",false,false);
13689: } else {
13690: singleserver.options[0] = new Option("","",true,true);
13691: }
13692: var idx = 0;
13693: for (var m=0; m<alltargets.length; m++) {
13694: if (currBalancers.indexOf(alltargets[m]) == -1) {
13695: idx ++;
13696: if (currVal == alltargets[m]) {
13697: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
13698: } else {
13699: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
13700: }
13701: }
13702: }
13703: }
13704: }
13705: }
13706: }
1.150 raeburn 13707: }
13708: }
13709: }
13710: return;
13711: }
13712:
1.152 raeburn 13713: // ]]>
13714: </script>
13715:
13716: END
13717: }
13718:
13719: sub new_spares_js {
13720: my @sparestypes = ('primary','default');
13721: my $types = join("','",@sparestypes);
13722: my $select = &mt('Select');
13723: return <<"END";
13724:
13725: <script type="text/javascript">
13726: // <![CDATA[
13727:
13728: function updateNewSpares(formname,lonhost) {
13729: var types = new Array('$types');
13730: var include = new Array();
13731: var exclude = new Array();
13732: for (var i=0; i<types.length; i++) {
13733: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
13734: for (var j=0; j<spareboxes.length; j++) {
13735: if (formname.elements[spareboxes[j]].checked) {
13736: exclude.push(formname.elements[spareboxes[j]].value);
13737: } else {
13738: include.push(formname.elements[spareboxes[j]].value);
13739: }
13740: }
13741: }
13742: for (var i=0; i<types.length; i++) {
13743: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
13744: var selIdx = newSpare.selectedIndex;
13745: var currnew = newSpare.options[selIdx].value;
13746: var okSpares = new Array();
13747: for (var j=0; j<newSpare.options.length; j++) {
13748: var possible = newSpare.options[j].value;
13749: if (possible != '') {
13750: if (exclude.indexOf(possible) == -1) {
13751: okSpares.push(possible);
13752: } else {
13753: if (currnew == possible) {
13754: selIdx = 0;
13755: }
13756: }
13757: }
13758: }
13759: for (var k=0; k<include.length; k++) {
13760: if (okSpares.indexOf(include[k]) == -1) {
13761: okSpares.push(include[k]);
13762: }
13763: }
13764: okSpares.sort();
13765: newSpare.options.length = 0;
13766: if (selIdx == 0) {
13767: newSpare.options[0] = new Option("$select","",true,true);
13768: } else {
13769: newSpare.options[0] = new Option("$select","",false,false);
13770: }
13771: for (var m=0; m<okSpares.length; m++) {
13772: var idx = m+1;
13773: var selThis = 0;
13774: if (selIdx != 0) {
13775: if (okSpares[m] == currnew) {
13776: selThis = 1;
13777: }
13778: }
13779: if (selThis == 1) {
13780: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
13781: } else {
13782: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
13783: }
13784: }
13785: }
13786: return;
13787: }
13788:
13789: function checkNewSpares(lonhost,type) {
13790: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
13791: var chosen = newSpare.options[newSpare.selectedIndex].value;
13792: if (chosen != '') {
13793: var othertype;
13794: var othernewSpare;
13795: if (type == 'primary') {
13796: othernewSpare = document.getElementById('newspare_default_'+lonhost);
13797: }
13798: if (type == 'default') {
13799: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
13800: }
13801: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
13802: othernewSpare.selectedIndex = 0;
13803: }
13804: }
13805: return;
13806: }
13807:
13808: // ]]>
13809: </script>
13810:
13811: END
13812:
13813: }
13814:
13815: sub common_domprefs_js {
13816: return <<"END";
13817:
13818: <script type="text/javascript">
13819: // <![CDATA[
13820:
1.150 raeburn 13821: function getIndicesByName(formname,item) {
1.152 raeburn 13822: var group = new Array();
1.150 raeburn 13823: for (var i=0;i<formname.elements.length;i++) {
13824: if (formname.elements[i].name == item) {
1.152 raeburn 13825: group.push(formname.elements[i].id);
1.150 raeburn 13826: }
13827: }
1.152 raeburn 13828: return group;
1.150 raeburn 13829: }
13830:
13831: // ]]>
13832: </script>
13833:
13834: END
1.152 raeburn 13835:
1.150 raeburn 13836: }
13837:
1.165 raeburn 13838: sub recaptcha_js {
13839: my %lt = &captcha_phrases();
13840: return <<"END";
13841:
13842: <script type="text/javascript">
13843: // <![CDATA[
13844:
13845: function updateCaptcha(caller,context) {
13846: var privitem;
13847: var pubitem;
13848: var privtext;
13849: var pubtext;
1.269 raeburn 13850: var versionitem;
13851: var versiontext;
1.165 raeburn 13852: if (document.getElementById(context+'_recaptchapub')) {
13853: pubitem = document.getElementById(context+'_recaptchapub');
13854: } else {
13855: return;
13856: }
13857: if (document.getElementById(context+'_recaptchapriv')) {
13858: privitem = document.getElementById(context+'_recaptchapriv');
13859: } else {
13860: return;
13861: }
13862: if (document.getElementById(context+'_recaptchapubtxt')) {
13863: pubtext = document.getElementById(context+'_recaptchapubtxt');
13864: } else {
13865: return;
13866: }
13867: if (document.getElementById(context+'_recaptchaprivtxt')) {
13868: privtext = document.getElementById(context+'_recaptchaprivtxt');
13869: } else {
13870: return;
13871: }
1.269 raeburn 13872: if (document.getElementById(context+'_recaptchaversion')) {
13873: versionitem = document.getElementById(context+'_recaptchaversion');
13874: } else {
13875: return;
13876: }
13877: if (document.getElementById(context+'_recaptchavertxt')) {
13878: versiontext = document.getElementById(context+'_recaptchavertxt');
13879: } else {
13880: return;
13881: }
1.165 raeburn 13882: if (caller.checked) {
13883: if (caller.value == 'recaptcha') {
13884: pubitem.type = 'text';
13885: privitem.type = 'text';
13886: pubitem.size = '40';
13887: privitem.size = '40';
13888: pubtext.innerHTML = "$lt{'pub'}";
13889: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 13890: versionitem.type = 'text';
13891: versionitem.size = '3';
13892: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 13893: } else {
13894: pubitem.type = 'hidden';
13895: privitem.type = 'hidden';
1.269 raeburn 13896: versionitem.type = 'hidden';
1.165 raeburn 13897: pubtext.innerHTML = '';
13898: privtext.innerHTML = '';
1.269 raeburn 13899: versiontext.innerHTML = '';
1.165 raeburn 13900: }
13901: }
13902: return;
13903: }
13904:
13905: // ]]>
13906: </script>
13907:
13908: END
13909:
13910: }
13911:
1.236 raeburn 13912: sub toggle_display_js {
1.192 raeburn 13913: return <<"END";
13914:
13915: <script type="text/javascript">
13916: // <![CDATA[
13917:
1.236 raeburn 13918: function toggleDisplay(domForm,caller) {
13919: if (document.getElementById(caller)) {
13920: var divitem = document.getElementById(caller);
13921: var optionsElement = domForm.coursecredits;
1.264 raeburn 13922: var checkval = 1;
13923: var dispval = 'block';
1.236 raeburn 13924: if (caller == 'emailoptions') {
13925: optionsElement = domForm.cancreate_email;
13926: }
1.257 raeburn 13927: if (caller == 'studentsubmission') {
13928: optionsElement = domForm.postsubmit;
13929: }
1.264 raeburn 13930: if (caller == 'cloneinstcode') {
13931: optionsElement = domForm.canclone;
13932: checkval = 'instcode';
13933: }
1.236 raeburn 13934: if (optionsElement.length) {
1.192 raeburn 13935: var currval;
1.236 raeburn 13936: for (var i=0; i<optionsElement.length; i++) {
13937: if (optionsElement[i].checked) {
13938: currval = optionsElement[i].value;
1.192 raeburn 13939: }
13940: }
1.264 raeburn 13941: if (currval == checkval) {
13942: divitem.style.display = dispval;
1.192 raeburn 13943: } else {
1.236 raeburn 13944: divitem.style.display = 'none';
1.192 raeburn 13945: }
13946: }
13947: }
13948: return;
13949: }
13950:
13951: // ]]>
13952: </script>
13953:
13954: END
13955:
13956: }
13957:
1.165 raeburn 13958: sub captcha_phrases {
13959: return &Apache::lonlocal::texthash (
13960: priv => 'Private key',
13961: pub => 'Public key',
13962: original => 'original (CAPTCHA)',
13963: recaptcha => 'successor (ReCAPTCHA)',
13964: notused => 'unused',
1.269 raeburn 13965: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 13966: );
13967: }
13968:
1.205 raeburn 13969: sub devalidate_remote_domconfs {
1.212 raeburn 13970: my ($dom,$cachekeys) = @_;
13971: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 13972: my %servers = &Apache::lonnet::internet_dom_servers($dom);
13973: my %thismachine;
13974: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.267 raeburn 13975: my @posscached = ('domainconfig','domdefaults','ltitools');
1.260 raeburn 13976: if (keys(%servers)) {
1.205 raeburn 13977: foreach my $server (keys(%servers)) {
13978: next if ($thismachine{$server});
1.212 raeburn 13979: my @cached;
13980: foreach my $name (@posscached) {
13981: if ($cachekeys->{$name}) {
13982: push(@cached,&escape($name).':'.&escape($dom));
13983: }
13984: }
13985: if (@cached) {
13986: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
13987: }
1.205 raeburn 13988: }
13989: }
13990: return;
13991: }
13992:
1.3 raeburn 13993: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>