Annotation of loncom/interface/domainprefs.pm, revision 1.284
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.284 ! raeburn 4: # $Id: domainprefs.pm,v 1.283 2016/10/25 12:45:33 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' =>
1.282 raeburn 420: {text => 'Support settings',
1.118 jms 421: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 422: header => [{col1 => 'Help Page Settings (logged-in users)',
423: col2 => 'Value'},
424: {col1 => 'Helpdesk Roles',
425: col2 => 'Settings'},],
1.230 raeburn 426: print => \&print_helpsettings,
427: modify => \&modify_helpsettings,
1.118 jms 428: },
1.121 raeburn 429: 'coursedefaults' =>
430: {text => 'Course/Community defaults',
431: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 432: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
433: col2 => 'Value',},
434: {col1 => 'Defaults which can be overridden for each course by a DC',
435: col2 => 'Value',},],
1.230 raeburn 436: print => \&print_coursedefaults,
437: modify => \&modify_coursedefaults,
1.121 raeburn 438: },
1.231 raeburn 439: 'selfenrollment' =>
440: {text => 'Self-enrollment in Course/Community',
441: help => 'Domain_Configuration_Selfenrollment',
442: header => [{col1 => 'Configuration Rights',
443: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
444: {col1 => 'Defaults',
445: col2 => 'Value'},
446: {col1 => 'Self-enrollment validation (optional)',
447: col2 => 'Value'},],
448: print => \&print_selfenrollment,
449: modify => \&modify_selfenrollment,
450: },
1.120 raeburn 451: 'privacy' =>
452: {text => 'User Privacy',
453: help => 'Domain_Configuration_User_Privacy',
454: header => [{col1 => 'Setting',
455: col2 => 'Value',}],
1.230 raeburn 456: print => \&print_privacy,
457: modify => \&modify_privacy,
1.120 raeburn 458: },
1.141 raeburn 459: 'usersessions' =>
1.145 raeburn 460: {text => 'User session hosting/offloading',
1.137 raeburn 461: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 462: header => [{col1 => 'Domain server',
463: col2 => 'Servers to offload sessions to when busy'},
464: {col1 => 'Hosting of users from other domains',
1.137 raeburn 465: col2 => 'Rules'},
466: {col1 => "Hosting domain's own users elsewhere",
467: col2 => 'Rules'}],
1.230 raeburn 468: print => \&print_usersessions,
469: modify => \&modify_usersessions,
1.137 raeburn 470: },
1.279 raeburn 471: 'loadbalancing' =>
1.185 raeburn 472: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 473: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 474: header => [{col1 => 'Balancers',
1.150 raeburn 475: col2 => 'Default destinations',
1.183 bisitz 476: col3 => 'User affiliation',
1.150 raeburn 477: col4 => 'Overrides'},
478: ],
1.230 raeburn 479: print => \&print_loadbalancing,
480: modify => \&modify_loadbalancing,
1.150 raeburn 481: },
1.279 raeburn 482: 'ltitools' =>
1.267 raeburn 483: {text => 'External Tools (LTI)',
484: help => 'Domain_configuration_LTI_Tools',
485: header => [{col1 => 'Setting',
486: col2 => 'Value',}],
487: print => \&print_ltitools,
488: modify => \&modify_ltitools,
489: },
1.279 raeburn 490: 'ssl' =>
1.275 raeburn 491: {text => 'LON-CAPA Network (SSL)',
492: help => 'Domain_Configuration_Network_SSL',
493: header => [{col1 => 'Server',
494: col2 => 'Certificate Status'},
495: {col1 => 'Connections to other servers',
496: col2 => 'Rules'},
497: {col1 => "Replicating domain's published content",
498: col2 => 'Rules'}],
499: print => \&print_ssl,
500: modify => \&modify_ssl,
501: },
1.279 raeburn 502: 'trust' =>
503: {text => 'Trust Settings',
504: help => 'Domain_Configuration_Trust',
505: header => [{col1 => "Access to this domain's content by others",
506: col2 => 'Rules'},
507: {col1 => "Access to other domain's content by this domain",
508: col2 => 'Rules'},
509: {col1 => "Enrollment in this domain's courses by others",
510: col2 => 'Rules',},
511: {col1 => "Co-author roles in this domain for others",
512: col2 => 'Rules',},
513: {col1 => "Co-author roles for this domain's users elsewhere",
514: col2 => 'Rules',},
515: {col1 => "Domain roles in this domain assignable to others",
516: col2 => 'Rules'},
517: {col1 => "Course catalog for this domain displayed elsewhere",
518: col2 => 'Rules'},
519: {col1 => "Requests for creation of courses in this domain by others",
520: col2 => 'Rules'},
521: {col1 => "Users in other domains can send messages to this domain",
522: col2 => 'Rules'},],
523: print => \&print_trust,
524: modify => \&modify_trust,
525: },
1.3 raeburn 526: );
1.110 raeburn 527: if (keys(%servers) > 1) {
528: $prefs{'login'} = { text => 'Log-in page options',
529: help => 'Domain_Configuration_Login_Page',
530: header => [{col1 => 'Log-in Service',
531: col2 => 'Server Setting',},
532: {col1 => 'Log-in Page Items',
1.168 raeburn 533: col2 => ''},
534: {col1 => 'Log-in Help',
1.256 raeburn 535: col2 => 'Value'},
536: {col1 => 'Custom HTML in document head',
1.168 raeburn 537: col2 => 'Value'}],
1.230 raeburn 538: print => \&print_login,
539: modify => \&modify_login,
1.110 raeburn 540: };
541: }
1.174 foxr 542:
1.6 raeburn 543: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 544: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 545: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 546: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 547: text=>"Settings to display/modify"});
1.9 raeburn 548: my $confname = $dom.'-domainconfig';
1.174 foxr 549:
1.3 raeburn 550: if ($phase eq 'process') {
1.212 raeburn 551: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
552: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 553: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 554: $r->rflush();
1.212 raeburn 555: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 556: }
1.30 raeburn 557: } elsif ($phase eq 'display') {
1.192 raeburn 558: my $js = &recaptcha_js().
1.236 raeburn 559: &toggle_display_js();
1.171 raeburn 560: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 561: my ($othertitle,$usertypes,$types) =
562: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 563: $js .= &lonbalance_targets_js($dom,$types,\%servers,
564: $domconfig{'loadbalancing'}).
1.170 raeburn 565: &new_spares_js().
566: &common_domprefs_js().
567: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 568: }
1.216 raeburn 569: if (grep(/^requestcourses$/,@actions)) {
570: my $javascript_validations;
571: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
572: $js .= <<END;
573: <script type="text/javascript">
574: $javascript_validations
575: </script>
576: $coursebrowserjs
577: END
578: }
1.150 raeburn 579: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 580: } else {
1.180 raeburn 581: # check if domconfig user exists for the domain.
582: my $servadm = $r->dir_config('lonAdmEMail');
583: my ($configuserok,$author_ok,$switchserver) =
584: &config_check($dom,$confname,$servadm);
585: unless ($configuserok eq 'ok') {
1.181 raeburn 586: &Apache::lonconfigsettings::print_header($r,$phase,$context);
587: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 588: $confname).
1.181 raeburn 589: '<br />'
590: );
1.180 raeburn 591: if ($switchserver) {
1.181 raeburn 592: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
593: '<br />'.
594: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
595: '<br />'.
596: &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).
597: '<br />'.
598: &mt('To do that now, use the following link: [_1]',$switchserver)
599: );
600: } else {
601: $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.').
602: '<br />'.
603: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
604: );
1.180 raeburn 605: }
606: $r->print(&Apache::loncommon::end_page());
607: return OK;
608: }
1.21 raeburn 609: if (keys(%domconfig) == 0) {
610: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 611: my @ids=&Apache::lonnet::current_machine_ids();
612: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 613: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 614: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 615: my $custom_img_count = 0;
616: foreach my $img (@loginimages) {
617: if ($designhash{$dom.'.login.'.$img} ne '') {
618: $custom_img_count ++;
619: }
620: }
621: foreach my $role (@roles) {
622: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
623: $custom_img_count ++;
624: }
625: }
626: if ($custom_img_count > 0) {
1.94 raeburn 627: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 628: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 629: $r->print(
630: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
631: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
632: &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 />'.
633: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
634: if ($switch_server) {
1.30 raeburn 635: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 636: }
1.91 raeburn 637: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 638: return OK;
639: }
640: }
641: }
1.91 raeburn 642: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 643: }
644: return OK;
645: }
646:
647: sub process_changes {
1.205 raeburn 648: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 649: my %domconfig;
650: if (ref($values) eq 'HASH') {
651: %domconfig = %{$values};
652: }
1.3 raeburn 653: my $output;
654: if ($action eq 'login') {
1.205 raeburn 655: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 656: } elsif ($action eq 'rolecolors') {
1.9 raeburn 657: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 658: $lastactref,%domconfig);
1.3 raeburn 659: } elsif ($action eq 'quotas') {
1.216 raeburn 660: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 661: } elsif ($action eq 'autoenroll') {
1.205 raeburn 662: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 663: } elsif ($action eq 'autoupdate') {
664: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 665: } elsif ($action eq 'autocreate') {
666: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 667: } elsif ($action eq 'directorysrch') {
668: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 669: } elsif ($action eq 'usercreation') {
1.28 raeburn 670: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 671: } elsif ($action eq 'selfcreation') {
672: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 673: } elsif ($action eq 'usermodification') {
674: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 675: } elsif ($action eq 'contacts') {
1.205 raeburn 676: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 677: } elsif ($action eq 'defaults') {
1.212 raeburn 678: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 679: } elsif ($action eq 'scantron') {
1.205 raeburn 680: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 681: } elsif ($action eq 'coursecategories') {
1.239 raeburn 682: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 683: } elsif ($action eq 'serverstatuses') {
684: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 685: } elsif ($action eq 'requestcourses') {
1.216 raeburn 686: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 687: } elsif ($action eq 'requestauthor') {
1.216 raeburn 688: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 689: } elsif ($action eq 'helpsettings') {
1.122 jms 690: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 691: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 692: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 693: } elsif ($action eq 'selfenrollment') {
694: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 695: } elsif ($action eq 'usersessions') {
1.212 raeburn 696: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 697: } elsif ($action eq 'loadbalancing') {
698: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 699: } elsif ($action eq 'ltitools') {
700: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 701: } elsif ($action eq 'ssl') {
702: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 703: } elsif ($action eq 'trust') {
704: $output = &modify_trust($dom,$lastactref,%domconfig);
1.3 raeburn 705: }
706: return $output;
707: }
708:
709: sub print_config_box {
1.9 raeburn 710: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 711: my $rowtotal = 0;
1.49 raeburn 712: my $output;
713: if ($action eq 'coursecategories') {
714: $output = &coursecategories_javascript($settings);
1.236 raeburn 715: } elsif ($action eq 'defaults') {
716: $output = &defaults_javascript($settings);
1.282 raeburn 717: } elsif ($action eq 'helpsettings') {
718: my (%privs,%levelscurrent);
719: my %full=();
720: my %levels=(
721: course => {},
722: domain => {},
723: system => {},
724: );
725: my $context = 'domain';
726: my $crstype = 'Course';
727: my $formname = 'display';
728: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
729: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
730: $output =
731: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
732: \@templateroles);
1.91 raeburn 733: }
1.236 raeburn 734: $output .=
1.30 raeburn 735: '<table class="LC_nested_outer">
1.3 raeburn 736: <tr>
1.66 raeburn 737: <th align="left" valign="middle"><span class="LC_nobreak">'.
738: &mt($item->{text}).' '.
739: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
740: '</tr>';
1.30 raeburn 741: $rowtotal ++;
1.110 raeburn 742: my $numheaders = 1;
743: if (ref($item->{'header'}) eq 'ARRAY') {
744: $numheaders = scalar(@{$item->{'header'}});
745: }
746: if ($numheaders > 1) {
1.64 raeburn 747: my $colspan = '';
1.145 raeburn 748: my $rightcolspan = '';
1.238 raeburn 749: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 750: ($action eq 'directorysrch') ||
1.256 raeburn 751: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 752: $colspan = ' colspan="2"';
753: }
1.145 raeburn 754: if ($action eq 'usersessions') {
755: $rightcolspan = ' colspan="3"';
756: }
1.30 raeburn 757: $output .= '
1.3 raeburn 758: <tr>
759: <td>
760: <table class="LC_nested">
761: <tr class="LC_info_row">
1.59 bisitz 762: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 763: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 764: </tr>';
1.69 raeburn 765: $rowtotal ++;
1.230 raeburn 766: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 767: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 768: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.282 raeburn 769: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings')) {
1.230 raeburn 770: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 771: } elsif ($action eq 'coursecategories') {
1.230 raeburn 772: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 773: } elsif ($action eq 'login') {
1.256 raeburn 774: if ($numheaders == 4) {
1.168 raeburn 775: $colspan = ' colspan="2"';
776: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
777: } else {
778: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
779: }
1.230 raeburn 780: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 781: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 782: } elsif ($action eq 'rolecolors') {
1.30 raeburn 783: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 784: }
1.30 raeburn 785: $output .= '
1.6 raeburn 786: </table>
787: </td>
788: </tr>
789: <tr>
790: <td>
791: <table class="LC_nested">
792: <tr class="LC_info_row">
1.230 raeburn 793: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 794: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 795: </tr>';
796: $rowtotal ++;
1.230 raeburn 797: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
798: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 799: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.279 raeburn 800: ($action eq 'ssl') || ($action eq 'trust')) {
1.238 raeburn 801: if ($action eq 'coursecategories') {
802: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
803: $colspan = ' colspan="2"';
1.279 raeburn 804: } elsif ($action eq 'trust') {
805: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.238 raeburn 806: } else {
807: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
808: }
1.279 raeburn 809: if ($action eq 'trust') {
810: $output .= '
811: </table>
812: </td>
813: </tr>';
814: my @trusthdrs = qw(2 3 4 5 6 7);
815: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
816: for (my $i=0; $i<@trusthdrs; $i++) {
817: $output .= '
818: <tr>
819: <td>
820: <table class="LC_nested">
821: <tr class="LC_info_row">
822: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
823: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
824: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
825: </table>
826: </td>
827: </tr>';
828: }
829: $output .= '
830: <tr>
831: <td>
832: <table class="LC_nested">
833: <tr class="LC_info_row">
834: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
835: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
836: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
837: } else {
838: $output .= '
1.63 raeburn 839: </table>
840: </td>
841: </tr>
842: <tr>
843: <td>
844: <table class="LC_nested">
845: <tr class="LC_info_row">
846: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 847: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 848: </tr>'."\n";
1.279 raeburn 849: if ($action eq 'coursecategories') {
850: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
851: } else {
852: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
853: }
1.238 raeburn 854: }
1.63 raeburn 855: $rowtotal ++;
1.236 raeburn 856: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282 raeburn 857: ($action eq 'defaults') || ($action eq 'directorysrch') ||
858: ($action eq 'helpsettings')) {
1.230 raeburn 859: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 860: } elsif ($action eq 'login') {
1.256 raeburn 861: if ($numheaders == 4) {
1.168 raeburn 862: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
863: </table>
864: </td>
865: </tr>
866: <tr>
867: <td>
868: <table class="LC_nested">
869: <tr class="LC_info_row">
870: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 871: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 872: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
873: $rowtotal ++;
874: } else {
875: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
876: }
1.256 raeburn 877: $output .= '
878: </table>
879: </td>
880: </tr>
881: <tr>
882: <td>
883: <table class="LC_nested">
884: <tr class="LC_info_row">';
885: if ($numheaders == 4) {
886: $output .= '
887: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
888: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
889: </tr>';
890: } else {
891: $output .= '
892: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
893: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
894: </tr>';
895: }
896: $rowtotal ++;
897: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 898: } elsif ($action eq 'requestcourses') {
1.247 raeburn 899: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
900: $rowtotal ++;
901: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 902: </table>
903: </td>
904: </tr>
905: <tr>
906: <td>
907: <table class="LC_nested">
908: <tr class="LC_info_row">
909: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
910: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 911: &textbookcourses_javascript($settings).
912: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
913: </table>
914: </td>
915: </tr>
916: <tr>
917: <td>
918: <table class="LC_nested">
919: <tr class="LC_info_row">
920: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
921: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
922: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 923: </table>
924: </td>
925: </tr>
926: <tr>
927: <td>
928: <table class="LC_nested">
929: <tr class="LC_info_row">
1.242 raeburn 930: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
931: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 932: </tr>'.
933: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 934: } elsif ($action eq 'requestauthor') {
935: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 936: $rowtotal ++;
1.122 jms 937: } elsif ($action eq 'rolecolors') {
1.30 raeburn 938: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 939: </table>
940: </td>
941: </tr>
942: <tr>
943: <td>
944: <table class="LC_nested">
945: <tr class="LC_info_row">
1.69 raeburn 946: <td class="LC_left_item"'.$colspan.' valign="top">'.
947: &mt($item->{'header'}->[2]->{'col1'}).'</td>
948: <td class="LC_right_item" valign="top">'.
949: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 950: </tr>'.
1.30 raeburn 951: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 952: </table>
953: </td>
954: </tr>
955: <tr>
956: <td>
957: <table class="LC_nested">
958: <tr class="LC_info_row">
1.59 bisitz 959: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
960: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 961: </tr>'.
1.30 raeburn 962: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
963: $rowtotal += 2;
1.6 raeburn 964: }
1.3 raeburn 965: } else {
1.30 raeburn 966: $output .= '
1.3 raeburn 967: <tr>
968: <td>
969: <table class="LC_nested">
1.30 raeburn 970: <tr class="LC_info_row">';
1.277 raeburn 971: if ($action eq 'login') {
1.30 raeburn 972: $output .= '
1.59 bisitz 973: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 974: } elsif ($action eq 'serverstatuses') {
975: $output .= '
976: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
977: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
978:
1.6 raeburn 979: } else {
1.30 raeburn 980: $output .= '
1.69 raeburn 981: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
982: }
1.72 raeburn 983: if (defined($item->{'header'}->[0]->{'col3'})) {
984: $output .= '<td class="LC_left_item" valign="top">'.
985: &mt($item->{'header'}->[0]->{'col2'});
986: if ($action eq 'serverstatuses') {
987: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
988: }
1.69 raeburn 989: } else {
990: $output .= '<td class="LC_right_item" valign="top">'.
991: &mt($item->{'header'}->[0]->{'col2'});
992: }
993: $output .= '</td>';
994: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 995: if (defined($item->{'header'}->[0]->{'col4'})) {
996: $output .= '<td class="LC_left_item" valign="top">'.
997: &mt($item->{'header'}->[0]->{'col3'});
998: } else {
999: $output .= '<td class="LC_right_item" valign="top">'.
1000: &mt($item->{'header'}->[0]->{'col3'});
1001: }
1.69 raeburn 1002: if ($action eq 'serverstatuses') {
1003: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1004: }
1005: $output .= '</td>';
1.6 raeburn 1006: }
1.150 raeburn 1007: if ($item->{'header'}->[0]->{'col4'}) {
1008: $output .= '<td class="LC_right_item" valign="top">'.
1009: &mt($item->{'header'}->[0]->{'col4'});
1010: }
1.69 raeburn 1011: $output .= '</tr>';
1.48 raeburn 1012: $rowtotal ++;
1.168 raeburn 1013: if ($action eq 'quotas') {
1.86 raeburn 1014: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1015: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1016: ($action eq 'contacts') || ($action eq 'serverstatuses') ||
1017: ($action eq 'loadbalancing') || ($action eq 'ltitools')) {
1.230 raeburn 1018: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 1019: } elsif ($action eq 'scantron') {
1020: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.121 raeburn 1021: }
1.3 raeburn 1022: }
1.30 raeburn 1023: $output .= '
1.3 raeburn 1024: </table>
1025: </td>
1026: </tr>
1.30 raeburn 1027: </table><br />';
1028: return ($output,$rowtotal);
1.1 raeburn 1029: }
1030:
1.3 raeburn 1031: sub print_login {
1.168 raeburn 1032: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 1033: my ($css_class,$datatable);
1.6 raeburn 1034: my %choices = &login_choices();
1.110 raeburn 1035:
1.168 raeburn 1036: if ($caller eq 'service') {
1.149 raeburn 1037: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1038: my $choice = $choices{'disallowlogin'};
1039: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1040: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 1041: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1042: '<th>'.$choices{'server'}.'</th>'.
1043: '<th>'.$choices{'serverpath'}.'</th>'.
1044: '<th>'.$choices{'custompath'}.'</th>'.
1045: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1046: my %disallowed;
1047: if (ref($settings) eq 'HASH') {
1048: if (ref($settings->{'loginvia'}) eq 'HASH') {
1049: %disallowed = %{$settings->{'loginvia'}};
1050: }
1051: }
1052: foreach my $lonhost (sort(keys(%servers))) {
1053: my $direct = 'selected="selected"';
1.128 raeburn 1054: if (ref($disallowed{$lonhost}) eq 'HASH') {
1055: if ($disallowed{$lonhost}{'server'} ne '') {
1056: $direct = '';
1057: }
1.110 raeburn 1058: }
1.115 raeburn 1059: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1060: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1061: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1062: '</option>';
1.184 raeburn 1063: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1064: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1065: my $selected = '';
1.128 raeburn 1066: if (ref($disallowed{$lonhost}) eq 'HASH') {
1067: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1068: $selected = 'selected="selected"';
1069: }
1.110 raeburn 1070: }
1071: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1072: $servers{$hostid}.'</option>';
1073: }
1.128 raeburn 1074: $datatable .= '</select></td>'.
1075: '<td><select name="'.$lonhost.'_serverpath">';
1076: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1077: my $pathname = $path;
1078: if ($path eq 'custom') {
1079: $pathname = &mt('Custom Path').' ->';
1080: }
1081: my $selected = '';
1082: if (ref($disallowed{$lonhost}) eq 'HASH') {
1083: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1084: $selected = 'selected="selected"';
1085: }
1086: } elsif ($path eq '') {
1087: $selected = 'selected="selected"';
1088: }
1089: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1090: }
1091: $datatable .= '</select></td>';
1092: my ($custom,$exempt);
1093: if (ref($disallowed{$lonhost}) eq 'HASH') {
1094: $custom = $disallowed{$lonhost}{'custompath'};
1095: $exempt = $disallowed{$lonhost}{'exempt'};
1096: }
1097: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1098: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1099: '</tr>';
1.110 raeburn 1100: }
1101: $datatable .= '</table></td></tr>';
1102: return $datatable;
1.168 raeburn 1103: } elsif ($caller eq 'page') {
1104: my %defaultchecked = (
1105: 'coursecatalog' => 'on',
1.188 raeburn 1106: 'helpdesk' => 'on',
1.168 raeburn 1107: 'adminmail' => 'off',
1108: 'newuser' => 'off',
1109: );
1.188 raeburn 1110: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1111: my (%checkedon,%checkedoff);
1.42 raeburn 1112: foreach my $item (@toggles) {
1.168 raeburn 1113: if ($defaultchecked{$item} eq 'on') {
1114: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1115: $checkedoff{$item} = ' ';
1.168 raeburn 1116: } elsif ($defaultchecked{$item} eq 'off') {
1117: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1118: $checkedon{$item} = ' ';
1119: }
1.1 raeburn 1120: }
1.168 raeburn 1121: my @images = ('img','logo','domlogo','login');
1122: my @logintext = ('textcol','bgcol');
1123: my @bgs = ('pgbg','mainbg','sidebg');
1124: my @links = ('link','alink','vlink');
1125: my %designhash = &Apache::loncommon::get_domainconf($dom);
1126: my %defaultdesign = %Apache::loncommon::defaultdesign;
1127: my (%is_custom,%designs);
1128: my %defaults = (
1129: font => $defaultdesign{'login.font'},
1130: );
1.6 raeburn 1131: foreach my $item (@images) {
1.168 raeburn 1132: $defaults{$item} = $defaultdesign{'login.'.$item};
1133: $defaults{'showlogo'}{$item} = 1;
1134: }
1135: foreach my $item (@bgs) {
1136: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1137: }
1.41 raeburn 1138: foreach my $item (@logintext) {
1.168 raeburn 1139: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1140: }
1.168 raeburn 1141: foreach my $item (@links) {
1142: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1143: }
1.168 raeburn 1144: if (ref($settings) eq 'HASH') {
1145: foreach my $item (@toggles) {
1146: if ($settings->{$item} eq '1') {
1147: $checkedon{$item} = ' checked="checked" ';
1148: $checkedoff{$item} = ' ';
1149: } elsif ($settings->{$item} eq '0') {
1150: $checkedoff{$item} = ' checked="checked" ';
1151: $checkedon{$item} = ' ';
1152: }
1153: }
1154: foreach my $item (@images) {
1155: if (defined($settings->{$item})) {
1156: $designs{$item} = $settings->{$item};
1157: $is_custom{$item} = 1;
1158: }
1159: if (defined($settings->{'showlogo'}{$item})) {
1160: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1161: }
1162: }
1163: foreach my $item (@logintext) {
1164: if ($settings->{$item} ne '') {
1165: $designs{'logintext'}{$item} = $settings->{$item};
1166: $is_custom{$item} = 1;
1167: }
1168: }
1169: if ($settings->{'font'} ne '') {
1170: $designs{'font'} = $settings->{'font'};
1171: $is_custom{'font'} = 1;
1172: }
1173: foreach my $item (@bgs) {
1174: if ($settings->{$item} ne '') {
1175: $designs{'bgs'}{$item} = $settings->{$item};
1176: $is_custom{$item} = 1;
1177: }
1178: }
1179: foreach my $item (@links) {
1180: if ($settings->{$item} ne '') {
1181: $designs{'links'}{$item} = $settings->{$item};
1182: $is_custom{$item} = 1;
1183: }
1184: }
1185: } else {
1186: if ($designhash{$dom.'.login.font'} ne '') {
1187: $designs{'font'} = $designhash{$dom.'.login.font'};
1188: $is_custom{'font'} = 1;
1189: }
1190: foreach my $item (@images) {
1191: if ($designhash{$dom.'.login.'.$item} ne '') {
1192: $designs{$item} = $designhash{$dom.'.login.'.$item};
1193: $is_custom{$item} = 1;
1194: }
1195: }
1196: foreach my $item (@bgs) {
1197: if ($designhash{$dom.'.login.'.$item} ne '') {
1198: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1199: $is_custom{$item} = 1;
1200: }
1.6 raeburn 1201: }
1.168 raeburn 1202: foreach my $item (@links) {
1203: if ($designhash{$dom.'.login.'.$item} ne '') {
1204: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1205: $is_custom{$item} = 1;
1206: }
1.6 raeburn 1207: }
1208: }
1.168 raeburn 1209: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1210: logo => 'Institution Logo',
1211: domlogo => 'Domain Logo',
1212: login => 'Login box');
1213: my $itemcount = 1;
1214: foreach my $item (@toggles) {
1215: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1216: $datatable .=
1217: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1218: '</td><td>'.
1219: '<span class="LC_nobreak"><label><input type="radio" name="'.
1220: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1221: '</label> <label><input type="radio" name="'.$item.'"'.
1222: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1223: '</tr>';
1224: $itemcount ++;
1.6 raeburn 1225: }
1.168 raeburn 1226: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1227: $datatable .= '</tr></table></td></tr>';
1228: } elsif ($caller eq 'help') {
1229: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1230: my $switchserver = &check_switchserver($dom,$confname);
1231: my $itemcount = 1;
1232: $defaulturl = '/adm/loginproblems.html';
1233: $defaulttype = 'default';
1234: %lt = &Apache::lonlocal::texthash (
1235: del => 'Delete?',
1236: rep => 'Replace:',
1237: upl => 'Upload:',
1238: default => 'Default',
1239: custom => 'Custom',
1240: );
1241: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1242: my @currlangs;
1243: if (ref($settings) eq 'HASH') {
1244: if (ref($settings->{'helpurl'}) eq 'HASH') {
1245: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1246: next if ($settings->{'helpurl'}{$key} eq '');
1247: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1248: $type{$key} = 'custom';
1249: unless ($key eq 'nolang') {
1250: push(@currlangs,$key);
1251: }
1252: }
1253: } elsif ($settings->{'helpurl'} ne '') {
1254: $type{'nolang'} = 'custom';
1255: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1256: }
1257: }
1.168 raeburn 1258: foreach my $lang ('nolang',sort(@currlangs)) {
1259: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1260: $datatable .= '<tr'.$css_class.'>';
1261: if ($url{$lang} eq '') {
1262: $url{$lang} = $defaulturl;
1263: }
1264: if ($type{$lang} eq '') {
1265: $type{$lang} = $defaulttype;
1266: }
1267: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1268: if ($lang eq 'nolang') {
1269: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1270: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1271: } else {
1272: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1273: $langchoices{$lang},
1274: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1275: }
1276: $datatable .= '</span></td>'."\n".
1277: '<td class="LC_left_item">';
1278: if ($type{$lang} eq 'custom') {
1279: $datatable .= '<span class="LC_nobreak"><label>'.
1280: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1281: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1282: } else {
1283: $datatable .= $lt{'upl'};
1284: }
1285: $datatable .='<br />';
1286: if ($switchserver) {
1287: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1288: } else {
1289: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1290: }
1.168 raeburn 1291: $datatable .= '</td></tr>';
1292: $itemcount ++;
1.6 raeburn 1293: }
1.168 raeburn 1294: my @addlangs;
1295: foreach my $lang (sort(keys(%langchoices))) {
1296: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1297: push(@addlangs,$lang);
1298: }
1299: if (@addlangs > 0) {
1300: my %toadd;
1301: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1302: $toadd{''} = &mt('Select');
1303: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1304: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1305: &mt('Add log-in help page for a specific language:').' '.
1306: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1307: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1308: if ($switchserver) {
1309: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1310: } else {
1311: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1312: }
1.168 raeburn 1313: $datatable .= '</td></tr>';
1.169 raeburn 1314: $itemcount ++;
1.6 raeburn 1315: }
1.169 raeburn 1316: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1317: } elsif ($caller eq 'headtag') {
1318: my %domservers = &Apache::lonnet::get_servers($dom);
1319: my $choice = $choices{'headtag'};
1320: $css_class = ' class="LC_odd_row"';
1321: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1322: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1323: '<th>'.$choices{'current'}.'</th>'.
1324: '<th>'.$choices{'action'}.'</th>'.
1325: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1326: my (%currurls,%currexempt);
1327: if (ref($settings) eq 'HASH') {
1328: if (ref($settings->{'headtag'}) eq 'HASH') {
1329: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1330: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1331: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1332: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1333: }
1334: }
1335: }
1336: }
1337: my %lt = &Apache::lonlocal::texthash(
1338: del => 'Delete?',
1339: rep => 'Replace:',
1340: upl => 'Upload:',
1341: curr => 'View contents',
1342: none => 'None',
1343: );
1344: my $switchserver = &check_switchserver($dom,$confname);
1345: foreach my $lonhost (sort(keys(%domservers))) {
1346: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1347: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1348: if ($currurls{$lonhost}) {
1349: $datatable .= '<td class="LC_right_item"><a href="'.
1350: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1351: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1352: '">'.$lt{'curr'}.'</a></td>'.
1353: '<td><span class="LC_nobreak"><label>'.
1354: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1355: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1356: } else {
1357: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1358: }
1359: $datatable .='<br />';
1360: if ($switchserver) {
1361: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1362: } else {
1363: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1364: }
1365: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1366: }
1367: $datatable .= '</table></td></tr>';
1.1 raeburn 1368: }
1.6 raeburn 1369: return $datatable;
1370: }
1371:
1372: sub login_choices {
1373: my %choices =
1374: &Apache::lonlocal::texthash (
1.116 bisitz 1375: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1376: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1377: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1378: disallowlogin => "Login page requests redirected",
1379: hostid => "Server",
1.128 raeburn 1380: server => "Redirect to:",
1381: serverpath => "Path",
1382: custompath => "Custom",
1383: exempt => "Exempt IP(s)",
1.110 raeburn 1384: directlogin => "No redirect",
1385: newuser => "Link to create a user account",
1386: img => "Header",
1387: logo => "Main Logo",
1388: domlogo => "Domain Logo",
1389: login => "Log-in Header",
1390: textcol => "Text color",
1391: bgcol => "Box color",
1392: bgs => "Background colors",
1393: links => "Link colors",
1394: font => "Font color",
1395: pgbg => "Header",
1396: mainbg => "Page",
1397: sidebg => "Login box",
1398: link => "Link",
1399: alink => "Active link",
1400: vlink => "Visited link",
1.256 raeburn 1401: headtag => "Custom markup",
1402: action => "Action",
1403: current => "Current",
1.6 raeburn 1404: );
1405: return %choices;
1406: }
1407:
1408: sub print_rolecolors {
1.30 raeburn 1409: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1410: my %choices = &color_font_choices();
1411: my @bgs = ('pgbg','tabbg','sidebg');
1412: my @links = ('link','alink','vlink');
1413: my @images = ('img');
1414: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1415: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1416: my %defaultdesign = %Apache::loncommon::defaultdesign;
1417: my (%is_custom,%designs);
1.200 raeburn 1418: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1419: if (ref($settings) eq 'HASH') {
1420: if (ref($settings->{$role}) eq 'HASH') {
1421: if ($settings->{$role}->{'img'} ne '') {
1422: $designs{'img'} = $settings->{$role}->{'img'};
1423: $is_custom{'img'} = 1;
1424: }
1425: if ($settings->{$role}->{'font'} ne '') {
1426: $designs{'font'} = $settings->{$role}->{'font'};
1427: $is_custom{'font'} = 1;
1428: }
1.97 tempelho 1429: if ($settings->{$role}->{'fontmenu'} ne '') {
1430: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1431: $is_custom{'fontmenu'} = 1;
1432: }
1.6 raeburn 1433: foreach my $item (@bgs) {
1434: if ($settings->{$role}->{$item} ne '') {
1435: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1436: $is_custom{$item} = 1;
1437: }
1438: }
1439: foreach my $item (@links) {
1440: if ($settings->{$role}->{$item} ne '') {
1441: $designs{'links'}{$item} = $settings->{$role}->{$item};
1442: $is_custom{$item} = 1;
1443: }
1444: }
1445: }
1446: } else {
1447: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1448: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1449: $is_custom{'img'} = 1;
1450: }
1.97 tempelho 1451: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1452: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1453: $is_custom{'fontmenu'} = 1;
1454: }
1.6 raeburn 1455: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1456: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1457: $is_custom{'font'} = 1;
1458: }
1459: foreach my $item (@bgs) {
1460: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1461: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1462: $is_custom{$item} = 1;
1463:
1464: }
1465: }
1466: foreach my $item (@links) {
1467: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1468: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1469: $is_custom{$item} = 1;
1470: }
1471: }
1472: }
1473: my $itemcount = 1;
1.30 raeburn 1474: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1475: $datatable .= '</tr></table></td></tr>';
1476: return $datatable;
1477: }
1478:
1.200 raeburn 1479: sub role_defaults {
1480: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1481: my %defaults;
1482: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1483: return %defaults;
1484: }
1485: my %defaultdesign = %Apache::loncommon::defaultdesign;
1486: if ($role eq 'login') {
1487: %defaults = (
1488: font => $defaultdesign{$role.'.font'},
1489: );
1490: if (ref($logintext) eq 'ARRAY') {
1491: foreach my $item (@{$logintext}) {
1492: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1493: }
1494: }
1495: foreach my $item (@{$images}) {
1496: $defaults{'showlogo'}{$item} = 1;
1497: }
1498: } else {
1499: %defaults = (
1500: img => $defaultdesign{$role.'.img'},
1501: font => $defaultdesign{$role.'.font'},
1502: fontmenu => $defaultdesign{$role.'.fontmenu'},
1503: );
1504: }
1505: foreach my $item (@{$bgs}) {
1506: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1507: }
1508: foreach my $item (@{$links}) {
1509: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1510: }
1511: foreach my $item (@{$images}) {
1512: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1513: }
1514: return %defaults;
1515: }
1516:
1.6 raeburn 1517: sub display_color_options {
1.9 raeburn 1518: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1519: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1520: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1521: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1522: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1523: '<td>'.$choices->{'font'}.'</td>';
1524: if (!$is_custom->{'font'}) {
1.30 raeburn 1525: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1526: } else {
1527: $datatable .= '<td> </td>';
1528: }
1.174 foxr 1529: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1530:
1.8 raeburn 1531: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1532: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1533: ' value="'.$current_color.'" /> '.
1.174 foxr 1534: ' </td></tr>';
1.107 raeburn 1535: unless ($role eq 'login') {
1536: $datatable .= '<tr'.$css_class.'>'.
1537: '<td>'.$choices->{'fontmenu'}.'</td>';
1538: if (!$is_custom->{'fontmenu'}) {
1539: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1540: } else {
1541: $datatable .= '<td> </td>';
1542: }
1.202 raeburn 1543: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1544: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1545: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1546: '<input class="colorchooser" type="text" size="10" name="'
1547: .$role.'_fontmenu"'.
1548: ' value="'.$current_color.'" /> '.
1549: ' </td></tr>';
1.97 tempelho 1550: }
1.9 raeburn 1551: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1552: foreach my $img (@{$images}) {
1.18 albertel 1553: $itemcount ++;
1.6 raeburn 1554: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1555: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1556: '<td>'.$choices->{$img};
1.41 raeburn 1557: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1558: if ($role eq 'login') {
1559: if ($img eq 'login') {
1560: $login_hdr_pick =
1.135 bisitz 1561: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1562: $logincolors =
1563: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1564: $designs,$defaults);
1.70 raeburn 1565: } elsif ($img ne 'domlogo') {
1566: $datatable.= &logo_display_options($img,$defaults,$designs);
1567: }
1568: }
1569: $datatable .= '</td>';
1.6 raeburn 1570: if ($designs->{$img} ne '') {
1571: $imgfile = $designs->{$img};
1.18 albertel 1572: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1573: } else {
1574: $imgfile = $defaults->{$img};
1575: }
1576: if ($imgfile) {
1.9 raeburn 1577: my ($showfile,$fullsize);
1578: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1579: my $urldir = $1;
1580: my $filename = $2;
1581: my @info = &Apache::lonnet::stat_file($designs->{$img});
1582: if (@info) {
1583: my $thumbfile = 'tn-'.$filename;
1584: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1585: if (@thumb) {
1586: $showfile = $urldir.'/'.$thumbfile;
1587: } else {
1588: $showfile = $imgfile;
1589: }
1590: } else {
1591: $showfile = '';
1592: }
1593: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1594: $showfile = $imgfile;
1.6 raeburn 1595: my $imgdir = $1;
1596: my $filename = $2;
1.159 raeburn 1597: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1598: $showfile = "/$imgdir/tn-".$filename;
1599: } else {
1.159 raeburn 1600: my $input = $londocroot.$imgfile;
1601: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1602: if (!-e $output) {
1.9 raeburn 1603: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1604: my ($fullwidth,$fullheight) = &check_dimensions($input);
1605: if ($fullwidth ne '' && $fullheight ne '') {
1606: if ($fullwidth > $width && $fullheight > $height) {
1607: my $size = $width.'x'.$height;
1608: system("convert -sample $size $input $output");
1.159 raeburn 1609: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1610: }
1611: }
1.6 raeburn 1612: }
1613: }
1.16 raeburn 1614: }
1.6 raeburn 1615: if ($showfile) {
1.40 raeburn 1616: if ($showfile =~ m{^/(adm|res)/}) {
1617: if ($showfile =~ m{^/res/}) {
1618: my $local_showfile =
1619: &Apache::lonnet::filelocation('',$showfile);
1620: &Apache::lonnet::repcopy($local_showfile);
1621: }
1622: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1623: }
1624: if ($imgfile) {
1625: if ($imgfile =~ m{^/(adm|res)/}) {
1626: if ($imgfile =~ m{^/res/}) {
1627: my $local_imgfile =
1628: &Apache::lonnet::filelocation('',$imgfile);
1629: &Apache::lonnet::repcopy($local_imgfile);
1630: }
1631: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1632: } else {
1633: $fullsize = $imgfile;
1634: }
1635: }
1.41 raeburn 1636: $datatable .= '<td>';
1637: if ($img eq 'login') {
1.135 bisitz 1638: $datatable .= $login_hdr_pick;
1639: }
1.41 raeburn 1640: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1641: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1642: } else {
1.201 raeburn 1643: $datatable .= '<td> </td><td class="LC_left_item">'.
1644: &mt('Upload:').'<br />';
1.6 raeburn 1645: }
1646: } else {
1.201 raeburn 1647: $datatable .= '<td> </td><td class="LC_left_item">'.
1648: &mt('Upload:').'<br />';
1.6 raeburn 1649: }
1.9 raeburn 1650: if ($switchserver) {
1651: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1652: } else {
1.135 bisitz 1653: if ($img ne 'login') { # suppress file selection for Log-in header
1654: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1655: }
1.9 raeburn 1656: }
1657: $datatable .= '</td></tr>';
1.6 raeburn 1658: }
1659: $itemcount ++;
1660: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1661: $datatable .= '<tr'.$css_class.'>'.
1662: '<td>'.$choices->{'bgs'}.'</td>';
1663: my $bgs_def;
1664: foreach my $item (@{$bgs}) {
1665: if (!$is_custom->{$item}) {
1.70 raeburn 1666: $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 1667: }
1668: }
1669: if ($bgs_def) {
1.8 raeburn 1670: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1671: } else {
1672: $datatable .= '<td> </td>';
1673: }
1674: $datatable .= '<td class="LC_right_item">'.
1675: '<table border="0"><tr>';
1.174 foxr 1676:
1.6 raeburn 1677: foreach my $item (@{$bgs}) {
1.201 raeburn 1678: $datatable .= '<td align="center">'.$choices->{$item};
1.174 foxr 1679: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1680: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1681: $datatable .= ' ';
1.6 raeburn 1682: }
1.174 foxr 1683: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1684: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1685: }
1686: $datatable .= '</tr></table></td></tr>';
1687: $itemcount ++;
1688: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1689: $datatable .= '<tr'.$css_class.'>'.
1690: '<td>'.$choices->{'links'}.'</td>';
1691: my $links_def;
1692: foreach my $item (@{$links}) {
1693: if (!$is_custom->{$item}) {
1.30 raeburn 1694: $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 1695: }
1696: }
1697: if ($links_def) {
1.8 raeburn 1698: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1699: } else {
1700: $datatable .= '<td> </td>';
1701: }
1702: $datatable .= '<td class="LC_right_item">'.
1703: '<table border="0"><tr>';
1704: foreach my $item (@{$links}) {
1.234 raeburn 1705: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.201 raeburn 1706: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1707: if ($designs->{'links'}{$item}) {
1.174 foxr 1708: $datatable.=' ';
1.6 raeburn 1709: }
1.174 foxr 1710: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1711: '" /></td>';
1712: }
1.30 raeburn 1713: $$rowtotal += $itemcount;
1.3 raeburn 1714: return $datatable;
1715: }
1716:
1.70 raeburn 1717: sub logo_display_options {
1718: my ($img,$defaults,$designs) = @_;
1719: my $checkedon;
1720: if (ref($defaults) eq 'HASH') {
1721: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1722: if ($defaults->{'showlogo'}{$img}) {
1723: $checkedon = 'checked="checked" ';
1724: }
1725: }
1726: }
1727: if (ref($designs) eq 'HASH') {
1728: if (ref($designs->{'showlogo'}) eq 'HASH') {
1729: if (defined($designs->{'showlogo'}{$img})) {
1730: if ($designs->{'showlogo'}{$img} == 0) {
1731: $checkedon = '';
1732: } elsif ($designs->{'showlogo'}{$img} == 1) {
1733: $checkedon = 'checked="checked" ';
1734: }
1735: }
1736: }
1737: }
1738: return '<br /><label> <input type="checkbox" name="'.
1739: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1740: &mt('show').'</label>'."\n";
1741: }
1742:
1.41 raeburn 1743: sub login_header_options {
1.135 bisitz 1744: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1745: my $output = '';
1.41 raeburn 1746: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1747: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1748: if (!$is_custom->{'textcol'}) {
1749: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1750: ' ';
1751: }
1752: if (!$is_custom->{'bgcol'}) {
1753: $output .= $choices->{'bgcol'}.': '.
1754: '<span id="css_'.$role.'_font" style="background-color: '.
1755: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1756: }
1757: $output .= '<br />';
1758: }
1759: $output .='<br />';
1760: return $output;
1761: }
1762:
1763: sub login_text_colors {
1.201 raeburn 1764: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1765: my $color_menu = '<table border="0"><tr>';
1766: foreach my $item (@{$logintext}) {
1.201 raeburn 1767: $color_menu .= '<td align="center">'.$choices->{$item};
1768: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1769: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1770: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1771: }
1772: $color_menu .= '</tr></table><br />';
1773: return $color_menu;
1774: }
1775:
1776: sub image_changes {
1777: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1778: my $output;
1.135 bisitz 1779: if ($img eq 'login') {
1780: # suppress image for Log-in header
1781: } elsif (!$is_custom) {
1.70 raeburn 1782: if ($img ne 'domlogo') {
1.41 raeburn 1783: $output .= &mt('Default image:').'<br />';
1784: } else {
1785: $output .= &mt('Default in use:').'<br />';
1786: }
1787: }
1.135 bisitz 1788: if ($img eq 'login') { # suppress image for Log-in header
1789: $output .= '<td>'.$logincolors;
1.41 raeburn 1790: } else {
1.135 bisitz 1791: if ($img_import) {
1792: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1793: }
1794: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1795: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1796: if ($is_custom) {
1797: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1798: '<input type="checkbox" name="'.
1799: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1800: '</label> '.&mt('Replace:').'</span><br />';
1801: } else {
1.201 raeburn 1802: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1803: }
1.41 raeburn 1804: }
1805: return $output;
1806: }
1807:
1.3 raeburn 1808: sub print_quotas {
1.86 raeburn 1809: my ($dom,$settings,$rowtotal,$action) = @_;
1810: my $context;
1811: if ($action eq 'quotas') {
1812: $context = 'tools';
1813: } else {
1814: $context = $action;
1815: }
1.197 raeburn 1816: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1817: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1818: my $typecount = 0;
1.101 raeburn 1819: my ($css_class,%titles);
1.86 raeburn 1820: if ($context eq 'requestcourses') {
1.271 raeburn 1821: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 1822: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1823: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1824: %titles = &courserequest_titles();
1.163 raeburn 1825: } elsif ($context eq 'requestauthor') {
1826: @usertools = ('author');
1827: @options = ('norequest','approval','automatic');
1.210 raeburn 1828: %titles = &authorrequest_titles();
1.86 raeburn 1829: } else {
1.162 raeburn 1830: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1831: %titles = &tool_titles();
1.86 raeburn 1832: }
1.26 raeburn 1833: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1834: foreach my $type (@{$types}) {
1.197 raeburn 1835: my ($currdefquota,$currauthorquota);
1.163 raeburn 1836: unless (($context eq 'requestcourses') ||
1837: ($context eq 'requestauthor')) {
1.86 raeburn 1838: if (ref($settings) eq 'HASH') {
1839: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1840: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1841: } else {
1842: $currdefquota = $settings->{$type};
1843: }
1.197 raeburn 1844: if (ref($settings->{authorquota}) eq 'HASH') {
1845: $currauthorquota = $settings->{authorquota}->{$type};
1846: }
1.78 raeburn 1847: }
1.72 raeburn 1848: }
1.3 raeburn 1849: if (defined($usertypes->{$type})) {
1850: $typecount ++;
1851: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1852: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1853: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1854: '<td class="LC_left_item">';
1.101 raeburn 1855: if ($context eq 'requestcourses') {
1856: $datatable .= '<table><tr>';
1857: }
1858: my %cell;
1.72 raeburn 1859: foreach my $item (@usertools) {
1.101 raeburn 1860: if ($context eq 'requestcourses') {
1861: my ($curroption,$currlimit);
1862: if (ref($settings) eq 'HASH') {
1863: if (ref($settings->{$item}) eq 'HASH') {
1864: $curroption = $settings->{$item}->{$type};
1865: if ($curroption =~ /^autolimit=(\d*)$/) {
1866: $currlimit = $1;
1867: }
1868: }
1869: }
1870: if (!$curroption) {
1871: $curroption = 'norequest';
1872: }
1873: $datatable .= '<th>'.$titles{$item}.'</th>';
1874: foreach my $option (@options) {
1875: my $val = $option;
1876: if ($option eq 'norequest') {
1877: $val = 0;
1878: }
1879: if ($option eq 'validate') {
1880: my $canvalidate = 0;
1881: if (ref($validations{$item}) eq 'HASH') {
1882: if ($validations{$item}{$type}) {
1883: $canvalidate = 1;
1884: }
1885: }
1886: next if (!$canvalidate);
1887: }
1888: my $checked = '';
1889: if ($option eq $curroption) {
1890: $checked = ' checked="checked"';
1891: } elsif ($option eq 'autolimit') {
1892: if ($curroption =~ /^autolimit/) {
1893: $checked = ' checked="checked"';
1894: }
1895: }
1896: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1897: '<input type="radio" name="crsreq_'.$item.
1898: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1899: $titles{$option}.'</label>';
1.101 raeburn 1900: if ($option eq 'autolimit') {
1.127 raeburn 1901: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1902: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1903: 'value="'.$currlimit.'" />';
1.101 raeburn 1904: }
1.127 raeburn 1905: $cell{$item} .= '</span> ';
1.103 raeburn 1906: if ($option eq 'autolimit') {
1.127 raeburn 1907: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1908: }
1.101 raeburn 1909: }
1.163 raeburn 1910: } elsif ($context eq 'requestauthor') {
1911: my $curroption;
1912: if (ref($settings) eq 'HASH') {
1913: $curroption = $settings->{$type};
1914: }
1915: if (!$curroption) {
1916: $curroption = 'norequest';
1917: }
1918: foreach my $option (@options) {
1919: my $val = $option;
1920: if ($option eq 'norequest') {
1921: $val = 0;
1922: }
1923: my $checked = '';
1924: if ($option eq $curroption) {
1925: $checked = ' checked="checked"';
1926: }
1927: $datatable .= '<span class="LC_nobreak"><label>'.
1928: '<input type="radio" name="authorreq_'.$type.
1929: '" value="'.$val.'"'.$checked.' />'.
1930: $titles{$option}.'</label></span> ';
1931: }
1.101 raeburn 1932: } else {
1933: my $checked = 'checked="checked" ';
1934: if (ref($settings) eq 'HASH') {
1935: if (ref($settings->{$item}) eq 'HASH') {
1936: if ($settings->{$item}->{$type} == 0) {
1937: $checked = '';
1938: } elsif ($settings->{$item}->{$type} == 1) {
1939: $checked = 'checked="checked" ';
1940: }
1.78 raeburn 1941: }
1.72 raeburn 1942: }
1.101 raeburn 1943: $datatable .= '<span class="LC_nobreak"><label>'.
1944: '<input type="checkbox" name="'.$context.'_'.$item.
1945: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1946: '</label></span> ';
1.72 raeburn 1947: }
1.101 raeburn 1948: }
1949: if ($context eq 'requestcourses') {
1950: $datatable .= '</tr><tr>';
1951: foreach my $item (@usertools) {
1.106 raeburn 1952: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1953: }
1954: $datatable .= '</tr></table>';
1.72 raeburn 1955: }
1.86 raeburn 1956: $datatable .= '</td>';
1.163 raeburn 1957: unless (($context eq 'requestcourses') ||
1958: ($context eq 'requestauthor')) {
1.86 raeburn 1959: $datatable .=
1.197 raeburn 1960: '<td class="LC_right_item">'.
1961: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1962: '<input type="text" name="quota_'.$type.
1.72 raeburn 1963: '" value="'.$currdefquota.
1.197 raeburn 1964: '" size="5" /></span>'.(' ' x 2).
1965: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1966: '<input type="text" name="authorquota_'.$type.
1967: '" value="'.$currauthorquota.
1968: '" size="5" /></span></td>';
1.86 raeburn 1969: }
1970: $datatable .= '</tr>';
1.3 raeburn 1971: }
1972: }
1973: }
1.163 raeburn 1974: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1975: $defaultquota = '20';
1.197 raeburn 1976: $authorquota = '500';
1.86 raeburn 1977: if (ref($settings) eq 'HASH') {
1978: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1979: $defaultquota = $settings->{'defaultquota'}->{'default'};
1980: } elsif (defined($settings->{'default'})) {
1981: $defaultquota = $settings->{'default'};
1982: }
1.197 raeburn 1983: if (ref($settings->{'authorquota'}) eq 'HASH') {
1984: $authorquota = $settings->{'authorquota'}->{'default'};
1985: }
1.3 raeburn 1986: }
1987: }
1988: $typecount ++;
1989: $css_class = $typecount%2?' class="LC_odd_row"':'';
1990: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1991: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1992: '<td class="LC_left_item">';
1.101 raeburn 1993: if ($context eq 'requestcourses') {
1994: $datatable .= '<table><tr>';
1995: }
1996: my %defcell;
1.72 raeburn 1997: foreach my $item (@usertools) {
1.101 raeburn 1998: if ($context eq 'requestcourses') {
1999: my ($curroption,$currlimit);
2000: if (ref($settings) eq 'HASH') {
2001: if (ref($settings->{$item}) eq 'HASH') {
2002: $curroption = $settings->{$item}->{'default'};
2003: if ($curroption =~ /^autolimit=(\d*)$/) {
2004: $currlimit = $1;
2005: }
2006: }
2007: }
2008: if (!$curroption) {
2009: $curroption = 'norequest';
2010: }
2011: $datatable .= '<th>'.$titles{$item}.'</th>';
2012: foreach my $option (@options) {
2013: my $val = $option;
2014: if ($option eq 'norequest') {
2015: $val = 0;
2016: }
2017: if ($option eq 'validate') {
2018: my $canvalidate = 0;
2019: if (ref($validations{$item}) eq 'HASH') {
2020: if ($validations{$item}{'default'}) {
2021: $canvalidate = 1;
2022: }
2023: }
2024: next if (!$canvalidate);
2025: }
2026: my $checked = '';
2027: if ($option eq $curroption) {
2028: $checked = ' checked="checked"';
2029: } elsif ($option eq 'autolimit') {
2030: if ($curroption =~ /^autolimit/) {
2031: $checked = ' checked="checked"';
2032: }
2033: }
2034: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2035: '<input type="radio" name="crsreq_'.$item.
2036: '_default" value="'.$val.'"'.$checked.' />'.
2037: $titles{$option}.'</label>';
2038: if ($option eq 'autolimit') {
1.127 raeburn 2039: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2040: $item.'_limit_default" size="1" '.
2041: 'value="'.$currlimit.'" />';
2042: }
1.127 raeburn 2043: $defcell{$item} .= '</span> ';
1.104 raeburn 2044: if ($option eq 'autolimit') {
1.127 raeburn 2045: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2046: }
1.101 raeburn 2047: }
1.163 raeburn 2048: } elsif ($context eq 'requestauthor') {
2049: my $curroption;
2050: if (ref($settings) eq 'HASH') {
1.172 raeburn 2051: $curroption = $settings->{'default'};
1.163 raeburn 2052: }
2053: if (!$curroption) {
2054: $curroption = 'norequest';
2055: }
2056: foreach my $option (@options) {
2057: my $val = $option;
2058: if ($option eq 'norequest') {
2059: $val = 0;
2060: }
2061: my $checked = '';
2062: if ($option eq $curroption) {
2063: $checked = ' checked="checked"';
2064: }
2065: $datatable .= '<span class="LC_nobreak"><label>'.
2066: '<input type="radio" name="authorreq_default"'.
2067: ' value="'.$val.'"'.$checked.' />'.
2068: $titles{$option}.'</label></span> ';
2069: }
1.101 raeburn 2070: } else {
2071: my $checked = 'checked="checked" ';
2072: if (ref($settings) eq 'HASH') {
2073: if (ref($settings->{$item}) eq 'HASH') {
2074: if ($settings->{$item}->{'default'} == 0) {
2075: $checked = '';
2076: } elsif ($settings->{$item}->{'default'} == 1) {
2077: $checked = 'checked="checked" ';
2078: }
1.78 raeburn 2079: }
1.72 raeburn 2080: }
1.101 raeburn 2081: $datatable .= '<span class="LC_nobreak"><label>'.
2082: '<input type="checkbox" name="'.$context.'_'.$item.
2083: '" value="default" '.$checked.'/>'.$titles{$item}.
2084: '</label></span> ';
2085: }
2086: }
2087: if ($context eq 'requestcourses') {
2088: $datatable .= '</tr><tr>';
2089: foreach my $item (@usertools) {
1.106 raeburn 2090: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2091: }
1.101 raeburn 2092: $datatable .= '</tr></table>';
1.72 raeburn 2093: }
1.86 raeburn 2094: $datatable .= '</td>';
1.163 raeburn 2095: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2096: $datatable .= '<td class="LC_right_item">'.
2097: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2098: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2099: $defaultquota.'" size="5" /></span>'.(' ' x2).
2100: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2101: '<input type="text" name="authorquota" value="'.
2102: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2103: }
2104: $datatable .= '</tr>';
1.72 raeburn 2105: $typecount ++;
2106: $css_class = $typecount%2?' class="LC_odd_row"':'';
2107: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2108: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2109: if ($context eq 'requestcourses') {
1.109 raeburn 2110: $datatable .= &mt('(overrides affiliation, if set)').
2111: '</td>'.
2112: '<td class="LC_left_item">'.
2113: '<table><tr>';
1.101 raeburn 2114: } else {
1.109 raeburn 2115: $datatable .= &mt('(overrides affiliation, if checked)').
2116: '</td>'.
2117: '<td class="LC_left_item" colspan="2">'.
2118: '<br />';
1.101 raeburn 2119: }
2120: my %advcell;
1.72 raeburn 2121: foreach my $item (@usertools) {
1.101 raeburn 2122: if ($context eq 'requestcourses') {
2123: my ($curroption,$currlimit);
2124: if (ref($settings) eq 'HASH') {
2125: if (ref($settings->{$item}) eq 'HASH') {
2126: $curroption = $settings->{$item}->{'_LC_adv'};
2127: if ($curroption =~ /^autolimit=(\d*)$/) {
2128: $currlimit = $1;
2129: }
2130: }
2131: }
2132: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2133: my $checked = '';
2134: if ($curroption eq '') {
2135: $checked = ' checked="checked"';
2136: }
2137: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2138: '<input type="radio" name="crsreq_'.$item.
2139: '__LC_adv" value=""'.$checked.' />'.
2140: &mt('No override set').'</label></span> ';
1.101 raeburn 2141: foreach my $option (@options) {
2142: my $val = $option;
2143: if ($option eq 'norequest') {
2144: $val = 0;
2145: }
2146: if ($option eq 'validate') {
2147: my $canvalidate = 0;
2148: if (ref($validations{$item}) eq 'HASH') {
2149: if ($validations{$item}{'_LC_adv'}) {
2150: $canvalidate = 1;
2151: }
2152: }
2153: next if (!$canvalidate);
2154: }
2155: my $checked = '';
1.104 raeburn 2156: if ($val eq $curroption) {
1.101 raeburn 2157: $checked = ' checked="checked"';
2158: } elsif ($option eq 'autolimit') {
2159: if ($curroption =~ /^autolimit/) {
2160: $checked = ' checked="checked"';
2161: }
2162: }
2163: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2164: '<input type="radio" name="crsreq_'.$item.
2165: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2166: $titles{$option}.'</label>';
2167: if ($option eq 'autolimit') {
1.127 raeburn 2168: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2169: $item.'_limit__LC_adv" size="1" '.
2170: 'value="'.$currlimit.'" />';
2171: }
1.127 raeburn 2172: $advcell{$item} .= '</span> ';
1.104 raeburn 2173: if ($option eq 'autolimit') {
1.127 raeburn 2174: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2175: }
1.101 raeburn 2176: }
1.163 raeburn 2177: } elsif ($context eq 'requestauthor') {
2178: my $curroption;
2179: if (ref($settings) eq 'HASH') {
2180: $curroption = $settings->{'_LC_adv'};
2181: }
2182: my $checked = '';
2183: if ($curroption eq '') {
2184: $checked = ' checked="checked"';
2185: }
2186: $datatable .= '<span class="LC_nobreak"><label>'.
2187: '<input type="radio" name="authorreq__LC_adv"'.
2188: ' value=""'.$checked.' />'.
2189: &mt('No override set').'</label></span> ';
2190: foreach my $option (@options) {
2191: my $val = $option;
2192: if ($option eq 'norequest') {
2193: $val = 0;
2194: }
2195: my $checked = '';
2196: if ($val eq $curroption) {
2197: $checked = ' checked="checked"';
2198: }
2199: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2200: '<input type="radio" name="authorreq__LC_adv"'.
2201: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2202: $titles{$option}.'</label></span> ';
2203: }
1.101 raeburn 2204: } else {
2205: my $checked = 'checked="checked" ';
2206: if (ref($settings) eq 'HASH') {
2207: if (ref($settings->{$item}) eq 'HASH') {
2208: if ($settings->{$item}->{'_LC_adv'} == 0) {
2209: $checked = '';
2210: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2211: $checked = 'checked="checked" ';
2212: }
1.79 raeburn 2213: }
1.72 raeburn 2214: }
1.101 raeburn 2215: $datatable .= '<span class="LC_nobreak"><label>'.
2216: '<input type="checkbox" name="'.$context.'_'.$item.
2217: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2218: '</label></span> ';
2219: }
2220: }
2221: if ($context eq 'requestcourses') {
2222: $datatable .= '</tr><tr>';
2223: foreach my $item (@usertools) {
1.106 raeburn 2224: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2225: }
1.101 raeburn 2226: $datatable .= '</tr></table>';
1.72 raeburn 2227: }
1.98 raeburn 2228: $datatable .= '</td></tr>';
1.30 raeburn 2229: $$rowtotal += $typecount;
1.3 raeburn 2230: return $datatable;
2231: }
2232:
1.163 raeburn 2233: sub print_requestmail {
2234: my ($dom,$action,$settings,$rowtotal) = @_;
1.208 raeburn 2235: my ($now,$datatable,%currapp);
1.102 raeburn 2236: $now = time;
2237: if (ref($settings) eq 'HASH') {
2238: if (ref($settings->{'notify'}) eq 'HASH') {
2239: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2240: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2241: }
2242: }
2243: }
1.191 raeburn 2244: my $numinrow = 2;
1.224 raeburn 2245: my $css_class;
2246: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.163 raeburn 2247: my $text;
2248: if ($action eq 'requestcourses') {
2249: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2250: } elsif ($action eq 'requestauthor') {
2251: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2252: } else {
1.224 raeburn 2253: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2254: }
1.224 raeburn 2255: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2256: ' <td>'.$text.'</td>'.
1.102 raeburn 2257: ' <td class="LC_left_item">';
1.191 raeburn 2258: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2259: $action.'notifyapproval',%currapp);
1.191 raeburn 2260: if ($numdc > 0) {
2261: $datatable .= $table;
1.102 raeburn 2262: } else {
2263: $datatable .= &mt('There are no active Domain Coordinators');
2264: }
2265: $datatable .='</td></tr>';
2266: return $datatable;
2267: }
2268:
1.216 raeburn 2269: sub print_studentcode {
2270: my ($settings,$rowtotal) = @_;
2271: my $rownum = 0;
1.218 raeburn 2272: my ($output,%current);
1.271 raeburn 2273: my @crstypes = ('official','unofficial','community','textbook','placement');
1.248 raeburn 2274: if (ref($settings) eq 'HASH') {
2275: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2276: foreach my $type (@crstypes) {
2277: $current{$type} = $settings->{'uniquecode'}{$type};
2278: }
1.218 raeburn 2279: }
2280: }
2281: $output .= '<tr>'.
2282: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2283: '<td class="LC_left_item">';
2284: foreach my $type (@crstypes) {
2285: my $check = ' ';
2286: if ($current{$type}) {
2287: $check = ' checked="checked" ';
2288: }
2289: $output .= '<span class="LC_nobreak"><label>'.
2290: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2291: &mt($type).'</label></span>'.(' 'x2).' ';
2292: }
2293: $output .= '</td></tr>';
2294: $$rowtotal ++;
2295: return $output;
1.216 raeburn 2296: }
2297:
2298: sub print_textbookcourses {
1.242 raeburn 2299: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2300: my $rownum = 0;
2301: my $css_class;
2302: my $itemcount = 1;
2303: my $maxnum = 0;
2304: my $bookshash;
2305: if (ref($settings) eq 'HASH') {
1.242 raeburn 2306: $bookshash = $settings->{$type};
1.216 raeburn 2307: }
2308: my %ordered;
2309: if (ref($bookshash) eq 'HASH') {
2310: foreach my $item (keys(%{$bookshash})) {
2311: if (ref($bookshash->{$item}) eq 'HASH') {
2312: my $num = $bookshash->{$item}{'order'};
2313: $ordered{$num} = $item;
2314: }
2315: }
2316: }
2317: my $confname = $dom.'-domainconfig';
2318: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2319: my $maxnum = scalar(keys(%ordered));
2320: my $datatable;
1.216 raeburn 2321: if (keys(%ordered)) {
2322: my @items = sort { $a <=> $b } keys(%ordered);
2323: for (my $i=0; $i<@items; $i++) {
2324: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2325: my $key = $ordered{$items[$i]};
2326: my %coursehash=&Apache::lonnet::coursedescription($key);
2327: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2328: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2329: if (ref($bookshash->{$key}) eq 'HASH') {
2330: $subject = $bookshash->{$key}->{'subject'};
2331: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2332: if ($type eq 'textbooks') {
1.243 raeburn 2333: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2334: $author = $bookshash->{$key}->{'author'};
2335: $image = $bookshash->{$key}->{'image'};
2336: if ($image ne '') {
2337: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2338: my $imagethumb = "$path/tn-".$imagefile;
2339: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2340: }
1.216 raeburn 2341: }
2342: }
1.242 raeburn 2343: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2344: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2345: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2346: for (my $k=0; $k<=$maxnum; $k++) {
2347: my $vpos = $k+1;
2348: my $selstr;
2349: if ($k == $i) {
2350: $selstr = ' selected="selected" ';
2351: }
2352: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2353: }
2354: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2355: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2356: &mt('Delete?').'</label></span></td>'.
2357: '<td colspan="2">'.
1.242 raeburn 2358: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2359: (' 'x2).
1.242 raeburn 2360: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2361: if ($type eq 'textbooks') {
2362: $datatable .= (' 'x2).
1.243 raeburn 2363: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2364: (' 'x2).
1.242 raeburn 2365: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2366: (' 'x2).
2367: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2368: if ($image) {
1.267 raeburn 2369: $datatable .= $imgsrc.
1.242 raeburn 2370: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2371: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2372: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2373: }
2374: if ($switchserver) {
2375: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2376: } else {
2377: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2378: }
1.216 raeburn 2379: }
1.242 raeburn 2380: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2381: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2382: $coursetitle.'</span></td></tr>'."\n";
2383: $itemcount ++;
2384: }
2385: }
2386: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2387: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2388: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2389: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2390: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2391: for (my $k=0; $k<$maxnum+1; $k++) {
2392: my $vpos = $k+1;
2393: my $selstr;
2394: if ($k == $maxnum) {
2395: $selstr = ' selected="selected" ';
2396: }
2397: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2398: }
2399: $datatable .= '</select> '."\n".
1.242 raeburn 2400: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.216 raeburn 2401: '<td colspan="2">'.
1.242 raeburn 2402: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2403: (' 'x2).
1.242 raeburn 2404: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2405: (' 'x2);
2406: if ($type eq 'textbooks') {
1.243 raeburn 2407: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2408: (' 'x2).
2409: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2410: (' 'x2).
2411: '<span class="LC_nobreak">'.&mt('Image:').' ';
2412: if ($switchserver) {
2413: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2414: } else {
2415: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2416: }
1.216 raeburn 2417: }
2418: $datatable .= '</span>'."\n".
2419: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2420: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2421: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2422: &Apache::loncommon::selectcourse_link
1.242 raeburn 2423: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.216 raeburn 2424: '</span></td>'."\n".
2425: '</tr>'."\n";
2426: $itemcount ++;
2427: return $datatable;
2428: }
2429:
1.217 raeburn 2430: sub textbookcourses_javascript {
1.242 raeburn 2431: my ($settings) = @_;
2432: return unless(ref($settings) eq 'HASH');
2433: my (%ordered,%total,%jstext);
2434: foreach my $type ('textbooks','templates') {
2435: $total{$type} = 0;
2436: if (ref($settings->{$type}) eq 'HASH') {
2437: foreach my $item (keys(%{$settings->{$type}})) {
2438: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2439: my $num = $settings->{$type}->{$item}{'order'};
2440: $ordered{$type}{$num} = $item;
2441: }
2442: }
2443: $total{$type} = scalar(keys(%{$settings->{$type}}));
2444: }
2445: my @jsarray = ();
2446: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2447: push(@jsarray,$ordered{$type}{$item});
2448: }
2449: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2450: }
2451: return <<"ENDSCRIPT";
2452: <script type="text/javascript">
2453: // <![CDATA[
1.242 raeburn 2454: function reorderBooks(form,item,caller) {
1.217 raeburn 2455: var changedVal;
1.242 raeburn 2456: $jstext{'textbooks'};
2457: $jstext{'templates'};
2458: var newpos;
2459: var maxh;
2460: if (caller == 'textbooks') {
2461: newpos = 'textbooks_addbook_pos';
2462: maxh = 1 + $total{'textbooks'};
2463: } else {
2464: newpos = 'templates_addbook_pos';
2465: maxh = 1 + $total{'templates'};
2466: }
1.217 raeburn 2467: var current = new Array;
2468: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2469: if (item == newpos) {
2470: changedVal = newitemVal;
2471: } else {
2472: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2473: current[newitemVal] = newpos;
2474: }
1.242 raeburn 2475: if (caller == 'textbooks') {
2476: for (var i=0; i<textbooks.length; i++) {
2477: var elementName = 'textbooks_'+textbooks[i];
2478: if (elementName != item) {
2479: if (form.elements[elementName]) {
2480: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2481: current[currVal] = elementName;
2482: }
2483: }
2484: }
2485: }
2486: if (caller == 'templates') {
2487: for (var i=0; i<templates.length; i++) {
2488: var elementName = 'templates_'+templates[i];
2489: if (elementName != item) {
2490: if (form.elements[elementName]) {
2491: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2492: current[currVal] = elementName;
2493: }
1.217 raeburn 2494: }
2495: }
2496: }
2497: var oldVal;
2498: for (var j=0; j<maxh; j++) {
2499: if (current[j] == undefined) {
2500: oldVal = j;
2501: }
2502: }
2503: if (oldVal < changedVal) {
2504: for (var k=oldVal+1; k<=changedVal ; k++) {
2505: var elementName = current[k];
2506: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2507: }
2508: } else {
2509: for (var k=changedVal; k<oldVal; k++) {
2510: var elementName = current[k];
2511: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2512: }
2513: }
2514: return;
2515: }
2516:
2517: // ]]>
2518: </script>
2519:
2520: ENDSCRIPT
2521: }
2522:
1.267 raeburn 2523: sub ltitools_javascript {
2524: my ($settings) = @_;
2525: return unless(ref($settings) eq 'HASH');
2526: my (%ordered,$total,%jstext);
2527: $total = 0;
2528: foreach my $item (keys(%{$settings})) {
2529: if (ref($settings->{$item}) eq 'HASH') {
2530: my $num = $settings->{$item}{'order'};
2531: $ordered{$num} = $item;
2532: }
2533: }
2534: $total = scalar(keys(%{$settings}));
2535: my @jsarray = ();
2536: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2537: push(@jsarray,$ordered{$item});
2538: }
2539: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2540: return <<"ENDSCRIPT";
2541: <script type="text/javascript">
2542: // <![CDATA[
2543: function reorderLTI(form,item) {
2544: var changedVal;
2545: $jstext
2546: var newpos = 'ltitools_add_pos';
2547: var maxh = 1 + $total;
2548: var current = new Array;
2549: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2550: if (item == newpos) {
2551: changedVal = newitemVal;
2552: } else {
2553: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2554: current[newitemVal] = newpos;
2555: }
2556: for (var i=0; i<ltitools.length; i++) {
2557: var elementName = 'ltitools_'+ltitools[i];
2558: if (elementName != item) {
2559: if (form.elements[elementName]) {
2560: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2561: current[currVal] = elementName;
2562: }
2563: }
2564: }
2565: var oldVal;
2566: for (var j=0; j<maxh; j++) {
2567: if (current[j] == undefined) {
2568: oldVal = j;
2569: }
2570: }
2571: if (oldVal < changedVal) {
2572: for (var k=oldVal+1; k<=changedVal ; k++) {
2573: var elementName = current[k];
2574: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2575: }
2576: } else {
2577: for (var k=changedVal; k<oldVal; k++) {
2578: var elementName = current[k];
2579: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2580: }
2581: }
2582: return;
2583: }
2584:
2585: // ]]>
2586: </script>
2587:
2588: ENDSCRIPT
2589: }
2590:
1.3 raeburn 2591: sub print_autoenroll {
1.30 raeburn 2592: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2593: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 2594: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2595: if (ref($settings) eq 'HASH') {
2596: if (exists($settings->{'run'})) {
2597: if ($settings->{'run'} eq '0') {
2598: $runoff = ' checked="checked" ';
2599: $runon = ' ';
2600: } else {
2601: $runon = ' checked="checked" ';
2602: $runoff = ' ';
2603: }
2604: } else {
2605: if ($autorun) {
2606: $runon = ' checked="checked" ';
2607: $runoff = ' ';
2608: } else {
2609: $runoff = ' checked="checked" ';
2610: $runon = ' ';
2611: }
2612: }
1.129 raeburn 2613: if (exists($settings->{'co-owners'})) {
2614: if ($settings->{'co-owners'} eq '0') {
2615: $coownersoff = ' checked="checked" ';
2616: $coownerson = ' ';
2617: } else {
2618: $coownerson = ' checked="checked" ';
2619: $coownersoff = ' ';
2620: }
2621: } else {
2622: $coownersoff = ' checked="checked" ';
2623: $coownerson = ' ';
2624: }
1.3 raeburn 2625: if (exists($settings->{'sender_domain'})) {
2626: $defdom = $settings->{'sender_domain'};
2627: }
1.274 raeburn 2628: if (exists($settings->{'autofailsafe'})) {
2629: $failsafe = $settings->{'autofailsafe'};
2630: }
1.14 raeburn 2631: } else {
2632: if ($autorun) {
2633: $runon = ' checked="checked" ';
2634: $runoff = ' ';
2635: } else {
2636: $runoff = ' checked="checked" ';
2637: $runon = ' ';
2638: }
1.3 raeburn 2639: }
2640: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2641: my $notif_sender;
2642: if (ref($settings) eq 'HASH') {
2643: $notif_sender = $settings->{'sender_uname'};
2644: }
1.3 raeburn 2645: my $datatable='<tr class="LC_odd_row">'.
2646: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2647: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2648: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2649: $runon.' value="1" />'.&mt('Yes').'</label> '.
2650: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2651: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2652: '</tr><tr>'.
2653: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2654: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2655: &mt('username').': '.
2656: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2657: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2658: ': '.$domform.'</span></td></tr>'.
2659: '<tr class="LC_odd_row">'.
2660: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2661: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2662: '<input type="radio" name="autoassign_coowners"'.
2663: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2664: '<label><input type="radio" name="autoassign_coowners"'.
2665: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 2666: '</tr><tr>'.
2667: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2668: '<td class="LC_right_item"><span class="LC_nobreak">'.
2669: '<input type="text" name="autoenroll_failsafe"'.
2670: ' value="'.$failsafe.'" size="4" /></td></tr>';
2671: $$rowtotal += 4;
1.3 raeburn 2672: return $datatable;
2673: }
2674:
2675: sub print_autoupdate {
1.30 raeburn 2676: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2677: my $datatable;
2678: if ($position eq 'top') {
2679: my $updateon = ' ';
2680: my $updateoff = ' checked="checked" ';
2681: my $classlistson = ' ';
2682: my $classlistsoff = ' checked="checked" ';
2683: if (ref($settings) eq 'HASH') {
2684: if ($settings->{'run'} eq '1') {
2685: $updateon = $updateoff;
2686: $updateoff = ' ';
2687: }
2688: if ($settings->{'classlists'} eq '1') {
2689: $classlistson = $classlistsoff;
2690: $classlistsoff = ' ';
2691: }
2692: }
2693: my %title = (
2694: run => 'Auto-update active?',
2695: classlists => 'Update information in classlists?',
2696: );
2697: $datatable = '<tr class="LC_odd_row">'.
2698: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2699: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2700: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2701: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2702: '<label><input type="radio" name="autoupdate_run"'.
2703: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2704: '</tr><tr>'.
2705: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2706: '<td class="LC_right_item"><span class="LC_nobreak">'.
2707: '<label><input type="radio" name="classlists"'.
2708: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2709: '<label><input type="radio" name="classlists"'.
2710: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2711: '</tr>';
1.30 raeburn 2712: $$rowtotal += 2;
1.131 raeburn 2713: } elsif ($position eq 'middle') {
2714: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2715: my $numinrow = 3;
2716: my $locknamesettings;
2717: $datatable .= &insttypes_row($settings,$types,$usertypes,
2718: $dom,$numinrow,$othertitle,
2719: 'lockablenames');
2720: $$rowtotal ++;
1.3 raeburn 2721: } else {
1.44 raeburn 2722: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2723: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2724: 'permanentemail','id');
1.33 raeburn 2725: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2726: my $numrows = 0;
1.26 raeburn 2727: if (ref($types) eq 'ARRAY') {
2728: if (@{$types} > 0) {
2729: $datatable =
2730: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2731: \@fields,$types,\$numrows);
1.30 raeburn 2732: $$rowtotal += @{$types};
1.26 raeburn 2733: }
1.3 raeburn 2734: }
2735: $datatable .=
2736: &usertype_update_row($settings,{'default' => $othertitle},
2737: \%fieldtitles,\@fields,['default'],
2738: \$numrows);
1.30 raeburn 2739: $$rowtotal ++;
1.3 raeburn 2740: }
2741: return $datatable;
2742: }
2743:
1.125 raeburn 2744: sub print_autocreate {
2745: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 2746: my (%createon,%createoff,%currhash);
1.125 raeburn 2747: my @types = ('xml','req');
2748: if (ref($settings) eq 'HASH') {
2749: foreach my $item (@types) {
2750: $createoff{$item} = ' checked="checked" ';
2751: $createon{$item} = ' ';
2752: if (exists($settings->{$item})) {
2753: if ($settings->{$item}) {
2754: $createon{$item} = ' checked="checked" ';
2755: $createoff{$item} = ' ';
2756: }
2757: }
2758: }
1.210 raeburn 2759: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 2760: $currhash{$settings->{'xmldc'}} = 1;
2761: }
1.125 raeburn 2762: } else {
2763: foreach my $item (@types) {
2764: $createoff{$item} = ' checked="checked" ';
2765: $createon{$item} = ' ';
2766: }
2767: }
2768: $$rowtotal += 2;
1.191 raeburn 2769: my $numinrow = 2;
1.125 raeburn 2770: my $datatable='<tr class="LC_odd_row">'.
2771: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2772: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2773: '<input type="radio" name="autocreate_xml"'.
2774: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2775: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2776: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2777: '</td></tr><tr>'.
2778: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2779: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2780: '<input type="radio" name="autocreate_req"'.
2781: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2782: '<label><input type="radio" name="autocreate_req"'.
2783: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 2784: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2785: 'autocreate_xmldc',%currhash);
1.247 raeburn 2786: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2787: if ($numdc > 1) {
1.247 raeburn 2788: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2789: '</td><td class="LC_left_item">';
1.125 raeburn 2790: } else {
1.247 raeburn 2791: $datatable .= &mt('Course creation processed as:').
2792: '</td><td class="LC_right_item">';
1.125 raeburn 2793: }
1.247 raeburn 2794: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 2795: $$rowtotal += $rows;
1.125 raeburn 2796: return $datatable;
2797: }
2798:
1.23 raeburn 2799: sub print_directorysrch {
1.277 raeburn 2800: my ($position,$dom,$settings,$rowtotal) = @_;
2801: my $datatable;
2802: if ($position eq 'top') {
2803: my $instsrchon = ' ';
2804: my $instsrchoff = ' checked="checked" ';
2805: my ($exacton,$containson,$beginson);
2806: my $instlocalon = ' ';
2807: my $instlocaloff = ' checked="checked" ';
2808: if (ref($settings) eq 'HASH') {
2809: if ($settings->{'available'} eq '1') {
2810: $instsrchon = $instsrchoff;
2811: $instsrchoff = ' ';
2812: }
2813: if ($settings->{'localonly'} eq '1') {
2814: $instlocalon = $instlocaloff;
2815: $instlocaloff = ' ';
2816: }
2817: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2818: foreach my $type (@{$settings->{'searchtypes'}}) {
2819: if ($type eq 'exact') {
2820: $exacton = ' checked="checked" ';
2821: } elsif ($type eq 'contains') {
2822: $containson = ' checked="checked" ';
2823: } elsif ($type eq 'begins') {
2824: $beginson = ' checked="checked" ';
2825: }
2826: }
2827: } else {
2828: if ($settings->{'searchtypes'} eq 'exact') {
2829: $exacton = ' checked="checked" ';
2830: } elsif ($settings->{'searchtypes'} eq 'contains') {
2831: $containson = ' checked="checked" ';
2832: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 2833: $exacton = ' checked="checked" ';
2834: $containson = ' checked="checked" ';
2835: }
2836: }
1.277 raeburn 2837: }
2838: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2839: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2840:
2841: my $numinrow = 4;
2842: my $cansrchrow = 0;
2843: $datatable='<tr class="LC_odd_row">'.
2844: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
2845: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2846: '<input type="radio" name="dirsrch_available"'.
2847: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
2848: '<label><input type="radio" name="dirsrch_available"'.
2849: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2850: '</tr><tr>'.
2851: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
2852: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2853: '<input type="radio" name="dirsrch_instlocalonly"'.
2854: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2855: '<label><input type="radio" name="dirsrch_instlocalonly"'.
2856: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2857: '</tr>';
2858: $$rowtotal += 2;
2859: if (ref($usertypes) eq 'HASH') {
2860: if (keys(%{$usertypes}) > 0) {
2861: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2862: $numinrow,$othertitle,'cansearch');
2863: $cansrchrow = 1;
1.25 raeburn 2864: }
1.23 raeburn 2865: }
1.277 raeburn 2866: if ($cansrchrow) {
2867: $$rowtotal ++;
2868: $datatable .= '<tr>';
2869: } else {
2870: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 2871: }
1.277 raeburn 2872: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2873: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2874: foreach my $title (@{$titleorder}) {
2875: if (defined($searchtitles->{$title})) {
2876: my $check = ' ';
2877: if (ref($settings) eq 'HASH') {
2878: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2879: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2880: $check = ' checked="checked" ';
2881: }
1.39 raeburn 2882: }
1.25 raeburn 2883: }
1.277 raeburn 2884: $datatable .= '<td class="LC_left_item">'.
2885: '<span class="LC_nobreak"><label>'.
2886: '<input type="checkbox" name="searchby" '.
2887: 'value="'.$title.'"'.$check.'/>'.
2888: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 2889: }
2890: }
1.277 raeburn 2891: $datatable .= '</tr></table></td></tr>';
2892: $$rowtotal ++;
2893: if ($cansrchrow) {
2894: $datatable .= '<tr class="LC_odd_row">';
2895: } else {
2896: $datatable .= '<tr>';
2897: }
2898: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2899: '<td class="LC_left_item" colspan="2">'.
2900: '<span class="LC_nobreak"><label>'.
2901: '<input type="checkbox" name="searchtypes" '.
2902: $exacton.' value="exact" />'.&mt('Exact match').
2903: '</label> '.
2904: '<label><input type="checkbox" name="searchtypes" '.
2905: $beginson.' value="begins" />'.&mt('Begins with').
2906: '</label> '.
2907: '<label><input type="checkbox" name="searchtypes" '.
2908: $containson.' value="contains" />'.&mt('Contains').
2909: '</label></span></td></tr>';
2910: $$rowtotal ++;
1.26 raeburn 2911: } else {
1.277 raeburn 2912: my $domsrchon = ' checked="checked" ';
2913: my $domsrchoff = ' ';
2914: my $domlocalon = ' ';
2915: my $domlocaloff = ' checked="checked" ';
2916: if (ref($settings) eq 'HASH') {
2917: if ($settings->{'lclocalonly'} eq '1') {
2918: $domlocalon = $domlocaloff;
2919: $domlocaloff = ' ';
2920: }
2921: if ($settings->{'lcavailable'} eq '0') {
2922: $domsrchoff = $domsrchon;
2923: $domsrchon = ' ';
2924: }
2925: }
2926: $datatable='<tr class="LC_odd_row">'.
2927: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
2928: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2929: '<input type="radio" name="dirsrch_domavailable"'.
2930: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
2931: '<label><input type="radio" name="dirsrch_domavailable"'.
2932: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2933: '</tr><tr>'.
2934: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
2935: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2936: '<input type="radio" name="dirsrch_domlocalonly"'.
2937: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2938: '<label><input type="radio" name="dirsrch_domlocalonly"'.
2939: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2940: '</tr>';
2941: $$rowtotal += 2;
1.26 raeburn 2942: }
1.25 raeburn 2943: return $datatable;
2944: }
2945:
1.28 raeburn 2946: sub print_contacts {
1.30 raeburn 2947: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2948: my $datatable;
2949: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2950: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2951: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.203 raeburn 2952: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2953: foreach my $type (@mailings) {
2954: $otheremails{$type} = '';
2955: }
1.134 raeburn 2956: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2957: if (ref($settings) eq 'HASH') {
2958: foreach my $item (@contacts) {
2959: if (exists($settings->{$item})) {
2960: $to{$item} = $settings->{$item};
2961: }
2962: }
2963: foreach my $type (@mailings) {
2964: if (exists($settings->{$type})) {
2965: if (ref($settings->{$type}) eq 'HASH') {
2966: foreach my $item (@contacts) {
2967: if ($settings->{$type}{$item}) {
2968: $checked{$type}{$item} = ' checked="checked" ';
2969: }
2970: }
2971: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2972: if ($type eq 'helpdeskmail') {
2973: $bccemails{$type} = $settings->{$type}{'bcc'};
2974: }
1.28 raeburn 2975: }
1.89 raeburn 2976: } elsif ($type eq 'lonstatusmail') {
2977: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2978: }
2979: }
2980: } else {
2981: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2982: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2983: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2984: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2985: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2986: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2987: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.190 raeburn 2988: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.203 raeburn 2989: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2990: }
2991: my ($titles,$short_titles) = &contact_titles();
2992: my $rownum = 0;
2993: my $css_class;
2994: foreach my $item (@contacts) {
1.69 raeburn 2995: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2996: $datatable .= '<tr'.$css_class.'>'.
2997: '<td><span class="LC_nobreak">'.$titles->{$item}.
2998: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2999: '<input type="text" name="'.$item.'" value="'.
3000: $to{$item}.'" /></td></tr>';
1.203 raeburn 3001: $rownum ++;
1.28 raeburn 3002: }
3003: foreach my $type (@mailings) {
1.69 raeburn 3004: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 3005: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 3006: '<td><span class="LC_nobreak">'.
3007: $titles->{$type}.': </span></td>'.
1.28 raeburn 3008: '<td class="LC_left_item">'.
3009: '<span class="LC_nobreak">';
3010: foreach my $item (@contacts) {
3011: $datatable .= '<label>'.
3012: '<input type="checkbox" name="'.$type.'"'.
3013: $checked{$type}{$item}.
3014: ' value="'.$item.'" />'.$short_titles->{$item}.
3015: '</label> ';
3016: }
3017: $datatable .= '</span><br />'.&mt('Others').': '.
3018: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 3019: 'value="'.$otheremails{$type}.'" />';
3020: if ($type eq 'helpdeskmail') {
1.136 raeburn 3021: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 3022: '<input type="text" name="'.$type.'_bcc" '.
3023: 'value="'.$bccemails{$type}.'" />';
3024: }
3025: $datatable .= '</td></tr>'."\n";
1.203 raeburn 3026: $rownum ++;
1.28 raeburn 3027: }
1.203 raeburn 3028: my %choices;
3029: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
3030: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3031: &mt('LON-CAPA core group - MSU'),600,500));
3032: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
3033: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3034: &mt('LON-CAPA core group - MSU'),600,500));
3035: my @toggles = ('reporterrors','reportupdates');
3036: my %defaultchecked = ('reporterrors' => 'on',
3037: 'reportupdates' => 'on');
3038: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3039: \%choices,$rownum);
3040: $datatable .= $reports;
1.30 raeburn 3041: $$rowtotal += $rownum;
1.28 raeburn 3042: return $datatable;
3043: }
3044:
1.118 jms 3045: sub print_helpsettings {
1.282 raeburn 3046: my ($position,$dom,$settings,$rowtotal) = @_;
3047: my $confname = $dom.'-domainconfig';
1.168 raeburn 3048: my ($datatable,$itemcount);
1.282 raeburn 3049: if ($position eq 'top') {
3050: $itemcount = 1;
3051: my (%choices,%defaultchecked,@toggles);
3052: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3053: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3054: &mt('LON-CAPA bug tracker'),600,500));
3055: %defaultchecked = ('submitbugs' => 'on');
3056: @toggles = ('submitbugs');
3057: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3058: \%choices,$itemcount);
3059: $$rowtotal ++;
3060: } else {
3061: my $css_class;
3062: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
3063: my %customroles;
3064: foreach my $key (keys(%existing)) {
3065: if ($key=~/^rolesdef\_(\w+)$/) {
3066: my $rolename = $1;
3067: my %privs;
3068: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3069: $customroles{$rolename} = \%privs;
3070: }
3071: }
3072: my $count = 0;
3073: my $context = 'domprefs';
3074: my $crstype = 'Course';
3075: foreach my $role (sort(keys(%customroles))) {
3076: my $prefix = 'custhelp'.$count;
3077: my %full=();
3078: my %levels= (
3079: course => {},
3080: domain => {},
3081: system => {},
3082: );
3083: my %levelscurrent=(
3084: course => {},
3085: domain => {},
3086: system => {},
3087: );
3088: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3089: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3090: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3091: $datatable .= '<tr '.$css_class.'><td><label>'.
3092: '<input type="checkbox" name="modifycusthelp" value="'.$count.'" />'.
3093: '<input type="hidden" name="custhelprole'.$count.'" value="'.$role.'" />'.
3094: &mt('Modify').'</label></td>'.
3095: '<td>'.&mt('Existing helpdesk role:').' '.
3096: '<b>'.$role.'</b><br />'.
3097: &Apache::lonuserutils::custom_role_header($context,$crstype,
3098: \@templateroles,$prefix).
3099: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
3100: \%levelscurrent,$prefix).
3101: '<br /></td>';
3102: $count ++;
3103: $itemcount ++;
3104: }
3105: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3106: my $newcust = 'custhelp'.$count;
3107: my (%privs,%levelscurrent);
3108: my %full=();
3109: my %levels= (
3110: course => {},
3111: domain => {},
3112: system => {},
3113: );
3114: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3115: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3116: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><label>'.
3117: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3118: '</label></span></td>'.
3119: '<td><span class="LC_nobreak">'.
3120: '<b>'.&mt('Name of new helpdesk role:').'</b> '.
3121: '<input type="text" size="20" name="newcusthelpname" value="" />'.
3122: '</span><br />'.
3123: &Apache::lonuserutils::custom_role_header($context,$crstype,
3124: \@templateroles,$newcust).
3125: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3126: \%levelscurrent,$newcust).
3127: '<br /><br />'.
3128: '</td></tr>';
3129: $count ++;
3130: $$rowtotal += $count;
3131: }
1.166 raeburn 3132: return $datatable;
1.121 raeburn 3133: }
3134:
3135: sub radiobutton_prefs {
1.192 raeburn 3136: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 3137: $additional,$align) = @_;
1.121 raeburn 3138: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3139: (ref($choices) eq 'HASH'));
3140:
1.170 raeburn 3141: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 3142:
3143: foreach my $item (@{$toggles}) {
3144: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3145: $checkedon{$item} = ' checked="checked" ';
3146: $checkedoff{$item} = ' ';
1.121 raeburn 3147: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3148: $checkedoff{$item} = ' checked="checked" ';
3149: $checkedon{$item} = ' ';
3150: }
3151: }
3152: if (ref($settings) eq 'HASH') {
1.121 raeburn 3153: foreach my $item (@{$toggles}) {
1.118 jms 3154: if ($settings->{$item} eq '1') {
3155: $checkedon{$item} = ' checked="checked" ';
3156: $checkedoff{$item} = ' ';
3157: } elsif ($settings->{$item} eq '0') {
3158: $checkedoff{$item} = ' checked="checked" ';
3159: $checkedon{$item} = ' ';
3160: }
3161: }
1.121 raeburn 3162: }
1.192 raeburn 3163: if ($onclick) {
3164: $onclick = ' onclick="'.$onclick.'"';
3165: }
1.121 raeburn 3166: foreach my $item (@{$toggles}) {
1.118 jms 3167: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3168: $datatable .=
1.192 raeburn 3169: '<tr'.$css_class.'><td valign="top">'.
3170: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 3171: '</span></td>';
3172: if ($align eq 'left') {
3173: $datatable .= '<td class="LC_left_item">';
3174: } else {
3175: $datatable .= '<td class="LC_right_item">';
3176: }
3177: $datatable .=
3178: '<span class="LC_nobreak">'.
1.118 jms 3179: '<label><input type="radio" name="'.
1.192 raeburn 3180: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3181: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 3182: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3183: '</span>'.$additional.
3184: '</td>'.
1.118 jms 3185: '</tr>';
3186: $itemcount ++;
1.121 raeburn 3187: }
3188: return ($datatable,$itemcount);
3189: }
3190:
1.267 raeburn 3191: sub print_ltitools {
3192: my ($dom,$settings,$rowtotal) = @_;
3193: my $rownum = 0;
3194: my $css_class;
3195: my $itemcount = 1;
3196: my $maxnum = 0;
3197: my %ordered;
3198: if (ref($settings) eq 'HASH') {
3199: foreach my $item (keys(%{$settings})) {
3200: if (ref($settings->{$item}) eq 'HASH') {
3201: my $num = $settings->{$item}{'order'};
3202: $ordered{$num} = $item;
3203: }
3204: }
3205: }
3206: my $confname = $dom.'-domainconfig';
3207: my $switchserver = &check_switchserver($dom,$confname);
3208: my $maxnum = scalar(keys(%ordered));
3209: my $datatable = <itools_javascript($settings);
3210: my %lt = <itools_names();
3211: my @courseroles = ('cc','in','ta','ep','st');
3212: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
3213: my @fields = ('fullname','firstname','lastname','email','user','roles');
3214: if (keys(%ordered)) {
3215: my @items = sort { $a <=> $b } keys(%ordered);
3216: for (my $i=0; $i<@items; $i++) {
3217: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3218: my $item = $ordered{$items[$i]};
3219: my ($title,$key,$secret,$url,$imgsrc,$version);
3220: if (ref($settings->{$item}) eq 'HASH') {
3221: $title = $settings->{$item}->{'title'};
3222: $url = $settings->{$item}->{'url'};
3223: $key = $settings->{$item}->{'key'};
3224: $secret = $settings->{$item}->{'secret'};
3225: my $image = $settings->{$item}->{'image'};
3226: if ($image ne '') {
3227: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
3228: }
3229: }
3230: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_".$item."'".');"';
3231: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3232: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
3233: for (my $k=0; $k<=$maxnum; $k++) {
3234: my $vpos = $k+1;
3235: my $selstr;
3236: if ($k == $i) {
3237: $selstr = ' selected="selected" ';
3238: }
3239: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3240: }
3241: $datatable .= '</select>'.(' 'x2).
3242: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
3243: &mt('Delete?').'</label></span></td>'.
3244: '<td colspan="2">'.
3245: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3246: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
3247: (' 'x2).
3248: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
3249: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
3250: (' 'x2).
3251: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
3252: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3253: '<br /><br />'.
3254: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_url_'.$i.'"'.
3255: ' value="'.$url.'" /></span>'.
3256: (' 'x2).
3257: '<span class="LC_nobreak">'.$lt{'key'}.
3258: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
3259: (' 'x2).
3260: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
3261: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
3262: '<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>'.
3263: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
3264: '</fieldset>'.
3265: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3266: '<span class="LC_nobreak">'.&mt('Display target:');
3267: my %currdisp;
3268: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
3269: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
3270: $currdisp{'window'} = ' checked="checked"';
3271: } else {
3272: $currdisp{'iframe'} = ' checked="checked"';
3273: }
3274: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
3275: $currdisp{'width'} = $1;
3276: }
3277: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
3278: $currdisp{'height'} = $1;
3279: }
3280: } else {
3281: $currdisp{'iframe'} = ' checked="checked"';
3282: }
3283: foreach my $disp ('iframe','window') {
3284: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
3285: $lt{$disp}.'</label>'.(' 'x2);
3286: }
3287: $datatable .= (' 'x4);
3288: foreach my $dimen ('width','height') {
3289: $datatable .= '<label>'.$lt{$dimen}.' '.
3290: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
3291: (' 'x2);
3292: }
3293: $datatable .= '<br />';
3294: foreach my $extra ('passback','roster') {
3295: my $checkedon = '';
3296: my $checkedoff = ' checked="checked"';
3297: if ($settings->{$item}->{$extra}) {
3298: $checkedon = $checkedoff;
3299: $checkedoff = '';
3300: }
3301: $datatable .= $lt{$extra}.' '.
3302: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.' />'.
3303: &mt('Yes').'</label>'.(' 'x2).
3304: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.' />'.
3305: &mt('No').'</label>'.(' 'x4);
3306: }
3307: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': ';
3308: if ($imgsrc) {
3309: $datatable .= $imgsrc.
3310: '<label><input type="checkbox" name="ltitools_image_del"'.
3311: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
3312: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
3313: } else {
3314: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3315: }
3316: if ($switchserver) {
3317: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3318: } else {
3319: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
3320: }
3321: $datatable .= '</span></fieldset>';
3322: my (%checkedfields,%rolemaps);
3323: if (ref($settings->{$item}) eq 'HASH') {
3324: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
3325: %checkedfields = %{$settings->{$item}->{'fields'}};
3326: }
3327: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
3328: %rolemaps = %{$settings->{$item}->{'roles'}};
3329: $checkedfields{'roles'} = 1;
3330: }
3331: }
3332: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3333: '<span class="LC_nobreak">';
3334: foreach my $field (@fields) {
3335: my $checked;
3336: if ($checkedfields{$field}) {
3337: $checked = ' checked="checked"';
3338: }
3339: $datatable .= '<label>'.
3340: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
3341: $lt{$field}.'</label>'.(' ' x2);
3342: }
3343: $datatable .= '</span></fieldset>'.
3344: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3345: foreach my $role (@courseroles) {
3346: my ($selected,$selectnone);
3347: if (!$rolemaps{$role}) {
3348: $selectnone = ' selected="selected"';
3349: }
3350: $datatable .= '<td align="center">'.
3351: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3352: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
3353: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
3354: foreach my $ltirole (@ltiroles) {
3355: unless ($selectnone) {
3356: if ($rolemaps{$role} eq $ltirole) {
3357: $selected = ' selected="selected"';
3358: } else {
3359: $selected = '';
3360: }
3361: }
3362: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
3363: }
3364: $datatable .= '</select></td>';
3365: }
1.273 raeburn 3366: $datatable .= '</tr></table></fieldset>';
3367: my %courseconfig;
3368: if (ref($settings->{$item}) eq 'HASH') {
3369: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
3370: %courseconfig = %{$settings->{$item}->{'crsconf'}};
3371: }
3372: }
3373: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
3374: foreach my $item ('label','title','target') {
3375: my $checked;
3376: if ($courseconfig{$item}) {
3377: $checked = ' checked="checked"';
3378: }
3379: $datatable .= '<label>'.
3380: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
3381: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3382: }
3383: $datatable .= '</span></fieldset>'.
1.267 raeburn 3384: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3385: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
3386: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
3387: my %custom = %{$settings->{$item}->{'custom'}};
3388: if (keys(%custom) > 0) {
3389: foreach my $key (sort(keys(%custom))) {
3390: $datatable .= '<tr><td><span class="LC_nobreak">'.
3391: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
3392: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
3393: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
3394: ' value="'.$custom{$key}.'" /></td></tr>';
3395: }
3396: }
3397: }
3398: $datatable .= '<tr><td><span class="LC_nobreak">'.
3399: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
3400: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
3401: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
3402: $datatable .= '</table></fieldset></td></tr>'."\n";
3403: $itemcount ++;
3404: }
3405: }
3406: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3407: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_add_pos'".');"';
3408: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
3409: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
3410: '<select name="ltitools_add_pos"'.$chgstr.'>';
3411: for (my $k=0; $k<$maxnum+1; $k++) {
3412: my $vpos = $k+1;
3413: my $selstr;
3414: if ($k == $maxnum) {
3415: $selstr = ' selected="selected" ';
3416: }
3417: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3418: }
3419: $datatable .= '</select> '."\n".
3420: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
3421: '<td colspan="2">'.
3422: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3423: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
3424: (' 'x2).
3425: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
3426: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
3427: (' 'x2).
3428: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
3429: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3430: '<br />'.
3431: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
3432: (' 'x2).
3433: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
3434: (' 'x2).
3435: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
3436: '<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".
3437: '</fieldset>'.
3438: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3439: '<span class="LC_nobreak">'.&mt('Display target:');
3440: my %defaultdisp;
3441: $defaultdisp{'iframe'} = ' checked="checked"';
3442: foreach my $disp ('iframe','window') {
3443: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
3444: $lt{$disp}.'</label>'.(' 'x2);
3445: }
3446: $datatable .= (' 'x4);
3447: foreach my $dimen ('width','height') {
3448: $datatable .= '<label>'.$lt{$dimen}.' '.
3449: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
3450: (' 'x2);
3451: }
3452: $datatable .= '<br />';
3453: foreach my $extra ('passback','roster') {
3454: $datatable .= $lt{$extra}.' '.
3455: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="1" />'.
3456: &mt('Yes').'</label>'.(' 'x2).
3457: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="0" checked="checked" />'.
3458: &mt('No').'</label>'.(' 'x4);
3459: }
3460: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': '.
3461: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3462: if ($switchserver) {
3463: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3464: } else {
3465: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
3466: }
3467: $datatable .= '</span></fieldset>'.
3468: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3469: '<span class="LC_nobreak">';
3470: foreach my $field (@fields) {
3471: $datatable .= '<label>'.
3472: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
3473: $lt{$field}.'</label>'.(' ' x2);
3474: }
3475: $datatable .= '</span></fieldset>'.
3476: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3477: foreach my $role (@courseroles) {
3478: my ($checked,$checkednone);
3479: $datatable .= '<td align="center">'.
3480: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3481: '<select name="ltitools_add_roles_'.$role.'">'.
3482: '<option value="" selected="selected">'.&mt('Select').'</option>';
3483: foreach my $ltirole (@ltiroles) {
3484: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
3485: }
3486: $datatable .= '</select></td>';
3487: }
3488: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 3489: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
3490: foreach my $item ('label','title','target') {
3491: $datatable .= '<label>'.
3492: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
3493: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3494: }
3495: $datatable .= '</span></fieldset>'.
1.267 raeburn 3496: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3497: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
3498: '<tr><td><span class="LC_nobreak">'.
3499: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
3500: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
3501: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
3502: '</table></fieldset></td></tr>'."\n".
3503: '</td>'."\n".
3504: '</tr>'."\n";
3505: $itemcount ++;
3506: return $datatable;
3507: }
3508:
3509: sub ltitools_names {
3510: my %lt = &Apache::lonlocal::texthash(
3511: 'title' => 'Title',
3512: 'version' => 'Version',
3513: 'msgtype' => 'Message Type',
3514: 'url' => 'URL',
3515: 'key' => 'Key',
3516: 'secret' => 'Secret',
3517: 'icon' => 'Icon',
3518: 'user' => 'Username:domain',
3519: 'fullname' => 'Full Name',
3520: 'firstname' => 'First Name',
3521: 'lastname' => 'Last Name',
3522: 'email' => 'E-mail',
3523: 'roles' => 'Role',
3524: 'window' => 'Window/Tab',
3525: 'iframe' => 'iFrame',
3526: 'height' => 'Height',
3527: 'width' => 'Width',
3528: 'passback' => 'Tool can return grades:',
3529: 'roster' => 'Tool can retrieve roster:',
1.273 raeburn 3530: 'crstarget' => 'Display target',
3531: 'crslabel' => 'Course label',
3532: 'crstitle' => 'Course title',
1.267 raeburn 3533: );
3534: return %lt;
3535: }
3536:
1.121 raeburn 3537: sub print_coursedefaults {
1.139 raeburn 3538: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 3539: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 3540: my $itemcount = 1;
1.192 raeburn 3541: my %choices = &Apache::lonlocal::texthash (
3542: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 3543: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 3544: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
3545: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 3546: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
3547: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
3548: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 3549: canclone => "People who may clone a course (besides course's owner and coordinators)",
3550: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 3551: );
1.198 raeburn 3552: my %staticdefaults = (
3553: anonsurvey_threshold => 10,
3554: uploadquota => 500,
1.257 raeburn 3555: postsubmit => 60,
1.276 raeburn 3556: mysqltables => 172800,
1.198 raeburn 3557: );
1.139 raeburn 3558: if ($position eq 'top') {
1.257 raeburn 3559: %defaultchecked = (
3560: 'canuse_pdfforms' => 'off',
3561: 'uselcmath' => 'on',
3562: 'usejsme' => 'on',
1.264 raeburn 3563: 'canclone' => 'none',
1.257 raeburn 3564: );
3565: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.139 raeburn 3566: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 3567: \%choices,$itemcount);
1.264 raeburn 3568: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3569: $datatable .=
3570: '<tr'.$css_class.'><td valign="top">'.
3571: '<span class="LC_nobreak">'.$choices{'canclone'}.
3572: '</span></td><td class="LC_left_item">';
3573: my $currcanclone = 'none';
3574: my $onclick;
3575: my @cloneoptions = ('none','domain');
3576: my %clonetitles = (
3577: none => 'No additional course requesters',
3578: domain => "Any course requester in course's domain",
3579: instcode => 'Course requests for official courses ...',
3580: );
3581: my (%codedefaults,@code_order,@posscodes);
3582: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
3583: \@code_order) eq 'ok') {
3584: if (@code_order > 0) {
3585: push(@cloneoptions,'instcode');
3586: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
3587: }
3588: }
3589: if (ref($settings) eq 'HASH') {
3590: if ($settings->{'canclone'}) {
3591: if (ref($settings->{'canclone'}) eq 'HASH') {
3592: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
3593: if (@code_order > 0) {
3594: $currcanclone = 'instcode';
3595: @posscodes = @{$settings->{'canclone'}{'instcode'}};
3596: }
3597: }
3598: } elsif ($settings->{'canclone'} eq 'domain') {
3599: $currcanclone = $settings->{'canclone'};
3600: }
3601: }
3602: }
3603: foreach my $option (@cloneoptions) {
3604: my ($checked,$additional);
3605: if ($currcanclone eq $option) {
3606: $checked = ' checked="checked"';
3607: }
3608: if ($option eq 'instcode') {
3609: if (@code_order) {
3610: my $show = 'none';
3611: if ($checked) {
3612: $show = 'block';
3613: }
3614: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
3615: &mt('Institutional codes for new and cloned course have identical:').
3616: '<br />';
3617: foreach my $item (@code_order) {
3618: my $codechk;
3619: if ($checked) {
3620: if (grep(/^\Q$item\E$/,@posscodes)) {
3621: $codechk = ' checked="checked"';
3622: }
3623: }
3624: $additional .= '<label>'.
3625: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
3626: $item.'</label>';
3627: }
3628: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
3629: }
3630: }
3631: $datatable .=
3632: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
3633: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
3634: '</label> '.$additional.'</span><br />';
3635: }
3636: $datatable .= '</td>'.
3637: '</tr>';
3638: $itemcount ++;
1.139 raeburn 3639: } else {
3640: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 3641: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 3642: my $currusecredits = 0;
1.257 raeburn 3643: my $postsubmitclient = 1;
1.271 raeburn 3644: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 3645: if (ref($settings) eq 'HASH') {
3646: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 3647: if (ref($settings->{'uploadquota'}) eq 'HASH') {
3648: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
3649: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
3650: }
3651: }
1.192 raeburn 3652: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 3653: foreach my $type (@types) {
3654: next if ($type eq 'community');
3655: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
3656: if ($defcredits{$type} ne '') {
3657: $currusecredits = 1;
3658: }
3659: }
3660: }
3661: if (ref($settings->{'postsubmit'}) eq 'HASH') {
3662: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
3663: $postsubmitclient = 0;
3664: foreach my $type (@types) {
3665: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3666: }
3667: } else {
3668: foreach my $type (@types) {
3669: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
3670: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
3671: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
3672: } else {
3673: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3674: }
3675: } else {
3676: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3677: }
3678: }
3679: }
3680: } else {
3681: foreach my $type (@types) {
3682: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 3683: }
3684: }
1.276 raeburn 3685: if (ref($settings->{'mysqltables'}) eq 'HASH') {
3686: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
3687: $currmysql{$type} = $settings->{'mysqltables'}{$type};
3688: }
3689: } else {
3690: foreach my $type (@types) {
3691: $currmysql{$type} = $staticdefaults{'mysqltables'};
3692: }
3693: }
1.258 raeburn 3694: } else {
3695: foreach my $type (@types) {
3696: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3697: }
1.139 raeburn 3698: }
3699: if (!$currdefresponder) {
1.198 raeburn 3700: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 3701: } elsif ($currdefresponder < 1) {
3702: $currdefresponder = 1;
3703: }
1.198 raeburn 3704: foreach my $type (@types) {
3705: if ($curruploadquota{$type} eq '') {
3706: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
3707: }
3708: }
1.139 raeburn 3709: $datatable .=
1.192 raeburn 3710: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3711: $choices{'anonsurvey_threshold'}.
1.139 raeburn 3712: '</span></td>'.
3713: '<td class="LC_right_item"><span class="LC_nobreak">'.
3714: '<input type="text" name="anonsurvey_threshold"'.
3715: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 3716: '</td></tr>'."\n";
3717: $itemcount ++;
3718: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3719: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3720: $choices{'uploadquota'}.
3721: '</span></td>'.
3722: '<td align="right" class="LC_right_item">'.
3723: '<table><tr>';
1.198 raeburn 3724: foreach my $type (@types) {
3725: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3726: '<input type="text" name="uploadquota_'.$type.'"'.
3727: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
3728: }
3729: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 3730: $itemcount ++;
1.236 raeburn 3731: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 3732: my $display = 'none';
1.192 raeburn 3733: if ($currusecredits) {
3734: $display = 'block';
3735: }
3736: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 3737: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
3738: foreach my $type (@types) {
3739: next if ($type eq 'community');
3740: $additional .= '<td align="center">'.&mt($type).'<br />'.
3741: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 3742: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 3743: }
3744: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 3745: %defaultchecked = ('coursecredits' => 'off');
3746: @toggles = ('coursecredits');
3747: my $current = {
3748: 'coursecredits' => $currusecredits,
3749: };
3750: (my $table,$itemcount) =
3751: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 3752: \%choices,$itemcount,$onclick,$additional,'left');
3753: $datatable .= $table;
3754: $onclick = "toggleDisplay(this.form,'studentsubmission');";
3755: my $display = 'none';
3756: if ($postsubmitclient) {
3757: $display = 'block';
3758: }
3759: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 3760: &mt('Number of seconds submit is disabled').'<br />'.
3761: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
3762: '<table><tr>';
1.257 raeburn 3763: foreach my $type (@types) {
3764: $additional .= '<td align="center">'.&mt($type).'<br />'.
3765: '<input type="text" name="'.$type.'_timeout" value="'.
3766: $deftimeout{$type}.'" size="5" /></td>';
3767: }
3768: $additional .= '</tr></table></div>'."\n";
3769: %defaultchecked = ('postsubmit' => 'on');
3770: @toggles = ('postsubmit');
1.280 raeburn 3771: $current = {
3772: 'postsubmit' => $postsubmitclient,
3773: };
1.257 raeburn 3774: ($table,$itemcount) =
3775: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3776: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 3777: $datatable .= $table;
1.276 raeburn 3778: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3779: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3780: $choices{'mysqltables'}.
3781: '</span></td>'.
3782: '<td align="right" class="LC_right_item">'.
3783: '<table><tr>';
3784: foreach my $type (@types) {
3785: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3786: '<input type="text" name="mysqltables_'.$type.'"'.
3787: ' value="'.$currmysql{$type}.'" size="5" /></td>';
3788: }
3789: $datatable .= '</tr></table></td></tr>'."\n";
3790: $itemcount ++;
3791:
1.139 raeburn 3792: }
1.192 raeburn 3793: $$rowtotal += $itemcount;
1.121 raeburn 3794: return $datatable;
1.118 jms 3795: }
3796:
1.231 raeburn 3797: sub print_selfenrollment {
3798: my ($position,$dom,$settings,$rowtotal) = @_;
3799: my ($css_class,$datatable);
3800: my $itemcount = 1;
1.271 raeburn 3801: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 3802: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 3803: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3804: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 3805: my @rows;
3806: my $key;
3807: if ($position eq 'top') {
3808: $key = 'admin';
3809: if (ref($rowsref) eq 'ARRAY') {
3810: @rows = @{$rowsref};
3811: }
3812: } elsif ($position eq 'middle') {
3813: $key = 'default';
3814: @rows = ('types','registered','approval','limit');
3815: }
3816: foreach my $row (@rows) {
3817: if (defined($titlesref->{$row})) {
3818: $itemcount ++;
3819: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3820: $datatable .= '<tr'.$css_class.'>'.
3821: '<td>'.$titlesref->{$row}.'</td>'.
3822: '<td class="LC_left_item">'.
3823: '<table><tr>';
3824: my (%current,%currentcap);
3825: if (ref($settings) eq 'HASH') {
3826: if (ref($settings->{$key}) eq 'HASH') {
3827: foreach my $type (@types) {
3828: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3829: $current{$type} = $settings->{$key}->{$type}->{$row};
3830: }
3831: if (($row eq 'limit') && ($key eq 'default')) {
3832: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3833: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
3834: }
3835: }
3836: }
3837: }
3838: }
3839: my %roles = (
3840: '0' => &Apache::lonnet::plaintext('dc'),
3841: );
3842:
3843: foreach my $type (@types) {
3844: unless (($row eq 'registered') && ($key eq 'default')) {
3845: $datatable .= '<th>'.&mt($type).'</th>';
3846: }
3847: }
3848: unless (($row eq 'registered') && ($key eq 'default')) {
3849: $datatable .= '</tr><tr>';
3850: }
3851: foreach my $type (@types) {
3852: if ($type eq 'community') {
3853: $roles{'1'} = &mt('Community personnel');
3854: } else {
3855: $roles{'1'} = &mt('Course personnel');
3856: }
3857: $datatable .= '<td style="vertical-align: top">';
3858: if ($position eq 'top') {
3859: my %checked;
3860: if ($current{$type} eq '0') {
3861: $checked{'0'} = ' checked="checked"';
3862: } else {
3863: $checked{'1'} = ' checked="checked"';
3864: }
3865: foreach my $role ('1','0') {
3866: $datatable .= '<span class="LC_nobreak"><label>'.
3867: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
3868: 'value="'.$role.'"'.$checked{$role}.' />'.
3869: $roles{$role}.'</label></span> ';
3870: }
3871: } else {
3872: if ($row eq 'types') {
3873: my %checked;
3874: if ($current{$type} =~ /^(all|dom)$/) {
3875: $checked{$1} = ' checked="checked"';
3876: } else {
3877: $checked{''} = ' checked="checked"';
3878: }
3879: foreach my $val ('','dom','all') {
3880: $datatable .= '<span class="LC_nobreak"><label>'.
3881: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3882: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3883: }
3884: } elsif ($row eq 'registered') {
3885: my %checked;
3886: if ($current{$type} eq '1') {
3887: $checked{'1'} = ' checked="checked"';
3888: } else {
3889: $checked{'0'} = ' checked="checked"';
3890: }
3891: foreach my $val ('0','1') {
3892: $datatable .= '<span class="LC_nobreak"><label>'.
3893: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3894: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3895: }
3896: } elsif ($row eq 'approval') {
3897: my %checked;
3898: if ($current{$type} =~ /^([12])$/) {
3899: $checked{$1} = ' checked="checked"';
3900: } else {
3901: $checked{'0'} = ' checked="checked"';
3902: }
3903: for my $val (0..2) {
3904: $datatable .= '<span class="LC_nobreak"><label>'.
3905: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3906: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3907: }
3908: } elsif ($row eq 'limit') {
3909: my %checked;
3910: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3911: $checked{$1} = ' checked="checked"';
3912: } else {
3913: $checked{'none'} = ' checked="checked"';
3914: }
3915: my $cap;
3916: if ($currentcap{$type} =~ /^\d+$/) {
3917: $cap = $currentcap{$type};
3918: }
3919: foreach my $val ('none','allstudents','selfenrolled') {
3920: $datatable .= '<span class="LC_nobreak"><label>'.
3921: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3922: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3923: }
3924: $datatable .= '<br />'.
3925: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3926: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3927: '</span>';
3928: }
3929: }
3930: $datatable .= '</td>';
3931: }
3932: $datatable .= '</tr>';
3933: }
3934: $datatable .= '</table></td></tr>';
3935: }
3936: } elsif ($position eq 'bottom') {
1.235 raeburn 3937: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3938: }
3939: $$rowtotal += $itemcount;
3940: return $datatable;
3941: }
3942:
3943: sub print_validation_rows {
3944: my ($caller,$dom,$settings,$rowtotal) = @_;
3945: my ($itemsref,$namesref,$fieldsref);
3946: if ($caller eq 'selfenroll') {
3947: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3948: } elsif ($caller eq 'requestcourses') {
3949: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3950: }
3951: my %currvalidation;
3952: if (ref($settings) eq 'HASH') {
3953: if (ref($settings->{'validation'}) eq 'HASH') {
3954: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 3955: }
1.235 raeburn 3956: }
3957: my $datatable;
3958: my $itemcount = 0;
3959: foreach my $item (@{$itemsref}) {
3960: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3961: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3962: $namesref->{$item}.
3963: '</span></td>'.
3964: '<td class="LC_left_item">';
3965: if (($item eq 'url') || ($item eq 'button')) {
3966: $datatable .= '<span class="LC_nobreak">'.
3967: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3968: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3969: } elsif ($item eq 'fields') {
3970: my @currfields;
3971: if (ref($currvalidation{$item}) eq 'ARRAY') {
3972: @currfields = @{$currvalidation{$item}};
3973: }
3974: foreach my $field (@{$fieldsref}) {
3975: my $check = '';
3976: if (grep(/^\Q$field\E$/,@currfields)) {
3977: $check = ' checked="checked"';
3978: }
3979: $datatable .= '<span class="LC_nobreak"><label>'.
3980: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3981: ' value="'.$field.'"'.$check.' />'.$field.
3982: '</label></span> ';
3983: }
3984: } elsif ($item eq 'markup') {
3985: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3986: $currvalidation{$item}.
1.231 raeburn 3987: '</textarea>';
1.235 raeburn 3988: }
3989: $datatable .= '</td></tr>'."\n";
3990: if (ref($rowtotal)) {
1.231 raeburn 3991: $itemcount ++;
3992: }
3993: }
1.235 raeburn 3994: if ($caller eq 'requestcourses') {
3995: my %currhash;
1.248 raeburn 3996: if (ref($settings) eq 'HASH') {
3997: if (ref($settings->{'validation'}) eq 'HASH') {
3998: if ($settings->{'validation'}{'dc'} ne '') {
3999: $currhash{$settings->{'validation'}{'dc'}} = 1;
4000: }
1.235 raeburn 4001: }
4002: }
4003: my $numinrow = 2;
4004: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4005: 'validationdc',%currhash);
1.247 raeburn 4006: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4007: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235 raeburn 4008: if ($numdc > 1) {
1.247 raeburn 4009: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 4010: } else {
1.247 raeburn 4011: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 4012: }
1.247 raeburn 4013: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 4014: $itemcount ++;
4015: }
4016: if (ref($rowtotal)) {
4017: $$rowtotal += $itemcount;
4018: }
1.231 raeburn 4019: return $datatable;
4020: }
4021:
1.137 raeburn 4022: sub print_usersessions {
4023: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 4024: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 4025: my (%by_ip,%by_location,@intdoms,@instdoms);
4026: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 4027:
4028: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 4029: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 4030: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 4031: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 4032: if ($position eq 'top') {
1.152 raeburn 4033: if (keys(%serverhomes) > 1) {
1.145 raeburn 4034: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 4035: my $curroffloadnow;
4036: if (ref($settings) eq 'HASH') {
4037: if (ref($settings->{'offloadnow'}) eq 'HASH') {
4038: $curroffloadnow = $settings->{'offloadnow'};
4039: }
4040: }
4041: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 4042: } else {
1.140 raeburn 4043: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 4044: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
4045: '</td></tr>';
1.140 raeburn 4046: }
1.137 raeburn 4047: } else {
1.279 raeburn 4048: my %titles = &usersession_titles();
4049: my ($prefix,@types);
4050: if ($position eq 'bottom') {
4051: $prefix = 'remote';
4052: @types = ('version','excludedomain','includedomain');
1.145 raeburn 4053: } else {
1.279 raeburn 4054: $prefix = 'hosted';
4055: @types = ('excludedomain','includedomain');
4056: }
4057: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
4058: }
4059: $$rowtotal += $itemcount;
4060: return $datatable;
4061: }
4062:
4063: sub rules_by_location {
4064: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
4065: my ($datatable,$itemcount,$css_class);
4066: if (keys(%{$by_location}) == 0) {
4067: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4068: $datatable = '<tr'.$css_class.'><td colspan="2">'.
4069: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
4070: '</td></tr>';
4071: $itemcount = 1;
4072: } else {
4073: $itemcount = 0;
4074: my $numinrow = 5;
4075: my (%current,%checkedon,%checkedoff);
4076: my @locations = sort(keys(%{$by_location}));
4077: foreach my $type (@{$types}) {
4078: $checkedon{$type} = '';
4079: $checkedoff{$type} = ' checked="checked"';
4080: }
4081: if (ref($settings) eq 'HASH') {
4082: if (ref($settings->{$prefix}) eq 'HASH') {
4083: foreach my $key (keys(%{$settings->{$prefix}})) {
4084: $current{$key} = $settings->{$prefix}{$key};
4085: if ($key eq 'version') {
4086: if ($current{$key} ne '') {
1.145 raeburn 4087: $checkedon{$key} = ' checked="checked"';
4088: $checkedoff{$key} = '';
4089: }
1.279 raeburn 4090: } elsif (ref($current{$key}) eq 'ARRAY') {
4091: $checkedon{$key} = ' checked="checked"';
4092: $checkedoff{$key} = '';
1.137 raeburn 4093: }
4094: }
4095: }
1.279 raeburn 4096: }
4097: foreach my $type (@{$types}) {
4098: next if ($type ne 'version' && !@locations);
4099: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4100: $datatable .= '<tr'.$css_class.'>
4101: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
4102: <span class="LC_nobreak">
4103: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4104: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4105: if ($type eq 'version') {
4106: my @lcversions = &Apache::lonnet::all_loncaparevs();
4107: my $selector = '<select name="'.$prefix.'_version">';
4108: foreach my $version (@lcversions) {
4109: my $selected = '';
4110: if ($current{'version'} eq $version) {
4111: $selected = ' selected="selected"';
1.145 raeburn 4112: }
1.279 raeburn 4113: $selector .= ' <option value="'.$version.'"'.
4114: $selected.'>'.$version.'</option>';
4115: }
4116: $selector .= '</select> ';
4117: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4118: } else {
4119: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4120: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4121: ' />'.(' 'x2).
4122: '<input type="button" value="'.&mt('uncheck all').'" '.
4123: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4124: "\n".
4125: '</div><div><table>';
4126: my $rem;
4127: for (my $i=0; $i<@locations; $i++) {
4128: my ($showloc,$value,$checkedtype);
4129: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
4130: my $ip = $by_location->{$locations[$i]}->[0];
4131: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4132: $value = join(':',@{$by_ip->{$ip}});
4133: $showloc = join(', ',@{$by_ip->{$ip}});
4134: if (ref($current{$type}) eq 'ARRAY') {
4135: foreach my $loc (@{$by_ip->{$ip}}) {
4136: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4137: $checkedtype = ' checked="checked"';
4138: last;
1.145 raeburn 4139: }
1.138 raeburn 4140: }
4141: }
4142: }
1.137 raeburn 4143: }
1.279 raeburn 4144: $rem = $i%($numinrow);
4145: if ($rem == 0) {
4146: if ($i > 0) {
4147: $datatable .= '</tr>';
4148: }
4149: $datatable .= '<tr>';
4150: }
4151: $datatable .= '<td class="LC_left_item">'.
4152: '<span class="LC_nobreak"><label>'.
4153: '<input type="checkbox" name="'.$prefix.'_'.$type.
4154: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4155: '</label></span></td>';
4156: }
4157: $rem = @locations%($numinrow);
4158: my $colsleft = $numinrow - $rem;
4159: if ($colsleft > 1 ) {
4160: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4161: ' </td>';
4162: } elsif ($colsleft == 1) {
4163: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4164: }
1.279 raeburn 4165: $datatable .= '</tr></table>';
1.137 raeburn 4166: }
1.279 raeburn 4167: $datatable .= '</td></tr>';
4168: $itemcount ++;
1.137 raeburn 4169: }
4170: }
1.279 raeburn 4171: return ($datatable,$itemcount);
1.137 raeburn 4172: }
4173:
1.275 raeburn 4174: sub print_ssl {
4175: my ($position,$dom,$settings,$rowtotal) = @_;
4176: my ($css_class,$datatable);
4177: my $itemcount = 1;
4178: if ($position eq 'top') {
1.281 raeburn 4179: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4180: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4181: my $same_institution;
4182: if ($intdom ne '') {
4183: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
4184: if (ref($internet_names) eq 'ARRAY') {
4185: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
4186: $same_institution = 1;
4187: }
4188: }
4189: }
1.275 raeburn 4190: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 4191: $datatable = '<tr'.$css_class.'><td colspan="2">';
4192: if ($same_institution) {
4193: my %domservers = &Apache::lonnet::get_servers($dom);
4194: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
4195: } else {
4196: $datatable .= &mt("You need to be logged into one of your own domain's servers to display information about the status of LON-CAPA SSL certificates.");
4197: }
4198: $datatable .= '</td></tr>';
1.275 raeburn 4199: $itemcount ++;
4200: } else {
4201: my %titles = &ssl_titles();
4202: my (%by_ip,%by_location,@intdoms,@instdoms);
4203: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
4204: my @alldoms = &Apache::lonnet::all_domains();
4205: my %serverhomes = %Apache::lonnet::serverhomeIDs;
4206: my @domservers = &Apache::lonnet::get_servers($dom);
4207: my %servers = &Apache::lonnet::internet_dom_servers($dom);
4208: my %altids = &id_for_thisdom(%servers);
4209: if ($position eq 'middle') {
4210: foreach my $type ('dom','intdom','other') {
4211: my %checked;
4212: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4213: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
4214: '<td class="LC_right_item">';
4215: my $skip;
4216: if ($type eq 'dom') {
4217: unless (keys(%servers) > 1) {
4218: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
4219: $skip = 1;
4220: }
4221: }
4222: if ($type eq 'intdom') {
4223: unless (@instdoms > 1) {
4224: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
4225: $skip = 1;
4226: }
4227: } elsif ($type eq 'other') {
4228: if (keys(%by_location) == 0) {
4229: $datatable .= &mt('Nothing to set here, as there are no other institutions');
4230: $skip = 1;
4231: }
4232: }
4233: unless ($skip) {
4234: $checked{'yes'} = ' checked="checked"';
4235: if (ref($settings) eq 'HASH') {
4236: if (ref($settings->{'connect'}) eq 'HASH') {
4237: if ($settings->{'connect'}->{$type} =~ /^(no|req)$/) {
4238: $checked{$1} = $checked{'yes'};
4239: delete($checked{'yes'});
4240: }
4241: }
4242: }
4243: foreach my $option ('no','yes','req') {
4244: $datatable .= '<span class="LC_nobreak"><label>'.
4245: '<input type="radio" name="connect_'.$type.'" '.
4246: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
4247: '</label></span>'.(' 'x2);
4248: }
4249: }
4250: $datatable .= '</td></tr>';
4251: $itemcount ++;
4252: }
4253: } else {
4254: my $prefix = 'replication';
4255: my @types = ('certreq','nocertreq');
1.279 raeburn 4256: if (keys(%by_location) == 0) {
4257: $datatable .= '<tr'.$css_class.'><td>'.
4258: &mt('Nothing to set here, as there are no other institutions').
4259: '</td></tr>';
4260: $itemcount ++;
1.275 raeburn 4261: } else {
1.279 raeburn 4262: ($datatable,$itemcount) =
4263: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 4264: }
4265: }
4266: }
4267: $$rowtotal += $itemcount;
4268: return $datatable;
4269: }
4270:
4271: sub ssl_titles {
4272: return &Apache::lonlocal::texthash (
4273: dom => 'LON-CAPA servers/VMs from same domain',
4274: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
4275: other => 'External LON-CAPA servers/VMs',
4276: connect => 'Connections to other servers',
4277: replication => 'Replicating content to other institutions',
4278: certreq => 'Client certificate required, but specific domains exempt',
4279: nocertreq => 'No client certificate required, except for specific domains',
4280: no => 'SSL not used',
4281: yes => 'SSL Optional (used if available)',
4282: req => 'SSL Required',
4283: );
1.279 raeburn 4284: }
4285:
4286: sub print_trust {
4287: my ($prefix,$dom,$settings,$rowtotal) = @_;
4288: my ($css_class,$datatable,%checked,%choices);
4289: my (%by_ip,%by_location,@intdoms,@instdoms);
4290: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
4291: my $itemcount = 1;
4292: my %titles = &trust_titles();
4293: my @types = ('exc','inc');
4294: if ($prefix eq 'top') {
4295: $prefix = 'content';
4296: } elsif ($prefix eq 'bottom') {
4297: $prefix = 'msg';
4298: }
4299: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
4300: $$rowtotal += $itemcount;
4301: return $datatable;
4302: }
4303:
4304: sub trust_titles {
4305: return &Apache::lonlocal::texthash(
4306: content => "Access to this domain's content by others",
4307: shared => "Access to other domain's content by this domain",
4308: enroll => "Enrollment in this domain's courses by others",
4309: othcoau => "Co-author roles in this domain for others",
4310: coaurem => "Co-author roles for this domain's users elsewhere",
4311: domroles => "Domain roles in this domain assignable to others",
4312: catalog => "Course Catalog for this domain displayed elsewhere",
4313: reqcrs => "Requests for creation of courses in this domain by others",
4314: msg => "Users in other domains can send messages to this domain",
4315: exc => "Allow all, but exclude specific domains",
4316: inc => "Deny all, but include specific domains",
4317: );
1.275 raeburn 4318: }
4319:
1.138 raeburn 4320: sub build_location_hashes {
1.275 raeburn 4321: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 4322: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 4323: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 4324: my %iphost = &Apache::lonnet::get_iphost();
4325: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4326: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4327: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4328: foreach my $id (@{$iphost{$primary_ip}}) {
4329: my $intdom = &Apache::lonnet::internet_dom($id);
4330: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4331: push(@{$intdoms},$intdom);
4332: }
4333: }
4334: }
4335: foreach my $ip (keys(%iphost)) {
4336: if (ref($iphost{$ip}) eq 'ARRAY') {
4337: foreach my $id (@{$iphost{$ip}}) {
4338: my $location = &Apache::lonnet::internet_dom($id);
4339: if ($location) {
1.275 raeburn 4340: if (grep(/^\Q$location\E$/,@{$intdoms})) {
4341: my $dom = &Apache::lonnet::host_domain($id);
4342: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
4343: push(@{$instdoms},$dom);
4344: }
4345: next;
4346: }
1.138 raeburn 4347: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4348: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4349: push(@{$by_ip->{$ip}},$location);
4350: }
4351: } else {
4352: $by_ip->{$ip} = [$location];
4353: }
4354: }
4355: }
4356: }
4357: }
4358: foreach my $ip (sort(keys(%{$by_ip}))) {
4359: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4360: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4361: my $first = $by_ip->{$ip}->[0];
4362: if (ref($by_location->{$first}) eq 'ARRAY') {
4363: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4364: push(@{$by_location->{$first}},$ip);
4365: }
4366: } else {
4367: $by_location->{$first} = [$ip];
4368: }
4369: }
4370: }
4371: return;
4372: }
4373:
1.145 raeburn 4374: sub current_offloads_to {
4375: my ($dom,$settings,$servers) = @_;
4376: my (%spareid,%otherdomconfigs);
1.152 raeburn 4377: if (ref($servers) eq 'HASH') {
1.145 raeburn 4378: foreach my $lonhost (sort(keys(%{$servers}))) {
4379: my $gotspares;
1.152 raeburn 4380: if (ref($settings) eq 'HASH') {
4381: if (ref($settings->{'spares'}) eq 'HASH') {
4382: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4383: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4384: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4385: $gotspares = 1;
4386: }
1.145 raeburn 4387: }
4388: }
4389: unless ($gotspares) {
4390: my $gotspares;
4391: my $serverhomeID =
4392: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4393: my $serverhomedom =
4394: &Apache::lonnet::host_domain($serverhomeID);
4395: if ($serverhomedom ne $dom) {
4396: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4397: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4398: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4399: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4400: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4401: $gotspares = 1;
4402: }
4403: }
4404: } else {
4405: $otherdomconfigs{$serverhomedom} =
4406: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4407: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4408: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4409: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4410: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4411: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4412: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4413: $gotspares = 1;
4414: }
4415: }
4416: }
4417: }
4418: }
4419: }
4420: }
4421: unless ($gotspares) {
4422: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4423: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4424: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4425: } else {
4426: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4427: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4428: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4429: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4430: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4431: } else {
1.150 raeburn 4432: my %what = (
4433: spareid => 1,
4434: );
4435: my ($result,$returnhash) =
4436: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4437: if ($result eq 'ok') {
4438: if (ref($returnhash) eq 'HASH') {
4439: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4440: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4441: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4442: }
4443: }
1.145 raeburn 4444: }
4445: }
4446: }
4447: }
4448: }
4449: }
4450: return %spareid;
4451: }
4452:
4453: sub spares_row {
1.261 raeburn 4454: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4455: my $css_class;
4456: my $numinrow = 4;
4457: my $itemcount = 1;
4458: my $datatable;
1.152 raeburn 4459: my %typetitles = &sparestype_titles();
4460: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 4461: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 4462: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
4463: my ($othercontrol,$serverdom);
4464: if ($serverhome ne $server) {
4465: $serverdom = &Apache::lonnet::host_domain($serverhome);
4466: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4467: } else {
4468: $serverdom = &Apache::lonnet::host_domain($server);
4469: if ($serverdom ne $dom) {
4470: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4471: }
4472: }
4473: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 4474: my $checkednow;
4475: if (ref($curroffloadnow) eq 'HASH') {
4476: if ($curroffloadnow->{$server}) {
4477: $checkednow = ' checked="checked"';
4478: }
4479: }
1.145 raeburn 4480: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4481: $datatable .= '<tr'.$css_class.'>
4482: <td rowspan="2">
1.183 bisitz 4483: <span class="LC_nobreak">'.
4484: &mt('[_1] when busy, offloads to:'
1.261 raeburn 4485: ,'<b>'.$server.'</b>').'</span><br />'.
4486: '<span class="LC_nobreak">'."\n".
4487: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
4488: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 4489: "\n";
1.145 raeburn 4490: my (%current,%canselect);
1.152 raeburn 4491: my @choices =
4492: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
4493: foreach my $type ('primary','default') {
4494: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 4495: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
4496: my @spares = @{$spareid->{$server}{$type}};
4497: if (@spares > 0) {
1.152 raeburn 4498: if ($othercontrol) {
4499: $current{$type} = join(', ',@spares);
4500: } else {
4501: $current{$type} .= '<table>';
4502: my $numspares = scalar(@spares);
4503: for (my $i=0; $i<@spares; $i++) {
4504: my $rem = $i%($numinrow);
4505: if ($rem == 0) {
4506: if ($i > 0) {
4507: $current{$type} .= '</tr>';
4508: }
4509: $current{$type} .= '<tr>';
1.145 raeburn 4510: }
1.152 raeburn 4511: $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'".');" /> '.
4512: $spareid->{$server}{$type}[$i].
4513: '</label></td>'."\n";
4514: }
4515: my $rem = @spares%($numinrow);
4516: my $colsleft = $numinrow - $rem;
4517: if ($colsleft > 1 ) {
4518: $current{$type} .= '<td colspan="'.$colsleft.
4519: '" class="LC_left_item">'.
4520: ' </td>';
4521: } elsif ($colsleft == 1) {
4522: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 4523: }
1.152 raeburn 4524: $current{$type} .= '</tr></table>';
1.150 raeburn 4525: }
1.145 raeburn 4526: }
4527: }
4528: if ($current{$type} eq '') {
4529: $current{$type} = &mt('None specified');
4530: }
1.152 raeburn 4531: if ($othercontrol) {
4532: if ($type eq 'primary') {
4533: $canselect{$type} = $othercontrol;
4534: }
4535: } else {
4536: $canselect{$type} =
4537: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
4538: '<select name="newspare_'.$type.'_'.$server.'" '.
4539: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
4540: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
4541: if (@choices > 0) {
4542: foreach my $lonhost (@choices) {
4543: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
4544: }
4545: }
4546: $canselect{$type} .= '</select>'."\n";
4547: }
4548: } else {
4549: $current{$type} = &mt('Could not be determined');
4550: if ($type eq 'primary') {
4551: $canselect{$type} = $othercontrol;
4552: }
1.145 raeburn 4553: }
1.152 raeburn 4554: if ($type eq 'default') {
4555: $datatable .= '<tr'.$css_class.'>';
4556: }
4557: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
4558: '<td>'.$current{$type}.'</td>'."\n".
4559: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 4560: }
4561: $itemcount ++;
4562: }
4563: }
4564: $$rowtotal += $itemcount;
4565: return $datatable;
4566: }
4567:
1.152 raeburn 4568: sub possible_newspares {
4569: my ($server,$currspares,$serverhomes,$altids) = @_;
4570: my $serverhostname = &Apache::lonnet::hostname($server);
4571: my %excluded;
4572: if ($serverhostname ne '') {
4573: %excluded = (
4574: $serverhostname => 1,
4575: );
4576: }
4577: if (ref($currspares) eq 'HASH') {
4578: foreach my $type (keys(%{$currspares})) {
4579: if (ref($currspares->{$type}) eq 'ARRAY') {
4580: if (@{$currspares->{$type}} > 0) {
4581: foreach my $curr (@{$currspares->{$type}}) {
4582: my $hostname = &Apache::lonnet::hostname($curr);
4583: $excluded{$hostname} = 1;
4584: }
4585: }
4586: }
4587: }
4588: }
4589: my @choices;
4590: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
4591: if (keys(%{$serverhomes}) > 1) {
4592: foreach my $name (sort(keys(%{$serverhomes}))) {
4593: unless ($excluded{$name}) {
4594: if (exists($altids->{$serverhomes->{$name}})) {
4595: push(@choices,$altids->{$serverhomes->{$name}});
4596: } else {
4597: push(@choices,$serverhomes->{$name});
1.145 raeburn 4598: }
4599: }
4600: }
4601: }
4602: }
1.152 raeburn 4603: return sort(@choices);
1.145 raeburn 4604: }
4605:
1.150 raeburn 4606: sub print_loadbalancing {
4607: my ($dom,$settings,$rowtotal) = @_;
4608: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4609: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4610: my $numinrow = 1;
4611: my $datatable;
4612: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 4613: my (%currbalancer,%currtargets,%currrules,%existing);
4614: if (ref($settings) eq 'HASH') {
4615: %existing = %{$settings};
4616: }
4617: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
4618: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
4619: \%currtargets,\%currrules);
1.150 raeburn 4620: } else {
4621: return;
4622: }
4623: my ($othertitle,$usertypes,$types) =
4624: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 4625: my $rownum = 8;
1.150 raeburn 4626: if (ref($types) eq 'ARRAY') {
4627: $rownum += scalar(@{$types});
4628: }
1.171 raeburn 4629: my @css_class = ('LC_odd_row','LC_even_row');
4630: my $balnum = 0;
4631: my $islast;
4632: my (@toshow,$disabledtext);
4633: if (keys(%currbalancer) > 0) {
4634: @toshow = sort(keys(%currbalancer));
4635: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
4636: push(@toshow,'');
4637: }
4638: } else {
4639: @toshow = ('');
4640: $disabledtext = &mt('No existing load balancer');
4641: }
4642: foreach my $lonhost (@toshow) {
4643: if ($balnum == scalar(@toshow)-1) {
4644: $islast = 1;
4645: } else {
4646: $islast = 0;
4647: }
4648: my $cssidx = $balnum%2;
4649: my $targets_div_style = 'display: none';
4650: my $disabled_div_style = 'display: block';
4651: my $homedom_div_style = 'display: none';
4652: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
4653: '<td rowspan="'.$rownum.'" valign="top">'.
4654: '<p>';
4655: if ($lonhost eq '') {
1.210 raeburn 4656: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 4657: if (keys(%currbalancer) > 0) {
4658: $datatable .= &mt('Add balancer:');
4659: } else {
4660: $datatable .= &mt('Enable balancer:');
4661: }
4662: $datatable .= ' '.
4663: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
4664: ' id="loadbalancing_lonhost_'.$balnum.'"'.
4665: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
4666: '<option value="" selected="selected">'.&mt('None').
4667: '</option>'."\n";
4668: foreach my $server (sort(keys(%servers))) {
4669: next if ($currbalancer{$server});
4670: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
4671: }
1.210 raeburn 4672: $datatable .=
1.171 raeburn 4673: '</select>'."\n".
4674: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
4675: } else {
4676: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
4677: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
4678: &mt('Stop balancing').'</label>'.
4679: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
4680: $targets_div_style = 'display: block';
4681: $disabled_div_style = 'display: none';
4682: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
4683: $homedom_div_style = 'display: block';
4684: }
4685: }
4686: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
4687: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
4688: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
4689: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
4690: my ($numspares,@spares) = &count_servers($lonhost,%servers);
4691: my @sparestypes = ('primary','default');
4692: my %typetitles = &sparestype_titles();
1.284 ! raeburn 4693: my %hostherechecked = (
! 4694: no => ' checked="checked"',
! 4695: );
1.171 raeburn 4696: foreach my $sparetype (@sparestypes) {
4697: my $targettable;
4698: for (my $i=0; $i<$numspares; $i++) {
4699: my $checked;
4700: if (ref($currtargets{$lonhost}) eq 'HASH') {
4701: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4702: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
4703: $checked = ' checked="checked"';
4704: }
4705: }
4706: }
4707: my ($chkboxval,$disabled);
4708: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
4709: $chkboxval = $spares[$i];
4710: }
4711: if (exists($currbalancer{$spares[$i]})) {
4712: $disabled = ' disabled="disabled"';
4713: }
1.210 raeburn 4714: $targettable .=
1.253 raeburn 4715: '<td><span class="LC_nobreak"><label>'.
4716: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 4717: $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 4718: '</span></label></span></td>';
1.171 raeburn 4719: my $rem = $i%($numinrow);
4720: if ($rem == 0) {
4721: if (($i > 0) && ($i < $numspares-1)) {
4722: $targettable .= '</tr>';
4723: }
4724: if ($i < $numspares-1) {
4725: $targettable .= '<tr>';
1.150 raeburn 4726: }
4727: }
4728: }
1.171 raeburn 4729: if ($targettable ne '') {
4730: my $rem = $numspares%($numinrow);
4731: my $colsleft = $numinrow - $rem;
4732: if ($colsleft > 1 ) {
4733: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4734: ' </td>';
4735: } elsif ($colsleft == 1) {
4736: $targettable .= '<td class="LC_left_item"> </td>';
4737: }
4738: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
4739: '<table><tr>'.$targettable.'</tr></table><br />';
4740: }
1.284 ! raeburn 4741: $hostherechecked{$sparetype} = '';
! 4742: if (ref($currtargets{$lonhost}) eq 'HASH') {
! 4743: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
! 4744: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
! 4745: $hostherechecked{$sparetype} = ' checked="checked"';
! 4746: $hostherechecked{'no'} = '';
! 4747: }
! 4748: }
! 4749: }
! 4750: }
! 4751: $datatable .= &mt('Hosting on balancer itself').'<br />'.
! 4752: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
! 4753: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
! 4754: foreach my $sparetype (@sparestypes) {
! 4755: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
! 4756: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
! 4757: '</i></label><br />';
1.171 raeburn 4758: }
4759: $datatable .= '</div></td></tr>'.
4760: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
4761: $othertitle,$usertypes,$types,\%servers,
4762: \%currbalancer,$lonhost,
4763: $targets_div_style,$homedom_div_style,
4764: $css_class[$cssidx],$balnum,$islast);
4765: $$rowtotal += $rownum;
4766: $balnum ++;
4767: }
4768: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
4769: return $datatable;
4770: }
4771:
4772: sub get_loadbalancers_config {
4773: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
4774: return unless ((ref($servers) eq 'HASH') &&
4775: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
4776: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
4777: if (keys(%{$existing}) > 0) {
4778: my $oldlonhost;
4779: foreach my $key (sort(keys(%{$existing}))) {
4780: if ($key eq 'lonhost') {
4781: $oldlonhost = $existing->{'lonhost'};
4782: $currbalancer->{$oldlonhost} = 1;
4783: } elsif ($key eq 'targets') {
4784: if ($oldlonhost) {
4785: $currtargets->{$oldlonhost} = $existing->{'targets'};
4786: }
4787: } elsif ($key eq 'rules') {
4788: if ($oldlonhost) {
4789: $currrules->{$oldlonhost} = $existing->{'rules'};
4790: }
4791: } elsif (ref($existing->{$key}) eq 'HASH') {
4792: $currbalancer->{$key} = 1;
4793: $currtargets->{$key} = $existing->{$key}{'targets'};
4794: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 4795: }
4796: }
1.171 raeburn 4797: } else {
4798: my ($balancerref,$targetsref) =
4799: &Apache::lonnet::get_lonbalancer_config($servers);
4800: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
4801: foreach my $server (sort(keys(%{$balancerref}))) {
4802: $currbalancer->{$server} = 1;
4803: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 4804: }
4805: }
4806: }
1.171 raeburn 4807: return;
1.150 raeburn 4808: }
4809:
4810: sub loadbalancing_rules {
4811: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 4812: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
4813: $css_class,$balnum,$islast) = @_;
1.150 raeburn 4814: my $output;
1.171 raeburn 4815: my $num = 0;
1.210 raeburn 4816: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 4817: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
4818: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
4819: foreach my $type (@{$alltypes}) {
1.171 raeburn 4820: $num ++;
1.150 raeburn 4821: my $current;
4822: if (ref($currrules) eq 'HASH') {
4823: $current = $currrules->{$type};
4824: }
1.253 raeburn 4825: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 4826: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 4827: $current = '';
4828: }
4829: }
4830: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 4831: $servers,$currbalancer,$lonhost,$dom,
4832: $targets_div_style,$homedom_div_style,
4833: $css_class,$balnum,$num,$islast);
1.150 raeburn 4834: }
4835: }
4836: return $output;
4837: }
4838:
4839: sub loadbalancing_titles {
4840: my ($dom,$intdom,$usertypes,$types) = @_;
4841: my %othertypes = (
4842: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
4843: '_LC_author' => &mt('Users from [_1] with author role',$dom),
4844: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
4845: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 4846: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
4847: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 4848: );
1.209 raeburn 4849: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 4850: if (ref($types) eq 'ARRAY') {
4851: unshift(@alltypes,@{$types},'default');
4852: }
4853: my %titles;
4854: foreach my $type (@alltypes) {
4855: if ($type =~ /^_LC_/) {
4856: $titles{$type} = $othertypes{$type};
4857: } elsif ($type eq 'default') {
4858: $titles{$type} = &mt('All users from [_1]',$dom);
4859: if (ref($types) eq 'ARRAY') {
4860: if (@{$types} > 0) {
4861: $titles{$type} = &mt('Other users from [_1]',$dom);
4862: }
4863: }
4864: } elsif (ref($usertypes) eq 'HASH') {
4865: $titles{$type} = $usertypes->{$type};
4866: }
4867: }
4868: return (\@alltypes,\%othertypes,\%titles);
4869: }
4870:
4871: sub loadbalance_rule_row {
1.171 raeburn 4872: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
4873: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 4874: my @rulenames;
1.150 raeburn 4875: my %ruletitles = &offloadtype_text();
1.209 raeburn 4876: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 4877: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 4878: } else {
1.209 raeburn 4879: @rulenames = ('default','homeserver');
4880: if ($type eq '_LC_external') {
4881: push(@rulenames,'externalbalancer');
4882: } else {
4883: push(@rulenames,'specific');
4884: }
4885: push(@rulenames,'none');
1.150 raeburn 4886: }
4887: my $style = $targets_div_style;
1.253 raeburn 4888: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 4889: $style = $homedom_div_style;
4890: }
1.171 raeburn 4891: my $space;
4892: if ($islast && $num == 1) {
4893: $space = '<div display="inline-block"> </div>';
4894: }
1.210 raeburn 4895: my $output =
1.171 raeburn 4896: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
4897: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
4898: '<td valaign="top">'.$space.
4899: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 4900: for (my $i=0; $i<@rulenames; $i++) {
4901: my $rule = $rulenames[$i];
4902: my ($checked,$extra);
4903: if ($rulenames[$i] eq 'default') {
4904: $rule = '';
4905: }
4906: if ($rulenames[$i] eq 'specific') {
4907: if (ref($servers) eq 'HASH') {
4908: my $default;
4909: if (($current ne '') && (exists($servers->{$current}))) {
4910: $checked = ' checked="checked"';
4911: }
4912: unless ($checked) {
4913: $default = ' selected="selected"';
4914: }
1.210 raeburn 4915: $extra =
1.171 raeburn 4916: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
4917: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
4918: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
4919: '<option value=""'.$default.'></option>'."\n";
4920: foreach my $server (sort(keys(%{$servers}))) {
4921: if (ref($currbalancer) eq 'HASH') {
4922: next if (exists($currbalancer->{$server}));
4923: }
1.150 raeburn 4924: my $selected;
1.171 raeburn 4925: if ($server eq $current) {
1.150 raeburn 4926: $selected = ' selected="selected"';
4927: }
1.171 raeburn 4928: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 4929: }
4930: $extra .= '</select>';
4931: }
4932: } elsif ($rule eq $current) {
4933: $checked = ' checked="checked"';
4934: }
4935: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 4936: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
4937: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
4938: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 4939: ')"'.$checked.' /> ';
4940: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
4941: $output .= $ruletitles{'particular'};
4942: } else {
4943: $output .= $ruletitles{$rulenames[$i]};
4944: }
4945: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 4946: }
4947: $output .= '</div></td></tr>'."\n";
4948: return $output;
4949: }
4950:
4951: sub offloadtype_text {
4952: my %ruletitles = &Apache::lonlocal::texthash (
4953: 'default' => 'Offloads to default destinations',
4954: 'homeserver' => "Offloads to user's home server",
4955: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
4956: 'specific' => 'Offloads to specific server',
1.161 raeburn 4957: 'none' => 'No offload',
1.209 raeburn 4958: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
4959: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 4960: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 4961: );
4962: return %ruletitles;
4963: }
4964:
4965: sub sparestype_titles {
4966: my %typestitles = &Apache::lonlocal::texthash (
4967: 'primary' => 'primary',
4968: 'default' => 'default',
4969: );
4970: return %typestitles;
4971: }
4972:
1.28 raeburn 4973: sub contact_titles {
4974: my %titles = &Apache::lonlocal::texthash (
4975: 'supportemail' => 'Support E-mail address',
1.69 raeburn 4976: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 4977: 'errormail' => 'Error reports to be e-mailed to',
4978: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 4979: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
4980: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 4981: 'requestsmail' => 'E-mail from course requests requiring approval',
1.190 raeburn 4982: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 4983: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 4984: );
4985: my %short_titles = &Apache::lonlocal::texthash (
4986: adminemail => 'Admin E-mail address',
4987: supportemail => 'Support E-mail',
4988: );
4989: return (\%titles,\%short_titles);
4990: }
4991:
1.72 raeburn 4992: sub tool_titles {
4993: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 4994: aboutme => 'Personal web page',
1.86 raeburn 4995: blog => 'Blog',
1.162 raeburn 4996: webdav => 'WebDAV',
1.86 raeburn 4997: portfolio => 'Portfolio',
1.88 bisitz 4998: official => 'Official courses (with institutional codes)',
4999: unofficial => 'Unofficial courses',
1.98 raeburn 5000: community => 'Communities',
1.216 raeburn 5001: textbook => 'Textbook courses',
1.271 raeburn 5002: placement => 'Placement tests',
1.86 raeburn 5003: );
1.72 raeburn 5004: return %titles;
5005: }
5006:
1.101 raeburn 5007: sub courserequest_titles {
5008: my %titles = &Apache::lonlocal::texthash (
5009: official => 'Official',
5010: unofficial => 'Unofficial',
5011: community => 'Communities',
1.216 raeburn 5012: textbook => 'Textbook',
1.271 raeburn 5013: placement => 'Placement tests',
1.101 raeburn 5014: norequest => 'Not allowed',
1.104 raeburn 5015: approval => 'Approval by Dom. Coord.',
1.101 raeburn 5016: validate => 'With validation',
5017: autolimit => 'Numerical limit',
1.103 raeburn 5018: unlimited => '(blank for unlimited)',
1.101 raeburn 5019: );
5020: return %titles;
5021: }
5022:
1.163 raeburn 5023: sub authorrequest_titles {
5024: my %titles = &Apache::lonlocal::texthash (
5025: norequest => 'Not allowed',
5026: approval => 'Approval by Dom. Coord.',
5027: automatic => 'Automatic approval',
5028: );
5029: return %titles;
1.210 raeburn 5030: }
1.163 raeburn 5031:
1.101 raeburn 5032: sub courserequest_conditions {
5033: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 5034: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 5035: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 5036: );
5037: return %conditions;
5038: }
5039:
5040:
1.27 raeburn 5041: sub print_usercreation {
1.30 raeburn 5042: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 5043: my $numinrow = 4;
1.28 raeburn 5044: my $datatable;
5045: if ($position eq 'top') {
1.30 raeburn 5046: $$rowtotal ++;
1.34 raeburn 5047: my $rowcount = 0;
1.32 raeburn 5048: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 5049: if (ref($rules) eq 'HASH') {
5050: if (keys(%{$rules}) > 0) {
1.32 raeburn 5051: $datatable .= &user_formats_row('username',$settings,$rules,
5052: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 5053: $$rowtotal ++;
1.32 raeburn 5054: $rowcount ++;
5055: }
5056: }
5057: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
5058: if (ref($idrules) eq 'HASH') {
5059: if (keys(%{$idrules}) > 0) {
5060: $datatable .= &user_formats_row('id',$settings,$idrules,
5061: $idruleorder,$numinrow,$rowcount);
5062: $$rowtotal ++;
5063: $rowcount ++;
1.28 raeburn 5064: }
5065: }
1.39 raeburn 5066: if ($rowcount == 0) {
5067: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
5068: $$rowtotal ++;
5069: $rowcount ++;
5070: }
1.34 raeburn 5071: } elsif ($position eq 'middle') {
1.224 raeburn 5072: my @creators = ('author','course','requestcrs');
1.37 raeburn 5073: my ($rules,$ruleorder) =
5074: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 5075: my %lt = &usercreation_types();
5076: my %checked;
5077: if (ref($settings) eq 'HASH') {
5078: if (ref($settings->{'cancreate'}) eq 'HASH') {
5079: foreach my $item (@creators) {
5080: $checked{$item} = $settings->{'cancreate'}{$item};
5081: }
5082: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
5083: foreach my $item (@creators) {
5084: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
5085: $checked{$item} = 'none';
5086: }
5087: }
5088: }
5089: }
5090: my $rownum = 0;
5091: foreach my $item (@creators) {
5092: $rownum ++;
1.224 raeburn 5093: if ($checked{$item} eq '') {
5094: $checked{$item} = 'any';
1.34 raeburn 5095: }
5096: my $css_class;
5097: if ($rownum%2) {
5098: $css_class = '';
5099: } else {
5100: $css_class = ' class="LC_odd_row" ';
5101: }
5102: $datatable .= '<tr'.$css_class.'>'.
5103: '<td><span class="LC_nobreak">'.$lt{$item}.
5104: '</span></td><td align="right">';
1.224 raeburn 5105: my @options = ('any');
5106: if (ref($rules) eq 'HASH') {
5107: if (keys(%{$rules}) > 0) {
5108: push(@options,('official','unofficial'));
1.37 raeburn 5109: }
5110: }
1.224 raeburn 5111: push(@options,'none');
1.37 raeburn 5112: foreach my $option (@options) {
1.50 raeburn 5113: my $type = 'radio';
1.34 raeburn 5114: my $check = ' ';
1.224 raeburn 5115: if ($checked{$item} eq $option) {
5116: $check = ' checked="checked" ';
1.34 raeburn 5117: }
5118: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 5119: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 5120: $item.'" value="'.$option.'"'.$check.'/> '.
5121: $lt{$option}.'</label> </span>';
5122: }
5123: $datatable .= '</td></tr>';
5124: }
1.28 raeburn 5125: } else {
5126: my @contexts = ('author','course','domain');
5127: my @authtypes = ('int','krb4','krb5','loc');
5128: my %checked;
5129: if (ref($settings) eq 'HASH') {
5130: if (ref($settings->{'authtypes'}) eq 'HASH') {
5131: foreach my $item (@contexts) {
5132: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
5133: foreach my $auth (@authtypes) {
5134: if ($settings->{'authtypes'}{$item}{$auth}) {
5135: $checked{$item}{$auth} = ' checked="checked" ';
5136: }
5137: }
5138: }
5139: }
1.27 raeburn 5140: }
1.35 raeburn 5141: } else {
5142: foreach my $item (@contexts) {
1.36 raeburn 5143: foreach my $auth (@authtypes) {
1.35 raeburn 5144: $checked{$item}{$auth} = ' checked="checked" ';
5145: }
5146: }
1.27 raeburn 5147: }
1.28 raeburn 5148: my %title = &context_names();
5149: my %authname = &authtype_names();
5150: my $rownum = 0;
5151: my $css_class;
5152: foreach my $item (@contexts) {
5153: if ($rownum%2) {
5154: $css_class = '';
5155: } else {
5156: $css_class = ' class="LC_odd_row" ';
5157: }
1.30 raeburn 5158: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 5159: '<td>'.$title{$item}.
5160: '</td><td class="LC_left_item">'.
5161: '<span class="LC_nobreak">';
5162: foreach my $auth (@authtypes) {
5163: $datatable .= '<label>'.
5164: '<input type="checkbox" name="'.$item.'_auth" '.
5165: $checked{$item}{$auth}.' value="'.$auth.'" />'.
5166: $authname{$auth}.'</label> ';
5167: }
5168: $datatable .= '</span></td></tr>';
5169: $rownum ++;
1.27 raeburn 5170: }
1.30 raeburn 5171: $$rowtotal += $rownum;
1.27 raeburn 5172: }
5173: return $datatable;
5174: }
5175:
1.224 raeburn 5176: sub print_selfcreation {
5177: my ($position,$dom,$settings,$rowtotal) = @_;
1.236 raeburn 5178: my (@selfcreate,$createsettings,$processing,$datatable);
1.224 raeburn 5179: if (ref($settings) eq 'HASH') {
5180: if (ref($settings->{'cancreate'}) eq 'HASH') {
5181: $createsettings = $settings->{'cancreate'};
1.236 raeburn 5182: if (ref($createsettings) eq 'HASH') {
5183: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
5184: @selfcreate = @{$createsettings->{'selfcreate'}};
5185: } elsif ($createsettings->{'selfcreate'} ne '') {
5186: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
5187: @selfcreate = ('email','login','sso');
5188: } elsif ($createsettings->{'selfcreate'} ne 'none') {
5189: @selfcreate = ($createsettings->{'selfcreate'});
5190: }
5191: }
5192: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5193: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 5194: }
5195: }
5196: }
5197: }
5198: my %radiohash;
5199: my $numinrow = 4;
5200: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
5201: if ($position eq 'top') {
5202: my %choices = &Apache::lonlocal::texthash (
5203: cancreate_login => 'Institutional Login',
5204: cancreate_sso => 'Institutional Single Sign On',
5205: );
5206: my @toggles = sort(keys(%choices));
5207: my %defaultchecked = (
5208: 'cancreate_login' => 'off',
5209: 'cancreate_sso' => 'off',
5210: );
1.228 raeburn 5211: my ($onclick,$itemcount);
1.224 raeburn 5212: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5213: \%choices,$itemcount,$onclick);
1.228 raeburn 5214: $$rowtotal += $itemcount;
5215:
1.224 raeburn 5216: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5217:
5218: if (ref($usertypes) eq 'HASH') {
5219: if (keys(%{$usertypes}) > 0) {
5220: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5221: $dom,$numinrow,$othertitle,
1.228 raeburn 5222: 'statustocreate',$$rowtotal);
1.224 raeburn 5223: $$rowtotal ++;
5224: }
5225: }
1.240 raeburn 5226: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5227: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5228: $fieldtitles{'inststatus'} = &mt('Institutional status');
5229: my $rem;
5230: my $numperrow = 2;
5231: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5232: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 5233: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 5234: '<td class="LC_left_item">'."\n".
5235: '<table><tr><td>'."\n";
5236: for (my $i=0; $i<@fields; $i++) {
5237: $rem = $i%($numperrow);
5238: if ($rem == 0) {
5239: if ($i > 0) {
5240: $datatable .= '</tr>';
5241: }
5242: $datatable .= '<tr>';
5243: }
5244: my $currval;
1.248 raeburn 5245: if (ref($createsettings) eq 'HASH') {
5246: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5247: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5248: }
1.240 raeburn 5249: }
5250: $datatable .= '<td class="LC_left_item">'.
5251: '<span class="LC_nobreak">'.
5252: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5253: 'value="'.$currval.'" size="10" /> '.
5254: $fieldtitles{$fields[$i]}.'</span></td>';
5255: }
5256: my $colsleft = $numperrow - $rem;
5257: if ($colsleft > 1 ) {
5258: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5259: ' </td>';
5260: } elsif ($colsleft == 1) {
5261: $datatable .= '<td class="LC_left_item"> </td>';
5262: }
5263: $datatable .= '</tr></table></td></tr>';
5264: $$rowtotal ++;
1.224 raeburn 5265: } elsif ($position eq 'middle') {
5266: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
5267: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5268: $usertypes->{'default'} = $othertitle;
5269: if (ref($types) eq 'ARRAY') {
5270: push(@{$types},'default');
5271: $usertypes->{'default'} = $othertitle;
5272: foreach my $status (@{$types}) {
5273: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.228 raeburn 5274: $numinrow,$$rowtotal,$usertypes);
1.240 raeburn 5275: $$rowtotal ++;
1.224 raeburn 5276: }
5277: }
5278: } else {
1.236 raeburn 5279: my %choices = &Apache::lonlocal::texthash (
5280: cancreate_email => 'E-mail address as username',
5281: );
5282: my @toggles = sort(keys(%choices));
5283: my %defaultchecked = (
5284: 'cancreate_email' => 'off',
5285: );
5286: my $itemcount = 0;
5287: my $display = 'none';
5288: if (grep(/^\Qemail\E$/,@selfcreate)) {
5289: $display = 'block';
5290: }
5291: my $onclick = "toggleDisplay(this.form,'emailoptions');";
5292: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
5293: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
5294: my $usertypes = {};
5295: my $order = [];
5296: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
5297: $usertypes = $domdefaults{'inststatustypes'};
5298: $order = $domdefaults{'inststatusguest'};
5299: }
5300: if (ref($order) eq 'ARRAY') {
5301: push(@{$order},'default');
5302: if (@{$order} > 1) {
5303: $usertypes->{'default'} = &mt('Other users');
5304: $additional .= '<table><tr>';
5305: foreach my $status (@{$order}) {
5306: $additional .= '<th>'.$usertypes->{$status}.'</th>';
5307: }
5308: $additional .= '</tr><tr>';
5309: foreach my $status (@{$order}) {
5310: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.224 raeburn 5311: }
1.236 raeburn 5312: $additional .= '</tr></table>';
1.224 raeburn 5313: } else {
1.236 raeburn 5314: $usertypes->{'default'} = &mt('All users');
5315: $additional .= &email_as_username($rowtotal,$processing);
1.224 raeburn 5316: }
5317: }
1.236 raeburn 5318: $additional .= '</div>'."\n";
5319:
5320: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.240 raeburn 5321: \%choices,$$rowtotal,$onclick,$additional);
5322: $$rowtotal ++;
1.236 raeburn 5323: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228 raeburn 5324: $$rowtotal ++;
1.224 raeburn 5325: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 5326: $numinrow = 1;
1.236 raeburn 5327: if (ref($order) eq 'ARRAY') {
5328: foreach my $status (@{$order}) {
1.228 raeburn 5329: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5330: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
5331: $$rowtotal ++;
5332: }
5333: }
1.224 raeburn 5334: my ($emailrules,$emailruleorder) =
5335: &Apache::lonnet::inst_userrules($dom,'email');
5336: if (ref($emailrules) eq 'HASH') {
5337: if (keys(%{$emailrules}) > 0) {
5338: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228 raeburn 5339: $emailruleorder,$numinrow,$$rowtotal);
1.224 raeburn 5340: $$rowtotal ++;
5341: }
5342: }
1.228 raeburn 5343: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224 raeburn 5344: }
5345: return $datatable;
5346: }
5347:
1.236 raeburn 5348: sub email_as_username {
5349: my ($rowtotal,$processing,$type) = @_;
5350: my %choices =
5351: &Apache::lonlocal::texthash (
5352: automatic => 'Automatic approval',
5353: approval => 'Queued for approval',
5354: );
5355: my $output;
5356: foreach my $option ('automatic','approval') {
5357: my $checked;
5358: if (ref($processing) eq 'HASH') {
5359: if ($type eq '') {
5360: if (!exists($processing->{'default'})) {
5361: if ($option eq 'automatic') {
5362: $checked = ' checked="checked"';
5363: }
5364: } else {
5365: if ($processing->{'default'} eq $option) {
5366: $checked = ' checked="checked"';
5367: }
5368: }
5369: } else {
5370: if (!exists($processing->{$type})) {
5371: if ($option eq 'automatic') {
5372: $checked = ' checked="checked"';
5373: }
5374: } else {
5375: if ($processing->{$type} eq $option) {
5376: $checked = ' checked="checked"';
5377: }
5378: }
5379: }
5380: } elsif ($option eq 'automatic') {
5381: $checked = ' checked="checked"';
5382: }
5383: my $name = 'cancreate_emailprocess';
5384: if (($type ne '') && ($type ne 'default')) {
5385: $name .= '_'.$type;
5386: }
5387: $output .= '<span class="LC_nobreak"><label>'.
5388: '<input type="radio" name="'.$name.'"'.
5389: $checked.' value="'.$option.'" />'.
5390: $choices{$option}.'</label></span>';
5391: if ($type eq '') {
5392: $output .= ' ';
5393: } else {
5394: $output .= '<br />';
5395: }
5396: }
5397: $$rowtotal ++;
5398: return $output;
5399: }
5400:
1.165 raeburn 5401: sub captcha_choice {
1.169 raeburn 5402: my ($context,$settings,$itemcount) = @_;
1.269 raeburn 5403: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
5404: $vertext,$currver);
1.165 raeburn 5405: my %lt = &captcha_phrases();
5406: $keyentry = 'hidden';
5407: if ($context eq 'cancreate') {
1.224 raeburn 5408: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 5409: } elsif ($context eq 'login') {
5410: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 5411: }
5412: if (ref($settings) eq 'HASH') {
5413: if ($settings->{'captcha'}) {
5414: $checked{$settings->{'captcha'}} = ' checked="checked"';
5415: } else {
5416: $checked{'original'} = ' checked="checked"';
5417: }
5418: if ($settings->{'captcha'} eq 'recaptcha') {
5419: $pubtext = $lt{'pub'};
5420: $privtext = $lt{'priv'};
5421: $keyentry = 'text';
1.269 raeburn 5422: $vertext = $lt{'ver'};
5423: $currver = $settings->{'recaptchaversion'};
5424: if ($currver ne '2') {
5425: $currver = 1;
5426: }
1.165 raeburn 5427: }
5428: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
5429: $currpub = $settings->{'recaptchakeys'}{'public'};
5430: $currpriv = $settings->{'recaptchakeys'}{'private'};
5431: }
5432: } else {
5433: $checked{'original'} = ' checked="checked"';
5434: }
1.169 raeburn 5435: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
5436: my $output = '<tr'.$css_class.'>'.
5437: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 5438: '<table><tr><td>'."\n";
5439: foreach my $option ('original','recaptcha','notused') {
5440: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
5441: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
5442: $lt{$option}.'</label></span>';
5443: unless ($option eq 'notused') {
5444: $output .= (' 'x2)."\n";
5445: }
5446: }
5447: #
5448: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
5449: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 5450: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 5451: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 5452: #
1.165 raeburn 5453: $output .= '</td></tr>'."\n".
5454: '<tr><td>'."\n".
5455: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
5456: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
5457: $currpub.'" size="40" /></span><br />'."\n".
5458: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
5459: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 5460: $currpriv.'" size="40" /></span><br />'.
5461: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
5462: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
5463: $currver.'" size="3" /></span><br />'.
5464: '</td></tr></table>'."\n".
1.165 raeburn 5465: '</td></tr>';
5466: return $output;
5467: }
5468:
1.32 raeburn 5469: sub user_formats_row {
5470: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
5471: my $output;
5472: my %text = (
5473: 'username' => 'new usernames',
5474: 'id' => 'IDs',
1.45 raeburn 5475: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 5476: );
5477: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5478: $output = '<tr '.$css_class.'>'.
1.63 raeburn 5479: '<td><span class="LC_nobreak">';
5480: if ($type eq 'email') {
5481: $output .= &mt("Formats disallowed for $text{$type}: ");
5482: } else {
5483: $output .= &mt("Format rules to check for $text{$type}: ");
5484: }
5485: $output .= '</span></td>'.
5486: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 5487: my $rem;
5488: if (ref($ruleorder) eq 'ARRAY') {
5489: for (my $i=0; $i<@{$ruleorder}; $i++) {
5490: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
5491: my $rem = $i%($numinrow);
5492: if ($rem == 0) {
5493: if ($i > 0) {
5494: $output .= '</tr>';
5495: }
5496: $output .= '<tr>';
5497: }
5498: my $check = ' ';
1.39 raeburn 5499: if (ref($settings) eq 'HASH') {
5500: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
5501: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
5502: $check = ' checked="checked" ';
5503: }
1.27 raeburn 5504: }
5505: }
5506: $output .= '<td class="LC_left_item">'.
5507: '<span class="LC_nobreak"><label>'.
1.32 raeburn 5508: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 5509: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
5510: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
5511: }
5512: }
5513: $rem = @{$ruleorder}%($numinrow);
5514: }
5515: my $colsleft = $numinrow - $rem;
5516: if ($colsleft > 1 ) {
5517: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5518: ' </td>';
5519: } elsif ($colsleft == 1) {
5520: $output .= '<td class="LC_left_item"> </td>';
5521: }
5522: $output .= '</tr></table></td></tr>';
5523: return $output;
5524: }
5525:
1.34 raeburn 5526: sub usercreation_types {
5527: my %lt = &Apache::lonlocal::texthash (
5528: author => 'When adding a co-author',
5529: course => 'When adding a user to a course',
1.100 raeburn 5530: requestcrs => 'When requesting a course',
1.34 raeburn 5531: any => 'Any',
5532: official => 'Institutional only ',
5533: unofficial => 'Non-institutional only',
5534: none => 'None',
5535: );
5536: return %lt;
1.48 raeburn 5537: }
1.34 raeburn 5538:
1.224 raeburn 5539: sub selfcreation_types {
5540: my %lt = &Apache::lonlocal::texthash (
5541: selfcreate => 'User creates own account',
5542: any => 'Any',
5543: official => 'Institutional only ',
5544: unofficial => 'Non-institutional only',
5545: email => 'E-mail address',
5546: login => 'Institutional Login',
5547: sso => 'SSO',
5548: );
5549: }
5550:
1.28 raeburn 5551: sub authtype_names {
5552: my %lt = &Apache::lonlocal::texthash(
5553: int => 'Internal',
5554: krb4 => 'Kerberos 4',
5555: krb5 => 'Kerberos 5',
5556: loc => 'Local',
5557: );
5558: return %lt;
5559: }
5560:
5561: sub context_names {
5562: my %context_title = &Apache::lonlocal::texthash(
5563: author => 'Creating users when an Author',
5564: course => 'Creating users when in a course',
5565: domain => 'Creating users when a Domain Coordinator',
5566: );
5567: return %context_title;
5568: }
5569:
1.33 raeburn 5570: sub print_usermodification {
5571: my ($position,$dom,$settings,$rowtotal) = @_;
5572: my $numinrow = 4;
5573: my ($context,$datatable,$rowcount);
5574: if ($position eq 'top') {
5575: $rowcount = 0;
5576: $context = 'author';
5577: foreach my $role ('ca','aa') {
5578: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5579: $numinrow,$rowcount);
5580: $$rowtotal ++;
5581: $rowcount ++;
5582: }
1.230 raeburn 5583: } elsif ($position eq 'bottom') {
1.33 raeburn 5584: $context = 'course';
5585: $rowcount = 0;
5586: foreach my $role ('st','ep','ta','in','cr') {
5587: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5588: $numinrow,$rowcount);
5589: $$rowtotal ++;
5590: $rowcount ++;
5591: }
5592: }
5593: return $datatable;
5594: }
5595:
1.43 raeburn 5596: sub print_defaults {
1.236 raeburn 5597: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 5598: my $rownum = 0;
5599: my ($datatable,$css_class);
1.236 raeburn 5600: if ($position eq 'top') {
5601: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
5602: 'datelocale_def','portal_def');
5603: my %defaults;
5604: if (ref($settings) eq 'HASH') {
5605: %defaults = %{$settings};
1.43 raeburn 5606: } else {
1.236 raeburn 5607: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
5608: foreach my $item (@items) {
5609: $defaults{$item} = $domdefaults{$item};
5610: }
1.43 raeburn 5611: }
1.236 raeburn 5612: my $titles = &defaults_titles($dom);
5613: foreach my $item (@items) {
5614: if ($rownum%2) {
5615: $css_class = '';
5616: } else {
5617: $css_class = ' class="LC_odd_row" ';
5618: }
5619: $datatable .= '<tr'.$css_class.'>'.
5620: '<td><span class="LC_nobreak">'.$titles->{$item}.
5621: '</span></td><td class="LC_right_item" colspan="3">';
5622: if ($item eq 'auth_def') {
5623: my @authtypes = ('internal','krb4','krb5','localauth');
5624: my %shortauth = (
5625: internal => 'int',
5626: krb4 => 'krb4',
5627: krb5 => 'krb5',
5628: localauth => 'loc'
5629: );
5630: my %authnames = &authtype_names();
5631: foreach my $auth (@authtypes) {
5632: my $checked = ' ';
5633: if ($defaults{$item} eq $auth) {
5634: $checked = ' checked="checked" ';
5635: }
5636: $datatable .= '<label><input type="radio" name="'.$item.
5637: '" value="'.$auth.'"'.$checked.'/>'.
5638: $authnames{$shortauth{$auth}}.'</label> ';
5639: }
5640: } elsif ($item eq 'timezone_def') {
5641: my $includeempty = 1;
5642: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
5643: } elsif ($item eq 'datelocale_def') {
5644: my $includeempty = 1;
5645: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
5646: } elsif ($item eq 'lang_def') {
1.263 raeburn 5647: my $includeempty = 1;
5648: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 5649: } else {
5650: my $size;
5651: if ($item eq 'portal_def') {
5652: $size = ' size="25"';
5653: }
5654: $datatable .= '<input type="text" name="'.$item.'" value="'.
5655: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 5656: }
1.236 raeburn 5657: $datatable .= '</td></tr>';
5658: $rownum ++;
5659: }
5660: } else {
5661: my (%defaults);
5662: if (ref($settings) eq 'HASH') {
5663: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
5664: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
5665: my $maxnum = @{$settings->{'inststatusorder'}};
5666: for (my $i=0; $i<$maxnum; $i++) {
5667: $css_class = $rownum%2?' class="LC_odd_row"':'';
5668: my $item = $settings->{'inststatusorder'}->[$i];
5669: my $title = $settings->{'inststatustypes'}->{$item};
5670: my $guestok;
5671: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
5672: $guestok = 1;
5673: }
5674: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
5675: $datatable .= '<tr'.$css_class.'>'.
5676: '<td><span class="LC_nobreak">'.
5677: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
5678: for (my $k=0; $k<=$maxnum; $k++) {
5679: my $vpos = $k+1;
5680: my $selstr;
5681: if ($k == $i) {
5682: $selstr = ' selected="selected" ';
5683: }
5684: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5685: }
5686: my ($checkedon,$checkedoff);
5687: $checkedoff = ' checked="checked"';
5688: if ($guestok) {
5689: $checkedon = $checkedoff;
5690: $checkedoff = '';
5691: }
5692: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
5693: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
5694: &mt('delete').'</span></td>'.
5695: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
5696: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
5697: '</span></td>'.
5698: '<td class="LC_right_item"><span class="LC_nobreak">'.
5699: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
5700: &mt('Yes').'</label>'.(' 'x2).
5701: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
5702: &mt('No').'</label></span></td></tr>';
5703: }
5704: $css_class = $rownum%2?' class="LC_odd_row"':'';
5705: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
5706: $datatable .= '<tr '.$css_class.'>'.
5707: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
5708: for (my $k=0; $k<=$maxnum; $k++) {
5709: my $vpos = $k+1;
5710: my $selstr;
5711: if ($k == $maxnum) {
5712: $selstr = ' selected="selected" ';
5713: }
5714: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5715: }
5716: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 5717: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 5718: ' '.&mt('(new)').
5719: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
5720: &mt('Name displayed:').
5721: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
5722: '<td class="LC_right_item"><span class="LC_nobreak">'.
5723: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
5724: &mt('Yes').'</label>'.(' 'x2).
5725: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
5726: &mt('No').'</label></span></td></tr>';
5727: '</tr>'."\n";
5728: $rownum ++;
1.141 raeburn 5729: }
1.43 raeburn 5730: }
5731: }
5732: $$rowtotal += $rownum;
5733: return $datatable;
5734: }
5735:
1.168 raeburn 5736: sub get_languages_hash {
5737: my %langchoices;
5738: foreach my $id (&Apache::loncommon::languageids()) {
5739: my $code = &Apache::loncommon::supportedlanguagecode($id);
5740: if ($code ne '') {
5741: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5742: }
5743: }
5744: return %langchoices;
5745: }
5746:
1.43 raeburn 5747: sub defaults_titles {
1.141 raeburn 5748: my ($dom) = @_;
1.43 raeburn 5749: my %titles = &Apache::lonlocal::texthash (
5750: 'auth_def' => 'Default authentication type',
5751: 'auth_arg_def' => 'Default authentication argument',
5752: 'lang_def' => 'Default language',
1.54 raeburn 5753: 'timezone_def' => 'Default timezone',
1.68 raeburn 5754: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 5755: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 5756: );
1.141 raeburn 5757: if ($dom) {
5758: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
5759: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
5760: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
5761: $protocol = 'http' if ($protocol ne 'https');
5762: if ($uint_dom) {
5763: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
5764: $uint_dom);
5765: }
5766: }
1.43 raeburn 5767: return (\%titles);
5768: }
5769:
1.46 raeburn 5770: sub print_scantronformat {
5771: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
5772: my $itemcount = 1;
1.60 raeburn 5773: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
5774: %confhash);
1.46 raeburn 5775: my $switchserver = &check_switchserver($dom,$confname);
5776: my %lt = &Apache::lonlocal::texthash (
1.95 www 5777: default => 'Default bubblesheet format file error',
5778: custom => 'Custom bubblesheet format file error',
1.46 raeburn 5779: );
5780: my %scantronfiles = (
5781: default => 'default.tab',
5782: custom => 'custom.tab',
5783: );
5784: foreach my $key (keys(%scantronfiles)) {
5785: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
5786: .$scantronfiles{$key};
5787: }
5788: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
5789: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
5790: if (!$switchserver) {
5791: my $servadm = $r->dir_config('lonAdmEMail');
5792: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
5793: if ($configuserok eq 'ok') {
5794: if ($author_ok eq 'ok') {
5795: my %legacyfile = (
5796: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
5797: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
5798: );
5799: my %md5chk;
5800: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5801: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
5802: chomp($md5chk{$type});
1.46 raeburn 5803: }
5804: if ($md5chk{'default'} ne $md5chk{'custom'}) {
5805: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5806: ($scantronurls{$type},my $error) =
1.46 raeburn 5807: &legacy_scantronformat($r,$dom,$confname,
5808: $type,$legacyfile{$type},
5809: $scantronurls{$type},
5810: $scantronfiles{$type});
1.60 raeburn 5811: if ($error ne '') {
5812: $error{$type} = $error;
5813: }
5814: }
5815: if (keys(%error) == 0) {
5816: $is_custom = 1;
5817: $confhash{'scantron'}{'scantronformat'} =
5818: $scantronurls{'custom'};
5819: my $putresult =
5820: &Apache::lonnet::put_dom('configuration',
5821: \%confhash,$dom);
5822: if ($putresult ne 'ok') {
5823: $error{'custom'} =
5824: '<span class="LC_error">'.
5825: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5826: }
1.46 raeburn 5827: }
5828: } else {
1.60 raeburn 5829: ($scantronurls{'default'},my $error) =
1.46 raeburn 5830: &legacy_scantronformat($r,$dom,$confname,
5831: 'default',$legacyfile{'default'},
5832: $scantronurls{'default'},
5833: $scantronfiles{'default'});
1.60 raeburn 5834: if ($error eq '') {
5835: $confhash{'scantron'}{'scantronformat'} = '';
5836: my $putresult =
5837: &Apache::lonnet::put_dom('configuration',
5838: \%confhash,$dom);
5839: if ($putresult ne 'ok') {
5840: $error{'default'} =
5841: '<span class="LC_error">'.
5842: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5843: }
5844: } else {
5845: $error{'default'} = $error;
5846: }
1.46 raeburn 5847: }
5848: }
5849: }
5850: } else {
1.95 www 5851: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 5852: }
5853: }
5854: if (ref($settings) eq 'HASH') {
5855: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
5856: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
5857: if ((!@info) || ($info[0] eq 'no_such_dir')) {
5858: $scantronurl = '';
5859: } else {
5860: $scantronurl = $settings->{'scantronformat'};
5861: }
5862: $is_custom = 1;
5863: } else {
5864: $scantronurl = $scantronurls{'default'};
5865: }
5866: } else {
1.60 raeburn 5867: if ($is_custom) {
5868: $scantronurl = $scantronurls{'custom'};
5869: } else {
5870: $scantronurl = $scantronurls{'default'};
5871: }
1.46 raeburn 5872: }
5873: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5874: $datatable .= '<tr'.$css_class.'>';
5875: if (!$is_custom) {
1.65 raeburn 5876: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
5877: '<span class="LC_nobreak">';
1.46 raeburn 5878: if ($scantronurl) {
1.199 raeburn 5879: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
5880: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 5881: } else {
5882: $datatable = &mt('File unavailable for display');
5883: }
1.65 raeburn 5884: $datatable .= '</span></td>';
1.60 raeburn 5885: if (keys(%error) == 0) {
5886: $datatable .= '<td valign="bottom">';
5887: if (!$switchserver) {
5888: $datatable .= &mt('Upload:').'<br />';
5889: }
5890: } else {
5891: my $errorstr;
5892: foreach my $key (sort(keys(%error))) {
5893: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5894: }
5895: $datatable .= '<td>'.$errorstr;
5896: }
1.46 raeburn 5897: } else {
5898: if (keys(%error) > 0) {
5899: my $errorstr;
5900: foreach my $key (sort(keys(%error))) {
5901: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5902: }
1.60 raeburn 5903: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 5904: } elsif ($scantronurl) {
1.199 raeburn 5905: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
5906: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 5907: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 5908: $link.
5909: '<label><input type="checkbox" name="scantronformat_del"'.
5910: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 5911: '<td><span class="LC_nobreak"> '.
5912: &mt('Replace:').'</span><br />';
1.46 raeburn 5913: }
5914: }
5915: if (keys(%error) == 0) {
5916: if ($switchserver) {
5917: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5918: } else {
1.65 raeburn 5919: $datatable .='<span class="LC_nobreak"> '.
5920: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 5921: }
5922: }
5923: $datatable .= '</td></tr>';
5924: $$rowtotal ++;
5925: return $datatable;
5926: }
5927:
5928: sub legacy_scantronformat {
5929: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
5930: my ($url,$error);
5931: my @statinfo = &Apache::lonnet::stat_file($newurl);
5932: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
5933: (my $result,$url) =
5934: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
5935: '','',$newfile);
5936: if ($result ne 'ok') {
1.130 raeburn 5937: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 5938: }
5939: }
5940: return ($url,$error);
5941: }
1.43 raeburn 5942:
1.49 raeburn 5943: sub print_coursecategories {
1.57 raeburn 5944: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
5945: my $datatable;
5946: if ($position eq 'top') {
1.238 raeburn 5947: my (%checked);
5948: my @catitems = ('unauth','auth');
5949: my @cattypes = ('std','domonly','codesrch','none');
5950: $checked{'unauth'} = 'std';
5951: $checked{'auth'} = 'std';
5952: if (ref($settings) eq 'HASH') {
5953: foreach my $type (@cattypes) {
5954: if ($type eq $settings->{'unauth'}) {
5955: $checked{'unauth'} = $type;
5956: }
5957: if ($type eq $settings->{'auth'}) {
5958: $checked{'auth'} = $type;
5959: }
5960: }
5961: }
5962: my %lt = &Apache::lonlocal::texthash (
5963: unauth => 'Catalog type for unauthenticated users',
5964: auth => 'Catalog type for authenticated users',
5965: none => 'No catalog',
5966: std => 'Standard catalog',
5967: domonly => 'Domain-only catalog',
5968: codesrch => "Code search form",
5969: );
5970: my $itemcount = 0;
5971: foreach my $item (@catitems) {
5972: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
5973: $datatable .= '<tr '.$css_class.'>'.
5974: '<td>'.$lt{$item}.'</td>'.
5975: '<td class="LC_right_item"><span class="LC_nobreak">';
5976: foreach my $type (@cattypes) {
5977: my $ischecked;
5978: if ($checked{$item} eq $type) {
5979: $ischecked=' checked="checked"';
5980: }
5981: $datatable .= '<label>'.
5982: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
5983: ' />'.$lt{$type}.'</label> ';
5984: }
5985: $datatable .= '</td></tr>';
5986: $itemcount ++;
5987: }
5988: $$rowtotal += $itemcount;
5989: } elsif ($position eq 'middle') {
1.57 raeburn 5990: my $toggle_cats_crs = ' ';
5991: my $toggle_cats_dom = ' checked="checked" ';
5992: my $can_cat_crs = ' ';
5993: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 5994: my $toggle_catscomm_comm = ' ';
5995: my $toggle_catscomm_dom = ' checked="checked" ';
5996: my $can_catcomm_comm = ' ';
5997: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 5998: my $toggle_catsplace_place = ' ';
5999: my $toggle_catsplace_dom = ' checked="checked" ';
6000: my $can_catplace_place = ' ';
6001: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 6002:
1.57 raeburn 6003: if (ref($settings) eq 'HASH') {
6004: if ($settings->{'togglecats'} eq 'crs') {
6005: $toggle_cats_crs = $toggle_cats_dom;
6006: $toggle_cats_dom = ' ';
6007: }
6008: if ($settings->{'categorize'} eq 'crs') {
6009: $can_cat_crs = $can_cat_dom;
6010: $can_cat_dom = ' ';
6011: }
1.120 raeburn 6012: if ($settings->{'togglecatscomm'} eq 'comm') {
6013: $toggle_catscomm_comm = $toggle_catscomm_dom;
6014: $toggle_catscomm_dom = ' ';
6015: }
6016: if ($settings->{'categorizecomm'} eq 'comm') {
6017: $can_catcomm_comm = $can_catcomm_dom;
6018: $can_catcomm_dom = ' ';
6019: }
1.272 raeburn 6020: if ($settings->{'togglecatsplace'} eq 'place') {
6021: $toggle_catsplace_place = $toggle_catsplace_dom;
6022: $toggle_catsplace_dom = ' ';
6023: }
6024: if ($settings->{'categorizeplace'} eq 'place') {
6025: $can_catplace_place = $can_catplace_dom;
6026: $can_catplace_dom = ' ';
6027: }
1.57 raeburn 6028: }
6029: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 6030: togglecats => 'Show/Hide a course in catalog',
6031: togglecatscomm => 'Show/Hide a community in catalog',
6032: togglecatsplace => 'Show/Hide a placement test in catalog',
6033: categorize => 'Assign a category to a course',
6034: categorizecomm => 'Assign a category to a community',
6035: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 6036: );
6037: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 6038: dom => 'Set in Domain',
6039: crs => 'Set in Course',
6040: comm => 'Set in Community',
6041: place => 'Set in Placement Test',
1.57 raeburn 6042: );
6043: $datatable = '<tr class="LC_odd_row">'.
6044: '<td>'.$title{'togglecats'}.'</td>'.
6045: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6046: '<input type="radio" name="togglecats"'.
6047: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6048: '<label><input type="radio" name="togglecats"'.
6049: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
6050: '</tr><tr>'.
6051: '<td>'.$title{'categorize'}.'</td>'.
6052: '<td class="LC_right_item"><span class="LC_nobreak">'.
6053: '<label><input type="radio" name="categorize"'.
6054: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6055: '<label><input type="radio" name="categorize"'.
6056: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 6057: '</tr><tr class="LC_odd_row">'.
6058: '<td>'.$title{'togglecatscomm'}.'</td>'.
6059: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6060: '<input type="radio" name="togglecatscomm"'.
6061: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6062: '<label><input type="radio" name="togglecatscomm"'.
6063: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
6064: '</tr><tr>'.
6065: '<td>'.$title{'categorizecomm'}.'</td>'.
6066: '<td class="LC_right_item"><span class="LC_nobreak">'.
6067: '<label><input type="radio" name="categorizecomm"'.
6068: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6069: '<label><input type="radio" name="categorizecomm"'.
6070: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.272 raeburn 6071: '</tr><tr>'.
6072: '<td>'.$title{'togglecatsplace'}.'</td>'.
6073: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6074: '<input type="radio" name="togglecatsplace"'.
6075: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6076: '<label><input type="radio" name="togglecatscomm"'.
6077: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
6078: '</tr><tr>'.
6079: '<td>'.$title{'categorizeplace'}.'</td>'.
6080: '<td class="LC_right_item"><span class="LC_nobreak">'.
6081: '<label><input type="radio" name="categorizeplace"'.
6082: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6083: '<label><input type="radio" name="categorizeplace"'.
6084: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 6085: '</tr>';
1.272 raeburn 6086: $$rowtotal += 6;
1.57 raeburn 6087: } else {
6088: my $css_class;
6089: my $itemcount = 1;
6090: my $cathash;
6091: if (ref($settings) eq 'HASH') {
6092: $cathash = $settings->{'cats'};
6093: }
6094: if (ref($cathash) eq 'HASH') {
6095: my (@cats,@trails,%allitems,%idx,@jsarray);
6096: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
6097: \%allitems,\%idx,\@jsarray);
6098: my $maxdepth = scalar(@cats);
6099: my $colattrib = '';
6100: if ($maxdepth > 2) {
6101: $colattrib = ' colspan="2" ';
6102: }
6103: my @path;
6104: if (@cats > 0) {
6105: if (ref($cats[0]) eq 'ARRAY') {
6106: my $numtop = @{$cats[0]};
6107: my $maxnum = $numtop;
1.120 raeburn 6108: my %default_names = (
6109: instcode => &mt('Official courses'),
6110: communities => &mt('Communities'),
1.272 raeburn 6111: placement => &mt('Placement Tests'),
1.120 raeburn 6112: );
6113:
6114: if ((!grep(/^instcode$/,@{$cats[0]})) ||
6115: ($cathash->{'instcode::0'} eq '') ||
6116: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 6117: ($cathash->{'communities::0'} eq '') ||
6118: (!grep(/^placement$/,@{$cats[0]})) ||
6119: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 6120: $maxnum ++;
6121: }
6122: my $lastidx;
6123: for (my $i=0; $i<$numtop; $i++) {
6124: my $parent = $cats[0][$i];
6125: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6126: my $item = &escape($parent).'::0';
6127: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
6128: $lastidx = $idx{$item};
6129: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6130: .'<select name="'.$item.'"'.$chgstr.'>';
6131: for (my $k=0; $k<=$maxnum; $k++) {
6132: my $vpos = $k+1;
6133: my $selstr;
6134: if ($k == $i) {
6135: $selstr = ' selected="selected" ';
6136: }
6137: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6138: }
1.214 raeburn 6139: $datatable .= '</select></span></td><td>';
1.272 raeburn 6140: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 6141: $datatable .= '<span class="LC_nobreak">'
6142: .$default_names{$parent}.'</span>';
6143: if ($parent eq 'instcode') {
6144: $datatable .= '<br /><span class="LC_nobreak">('
6145: .&mt('with institutional codes')
6146: .')</span></td><td'.$colattrib.'>';
6147: } else {
6148: $datatable .= '<table><tr><td>';
6149: }
6150: $datatable .= '<span class="LC_nobreak">'
6151: .'<label><input type="radio" name="'
6152: .$parent.'" value="1" checked="checked" />'
6153: .&mt('Display').'</label>';
6154: if ($parent eq 'instcode') {
6155: $datatable .= ' ';
6156: } else {
6157: $datatable .= '</span></td></tr><tr><td>'
6158: .'<span class="LC_nobreak">';
6159: }
6160: $datatable .= '<label><input type="radio" name="'
6161: .$parent.'" value="0" />'
6162: .&mt('Do not display').'</label></span>';
1.272 raeburn 6163: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 6164: $datatable .= '</td></tr></table>';
6165: }
6166: $datatable .= '</td>';
1.57 raeburn 6167: } else {
6168: $datatable .= $parent
1.214 raeburn 6169: .' <span class="LC_nobreak"><label>'
6170: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 6171: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
6172: }
6173: my $depth = 1;
6174: push(@path,$parent);
6175: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
6176: pop(@path);
6177: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
6178: $itemcount ++;
6179: }
1.48 raeburn 6180: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 6181: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
6182: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 6183: for (my $k=0; $k<=$maxnum; $k++) {
6184: my $vpos = $k+1;
6185: my $selstr;
1.57 raeburn 6186: if ($k == $numtop) {
1.48 raeburn 6187: $selstr = ' selected="selected" ';
6188: }
6189: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6190: }
1.59 bisitz 6191: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 6192: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
6193: .'</tr>'."\n";
1.48 raeburn 6194: $itemcount ++;
1.272 raeburn 6195: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 6196: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
6197: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6198: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
6199: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
6200: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
6201: for (my $k=0; $k<=$maxnum; $k++) {
6202: my $vpos = $k+1;
6203: my $selstr;
6204: if ($k == $maxnum) {
6205: $selstr = ' selected="selected" ';
6206: }
6207: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 6208: }
1.120 raeburn 6209: $datatable .= '</select></span></td>'.
6210: '<td><span class="LC_nobreak">'.
6211: $default_names{$default}.'</span>';
6212: if ($default eq 'instcode') {
6213: $datatable .= '<br /><span class="LC_nobreak">('
6214: .&mt('with institutional codes').')</span>';
6215: }
6216: $datatable .= '</td>'
6217: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
6218: .&mt('Display').'</label> '
6219: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
6220: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 6221: }
6222: }
6223: }
1.57 raeburn 6224: } else {
6225: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 6226: }
6227: } else {
1.238 raeburn 6228: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 6229: .&initialize_categories($itemcount);
1.48 raeburn 6230: }
1.57 raeburn 6231: $$rowtotal += $itemcount;
1.48 raeburn 6232: }
6233: return $datatable;
6234: }
6235:
1.69 raeburn 6236: sub print_serverstatuses {
6237: my ($dom,$settings,$rowtotal) = @_;
6238: my $datatable;
6239: my @pages = &serverstatus_pages();
6240: my (%namedaccess,%machineaccess);
6241: foreach my $type (@pages) {
6242: $namedaccess{$type} = '';
6243: $machineaccess{$type}= '';
6244: }
6245: if (ref($settings) eq 'HASH') {
6246: foreach my $type (@pages) {
6247: if (exists($settings->{$type})) {
6248: if (ref($settings->{$type}) eq 'HASH') {
6249: foreach my $key (keys(%{$settings->{$type}})) {
6250: if ($key eq 'namedusers') {
6251: $namedaccess{$type} = $settings->{$type}->{$key};
6252: } elsif ($key eq 'machines') {
6253: $machineaccess{$type} = $settings->{$type}->{$key};
6254: }
6255: }
6256: }
6257: }
6258: }
6259: }
1.81 raeburn 6260: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 6261: my $rownum = 0;
6262: my $css_class;
6263: foreach my $type (@pages) {
6264: $rownum ++;
6265: $css_class = $rownum%2?' class="LC_odd_row"':'';
6266: $datatable .= '<tr'.$css_class.'>'.
6267: '<td><span class="LC_nobreak">'.
6268: $titles->{$type}.'</span></td>'.
6269: '<td class="LC_left_item">'.
6270: '<input type="text" name="'.$type.'_namedusers" '.
6271: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
6272: '<td class="LC_right_item">'.
6273: '<span class="LC_nobreak">'.
6274: '<input type="text" name="'.$type.'_machines" '.
6275: 'value="'.$machineaccess{$type}.'" size="10" />'.
6276: '</td></tr>'."\n";
6277: }
6278: $$rowtotal += $rownum;
6279: return $datatable;
6280: }
6281:
6282: sub serverstatus_pages {
6283: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 6284: 'checksums','clusterstatus','certstatus','metadata_keywords',
6285: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
6286: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 6287: }
6288:
1.236 raeburn 6289: sub defaults_javascript {
6290: my ($settings) = @_;
1.248 raeburn 6291: return unless (ref($settings) eq 'HASH');
1.236 raeburn 6292: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
6293: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
6294: if ($maxnum eq '') {
6295: $maxnum = 0;
6296: }
6297: $maxnum ++;
1.249 raeburn 6298: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 6299: return <<"ENDSCRIPT";
6300: <script type="text/javascript">
6301: // <![CDATA[
6302: function reorderTypes(form,caller) {
6303: var changedVal;
6304: $jstext
6305: var newpos = 'addinststatus_pos';
6306: var current = new Array;
6307: var maxh = $maxnum;
6308: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6309: var oldVal;
6310: if (caller == newpos) {
6311: changedVal = newitemVal;
6312: } else {
6313: var curritem = 'inststatus_pos_'+caller;
6314: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
6315: current[newitemVal] = newpos;
6316: }
6317: for (var i=0; i<inststatuses.length; i++) {
6318: if (inststatuses[i] != caller) {
6319: var elementName = 'inststatus_pos_'+inststatuses[i];
6320: if (form.elements[elementName]) {
6321: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6322: current[currVal] = elementName;
6323: }
6324: }
6325: }
6326: for (var j=0; j<maxh; j++) {
6327: if (current[j] == undefined) {
6328: oldVal = j;
6329: }
6330: }
6331: if (oldVal < changedVal) {
6332: for (var k=oldVal+1; k<=changedVal ; k++) {
6333: var elementName = current[k];
6334: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6335: }
6336: } else {
6337: for (var k=changedVal; k<oldVal; k++) {
6338: var elementName = current[k];
6339: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6340: }
6341: }
6342: return;
6343: }
6344:
6345: // ]]>
6346: </script>
6347:
6348: ENDSCRIPT
6349: }
6350: }
6351:
1.49 raeburn 6352: sub coursecategories_javascript {
6353: my ($settings) = @_;
1.57 raeburn 6354: my ($output,$jstext,$cathash);
1.49 raeburn 6355: if (ref($settings) eq 'HASH') {
1.57 raeburn 6356: $cathash = $settings->{'cats'};
6357: }
6358: if (ref($cathash) eq 'HASH') {
1.49 raeburn 6359: my (@cats,@jsarray,%idx);
1.57 raeburn 6360: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 6361: if (@jsarray > 0) {
6362: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
6363: for (my $i=0; $i<@jsarray; $i++) {
6364: if (ref($jsarray[$i]) eq 'ARRAY') {
6365: my $catstr = join('","',@{$jsarray[$i]});
6366: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
6367: }
6368: }
6369: }
6370: } else {
6371: $jstext = ' var categories = Array(1);'."\n".
6372: ' categories[0] = Array("instcode_pos");'."\n";
6373: }
1.237 bisitz 6374: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
6375: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 6376: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 6377: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
6378: &js_escape(\$instcode_reserved);
6379: &js_escape(\$communities_reserved);
1.272 raeburn 6380: &js_escape(\$placement_reserved);
1.265 damieng 6381: &js_escape(\$choose_again);
1.49 raeburn 6382: $output = <<"ENDSCRIPT";
6383: <script type="text/javascript">
1.109 raeburn 6384: // <![CDATA[
1.49 raeburn 6385: function reorderCats(form,parent,item,idx) {
6386: var changedVal;
6387: $jstext
6388: var newpos = 'addcategory_pos';
6389: if (parent == '') {
6390: var has_instcode = 0;
6391: var maxtop = categories[idx].length;
6392: for (var j=0; j<maxtop; j++) {
6393: if (categories[idx][j] == 'instcode::0') {
6394: has_instcode == 1;
6395: }
6396: }
6397: if (has_instcode == 0) {
6398: categories[idx][maxtop] = 'instcode_pos';
6399: }
6400: } else {
6401: newpos += '_'+parent;
6402: }
6403: var maxh = 1 + categories[idx].length;
6404: var current = new Array;
6405: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6406: if (item == newpos) {
6407: changedVal = newitemVal;
6408: } else {
6409: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
6410: current[newitemVal] = newpos;
6411: }
6412: for (var i=0; i<categories[idx].length; i++) {
6413: var elementName = categories[idx][i];
6414: if (elementName != item) {
6415: if (form.elements[elementName]) {
6416: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6417: current[currVal] = elementName;
6418: }
6419: }
6420: }
6421: var oldVal;
6422: for (var j=0; j<maxh; j++) {
6423: if (current[j] == undefined) {
6424: oldVal = j;
6425: }
6426: }
6427: if (oldVal < changedVal) {
6428: for (var k=oldVal+1; k<=changedVal ; k++) {
6429: var elementName = current[k];
6430: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6431: }
6432: } else {
6433: for (var k=changedVal; k<oldVal; k++) {
6434: var elementName = current[k];
6435: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6436: }
6437: }
6438: return;
6439: }
1.120 raeburn 6440:
6441: function categoryCheck(form) {
6442: if (form.elements['addcategory_name'].value == 'instcode') {
6443: alert('$instcode_reserved\\n$choose_again');
6444: return false;
6445: }
6446: if (form.elements['addcategory_name'].value == 'communities') {
6447: alert('$communities_reserved\\n$choose_again');
6448: return false;
6449: }
1.272 raeburn 6450: if (form.elements['addcategory_name'].value == 'placement') {
6451: alert('$placement_reserved\\n$choose_again');
6452: return false;
6453: }
1.120 raeburn 6454: return true;
6455: }
6456:
1.109 raeburn 6457: // ]]>
1.49 raeburn 6458: </script>
6459:
6460: ENDSCRIPT
6461: return $output;
6462: }
6463:
1.48 raeburn 6464: sub initialize_categories {
6465: my ($itemcount) = @_;
1.120 raeburn 6466: my ($datatable,$css_class,$chgstr);
6467: my %default_names = (
6468: instcode => 'Official courses (with institutional codes)',
6469: communities => 'Communities',
1.272 raeburn 6470: placement => 'Placement Tests',
1.120 raeburn 6471: );
6472: my $select0 = ' selected="selected"';
6473: my $select1 = '';
1.272 raeburn 6474: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 6475: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6476: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
1.272 raeburn 6477: if (($default eq 'communities') || ($default eq 'placement')) {
1.120 raeburn 6478: $select1 = $select0;
6479: $select0 = '';
6480: }
6481: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6482: .'<select name="'.$default.'_pos">'
6483: .'<option value="0"'.$select0.'>1</option>'
6484: .'<option value="1"'.$select1.'>2</option>'
6485: .'<option value="2">3</option></select> '
6486: .$default_names{$default}
6487: .'</span></td><td><span class="LC_nobreak">'
6488: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
6489: .&mt('Display').'</label> <label>'
6490: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 6491: .'</label></span></td></tr>';
1.120 raeburn 6492: $itemcount ++;
6493: }
1.48 raeburn 6494: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 6495: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 6496: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 6497: .'<select name="addcategory_pos"'.$chgstr.'>'
6498: .'<option value="0">1</option>'
6499: .'<option value="1">2</option>'
6500: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 6501: .&mt('Add category').'</td><td>'.&mt('Name:')
6502: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
6503: return $datatable;
6504: }
6505:
6506: sub build_category_rows {
1.49 raeburn 6507: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
6508: my ($text,$name,$item,$chgstr);
1.48 raeburn 6509: if (ref($cats) eq 'ARRAY') {
6510: my $maxdepth = scalar(@{$cats});
6511: if (ref($cats->[$depth]) eq 'HASH') {
6512: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
6513: my $numchildren = @{$cats->[$depth]{$parent}};
6514: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 6515: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 6516: my ($idxnum,$parent_name,$parent_item);
6517: my $higher = $depth - 1;
6518: if ($higher == 0) {
6519: $parent_name = &escape($parent).'::'.$higher;
6520: } else {
6521: if (ref($path) eq 'ARRAY') {
6522: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6523: }
6524: }
6525: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 6526: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 6527: if ($j < $numchildren) {
1.48 raeburn 6528: $name = $cats->[$depth]{$parent}[$j];
6529: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 6530: $idxnum = $idx->{$item};
6531: } else {
6532: $name = $parent_name;
6533: $item = $parent_item;
1.48 raeburn 6534: }
1.49 raeburn 6535: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
6536: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 6537: for (my $i=0; $i<=$numchildren; $i++) {
6538: my $vpos = $i+1;
6539: my $selstr;
6540: if ($j == $i) {
6541: $selstr = ' selected="selected" ';
6542: }
6543: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
6544: }
6545: $text .= '</select> ';
6546: if ($j < $numchildren) {
6547: my $deeper = $depth+1;
6548: $text .= $name.' '
6549: .'<label><input type="checkbox" name="deletecategory" value="'
6550: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
6551: if(ref($path) eq 'ARRAY') {
6552: push(@{$path},$name);
1.49 raeburn 6553: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 6554: pop(@{$path});
6555: }
6556: } else {
1.59 bisitz 6557: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 6558: if ($j == $numchildren) {
6559: $text .= $name;
6560: } else {
6561: $text .= $item;
6562: }
6563: $text .= '" value="" />';
6564: }
6565: $text .= '</td></tr>';
6566: }
6567: $text .= '</table></td>';
6568: } else {
6569: my $higher = $depth-1;
6570: if ($higher == 0) {
6571: $name = &escape($parent).'::'.$higher;
6572: } else {
6573: if (ref($path) eq 'ARRAY') {
6574: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6575: }
6576: }
6577: my $colspan;
6578: if ($parent ne 'instcode') {
6579: $colspan = $maxdepth - $depth - 1;
6580: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
6581: }
6582: }
6583: }
6584: }
6585: return $text;
6586: }
6587:
1.33 raeburn 6588: sub modifiable_userdata_row {
1.228 raeburn 6589: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
6590: my ($role,$rolename,$statustype);
6591: $role = $item;
1.224 raeburn 6592: if ($context eq 'cancreate') {
1.228 raeburn 6593: if ($item =~ /^emailusername_(.+)$/) {
6594: $statustype = $1;
6595: $role = 'emailusername';
6596: if (ref($usertypes) eq 'HASH') {
6597: if ($usertypes->{$statustype}) {
6598: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
6599: } else {
6600: $rolename = &mt('Data provided by user');
6601: }
6602: }
1.224 raeburn 6603: }
6604: } elsif ($context eq 'selfcreate') {
1.63 raeburn 6605: if (ref($usertypes) eq 'HASH') {
6606: $rolename = $usertypes->{$role};
6607: } else {
6608: $rolename = $role;
6609: }
1.33 raeburn 6610: } else {
1.63 raeburn 6611: if ($role eq 'cr') {
6612: $rolename = &mt('Custom role');
6613: } else {
6614: $rolename = &Apache::lonnet::plaintext($role);
6615: }
1.33 raeburn 6616: }
1.224 raeburn 6617: my (@fields,%fieldtitles);
6618: if (ref($fieldsref) eq 'ARRAY') {
6619: @fields = @{$fieldsref};
6620: } else {
6621: @fields = ('lastname','firstname','middlename','generation',
6622: 'permanentemail','id');
6623: }
6624: if ((ref($titlesref) eq 'HASH')) {
6625: %fieldtitles = %{$titlesref};
6626: } else {
6627: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6628: }
1.33 raeburn 6629: my $output;
6630: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6631: $output = '<tr '.$css_class.'>'.
6632: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
6633: '<td class="LC_left_item" colspan="2"><table>';
6634: my $rem;
6635: my %checks;
6636: if (ref($settings) eq 'HASH') {
6637: if (ref($settings->{$context}) eq 'HASH') {
6638: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 6639: my $hashref = $settings->{$context}->{$role};
6640: if ($role eq 'emailusername') {
6641: if ($statustype) {
6642: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
6643: $hashref = $settings->{$context}->{$role}->{$statustype};
6644: if (ref($hashref) eq 'HASH') {
6645: foreach my $field (@fields) {
6646: if ($hashref->{$field}) {
6647: $checks{$field} = $hashref->{$field};
6648: }
6649: }
6650: }
6651: }
6652: }
6653: } else {
6654: if (ref($hashref) eq 'HASH') {
6655: foreach my $field (@fields) {
6656: if ($hashref->{$field}) {
6657: $checks{$field} = ' checked="checked" ';
6658: }
6659: }
1.33 raeburn 6660: }
6661: }
6662: }
6663: }
6664: }
1.228 raeburn 6665:
1.33 raeburn 6666: for (my $i=0; $i<@fields; $i++) {
6667: my $rem = $i%($numinrow);
6668: if ($rem == 0) {
6669: if ($i > 0) {
6670: $output .= '</tr>';
6671: }
6672: $output .= '<tr>';
6673: }
6674: my $check = ' ';
1.228 raeburn 6675: unless ($role eq 'emailusername') {
6676: if (exists($checks{$fields[$i]})) {
6677: $check = $checks{$fields[$i]}
6678: } else {
6679: if ($role eq 'st') {
6680: if (ref($settings) ne 'HASH') {
6681: $check = ' checked="checked" ';
6682: }
1.33 raeburn 6683: }
6684: }
6685: }
6686: $output .= '<td class="LC_left_item">'.
1.228 raeburn 6687: '<span class="LC_nobreak">';
6688: if ($role eq 'emailusername') {
6689: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
6690: $checks{$fields[$i]} = 'omit';
6691: }
6692: foreach my $option ('required','optional','omit') {
6693: my $checked='';
6694: if ($checks{$fields[$i]} eq $option) {
6695: $checked='checked="checked" ';
6696: }
6697: $output .= '<label>'.
6698: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
6699: &mt($option).'</label>'.(' ' x2);
6700: }
6701: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
6702: } else {
6703: $output .= '<label>'.
6704: '<input type="checkbox" name="canmodify_'.$role.'" '.
6705: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
6706: '</label>';
6707: }
6708: $output .= '</span></td>';
1.33 raeburn 6709: $rem = @fields%($numinrow);
6710: }
6711: my $colsleft = $numinrow - $rem;
6712: if ($colsleft > 1 ) {
6713: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6714: ' </td>';
6715: } elsif ($colsleft == 1) {
6716: $output .= '<td class="LC_left_item"> </td>';
6717: }
6718: $output .= '</tr></table></td></tr>';
6719: return $output;
6720: }
1.28 raeburn 6721:
1.93 raeburn 6722: sub insttypes_row {
1.224 raeburn 6723: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 6724: my %lt = &Apache::lonlocal::texthash (
6725: cansearch => 'Users allowed to search',
6726: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 6727: lockablenames => 'User preference to lock name',
1.93 raeburn 6728: );
6729: my $showdom;
6730: if ($context eq 'cansearch') {
6731: $showdom = ' ('.$dom.')';
6732: }
1.165 raeburn 6733: my $class = 'LC_left_item';
6734: if ($context eq 'statustocreate') {
6735: $class = 'LC_right_item';
6736: }
1.224 raeburn 6737: my $css_class = ' class="LC_odd_row"';
6738: if ($rownum ne '') {
6739: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
6740: }
6741: my $output = '<tr'.$css_class.'>'.
6742: '<td>'.$lt{$context}.$showdom.
6743: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 6744: my $rem;
6745: if (ref($types) eq 'ARRAY') {
6746: for (my $i=0; $i<@{$types}; $i++) {
6747: if (defined($usertypes->{$types->[$i]})) {
6748: my $rem = $i%($numinrow);
6749: if ($rem == 0) {
6750: if ($i > 0) {
6751: $output .= '</tr>';
6752: }
6753: $output .= '<tr>';
1.23 raeburn 6754: }
1.26 raeburn 6755: my $check = ' ';
1.99 raeburn 6756: if (ref($settings) eq 'HASH') {
6757: if (ref($settings->{$context}) eq 'ARRAY') {
6758: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
6759: $check = ' checked="checked" ';
6760: }
6761: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6762: $check = ' checked="checked" ';
6763: }
1.23 raeburn 6764: }
1.26 raeburn 6765: $output .= '<td class="LC_left_item">'.
6766: '<span class="LC_nobreak"><label>'.
1.93 raeburn 6767: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 6768: 'value="'.$types->[$i].'"'.$check.'/>'.
6769: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 6770: }
6771: }
1.26 raeburn 6772: $rem = @{$types}%($numinrow);
1.23 raeburn 6773: }
6774: my $colsleft = $numinrow - $rem;
1.131 raeburn 6775: if (($rem == 0) && (@{$types} > 0)) {
6776: $output .= '<tr>';
6777: }
1.23 raeburn 6778: if ($colsleft > 1) {
1.25 raeburn 6779: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 6780: } else {
1.25 raeburn 6781: $output .= '<td class="LC_left_item">';
1.23 raeburn 6782: }
6783: my $defcheck = ' ';
1.99 raeburn 6784: if (ref($settings) eq 'HASH') {
6785: if (ref($settings->{$context}) eq 'ARRAY') {
6786: if (grep(/^default$/,@{$settings->{$context}})) {
6787: $defcheck = ' checked="checked" ';
6788: }
6789: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6790: $defcheck = ' checked="checked" ';
6791: }
1.23 raeburn 6792: }
1.25 raeburn 6793: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 6794: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 6795: 'value="default"'.$defcheck.'/>'.
6796: $othertitle.'</label></span></td>'.
6797: '</tr></table></td></tr>';
6798: return $output;
1.23 raeburn 6799: }
6800:
6801: sub sorted_searchtitles {
6802: my %searchtitles = &Apache::lonlocal::texthash(
6803: 'uname' => 'username',
6804: 'lastname' => 'last name',
6805: 'lastfirst' => 'last name, first name',
6806: );
6807: my @titleorder = ('uname','lastname','lastfirst');
6808: return (\%searchtitles,\@titleorder);
6809: }
6810:
1.25 raeburn 6811: sub sorted_searchtypes {
6812: my %srchtypes_desc = (
6813: exact => 'is exact match',
6814: contains => 'contains ..',
6815: begins => 'begins with ..',
6816: );
6817: my @srchtypeorder = ('exact','begins','contains');
6818: return (\%srchtypes_desc,\@srchtypeorder);
6819: }
6820:
1.3 raeburn 6821: sub usertype_update_row {
6822: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
6823: my $datatable;
6824: my $numinrow = 4;
6825: foreach my $type (@{$types}) {
6826: if (defined($usertypes->{$type})) {
6827: $$rownums ++;
6828: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
6829: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
6830: '</td><td class="LC_left_item"><table>';
6831: for (my $i=0; $i<@{$fields}; $i++) {
6832: my $rem = $i%($numinrow);
6833: if ($rem == 0) {
6834: if ($i > 0) {
6835: $datatable .= '</tr>';
6836: }
6837: $datatable .= '<tr>';
6838: }
6839: my $check = ' ';
1.39 raeburn 6840: if (ref($settings) eq 'HASH') {
6841: if (ref($settings->{'fields'}) eq 'HASH') {
6842: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
6843: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
6844: $check = ' checked="checked" ';
6845: }
1.3 raeburn 6846: }
6847: }
6848: }
6849:
6850: if ($i == @{$fields}-1) {
6851: my $colsleft = $numinrow - $rem;
6852: if ($colsleft > 1) {
6853: $datatable .= '<td colspan="'.$colsleft.'">';
6854: } else {
6855: $datatable .= '<td>';
6856: }
6857: } else {
6858: $datatable .= '<td>';
6859: }
1.8 raeburn 6860: $datatable .= '<span class="LC_nobreak"><label>'.
6861: '<input type="checkbox" name="updateable_'.$type.
6862: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
6863: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 6864: }
6865: $datatable .= '</tr></table></td></tr>';
6866: }
6867: }
6868: return $datatable;
1.1 raeburn 6869: }
6870:
6871: sub modify_login {
1.205 raeburn 6872: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 6873: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
6874: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
6875: %title = ( coursecatalog => 'Display course catalog',
6876: adminmail => 'Display administrator E-mail address',
1.188 raeburn 6877: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 6878: newuser => 'Link for visitors to create a user account',
6879: loginheader => 'Log-in box header');
6880: @offon = ('off','on');
1.112 raeburn 6881: if (ref($domconfig{login}) eq 'HASH') {
6882: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
6883: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
6884: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
6885: }
6886: }
6887: }
1.9 raeburn 6888: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
6889: \%domconfig,\%loginhash);
1.188 raeburn 6890: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6891: foreach my $item (@toggles) {
6892: $loginhash{login}{$item} = $env{'form.'.$item};
6893: }
1.41 raeburn 6894: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 6895: if (ref($colchanges{'login'}) eq 'HASH') {
6896: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
6897: \%loginhash);
6898: }
1.110 raeburn 6899:
1.149 raeburn 6900: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 6901: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 6902: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 6903: if (keys(%servers) > 1) {
6904: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 6905: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
6906: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
6907: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
6908: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
6909: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
6910: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6911: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6912: $changes{'loginvia'}{$lonhost} = 1;
6913: } else {
6914: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
6915: $changes{'loginvia'}{$lonhost} = 1;
6916: }
6917: } else {
6918: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6919: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6920: $changes{'loginvia'}{$lonhost} = 1;
6921: }
6922: }
6923: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
6924: foreach my $item (@loginvia_attribs) {
6925: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
6926: }
6927: } else {
6928: foreach my $item (@loginvia_attribs) {
6929: my $new = $env{'form.'.$lonhost.'_'.$item};
6930: if (($item eq 'serverpath') && ($new eq 'custom')) {
6931: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
6932: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6933: $new = '/';
6934: }
6935: }
6936: if (($item eq 'custompath') &&
6937: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6938: $new = '';
6939: }
6940: if ($new ne $curr_loginvia{$lonhost}{$item}) {
6941: $changes{'loginvia'}{$lonhost} = 1;
6942: }
6943: if ($item eq 'exempt') {
1.256 raeburn 6944: $new = &check_exempt_addresses($new);
1.128 raeburn 6945: }
6946: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6947: }
6948: }
1.112 raeburn 6949: } else {
1.128 raeburn 6950: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6951: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 6952: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 6953: foreach my $item (@loginvia_attribs) {
6954: my $new = $env{'form.'.$lonhost.'_'.$item};
6955: if (($item eq 'serverpath') && ($new eq 'custom')) {
6956: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6957: $new = '/';
6958: }
6959: }
6960: if (($item eq 'custompath') &&
6961: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6962: $new = '';
6963: }
6964: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6965: }
1.110 raeburn 6966: }
6967: }
6968: }
6969: }
1.119 raeburn 6970:
1.168 raeburn 6971: my $servadm = $r->dir_config('lonAdmEMail');
6972: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
6973: if (ref($domconfig{'login'}) eq 'HASH') {
6974: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
6975: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
6976: if ($lang eq 'nolang') {
6977: push(@currlangs,$lang);
6978: } elsif (defined($langchoices{$lang})) {
6979: push(@currlangs,$lang);
6980: } else {
6981: next;
6982: }
6983: }
6984: }
6985: }
6986: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
6987: if (@currlangs > 0) {
6988: foreach my $lang (@currlangs) {
6989: if (grep(/^\Q$lang\E$/,@delurls)) {
6990: $changes{'helpurl'}{$lang} = 1;
6991: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
6992: $changes{'helpurl'}{$lang} = 1;
6993: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
6994: push(@newlangs,$lang);
6995: } else {
6996: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6997: }
6998: }
6999: }
7000: unless (grep(/^nolang$/,@currlangs)) {
7001: if ($env{'form.loginhelpurl_nolang.filename'}) {
7002: $changes{'helpurl'}{'nolang'} = 1;
7003: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
7004: push(@newlangs,'nolang');
7005: }
7006: }
7007: if ($env{'form.loginhelpurl_add_lang'}) {
7008: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
7009: ($env{'form.loginhelpurl_add_file.filename'})) {
7010: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
7011: $addedfile = $env{'form.loginhelpurl_add_lang'};
7012: }
7013: }
7014: if ((@newlangs > 0) || ($addedfile)) {
7015: my $error;
7016: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7017: if ($configuserok eq 'ok') {
7018: if ($switchserver) {
7019: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
7020: } elsif ($author_ok eq 'ok') {
7021: my @allnew = @newlangs;
7022: if ($addedfile ne '') {
7023: push(@allnew,$addedfile);
7024: }
7025: foreach my $lang (@allnew) {
7026: my $formelem = 'loginhelpurl_'.$lang;
7027: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
7028: $formelem = 'loginhelpurl_add_file';
7029: }
7030: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7031: "help/$lang",'','',$newfile{$lang});
7032: if ($result eq 'ok') {
7033: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
7034: $changes{'helpurl'}{$lang} = 1;
7035: } else {
7036: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
7037: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 7038: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 7039: (!grep(/^\Q$lang\E$/,@delurls))) {
7040: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7041: }
7042: }
7043: }
7044: } else {
7045: $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);
7046: }
7047: } else {
7048: $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);
7049: }
7050: if ($error) {
7051: &Apache::lonnet::logthis($error);
7052: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7053: }
7054: }
1.256 raeburn 7055:
7056: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
7057: if (ref($domconfig{'login'}) eq 'HASH') {
7058: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
7059: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
7060: if ($domservers{$lonhost}) {
7061: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7062: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 7063: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 7064: }
7065: }
7066: }
7067: }
7068: }
7069: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
7070: foreach my $lonhost (sort(keys(%domservers))) {
7071: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7072: $changes{'headtag'}{$lonhost} = 1;
7073: } else {
7074: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
7075: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
7076: }
7077: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
7078: push(@newhosts,$lonhost);
7079: } elsif ($currheadtagurls{$lonhost}) {
7080: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
7081: if ($currexempt{$lonhost}) {
7082: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
7083: $changes{'headtag'}{$lonhost} = 1;
7084: }
7085: } elsif ($possexempt{$lonhost}) {
7086: $changes{'headtag'}{$lonhost} = 1;
7087: }
7088: if ($possexempt{$lonhost}) {
7089: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7090: }
7091: }
7092: }
7093: }
7094: if (@newhosts) {
7095: my $error;
7096: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7097: if ($configuserok eq 'ok') {
7098: if ($switchserver) {
7099: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
7100: } elsif ($author_ok eq 'ok') {
7101: foreach my $lonhost (@newhosts) {
7102: my $formelem = 'loginheadtag_'.$lonhost;
7103: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7104: "login/headtag/$lonhost",'','',
7105: $env{'form.loginheadtag_'.$lonhost.'.filename'});
7106: if ($result eq 'ok') {
7107: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
7108: $changes{'headtag'}{$lonhost} = 1;
7109: if ($possexempt{$lonhost}) {
7110: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7111: }
7112: } else {
7113: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
7114: $newheadtagurls{$lonhost},$result);
7115: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7116: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
7117: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
7118: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
7119: }
7120: }
7121: }
7122: } else {
7123: $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);
7124: }
7125: } else {
7126: $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);
7127: }
7128: if ($error) {
7129: &Apache::lonnet::logthis($error);
7130: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7131: }
7132: }
1.169 raeburn 7133: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 7134:
7135: my $defaulthelpfile = '/adm/loginproblems.html';
7136: my $defaulttext = &mt('Default in use');
7137:
1.1 raeburn 7138: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
7139: $dom);
7140: if ($putresult eq 'ok') {
1.188 raeburn 7141: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7142: my %defaultchecked = (
7143: 'coursecatalog' => 'on',
1.188 raeburn 7144: 'helpdesk' => 'on',
1.42 raeburn 7145: 'adminmail' => 'off',
1.43 raeburn 7146: 'newuser' => 'off',
1.42 raeburn 7147: );
1.55 raeburn 7148: if (ref($domconfig{'login'}) eq 'HASH') {
7149: foreach my $item (@toggles) {
7150: if ($defaultchecked{$item} eq 'on') {
7151: if (($domconfig{'login'}{$item} eq '0') &&
7152: ($env{'form.'.$item} eq '1')) {
7153: $changes{$item} = 1;
7154: } elsif (($domconfig{'login'}{$item} eq '' ||
7155: $domconfig{'login'}{$item} eq '1') &&
7156: ($env{'form.'.$item} eq '0')) {
7157: $changes{$item} = 1;
7158: }
7159: } elsif ($defaultchecked{$item} eq 'off') {
7160: if (($domconfig{'login'}{$item} eq '1') &&
7161: ($env{'form.'.$item} eq '0')) {
7162: $changes{$item} = 1;
7163: } elsif (($domconfig{'login'}{$item} eq '' ||
7164: $domconfig{'login'}{$item} eq '0') &&
7165: ($env{'form.'.$item} eq '1')) {
7166: $changes{$item} = 1;
7167: }
1.42 raeburn 7168: }
7169: }
1.41 raeburn 7170: }
1.6 raeburn 7171: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 7172: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7173: if (ref($lastactref) eq 'HASH') {
7174: $lastactref->{'domainconfig'} = 1;
7175: }
1.1 raeburn 7176: $resulttext = &mt('Changes made:').'<ul>';
7177: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 7178: if ($item eq 'loginvia') {
1.112 raeburn 7179: if (ref($changes{$item}) eq 'HASH') {
7180: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
7181: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 7182: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
7183: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
7184: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
7185: $protocol = 'http' if ($protocol ne 'https');
7186: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
7187:
7188: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
7189: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
7190: } else {
7191: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
7192: }
7193: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
7194: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
7195: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
7196: }
7197: $resulttext .= '</li>';
7198: } else {
7199: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
7200: }
1.112 raeburn 7201: } else {
1.128 raeburn 7202: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 7203: }
7204: }
1.128 raeburn 7205: $resulttext .= '</ul></li>';
1.112 raeburn 7206: }
1.168 raeburn 7207: } elsif ($item eq 'helpurl') {
7208: if (ref($changes{$item}) eq 'HASH') {
7209: foreach my $lang (sort(keys(%{$changes{$item}}))) {
7210: if (grep(/^\Q$lang\E$/,@delurls)) {
7211: my ($chg,$link);
7212: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
7213: if ($lang eq 'nolang') {
7214: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
7215: } else {
7216: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
7217: }
7218: $resulttext .= '<li>'.$chg.'</li>';
7219: } else {
7220: my $chg;
7221: if ($lang eq 'nolang') {
7222: $chg = &mt('custom log-in help file for no preferred language');
7223: } else {
7224: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
7225: }
7226: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
7227: $loginhash{'login'}{'helpurl'}{$lang}.
7228: '?inhibitmenu=yes',$chg,600,500).
7229: '</li>';
7230: }
7231: }
7232: }
1.256 raeburn 7233: } elsif ($item eq 'headtag') {
7234: if (ref($changes{$item}) eq 'HASH') {
7235: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
7236: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7237: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
7238: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7239: $resulttext .= '<li><a href="'.
7240: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
7241: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
7242: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
7243: if ($possexempt{$lonhost}) {
7244: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
7245: } else {
7246: $resulttext .= &mt('included for any client IP');
7247: }
7248: $resulttext .= '</li>';
7249: }
7250: }
7251: }
1.169 raeburn 7252: } elsif ($item eq 'captcha') {
7253: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 7254: my $chgtxt;
1.169 raeburn 7255: if ($loginhash{'login'}{$item} eq 'notused') {
7256: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
7257: } else {
7258: my %captchas = &captcha_phrases();
7259: if ($captchas{$loginhash{'login'}{$item}}) {
7260: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
7261: } else {
7262: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
7263: }
7264: }
7265: $resulttext .= '<li>'.$chgtxt.'</li>';
7266: }
7267: } elsif ($item eq 'recaptchakeys') {
7268: if (ref($loginhash{'login'}) eq 'HASH') {
7269: my ($privkey,$pubkey);
7270: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
7271: $pubkey = $loginhash{'login'}{$item}{'public'};
7272: $privkey = $loginhash{'login'}{$item}{'private'};
7273: }
7274: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
7275: if (!$pubkey) {
7276: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
7277: } else {
7278: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7279: }
7280: if (!$privkey) {
7281: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
7282: } else {
1.251 raeburn 7283: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 7284: }
7285: $chgtxt .= '</ul>';
7286: $resulttext .= '<li>'.$chgtxt.'</li>';
7287: }
1.269 raeburn 7288: } elsif ($item eq 'recaptchaversion') {
7289: if (ref($loginhash{'login'}) eq 'HASH') {
7290: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 7291: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 7292: '</li>';
7293: }
7294: }
1.41 raeburn 7295: } else {
7296: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7297: }
1.1 raeburn 7298: }
1.6 raeburn 7299: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 7300: } else {
7301: $resulttext = &mt('No changes made to log-in page settings');
7302: }
7303: } else {
1.11 albertel 7304: $resulttext = '<span class="LC_error">'.
7305: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7306: }
1.6 raeburn 7307: if ($errors) {
1.9 raeburn 7308: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 7309: $errors.'</ul>';
7310: }
7311: return $resulttext;
7312: }
7313:
1.256 raeburn 7314:
7315: sub check_exempt_addresses {
7316: my ($iplist) = @_;
7317: $iplist =~ s/^\s+//;
7318: $iplist =~ s/\s+$//;
7319: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
7320: my (@okips,$new);
7321: foreach my $ip (@poss_ips) {
7322: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
7323: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
7324: push(@okips,$ip);
7325: }
7326: }
7327: }
7328: if (@okips > 0) {
7329: $new = join(',',@okips);
7330: } else {
7331: $new = '';
7332: }
7333: return $new;
7334: }
7335:
1.6 raeburn 7336: sub color_font_choices {
7337: my %choices =
7338: &Apache::lonlocal::texthash (
7339: img => "Header",
7340: bgs => "Background colors",
7341: links => "Link colors",
1.55 raeburn 7342: images => "Images",
1.6 raeburn 7343: font => "Font color",
1.201 raeburn 7344: fontmenu => "Font menu",
1.76 raeburn 7345: pgbg => "Page",
1.6 raeburn 7346: tabbg => "Header",
7347: sidebg => "Border",
7348: link => "Link",
7349: alink => "Active link",
7350: vlink => "Visited link",
7351: );
7352: return %choices;
7353: }
7354:
7355: sub modify_rolecolors {
1.205 raeburn 7356: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 7357: my ($resulttext,%rolehash);
7358: $rolehash{'rolecolors'} = {};
1.55 raeburn 7359: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
7360: if ($domconfig{'rolecolors'} eq '') {
7361: $domconfig{'rolecolors'} = {};
7362: }
7363: }
1.9 raeburn 7364: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 7365: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
7366: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
7367: $dom);
7368: if ($putresult eq 'ok') {
7369: if (keys(%changes) > 0) {
1.41 raeburn 7370: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7371: if (ref($lastactref) eq 'HASH') {
7372: $lastactref->{'domainconfig'} = 1;
7373: }
1.6 raeburn 7374: $resulttext = &display_colorchgs($dom,\%changes,$roles,
7375: $rolehash{'rolecolors'});
7376: } else {
7377: $resulttext = &mt('No changes made to default color schemes');
7378: }
7379: } else {
1.11 albertel 7380: $resulttext = '<span class="LC_error">'.
7381: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 7382: }
7383: if ($errors) {
7384: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7385: $errors.'</ul>';
7386: }
7387: return $resulttext;
7388: }
7389:
7390: sub modify_colors {
1.9 raeburn 7391: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 7392: my (%changes,%choices);
1.51 raeburn 7393: my @bgs;
1.6 raeburn 7394: my @links = ('link','alink','vlink');
1.41 raeburn 7395: my @logintext;
1.6 raeburn 7396: my @images;
7397: my $servadm = $r->dir_config('lonAdmEMail');
7398: my $errors;
1.200 raeburn 7399: my %defaults;
1.6 raeburn 7400: foreach my $role (@{$roles}) {
7401: if ($role eq 'login') {
1.12 raeburn 7402: %choices = &login_choices();
1.41 raeburn 7403: @logintext = ('textcol','bgcol');
1.12 raeburn 7404: } else {
7405: %choices = &color_font_choices();
7406: }
7407: if ($role eq 'login') {
1.41 raeburn 7408: @images = ('img','logo','domlogo','login');
1.51 raeburn 7409: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 7410: } else {
7411: @images = ('img');
1.200 raeburn 7412: @bgs = ('pgbg','tabbg','sidebg');
7413: }
7414: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
7415: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
7416: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
7417: }
7418: if ($role eq 'login') {
7419: foreach my $item (@logintext) {
1.234 raeburn 7420: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7421: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7422: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7423: }
7424: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 7425: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7426: }
7427: }
7428: } else {
1.234 raeburn 7429: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
7430: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
7431: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
7432: }
7433: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 7434: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
7435: }
1.6 raeburn 7436: }
1.200 raeburn 7437: foreach my $item (@bgs) {
1.234 raeburn 7438: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7439: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7440: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7441: }
7442: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 7443: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7444: }
7445: }
7446: foreach my $item (@links) {
1.234 raeburn 7447: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7448: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7449: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7450: }
7451: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 7452: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7453: }
1.6 raeburn 7454: }
1.46 raeburn 7455: my ($configuserok,$author_ok,$switchserver) =
7456: &config_check($dom,$confname,$servadm);
1.9 raeburn 7457: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 7458: if (ref($domconfig->{$role}) ne 'HASH') {
7459: $domconfig->{$role} = {};
7460: }
1.8 raeburn 7461: foreach my $img (@images) {
1.70 raeburn 7462: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
7463: if (defined($env{'form.login_showlogo_'.$img})) {
7464: $confhash->{$role}{'showlogo'}{$img} = 1;
7465: } else {
7466: $confhash->{$role}{'showlogo'}{$img} = 0;
7467: }
7468: }
1.18 albertel 7469: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
7470: && !defined($domconfig->{$role}{$img})
7471: && !$env{'form.'.$role.'_del_'.$img}
7472: && $env{'form.'.$role.'_import_'.$img}) {
7473: # import the old configured image from the .tab setting
7474: # if they haven't provided a new one
7475: $domconfig->{$role}{$img} =
7476: $env{'form.'.$role.'_import_'.$img};
7477: }
1.6 raeburn 7478: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 7479: my $error;
1.6 raeburn 7480: if ($configuserok eq 'ok') {
1.9 raeburn 7481: if ($switchserver) {
1.12 raeburn 7482: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 7483: } else {
7484: if ($author_ok eq 'ok') {
7485: my ($result,$logourl) =
7486: &publishlogo($r,'upload',$role.'_'.$img,
7487: $dom,$confname,$img,$width,$height);
7488: if ($result eq 'ok') {
7489: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 7490: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7491: } else {
1.12 raeburn 7492: $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 7493: }
7494: } else {
1.46 raeburn 7495: $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 7496: }
7497: }
7498: } else {
1.46 raeburn 7499: $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 7500: }
7501: if ($error) {
1.8 raeburn 7502: &Apache::lonnet::logthis($error);
1.11 albertel 7503: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 7504: }
7505: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 7506: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
7507: my $error;
7508: if ($configuserok eq 'ok') {
7509: # is confname an author?
7510: if ($switchserver eq '') {
7511: if ($author_ok eq 'ok') {
7512: my ($result,$logourl) =
7513: &publishlogo($r,'copy',$domconfig->{$role}{$img},
7514: $dom,$confname,$img,$width,$height);
7515: if ($result eq 'ok') {
7516: $confhash->{$role}{$img} = $logourl;
1.18 albertel 7517: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7518: }
7519: }
7520: }
7521: }
1.6 raeburn 7522: }
7523: }
7524: }
7525: if (ref($domconfig) eq 'HASH') {
7526: if (ref($domconfig->{$role}) eq 'HASH') {
7527: foreach my $img (@images) {
7528: if ($domconfig->{$role}{$img} ne '') {
7529: if ($env{'form.'.$role.'_del_'.$img}) {
7530: $confhash->{$role}{$img} = '';
1.12 raeburn 7531: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7532: } else {
1.9 raeburn 7533: if ($confhash->{$role}{$img} eq '') {
7534: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
7535: }
1.6 raeburn 7536: }
7537: } else {
7538: if ($env{'form.'.$role.'_del_'.$img}) {
7539: $confhash->{$role}{$img} = '';
1.12 raeburn 7540: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7541: }
7542: }
1.70 raeburn 7543: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
7544: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
7545: if ($confhash->{$role}{'showlogo'}{$img} ne
7546: $domconfig->{$role}{'showlogo'}{$img}) {
7547: $changes{$role}{'showlogo'}{$img} = 1;
7548: }
7549: } else {
7550: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7551: $changes{$role}{'showlogo'}{$img} = 1;
7552: }
7553: }
7554: }
7555: }
1.6 raeburn 7556: if ($domconfig->{$role}{'font'} ne '') {
7557: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
7558: $changes{$role}{'font'} = 1;
7559: }
7560: } else {
7561: if ($confhash->{$role}{'font'}) {
7562: $changes{$role}{'font'} = 1;
7563: }
7564: }
1.107 raeburn 7565: if ($role ne 'login') {
7566: if ($domconfig->{$role}{'fontmenu'} ne '') {
7567: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
7568: $changes{$role}{'fontmenu'} = 1;
7569: }
7570: } else {
7571: if ($confhash->{$role}{'fontmenu'}) {
7572: $changes{$role}{'fontmenu'} = 1;
7573: }
1.97 tempelho 7574: }
7575: }
1.6 raeburn 7576: foreach my $item (@bgs) {
7577: if ($domconfig->{$role}{$item} ne '') {
7578: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7579: $changes{$role}{'bgs'}{$item} = 1;
7580: }
7581: } else {
7582: if ($confhash->{$role}{$item}) {
7583: $changes{$role}{'bgs'}{$item} = 1;
7584: }
7585: }
7586: }
7587: foreach my $item (@links) {
7588: if ($domconfig->{$role}{$item} ne '') {
7589: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7590: $changes{$role}{'links'}{$item} = 1;
7591: }
7592: } else {
7593: if ($confhash->{$role}{$item}) {
7594: $changes{$role}{'links'}{$item} = 1;
7595: }
7596: }
7597: }
1.41 raeburn 7598: foreach my $item (@logintext) {
7599: if ($domconfig->{$role}{$item} ne '') {
7600: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7601: $changes{$role}{'logintext'}{$item} = 1;
7602: }
7603: } else {
7604: if ($confhash->{$role}{$item}) {
7605: $changes{$role}{'logintext'}{$item} = 1;
7606: }
7607: }
7608: }
1.6 raeburn 7609: } else {
7610: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7611: \@logintext,$confhash,\%changes);
1.6 raeburn 7612: }
7613: } else {
7614: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7615: \@logintext,$confhash,\%changes);
1.6 raeburn 7616: }
7617: }
7618: return ($errors,%changes);
7619: }
7620:
1.46 raeburn 7621: sub config_check {
7622: my ($dom,$confname,$servadm) = @_;
7623: my ($configuserok,$author_ok,$switchserver,%currroles);
7624: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
7625: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
7626: $confname,$servadm);
7627: if ($configuserok eq 'ok') {
7628: $switchserver = &check_switchserver($dom,$confname);
7629: if ($switchserver eq '') {
7630: $author_ok = &check_authorstatus($dom,$confname,%currroles);
7631: }
7632: }
7633: return ($configuserok,$author_ok,$switchserver);
7634: }
7635:
1.6 raeburn 7636: sub default_change_checker {
1.41 raeburn 7637: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 7638: foreach my $item (@{$links}) {
7639: if ($confhash->{$role}{$item}) {
7640: $changes->{$role}{'links'}{$item} = 1;
7641: }
7642: }
7643: foreach my $item (@{$bgs}) {
7644: if ($confhash->{$role}{$item}) {
7645: $changes->{$role}{'bgs'}{$item} = 1;
7646: }
7647: }
1.41 raeburn 7648: foreach my $item (@{$logintext}) {
7649: if ($confhash->{$role}{$item}) {
7650: $changes->{$role}{'logintext'}{$item} = 1;
7651: }
7652: }
1.6 raeburn 7653: foreach my $img (@{$images}) {
7654: if ($env{'form.'.$role.'_del_'.$img}) {
7655: $confhash->{$role}{$img} = '';
1.12 raeburn 7656: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 7657: }
1.70 raeburn 7658: if ($role eq 'login') {
7659: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7660: $changes->{$role}{'showlogo'}{$img} = 1;
7661: }
7662: }
1.6 raeburn 7663: }
7664: if ($confhash->{$role}{'font'}) {
7665: $changes->{$role}{'font'} = 1;
7666: }
1.48 raeburn 7667: }
1.6 raeburn 7668:
7669: sub display_colorchgs {
7670: my ($dom,$changes,$roles,$confhash) = @_;
7671: my (%choices,$resulttext);
7672: if (!grep(/^login$/,@{$roles})) {
7673: $resulttext = &mt('Changes made:').'<br />';
7674: }
7675: foreach my $role (@{$roles}) {
7676: if ($role eq 'login') {
7677: %choices = &login_choices();
7678: } else {
7679: %choices = &color_font_choices();
7680: }
7681: if (ref($changes->{$role}) eq 'HASH') {
7682: if ($role ne 'login') {
7683: $resulttext .= '<h4>'.&mt($role).'</h4>';
7684: }
7685: foreach my $key (sort(keys(%{$changes->{$role}}))) {
7686: if ($role ne 'login') {
7687: $resulttext .= '<ul>';
7688: }
7689: if (ref($changes->{$role}{$key}) eq 'HASH') {
7690: if ($role ne 'login') {
7691: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
7692: }
7693: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 7694: if (($role eq 'login') && ($key eq 'showlogo')) {
7695: if ($confhash->{$role}{$key}{$item}) {
7696: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
7697: } else {
7698: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
7699: }
7700: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 7701: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
7702: } else {
1.12 raeburn 7703: my $newitem = $confhash->{$role}{$item};
7704: if ($key eq 'images') {
7705: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
7706: }
7707: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 7708: }
7709: }
7710: if ($role ne 'login') {
7711: $resulttext .= '</ul></li>';
7712: }
7713: } else {
7714: if ($confhash->{$role}{$key} eq '') {
7715: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
7716: } else {
7717: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
7718: }
7719: }
7720: if ($role ne 'login') {
7721: $resulttext .= '</ul>';
7722: }
7723: }
7724: }
7725: }
1.3 raeburn 7726: return $resulttext;
1.1 raeburn 7727: }
7728:
1.9 raeburn 7729: sub thumb_dimensions {
7730: return ('200','50');
7731: }
7732:
1.16 raeburn 7733: sub check_dimensions {
7734: my ($inputfile) = @_;
7735: my ($fullwidth,$fullheight);
7736: if ($inputfile =~ m|^[/\w.\-]+$|) {
7737: if (open(PIPE,"identify $inputfile 2>&1 |")) {
7738: my $imageinfo = <PIPE>;
7739: if (!close(PIPE)) {
7740: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
7741: }
7742: chomp($imageinfo);
7743: my ($fullsize) =
1.21 raeburn 7744: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 7745: if ($fullsize) {
7746: ($fullwidth,$fullheight) = split(/x/,$fullsize);
7747: }
7748: }
7749: }
7750: return ($fullwidth,$fullheight);
7751: }
7752:
1.9 raeburn 7753: sub check_configuser {
7754: my ($uhome,$dom,$confname,$servadm) = @_;
7755: my ($configuserok,%currroles);
7756: if ($uhome eq 'no_host') {
7757: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
7758: my $configpass = &LONCAPA::Enrollment::create_password();
7759: $configuserok =
7760: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
7761: $configpass,'','','','','',undef,$servadm);
7762: } else {
7763: $configuserok = 'ok';
7764: %currroles =
7765: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
7766: }
7767: return ($configuserok,%currroles);
7768: }
7769:
7770: sub check_authorstatus {
7771: my ($dom,$confname,%currroles) = @_;
7772: my $author_ok;
1.40 raeburn 7773: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 7774: my $start = time;
7775: my $end = 0;
7776: $author_ok =
7777: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 7778: 'au',$end,$start,'','','domconfig');
1.9 raeburn 7779: } else {
7780: $author_ok = 'ok';
7781: }
7782: return $author_ok;
7783: }
7784:
7785: sub publishlogo {
1.46 raeburn 7786: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 7787: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 7788: if ($action eq 'upload') {
7789: $fname=$env{'form.'.$formname.'.filename'};
7790: chop($env{'form.'.$formname});
7791: } else {
7792: ($fname) = ($formname =~ /([^\/]+)$/);
7793: }
1.46 raeburn 7794: if ($savefileas ne '') {
7795: $fname = $savefileas;
7796: }
1.9 raeburn 7797: $fname=&Apache::lonnet::clean_filename($fname);
7798: # See if there is anything left
7799: unless ($fname) { return ('error: no uploaded file'); }
7800: $fname="$subdir/$fname";
1.210 raeburn 7801: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 7802: my $filepath="$docroot/priv";
7803: my $relpath = "$dom/$confname";
1.9 raeburn 7804: my ($fnamepath,$file,$fetchthumb);
7805: $file=$fname;
7806: if ($fname=~m|/|) {
7807: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
7808: }
1.164 raeburn 7809: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 7810: my $count;
1.164 raeburn 7811: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 7812: $filepath.="/$parts[$count]";
7813: if ((-e $filepath)!=1) {
7814: mkdir($filepath,02770);
7815: }
7816: }
7817: # Check for bad extension and disallow upload
7818: if ($file=~/\.(\w+)$/ &&
7819: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7820: $output =
1.207 bisitz 7821: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 7822: } elsif ($file=~/\.(\w+)$/ &&
7823: !defined(&Apache::loncommon::fileembstyle($1))) {
7824: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7825: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 7826: $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 7827: } elsif (-d "$filepath/$file") {
1.195 bisitz 7828: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 7829: } else {
7830: my $source = $filepath.'/'.$file;
7831: my $logfile;
7832: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 7833: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 7834: }
7835: print $logfile
7836: "\n================= Publish ".localtime()." ================\n".
7837: $env{'user.name'}.':'.$env{'user.domain'}."\n";
7838: # Save the file
7839: if (!open(FH,'>'.$source)) {
7840: &Apache::lonnet::logthis('Failed to create '.$source);
7841: return (&mt('Failed to create file'));
7842: }
7843: if ($action eq 'upload') {
7844: if (!print FH ($env{'form.'.$formname})) {
7845: &Apache::lonnet::logthis('Failed to write to '.$source);
7846: return (&mt('Failed to write file'));
7847: }
7848: } else {
7849: my $original = &Apache::lonnet::filelocation('',$formname);
7850: if(!copy($original,$source)) {
7851: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
7852: return (&mt('Failed to write file'));
7853: }
7854: }
7855: close(FH);
7856: chmod(0660, $source); # Permissions to rw-rw---.
7857:
7858: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
7859: my $copyfile=$targetdir.'/'.$file;
7860:
7861: my @parts=split(/\//,$targetdir);
7862: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
7863: for (my $count=5;$count<=$#parts;$count++) {
7864: $path.="/$parts[$count]";
7865: if (!-e $path) {
7866: print $logfile "\nCreating directory ".$path;
7867: mkdir($path,02770);
7868: }
7869: }
7870: my $versionresult;
7871: if (-e $copyfile) {
7872: $versionresult = &logo_versioning($targetdir,$file,$logfile);
7873: } else {
7874: $versionresult = 'ok';
7875: }
7876: if ($versionresult eq 'ok') {
7877: if (copy($source,$copyfile)) {
7878: print $logfile "\nCopied original source to ".$copyfile."\n";
7879: $output = 'ok';
7880: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 7881: push(@{$modified_urls},[$copyfile,$source]);
7882: my $metaoutput =
7883: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
7884: unless ($registered_cleanup) {
7885: my $handlers = $r->get_handlers('PerlCleanupHandler');
7886: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7887: $registered_cleanup=1;
7888: }
1.9 raeburn 7889: } else {
7890: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
7891: $output = &mt('Failed to copy file to RES space').", $!";
7892: }
7893: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
7894: my $inputfile = $filepath.'/'.$file;
7895: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 7896: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
7897: if ($fullwidth ne '' && $fullheight ne '') {
7898: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
7899: my $thumbsize = $thumbwidth.'x'.$thumbheight;
7900: system("convert -sample $thumbsize $inputfile $outfile");
7901: chmod(0660, $filepath.'/tn-'.$file);
7902: if (-e $outfile) {
7903: my $copyfile=$targetdir.'/tn-'.$file;
7904: if (copy($outfile,$copyfile)) {
7905: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 7906: my $thumb_metaoutput =
7907: &write_metadata($dom,$confname,$formname,
7908: $targetdir,'tn-'.$file,$logfile);
7909: push(@{$modified_urls},[$copyfile,$outfile]);
7910: unless ($registered_cleanup) {
7911: my $handlers = $r->get_handlers('PerlCleanupHandler');
7912: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7913: $registered_cleanup=1;
7914: }
1.267 raeburn 7915: $madethumb = 1;
1.16 raeburn 7916: } else {
7917: print $logfile "\nUnable to write ".$copyfile.
7918: ':'.$!."\n";
7919: }
7920: }
1.9 raeburn 7921: }
7922: }
7923: }
7924: } else {
7925: $output = $versionresult;
7926: }
7927: }
1.267 raeburn 7928: return ($output,$logourl,$madethumb);
1.9 raeburn 7929: }
7930:
7931: sub logo_versioning {
7932: my ($targetdir,$file,$logfile) = @_;
7933: my $target = $targetdir.'/'.$file;
7934: my ($maxversion,$fn,$extn,$output);
7935: $maxversion = 0;
7936: if ($file =~ /^(.+)\.(\w+)$/) {
7937: $fn=$1;
7938: $extn=$2;
7939: }
7940: opendir(DIR,$targetdir);
7941: while (my $filename=readdir(DIR)) {
7942: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
7943: $maxversion=($1>$maxversion)?$1:$maxversion;
7944: }
7945: }
7946: $maxversion++;
7947: print $logfile "\nCreating old version ".$maxversion."\n";
7948: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
7949: if (copy($target,$copyfile)) {
7950: print $logfile "Copied old target to ".$copyfile."\n";
7951: $copyfile=$copyfile.'.meta';
7952: if (copy($target.'.meta',$copyfile)) {
7953: print $logfile "Copied old target metadata to ".$copyfile."\n";
7954: $output = 'ok';
7955: } else {
7956: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
7957: $output = &mt('Failed to copy old meta').", $!, ";
7958: }
7959: } else {
7960: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
7961: $output = &mt('Failed to copy old target').", $!, ";
7962: }
7963: return $output;
7964: }
7965:
7966: sub write_metadata {
7967: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
7968: my (%metadatafields,%metadatakeys,$output);
7969: $metadatafields{'title'}=$formname;
7970: $metadatafields{'creationdate'}=time;
7971: $metadatafields{'lastrevisiondate'}=time;
7972: $metadatafields{'copyright'}='public';
7973: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
7974: $env{'user.domain'};
7975: $metadatafields{'authorspace'}=$confname.':'.$dom;
7976: $metadatafields{'domain'}=$dom;
7977: {
7978: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
7979: my $mfh;
1.155 raeburn 7980: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 7981: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 7982: unless ($_=~/\./) {
7983: my $unikey=$_;
7984: $unikey=~/^([A-Za-z]+)/;
7985: my $tag=$1;
7986: $tag=~tr/A-Z/a-z/;
7987: print $mfh "\n\<$tag";
7988: foreach (split(/\,/,$metadatakeys{$unikey})) {
7989: my $value=$metadatafields{$unikey.'.'.$_};
7990: $value=~s/\"/\'\'/g;
7991: print $mfh ' '.$_.'="'.$value.'"';
7992: }
7993: print $mfh '>'.
7994: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
7995: .'</'.$tag.'>';
7996: }
7997: }
7998: $output = 'ok';
7999: print $logfile "\nWrote metadata";
8000: close($mfh);
8001: } else {
8002: print $logfile "\nFailed to open metadata file";
1.9 raeburn 8003: $output = &mt('Could not write metadata');
8004: }
8005: }
1.155 raeburn 8006: return $output;
8007: }
8008:
8009: sub notifysubscribed {
8010: foreach my $targetsource (@{$modified_urls}){
8011: next unless (ref($targetsource) eq 'ARRAY');
8012: my ($target,$source)=@{$targetsource};
8013: if ($source ne '') {
8014: if (open(my $logfh,'>>'.$source.'.log')) {
8015: print $logfh "\nCleanup phase: Notifications\n";
8016: my @subscribed=&subscribed_hosts($target);
8017: foreach my $subhost (@subscribed) {
8018: print $logfh "\nNotifying host ".$subhost.':';
8019: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
8020: print $logfh $reply;
8021: }
8022: my @subscribedmeta=&subscribed_hosts("$target.meta");
8023: foreach my $subhost (@subscribedmeta) {
8024: print $logfh "\nNotifying host for metadata only ".$subhost.':';
8025: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
8026: $subhost);
8027: print $logfh $reply;
8028: }
8029: print $logfh "\n============ Done ============\n";
1.160 raeburn 8030: close($logfh);
1.155 raeburn 8031: }
8032: }
8033: }
8034: return OK;
8035: }
8036:
8037: sub subscribed_hosts {
8038: my ($target) = @_;
8039: my @subscribed;
8040: if (open(my $fh,"<$target.subscription")) {
8041: while (my $subline=<$fh>) {
8042: if ($subline =~ /^($match_lonid):/) {
8043: my $host = $1;
8044: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
8045: unless (grep(/^\Q$host\E$/,@subscribed)) {
8046: push(@subscribed,$host);
8047: }
8048: }
8049: }
8050: }
8051: }
8052: return @subscribed;
1.9 raeburn 8053: }
8054:
8055: sub check_switchserver {
8056: my ($dom,$confname) = @_;
8057: my ($allowed,$switchserver);
8058: my $home = &Apache::lonnet::homeserver($confname,$dom);
8059: if ($home eq 'no_host') {
8060: $home = &Apache::lonnet::domain($dom,'primary');
8061: }
8062: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 8063: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
8064: if (!$allowed) {
1.180 raeburn 8065: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 8066: }
8067: return $switchserver;
8068: }
8069:
1.1 raeburn 8070: sub modify_quotas {
1.216 raeburn 8071: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 8072: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 8073: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 8074: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
8075: $validationfieldsref);
1.86 raeburn 8076: if ($action eq 'quotas') {
8077: $context = 'tools';
1.163 raeburn 8078: } else {
1.86 raeburn 8079: $context = $action;
8080: }
8081: if ($context eq 'requestcourses') {
1.271 raeburn 8082: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 8083: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 8084: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
8085: %titles = &courserequest_titles();
8086: $toolregexp = join('|',@usertools);
8087: %conditions = &courserequest_conditions();
1.216 raeburn 8088: $confname = $dom.'-domainconfig';
8089: my $servadm = $r->dir_config('lonAdmEMail');
8090: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 8091: ($validationitemsref,$validationnamesref,$validationfieldsref) =
8092: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 8093: } elsif ($context eq 'requestauthor') {
8094: @usertools = ('author');
8095: %titles = &authorrequest_titles();
1.86 raeburn 8096: } else {
1.162 raeburn 8097: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 8098: %titles = &tool_titles();
1.86 raeburn 8099: }
1.212 raeburn 8100: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 8101: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8102: foreach my $key (keys(%env)) {
1.101 raeburn 8103: if ($context eq 'requestcourses') {
8104: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
8105: my $item = $1;
8106: my $type = $2;
8107: if ($type =~ /^limit_(.+)/) {
8108: $limithash{$item}{$1} = $env{$key};
8109: } else {
8110: $confhash{$item}{$type} = $env{$key};
8111: }
8112: }
1.163 raeburn 8113: } elsif ($context eq 'requestauthor') {
8114: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
8115: $confhash{$1} = $env{$key};
8116: }
1.101 raeburn 8117: } else {
1.86 raeburn 8118: if ($key =~ /^form\.quota_(.+)$/) {
8119: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 8120: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
8121: $confhash{'authorquota'}{$1} = $env{$key};
8122: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 8123: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
8124: }
1.72 raeburn 8125: }
8126: }
1.163 raeburn 8127: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 8128: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 8129: @approvalnotify = sort(@approvalnotify);
8130: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.271 raeburn 8131: my @crstypes = ('official','unofficial','community','textbook','placement');
1.218 raeburn 8132: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
8133: foreach my $type (@hasuniquecode) {
8134: if (grep(/^\Q$type\E$/,@crstypes)) {
8135: $confhash{'uniquecode'}{$type} = 1;
8136: }
1.216 raeburn 8137: }
1.242 raeburn 8138: my (%newbook,%allpos);
1.216 raeburn 8139: if ($context eq 'requestcourses') {
1.242 raeburn 8140: foreach my $type ('textbooks','templates') {
8141: @{$allpos{$type}} = ();
8142: my $invalid;
8143: if ($type eq 'textbooks') {
8144: $invalid = &mt('Invalid LON-CAPA course for textbook');
8145: } else {
8146: $invalid = &mt('Invalid LON-CAPA course for template');
8147: }
8148: if ($env{'form.'.$type.'_addbook'}) {
8149: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
8150: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
8151: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
8152: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
8153: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
8154: } else {
8155: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
8156: my $position = $env{'form.'.$type.'_addbook_pos'};
8157: $position =~ s/\D+//g;
8158: if ($position ne '') {
8159: $allpos{$type}[$position] = $newbook{$type};
8160: }
1.216 raeburn 8161: }
1.242 raeburn 8162: } else {
8163: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 8164: }
8165: }
1.242 raeburn 8166: }
1.216 raeburn 8167: }
1.102 raeburn 8168: if (ref($domconfig{$action}) eq 'HASH') {
8169: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
8170: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
8171: $changes{'notify'}{'approval'} = 1;
8172: }
8173: } else {
1.144 raeburn 8174: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8175: $changes{'notify'}{'approval'} = 1;
8176: }
8177: }
1.218 raeburn 8178: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
8179: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8180: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
8181: unless ($confhash{'uniquecode'}{$crstype}) {
8182: $changes{'uniquecode'} = 1;
8183: }
8184: }
8185: unless ($changes{'uniquecode'}) {
8186: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
8187: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
8188: $changes{'uniquecode'} = 1;
8189: }
8190: }
8191: }
8192: } else {
8193: $changes{'uniquecode'} = 1;
8194: }
8195: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
8196: $changes{'uniquecode'} = 1;
1.216 raeburn 8197: }
8198: if ($context eq 'requestcourses') {
1.242 raeburn 8199: foreach my $type ('textbooks','templates') {
8200: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8201: my %deletions;
8202: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
8203: if (@todelete) {
8204: map { $deletions{$_} = 1; } @todelete;
8205: }
8206: my %imgdeletions;
8207: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
8208: if (@todeleteimages) {
8209: map { $imgdeletions{$_} = 1; } @todeleteimages;
8210: }
8211: my $maxnum = $env{'form.'.$type.'_maxnum'};
8212: for (my $i=0; $i<=$maxnum; $i++) {
8213: my $itemid = $env{'form.'.$type.'_id_'.$i};
8214: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
8215: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
8216: if ($deletions{$key}) {
8217: if ($domconfig{$action}{$type}{$key}{'image'}) {
8218: #FIXME need to obsolete item in RES space
8219: }
8220: next;
8221: } else {
8222: my $newpos = $env{'form.'.$itemid};
8223: $newpos =~ s/\D+//g;
1.243 raeburn 8224: foreach my $item ('subject','title','publisher','author') {
8225: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8226: ($type eq 'templates'));
1.242 raeburn 8227: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
8228: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
8229: $changes{$type}{$key} = 1;
8230: }
8231: }
8232: $allpos{$type}[$newpos] = $key;
8233: }
8234: if ($imgdeletions{$key}) {
8235: $changes{$type}{$key} = 1;
1.216 raeburn 8236: #FIXME need to obsolete item in RES space
1.242 raeburn 8237: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
8238: my ($cdom,$cnum) = split(/_/,$key);
8239: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
8240: $cdom,$cnum,$type,$configuserok,
8241: $switchserver,$author_ok);
8242: if ($imgurl) {
8243: $confhash{$type}{$key}{'image'} = $imgurl;
8244: $changes{$type}{$key} = 1;
1.216 raeburn 8245: }
1.242 raeburn 8246: if ($error) {
8247: &Apache::lonnet::logthis($error);
8248: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8249: }
8250: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
8251: $confhash{$type}{$key}{'image'} =
8252: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 8253: }
8254: }
8255: }
8256: }
8257: }
8258: }
1.102 raeburn 8259: } else {
1.144 raeburn 8260: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8261: $changes{'notify'}{'approval'} = 1;
8262: }
1.218 raeburn 8263: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 8264: $changes{'uniquecode'} = 1;
8265: }
8266: }
8267: if ($context eq 'requestcourses') {
1.242 raeburn 8268: foreach my $type ('textbooks','templates') {
8269: if ($newbook{$type}) {
8270: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 8271: foreach my $item ('subject','title','publisher','author') {
8272: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8273: ($type eq 'template'));
1.242 raeburn 8274: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
8275: if ($env{'form.'.$type.'_addbook_'.$item}) {
8276: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
8277: }
8278: }
8279: if ($type eq 'textbooks') {
8280: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
8281: my ($cdom,$cnum) = split(/_/,$newbook{$type});
8282: my ($imageurl,$error) =
8283: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
8284: $configuserok,$switchserver,$author_ok);
8285: if ($imageurl) {
8286: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
8287: }
8288: if ($error) {
8289: &Apache::lonnet::logthis($error);
8290: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8291: }
8292: }
1.216 raeburn 8293: }
8294: }
1.242 raeburn 8295: if (@{$allpos{$type}} > 0) {
8296: my $idx = 0;
8297: foreach my $item (@{$allpos{$type}}) {
8298: if ($item ne '') {
8299: $confhash{$type}{$item}{'order'} = $idx;
8300: if (ref($domconfig{$action}) eq 'HASH') {
8301: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8302: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
8303: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
8304: $changes{$type}{$item} = 1;
8305: }
1.216 raeburn 8306: }
8307: }
8308: }
1.242 raeburn 8309: $idx ++;
1.216 raeburn 8310: }
8311: }
8312: }
8313: }
1.235 raeburn 8314: if (ref($validationitemsref) eq 'ARRAY') {
8315: foreach my $item (@{$validationitemsref}) {
8316: if ($item eq 'fields') {
8317: my @changed;
8318: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
8319: if (@{$confhash{'validation'}{$item}} > 0) {
8320: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
8321: }
1.266 raeburn 8322: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8323: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8324: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
8325: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
8326: $domconfig{'requestcourses'}{'validation'}{$item});
8327: } else {
8328: @changed = @{$confhash{'validation'}{$item}};
8329: }
1.235 raeburn 8330: } else {
8331: @changed = @{$confhash{'validation'}{$item}};
8332: }
8333: } else {
8334: @changed = @{$confhash{'validation'}{$item}};
8335: }
8336: if (@changed) {
8337: if ($confhash{'validation'}{$item}) {
8338: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
8339: } else {
8340: $changes{'validation'}{$item} = &mt('None');
8341: }
8342: }
8343: } else {
8344: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
8345: if ($item eq 'markup') {
8346: if ($env{'form.requestcourses_validation_'.$item}) {
8347: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
8348: }
8349: }
1.266 raeburn 8350: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8351: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8352: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
8353: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8354: }
8355: } else {
8356: if ($confhash{'validation'}{$item} ne '') {
8357: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8358: }
1.235 raeburn 8359: }
8360: } else {
8361: if ($confhash{'validation'}{$item} ne '') {
8362: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8363: }
8364: }
8365: }
8366: }
8367: }
8368: if ($env{'form.validationdc'}) {
8369: my $newval = $env{'form.validationdc'};
8370: my %domcoords = &get_active_dcs($dom);
8371: if (exists($domcoords{$newval})) {
8372: $confhash{'validation'}{'dc'} = $newval;
8373: }
8374: }
8375: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 8376: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8377: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8378: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8379: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
8380: if ($confhash{'validation'}{'dc'} eq '') {
8381: $changes{'validation'}{'dc'} = &mt('None');
8382: } else {
8383: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8384: }
1.235 raeburn 8385: }
1.266 raeburn 8386: } elsif ($confhash{'validation'}{'dc'} ne '') {
8387: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 8388: }
8389: } elsif ($confhash{'validation'}{'dc'} ne '') {
8390: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8391: }
8392: } elsif ($confhash{'validation'}{'dc'} ne '') {
8393: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.266 raeburn 8394: }
8395: } else {
8396: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8397: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8398: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8399: $changes{'validation'}{'dc'} = &mt('None');
8400: }
8401: }
1.235 raeburn 8402: }
8403: }
1.102 raeburn 8404: }
8405: } else {
1.86 raeburn 8406: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 8407: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 8408: }
1.72 raeburn 8409: foreach my $item (@usertools) {
8410: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 8411: my $unset;
1.101 raeburn 8412: if ($context eq 'requestcourses') {
1.104 raeburn 8413: $unset = '0';
8414: if ($type eq '_LC_adv') {
8415: $unset = '';
8416: }
1.101 raeburn 8417: if ($confhash{$item}{$type} eq 'autolimit') {
8418: $confhash{$item}{$type} .= '=';
8419: unless ($limithash{$item}{$type} =~ /\D/) {
8420: $confhash{$item}{$type} .= $limithash{$item}{$type};
8421: }
8422: }
1.163 raeburn 8423: } elsif ($context eq 'requestauthor') {
8424: $unset = '0';
8425: if ($type eq '_LC_adv') {
8426: $unset = '';
8427: }
1.72 raeburn 8428: } else {
1.101 raeburn 8429: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
8430: $confhash{$item}{$type} = 1;
8431: } else {
8432: $confhash{$item}{$type} = 0;
8433: }
1.72 raeburn 8434: }
1.86 raeburn 8435: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 8436: if ($action eq 'requestauthor') {
8437: if ($domconfig{$action}{$type} ne $confhash{$type}) {
8438: $changes{$type} = 1;
8439: }
8440: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 8441: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
8442: $changes{$item}{$type} = 1;
8443: }
8444: } else {
8445: if ($context eq 'requestcourses') {
1.104 raeburn 8446: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 8447: $changes{$item}{$type} = 1;
8448: }
8449: } else {
8450: if (!$confhash{$item}{$type}) {
8451: $changes{$item}{$type} = 1;
8452: }
8453: }
8454: }
8455: } else {
8456: if ($context eq 'requestcourses') {
1.104 raeburn 8457: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 8458: $changes{$item}{$type} = 1;
8459: }
1.163 raeburn 8460: } elsif ($context eq 'requestauthor') {
8461: if ($confhash{$type} ne $unset) {
8462: $changes{$type} = 1;
8463: }
1.72 raeburn 8464: } else {
8465: if (!$confhash{$item}{$type}) {
8466: $changes{$item}{$type} = 1;
8467: }
8468: }
8469: }
1.1 raeburn 8470: }
8471: }
1.163 raeburn 8472: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 8473: if (ref($domconfig{'quotas'}) eq 'HASH') {
8474: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8475: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
8476: if (exists($confhash{'defaultquota'}{$key})) {
8477: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
8478: $changes{'defaultquota'}{$key} = 1;
8479: }
8480: } else {
8481: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 8482: }
8483: }
1.86 raeburn 8484: } else {
8485: foreach my $key (keys(%{$domconfig{'quotas'}})) {
8486: if (exists($confhash{'defaultquota'}{$key})) {
8487: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
8488: $changes{'defaultquota'}{$key} = 1;
8489: }
8490: } else {
8491: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 8492: }
1.1 raeburn 8493: }
8494: }
1.197 raeburn 8495: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8496: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
8497: if (exists($confhash{'authorquota'}{$key})) {
8498: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
8499: $changes{'authorquota'}{$key} = 1;
8500: }
8501: } else {
8502: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
8503: }
8504: }
8505: }
1.1 raeburn 8506: }
1.86 raeburn 8507: if (ref($confhash{'defaultquota'}) eq 'HASH') {
8508: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
8509: if (ref($domconfig{'quotas'}) eq 'HASH') {
8510: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8511: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
8512: $changes{'defaultquota'}{$key} = 1;
8513: }
8514: } else {
8515: if (!exists($domconfig{'quotas'}{$key})) {
8516: $changes{'defaultquota'}{$key} = 1;
8517: }
1.72 raeburn 8518: }
8519: } else {
1.86 raeburn 8520: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 8521: }
1.1 raeburn 8522: }
8523: }
1.197 raeburn 8524: if (ref($confhash{'authorquota'}) eq 'HASH') {
8525: foreach my $key (keys(%{$confhash{'authorquota'}})) {
8526: if (ref($domconfig{'quotas'}) eq 'HASH') {
8527: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8528: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
8529: $changes{'authorquota'}{$key} = 1;
8530: }
8531: } else {
8532: $changes{'authorquota'}{$key} = 1;
8533: }
8534: } else {
8535: $changes{'authorquota'}{$key} = 1;
8536: }
8537: }
8538: }
1.1 raeburn 8539: }
1.72 raeburn 8540:
1.163 raeburn 8541: if ($context eq 'requestauthor') {
8542: $domdefaults{'requestauthor'} = \%confhash;
8543: } else {
8544: foreach my $key (keys(%confhash)) {
1.242 raeburn 8545: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 8546: $domdefaults{$key} = $confhash{$key};
8547: }
1.163 raeburn 8548: }
1.72 raeburn 8549: }
1.163 raeburn 8550:
1.1 raeburn 8551: my %quotahash = (
1.86 raeburn 8552: $action => { %confhash }
1.1 raeburn 8553: );
8554: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
8555: $dom);
8556: if ($putresult eq 'ok') {
8557: if (keys(%changes) > 0) {
1.72 raeburn 8558: my $cachetime = 24*60*60;
8559: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 8560: if (ref($lastactref) eq 'HASH') {
8561: $lastactref->{'domdefaults'} = 1;
8562: }
1.1 raeburn 8563: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 8564: unless (($context eq 'requestcourses') ||
1.163 raeburn 8565: ($context eq 'requestauthor')) {
1.86 raeburn 8566: if (ref($changes{'defaultquota'}) eq 'HASH') {
8567: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
8568: foreach my $type (@{$types},'default') {
8569: if (defined($changes{'defaultquota'}{$type})) {
8570: my $typetitle = $usertypes->{$type};
8571: if ($type eq 'default') {
8572: $typetitle = $othertitle;
8573: }
1.213 raeburn 8574: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 8575: }
8576: }
1.86 raeburn 8577: $resulttext .= '</ul></li>';
1.72 raeburn 8578: }
1.197 raeburn 8579: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 8580: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 8581: foreach my $type (@{$types},'default') {
8582: if (defined($changes{'authorquota'}{$type})) {
8583: my $typetitle = $usertypes->{$type};
8584: if ($type eq 'default') {
8585: $typetitle = $othertitle;
8586: }
1.213 raeburn 8587: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 8588: }
8589: }
8590: $resulttext .= '</ul></li>';
8591: }
1.72 raeburn 8592: }
1.80 raeburn 8593: my %newenv;
1.72 raeburn 8594: foreach my $item (@usertools) {
1.163 raeburn 8595: my (%haschgs,%inconf);
8596: if ($context eq 'requestauthor') {
8597: %haschgs = %changes;
1.210 raeburn 8598: %inconf = %confhash;
1.163 raeburn 8599: } else {
8600: if (ref($changes{$item}) eq 'HASH') {
8601: %haschgs = %{$changes{$item}};
8602: }
8603: if (ref($confhash{$item}) eq 'HASH') {
8604: %inconf = %{$confhash{$item}};
8605: }
8606: }
8607: if (keys(%haschgs) > 0) {
1.80 raeburn 8608: my $newacc =
8609: &Apache::lonnet::usertools_access($env{'user.name'},
8610: $env{'user.domain'},
1.86 raeburn 8611: $item,'reload',$context);
1.210 raeburn 8612: if (($context eq 'requestcourses') ||
1.163 raeburn 8613: ($context eq 'requestauthor')) {
1.108 raeburn 8614: if ($env{'environment.canrequest.'.$item} ne $newacc) {
8615: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 8616: }
8617: } else {
8618: if ($env{'environment.availabletools.'.$item} ne $newacc) {
8619: $newenv{'environment.availabletools.'.$item} = $newacc;
8620: }
1.80 raeburn 8621: }
1.163 raeburn 8622: unless ($context eq 'requestauthor') {
8623: $resulttext .= '<li>'.$titles{$item}.'<ul>';
8624: }
1.72 raeburn 8625: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 8626: if ($haschgs{$type}) {
1.72 raeburn 8627: my $typetitle = $usertypes->{$type};
8628: if ($type eq 'default') {
8629: $typetitle = $othertitle;
8630: } elsif ($type eq '_LC_adv') {
8631: $typetitle = 'LON-CAPA Advanced Users';
8632: }
1.163 raeburn 8633: if ($inconf{$type}) {
1.101 raeburn 8634: if ($context eq 'requestcourses') {
8635: my $cond;
1.163 raeburn 8636: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 8637: if ($1 eq '') {
8638: $cond = &mt('(Automatic processing of any request).');
8639: } else {
8640: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
8641: }
8642: } else {
1.163 raeburn 8643: $cond = $conditions{$inconf{$type}};
1.101 raeburn 8644: }
8645: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 8646: } elsif ($context eq 'requestauthor') {
8647: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
8648: $titles{$inconf{$type}},$typetitle);
8649:
1.101 raeburn 8650: } else {
8651: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
8652: }
1.72 raeburn 8653: } else {
1.104 raeburn 8654: if ($type eq '_LC_adv') {
1.163 raeburn 8655: if ($inconf{$type} eq '0') {
1.104 raeburn 8656: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8657: } else {
8658: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
8659: }
8660: } else {
8661: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8662: }
1.72 raeburn 8663: }
8664: }
1.26 raeburn 8665: }
1.163 raeburn 8666: unless ($context eq 'requestauthor') {
8667: $resulttext .= '</ul></li>';
8668: }
1.26 raeburn 8669: }
1.1 raeburn 8670: }
1.163 raeburn 8671: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 8672: if (ref($changes{'notify'}) eq 'HASH') {
8673: if ($changes{'notify'}{'approval'}) {
8674: if (ref($confhash{'notify'}) eq 'HASH') {
8675: if ($confhash{'notify'}{'approval'}) {
8676: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
8677: } else {
1.163 raeburn 8678: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 8679: }
8680: }
8681: }
8682: }
8683: }
1.216 raeburn 8684: if ($action eq 'requestcourses') {
8685: my @offon = ('off','on');
8686: if ($changes{'uniquecode'}) {
1.218 raeburn 8687: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8688: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
8689: $resulttext .= '<li>'.
8690: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
8691: '</li>';
8692: } else {
8693: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
8694: '</li>';
8695: }
1.216 raeburn 8696: }
1.242 raeburn 8697: foreach my $type ('textbooks','templates') {
8698: if (ref($changes{$type}) eq 'HASH') {
8699: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
8700: foreach my $key (sort(keys(%{$changes{$type}}))) {
8701: my %coursehash = &Apache::lonnet::coursedescription($key);
8702: my $coursetitle = $coursehash{'description'};
8703: my $position = $confhash{$type}{$key}{'order'} + 1;
8704: $resulttext .= '<li>';
1.243 raeburn 8705: foreach my $item ('subject','title','publisher','author') {
8706: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8707: ($type eq 'templates'));
1.242 raeburn 8708: my $name = $item.':';
8709: $name =~ s/^(\w)/\U$1/;
8710: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
8711: }
8712: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
8713: if ($type eq 'textbooks') {
8714: if ($confhash{$type}{$key}{'image'}) {
8715: $resulttext .= ' '.&mt('Image: [_1]',
8716: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
8717: ' alt="Textbook cover" />').'<br />';
8718: }
8719: }
8720: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 8721: }
1.242 raeburn 8722: $resulttext .= '</ul></li>';
1.216 raeburn 8723: }
8724: }
1.235 raeburn 8725: if (ref($changes{'validation'}) eq 'HASH') {
8726: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
8727: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
8728: foreach my $item (@{$validationitemsref}) {
8729: if (exists($changes{'validation'}{$item})) {
8730: if ($item eq 'markup') {
8731: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8732: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
8733: } else {
8734: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8735: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
8736: }
8737: }
8738: }
8739: if (exists($changes{'validation'}{'dc'})) {
8740: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
8741: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
8742: }
8743: }
8744: }
1.216 raeburn 8745: }
1.1 raeburn 8746: $resulttext .= '</ul>';
1.80 raeburn 8747: if (keys(%newenv)) {
8748: &Apache::lonnet::appenv(\%newenv);
8749: }
1.1 raeburn 8750: } else {
1.86 raeburn 8751: if ($context eq 'requestcourses') {
8752: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 8753: } elsif ($context eq 'requestauthor') {
8754: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 8755: } else {
1.90 weissno 8756: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 8757: }
1.1 raeburn 8758: }
8759: } else {
1.11 albertel 8760: $resulttext = '<span class="LC_error">'.
8761: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8762: }
1.216 raeburn 8763: if ($errors) {
8764: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
8765: '<ul>'.$errors.'</ul></p>';
8766: }
1.3 raeburn 8767: return $resulttext;
1.1 raeburn 8768: }
8769:
1.216 raeburn 8770: sub process_textbook_image {
1.242 raeburn 8771: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 8772: my $filename = $env{'form.'.$caller.'.filename'};
8773: my ($error,$url);
8774: my ($width,$height) = (50,50);
8775: if ($configuserok eq 'ok') {
8776: if ($switchserver) {
8777: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
8778: $switchserver);
8779: } elsif ($author_ok eq 'ok') {
8780: my ($result,$imageurl) =
8781: &publishlogo($r,'upload',$caller,$dom,$confname,
1.242 raeburn 8782: "$type/$dom/$cnum/cover",$width,$height);
1.216 raeburn 8783: if ($result eq 'ok') {
8784: $url = $imageurl;
8785: } else {
8786: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
8787: }
8788: } else {
8789: $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);
8790: }
8791: } else {
8792: $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);
8793: }
8794: return ($url,$error);
8795: }
8796:
1.267 raeburn 8797: sub modify_ltitools {
8798: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
8799: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8800: my ($newid,@allpos,%changes,%confhash,$errors,$resulttext);
8801: my $confname = $dom.'-domainconfig';
8802: my $servadm = $r->dir_config('lonAdmEMail');
8803: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8804: my (%posslti,%possfield);
8805: my @courseroles = ('cc','in','ta','ep','st');
8806: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
8807: map { $posslti{$_} = 1; } @ltiroles;
8808: my @allfields = ('fullname','firstname','lastname','email','user','roles');
8809: map { $possfield{$_} = 1; } @allfields;
8810: my %lt = <itools_names();
8811: if ($env{'form.ltitools_add'}) {
8812: my $title = $env{'form.ltitools_add_title'};
8813: $title =~ s/(`)/'/g;
8814: ($newid,my $error) = &get_ltitools_id($dom,$title);
8815: if ($newid) {
8816: my $position = $env{'form.ltitools_add_pos'};
8817: $position =~ s/\D+//g;
8818: if ($position ne '') {
8819: $allpos[$position] = $newid;
8820: }
8821: $changes{$newid} = 1;
8822: foreach my $item ('title','url','key','secret') {
8823: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
8824: if ($env{'form.ltitools_add_'.$item}) {
8825: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
8826: }
8827: }
8828: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
8829: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
8830: }
8831: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
8832: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
8833: }
8834: foreach my $item ('width','height') {
8835: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
8836: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
8837: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
8838: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
8839: }
8840: }
8841: if ($env{'form.ltitools_add_target'} eq 'window') {
8842: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
8843: } else {
8844: $confhash{$newid}{'display'}{'target'} = 'iframe';
8845: }
8846: foreach my $item ('passback','roster') {
8847: if ($env{'form.ltitools_add_'.$item}) {
8848: $confhash{$newid}{$item} = 1;
8849: }
8850: }
8851: if ($env{'form.ltitools_add_image.filename'} ne '') {
8852: my ($imageurl,$error) =
8853: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$dom,
8854: $configuserok,$switchserver,$author_ok);
8855: if ($imageurl) {
8856: $confhash{$newid}{'image'} = $imageurl;
8857: }
8858: if ($error) {
8859: &Apache::lonnet::logthis($error);
8860: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8861: }
8862: }
8863: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
8864: foreach my $field (@fields) {
8865: if ($possfield{$field}) {
8866: if ($field eq 'roles') {
8867: foreach my $role (@courseroles) {
8868: my $choice = $env{'form.ltitools_add_roles_'.$role};
8869: if (($choice ne '') && ($posslti{$choice})) {
8870: $confhash{$newid}{'roles'}{$role} = $choice;
8871: if ($role eq 'cc') {
8872: $confhash{$newid}{'roles'}{'co'} = $choice;
8873: }
8874: }
8875: }
8876: } else {
8877: $confhash{$newid}{'fields'}{$field} = 1;
8878: }
8879: }
8880: }
1.273 raeburn 8881: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
8882: foreach my $item (@courseconfig) {
8883: $confhash{$newid}{'crsconf'}{$item} = 1;
8884: }
1.267 raeburn 8885: if ($env{'form.ltitools_add_custom'}) {
8886: my $name = $env{'form.ltitools_add_custom_name'};
8887: my $value = $env{'form.ltitools_add_custom_value'};
8888: $value =~ s/(`)/'/g;
8889: $name =~ s/(`)/'/g;
8890: $confhash{$newid}{'custom'}{$name} = $value;
8891: }
8892: } else {
8893: my $error = &mt('Failed to acquire unique ID for new external tool');
8894: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8895: }
8896: }
8897: if (ref($domconfig{$action}) eq 'HASH') {
8898: my %deletions;
8899: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
8900: if (@todelete) {
8901: map { $deletions{$_} = 1; } @todelete;
8902: }
8903: my %customadds;
8904: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
8905: if (@newcustom) {
8906: map { $customadds{$_} = 1; } @newcustom;
8907: }
8908: my %imgdeletions;
8909: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
8910: if (@todeleteimages) {
8911: map { $imgdeletions{$_} = 1; } @todeleteimages;
8912: }
8913: my $maxnum = $env{'form.ltitools_maxnum'};
8914: for (my $i=0; $i<=$maxnum; $i++) {
8915: my $itemid = $env{'form.ltitools_id_'.$i};
8916: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
8917: if ($deletions{$itemid}) {
8918: if ($domconfig{$action}{$itemid}{'image'}) {
8919: #FIXME need to obsolete item in RES space
8920: }
8921: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
8922: next;
8923: } else {
8924: my $newpos = $env{'form.ltitools_'.$itemid};
8925: $newpos =~ s/\D+//g;
8926: foreach my $item ('title','url','key','secret') {
8927: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
8928: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
8929: $changes{$itemid} = 1;
8930: }
8931: }
8932: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
8933: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
8934: }
8935: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
8936: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
8937: }
8938: foreach my $size ('width','height') {
8939: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
8940: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
8941: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
8942: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
8943: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
8944: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
8945: $changes{$itemid} = 1;
8946: }
8947: } else {
8948: $changes{$itemid} = 1;
8949: }
8950: }
8951: }
8952: if ($env{'form.ltitools_target_'.$i} eq 'window') {
8953: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
8954: } else {
8955: $confhash{$itemid}{'display'}{'target'} = 'iframe';
8956: }
8957: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
8958: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
8959: $changes{$itemid} = 1;
8960: }
8961: } else {
8962: $changes{$itemid} = 1;
8963: }
8964: foreach my $extra ('passback','roster') {
8965: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
8966: $confhash{$itemid}{$extra} = 1;
8967: }
8968: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
8969: $changes{$itemid} = 1;
8970: }
8971: }
1.273 raeburn 8972: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
8973: foreach my $item ('label','title','target') {
8974: if (grep(/^\Q$item\E$/,@courseconfig)) {
8975: $confhash{$itemid}{'crsconf'}{$item} = 1;
8976: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
8977: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
8978: $changes{$itemid} = 1;
8979: }
8980: } else {
8981: $changes{$itemid} = 1;
8982: }
8983: }
8984: }
1.267 raeburn 8985: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
8986: foreach my $field (@fields) {
8987: if ($possfield{$field}) {
8988: if ($field eq 'roles') {
8989: foreach my $role (@courseroles) {
8990: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
8991: if (($choice ne '') && ($posslti{$choice})) {
8992: $confhash{$itemid}{'roles'}{$role} = $choice;
8993: if ($role eq 'cc') {
8994: $confhash{$itemid}{'roles'}{'co'} = $choice;
8995: }
8996: }
8997: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
8998: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
8999: $changes{$itemid} = 1;
9000: }
9001: } elsif ($confhash{$itemid}{'roles'}{$role}) {
9002: $changes{$itemid} = 1;
9003: }
9004: }
9005: } else {
9006: $confhash{$itemid}{'fields'}{$field} = 1;
9007: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
9008: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
9009: $changes{$itemid} = 1;
9010: }
9011: } else {
9012: $changes{$itemid} = 1;
9013: }
9014: }
9015: }
9016: }
9017: $allpos[$newpos] = $itemid;
9018: }
9019: if ($imgdeletions{$itemid}) {
9020: $changes{$itemid} = 1;
9021: #FIXME need to obsolete item in RES space
9022: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
9023: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
9024: $itemid,$configuserok,$switchserver,
9025: $author_ok);
9026: if ($imgurl) {
9027: $confhash{$itemid}{'image'} = $imgurl;
9028: $changes{$itemid} = 1;
9029: }
9030: if ($error) {
9031: &Apache::lonnet::logthis($error);
9032: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9033: }
9034: } elsif ($domconfig{$action}{$itemid}{'image'}) {
9035: $confhash{$itemid}{'image'} =
9036: $domconfig{$action}{$itemid}{'image'};
9037: }
9038: if ($customadds{$i}) {
9039: my $name = $env{'form.ltitools_custom_name_'.$i};
9040: $name =~ s/(`)/'/g;
9041: $name =~ s/^\s+//;
9042: $name =~ s/\s+$//;
9043: my $value = $env{'form.ltitools_custom_value_'.$i};
9044: $value =~ s/(`)/'/g;
9045: $value =~ s/^\s+//;
9046: $value =~ s/\s+$//;
9047: if ($name ne '') {
9048: $confhash{$itemid}{'custom'}{$name} = $value;
9049: $changes{$itemid} = 1;
9050: }
9051: }
9052: my %customdels;
9053: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
9054: if (@customdeletions) {
9055: $changes{$itemid} = 1;
9056: }
9057: map { $customdels{$_} = 1; } @customdeletions;
9058: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
9059: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
9060: unless ($customdels{$key}) {
9061: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
9062: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
9063: }
9064: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
9065: $changes{$itemid} = 1;
9066: }
9067: }
9068: }
9069: }
9070: unless ($changes{$itemid}) {
9071: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
9072: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
9073: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
9074: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
9075: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
9076: $changes{$itemid} = 1;
9077: last;
9078: }
9079: }
9080: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
9081: $changes{$itemid} = 1;
9082: }
9083: }
9084: last if ($changes{$itemid});
9085: }
9086: }
9087: }
9088: }
9089: }
9090: if (@allpos > 0) {
9091: my $idx = 0;
9092: foreach my $itemid (@allpos) {
9093: if ($itemid ne '') {
9094: $confhash{$itemid}{'order'} = $idx;
9095: if (ref($domconfig{$action}) eq 'HASH') {
9096: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
9097: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
9098: $changes{$itemid} = 1;
9099: }
9100: }
9101: }
9102: $idx ++;
9103: }
9104: }
9105: }
9106: my %ltitoolshash = (
9107: $action => { %confhash }
9108: );
9109: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
9110: $dom);
9111: if ($putresult eq 'ok') {
9112: if (keys(%changes) > 0) {
9113: my $cachetime = 24*60*60;
9114: &Apache::lonnet::do_cache_new('ltitools',$dom,\%confhash,$cachetime);
9115: if (ref($lastactref) eq 'HASH') {
9116: $lastactref->{'ltitools'} = 1;
9117: }
9118: $resulttext = &mt('Changes made:').'<ul>';
9119: my %bynum;
9120: foreach my $itemid (sort(keys(%changes))) {
9121: my $position = $confhash{$itemid}{'order'};
9122: $bynum{$position} = $itemid;
9123: }
9124: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
9125: my $itemid = $bynum{$pos};
9126: if (ref($confhash{$itemid}) ne 'HASH') {
9127: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
9128: } else {
9129: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
9130: if ($confhash{$itemid}{'image'}) {
9131: $resulttext .= ' '.
9132: '<img src="'.$confhash{$itemid}{'image'}.'"'.
9133: ' alt="'.&mt('Tool Provider icon').'" />';
9134: }
9135: $resulttext .= '</li><ul>';
9136: my $position = $pos + 1;
9137: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
9138: foreach my $item ('version','msgtype','url','key') {
9139: if ($confhash{$itemid}{$item} ne '') {
9140: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
9141: }
9142: }
9143: if ($confhash{$itemid}{'secret'} ne '') {
9144: $resulttext .= '<li>'.$lt{'secret'}.': ';
9145: my $num = length($confhash{$itemid}{'secret'});
9146: $resulttext .= ('*'x$num).'</li>';
9147: }
1.273 raeburn 9148: $resulttext .= '<li>'.&mt('Configurable in course:');
9149: my @possconfig = ('label','title','target');
9150: my $numconfig = 0;
9151: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
9152: foreach my $item (@possconfig) {
9153: if ($confhash{$itemid}{'crsconf'}{$item}) {
9154: $numconfig ++;
9155: $resulttext .= ' '.$lt{'crs'.$item};
9156: }
9157: }
9158: }
9159: if (!$numconfig) {
9160: $resulttext .= &mt('None');
9161: }
9162: $resulttext .= '</li>';
1.267 raeburn 9163: foreach my $item ('passback','roster') {
9164: $resulttext .= '<li>'.$lt{$item}.' ';
9165: if ($confhash{$itemid}{$item}) {
9166: $resulttext .= &mt('Yes');
9167: } else {
9168: $resulttext .= &mt('No');
9169: }
9170: $resulttext .= '</li>';
9171: }
9172: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
9173: my $displaylist;
9174: if ($confhash{$itemid}{'display'}{'target'}) {
9175: $displaylist = &mt('Display target').': '.
9176: $confhash{$itemid}{'display'}{'target'}.',';
9177: }
9178: foreach my $size ('width','height') {
9179: if ($confhash{$itemid}{'display'}{$size}) {
9180: $displaylist .= (' 'x2).$lt{$size}.': '.
9181: $confhash{$itemid}{'display'}{$size}.',';
9182: }
9183: }
9184: if ($displaylist) {
9185: $displaylist =~ s/,$//;
9186: $resulttext .= '<li>'.$displaylist.'</li>';
9187: }
9188: }
9189: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
9190: my $fieldlist;
9191: foreach my $field (@allfields) {
9192: if ($confhash{$itemid}{'fields'}{$field}) {
9193: $fieldlist .= (' 'x2).$lt{$field}.',';
9194: }
9195: }
9196: if ($fieldlist) {
9197: $fieldlist =~ s/,$//;
9198: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
9199: }
9200: }
9201: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
9202: my $rolemaps;
9203: foreach my $role (@courseroles) {
9204: if ($confhash{$itemid}{'roles'}{$role}) {
9205: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
9206: $confhash{$itemid}{'roles'}{$role}.',';
9207: }
9208: }
9209: if ($rolemaps) {
9210: $rolemaps =~ s/,$//;
9211: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
9212: }
9213: }
9214: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
9215: my $customlist;
9216: if (keys(%{$confhash{$itemid}{'custom'}})) {
9217: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
9218: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
9219: }
9220: }
9221: if ($customlist) {
9222: $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
9223: }
9224: }
9225: $resulttext .= '</ul></li>';
9226: }
9227: }
9228: $resulttext .= '</ul>';
9229: } else {
9230: $resulttext = &mt('No changes made.');
9231: }
9232: } else {
9233: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
9234: }
9235: if ($errors) {
9236: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9237: $errors.'</ul>';
9238: }
9239: return $resulttext;
9240: }
9241:
9242: sub process_ltitools_image {
9243: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
9244: my $filename = $env{'form.'.$caller.'.filename'};
9245: my ($error,$url);
9246: my ($width,$height) = (21,21);
9247: if ($configuserok eq 'ok') {
9248: if ($switchserver) {
9249: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
9250: $switchserver);
9251: } elsif ($author_ok eq 'ok') {
9252: my ($result,$imageurl,$madethumb) =
9253: &publishlogo($r,'upload',$caller,$dom,$confname,
9254: "ltitools/$itemid/icon",$width,$height);
9255: if ($result eq 'ok') {
9256: if ($madethumb) {
9257: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
9258: my $imagethumb = "$path/tn-".$imagefile;
9259: $url = $imagethumb;
9260: } else {
9261: $url = $imageurl;
9262: }
9263: } else {
9264: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9265: }
9266: } else {
9267: $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);
9268: }
9269: } else {
9270: $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);
9271: }
9272: return ($url,$error);
9273: }
9274:
9275: sub get_ltitools_id {
9276: my ($cdom,$title) = @_;
9277: # get lock on ltitools db
9278: my $lockhash = {
9279: lock => $env{'user.name'}.
9280: ':'.$env{'user.domain'},
9281: };
9282: my $tries = 0;
9283: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
9284: my ($id,$error);
9285:
9286: while (($gotlock ne 'ok') && ($tries<10)) {
9287: $tries ++;
9288: sleep (0.1);
9289: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
9290: }
9291: if ($gotlock eq 'ok') {
9292: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
9293: if ($currids{'lock'}) {
9294: delete($currids{'lock'});
9295: if (keys(%currids)) {
9296: my @curr = sort { $a <=> $b } keys(%currids);
9297: if ($curr[-1] =~ /^\d+$/) {
9298: $id = 1 + $curr[-1];
9299: }
9300: } else {
9301: $id = 1;
9302: }
9303: if ($id) {
9304: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
9305: $error = 'nostore';
9306: }
9307: } else {
9308: $error = 'nonumber';
9309: }
9310: }
9311: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
9312: } else {
9313: $error = 'nolock';
9314: }
9315: return ($id,$error);
9316: }
9317:
1.3 raeburn 9318: sub modify_autoenroll {
1.205 raeburn 9319: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 9320: my ($resulttext,%changes);
9321: my %currautoenroll;
9322: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
9323: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
9324: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
9325: }
9326: }
9327: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
9328: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 9329: sender => 'Sender for notification messages',
1.274 raeburn 9330: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
9331: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 9332: my @offon = ('off','on');
1.17 raeburn 9333: my $sender_uname = $env{'form.sender_uname'};
9334: my $sender_domain = $env{'form.sender_domain'};
9335: if ($sender_domain eq '') {
9336: $sender_uname = '';
9337: } elsif ($sender_uname eq '') {
9338: $sender_domain = '';
9339: }
1.129 raeburn 9340: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 9341: my $failsafe = $env{'form.autoenroll_failsafe'};
9342: $failsafe =~ s{^\s+|\s+$}{}g;
9343: if ($failsafe =~ /\D/) {
9344: undef($failsafe);
9345: }
1.1 raeburn 9346: my %autoenrollhash = (
1.129 raeburn 9347: autoenroll => { 'run' => $env{'form.autoenroll_run'},
9348: 'sender_uname' => $sender_uname,
9349: 'sender_domain' => $sender_domain,
9350: 'co-owners' => $coowners,
1.274 raeburn 9351: 'autofailsafe' => $failsafe,
1.1 raeburn 9352: }
9353: );
1.4 raeburn 9354: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
9355: $dom);
1.1 raeburn 9356: if ($putresult eq 'ok') {
9357: if (exists($currautoenroll{'run'})) {
9358: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
9359: $changes{'run'} = 1;
9360: }
9361: } elsif ($autorun) {
9362: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 9363: $changes{'run'} = 1;
1.1 raeburn 9364: }
9365: }
1.17 raeburn 9366: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 9367: $changes{'sender'} = 1;
9368: }
1.17 raeburn 9369: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 9370: $changes{'sender'} = 1;
9371: }
1.129 raeburn 9372: if ($currautoenroll{'co-owners'} ne '') {
9373: if ($currautoenroll{'co-owners'} ne $coowners) {
9374: $changes{'coowners'} = 1;
9375: }
9376: } elsif ($coowners) {
9377: $changes{'coowners'} = 1;
1.274 raeburn 9378: }
9379: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
9380: $changes{'autofailsafe'} = 1;
9381: }
1.1 raeburn 9382: if (keys(%changes) > 0) {
9383: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 9384: if ($changes{'run'}) {
1.1 raeburn 9385: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
9386: }
9387: if ($changes{'sender'}) {
1.17 raeburn 9388: if ($sender_uname eq '' || $sender_domain eq '') {
9389: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
9390: } else {
9391: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
9392: }
1.1 raeburn 9393: }
1.129 raeburn 9394: if ($changes{'coowners'}) {
9395: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
9396: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9397: if (ref($lastactref) eq 'HASH') {
9398: $lastactref->{'domainconfig'} = 1;
9399: }
1.129 raeburn 9400: }
1.274 raeburn 9401: if ($changes{'autofailsafe'}) {
9402: if ($failsafe ne '') {
9403: $resulttext .= '<li>'.&mt("$title{'failsafe'} set to [_1]",$failsafe).'</li>';
9404: } else {
9405: $resulttext .= '<li>'.&mt("$title{'failsafe'} deleted");
9406: }
9407: &Apache::lonnet::get_domain_defaults($dom,1);
9408: if (ref($lastactref) eq 'HASH') {
9409: $lastactref->{'domdefaults'} = 1;
9410: }
9411: }
1.1 raeburn 9412: $resulttext .= '</ul>';
9413: } else {
9414: $resulttext = &mt('No changes made to auto-enrollment settings');
9415: }
9416: } else {
1.11 albertel 9417: $resulttext = '<span class="LC_error">'.
9418: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9419: }
1.3 raeburn 9420: return $resulttext;
1.1 raeburn 9421: }
9422:
9423: sub modify_autoupdate {
1.3 raeburn 9424: my ($dom,%domconfig) = @_;
1.1 raeburn 9425: my ($resulttext,%currautoupdate,%fields,%changes);
9426: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
9427: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
9428: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
9429: }
9430: }
9431: my @offon = ('off','on');
9432: my %title = &Apache::lonlocal::texthash (
9433: run => 'Auto-update:',
9434: classlists => 'Updates to user information in classlists?'
9435: );
1.44 raeburn 9436: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 9437: my %fieldtitles = &Apache::lonlocal::texthash (
9438: id => 'Student/Employee ID',
1.20 raeburn 9439: permanentemail => 'E-mail address',
1.1 raeburn 9440: lastname => 'Last Name',
9441: firstname => 'First Name',
9442: middlename => 'Middle Name',
1.132 raeburn 9443: generation => 'Generation',
1.1 raeburn 9444: );
1.142 raeburn 9445: $othertitle = &mt('All users');
1.1 raeburn 9446: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 9447: $othertitle = &mt('Other users');
1.1 raeburn 9448: }
9449: foreach my $key (keys(%env)) {
9450: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 9451: my ($usertype,$item) = ($1,$2);
9452: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
9453: if ($usertype eq 'default') {
9454: push(@{$fields{$1}},$2);
9455: } elsif (ref($types) eq 'ARRAY') {
9456: if (grep(/^\Q$usertype\E$/,@{$types})) {
9457: push(@{$fields{$1}},$2);
9458: }
9459: }
9460: }
1.1 raeburn 9461: }
9462: }
1.131 raeburn 9463: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
9464: @lockablenames = sort(@lockablenames);
9465: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
9466: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9467: if (@changed) {
9468: $changes{'lockablenames'} = 1;
9469: }
9470: } else {
9471: if (@lockablenames) {
9472: $changes{'lockablenames'} = 1;
9473: }
9474: }
1.1 raeburn 9475: my %updatehash = (
9476: autoupdate => { run => $env{'form.autoupdate_run'},
9477: classlists => $env{'form.classlists'},
9478: fields => {%fields},
1.131 raeburn 9479: lockablenames => \@lockablenames,
1.1 raeburn 9480: }
9481: );
9482: foreach my $key (keys(%currautoupdate)) {
9483: if (($key eq 'run') || ($key eq 'classlists')) {
9484: if (exists($updatehash{autoupdate}{$key})) {
9485: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
9486: $changes{$key} = 1;
9487: }
9488: }
9489: } elsif ($key eq 'fields') {
9490: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 9491: foreach my $item (@{$types},'default') {
1.1 raeburn 9492: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
9493: my $change = 0;
9494: foreach my $type (@{$currautoupdate{$key}{$item}}) {
9495: if (!exists($fields{$item})) {
9496: $change = 1;
1.132 raeburn 9497: last;
1.1 raeburn 9498: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 9499: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 9500: $change = 1;
1.132 raeburn 9501: last;
1.1 raeburn 9502: }
9503: }
9504: }
9505: if ($change) {
9506: push(@{$changes{$key}},$item);
9507: }
1.26 raeburn 9508: }
1.1 raeburn 9509: }
9510: }
1.131 raeburn 9511: } elsif ($key eq 'lockablenames') {
9512: if (ref($currautoupdate{$key}) eq 'ARRAY') {
9513: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9514: if (@changed) {
9515: $changes{'lockablenames'} = 1;
9516: }
9517: } else {
9518: if (@lockablenames) {
9519: $changes{'lockablenames'} = 1;
9520: }
9521: }
9522: }
9523: }
9524: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
9525: if (@lockablenames) {
9526: $changes{'lockablenames'} = 1;
1.1 raeburn 9527: }
9528: }
1.26 raeburn 9529: foreach my $item (@{$types},'default') {
9530: if (defined($fields{$item})) {
9531: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 9532: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
9533: my $change = 0;
9534: if (ref($fields{$item}) eq 'ARRAY') {
9535: foreach my $type (@{$fields{$item}}) {
9536: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
9537: $change = 1;
9538: last;
9539: }
9540: }
9541: }
9542: if ($change) {
9543: push(@{$changes{'fields'}},$item);
9544: }
9545: } else {
1.26 raeburn 9546: push(@{$changes{'fields'}},$item);
9547: }
9548: } else {
9549: push(@{$changes{'fields'}},$item);
1.1 raeburn 9550: }
9551: }
9552: }
9553: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
9554: $dom);
9555: if ($putresult eq 'ok') {
9556: if (keys(%changes) > 0) {
9557: $resulttext = &mt('Changes made:').'<ul>';
9558: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 9559: if ($key eq 'lockablenames') {
9560: $resulttext .= '<li>';
9561: if (@lockablenames) {
9562: $usertypes->{'default'} = $othertitle;
9563: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
9564: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
9565: } else {
9566: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
9567: }
9568: $resulttext .= '</li>';
9569: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 9570: foreach my $item (@{$changes{$key}}) {
9571: my @newvalues;
9572: foreach my $type (@{$fields{$item}}) {
9573: push(@newvalues,$fieldtitles{$type});
9574: }
1.3 raeburn 9575: my $newvaluestr;
9576: if (@newvalues > 0) {
9577: $newvaluestr = join(', ',@newvalues);
9578: } else {
9579: $newvaluestr = &mt('none');
1.6 raeburn 9580: }
1.1 raeburn 9581: if ($item eq 'default') {
1.26 raeburn 9582: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 9583: } else {
1.26 raeburn 9584: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 9585: }
9586: }
9587: } else {
9588: my $newvalue;
9589: if ($key eq 'run') {
9590: $newvalue = $offon[$env{'form.autoupdate_run'}];
9591: } else {
9592: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 9593: }
1.1 raeburn 9594: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
9595: }
9596: }
9597: $resulttext .= '</ul>';
9598: } else {
1.3 raeburn 9599: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 9600: }
9601: } else {
1.11 albertel 9602: $resulttext = '<span class="LC_error">'.
9603: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9604: }
1.3 raeburn 9605: return $resulttext;
1.1 raeburn 9606: }
9607:
1.125 raeburn 9608: sub modify_autocreate {
9609: my ($dom,%domconfig) = @_;
9610: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
9611: if (ref($domconfig{'autocreate'}) eq 'HASH') {
9612: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
9613: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
9614: }
9615: }
9616: my %title= ( xml => 'Auto-creation of courses in XML course description files',
9617: req => 'Auto-creation of validated requests for official courses',
9618: xmldc => 'Identity of course creator of courses from XML files',
9619: );
9620: my @types = ('xml','req');
9621: foreach my $item (@types) {
9622: $newvals{$item} = $env{'form.autocreate_'.$item};
9623: $newvals{$item} =~ s/\D//g;
9624: $newvals{$item} = 0 if ($newvals{$item} eq '');
9625: }
9626: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
9627: my %domcoords = &get_active_dcs($dom);
9628: unless (exists($domcoords{$newvals{'xmldc'}})) {
9629: $newvals{'xmldc'} = '';
9630: }
9631: %autocreatehash = (
9632: autocreate => { xml => $newvals{'xml'},
9633: req => $newvals{'req'},
9634: }
9635: );
9636: if ($newvals{'xmldc'} ne '') {
9637: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
9638: }
9639: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
9640: $dom);
9641: if ($putresult eq 'ok') {
9642: my @items = @types;
9643: if ($newvals{'xml'}) {
9644: push(@items,'xmldc');
9645: }
9646: foreach my $item (@items) {
9647: if (exists($currautocreate{$item})) {
9648: if ($currautocreate{$item} ne $newvals{$item}) {
9649: $changes{$item} = 1;
9650: }
9651: } elsif ($newvals{$item}) {
9652: $changes{$item} = 1;
9653: }
9654: }
9655: if (keys(%changes) > 0) {
9656: my @offon = ('off','on');
9657: $resulttext = &mt('Changes made:').'<ul>';
9658: foreach my $item (@types) {
9659: if ($changes{$item}) {
9660: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 9661: $resulttext .= '<li>'.
9662: &mt("$title{$item} set to [_1]$newtxt [_2]",
9663: '<b>','</b>').
9664: '</li>';
1.125 raeburn 9665: }
9666: }
9667: if ($changes{'xmldc'}) {
9668: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
9669: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 9670: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 9671: }
9672: $resulttext .= '</ul>';
9673: } else {
9674: $resulttext = &mt('No changes made to auto-creation settings');
9675: }
9676: } else {
9677: $resulttext = '<span class="LC_error">'.
9678: &mt('An error occurred: [_1]',$putresult).'</span>';
9679: }
9680: return $resulttext;
9681: }
9682:
1.23 raeburn 9683: sub modify_directorysrch {
9684: my ($dom,%domconfig) = @_;
9685: my ($resulttext,%changes);
9686: my %currdirsrch;
9687: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
9688: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
9689: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
9690: }
9691: }
1.277 raeburn 9692: my %title = ( available => 'Institutional directory search available',
9693: localonly => 'Other domains can search institution',
9694: lcavailable => 'LON-CAPA directory search available',
9695: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 9696: searchby => 'Search types',
9697: searchtypes => 'Search latitude');
9698: my @offon = ('off','on');
1.24 raeburn 9699: my @otherdoms = ('Yes','No');
1.23 raeburn 9700:
1.25 raeburn 9701: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 9702: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
9703: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
9704:
1.44 raeburn 9705: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 9706: if (keys(%{$usertypes}) == 0) {
9707: @cansearch = ('default');
9708: } else {
9709: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
9710: foreach my $type (@{$currdirsrch{'cansearch'}}) {
9711: if (!grep(/^\Q$type\E$/,@cansearch)) {
9712: push(@{$changes{'cansearch'}},$type);
9713: }
1.23 raeburn 9714: }
1.26 raeburn 9715: foreach my $type (@cansearch) {
9716: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
9717: push(@{$changes{'cansearch'}},$type);
9718: }
1.23 raeburn 9719: }
1.26 raeburn 9720: } else {
9721: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 9722: }
9723: }
9724:
9725: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
9726: foreach my $by (@{$currdirsrch{'searchby'}}) {
9727: if (!grep(/^\Q$by\E$/,@searchby)) {
9728: push(@{$changes{'searchby'}},$by);
9729: }
9730: }
9731: foreach my $by (@searchby) {
9732: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
9733: push(@{$changes{'searchby'}},$by);
9734: }
9735: }
9736: } else {
9737: push(@{$changes{'searchby'}},@searchby);
9738: }
1.25 raeburn 9739:
9740: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
9741: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
9742: if (!grep(/^\Q$type\E$/,@searchtypes)) {
9743: push(@{$changes{'searchtypes'}},$type);
9744: }
9745: }
9746: foreach my $type (@searchtypes) {
9747: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
9748: push(@{$changes{'searchtypes'}},$type);
9749: }
9750: }
9751: } else {
9752: if (exists($currdirsrch{'searchtypes'})) {
9753: foreach my $type (@searchtypes) {
9754: if ($type ne $currdirsrch{'searchtypes'}) {
9755: push(@{$changes{'searchtypes'}},$type);
9756: }
9757: }
9758: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
9759: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
9760: }
9761: } else {
9762: push(@{$changes{'searchtypes'}},@searchtypes);
9763: }
9764: }
9765:
1.23 raeburn 9766: my %dirsrch_hash = (
9767: directorysrch => { available => $env{'form.dirsrch_available'},
9768: cansearch => \@cansearch,
1.277 raeburn 9769: localonly => $env{'form.dirsrch_instlocalonly'},
9770: lclocalonly => $env{'form.dirsrch_domlocalonly'},
9771: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 9772: searchby => \@searchby,
1.25 raeburn 9773: searchtypes => \@searchtypes,
1.23 raeburn 9774: }
9775: );
9776: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
9777: $dom);
9778: if ($putresult eq 'ok') {
9779: if (exists($currdirsrch{'available'})) {
9780: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
9781: $changes{'available'} = 1;
9782: }
9783: } else {
9784: if ($env{'form.dirsrch_available'} eq '1') {
9785: $changes{'available'} = 1;
9786: }
9787: }
1.277 raeburn 9788: if (exists($currdirsrch{'lcavailable'})) {
9789: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
9790: $changes{'lcavailable'} = 1;
9791: }
9792: } else {
9793: if ($env{'form.dirsrch_lcavailable'} eq '1') {
9794: $changes{'lcavailable'} = 1;
9795: }
9796: }
1.24 raeburn 9797: if (exists($currdirsrch{'localonly'})) {
1.277 raeburn 9798: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 9799: $changes{'localonly'} = 1;
9800: }
9801: } else {
1.277 raeburn 9802: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 9803: $changes{'localonly'} = 1;
9804: }
9805: }
1.277 raeburn 9806: if (exists($currdirsrch{'lclocalonly'})) {
9807: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
9808: $changes{'lclocalonly'} = 1;
9809: }
9810: } else {
9811: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
9812: $changes{'lclocalonly'} = 1;
9813: }
9814: }
1.23 raeburn 9815: if (keys(%changes) > 0) {
9816: $resulttext = &mt('Changes made:').'<ul>';
9817: if ($changes{'available'}) {
9818: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
9819: }
1.277 raeburn 9820: if ($changes{'lcavailable'}) {
9821: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
9822: }
1.24 raeburn 9823: if ($changes{'localonly'}) {
1.277 raeburn 9824: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 9825: }
1.277 raeburn 9826: if ($changes{'lclocalonly'}) {
9827: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
9828: }
1.23 raeburn 9829: if (ref($changes{'cansearch'}) eq 'ARRAY') {
9830: my $chgtext;
1.26 raeburn 9831: if (ref($usertypes) eq 'HASH') {
9832: if (keys(%{$usertypes}) > 0) {
9833: foreach my $type (@{$types}) {
9834: if (grep(/^\Q$type\E$/,@cansearch)) {
9835: $chgtext .= $usertypes->{$type}.'; ';
9836: }
9837: }
9838: if (grep(/^default$/,@cansearch)) {
9839: $chgtext .= $othertitle;
9840: } else {
9841: $chgtext =~ s/\; $//;
9842: }
1.210 raeburn 9843: $resulttext .=
1.178 raeburn 9844: '<li>'.
9845: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
9846: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
9847: '</li>';
1.23 raeburn 9848: }
9849: }
9850: }
9851: if (ref($changes{'searchby'}) eq 'ARRAY') {
9852: my ($searchtitles,$titleorder) = &sorted_searchtitles();
9853: my $chgtext;
9854: foreach my $type (@{$titleorder}) {
9855: if (grep(/^\Q$type\E$/,@searchby)) {
9856: if (defined($searchtitles->{$type})) {
9857: $chgtext .= $searchtitles->{$type}.'; ';
9858: }
9859: }
9860: }
9861: $chgtext =~ s/\; $//;
9862: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
9863: }
1.25 raeburn 9864: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
9865: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
9866: my $chgtext;
9867: foreach my $type (@{$srchtypeorder}) {
9868: if (grep(/^\Q$type\E$/,@searchtypes)) {
9869: if (defined($srchtypes_desc->{$type})) {
9870: $chgtext .= $srchtypes_desc->{$type}.'; ';
9871: }
9872: }
9873: }
9874: $chgtext =~ s/\; $//;
1.178 raeburn 9875: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 9876: }
9877: $resulttext .= '</ul>';
9878: } else {
1.277 raeburn 9879: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 9880: }
9881: } else {
9882: $resulttext = '<span class="LC_error">'.
1.27 raeburn 9883: &mt('An error occurred: [_1]',$putresult).'</span>';
9884: }
9885: return $resulttext;
9886: }
9887:
1.28 raeburn 9888: sub modify_contacts {
1.205 raeburn 9889: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 9890: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
9891: if (ref($domconfig{'contacts'}) eq 'HASH') {
9892: foreach my $key (keys(%{$domconfig{'contacts'}})) {
9893: $currsetting{$key} = $domconfig{'contacts'}{$key};
9894: }
9895: }
1.134 raeburn 9896: my (%others,%to,%bcc);
1.28 raeburn 9897: my @contacts = ('supportemail','adminemail');
1.102 raeburn 9898: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203 raeburn 9899: 'requestsmail','updatesmail','idconflictsmail');
9900: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 9901: foreach my $type (@mailings) {
9902: @{$newsetting{$type}} =
9903: &Apache::loncommon::get_env_multiple('form.'.$type);
9904: foreach my $item (@contacts) {
9905: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
9906: $contacts_hash{contacts}{$type}{$item} = 1;
9907: } else {
9908: $contacts_hash{contacts}{$type}{$item} = 0;
9909: }
9910: }
9911: $others{$type} = $env{'form.'.$type.'_others'};
9912: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 9913: if ($type eq 'helpdeskmail') {
9914: $bcc{$type} = $env{'form.'.$type.'_bcc'};
9915: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
9916: }
1.28 raeburn 9917: }
9918: foreach my $item (@contacts) {
9919: $to{$item} = $env{'form.'.$item};
9920: $contacts_hash{'contacts'}{$item} = $to{$item};
9921: }
1.203 raeburn 9922: foreach my $item (@toggles) {
9923: if ($env{'form.'.$item} =~ /^(0|1)$/) {
9924: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
9925: }
9926: }
1.28 raeburn 9927: if (keys(%currsetting) > 0) {
9928: foreach my $item (@contacts) {
9929: if ($to{$item} ne $currsetting{$item}) {
9930: $changes{$item} = 1;
9931: }
9932: }
9933: foreach my $type (@mailings) {
9934: foreach my $item (@contacts) {
9935: if (ref($currsetting{$type}) eq 'HASH') {
9936: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
9937: push(@{$changes{$type}},$item);
9938: }
9939: } else {
9940: push(@{$changes{$type}},@{$newsetting{$type}});
9941: }
9942: }
9943: if ($others{$type} ne $currsetting{$type}{'others'}) {
9944: push(@{$changes{$type}},'others');
9945: }
1.134 raeburn 9946: if ($type eq 'helpdeskmail') {
9947: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
9948: push(@{$changes{$type}},'bcc');
9949: }
9950: }
1.28 raeburn 9951: }
9952: } else {
9953: my %default;
9954: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
9955: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
9956: $default{'errormail'} = 'adminemail';
9957: $default{'packagesmail'} = 'adminemail';
9958: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 9959: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 9960: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 9961: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 9962: foreach my $item (@contacts) {
9963: if ($to{$item} ne $default{$item}) {
9964: $changes{$item} = 1;
1.203 raeburn 9965: }
1.28 raeburn 9966: }
9967: foreach my $type (@mailings) {
9968: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
9969:
9970: push(@{$changes{$type}},@{$newsetting{$type}});
9971: }
9972: if ($others{$type} ne '') {
9973: push(@{$changes{$type}},'others');
1.134 raeburn 9974: }
9975: if ($type eq 'helpdeskmail') {
9976: if ($bcc{$type} ne '') {
9977: push(@{$changes{$type}},'bcc');
9978: }
9979: }
1.28 raeburn 9980: }
9981: }
1.203 raeburn 9982: foreach my $item (@toggles) {
9983: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
9984: $changes{$item} = 1;
9985: } elsif ((!$env{'form.'.$item}) &&
9986: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
9987: $changes{$item} = 1;
9988: }
9989: }
1.28 raeburn 9990: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
9991: $dom);
9992: if ($putresult eq 'ok') {
9993: if (keys(%changes) > 0) {
1.205 raeburn 9994: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9995: if (ref($lastactref) eq 'HASH') {
9996: $lastactref->{'domainconfig'} = 1;
9997: }
1.28 raeburn 9998: my ($titles,$short_titles) = &contact_titles();
9999: $resulttext = &mt('Changes made:').'<ul>';
10000: foreach my $item (@contacts) {
10001: if ($changes{$item}) {
10002: $resulttext .= '<li>'.$titles->{$item}.
10003: &mt(' set to: ').
10004: '<span class="LC_cusr_emph">'.
10005: $to{$item}.'</span></li>';
10006: }
10007: }
10008: foreach my $type (@mailings) {
10009: if (ref($changes{$type}) eq 'ARRAY') {
10010: $resulttext .= '<li>'.$titles->{$type}.': ';
10011: my @text;
10012: foreach my $item (@{$newsetting{$type}}) {
10013: push(@text,$short_titles->{$item});
10014: }
10015: if ($others{$type} ne '') {
10016: push(@text,$others{$type});
10017: }
10018: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 10019: join(', ',@text).'</span>';
10020: if ($type eq 'helpdeskmail') {
10021: if ($bcc{$type} ne '') {
10022: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
10023: }
10024: }
10025: $resulttext .= '</li>';
1.28 raeburn 10026: }
10027: }
1.203 raeburn 10028: my @offon = ('off','on');
10029: if ($changes{'reporterrors'}) {
10030: $resulttext .= '<li>'.
10031: &mt('E-mail error reports to [_1] set to "'.
10032: $offon[$env{'form.reporterrors'}].'".',
10033: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10034: &mt('LON-CAPA core group - MSU'),600,500)).
10035: '</li>';
10036: }
10037: if ($changes{'reportupdates'}) {
10038: $resulttext .= '<li>'.
10039: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
10040: $offon[$env{'form.reportupdates'}].'".',
10041: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10042: &mt('LON-CAPA core group - MSU'),600,500)).
10043: '</li>';
10044: }
1.28 raeburn 10045: $resulttext .= '</ul>';
10046: } else {
1.34 raeburn 10047: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 10048: }
10049: } else {
10050: $resulttext = '<span class="LC_error">'.
10051: &mt('An error occurred: [_1].',$putresult).'</span>';
10052: }
10053: return $resulttext;
10054: }
10055:
10056: sub modify_usercreation {
1.27 raeburn 10057: my ($dom,%domconfig) = @_;
1.224 raeburn 10058: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 10059: my $warningmsg;
1.27 raeburn 10060: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10061: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 10062: if ($key eq 'cancreate') {
10063: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
10064: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
10065: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.269 raeburn 10066: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
10067: ($item eq 'recaptchaversion')) {
1.224 raeburn 10068: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10069: } else {
10070: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10071: }
10072: }
10073: }
10074: } elsif ($key eq 'email_rule') {
10075: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
10076: } else {
10077: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
10078: }
1.27 raeburn 10079: }
10080: }
10081: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 10082: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 10083: my @contexts = ('author','course','requestcrs');
1.34 raeburn 10084: foreach my $item(@contexts) {
1.224 raeburn 10085: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 10086: }
1.34 raeburn 10087: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10088: foreach my $item (@contexts) {
1.224 raeburn 10089: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
10090: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 10091: }
1.27 raeburn 10092: }
1.34 raeburn 10093: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
10094: foreach my $item (@contexts) {
1.43 raeburn 10095: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 10096: if ($cancreate{$item} ne 'any') {
10097: push(@{$changes{'cancreate'}},$item);
10098: }
10099: } else {
10100: if ($cancreate{$item} ne 'none') {
10101: push(@{$changes{'cancreate'}},$item);
10102: }
1.27 raeburn 10103: }
10104: }
10105: } else {
1.43 raeburn 10106: foreach my $item (@contexts) {
1.34 raeburn 10107: push(@{$changes{'cancreate'}},$item);
10108: }
1.27 raeburn 10109: }
1.34 raeburn 10110:
1.27 raeburn 10111: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
10112: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
10113: if (!grep(/^\Q$type\E$/,@username_rule)) {
10114: push(@{$changes{'username_rule'}},$type);
10115: }
10116: }
10117: foreach my $type (@username_rule) {
10118: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
10119: push(@{$changes{'username_rule'}},$type);
10120: }
10121: }
10122: } else {
10123: push(@{$changes{'username_rule'}},@username_rule);
10124: }
10125:
1.32 raeburn 10126: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
10127: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
10128: if (!grep(/^\Q$type\E$/,@id_rule)) {
10129: push(@{$changes{'id_rule'}},$type);
10130: }
10131: }
10132: foreach my $type (@id_rule) {
10133: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
10134: push(@{$changes{'id_rule'}},$type);
10135: }
10136: }
10137: } else {
10138: push(@{$changes{'id_rule'}},@id_rule);
10139: }
10140:
1.43 raeburn 10141: my @authen_contexts = ('author','course','domain');
1.28 raeburn 10142: my @authtypes = ('int','krb4','krb5','loc');
10143: my %authhash;
1.43 raeburn 10144: foreach my $item (@authen_contexts) {
1.28 raeburn 10145: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
10146: foreach my $auth (@authtypes) {
10147: if (grep(/^\Q$auth\E$/,@authallowed)) {
10148: $authhash{$item}{$auth} = 1;
10149: } else {
10150: $authhash{$item}{$auth} = 0;
10151: }
10152: }
10153: }
10154: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 10155: foreach my $item (@authen_contexts) {
1.28 raeburn 10156: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
10157: foreach my $auth (@authtypes) {
10158: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
10159: push(@{$changes{'authtypes'}},$item);
10160: last;
10161: }
10162: }
10163: }
10164: }
10165: } else {
1.43 raeburn 10166: foreach my $item (@authen_contexts) {
1.28 raeburn 10167: push(@{$changes{'authtypes'}},$item);
10168: }
10169: }
10170:
1.224 raeburn 10171: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
10172: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
10173: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
10174: $save_usercreate{'id_rule'} = \@id_rule;
10175: $save_usercreate{'username_rule'} = \@username_rule,
10176: $save_usercreate{'authtypes'} = \%authhash;
10177:
1.27 raeburn 10178: my %usercreation_hash = (
1.224 raeburn 10179: usercreation => \%save_usercreate,
10180: );
1.27 raeburn 10181:
10182: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
10183: $dom);
1.50 raeburn 10184:
1.224 raeburn 10185: if ($putresult eq 'ok') {
10186: if (keys(%changes) > 0) {
10187: $resulttext = &mt('Changes made:').'<ul>';
10188: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10189: my %lt = &usercreation_types();
10190: foreach my $type (@{$changes{'cancreate'}}) {
10191: my $chgtext = $lt{$type}.', ';
10192: if ($cancreate{$type} eq 'none') {
10193: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
10194: } elsif ($cancreate{$type} eq 'any') {
10195: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
10196: } elsif ($cancreate{$type} eq 'official') {
10197: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
10198: } elsif ($cancreate{$type} eq 'unofficial') {
10199: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
10200: }
10201: $resulttext .= '<li>'.$chgtext.'</li>';
10202: }
10203: }
10204: if (ref($changes{'username_rule'}) eq 'ARRAY') {
10205: my ($rules,$ruleorder) =
10206: &Apache::lonnet::inst_userrules($dom,'username');
10207: my $chgtext = '<ul>';
10208: foreach my $type (@username_rule) {
10209: if (ref($rules->{$type}) eq 'HASH') {
10210: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
10211: }
10212: }
10213: $chgtext .= '</ul>';
10214: if (@username_rule > 0) {
10215: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
10216: } else {
10217: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
10218: }
10219: }
10220: if (ref($changes{'id_rule'}) eq 'ARRAY') {
10221: my ($idrules,$idruleorder) =
10222: &Apache::lonnet::inst_userrules($dom,'id');
10223: my $chgtext = '<ul>';
10224: foreach my $type (@id_rule) {
10225: if (ref($idrules->{$type}) eq 'HASH') {
10226: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
10227: }
10228: }
10229: $chgtext .= '</ul>';
10230: if (@id_rule > 0) {
10231: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
10232: } else {
10233: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
10234: }
10235: }
10236: my %authname = &authtype_names();
10237: my %context_title = &context_names();
10238: if (ref($changes{'authtypes'}) eq 'ARRAY') {
10239: my $chgtext = '<ul>';
10240: foreach my $type (@{$changes{'authtypes'}}) {
10241: my @allowed;
10242: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
10243: foreach my $auth (@authtypes) {
10244: if ($authhash{$type}{$auth}) {
10245: push(@allowed,$authname{$auth});
10246: }
10247: }
10248: if (@allowed > 0) {
10249: $chgtext .= join(', ',@allowed).'</li>';
10250: } else {
10251: $chgtext .= &mt('none').'</li>';
10252: }
10253: }
10254: $chgtext .= '</ul>';
10255: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
10256: $resulttext .= '</li>';
10257: }
10258: $resulttext .= '</ul>';
10259: } else {
10260: $resulttext = &mt('No changes made to user creation settings');
10261: }
10262: } else {
10263: $resulttext = '<span class="LC_error">'.
10264: &mt('An error occurred: [_1]',$putresult).'</span>';
10265: }
10266: if ($warningmsg ne '') {
10267: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10268: }
10269: return $resulttext;
10270: }
10271:
10272: sub modify_selfcreation {
10273: my ($dom,%domconfig) = @_;
10274: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
10275: my (%save_usercreate,%save_usermodify);
1.228 raeburn 10276: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10277: if (ref($types) eq 'ARRAY') {
10278: $usertypes->{'default'} = $othertitle;
10279: push(@{$types},'default');
10280: }
1.224 raeburn 10281: #
10282: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
10283: #
10284: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10285: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
10286: if ($key eq 'cancreate') {
10287: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
10288: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
10289: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
10290: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.269 raeburn 10291: ($item eq 'recaptchaversion') ||
1.236 raeburn 10292: ($item eq 'emailusername') || ($item eq 'notify') ||
1.240 raeburn 10293: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.224 raeburn 10294: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10295: } else {
10296: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10297: }
10298: }
10299: }
10300: } elsif ($key eq 'email_rule') {
10301: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
10302: } else {
10303: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
10304: }
10305: }
10306: }
10307: #
10308: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
10309: #
10310: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10311: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
10312: if ($key eq 'selfcreate') {
10313: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
10314: } else {
10315: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
10316: }
10317: }
10318: }
10319:
10320: my @contexts = ('selfcreate');
10321: @{$cancreate{'selfcreate'}} = ();
10322: %{$cancreate{'emailusername'}} = ();
10323: @{$cancreate{'statustocreate'}} = ();
1.236 raeburn 10324: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 10325: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 10326: my %selfcreatetypes = (
10327: sso => 'users authenticated by institutional single sign on',
10328: login => 'users authenticated by institutional log-in',
1.236 raeburn 10329: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 10330: );
1.224 raeburn 10331: #
10332: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
10333: # is permitted.
10334: #
1.236 raeburn 10335:
10336: my @statuses;
10337: if (ref($domconfig{'inststatus'}) eq 'HASH') {
10338: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
10339: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
10340: }
10341: }
10342: push(@statuses,'default');
10343:
1.228 raeburn 10344: foreach my $item ('login','sso','email') {
1.224 raeburn 10345: if ($item eq 'email') {
1.236 raeburn 10346: if ($env{'form.cancreate_email'}) {
1.224 raeburn 10347: push(@{$cancreate{'selfcreate'}},'email');
1.236 raeburn 10348: push(@contexts,'selfcreateprocessing');
10349: foreach my $type (@statuses) {
10350: if ($type eq 'default') {
10351: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
10352: } else {
10353: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
10354: }
10355: }
1.224 raeburn 10356: }
10357: } else {
10358: if ($env{'form.cancreate_'.$item}) {
10359: push(@{$cancreate{'selfcreate'}},$item);
10360: }
10361: }
10362: }
10363: my (@email_rule,%userinfo,%savecaptcha);
10364: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
10365: #
1.228 raeburn 10366: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
10367: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 10368: #
1.236 raeburn 10369:
1.244 raeburn 10370: if ($env{'form.cancreate_email'}) {
1.228 raeburn 10371: push(@contexts,'emailusername');
10372: if (ref($types) eq 'ARRAY') {
10373: foreach my $type (@{$types}) {
10374: if (ref($infofields) eq 'ARRAY') {
10375: foreach my $field (@{$infofields}) {
10376: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
10377: $cancreate{'emailusername'}{$type}{$field} = $1;
10378: }
10379: }
1.224 raeburn 10380: }
10381: }
10382: }
10383: #
10384: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
10385: # queued requests for self-creation of account using e-mail address as username
10386: #
10387:
10388: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
10389: @approvalnotify = sort(@approvalnotify);
10390: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
10391: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10392: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
10393: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
10394: push(@{$changes{'cancreate'}},'notify');
10395: }
10396: } else {
10397: if ($cancreate{'notify'}{'approval'}) {
10398: push(@{$changes{'cancreate'}},'notify');
10399: }
10400: }
10401: } elsif ($cancreate{'notify'}{'approval'}) {
10402: push(@{$changes{'cancreate'}},'notify');
10403: }
10404:
10405: #
10406: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
10407: #
10408: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
10409: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
10410: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
10411: if (@{$curr_usercreation{'email_rule'}} > 0) {
10412: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
10413: if (!grep(/^\Q$type\E$/,@email_rule)) {
10414: push(@{$changes{'email_rule'}},$type);
10415: }
10416: }
10417: }
10418: if (@email_rule > 0) {
10419: foreach my $type (@email_rule) {
10420: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
10421: push(@{$changes{'email_rule'}},$type);
10422: }
10423: }
10424: }
10425: } elsif (@email_rule > 0) {
10426: push(@{$changes{'email_rule'}},@email_rule);
10427: }
10428: }
10429: #
1.236 raeburn 10430: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 10431: # institutional log-in.
10432: #
10433: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
10434: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10435: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
10436: ($domdefaults{'auth_def'} eq 'localauth'))) {
10437: $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.').' '.
10438: &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.');
10439: }
10440: }
10441: my @fields = ('lastname','firstname','middlename','generation',
10442: 'permanentemail','id');
1.240 raeburn 10443: my @shibfields = (@fields,'inststatus');
1.224 raeburn 10444: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10445: #
10446: # Where usernames may created for institutional log-in and/or institutional single sign on:
10447: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
10448: # may self-create accounts
10449: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
10450: # which the user may supply, if institutional data is unavailable.
10451: #
10452: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
10453: if (ref($types) eq 'ARRAY') {
1.228 raeburn 10454: if (@{$types} > 1) {
1.224 raeburn 10455: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
10456: push(@contexts,'statustocreate');
10457: } else {
10458: undef($cancreate{'statustocreate'});
10459: }
10460: foreach my $type (@{$types}) {
10461: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
10462: foreach my $field (@fields) {
10463: if (grep(/^\Q$field\E$/,@modifiable)) {
10464: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
10465: } else {
10466: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
10467: }
10468: }
10469: }
10470: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
10471: foreach my $type (@{$types}) {
10472: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
10473: foreach my $field (@fields) {
10474: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
10475: $curr_usermodify{'selfcreate'}{$type}{$field}) {
10476: push(@{$changes{'selfcreate'}},$type);
10477: last;
10478: }
10479: }
10480: }
10481: }
10482: } else {
10483: foreach my $type (@{$types}) {
10484: push(@{$changes{'selfcreate'}},$type);
10485: }
10486: }
10487: }
1.240 raeburn 10488: foreach my $field (@shibfields) {
10489: if ($env{'form.shibenv_'.$field} ne '') {
10490: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
10491: }
10492: }
10493: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10494: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
10495: foreach my $field (@shibfields) {
10496: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
10497: push(@{$changes{'cancreate'}},'shibenv');
10498: }
10499: }
10500: } else {
10501: foreach my $field (@shibfields) {
10502: if ($env{'form.shibenv_'.$field}) {
10503: push(@{$changes{'cancreate'}},'shibenv');
10504: last;
10505: }
10506: }
10507: }
10508: }
1.224 raeburn 10509: }
10510: foreach my $item (@contexts) {
10511: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
10512: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
10513: if (ref($cancreate{$item}) eq 'ARRAY') {
10514: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
10515: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10516: push(@{$changes{'cancreate'}},$item);
10517: }
10518: }
10519: }
10520: }
10521: if (ref($cancreate{$item}) eq 'ARRAY') {
10522: foreach my $type (@{$cancreate{$item}}) {
10523: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
10524: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10525: push(@{$changes{'cancreate'}},$item);
10526: }
10527: }
10528: }
10529: }
10530: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
10531: if (ref($cancreate{$item}) eq 'HASH') {
10532: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228 raeburn 10533: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
10534: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
10535: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
10536: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10537: push(@{$changes{'cancreate'}},$item);
10538: }
10539: }
10540: }
1.236 raeburn 10541: } elsif ($item eq 'selfcreateprocessing') {
10542: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
10543: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10544: push(@{$changes{'cancreate'}},$item);
10545: }
10546: }
1.228 raeburn 10547: } else {
10548: if (!$cancreate{$item}{$curr}) {
10549: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10550: push(@{$changes{'cancreate'}},$item);
10551: }
1.224 raeburn 10552: }
10553: }
10554: }
10555: foreach my $field (keys(%{$cancreate{$item}})) {
1.228 raeburn 10556: if (ref($cancreate{$item}{$field}) eq 'HASH') {
10557: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
10558: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
10559: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
10560: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10561: push(@{$changes{'cancreate'}},$item);
10562: }
10563: }
10564: } else {
10565: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10566: push(@{$changes{'cancreate'}},$item);
10567: }
10568: }
10569: }
1.236 raeburn 10570: } elsif ($item eq 'selfcreateprocessing') {
10571: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
10572: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10573: push(@{$changes{'cancreate'}},$item);
10574: }
10575: }
1.228 raeburn 10576: } else {
10577: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
10578: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10579: push(@{$changes{'cancreate'}},$item);
10580: }
1.224 raeburn 10581: }
10582: }
10583: }
10584: }
10585: } elsif ($curr_usercreation{'cancreate'}{$item}) {
10586: if (ref($cancreate{$item}) eq 'ARRAY') {
10587: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
10588: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10589: push(@{$changes{'cancreate'}},$item);
10590: }
10591: }
10592: } elsif (ref($cancreate{$item}) eq 'HASH') {
10593: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
10594: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10595: push(@{$changes{'cancreate'}},$item);
10596: }
10597: }
10598: }
10599: } elsif ($item eq 'emailusername') {
1.228 raeburn 10600: if (ref($cancreate{$item}) eq 'HASH') {
10601: foreach my $type (keys(%{$cancreate{$item}})) {
10602: if (ref($cancreate{$item}{$type}) eq 'HASH') {
10603: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
10604: if ($cancreate{$item}{$type}{$field}) {
10605: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10606: push(@{$changes{'cancreate'}},$item);
10607: }
10608: last;
10609: }
10610: }
10611: }
10612: }
1.224 raeburn 10613: }
10614: }
10615: }
10616: #
10617: # Populate %save_usercreate hash with updates to self-creation configuration.
10618: #
10619: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
10620: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 10621: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 10622: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
10623: if (ref($cancreate{'notify'}) eq 'HASH') {
10624: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
10625: }
1.236 raeburn 10626: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
10627: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
10628: }
1.224 raeburn 10629: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10630: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
10631: }
1.240 raeburn 10632: if (ref($cancreate{'shibenv'}) eq 'HASH') {
10633: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
10634: }
1.224 raeburn 10635: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
10636: $save_usercreate{'emailrule'} = \@email_rule;
10637:
10638: my %userconfig_hash = (
10639: usercreation => \%save_usercreate,
10640: usermodification => \%save_usermodify,
10641: );
10642: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
10643: $dom);
10644: #
10645: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
10646: #
1.27 raeburn 10647: if ($putresult eq 'ok') {
10648: if (keys(%changes) > 0) {
10649: $resulttext = &mt('Changes made:').'<ul>';
10650: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 10651: my %lt = &selfcreation_types();
1.34 raeburn 10652: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 10653: my $chgtext;
1.45 raeburn 10654: if ($type eq 'selfcreate') {
1.50 raeburn 10655: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 10656: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 10657: } else {
1.224 raeburn 10658: $chgtext .= &mt('Self-creation of a new account is permitted for:').
10659: '<ul>';
1.50 raeburn 10660: foreach my $case (@{$cancreate{$type}}) {
10661: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
10662: }
10663: $chgtext .= '</ul>';
1.100 raeburn 10664: if (ref($cancreate{$type}) eq 'ARRAY') {
10665: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
10666: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10667: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 raeburn 10668: $chgtext .= '<br />'.
10669: '<span class="LC_warning">'.
10670: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10671: '</span>';
1.100 raeburn 10672: }
10673: }
10674: }
10675: }
1.43 raeburn 10676: }
1.240 raeburn 10677: } elsif ($type eq 'shibenv') {
10678: if (keys(%{$cancreate{$type}}) == 0) {
10679: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
10680: } else {
10681: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
10682: '<ul>';
10683: foreach my $field (@shibfields) {
10684: next if ($cancreate{$type}{$field} eq '');
10685: if ($field eq 'inststatus') {
10686: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
10687: } else {
10688: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
10689: }
10690: }
10691: $chgtext .= '</ul>';
10692: }
1.93 raeburn 10693: } elsif ($type eq 'statustocreate') {
1.96 raeburn 10694: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
10695: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
10696: if (@{$cancreate{'selfcreate'}} > 0) {
10697: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 10698: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 10699: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 10700: $chgtext .= '<br />'.
10701: '<span class="LC_warning">'.
10702: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10703: '</span>';
10704: }
1.96 raeburn 10705: } elsif (ref($usertypes) eq 'HASH') {
10706: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 10707: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
10708: } else {
10709: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
10710: }
10711: $chgtext .= '<ul>';
10712: foreach my $case (@{$cancreate{$type}}) {
10713: if ($case eq 'default') {
10714: $chgtext .= '<li>'.$othertitle.'</li>';
10715: } else {
10716: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 10717: }
10718: }
1.100 raeburn 10719: $chgtext .= '</ul>';
10720: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 10721: $chgtext .= '<br /><span class="LC_warning">'.
10722: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
10723: '</span>';
1.100 raeburn 10724: }
10725: }
10726: } else {
10727: if (@{$cancreate{$type}} == 0) {
10728: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
10729: } else {
10730: $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 10731: }
10732: }
10733: }
1.236 raeburn 10734: } elsif ($type eq 'selfcreateprocessing') {
10735: my %choices = &Apache::lonlocal::texthash (
10736: automatic => 'Automatic approval',
10737: approval => 'Queued for approval',
10738: );
10739: if (@statuses > 1) {
10740: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
10741: '<ul>';
10742: foreach my $type (@statuses) {
10743: if ($type eq 'default') {
10744: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10745: } else {
10746: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10747: }
10748: }
10749: $chgtext .= '</ul>';
10750: } else {
10751: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
10752: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
10753: }
1.165 raeburn 10754: } elsif ($type eq 'captcha') {
1.224 raeburn 10755: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 10756: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
10757: } else {
10758: my %captchas = &captcha_phrases();
1.224 raeburn 10759: if ($captchas{$savecaptcha{$type}}) {
10760: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 10761: } else {
1.210 raeburn 10762: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 10763: }
10764: }
10765: } elsif ($type eq 'recaptchakeys') {
10766: my ($privkey,$pubkey);
1.224 raeburn 10767: if (ref($savecaptcha{$type}) eq 'HASH') {
10768: $pubkey = $savecaptcha{$type}{'public'};
10769: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 10770: }
10771: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
10772: if (!$pubkey) {
10773: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
10774: } else {
10775: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
10776: }
10777: if (!$privkey) {
10778: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
10779: } else {
10780: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
10781: }
10782: $chgtext .= '</ul>';
1.269 raeburn 10783: } elsif ($type eq 'recaptchaversion') {
10784: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 10785: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 10786: }
1.224 raeburn 10787: } elsif ($type eq 'emailusername') {
10788: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228 raeburn 10789: if (ref($types) eq 'ARRAY') {
10790: foreach my $type (@{$types}) {
10791: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
10792: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.245 raeburn 10793: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.228 raeburn 10794: '<ul>';
10795: foreach my $field (@{$infofields}) {
10796: if ($cancreate{'emailusername'}{$type}{$field}) {
10797: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
10798: }
10799: }
1.245 raeburn 10800: $chgtext .= '</ul>';
10801: } else {
10802: $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 10803: }
10804: } else {
1.245 raeburn 10805: $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 10806: }
10807: }
10808: }
10809: }
10810: } elsif ($type eq 'notify') {
10811: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
10812: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10813: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
10814: if ($cancreate{'notify'}{'approval'}) {
10815: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
10816: }
10817: }
1.43 raeburn 10818: }
1.34 raeburn 10819: }
1.224 raeburn 10820: if ($chgtext) {
10821: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 10822: }
10823: }
10824: }
1.43 raeburn 10825: if (ref($changes{'email_rule'}) eq 'ARRAY') {
10826: my ($emailrules,$emailruleorder) =
10827: &Apache::lonnet::inst_userrules($dom,'email');
10828: my $chgtext = '<ul>';
10829: foreach my $type (@email_rule) {
10830: if (ref($emailrules->{$type}) eq 'HASH') {
10831: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
10832: }
10833: }
10834: $chgtext .= '</ul>';
10835: if (@email_rule > 0) {
1.224 raeburn 10836: $resulttext .= '<li>'.
10837: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
10838: $chgtext.
10839: '</li>';
1.43 raeburn 10840: } else {
1.224 raeburn 10841: $resulttext .= '<li>'.
10842: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
10843: '</li>';
1.43 raeburn 10844: }
10845: }
1.224 raeburn 10846: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
10847: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
10848: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10849: foreach my $type (@{$changes{'selfcreate'}}) {
10850: my $typename = $type;
10851: if (ref($usertypes) eq 'HASH') {
10852: if ($usertypes->{$type} ne '') {
10853: $typename = $usertypes->{$type};
10854: }
10855: }
10856: my @modifiable;
10857: $resulttext .= '<li>'.
10858: &mt('Self-creation of account by users with status: [_1]',
10859: '<span class="LC_cusr_emph">'.$typename.'</span>').
10860: ' - '.&mt('modifiable fields (if institutional data blank): ');
10861: foreach my $field (@fields) {
10862: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
10863: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 10864: }
10865: }
1.224 raeburn 10866: if (@modifiable > 0) {
10867: $resulttext .= join(', ',@modifiable);
1.43 raeburn 10868: } else {
1.224 raeburn 10869: $resulttext .= &mt('none');
1.43 raeburn 10870: }
1.224 raeburn 10871: $resulttext .= '</li>';
1.28 raeburn 10872: }
1.224 raeburn 10873: $resulttext .= '</ul></li>';
1.28 raeburn 10874: }
1.27 raeburn 10875: $resulttext .= '</ul>';
10876: } else {
1.224 raeburn 10877: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 10878: }
10879: } else {
10880: $resulttext = '<span class="LC_error">'.
1.23 raeburn 10881: &mt('An error occurred: [_1]',$putresult).'</span>';
10882: }
1.43 raeburn 10883: if ($warningmsg ne '') {
10884: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10885: }
1.23 raeburn 10886: return $resulttext;
10887: }
10888:
1.165 raeburn 10889: sub process_captcha {
10890: my ($container,$changes,$newsettings,$current) = @_;
10891: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
10892: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
10893: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
10894: $newsettings->{'captcha'} = 'original';
10895: }
10896: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 10897: if ($container eq 'cancreate') {
1.169 raeburn 10898: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10899: push(@{$changes->{'cancreate'}},'captcha');
10900: } elsif (!defined($changes->{'cancreate'})) {
10901: $changes->{'cancreate'} = ['captcha'];
10902: }
10903: } else {
10904: $changes->{'captcha'} = 1;
1.165 raeburn 10905: }
10906: }
1.269 raeburn 10907: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 10908: if ($newsettings->{'captcha'} eq 'recaptcha') {
10909: $newpub = $env{'form.'.$container.'_recaptchapub'};
10910: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 10911: $newpub =~ s/[^\w\-]//g;
10912: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 10913: $newsettings->{'recaptchakeys'} = {
10914: public => $newpub,
10915: private => $newpriv,
10916: };
1.269 raeburn 10917: $newversion = $env{'form.'.$container.'_recaptchaversion'};
10918: $newversion =~ s/\D//g;
10919: if ($newversion ne '2') {
10920: $newversion = 1;
10921: }
10922: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 10923: }
10924: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
10925: $currpub = $current->{'recaptchakeys'}{'public'};
10926: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 10927: unless ($newsettings->{'captcha'} eq 'recaptcha') {
10928: $newsettings->{'recaptchakeys'} = {
10929: public => '',
10930: private => '',
10931: }
10932: }
1.165 raeburn 10933: }
1.269 raeburn 10934: if ($current->{'captcha'} eq 'recaptcha') {
10935: $currversion = $current->{'recaptchaversion'};
10936: if ($currversion ne '2') {
10937: $currversion = 1;
10938: }
10939: }
10940: if ($currversion ne $newversion) {
10941: if ($container eq 'cancreate') {
10942: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10943: push(@{$changes->{'cancreate'}},'recaptchaversion');
10944: } elsif (!defined($changes->{'cancreate'})) {
10945: $changes->{'cancreate'} = ['recaptchaversion'];
10946: }
10947: } else {
10948: $changes->{'recaptchaversion'} = 1;
10949: }
10950: }
1.165 raeburn 10951: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 10952: if ($container eq 'cancreate') {
10953: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10954: push(@{$changes->{'cancreate'}},'recaptchakeys');
10955: } elsif (!defined($changes->{'cancreate'})) {
10956: $changes->{'cancreate'} = ['recaptchakeys'];
10957: }
10958: } else {
1.210 raeburn 10959: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 10960: }
10961: }
10962: return;
10963: }
10964:
1.33 raeburn 10965: sub modify_usermodification {
10966: my ($dom,%domconfig) = @_;
1.224 raeburn 10967: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 10968: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10969: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 10970: if ($key eq 'selfcreate') {
10971: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
10972: } else {
10973: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
10974: }
1.33 raeburn 10975: }
10976: }
1.224 raeburn 10977: my @contexts = ('author','course');
1.33 raeburn 10978: my %context_title = (
10979: author => 'In author context',
10980: course => 'In course context',
10981: );
10982: my @fields = ('lastname','firstname','middlename','generation',
10983: 'permanentemail','id');
10984: my %roles = (
10985: author => ['ca','aa'],
10986: course => ['st','ep','ta','in','cr'],
10987: );
10988: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10989: foreach my $context (@contexts) {
10990: foreach my $role (@{$roles{$context}}) {
10991: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
10992: foreach my $item (@fields) {
10993: if (grep(/^\Q$item\E$/,@modifiable)) {
10994: $modifyhash{$context}{$role}{$item} = 1;
10995: } else {
10996: $modifyhash{$context}{$role}{$item} = 0;
10997: }
10998: }
10999: }
11000: if (ref($curr_usermodification{$context}) eq 'HASH') {
11001: foreach my $role (@{$roles{$context}}) {
11002: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
11003: foreach my $field (@fields) {
11004: if ($modifyhash{$context}{$role}{$field} ne
11005: $curr_usermodification{$context}{$role}{$field}) {
11006: push(@{$changes{$context}},$role);
11007: last;
11008: }
11009: }
11010: }
11011: }
11012: } else {
11013: foreach my $context (@contexts) {
11014: foreach my $role (@{$roles{$context}}) {
11015: push(@{$changes{$context}},$role);
11016: }
11017: }
11018: }
11019: }
11020: my %usermodification_hash = (
11021: usermodification => \%modifyhash,
11022: );
11023: my $putresult = &Apache::lonnet::put_dom('configuration',
11024: \%usermodification_hash,$dom);
11025: if ($putresult eq 'ok') {
11026: if (keys(%changes) > 0) {
11027: $resulttext = &mt('Changes made: ').'<ul>';
11028: foreach my $context (@contexts) {
11029: if (ref($changes{$context}) eq 'ARRAY') {
11030: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
11031: if (ref($changes{$context}) eq 'ARRAY') {
11032: foreach my $role (@{$changes{$context}}) {
11033: my $rolename;
1.224 raeburn 11034: if ($role eq 'cr') {
11035: $rolename = &mt('Custom');
1.33 raeburn 11036: } else {
1.224 raeburn 11037: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 11038: }
11039: my @modifiable;
1.224 raeburn 11040: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 11041: foreach my $field (@fields) {
11042: if ($modifyhash{$context}{$role}{$field}) {
11043: push(@modifiable,$fieldtitles{$field});
11044: }
11045: }
11046: if (@modifiable > 0) {
11047: $resulttext .= join(', ',@modifiable);
11048: } else {
11049: $resulttext .= &mt('none');
11050: }
11051: $resulttext .= '</li>';
11052: }
11053: $resulttext .= '</ul></li>';
11054: }
11055: }
11056: }
11057: $resulttext .= '</ul>';
11058: } else {
11059: $resulttext = &mt('No changes made to user modification settings');
11060: }
11061: } else {
11062: $resulttext = '<span class="LC_error">'.
11063: &mt('An error occurred: [_1]',$putresult).'</span>';
11064: }
11065: return $resulttext;
11066: }
11067:
1.43 raeburn 11068: sub modify_defaults {
1.212 raeburn 11069: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 11070: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 11071: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 11072: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 11073: my @authtypes = ('internal','krb4','krb5','localauth');
11074: foreach my $item (@items) {
11075: $newvalues{$item} = $env{'form.'.$item};
11076: if ($item eq 'auth_def') {
11077: if ($newvalues{$item} ne '') {
11078: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
11079: push(@errors,$item);
11080: }
11081: }
11082: } elsif ($item eq 'lang_def') {
11083: if ($newvalues{$item} ne '') {
11084: if ($newvalues{$item} =~ /^(\w+)/) {
11085: my $langcode = $1;
1.103 raeburn 11086: if ($langcode ne 'x_chef') {
11087: if (code2language($langcode) eq '') {
11088: push(@errors,$item);
11089: }
1.43 raeburn 11090: }
11091: } else {
11092: push(@errors,$item);
11093: }
11094: }
1.54 raeburn 11095: } elsif ($item eq 'timezone_def') {
11096: if ($newvalues{$item} ne '') {
1.62 raeburn 11097: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 11098: push(@errors,$item);
11099: }
11100: }
1.68 raeburn 11101: } elsif ($item eq 'datelocale_def') {
11102: if ($newvalues{$item} ne '') {
11103: my @datelocale_ids = DateTime::Locale->ids();
11104: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
11105: push(@errors,$item);
11106: }
11107: }
1.141 raeburn 11108: } elsif ($item eq 'portal_def') {
11109: if ($newvalues{$item} ne '') {
11110: 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])\/?$/) {
11111: push(@errors,$item);
11112: }
11113: }
1.43 raeburn 11114: }
11115: if (grep(/^\Q$item\E$/,@errors)) {
11116: $newvalues{$item} = $domdefaults{$item};
11117: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
11118: $changes{$item} = 1;
11119: }
1.72 raeburn 11120: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 11121: }
11122: my %defaults_hash = (
1.72 raeburn 11123: defaults => \%newvalues,
11124: );
1.43 raeburn 11125: my $title = &defaults_titles();
1.236 raeburn 11126:
11127: my $currinststatus;
11128: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11129: $currinststatus = $domconfig{'inststatus'};
11130: } else {
11131: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11132: $currinststatus = {
11133: inststatustypes => $usertypes,
11134: inststatusorder => $types,
11135: inststatusguest => [],
11136: };
11137: }
11138: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
11139: my @allpos;
11140: my %guests;
11141: my %alltypes;
11142: my ($currtitles,$currguests,$currorder);
11143: if (ref($currinststatus) eq 'HASH') {
11144: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
11145: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
11146: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
11147: if ($currinststatus->{inststatustypes}->{$type} ne '') {
11148: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
11149: }
11150: }
11151: unless (grep(/^\Q$type\E$/,@todelete)) {
11152: my $position = $env{'form.inststatus_pos_'.$type};
11153: $position =~ s/\D+//g;
11154: $allpos[$position] = $type;
11155: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
11156: $alltypes{$type} =~ s/`//g;
11157: if ($env{'form.inststatus_guest_'.$type}) {
11158: $guests{$type} = 1;
11159: }
11160: }
11161: }
11162: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
11163: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
11164: }
11165: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
11166: $currtitles =~ s/,$//;
11167: }
11168: }
11169: if ($env{'form.addinststatus'}) {
11170: my $newtype = $env{'form.addinststatus'};
11171: $newtype =~ s/\W//g;
11172: unless (exists($alltypes{$newtype})) {
11173: if ($env{'form.addinststatus_guest'}) {
11174: $guests{$newtype} = 1;
11175: }
11176: $alltypes{$newtype} = $env{'form.addinststatus_title'};
11177: $alltypes{$newtype} =~ s/`//g;
11178: my $position = $env{'form.addinststatus_pos'};
11179: $position =~ s/\D+//g;
11180: if ($position ne '') {
11181: $allpos[$position] = $newtype;
11182: }
11183: }
11184: }
11185: my (@orderedstatus,@orderedguests);
11186: foreach my $type (@allpos) {
11187: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
11188: push(@orderedstatus,$type);
11189: if ($guests{$type}) {
11190: push(@orderedguests,$type);
11191: }
11192: }
11193: }
11194: foreach my $type (keys(%alltypes)) {
11195: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
11196: delete($alltypes{$type});
11197: }
11198: }
11199: $defaults_hash{'inststatus'} = {
11200: inststatustypes => \%alltypes,
11201: inststatusorder => \@orderedstatus,
11202: inststatusguest => \@orderedguests,
11203: };
11204: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
11205: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
11206: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
11207: }
11208: }
11209: if ($currorder ne join(',',@orderedstatus)) {
11210: $changes{'inststatus'}{'inststatusorder'} = 1;
11211: }
11212: if ($currguests ne join(',',@orderedguests)) {
11213: $changes{'inststatus'}{'inststatusguest'} = 1;
11214: }
11215: my $newtitles;
11216: foreach my $item (@orderedstatus) {
11217: $newtitles .= $alltypes{$item}.',';
11218: }
11219: $newtitles =~ s/,$//;
11220: if ($currtitles ne $newtitles) {
11221: $changes{'inststatus'}{'inststatustypes'} = 1;
11222: }
1.43 raeburn 11223: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
11224: $dom);
11225: if ($putresult eq 'ok') {
11226: if (keys(%changes) > 0) {
11227: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 11228: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 11229: 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";
11230: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 11231: if ($item eq 'inststatus') {
11232: if (ref($changes{'inststatus'}) eq 'HASH') {
11233: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
11234: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
11235: foreach my $type (@orderedstatus) {
11236: $resulttext .= $alltypes{$type}.', ';
11237: }
11238: $resulttext =~ s/, $//;
11239: $resulttext .= '</li>';
11240: }
11241: if ($changes{'inststatus'}{'inststatusguest'}) {
11242: $resulttext .= '<li>';
11243: if (@orderedguests) {
11244: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
11245: foreach my $type (@orderedguests) {
11246: $resulttext .= $alltypes{$type}.', ';
11247: }
11248: $resulttext =~ s/, $//;
11249: } else {
11250: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
11251: }
11252: $resulttext .= '</li>';
11253: }
11254: }
11255: } else {
11256: my $value = $env{'form.'.$item};
11257: if ($value eq '') {
11258: $value = &mt('none');
11259: } elsif ($item eq 'auth_def') {
11260: my %authnames = &authtype_names();
11261: my %shortauth = (
11262: internal => 'int',
11263: krb4 => 'krb4',
11264: krb5 => 'krb5',
11265: localauth => 'loc',
11266: );
11267: $value = $authnames{$shortauth{$value}};
11268: }
11269: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
11270: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 11271: }
11272: }
11273: $resulttext .= '</ul>';
11274: $mailmsgtext .= "\n";
11275: my $cachetime = 24*60*60;
1.72 raeburn 11276: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 11277: if (ref($lastactref) eq 'HASH') {
11278: $lastactref->{'domdefaults'} = 1;
11279: }
1.68 raeburn 11280: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 11281: my $notify = 1;
11282: if (ref($domconfig{'contacts'}) eq 'HASH') {
11283: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
11284: $notify = 0;
11285: }
11286: }
11287: if ($notify) {
11288: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
11289: "LON-CAPA Domain Settings Change - $dom",
11290: $mailmsgtext);
11291: }
1.54 raeburn 11292: }
1.43 raeburn 11293: } else {
1.54 raeburn 11294: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 11295: }
11296: } else {
11297: $resulttext = '<span class="LC_error">'.
11298: &mt('An error occurred: [_1]',$putresult).'</span>';
11299: }
11300: if (@errors > 0) {
11301: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
11302: foreach my $item (@errors) {
11303: $resulttext .= ' "'.$title->{$item}.'",';
11304: }
11305: $resulttext =~ s/,$//;
11306: }
11307: return $resulttext;
11308: }
11309:
1.46 raeburn 11310: sub modify_scantron {
1.205 raeburn 11311: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 11312: my ($resulttext,%confhash,%changes,$errors);
11313: my $custom = 'custom.tab';
11314: my $default = 'default.tab';
11315: my $servadm = $r->dir_config('lonAdmEMail');
11316: my ($configuserok,$author_ok,$switchserver) =
11317: &config_check($dom,$confname,$servadm);
11318: if ($env{'form.scantronformat.filename'} ne '') {
11319: my $error;
11320: if ($configuserok eq 'ok') {
11321: if ($switchserver) {
1.130 raeburn 11322: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 11323: } else {
11324: if ($author_ok eq 'ok') {
11325: my ($result,$scantronurl) =
11326: &publishlogo($r,'upload','scantronformat',$dom,
11327: $confname,'scantron','','',$custom);
11328: if ($result eq 'ok') {
11329: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 11330: $changes{'scantronformat'} = 1;
1.46 raeburn 11331: } else {
11332: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
11333: }
11334: } else {
11335: $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);
11336: }
11337: }
11338: } else {
11339: $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);
11340: }
11341: if ($error) {
11342: &Apache::lonnet::logthis($error);
11343: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11344: }
11345: }
1.48 raeburn 11346: if (ref($domconfig{'scantron'}) eq 'HASH') {
11347: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
11348: if ($env{'form.scantronformat_del'}) {
11349: $confhash{'scantron'}{'scantronformat'} = '';
11350: $changes{'scantronformat'} = 1;
1.46 raeburn 11351: }
11352: }
11353: }
11354: if (keys(%confhash) > 0) {
11355: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
11356: $dom);
11357: if ($putresult eq 'ok') {
11358: if (keys(%changes) > 0) {
1.48 raeburn 11359: if (ref($confhash{'scantron'}) eq 'HASH') {
11360: $resulttext = &mt('Changes made:').'<ul>';
11361: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 11362: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 11363: } else {
1.130 raeburn 11364: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 11365: }
1.48 raeburn 11366: $resulttext .= '</ul>';
11367: } else {
1.130 raeburn 11368: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 11369: }
11370: $resulttext .= '</ul>';
11371: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 11372: if (ref($lastactref) eq 'HASH') {
11373: $lastactref->{'domainconfig'} = 1;
11374: }
1.46 raeburn 11375: } else {
1.130 raeburn 11376: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 11377: }
11378: } else {
11379: $resulttext = '<span class="LC_error">'.
11380: &mt('An error occurred: [_1]',$putresult).'</span>';
11381: }
11382: } else {
1.130 raeburn 11383: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 11384: }
11385: if ($errors) {
11386: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11387: $errors.'</ul>';
11388: }
11389: return $resulttext;
11390: }
11391:
1.48 raeburn 11392: sub modify_coursecategories {
1.239 raeburn 11393: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 11394: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
11395: $cathash);
1.48 raeburn 11396: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 11397: my @catitems = ('unauth','auth');
11398: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 11399: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 11400: $cathash = $domconfig{'coursecategories'}{'cats'};
11401: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
11402: $changes{'togglecats'} = 1;
11403: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
11404: }
11405: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
11406: $changes{'categorize'} = 1;
11407: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
11408: }
1.120 raeburn 11409: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
11410: $changes{'togglecatscomm'} = 1;
11411: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
11412: }
11413: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
11414: $changes{'categorizecomm'} = 1;
11415: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 11416:
11417: }
11418: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
11419: $changes{'togglecatsplace'} = 1;
11420: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
11421: }
11422: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
11423: $changes{'categorizeplace'} = 1;
11424: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 11425: }
1.238 raeburn 11426: foreach my $item (@catitems) {
11427: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
11428: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
11429: $changes{$item} = 1;
11430: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
11431: }
11432: }
11433: }
1.57 raeburn 11434: } else {
11435: $changes{'togglecats'} = 1;
11436: $changes{'categorize'} = 1;
1.124 raeburn 11437: $changes{'togglecatscomm'} = 1;
11438: $changes{'categorizecomm'} = 1;
1.272 raeburn 11439: $changes{'togglecatsplace'} = 1;
11440: $changes{'categorizeplace'} = 1;
1.87 raeburn 11441: $domconfig{'coursecategories'} = {
11442: togglecats => $env{'form.togglecats'},
11443: categorize => $env{'form.categorize'},
1.124 raeburn 11444: togglecatscomm => $env{'form.togglecatscomm'},
11445: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 11446: togglecatsplace => $env{'form.togglecatsplace'},
11447: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 11448: };
1.238 raeburn 11449: foreach my $item (@catitems) {
11450: if ($env{'form.coursecat_'.$item} ne 'std') {
11451: $changes{$item} = 1;
11452: }
11453: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
11454: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
11455: }
11456: }
1.57 raeburn 11457: }
11458: if (ref($cathash) eq 'HASH') {
11459: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 11460: push (@deletecategory,'instcode::0');
11461: }
1.120 raeburn 11462: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
11463: push(@deletecategory,'communities::0');
11464: }
1.272 raeburn 11465: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
11466: push(@deletecategory,'placement::0');
11467: }
1.48 raeburn 11468: }
1.57 raeburn 11469: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
11470: if (ref($cathash) eq 'HASH') {
1.48 raeburn 11471: if (@deletecategory > 0) {
11472: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 11473: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 11474: foreach my $item (@deletecategory) {
1.57 raeburn 11475: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
11476: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 11477: $deletions{$item} = 1;
1.57 raeburn 11478: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 11479: }
11480: }
11481: }
1.57 raeburn 11482: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 11483: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 11484: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 11485: $reorderings{$item} = 1;
1.57 raeburn 11486: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 11487: }
11488: if ($env{'form.addcategory_name_'.$item} ne '') {
11489: my $newcat = $env{'form.addcategory_name_'.$item};
11490: my $newdepth = $depth+1;
11491: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11492: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 11493: $adds{$newitem} = 1;
11494: }
11495: if ($env{'form.subcat_'.$item} ne '') {
11496: my $newcat = $env{'form.subcat_'.$item};
11497: my $newdepth = $depth+1;
11498: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11499: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 11500: $adds{$newitem} = 1;
11501: }
11502: }
11503: }
11504: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 11505: if (ref($cathash) eq 'HASH') {
1.48 raeburn 11506: my $newitem = 'instcode::0';
1.57 raeburn 11507: if ($cathash->{$newitem} eq '') {
11508: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11509: $adds{$newitem} = 1;
11510: }
11511: } else {
11512: my $newitem = 'instcode::0';
1.57 raeburn 11513: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11514: $adds{$newitem} = 1;
11515: }
11516: }
1.120 raeburn 11517: if ($env{'form.communities'} eq '1') {
11518: if (ref($cathash) eq 'HASH') {
11519: my $newitem = 'communities::0';
11520: if ($cathash->{$newitem} eq '') {
11521: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11522: $adds{$newitem} = 1;
11523: }
11524: } else {
11525: my $newitem = 'communities::0';
11526: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11527: $adds{$newitem} = 1;
11528: }
11529: }
1.272 raeburn 11530: if ($env{'form.placement'} eq '1') {
11531: if (ref($cathash) eq 'HASH') {
11532: my $newitem = 'placement::0';
11533: if ($cathash->{$newitem} eq '') {
11534: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
11535: $adds{$newitem} = 1;
11536: }
11537: } else {
11538: my $newitem = 'placement::0';
11539: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
11540: $adds{$newitem} = 1;
11541: }
11542: }
1.48 raeburn 11543: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 11544: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 11545: ($env{'form.addcategory_name'} ne 'communities') &&
11546: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 11547: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
11548: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
11549: $adds{$newitem} = 1;
11550: }
1.48 raeburn 11551: }
1.57 raeburn 11552: my $putresult;
1.48 raeburn 11553: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11554: if (keys(%deletions) > 0) {
11555: foreach my $key (keys(%deletions)) {
11556: if ($predelallitems{$key} ne '') {
11557: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
11558: }
11559: }
11560: }
11561: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 11562: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 11563: if (ref($chkcats[0]) eq 'ARRAY') {
11564: my $depth = 0;
11565: my $chg = 0;
11566: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
11567: my $name = $chkcats[0][$i];
11568: my $item;
11569: if ($name eq '') {
11570: $chg ++;
11571: } else {
11572: $item = &escape($name).'::0';
11573: if ($chg) {
1.57 raeburn 11574: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 11575: }
11576: $depth ++;
1.57 raeburn 11577: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 11578: $depth --;
11579: }
11580: }
11581: }
1.57 raeburn 11582: }
11583: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11584: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 11585: if ($putresult eq 'ok') {
1.57 raeburn 11586: my %title = (
1.120 raeburn 11587: togglecats => 'Show/Hide a course in catalog',
11588: categorize => 'Assign a category to a course',
11589: togglecatscomm => 'Show/Hide a community in catalog',
11590: categorizecomm => 'Assign a category to a community',
1.57 raeburn 11591: );
11592: my %level = (
1.120 raeburn 11593: dom => 'set in Domain ("Modify Course/Community")',
11594: crs => 'set in Course ("Course Configuration")',
11595: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 11596: none => 'No catalog',
11597: std => 'Standard catalog',
11598: domonly => 'Domain-only catalog',
11599: codesrch => 'Code search form',
1.57 raeburn 11600: );
1.48 raeburn 11601: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 11602: if ($changes{'togglecats'}) {
11603: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
11604: }
11605: if ($changes{'categorize'}) {
11606: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 11607: }
1.120 raeburn 11608: if ($changes{'togglecatscomm'}) {
11609: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
11610: }
11611: if ($changes{'categorizecomm'}) {
11612: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
11613: }
1.238 raeburn 11614: if ($changes{'unauth'}) {
11615: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
11616: }
11617: if ($changes{'auth'}) {
11618: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
11619: }
1.57 raeburn 11620: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11621: my $cathash;
11622: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
11623: $cathash = $domconfig{'coursecategories'}{'cats'};
11624: } else {
11625: $cathash = {};
11626: }
11627: my (@cats,@trails,%allitems);
11628: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
11629: if (keys(%deletions) > 0) {
11630: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
11631: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
11632: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
11633: }
11634: $resulttext .= '</ul></li>';
11635: }
11636: if (keys(%reorderings) > 0) {
11637: my %sort_by_trail;
11638: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
11639: foreach my $key (keys(%reorderings)) {
11640: if ($allitems{$key} ne '') {
11641: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11642: }
1.48 raeburn 11643: }
1.57 raeburn 11644: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11645: $resulttext .= '<li>'.$trails[$trail].'</li>';
11646: }
11647: $resulttext .= '</ul></li>';
1.48 raeburn 11648: }
1.57 raeburn 11649: if (keys(%adds) > 0) {
11650: my %sort_by_trail;
11651: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
11652: foreach my $key (keys(%adds)) {
11653: if ($allitems{$key} ne '') {
11654: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11655: }
11656: }
11657: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11658: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 11659: }
1.57 raeburn 11660: $resulttext .= '</ul></li>';
1.48 raeburn 11661: }
11662: }
11663: $resulttext .= '</ul>';
1.239 raeburn 11664: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 11665: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11666: if ($changes{'auth'}) {
11667: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
11668: }
11669: if ($changes{'unauth'}) {
11670: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
11671: }
11672: my $cachetime = 24*60*60;
11673: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 11674: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 11675: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 11676: }
11677: }
1.48 raeburn 11678: } else {
11679: $resulttext = '<span class="LC_error">'.
1.57 raeburn 11680: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 11681: }
11682: } else {
1.120 raeburn 11683: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 11684: }
11685: return $resulttext;
11686: }
11687:
1.69 raeburn 11688: sub modify_serverstatuses {
11689: my ($dom,%domconfig) = @_;
11690: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
11691: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
11692: %currserverstatus = %{$domconfig{'serverstatuses'}};
11693: }
11694: my @pages = &serverstatus_pages();
11695: foreach my $type (@pages) {
11696: $newserverstatus{$type}{'namedusers'} = '';
11697: $newserverstatus{$type}{'machines'} = '';
11698: if (defined($env{'form.'.$type.'_namedusers'})) {
11699: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
11700: my @okusers;
11701: foreach my $user (@users) {
11702: my ($uname,$udom) = split(/:/,$user);
11703: if (($udom =~ /^$match_domain$/) &&
11704: (&Apache::lonnet::domain($udom)) &&
11705: ($uname =~ /^$match_username$/)) {
11706: if (!grep(/^\Q$user\E/,@okusers)) {
11707: push(@okusers,$user);
11708: }
11709: }
11710: }
11711: if (@okusers > 0) {
11712: @okusers = sort(@okusers);
11713: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
11714: }
11715: }
11716: if (defined($env{'form.'.$type.'_machines'})) {
11717: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
11718: my @okmachines;
11719: foreach my $ip (@machines) {
11720: my @parts = split(/\./,$ip);
11721: next if (@parts < 4);
11722: my $badip = 0;
11723: for (my $i=0; $i<4; $i++) {
11724: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
11725: $badip = 1;
11726: last;
11727: }
11728: }
11729: if (!$badip) {
11730: push(@okmachines,$ip);
11731: }
11732: }
11733: @okmachines = sort(@okmachines);
11734: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
11735: }
11736: }
11737: my %serverstatushash = (
11738: serverstatuses => \%newserverstatus,
11739: );
11740: foreach my $type (@pages) {
1.83 raeburn 11741: foreach my $setting ('namedusers','machines') {
1.84 raeburn 11742: my (@current,@new);
1.83 raeburn 11743: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 11744: if ($currserverstatus{$type}{$setting} ne '') {
11745: @current = split(/,/,$currserverstatus{$type}{$setting});
11746: }
11747: }
11748: if ($newserverstatus{$type}{$setting} ne '') {
11749: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 11750: }
11751: if (@current > 0) {
11752: if (@new > 0) {
11753: foreach my $item (@current) {
11754: if (!grep(/^\Q$item\E$/,@new)) {
11755: $changes{$type}{$setting} = 1;
1.82 raeburn 11756: last;
11757: }
11758: }
1.84 raeburn 11759: foreach my $item (@new) {
11760: if (!grep(/^\Q$item\E$/,@current)) {
11761: $changes{$type}{$setting} = 1;
11762: last;
1.82 raeburn 11763: }
11764: }
11765: } else {
1.83 raeburn 11766: $changes{$type}{$setting} = 1;
1.69 raeburn 11767: }
1.83 raeburn 11768: } elsif (@new > 0) {
11769: $changes{$type}{$setting} = 1;
1.69 raeburn 11770: }
11771: }
11772: }
11773: if (keys(%changes) > 0) {
1.81 raeburn 11774: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11775: my $putresult = &Apache::lonnet::put_dom('configuration',
11776: \%serverstatushash,$dom);
11777: if ($putresult eq 'ok') {
11778: $resulttext .= &mt('Changes made:').'<ul>';
11779: foreach my $type (@pages) {
1.84 raeburn 11780: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 11781: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 11782: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 11783: if ($newserverstatus{$type}{'namedusers'} eq '') {
11784: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
11785: } else {
11786: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
11787: }
1.84 raeburn 11788: }
11789: if ($changes{$type}{'machines'}) {
1.69 raeburn 11790: if ($newserverstatus{$type}{'machines'} eq '') {
11791: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
11792: } else {
11793: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
11794: }
11795:
11796: }
11797: $resulttext .= '</ul></li>';
11798: }
11799: }
11800: $resulttext .= '</ul>';
11801: } else {
11802: $resulttext = '<span class="LC_error">'.
11803: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
11804:
11805: }
11806: } else {
11807: $resulttext = &mt('No changes made to access to server status pages');
11808: }
11809: return $resulttext;
11810: }
11811:
1.118 jms 11812: sub modify_helpsettings {
1.122 jms 11813: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 11814: my ($resulttext,$errors,%changes,%helphash);
11815: my %defaultchecked = ('submitbugs' => 'on');
11816: my @offon = ('off','on');
1.118 jms 11817: my @toggles = ('submitbugs');
1.282 raeburn 11818: my %current = ('submitbugs' => '');
1.118 jms 11819: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 11820: %current = %{$domconfig{'helpsettings'}};
11821: }
11822: foreach my $item (@toggles) {
11823: if ($defaultchecked{$item} eq 'on') {
11824: if ($current{$item} eq '') {
11825: if ($env{'form.'.$item} eq '0') {
11826: $changes{$item} = 1;
11827: }
11828: } elsif ($current{$item} ne $env{'form.'.$item}) {
11829: $changes{$item} = 1;
11830: }
11831: } elsif ($defaultchecked{$item} eq 'off') {
11832: if ($current{$item} eq '') {
11833: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 11834: $changes{$item} = 1;
11835: }
1.282 raeburn 11836: } elsif ($current{$item} ne $env{'form.'.$item}) {
11837: $changes{$item} = 1;
11838: }
11839: }
11840: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
11841: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
11842: }
11843: }
11844:
11845: my @modify = &Apache::loncommon::get_env_multiple('form.modifycusthelp');
11846: my $confname = $dom.'-domainconfig';
11847: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
11848: if (@modify) {
11849: foreach my $num (@modify) {
11850: my $rolename = $env{'form.custhelprole'.$num};
11851: if ($rolename ne '') {
11852: if (exists($existing{'rolesdef_'.$rolename})) {
11853: my $prefix = 'custhelp'.$num;
11854: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
11855: my %currprivs;
11856: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
11857: split(/\_/,$existing{'rolesdef_'.$rolename});
11858: foreach my $level ('c','d','s') {
11859: if ($newprivs{$level} ne $currprivs{$level}) {
11860: $changes{'customrole'}{$rolename} = 1;
11861: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
11862: $newprivs{'c'},$confname,$dom);
11863: last;
11864: }
1.166 raeburn 11865: }
11866: }
11867: }
1.282 raeburn 11868: }
11869: }
11870: if ($env{'form.newcusthelp'} ne '') {
11871: my $prefix = 'custhelp'.$env{'form.newcusthelp'};
11872: my $rolename = $env{'form.newcusthelpname'};
11873: $rolename=~s/[^A-Za-z0-9]//gs;
11874: if ($rolename ne '') {
11875: unless(exists($existing{'rolesdef_'.$rolename})) {
1.283 raeburn 11876: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
11877: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
11878: $newprivs{'c'},$confname,$dom);
1.282 raeburn 11879: if ($result eq 'ok') {
11880: $changes{'newcustomrole'} = $rolename;
11881: } else {
1.283 raeburn 11882: $errors .= '<li><span class="LC_error">'.
11883: &mt('An error occurred storing the new custom role: [_1]',
11884: $result).'</span></li>';
1.282 raeburn 11885: }
1.166 raeburn 11886: }
11887: }
1.118 jms 11888: }
1.282 raeburn 11889:
1.123 jms 11890: my $putresult;
11891: if (keys(%changes) > 0) {
1.166 raeburn 11892: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 11893: if ($putresult eq 'ok') {
1.166 raeburn 11894: $resulttext = &mt('Changes made:').'<ul>';
11895: foreach my $item (sort(keys(%changes))) {
11896: if ($item eq 'submitbugs') {
11897: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
11898: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
11899: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 11900: } elsif ($item eq 'customrole') {
11901: if (ref($changes{'customrole'}) eq 'HASH') {
11902: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
11903: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
11904: $role).'</li>';
11905: }
11906: }
11907: } elsif ($item eq 'newcustomrole') {
11908: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
11909: $changes{'newcustomrole'}).'</li>';
1.166 raeburn 11910: }
11911: }
11912: $resulttext .= '</ul>';
11913: } else {
11914: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 11915: $errors .= '<li><span class="LC_error">'.
11916: &mt('An error occurred storing the settings: [_1]',
11917: $putresult).'</span></li>';
1.166 raeburn 11918: }
1.118 jms 11919: }
11920: if ($errors) {
1.168 raeburn 11921: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 11922: $errors.'</ul>';
11923: }
11924: return $resulttext;
11925: }
11926:
1.121 raeburn 11927: sub modify_coursedefaults {
1.212 raeburn 11928: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 11929: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 11930: my %defaultchecked = (
11931: 'canuse_pdfforms' => 'off',
11932: 'uselcmath' => 'on',
11933: 'usejsme' => 'on'
11934: );
11935: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 11936: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 11937: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
11938: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
11939: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 11940: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 11941: my %staticdefaults = (
11942: anonsurvey_threshold => 10,
11943: uploadquota => 500,
1.257 raeburn 11944: postsubmit => 60,
1.276 raeburn 11945: mysqltables => 172800,
1.198 raeburn 11946: );
1.121 raeburn 11947:
11948: $defaultshash{'coursedefaults'} = {};
11949:
11950: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
11951: if ($domconfig{'coursedefaults'} eq '') {
11952: $domconfig{'coursedefaults'} = {};
11953: }
11954: }
11955:
11956: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
11957: foreach my $item (@toggles) {
11958: if ($defaultchecked{$item} eq 'on') {
11959: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11960: ($env{'form.'.$item} eq '0')) {
11961: $changes{$item} = 1;
1.192 raeburn 11962: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 11963: $changes{$item} = 1;
11964: }
11965: } elsif ($defaultchecked{$item} eq 'off') {
11966: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11967: ($env{'form.'.$item} eq '1')) {
11968: $changes{$item} = 1;
11969: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
11970: $changes{$item} = 1;
11971: }
11972: }
11973: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
11974: }
1.198 raeburn 11975: foreach my $item (@numbers) {
11976: my ($currdef,$newdef);
1.208 raeburn 11977: $newdef = $env{'form.'.$item};
1.198 raeburn 11978: if ($item eq 'anonsurvey_threshold') {
11979: $currdef = $domconfig{'coursedefaults'}{$item};
11980: $newdef =~ s/\D//g;
11981: if ($newdef eq '' || $newdef < 1) {
11982: $newdef = 1;
11983: }
11984: $defaultshash{'coursedefaults'}{$item} = $newdef;
11985: } else {
1.276 raeburn 11986: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
11987: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
11988: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 11989: }
11990: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 11991: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 11992: }
11993: if ($currdef ne $newdef) {
11994: my $staticdef;
11995: if ($item eq 'anonsurvey_threshold') {
11996: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
11997: $changes{$item} = 1;
11998: }
1.276 raeburn 11999: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
12000: my $setting = $1;
12001: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
12002: $changes{$setting} = 1;
1.198 raeburn 12003: }
12004: }
1.139 raeburn 12005: }
12006: }
1.264 raeburn 12007: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
12008: my @currclonecode;
12009: if (ref($currclone) eq 'HASH') {
12010: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
12011: @currclonecode = @{$currclone->{'instcode'}};
12012: }
12013: }
12014: my $newclone;
12015: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
12016: $newclone = $env{'form.canclone'};
12017: }
12018: if ($newclone eq 'instcode') {
12019: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
12020: my (%codedefaults,@code_order,@clonecode);
12021: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
12022: \@code_order);
12023: foreach my $item (@code_order) {
12024: if (grep(/^\Q$item\E$/,@newcodes)) {
12025: push(@clonecode,$item);
12026: }
12027: }
12028: if (@clonecode) {
12029: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
12030: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
12031: if (@diffs) {
12032: $changes{'canclone'} = 1;
12033: }
12034: } else {
12035: $newclone eq '';
12036: }
12037: } elsif ($newclone ne '') {
12038: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
12039: }
12040: if ($newclone ne $currclone) {
12041: $changes{'canclone'} = 1;
12042: }
1.257 raeburn 12043: my %credits;
12044: foreach my $type (@types) {
12045: unless ($type eq 'community') {
12046: $credits{$type} = $env{'form.'.$type.'_credits'};
12047: $credits{$type} =~ s/[^\d.]+//g;
12048: }
12049: }
12050: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
12051: ($env{'form.coursecredits'} eq '1')) {
12052: $changes{'coursecredits'} = 1;
12053: foreach my $type (keys(%credits)) {
12054: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
12055: }
12056: } else {
12057: if ($env{'form.coursecredits'} eq '1') {
12058: foreach my $type (@types) {
12059: unless ($type eq 'community') {
12060: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
12061: $changes{'coursecredits'} = 1;
12062: }
12063: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
12064: }
12065: }
12066: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
12067: foreach my $type (@types) {
12068: unless ($type eq 'community') {
12069: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
12070: $changes{'coursecredits'} = 1;
12071: last;
12072: }
12073: }
12074: }
12075: }
12076: }
12077: if ($env{'form.postsubmit'} eq '1') {
12078: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
12079: my %currtimeout;
12080: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12081: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
12082: $changes{'postsubmit'} = 1;
12083: }
12084: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
12085: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
12086: }
12087: } else {
12088: $changes{'postsubmit'} = 1;
12089: }
12090: foreach my $type (@types) {
12091: my $timeout = $env{'form.'.$type.'_timeout'};
12092: $timeout =~ s/\D//g;
12093: if ($timeout == $staticdefaults{'postsubmit'}) {
12094: $timeout = '';
12095: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
12096: $timeout = '0';
12097: }
12098: unless ($timeout eq '') {
12099: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
12100: }
12101: if (exists($currtimeout{$type})) {
12102: if ($timeout ne $currtimeout{$type}) {
12103: $changes{'postsubmit'} = 1;
12104: }
12105: } elsif ($timeout ne '') {
12106: $changes{'postsubmit'} = 1;
12107: }
12108: }
12109: } else {
12110: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
12111: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12112: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
12113: $changes{'postsubmit'} = 1;
12114: }
12115: } else {
12116: $changes{'postsubmit'} = 1;
12117: }
1.192 raeburn 12118: }
1.121 raeburn 12119: }
12120: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12121: $dom);
12122: if ($putresult eq 'ok') {
12123: if (keys(%changes) > 0) {
1.213 raeburn 12124: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 12125: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 12126: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.276 raeburn 12127: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.257 raeburn 12128: foreach my $item ('canuse_pdfforms','uselcmath','usejsme') {
12129: if ($changes{$item}) {
12130: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
12131: }
12132: }
1.192 raeburn 12133: if ($changes{'coursecredits'}) {
12134: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 12135: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
12136: $domdefaults{$type.'credits'} =
12137: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
12138: }
12139: }
12140: }
12141: if ($changes{'postsubmit'}) {
12142: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12143: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
12144: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
12145: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
12146: $domdefaults{$type.'postsubtimeout'} =
12147: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
12148: }
12149: }
1.192 raeburn 12150: }
12151: }
1.198 raeburn 12152: if ($changes{'uploadquota'}) {
12153: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
12154: foreach my $type (@types) {
12155: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
12156: }
12157: }
12158: }
1.264 raeburn 12159: if ($changes{'canclone'}) {
12160: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
12161: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
12162: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
12163: if (@clonecodes) {
12164: $domdefaults{'canclone'} = join('+',@clonecodes);
12165: }
12166: }
12167: } else {
12168: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
12169: }
12170: }
1.121 raeburn 12171: my $cachetime = 24*60*60;
12172: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 12173: if (ref($lastactref) eq 'HASH') {
12174: $lastactref->{'domdefaults'} = 1;
12175: }
1.121 raeburn 12176: }
12177: $resulttext = &mt('Changes made:').'<ul>';
12178: foreach my $item (sort(keys(%changes))) {
12179: if ($item eq 'canuse_pdfforms') {
12180: if ($env{'form.'.$item} eq '1') {
12181: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
12182: } else {
12183: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
12184: }
1.257 raeburn 12185: } elsif ($item eq 'uselcmath') {
12186: if ($env{'form.'.$item} eq '1') {
12187: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
12188: } else {
12189: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
12190: }
12191: } elsif ($item eq 'usejsme') {
12192: if ($env{'form.'.$item} eq '1') {
12193: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
12194: } else {
12195: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
12196: }
1.139 raeburn 12197: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 12198: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 12199: } elsif ($item eq 'uploadquota') {
12200: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
12201: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
12202: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
12203: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 12204: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 12205: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 12206: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
12207: '</ul>'.
12208: '</li>';
12209: } else {
12210: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
12211: }
1.276 raeburn 12212: } elsif ($item eq 'mysqltables') {
12213: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
12214: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
12215: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
12216: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
12217: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
12218: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
12219: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
12220: '</ul>'.
12221: '</li>';
12222: } else {
12223: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
12224: }
1.257 raeburn 12225: } elsif ($item eq 'postsubmit') {
12226: if ($domdefaults{'postsubmit'} eq 'off') {
12227: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
12228: } else {
12229: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
12230: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12231: $resulttext .= &mt('durations:').'<ul>';
12232: foreach my $type (@types) {
12233: $resulttext .= '<li>';
12234: my $timeout;
12235: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
12236: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
12237: }
12238: my $display;
12239: if ($timeout eq '0') {
12240: $display = &mt('unlimited');
12241: } elsif ($timeout eq '') {
12242: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
12243: } else {
12244: $display = &mt('[quant,_1,second]',$timeout);
12245: }
12246: if ($type eq 'community') {
12247: $resulttext .= &mt('Communities');
12248: } elsif ($type eq 'official') {
12249: $resulttext .= &mt('Official courses');
12250: } elsif ($type eq 'unofficial') {
12251: $resulttext .= &mt('Unofficial courses');
12252: } elsif ($type eq 'textbook') {
12253: $resulttext .= &mt('Textbook courses');
1.271 raeburn 12254: } elsif ($type eq 'placement') {
12255: $resulttext .= &mt('Placement tests');
1.257 raeburn 12256: }
12257: $resulttext .= ' -- '.$display.'</li>';
12258: }
12259: $resulttext .= '</ul>';
12260: }
12261: $resulttext .= '</li>';
12262: }
1.192 raeburn 12263: } elsif ($item eq 'coursecredits') {
12264: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
12265: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 12266: ($domdefaults{'unofficialcredits'} eq '') &&
12267: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 12268: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
12269: } else {
12270: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
12271: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
12272: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 12273: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 12274: '</ul>'.
12275: '</li>';
12276: }
12277: } else {
12278: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
12279: }
1.264 raeburn 12280: } elsif ($item eq 'canclone') {
12281: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
12282: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
12283: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
12284: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
12285: }
12286: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
12287: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
12288: } else {
12289: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
12290: }
1.140 raeburn 12291: }
1.121 raeburn 12292: }
12293: $resulttext .= '</ul>';
12294: } else {
12295: $resulttext = &mt('No changes made to course defaults');
12296: }
12297: } else {
12298: $resulttext = '<span class="LC_error">'.
12299: &mt('An error occurred: [_1]',$putresult).'</span>';
12300: }
12301: return $resulttext;
12302: }
12303:
1.231 raeburn 12304: sub modify_selfenrollment {
12305: my ($dom,$lastactref,%domconfig) = @_;
12306: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 12307: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 12308: my %titles = &tool_titles();
1.232 raeburn 12309: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
12310: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 12311: $ordered{'default'} = ['types','registered','approval','limit'];
12312:
12313: my (%roles,%shown,%toplevel);
12314: $roles{'0'} = &Apache::lonnet::plaintext('dc');
12315:
12316: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
12317: if ($domconfig{'selfenrollment'} eq '') {
12318: $domconfig{'selfenrollment'} = {};
12319: }
12320: }
12321: %toplevel = (
12322: admin => 'Configuration Rights',
12323: default => 'Default settings',
12324: validation => 'Validation of self-enrollment requests',
12325: );
1.233 raeburn 12326: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 12327:
12328: if (ref($ordered{'admin'}) eq 'ARRAY') {
12329: foreach my $item (@{$ordered{'admin'}}) {
12330: foreach my $type (@types) {
12331: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
12332: $selfenrollhash{'admin'}{$type}{$item} = 1;
12333: } else {
12334: $selfenrollhash{'admin'}{$type}{$item} = 0;
12335: }
12336: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
12337: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
12338: if ($selfenrollhash{'admin'}{$type}{$item} ne
12339: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
12340: push(@{$changes{'admin'}{$type}},$item);
12341: }
12342: } else {
12343: if (!$selfenrollhash{'admin'}{$type}{$item}) {
12344: push(@{$changes{'admin'}{$type}},$item);
12345: }
12346: }
12347: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
12348: push(@{$changes{'admin'}{$type}},$item);
12349: }
12350: }
12351: }
12352: }
12353:
12354: foreach my $item (@{$ordered{'default'}}) {
12355: foreach my $type (@types) {
12356: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
12357: if ($item eq 'types') {
12358: unless (($value eq 'all') || ($value eq 'dom')) {
12359: $value = '';
12360: }
12361: } elsif ($item eq 'registered') {
12362: unless ($value eq '1') {
12363: $value = 0;
12364: }
12365: } elsif ($item eq 'approval') {
12366: unless ($value =~ /^[012]$/) {
12367: $value = 0;
12368: }
12369: } else {
12370: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12371: $value = 'none';
12372: }
12373: }
12374: $selfenrollhash{'default'}{$type}{$item} = $value;
12375: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
12376: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12377: if ($selfenrollhash{'default'}{$type}{$item} ne
12378: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
12379: push(@{$changes{'default'}{$type}},$item);
12380: }
12381: } else {
12382: push(@{$changes{'default'}{$type}},$item);
12383: }
12384: } else {
12385: push(@{$changes{'default'}{$type}},$item);
12386: }
12387: if ($item eq 'limit') {
12388: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12389: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
12390: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
12391: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
12392: }
12393: } else {
12394: $selfenrollhash{'default'}{$type}{'cap'} = '';
12395: }
12396: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12397: if ($selfenrollhash{'default'}{$type}{'cap'} ne
12398: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
12399: push(@{$changes{'default'}{$type}},'cap');
12400: }
12401: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
12402: push(@{$changes{'default'}{$type}},'cap');
12403: }
12404: }
12405: }
12406: }
12407:
12408: foreach my $item (@{$itemsref}) {
12409: if ($item eq 'fields') {
12410: my @changed;
12411: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
12412: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
12413: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
12414: }
12415: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12416: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
12417: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
12418: $domconfig{'selfenrollment'}{'validation'}{$item});
12419: } else {
12420: @changed = @{$selfenrollhash{'validation'}{$item}};
12421: }
12422: } else {
12423: @changed = @{$selfenrollhash{'validation'}{$item}};
12424: }
12425: if (@changed) {
12426: if ($selfenrollhash{'validation'}{$item}) {
12427: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
12428: } else {
12429: $changes{'validation'}{$item} = &mt('None');
12430: }
12431: }
12432: } else {
12433: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
12434: if ($item eq 'markup') {
12435: if ($env{'form.selfenroll_validation_'.$item}) {
12436: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
12437: }
12438: }
12439: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12440: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
12441: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
12442: }
12443: }
12444: }
12445: }
12446:
12447: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
12448: $dom);
12449: if ($putresult eq 'ok') {
12450: if (keys(%changes) > 0) {
12451: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12452: $resulttext = &mt('Changes made:').'<ul>';
12453: foreach my $key ('admin','default','validation') {
12454: if (ref($changes{$key}) eq 'HASH') {
12455: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
12456: if ($key eq 'validation') {
12457: foreach my $item (@{$itemsref}) {
12458: if (exists($changes{$key}{$item})) {
12459: if ($item eq 'markup') {
12460: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12461: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
12462: } else {
12463: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12464: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
12465: }
12466: }
12467: }
12468: } else {
12469: foreach my $type (@types) {
12470: if ($type eq 'community') {
12471: $roles{'1'} = &mt('Community personnel');
12472: } else {
12473: $roles{'1'} = &mt('Course personnel');
12474: }
12475: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 12476: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12477: if ($key eq 'admin') {
12478: my @mgrdc = ();
12479: if (ref($ordered{$key}) eq 'ARRAY') {
12480: foreach my $item (@{$ordered{'admin'}}) {
12481: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12482: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
12483: push(@mgrdc,$item);
12484: }
12485: }
12486: }
12487: if (@mgrdc) {
12488: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
12489: } else {
12490: delete($domdefaults{$type.'selfenrolladmdc'});
12491: }
12492: }
12493: } else {
12494: if (ref($ordered{$key}) eq 'ARRAY') {
12495: foreach my $item (@{$ordered{$key}}) {
12496: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12497: $domdefaults{$type.'selfenroll'.$item} =
12498: $selfenrollhash{$key}{$type}{$item};
12499: }
12500: }
12501: }
12502: }
12503: }
1.231 raeburn 12504: $resulttext .= '<li>'.$titles{$type}.'<ul>';
12505: foreach my $item (@{$ordered{$key}}) {
12506: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12507: $resulttext .= '<li>';
12508: if ($key eq 'admin') {
12509: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
12510: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
12511: } else {
12512: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
12513: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
12514: }
12515: $resulttext .= '</li>';
12516: }
12517: }
12518: $resulttext .= '</ul></li>';
12519: }
12520: }
12521: $resulttext .= '</ul></li>';
12522: }
12523: }
1.232 raeburn 12524: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
12525: my $cachetime = 24*60*60;
12526: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12527: if (ref($lastactref) eq 'HASH') {
12528: $lastactref->{'domdefaults'} = 1;
12529: }
12530: }
1.231 raeburn 12531: }
12532: $resulttext .= '</ul>';
12533: } else {
12534: $resulttext = &mt('No changes made to self-enrollment settings');
12535: }
12536: } else {
12537: $resulttext = '<span class="LC_error">'.
12538: &mt('An error occurred: [_1]',$putresult).'</span>';
12539: }
12540: return $resulttext;
12541: }
12542:
1.137 raeburn 12543: sub modify_usersessions {
1.212 raeburn 12544: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 12545: my @hostingtypes = ('version','excludedomain','includedomain');
12546: my @offloadtypes = ('primary','default');
12547: my %types = (
12548: remote => \@hostingtypes,
12549: hosted => \@hostingtypes,
12550: spares => \@offloadtypes,
12551: );
12552: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 12553: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 12554: my (%by_ip,%by_location,@intdoms,@instdoms);
12555: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 12556: my @locations = sort(keys(%by_location));
1.137 raeburn 12557: my (%defaultshash,%changes);
12558: foreach my $prefix (@prefixes) {
12559: $defaultshash{'usersessions'}{$prefix} = {};
12560: }
1.212 raeburn 12561: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 12562: my $resulttext;
1.138 raeburn 12563: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 12564: foreach my $prefix (@prefixes) {
1.145 raeburn 12565: next if ($prefix eq 'spares');
12566: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 12567: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
12568: if ($type eq 'version') {
12569: my $value = $env{'form.'.$prefix.'_'.$type};
12570: my $okvalue;
12571: if ($value ne '') {
12572: if (grep(/^\Q$value\E$/,@lcversions)) {
12573: $okvalue = $value;
12574: }
12575: }
12576: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12577: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12578: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
12579: if ($inuse == 0) {
12580: $changes{$prefix}{$type} = 1;
12581: } else {
12582: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
12583: $changes{$prefix}{$type} = 1;
12584: }
12585: if ($okvalue ne '') {
12586: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12587: }
12588: }
12589: } else {
12590: if (($inuse == 1) && ($okvalue ne '')) {
12591: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12592: $changes{$prefix}{$type} = 1;
12593: }
12594: }
12595: } else {
12596: if (($inuse == 1) && ($okvalue ne '')) {
12597: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12598: $changes{$prefix}{$type} = 1;
12599: }
12600: }
12601: } else {
12602: if (($inuse == 1) && ($okvalue ne '')) {
12603: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12604: $changes{$prefix}{$type} = 1;
12605: }
12606: }
12607: } else {
12608: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
12609: my @okvals;
12610: foreach my $val (@vals) {
1.138 raeburn 12611: if ($val =~ /:/) {
12612: my @items = split(/:/,$val);
12613: foreach my $item (@items) {
12614: if (ref($by_location{$item}) eq 'ARRAY') {
12615: push(@okvals,$item);
12616: }
12617: }
12618: } else {
12619: if (ref($by_location{$val}) eq 'ARRAY') {
12620: push(@okvals,$val);
12621: }
1.137 raeburn 12622: }
12623: }
12624: @okvals = sort(@okvals);
12625: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12626: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12627: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12628: if ($inuse == 0) {
12629: $changes{$prefix}{$type} = 1;
12630: } else {
12631: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12632: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
12633: if (@changed > 0) {
12634: $changes{$prefix}{$type} = 1;
12635: }
12636: }
12637: } else {
12638: if ($inuse == 1) {
12639: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12640: $changes{$prefix}{$type} = 1;
12641: }
12642: }
12643: } else {
12644: if ($inuse == 1) {
12645: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12646: $changes{$prefix}{$type} = 1;
12647: }
12648: }
12649: } else {
12650: if ($inuse == 1) {
12651: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12652: $changes{$prefix}{$type} = 1;
12653: }
12654: }
12655: }
12656: }
12657: }
1.145 raeburn 12658:
12659: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 12660: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 12661: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
12662: my $savespares;
12663:
12664: foreach my $lonhost (sort(keys(%servers))) {
12665: my $serverhomeID =
12666: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 12667: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 12668: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
12669: my %spareschg;
12670: foreach my $type (@{$types{'spares'}}) {
12671: my @okspares;
12672: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
12673: foreach my $server (@checked) {
1.152 raeburn 12674: if (&Apache::lonnet::hostname($server) ne '') {
12675: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
12676: unless (grep(/^\Q$server\E$/,@okspares)) {
12677: push(@okspares,$server);
12678: }
1.145 raeburn 12679: }
12680: }
12681: }
12682: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
12683: my $newspare;
1.152 raeburn 12684: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
12685: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 12686: $newspare = $new;
12687: }
12688: }
1.152 raeburn 12689: my @spares;
12690: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
12691: @spares = sort(@okspares,$newspare);
12692: } else {
12693: @spares = sort(@okspares);
12694: }
12695: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 12696: if (ref($spareid{$lonhost}) eq 'HASH') {
12697: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 12698: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 12699: if (@diffs > 0) {
12700: $spareschg{$type} = 1;
12701: }
12702: }
12703: }
12704: }
12705: if (keys(%spareschg) > 0) {
12706: $changes{'spares'}{$lonhost} = \%spareschg;
12707: }
12708: }
1.261 raeburn 12709: $defaultshash{'usersessions'}{'offloadnow'} = {};
12710: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
12711: my @okoffload;
12712: if (@offloadnow) {
12713: foreach my $server (@offloadnow) {
12714: if (&Apache::lonnet::hostname($server) ne '') {
12715: unless (grep(/^\Q$server\E$/,@okoffload)) {
12716: push(@okoffload,$server);
12717: }
12718: }
12719: }
12720: if (@okoffload) {
12721: foreach my $lonhost (@okoffload) {
12722: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
12723: }
12724: }
12725: }
1.145 raeburn 12726: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12727: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
12728: if (ref($changes{'spares'}) eq 'HASH') {
12729: if (keys(%{$changes{'spares'}}) > 0) {
12730: $savespares = 1;
12731: }
12732: }
12733: } else {
12734: $savespares = 1;
12735: }
1.261 raeburn 12736: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
12737: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
12738: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
12739: $changes{'offloadnow'} = 1;
12740: last;
12741: }
12742: }
12743: unless ($changes{'offloadnow'}) {
12744: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
12745: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
12746: $changes{'offloadnow'} = 1;
12747: last;
12748: }
12749: }
12750: }
12751: } elsif (@okoffload) {
12752: $changes{'offloadnow'} = 1;
12753: }
12754: } elsif (@okoffload) {
12755: $changes{'offloadnow'} = 1;
1.145 raeburn 12756: }
1.147 raeburn 12757: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
12758: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 12759: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12760: $dom);
12761: if ($putresult eq 'ok') {
12762: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12763: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
12764: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
12765: }
12766: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
12767: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
12768: }
1.261 raeburn 12769: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12770: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
12771: }
1.137 raeburn 12772: }
12773: my $cachetime = 24*60*60;
12774: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 12775: if (ref($lastactref) eq 'HASH') {
12776: $lastactref->{'domdefaults'} = 1;
12777: }
1.147 raeburn 12778: if (keys(%changes) > 0) {
12779: my %lt = &usersession_titles();
12780: $resulttext = &mt('Changes made:').'<ul>';
12781: foreach my $prefix (@prefixes) {
12782: if (ref($changes{$prefix}) eq 'HASH') {
12783: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
12784: if ($prefix eq 'spares') {
12785: if (ref($changes{$prefix}) eq 'HASH') {
12786: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
12787: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 12788: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 12789: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
12790: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 12791: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
12792: foreach my $type (@{$types{$prefix}}) {
12793: if ($changes{$prefix}{$lonhost}{$type}) {
12794: my $offloadto = &mt('None');
12795: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
12796: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
12797: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
12798: }
1.145 raeburn 12799: }
1.147 raeburn 12800: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 12801: }
1.137 raeburn 12802: }
12803: }
1.147 raeburn 12804: $resulttext .= '</li>';
1.137 raeburn 12805: }
12806: }
1.147 raeburn 12807: } else {
12808: foreach my $type (@{$types{$prefix}}) {
12809: if (defined($changes{$prefix}{$type})) {
12810: my $newvalue;
12811: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12812: if (ref($defaultshash{'usersessions'}{$prefix})) {
12813: if ($type eq 'version') {
12814: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
12815: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12816: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
12817: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
12818: }
1.145 raeburn 12819: }
12820: }
12821: }
1.147 raeburn 12822: if ($newvalue eq '') {
12823: if ($type eq 'version') {
12824: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
12825: } else {
12826: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
12827: }
1.145 raeburn 12828: } else {
1.147 raeburn 12829: if ($type eq 'version') {
12830: $newvalue .= ' '.&mt('(or later)');
12831: }
12832: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 12833: }
1.137 raeburn 12834: }
12835: }
12836: }
1.147 raeburn 12837: $resulttext .= '</ul>';
1.137 raeburn 12838: }
12839: }
1.261 raeburn 12840: if ($changes{'offloadnow'}) {
12841: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12842: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
12843: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
12844: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
12845: $resulttext .= '<li>'.$lonhost.'</li>';
12846: }
12847: $resulttext .= '</ul>';
12848: } else {
12849: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
12850: }
12851: } else {
12852: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
12853: }
12854: }
1.147 raeburn 12855: $resulttext .= '</ul>';
12856: } else {
12857: $resulttext = $nochgmsg;
1.137 raeburn 12858: }
12859: } else {
12860: $resulttext = '<span class="LC_error">'.
12861: &mt('An error occurred: [_1]',$putresult).'</span>';
12862: }
12863: } else {
1.147 raeburn 12864: $resulttext = $nochgmsg;
1.137 raeburn 12865: }
12866: return $resulttext;
12867: }
12868:
1.275 raeburn 12869: sub modify_ssl {
12870: my ($dom,$lastactref,%domconfig) = @_;
12871: my (%by_ip,%by_location,@intdoms,@instdoms);
12872: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
12873: my @locations = sort(keys(%by_location));
12874: my %servers = &Apache::lonnet::internet_dom_servers($dom);
12875: my (%defaultshash,%changes);
12876: my $action = 'ssl';
12877: my @prefixes = ('connect','replication');
12878: foreach my $prefix (@prefixes) {
12879: $defaultshash{$action}{$prefix} = {};
12880: }
12881: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12882: my $resulttext;
12883: my %iphost = &Apache::lonnet::get_iphost();
12884: my @reptypes = ('certreq','nocertreq');
12885: my @connecttypes = ('dom','intdom','other');
12886: my %types = (
12887: connect => \@connecttypes,
12888: replication => \@reptypes,
12889: );
12890: foreach my $prefix (sort(keys(%types))) {
12891: foreach my $type (@{$types{$prefix}}) {
12892: if ($prefix eq 'connect') {
12893: my $value = 'yes';
12894: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
12895: $value = $env{'form.'.$prefix.'_'.$type};
12896: }
12897: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
12898: if ($domconfig{$action}{$prefix}{$type} ne '') {
12899: if ($value ne $domconfig{$action}{$prefix}{$type}) {
12900: $changes{$prefix}{$type} = 1;
12901: }
12902: $defaultshash{$action}{$prefix}{$type} = $value;
12903: } else {
12904: $defaultshash{$action}{$prefix}{$type} = $value;
12905: $changes{$prefix}{$type} = 1;
12906: }
12907: } else {
12908: $defaultshash{$action}{$prefix}{$type} = $value;
12909: $changes{$prefix}{$type} = 1;
12910: }
12911: if (($type eq 'dom') && (keys(%servers) == 1)) {
12912: delete($changes{$prefix}{$type});
12913: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
12914: delete($changes{$prefix}{$type});
12915: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
12916: delete($changes{$prefix}{$type});
12917: }
12918: } elsif ($prefix eq 'replication') {
12919: if (@locations > 0) {
12920: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
12921: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
12922: my @okvals;
12923: foreach my $val (@vals) {
12924: if ($val =~ /:/) {
12925: my @items = split(/:/,$val);
12926: foreach my $item (@items) {
12927: if (ref($by_location{$item}) eq 'ARRAY') {
12928: push(@okvals,$item);
12929: }
12930: }
12931: } else {
12932: if (ref($by_location{$val}) eq 'ARRAY') {
12933: push(@okvals,$val);
12934: }
12935: }
12936: }
12937: @okvals = sort(@okvals);
12938: if (ref($domconfig{$action}) eq 'HASH') {
12939: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
12940: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
12941: if ($inuse == 0) {
12942: $changes{$prefix}{$type} = 1;
12943: } else {
12944: $defaultshash{$action}{$prefix}{$type} = \@okvals;
12945: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
12946: if (@changed > 0) {
12947: $changes{$prefix}{$type} = 1;
12948: }
12949: }
12950: } else {
12951: if ($inuse == 1) {
12952: $defaultshash{$action}{$prefix}{$type} = \@okvals;
12953: $changes{$prefix}{$type} = 1;
12954: }
12955: }
12956: } else {
12957: if ($inuse == 1) {
12958: $defaultshash{$action}{$prefix}{$type} = \@okvals;
12959: $changes{$prefix}{$type} = 1;
12960: }
12961: }
12962: } else {
12963: if ($inuse == 1) {
12964: $defaultshash{$action}{$prefix}{$type} = \@okvals;
12965: $changes{$prefix}{$type} = 1;
12966: }
12967: }
12968: }
12969: }
12970: }
12971: }
12972: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
12973: if (keys(%changes) > 0) {
12974: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12975: $dom);
12976: if ($putresult eq 'ok') {
12977: if (ref($defaultshash{$action}) eq 'HASH') {
12978: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
12979: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
12980: }
12981: if (ref($defaultshash{$action}{'connect'}) eq 'HASH') {
12982: $domdefaults{'connect'} = $domconfig{$action}{'connect'};
12983: }
12984: }
12985: my $cachetime = 24*60*60;
12986: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12987: if (ref($lastactref) eq 'HASH') {
12988: $lastactref->{'domdefaults'} = 1;
12989: }
12990: if (keys(%changes) > 0) {
12991: my %titles = &ssl_titles();
12992: $resulttext = &mt('Changes made:').'<ul>';
12993: foreach my $prefix (@prefixes) {
12994: if (ref($changes{$prefix}) eq 'HASH') {
12995: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
12996: foreach my $type (@{$types{$prefix}}) {
12997: if (defined($changes{$prefix}{$type})) {
12998: my $newvalue;
12999: if (ref($defaultshash{$action}) eq 'HASH') {
13000: if (ref($defaultshash{$action}{$prefix})) {
13001: if ($prefix eq 'connect') {
13002: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
13003: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
13004: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
13005: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
13006: }
13007: }
13008: }
13009: if ($newvalue eq '') {
13010: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
13011: } else {
13012: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
13013: }
13014: }
13015: }
13016: }
13017: $resulttext .= '</ul>';
13018: }
13019: }
13020: } else {
13021: $resulttext = $nochgmsg;
13022: }
13023: } else {
13024: $resulttext = '<span class="LC_error">'.
13025: &mt('An error occurred: [_1]',$putresult).'</span>';
13026: }
13027: } else {
13028: $resulttext = $nochgmsg;
13029: }
13030: return $resulttext;
13031: }
13032:
1.279 raeburn 13033: sub modify_trust {
13034: my ($dom,$lastactref,%domconfig) = @_;
13035: my (%by_ip,%by_location,@intdoms,@instdoms);
13036: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
13037: my @locations = sort(keys(%by_location));
13038: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
13039: my @types = ('exc','inc');
13040: my (%defaultshash,%changes);
13041: foreach my $prefix (@prefixes) {
13042: $defaultshash{'trust'}{$prefix} = {};
13043: }
13044: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13045: my $resulttext;
13046: foreach my $prefix (@prefixes) {
13047: foreach my $type (@types) {
13048: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
13049: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
13050: my @okvals;
13051: foreach my $val (@vals) {
13052: if ($val =~ /:/) {
13053: my @items = split(/:/,$val);
13054: foreach my $item (@items) {
13055: if (ref($by_location{$item}) eq 'ARRAY') {
13056: push(@okvals,$item);
13057: }
13058: }
13059: } else {
13060: if (ref($by_location{$val}) eq 'ARRAY') {
13061: push(@okvals,$val);
13062: }
13063: }
13064: }
13065: @okvals = sort(@okvals);
13066: if (ref($domconfig{'trust'}) eq 'HASH') {
13067: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
13068: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
13069: if ($inuse == 0) {
13070: $changes{$prefix}{$type} = 1;
13071: } else {
13072: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
13073: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
13074: if (@changed > 0) {
13075: $changes{$prefix}{$type} = 1;
13076: }
13077: }
13078: } else {
13079: if ($inuse == 1) {
13080: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
13081: $changes{$prefix}{$type} = 1;
13082: }
13083: }
13084: } else {
13085: if ($inuse == 1) {
13086: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
13087: $changes{$prefix}{$type} = 1;
13088: }
13089: }
13090: } else {
13091: if ($inuse == 1) {
13092: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
13093: $changes{$prefix}{$type} = 1;
13094: }
13095: }
13096: }
13097: }
13098: my $nochgmsg = &mt('No changes made to trust settings.');
13099: if (keys(%changes) > 0) {
13100: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13101: $dom);
13102: if ($putresult eq 'ok') {
13103: if (ref($defaultshash{'trust'}) eq 'HASH') {
13104: foreach my $prefix (@prefixes) {
13105: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
13106: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
13107: }
13108: }
13109: }
13110: my $cachetime = 24*60*60;
13111: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13112: if (ref($lastactref) eq 'HASH') {
13113: $lastactref->{'domdefaults'} = 1;
13114: }
13115: if (keys(%changes) > 0) {
13116: my %lt = &trust_titles();
13117: $resulttext = &mt('Changes made:').'<ul>';
13118: foreach my $prefix (@prefixes) {
13119: if (ref($changes{$prefix}) eq 'HASH') {
13120: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
13121: foreach my $type (@types) {
13122: if (defined($changes{$prefix}{$type})) {
13123: my $newvalue;
13124: if (ref($defaultshash{'trust'}) eq 'HASH') {
13125: if (ref($defaultshash{'trust'}{$prefix})) {
13126: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
13127: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
13128: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
13129: }
13130: }
13131: }
13132: }
13133: if ($newvalue eq '') {
13134: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
13135: } else {
13136: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
13137: }
13138: }
13139: }
13140: $resulttext .= '</ul>';
13141: }
13142: }
13143: $resulttext .= '</ul>';
13144: } else {
13145: $resulttext = $nochgmsg;
13146: }
13147: } else {
13148: $resulttext = '<span class="LC_error">'.
13149: &mt('An error occurred: [_1]',$putresult).'</span>';
13150: }
13151: } else {
13152: $resulttext = $nochgmsg;
13153: }
13154: return $resulttext;
13155: }
13156:
1.150 raeburn 13157: sub modify_loadbalancing {
13158: my ($dom,%domconfig) = @_;
13159: my $primary_id = &Apache::lonnet::domain($dom,'primary');
13160: my $intdom = &Apache::lonnet::internet_dom($primary_id);
13161: my ($othertitle,$usertypes,$types) =
13162: &Apache::loncommon::sorted_inst_types($dom);
13163: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 13164: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 13165: my @sparestypes = ('primary','default');
13166: my %typetitles = &sparestype_titles();
13167: my $resulttext;
1.171 raeburn 13168: my (%currbalancer,%currtargets,%currrules,%existing);
13169: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
13170: %existing = %{$domconfig{'loadbalancing'}};
13171: }
13172: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
13173: \%currtargets,\%currrules);
13174: my ($saveloadbalancing,%defaultshash,%changes);
13175: my ($alltypes,$othertypes,$titles) =
13176: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
13177: my %ruletitles = &offloadtype_text();
13178: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
13179: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
13180: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
13181: if ($balancer eq '') {
13182: next;
13183: }
1.210 raeburn 13184: if (!exists($servers{$balancer})) {
1.171 raeburn 13185: if (exists($currbalancer{$balancer})) {
13186: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 13187: }
1.171 raeburn 13188: next;
13189: }
13190: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
13191: push(@{$changes{'delete'}},$balancer);
13192: next;
13193: }
13194: if (!exists($currbalancer{$balancer})) {
13195: push(@{$changes{'add'}},$balancer);
13196: }
13197: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
13198: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
13199: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
13200: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
13201: $saveloadbalancing = 1;
13202: }
13203: foreach my $sparetype (@sparestypes) {
13204: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
13205: my @offloadto;
13206: foreach my $target (@targets) {
13207: if (($servers{$target}) && ($target ne $balancer)) {
13208: if ($sparetype eq 'default') {
13209: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
13210: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 13211: }
13212: }
1.171 raeburn 13213: unless(grep(/^\Q$target\E$/,@offloadto)) {
13214: push(@offloadto,$target);
13215: }
1.150 raeburn 13216: }
13217: }
1.284 ! raeburn 13218: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
! 13219: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
! 13220: push(@offloadto,$balancer);
! 13221: }
! 13222: }
! 13223: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 13224: }
1.171 raeburn 13225: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 13226: foreach my $sparetype (@sparestypes) {
1.171 raeburn 13227: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
13228: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 13229: if (@targetdiffs > 0) {
1.171 raeburn 13230: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 13231: }
1.171 raeburn 13232: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
13233: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
13234: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 13235: }
13236: }
13237: }
13238: } else {
1.171 raeburn 13239: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 13240: foreach my $sparetype (@sparestypes) {
1.171 raeburn 13241: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
13242: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
13243: $changes{'curr'}{$balancer}{'targets'} = 1;
13244: }
1.150 raeburn 13245: }
13246: }
1.210 raeburn 13247: }
1.150 raeburn 13248: }
13249: my $ishomedom;
1.171 raeburn 13250: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
13251: $ishomedom = 1;
1.150 raeburn 13252: }
13253: if (ref($alltypes) eq 'ARRAY') {
13254: foreach my $type (@{$alltypes}) {
13255: my $rule;
1.210 raeburn 13256: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 13257: (!$ishomedom)) {
1.171 raeburn 13258: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
13259: }
13260: if ($rule eq 'specific') {
1.255 raeburn 13261: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
13262: if (exists($servers{$specifiedhost})) {
13263: $rule = $specifiedhost;
13264: }
1.150 raeburn 13265: }
1.171 raeburn 13266: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
13267: if (ref($currrules{$balancer}) eq 'HASH') {
13268: if ($rule ne $currrules{$balancer}{$type}) {
13269: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 13270: }
13271: } elsif ($rule ne '') {
1.171 raeburn 13272: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 13273: }
13274: }
13275: }
1.171 raeburn 13276: }
13277: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
13278: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
13279: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
13280: $defaultshash{'loadbalancing'} = {};
13281: }
13282: my $putresult = &Apache::lonnet::put_dom('configuration',
13283: \%defaultshash,$dom);
13284: if ($putresult eq 'ok') {
13285: if (keys(%changes) > 0) {
1.252 raeburn 13286: my %toupdate;
1.171 raeburn 13287: if (ref($changes{'delete'}) eq 'ARRAY') {
13288: foreach my $balancer (sort(@{$changes{'delete'}})) {
13289: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 13290: $toupdate{$balancer} = 1;
1.150 raeburn 13291: }
1.171 raeburn 13292: }
13293: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 13294: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 13295: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 13296: $toupdate{$balancer} = 1;
1.171 raeburn 13297: }
13298: }
13299: if (ref($changes{'curr'}) eq 'HASH') {
13300: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 13301: $toupdate{$balancer} = 1;
1.171 raeburn 13302: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
13303: if ($changes{'curr'}{$balancer}{'targets'}) {
13304: my %offloadstr;
13305: foreach my $sparetype (@sparestypes) {
13306: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
13307: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
13308: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
13309: }
13310: }
1.150 raeburn 13311: }
1.171 raeburn 13312: if (keys(%offloadstr) == 0) {
13313: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 13314: } else {
1.171 raeburn 13315: my $showoffload;
13316: foreach my $sparetype (@sparestypes) {
13317: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
13318: if (defined($offloadstr{$sparetype})) {
13319: $showoffload .= $offloadstr{$sparetype};
13320: } else {
13321: $showoffload .= &mt('None');
13322: }
13323: $showoffload .= (' 'x3);
13324: }
13325: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 13326: }
13327: }
13328: }
1.171 raeburn 13329: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
13330: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
13331: foreach my $type (@{$alltypes}) {
13332: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
13333: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
13334: my $balancetext;
13335: if ($rule eq '') {
13336: $balancetext = $ruletitles{'default'};
1.209 raeburn 13337: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.254 raeburn 13338: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
13339: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 13340: foreach my $sparetype (@sparestypes) {
13341: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
13342: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
13343: }
13344: }
1.253 raeburn 13345: foreach my $item (@{$alltypes}) {
13346: next if ($item =~ /^_LC_ipchange/);
13347: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
13348: if ($hasrule eq 'homeserver') {
13349: map { $toupdate{$_} = 1; } (keys(%libraryservers));
13350: } else {
13351: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
13352: if ($servers{$hasrule}) {
13353: $toupdate{$hasrule} = 1;
13354: }
13355: }
13356: }
13357: }
1.254 raeburn 13358: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
13359: $balancetext = $ruletitles{$rule};
13360: } else {
13361: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
13362: $balancetext = $ruletitles{'particular'}.' '.$receiver;
13363: if ($receiver) {
13364: $toupdate{$receiver};
13365: }
13366: }
13367: } else {
13368: $balancetext = $ruletitles{$rule};
1.252 raeburn 13369: }
1.171 raeburn 13370: } else {
13371: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
13372: }
1.210 raeburn 13373: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 13374: }
13375: }
13376: }
13377: }
1.252 raeburn 13378: if (keys(%toupdate)) {
13379: my %thismachine;
13380: my $updatedhere;
13381: my $cachetime = 60*60*24;
13382: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
13383: foreach my $lonhost (keys(%toupdate)) {
13384: if ($thismachine{$lonhost}) {
13385: unless ($updatedhere) {
13386: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
13387: $defaultshash{'loadbalancing'},
13388: $cachetime);
13389: $updatedhere = 1;
13390: }
13391: } else {
13392: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
13393: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
13394: }
13395: }
13396: }
1.150 raeburn 13397: }
1.171 raeburn 13398: }
13399: if ($resulttext ne '') {
13400: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 13401: } else {
13402: $resulttext = $nochgmsg;
13403: }
13404: } else {
1.171 raeburn 13405: $resulttext = $nochgmsg;
1.150 raeburn 13406: }
13407: } else {
1.171 raeburn 13408: $resulttext = '<span class="LC_error">'.
13409: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 13410: }
13411: } else {
1.171 raeburn 13412: $resulttext = $nochgmsg;
1.150 raeburn 13413: }
13414: return $resulttext;
13415: }
13416:
1.48 raeburn 13417: sub recurse_check {
13418: my ($chkcats,$categories,$depth,$name) = @_;
13419: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
13420: my $chg = 0;
13421: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
13422: my $category = $chkcats->[$depth]{$name}[$j];
13423: my $item;
13424: if ($category eq '') {
13425: $chg ++;
13426: } else {
13427: my $deeper = $depth + 1;
13428: $item = &escape($category).':'.&escape($name).':'.$depth;
13429: if ($chg) {
13430: $categories->{$item} -= $chg;
13431: }
13432: &recurse_check($chkcats,$categories,$deeper,$category);
13433: $deeper --;
13434: }
13435: }
13436: }
13437: return;
13438: }
13439:
13440: sub recurse_cat_deletes {
13441: my ($item,$coursecategories,$deletions) = @_;
13442: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13443: my $subdepth = $depth + 1;
13444: if (ref($coursecategories) eq 'HASH') {
13445: foreach my $subitem (keys(%{$coursecategories})) {
13446: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
13447: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
13448: delete($coursecategories->{$subitem});
13449: $deletions->{$subitem} = 1;
13450: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 13451: }
1.48 raeburn 13452: }
13453: }
13454: return;
13455: }
13456:
1.125 raeburn 13457: sub get_active_dcs {
13458: my ($dom) = @_;
1.191 raeburn 13459: my $now = time;
13460: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 13461: my %domcoords;
13462: my $numdcs = 0;
13463: foreach my $server (keys(%dompersonnel)) {
13464: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
13465: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191 raeburn 13466: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 13467: }
13468: }
13469: return %domcoords;
13470: }
13471:
13472: sub active_dc_picker {
1.191 raeburn 13473: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.235 raeburn 13474: my %domcoords = &get_active_dcs($dom);
1.191 raeburn 13475: my @domcoord = keys(%domcoords);
13476: if (keys(%currhash)) {
13477: foreach my $dc (keys(%currhash)) {
13478: unless (exists($domcoords{$dc})) {
13479: push(@domcoord,$dc);
13480: }
13481: }
13482: }
13483: @domcoord = sort(@domcoord);
1.210 raeburn 13484: my $numdcs = scalar(@domcoord);
1.191 raeburn 13485: my $rows = 0;
13486: my $table;
1.125 raeburn 13487: if ($numdcs > 1) {
1.191 raeburn 13488: $table = '<table>';
13489: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 13490: my $rem = $i%($numinrow);
13491: if ($rem == 0) {
13492: if ($i > 0) {
1.191 raeburn 13493: $table .= '</tr>';
1.125 raeburn 13494: }
1.191 raeburn 13495: $table .= '<tr>';
13496: $rows ++;
1.125 raeburn 13497: }
1.191 raeburn 13498: my $check = '';
13499: if ($inputtype eq 'radio') {
13500: if (keys(%currhash) == 0) {
13501: if (!$i) {
13502: $check = ' checked="checked"';
13503: }
13504: } elsif (exists($currhash{$domcoord[$i]})) {
13505: $check = ' checked="checked"';
13506: }
13507: } else {
13508: if (exists($currhash{$domcoord[$i]})) {
13509: $check = ' checked="checked"';
1.125 raeburn 13510: }
13511: }
1.191 raeburn 13512: if ($i == @domcoord - 1) {
1.125 raeburn 13513: my $colsleft = $numinrow - $rem;
13514: if ($colsleft > 1) {
1.191 raeburn 13515: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 13516: } else {
1.191 raeburn 13517: $table .= '<td class="LC_left_item">';
1.125 raeburn 13518: }
13519: } else {
1.191 raeburn 13520: $table .= '<td class="LC_left_item">';
13521: }
13522: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
13523: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
13524: $table .= '<span class="LC_nobreak"><label>'.
13525: '<input type="'.$inputtype.'" name="'.$name.'"'.
13526: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
13527: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 13528: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 13529: }
1.219 raeburn 13530: $table .= '</label></span></td>';
1.191 raeburn 13531: }
13532: $table .= '</tr></table>';
13533: } elsif ($numdcs == 1) {
1.219 raeburn 13534: my ($dcname,$dcdom) = split(':',$domcoord[0]);
13535: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 13536: if ($inputtype eq 'radio') {
1.247 raeburn 13537: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 13538: if ($user ne $dcname.':'.$dcdom) {
13539: $table .= ' ('.$dcname.':'.$dcdom.')';
13540: }
1.191 raeburn 13541: } else {
13542: my $check;
13543: if (exists($currhash{$domcoord[0]})) {
13544: $check = ' checked="checked"';
1.125 raeburn 13545: }
1.247 raeburn 13546: $table = '<span class="LC_nobreak"><label>'.
13547: '<input type="checkbox" name="'.$name.'" '.
13548: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 13549: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 13550: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 13551: }
1.220 raeburn 13552: $table .= '</label></span>';
1.191 raeburn 13553: $rows ++;
1.125 raeburn 13554: }
13555: }
1.191 raeburn 13556: return ($numdcs,$table,$rows);
1.125 raeburn 13557: }
13558:
1.137 raeburn 13559: sub usersession_titles {
13560: return &Apache::lonlocal::texthash(
13561: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
13562: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 13563: spares => 'Servers offloaded to, when busy',
1.137 raeburn 13564: version => 'LON-CAPA version requirement',
1.138 raeburn 13565: excludedomain => 'Allow all, but exclude specific domains',
13566: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 13567: primary => 'Primary (checked first)',
1.154 raeburn 13568: default => 'Default',
1.137 raeburn 13569: );
13570: }
13571:
1.152 raeburn 13572: sub id_for_thisdom {
13573: my (%servers) = @_;
13574: my %altids;
13575: foreach my $server (keys(%servers)) {
13576: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
13577: if ($serverhome ne $server) {
13578: $altids{$serverhome} = $server;
13579: }
13580: }
13581: return %altids;
13582: }
13583:
1.150 raeburn 13584: sub count_servers {
13585: my ($currbalancer,%servers) = @_;
13586: my (@spares,$numspares);
13587: foreach my $lonhost (sort(keys(%servers))) {
13588: next if ($currbalancer eq $lonhost);
13589: push(@spares,$lonhost);
13590: }
13591: if ($currbalancer) {
13592: $numspares = scalar(@spares);
13593: } else {
13594: $numspares = scalar(@spares) - 1;
13595: }
13596: return ($numspares,@spares);
13597: }
13598:
13599: sub lonbalance_targets_js {
1.171 raeburn 13600: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 13601: my $select = &mt('Select');
13602: my ($alltargets,$allishome,$allinsttypes,@alltypes);
13603: if (ref($servers) eq 'HASH') {
13604: $alltargets = join("','",sort(keys(%{$servers})));
13605: my @homedoms;
13606: foreach my $server (sort(keys(%{$servers}))) {
13607: if (&Apache::lonnet::host_domain($server) eq $dom) {
13608: push(@homedoms,'1');
13609: } else {
13610: push(@homedoms,'0');
13611: }
13612: }
13613: $allishome = join("','",@homedoms);
13614: }
13615: if (ref($types) eq 'ARRAY') {
13616: if (@{$types} > 0) {
13617: @alltypes = @{$types};
13618: }
13619: }
13620: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
13621: $allinsttypes = join("','",@alltypes);
1.171 raeburn 13622: my (%currbalancer,%currtargets,%currrules,%existing);
13623: if (ref($settings) eq 'HASH') {
13624: %existing = %{$settings};
13625: }
13626: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
13627: \%currtargets,\%currrules);
1.210 raeburn 13628: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 13629: return <<"END";
13630:
13631: <script type="text/javascript">
13632: // <![CDATA[
13633:
1.171 raeburn 13634: currBalancers = new Array('$balancers');
13635:
13636: function toggleTargets(balnum) {
13637: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13638: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
13639: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
13640: var prevbalancer = prevhostitem.value;
13641: var baltotal = document.getElementById('loadbalancing_total').value;
13642: prevhostitem.value = balancer;
13643: if (prevbalancer != '') {
13644: var prevIdx = currBalancers.indexOf(prevbalancer);
13645: if (prevIdx != -1) {
13646: currBalancers.splice(prevIdx,1);
13647: }
13648: }
1.150 raeburn 13649: if (balancer == '') {
1.171 raeburn 13650: hideSpares(balnum);
1.150 raeburn 13651: } else {
1.171 raeburn 13652: var currIdx = currBalancers.indexOf(balancer);
13653: if (currIdx == -1) {
13654: currBalancers.push(balancer);
13655: }
1.150 raeburn 13656: var homedoms = new Array('$allishome');
1.171 raeburn 13657: var ishomedom = homedoms[lonhostitem.selectedIndex];
13658: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 13659: }
1.171 raeburn 13660: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 13661: return;
13662: }
13663:
1.171 raeburn 13664: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 13665: var alltargets = new Array('$alltargets');
13666: var insttypes = new Array('$allinsttypes');
1.151 raeburn 13667: var offloadtypes = new Array('primary','default');
13668:
1.171 raeburn 13669: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
13670: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 13671:
1.151 raeburn 13672: for (var i=0; i<offloadtypes.length; i++) {
13673: var count = 0;
13674: for (var j=0; j<alltargets.length; j++) {
13675: if (alltargets[j] != balancer) {
1.171 raeburn 13676: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
13677: item.value = alltargets[j];
13678: item.style.textAlign='left';
13679: item.style.textFace='normal';
13680: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
13681: if (currBalancers.indexOf(alltargets[j]) == -1) {
13682: item.disabled = '';
13683: } else {
13684: item.disabled = 'disabled';
13685: item.checked = false;
13686: }
1.151 raeburn 13687: count ++;
13688: }
1.150 raeburn 13689: }
13690: }
1.151 raeburn 13691: for (var k=0; k<insttypes.length; k++) {
13692: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 13693: if (ishomedom == 1) {
1.171 raeburn 13694: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13695: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13696: } else {
1.171 raeburn 13697: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13698: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 13699: }
13700: } else {
1.171 raeburn 13701: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13702: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13703: }
1.151 raeburn 13704: if ((insttypes[k] != '_LC_external') &&
13705: ((insttypes[k] != '_LC_internetdom') ||
13706: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 13707: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
13708: item.options.length = 0;
13709: item.options[0] = new Option("","",true,true);
1.210 raeburn 13710: var idx = 0;
1.151 raeburn 13711: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 13712: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
13713: idx ++;
13714: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 13715: }
13716: }
13717: }
13718: }
13719: return;
13720: }
13721:
1.171 raeburn 13722: function hideSpares(balnum) {
1.150 raeburn 13723: var alltargets = new Array('$alltargets');
13724: var insttypes = new Array('$allinsttypes');
13725: var offloadtypes = new Array('primary','default');
13726:
1.171 raeburn 13727: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
13728: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 13729:
13730: var total = alltargets.length - 1;
13731: for (var i=0; i<offloadtypes; i++) {
13732: for (var j=0; j<total; j++) {
1.171 raeburn 13733: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
13734: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
13735: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 13736: }
1.150 raeburn 13737: }
13738: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 13739: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13740: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 13741: if (insttypes[k] != '_LC_external') {
1.171 raeburn 13742: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
13743: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 13744: }
13745: }
13746: return;
13747: }
13748:
1.171 raeburn 13749: function checkOffloads(item,balnum,type) {
1.150 raeburn 13750: var alltargets = new Array('$alltargets');
13751: var offloadtypes = new Array('primary','default');
13752: if (item.checked) {
13753: var total = alltargets.length - 1;
13754: var other;
13755: if (type == offloadtypes[0]) {
1.151 raeburn 13756: other = offloadtypes[1];
1.150 raeburn 13757: } else {
1.151 raeburn 13758: other = offloadtypes[0];
1.150 raeburn 13759: }
13760: for (var i=0; i<total; i++) {
1.171 raeburn 13761: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 13762: if (server == item.value) {
1.171 raeburn 13763: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
13764: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 13765: }
13766: }
13767: }
13768: }
13769: return;
13770: }
13771:
1.171 raeburn 13772: function singleServerToggle(balnum,type) {
13773: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 13774: if (offloadtoSelIdx == 0) {
1.171 raeburn 13775: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
13776: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13777:
13778: } else {
1.171 raeburn 13779: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
13780: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 13781: }
13782: return;
13783: }
13784:
1.171 raeburn 13785: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 13786: if (type == '_LC_external') {
1.171 raeburn 13787: return;
1.150 raeburn 13788: }
1.171 raeburn 13789: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 13790: for (var i=0; i<typesRules.length; i++) {
13791: if (formname.elements[typesRules[i]].checked) {
13792: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 13793: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
13794: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13795: } else {
1.171 raeburn 13796: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
13797: }
13798: }
13799: }
13800: return;
13801: }
13802:
13803: function balancerDeleteChange(balnum) {
13804: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13805: var baltotal = document.getElementById('loadbalancing_total').value;
13806: var addtarget;
13807: var removetarget;
13808: var action = 'delete';
13809: if (document.getElementById('loadbalancing_delete_'+balnum)) {
13810: var lonhost = hostitem.value;
13811: var currIdx = currBalancers.indexOf(lonhost);
13812: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
13813: if (currIdx != -1) {
13814: currBalancers.splice(currIdx,1);
13815: }
13816: addtarget = lonhost;
13817: } else {
13818: if (currIdx == -1) {
13819: currBalancers.push(lonhost);
13820: }
13821: removetarget = lonhost;
13822: action = 'undelete';
13823: }
13824: balancerChange(balnum,baltotal,action,addtarget,removetarget);
13825: }
13826: return;
13827: }
13828:
13829: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
13830: if (baltotal > 1) {
13831: var offloadtypes = new Array('primary','default');
13832: var alltargets = new Array('$alltargets');
13833: var insttypes = new Array('$allinsttypes');
13834: for (var i=0; i<baltotal; i++) {
13835: if (i != balnum) {
13836: for (var j=0; j<offloadtypes.length; j++) {
13837: var total = alltargets.length - 1;
13838: for (var k=0; k<total; k++) {
13839: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
13840: var server = serveritem.value;
13841: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13842: if (server == addtarget) {
13843: serveritem.disabled = '';
13844: }
13845: }
13846: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13847: if (server == removetarget) {
13848: serveritem.disabled = 'disabled';
13849: serveritem.checked = false;
13850: }
13851: }
13852: }
13853: }
13854: for (var j=0; j<insttypes.length; j++) {
13855: if (insttypes[j] != '_LC_external') {
13856: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
13857: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
13858: var currSel = singleserver.selectedIndex;
13859: var currVal = singleserver.options[currSel].value;
13860: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13861: var numoptions = singleserver.options.length;
13862: var needsnew = 1;
13863: for (var k=0; k<numoptions; k++) {
13864: if (singleserver.options[k] == addtarget) {
13865: needsnew = 0;
13866: break;
13867: }
13868: }
13869: if (needsnew == 1) {
13870: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
13871: }
13872: }
13873: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13874: singleserver.options.length = 0;
13875: if ((currVal) && (currVal != removetarget)) {
13876: singleserver.options[0] = new Option("","",false,false);
13877: } else {
13878: singleserver.options[0] = new Option("","",true,true);
13879: }
13880: var idx = 0;
13881: for (var m=0; m<alltargets.length; m++) {
13882: if (currBalancers.indexOf(alltargets[m]) == -1) {
13883: idx ++;
13884: if (currVal == alltargets[m]) {
13885: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
13886: } else {
13887: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
13888: }
13889: }
13890: }
13891: }
13892: }
13893: }
13894: }
1.150 raeburn 13895: }
13896: }
13897: }
13898: return;
13899: }
13900:
1.152 raeburn 13901: // ]]>
13902: </script>
13903:
13904: END
13905: }
13906:
13907: sub new_spares_js {
13908: my @sparestypes = ('primary','default');
13909: my $types = join("','",@sparestypes);
13910: my $select = &mt('Select');
13911: return <<"END";
13912:
13913: <script type="text/javascript">
13914: // <![CDATA[
13915:
13916: function updateNewSpares(formname,lonhost) {
13917: var types = new Array('$types');
13918: var include = new Array();
13919: var exclude = new Array();
13920: for (var i=0; i<types.length; i++) {
13921: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
13922: for (var j=0; j<spareboxes.length; j++) {
13923: if (formname.elements[spareboxes[j]].checked) {
13924: exclude.push(formname.elements[spareboxes[j]].value);
13925: } else {
13926: include.push(formname.elements[spareboxes[j]].value);
13927: }
13928: }
13929: }
13930: for (var i=0; i<types.length; i++) {
13931: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
13932: var selIdx = newSpare.selectedIndex;
13933: var currnew = newSpare.options[selIdx].value;
13934: var okSpares = new Array();
13935: for (var j=0; j<newSpare.options.length; j++) {
13936: var possible = newSpare.options[j].value;
13937: if (possible != '') {
13938: if (exclude.indexOf(possible) == -1) {
13939: okSpares.push(possible);
13940: } else {
13941: if (currnew == possible) {
13942: selIdx = 0;
13943: }
13944: }
13945: }
13946: }
13947: for (var k=0; k<include.length; k++) {
13948: if (okSpares.indexOf(include[k]) == -1) {
13949: okSpares.push(include[k]);
13950: }
13951: }
13952: okSpares.sort();
13953: newSpare.options.length = 0;
13954: if (selIdx == 0) {
13955: newSpare.options[0] = new Option("$select","",true,true);
13956: } else {
13957: newSpare.options[0] = new Option("$select","",false,false);
13958: }
13959: for (var m=0; m<okSpares.length; m++) {
13960: var idx = m+1;
13961: var selThis = 0;
13962: if (selIdx != 0) {
13963: if (okSpares[m] == currnew) {
13964: selThis = 1;
13965: }
13966: }
13967: if (selThis == 1) {
13968: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
13969: } else {
13970: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
13971: }
13972: }
13973: }
13974: return;
13975: }
13976:
13977: function checkNewSpares(lonhost,type) {
13978: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
13979: var chosen = newSpare.options[newSpare.selectedIndex].value;
13980: if (chosen != '') {
13981: var othertype;
13982: var othernewSpare;
13983: if (type == 'primary') {
13984: othernewSpare = document.getElementById('newspare_default_'+lonhost);
13985: }
13986: if (type == 'default') {
13987: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
13988: }
13989: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
13990: othernewSpare.selectedIndex = 0;
13991: }
13992: }
13993: return;
13994: }
13995:
13996: // ]]>
13997: </script>
13998:
13999: END
14000:
14001: }
14002:
14003: sub common_domprefs_js {
14004: return <<"END";
14005:
14006: <script type="text/javascript">
14007: // <![CDATA[
14008:
1.150 raeburn 14009: function getIndicesByName(formname,item) {
1.152 raeburn 14010: var group = new Array();
1.150 raeburn 14011: for (var i=0;i<formname.elements.length;i++) {
14012: if (formname.elements[i].name == item) {
1.152 raeburn 14013: group.push(formname.elements[i].id);
1.150 raeburn 14014: }
14015: }
1.152 raeburn 14016: return group;
1.150 raeburn 14017: }
14018:
14019: // ]]>
14020: </script>
14021:
14022: END
1.152 raeburn 14023:
1.150 raeburn 14024: }
14025:
1.165 raeburn 14026: sub recaptcha_js {
14027: my %lt = &captcha_phrases();
14028: return <<"END";
14029:
14030: <script type="text/javascript">
14031: // <![CDATA[
14032:
14033: function updateCaptcha(caller,context) {
14034: var privitem;
14035: var pubitem;
14036: var privtext;
14037: var pubtext;
1.269 raeburn 14038: var versionitem;
14039: var versiontext;
1.165 raeburn 14040: if (document.getElementById(context+'_recaptchapub')) {
14041: pubitem = document.getElementById(context+'_recaptchapub');
14042: } else {
14043: return;
14044: }
14045: if (document.getElementById(context+'_recaptchapriv')) {
14046: privitem = document.getElementById(context+'_recaptchapriv');
14047: } else {
14048: return;
14049: }
14050: if (document.getElementById(context+'_recaptchapubtxt')) {
14051: pubtext = document.getElementById(context+'_recaptchapubtxt');
14052: } else {
14053: return;
14054: }
14055: if (document.getElementById(context+'_recaptchaprivtxt')) {
14056: privtext = document.getElementById(context+'_recaptchaprivtxt');
14057: } else {
14058: return;
14059: }
1.269 raeburn 14060: if (document.getElementById(context+'_recaptchaversion')) {
14061: versionitem = document.getElementById(context+'_recaptchaversion');
14062: } else {
14063: return;
14064: }
14065: if (document.getElementById(context+'_recaptchavertxt')) {
14066: versiontext = document.getElementById(context+'_recaptchavertxt');
14067: } else {
14068: return;
14069: }
1.165 raeburn 14070: if (caller.checked) {
14071: if (caller.value == 'recaptcha') {
14072: pubitem.type = 'text';
14073: privitem.type = 'text';
14074: pubitem.size = '40';
14075: privitem.size = '40';
14076: pubtext.innerHTML = "$lt{'pub'}";
14077: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 14078: versionitem.type = 'text';
14079: versionitem.size = '3';
14080: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 14081: } else {
14082: pubitem.type = 'hidden';
14083: privitem.type = 'hidden';
1.269 raeburn 14084: versionitem.type = 'hidden';
1.165 raeburn 14085: pubtext.innerHTML = '';
14086: privtext.innerHTML = '';
1.269 raeburn 14087: versiontext.innerHTML = '';
1.165 raeburn 14088: }
14089: }
14090: return;
14091: }
14092:
14093: // ]]>
14094: </script>
14095:
14096: END
14097:
14098: }
14099:
1.236 raeburn 14100: sub toggle_display_js {
1.192 raeburn 14101: return <<"END";
14102:
14103: <script type="text/javascript">
14104: // <![CDATA[
14105:
1.236 raeburn 14106: function toggleDisplay(domForm,caller) {
14107: if (document.getElementById(caller)) {
14108: var divitem = document.getElementById(caller);
14109: var optionsElement = domForm.coursecredits;
1.264 raeburn 14110: var checkval = 1;
14111: var dispval = 'block';
1.236 raeburn 14112: if (caller == 'emailoptions') {
14113: optionsElement = domForm.cancreate_email;
14114: }
1.257 raeburn 14115: if (caller == 'studentsubmission') {
14116: optionsElement = domForm.postsubmit;
14117: }
1.264 raeburn 14118: if (caller == 'cloneinstcode') {
14119: optionsElement = domForm.canclone;
14120: checkval = 'instcode';
14121: }
1.236 raeburn 14122: if (optionsElement.length) {
1.192 raeburn 14123: var currval;
1.236 raeburn 14124: for (var i=0; i<optionsElement.length; i++) {
14125: if (optionsElement[i].checked) {
14126: currval = optionsElement[i].value;
1.192 raeburn 14127: }
14128: }
1.264 raeburn 14129: if (currval == checkval) {
14130: divitem.style.display = dispval;
1.192 raeburn 14131: } else {
1.236 raeburn 14132: divitem.style.display = 'none';
1.192 raeburn 14133: }
14134: }
14135: }
14136: return;
14137: }
14138:
14139: // ]]>
14140: </script>
14141:
14142: END
14143:
14144: }
14145:
1.165 raeburn 14146: sub captcha_phrases {
14147: return &Apache::lonlocal::texthash (
14148: priv => 'Private key',
14149: pub => 'Public key',
14150: original => 'original (CAPTCHA)',
14151: recaptcha => 'successor (ReCAPTCHA)',
14152: notused => 'unused',
1.269 raeburn 14153: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 14154: );
14155: }
14156:
1.205 raeburn 14157: sub devalidate_remote_domconfs {
1.212 raeburn 14158: my ($dom,$cachekeys) = @_;
14159: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 14160: my %servers = &Apache::lonnet::internet_dom_servers($dom);
14161: my %thismachine;
14162: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.267 raeburn 14163: my @posscached = ('domainconfig','domdefaults','ltitools');
1.260 raeburn 14164: if (keys(%servers)) {
1.205 raeburn 14165: foreach my $server (keys(%servers)) {
14166: next if ($thismachine{$server});
1.212 raeburn 14167: my @cached;
14168: foreach my $name (@posscached) {
14169: if ($cachekeys->{$name}) {
14170: push(@cached,&escape($name).':'.&escape($dom));
14171: }
14172: }
14173: if (@cached) {
14174: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
14175: }
1.205 raeburn 14176: }
14177: }
14178: return;
14179: }
14180:
1.3 raeburn 14181: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>